<commit_before>﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Navigation;
using Microsoft.WindowsAPICodePack.Taskbar;
using mshtml;

namespace Grooveshark
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        private Player m_player;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void BrowserLoadCompleted(object sender, NavigationEventArgs e)
        {
            var document = browser.Document as IHTMLDocument2;
            if (document == null) return;
            
            m_player = new Player(document);

            CreateToolbarButtons();
        }

        private void CreateToolbarButtons()
        {
            var favorite = new ThumbnailToolbarButton(Properties.Resources.Favorite, "Add to Favorites");
            favorite.Click += (sender, args) => m_player.FavoriteSong();

            var next = new ThumbnailToolbarButton(Properties.Resources.Next, "Next Song");
            next.Click += (sender, args) => m_player.NextSong();

            var previous = new ThumbnailToolbarButton(Properties.Resources.Previous, "Previous Song");
            previous.Click += (sender, args) => m_player.PreviousSong();

            var playback = new ThumbnailToolbarButton(Properties.Resources.Play, "Play");
            playback.Click += (sender, args) => m_player.TogglePlayback();

            m_player.PlayerStatusChanged += (sender, args) =>
                                                {
                                                    if (args.CurrentStatus == PlayerStatus.Playing ||
                                                        args.CurrentStatus == PlayerStatus.Loading)
                                                    {
                                                        playback.Icon = Properties.Resources.Pause;
                                                        playback.Tooltip = "Pause";
                                                    }
                                                    else
                                                    {
                                                        playback.Icon = Properties.Resources.Play;
                                                        playback.Tooltip = "Play";
                                                    }
                                                };

            m_player.SongChanged += (sender, args) =>
                                        {
                                            if (args.CurrentSong == null)
                                            {
                                                Title = "Grooveshark";
                                                return;
                                            }

                                            Title = String.Format("{0} - {1} - {2}", args.CurrentSong.Name,
                                                                  args.CurrentSong.ArtistName,
                                                                  args.CurrentSong.AlbumName);
                                        };

            if (TaskbarManager.IsPlatformSupported)
                TaskbarManager.Instance.ThumbnailToolbars.AddButtons(
                    new WindowInteropHelper(Application.Current.MainWindow).Handle,
                    previous,
                    playback,
                    favorite,
                    next);
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            e.Cancel = true;
            WindowState = WindowState.Minimized;

            base.OnClosed(e);
        }
    }
}
<commit_msg>TaskBar buttons are now added only once.<commit_after>﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Navigation;
using Microsoft.WindowsAPICodePack.Taskbar;
using mshtml;

namespace Grooveshark
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        private Player m_player;
        private bool m_buttonsAdded;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void BrowserLoadCompleted(object sender, NavigationEventArgs e)
        {
            var document = browser.Document as IHTMLDocument2;
            if (document == null) return;
            
            m_player = new Player(document);

            CreateToolbarButtons();
        }

        private void CreateToolbarButtons()
        {
            if (m_buttonsAdded) return;
            
            var favorite = new ThumbnailToolbarButton(Properties.Resources.Favorite, "Add to Favorites");
            favorite.Click += (sender, args) => m_player.FavoriteSong();

            var next = new ThumbnailToolbarButton(Properties.Resources.Next, "Next Song");
            next.Click += (sender, args) => m_player.NextSong();

            var previous = new ThumbnailToolbarButton(Properties.Resources.Previous, "Previous Song");
            previous.Click += (sender, args) => m_player.PreviousSong();

            var playback = new ThumbnailToolbarButton(Properties.Resources.Play, "Play");
            playback.Click += (sender, args) => m_player.TogglePlayback();

            m_player.PlayerStatusChanged += (sender, args) =>
                                                {
                                                    if (args.CurrentStatus == PlayerStatus.Playing ||
                                                        args.CurrentStatus == PlayerStatus.Loading)
                                                    {
                                                        playback.Icon = Properties.Resources.Pause;
                                                        playback.Tooltip = "Pause";
                                                    }
                                                    else
                                                    {
                                                        playback.Icon = Properties.Resources.Play;
                                                        playback.Tooltip = "Play";
                                                    }
                                                };

            m_player.SongChanged += (sender, args) =>
                                        {
                                            if (args.CurrentSong == null)
                                            {
                                                Title = "Grooveshark";
                                                return;
                                            }

                                            Title = String.Format("{0} - {1} - {2}", args.CurrentSong.Name,
                                                                  args.CurrentSong.ArtistName,
                                                                  args.CurrentSong.AlbumName);
                                        };

            if (TaskbarManager.IsPlatformSupported)
                TaskbarManager.Instance.ThumbnailToolbars.AddButtons(
                    new WindowInteropHelper(Application.Current.MainWindow).Handle,
                    previous,
                    playback,
                    favorite,
                    next);

            m_buttonsAdded = true;
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            e.Cancel = true;
            WindowState = WindowState.Minimized;

            base.OnClosed(e);
        }
    }
}

{'fraction_non_alphanumeric': 0.07339805825242718, 'fraction_numerical': 0.001035598705501618, 'mean_word_length': 0.9544649633189982, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 88, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '762152', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1416, 'n_words': 306}