private static ToolStripMenuItem CommandToButton(IToolbarCommand command)
        {
            var button = new ToolStripMenuItem();

            if (command.IsOption)
            {
                button = new ToolStripRadioButtonMenuItem();
            }

            button.Checked                  = command.Checked;
            button.CheckOnClick             = command.CheckOnClick;
            button.ToolTipText              = command.ToolTip?.Replace(@"&", "");
            button.Text                     = command.Text;
            button.Image                    = command.Icon;
            button.Enabled                  = command.IsEnabled;
            button.Visible                  = command.Visible;
            button.ImageScaling             = ToolStripItemImageScaling.SizeToFit;
            button.DisplayStyle             = ToolStripItemDisplayStyle.ImageAndText;
            button.ShowShortcutKeys         = true;
            button.ShortcutKeyDisplayString = command.ShortcutKeyString;
            var c = command; // create a closure around the command

            command.PropertyChanged += (o, s) =>
            {
                button.ShortcutKeyDisplayString = c.ShortcutKeyString;
                button.CheckOnClick             = c.CheckOnClick;
                button.Checked     = c.Checked;
                button.ToolTipText = c.ToolTip;
                button.Visible     = c.Visible;
                button.Text        = c.Text;
                button.Image       = c.Icon;
                button.Enabled     = c.IsEnabled;
            };

            if (!(command is DummyCommand))
            {
                button.Click     += (sender, args) => c.Execute();
                button.MouseDown += (sender, args) =>
                {
                    if (args.Button != MouseButtons.Left && !(SystemInformation.MouseButtonsSwapped
#if !__MonoCS__
                                                              || System.Windows.SystemParameters.SwapButtons
#endif
                                                              ))
                    {
                        c.Execute();
                    }
                    else if (args.Button != MouseButtons.Right && (SystemInformation.MouseButtonsSwapped
#if !__MonoCS__
                                                                   || System.Windows.SystemParameters.SwapButtons
#endif
                                                                   ))
                    {
                        c.Execute();
                    }
                };
            }
            return(button);
        }
        static void Main()
        {
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += ApplicationOnThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
            var culture = new CultureInfo("en");

            Thread.CurrentThread.CurrentUICulture     = culture;
            Thread.CurrentThread.CurrentCulture       = culture;
            CultureInfo.DefaultThreadCurrentUICulture = culture;
            CultureInfo.DefaultThreadCurrentCulture   = culture;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var episodeView      = new WpfEpisodeViewHost();
            var subscriptionView = new SubscriptionView();
            var podcastView      = new PodcastView();
            var toolbarView      = new ToolBarView();

            var podcastPlayer            = new PodcastPlayer();
            var podcastLoader            = new PodcastLoader();
            var settingsService          = new SettingsService();
            var subscriptionManager      = new SubscriptionManager("subscriptions.xml");
            var messageBoxDisplayService = new MessageBoxDisplayService();
            var systemInformationService = new SystemInformationService();
            var newSubscriptionService   = new NewSubscriptionService();

            var commands = new IToolbarCommand[]
            {
                new AddSubscriptionCommand(messageBoxDisplayService,
                                           newSubscriptionService,
                                           podcastLoader,
                                           subscriptionManager),
                new RemoveSubscriptionCommand(subscriptionView, subscriptionManager),
                new PlayCommand(podcastPlayer),
                new PauseCommand(podcastPlayer),
                new StopCommand(podcastPlayer),
                new FavouriteCommand(subscriptionView),
                new SettingsCommand()
            };
            var mainForm = new MainForm(episodeView, subscriptionView, podcastView, toolbarView);

            // for now, keep presenters alive with Tags
            episodeView.Tag      = new EpisodePresenter(episodeView, podcastPlayer);
            subscriptionView.Tag = new SubscriptionPresenter(subscriptionView);
            podcastView.Tag      = new PodcastPresenter(podcastView);
            toolbarView.Tag      = new ToolbarPresenter(toolbarView, commands);

            mainForm.Tag = new MainFormPresenter(mainForm,
                                                 podcastLoader,
                                                 subscriptionManager,
                                                 messageBoxDisplayService,
                                                 settingsService,
                                                 systemInformationService,
                                                 commands);
            Application.Run(mainForm);
        }
Example #3
0
        static void Main()
        {
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += ApplicationOnThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
            var culture = new CultureInfo("en");

            Thread.CurrentThread.CurrentUICulture     = culture;
            Thread.CurrentThread.CurrentCulture       = culture;
            CultureInfo.DefaultThreadCurrentUICulture = culture;
            CultureInfo.DefaultThreadCurrentCulture   = culture;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var subscriptionManager      = new SubscriptionManager("subscriptions.xml");
            var podcastLoader            = new PodcastLoader();
            var podcastPlayer            = new PodcastPlayer();
            var messageBoxDisplayService = new MessageBoxDisplayService();
            var settingsService          = new SettingsService();
            var systemInformationService = new SystemInformationService();
            var newSubscriptionService   = new NewSubscriptionService();
            var mainFormView             = new MainForm();

            var commands = new IToolbarCommand[]
            {
                new AddSubscriptionCommand(mainFormView.SubscriptionView, messageBoxDisplayService, newSubscriptionService, podcastLoader, subscriptionManager),
                new RemoveSubscriptionCommand(mainFormView.SubscriptionView, subscriptionManager),
                new PlayCommand(podcastPlayer),
                new PauseCommand(podcastPlayer),
                new StopCommand(podcastPlayer),
                new FavouriteCommand(mainFormView.SubscriptionView),
                new SettingsCommand()
            };

            var mainFormPresenter = new MainFormPresenter(mainFormView,
                                                          podcastLoader,
                                                          subscriptionManager,
                                                          podcastPlayer,
                                                          messageBoxDisplayService,
                                                          settingsService,
                                                          systemInformationService,
                                                          commands);

            Application.Run(mainFormView);
        }
        private static ToolStripMenuItem CommandToButton(IToolbarCommand command)
        {
            var button = new ToolStripMenuItem();

            if (command.IsOption)
            {
                button = new ToolStripRadioButtonMenuItem();
            }

            button.Checked                  = command.Checked;
            button.CheckOnClick             = command.CheckOnClick;
            button.ToolTipText              = command.ToolTip?.Replace(@"&", "");
            button.Text                     = command.Text;
            button.Image                    = command.Icon;
            button.Enabled                  = command.IsEnabled;
            button.Visible                  = command.Visible;
            button.ImageScaling             = ToolStripItemImageScaling.None;
            button.DisplayStyle             = ToolStripItemDisplayStyle.ImageAndText;
            button.ShowShortcutKeys         = true;
            button.ShortcutKeyDisplayString = command.ShortcutKeyString;
            var c = command; // create a closure around the command

            command.PropertyChanged += (o, s) =>
            {
                button.ShortcutKeyDisplayString = c.ShortcutKeyString;
                button.CheckOnClick             = c.CheckOnClick;
                button.Checked     = c.Checked;
                button.ToolTipText = c.ToolTip;
                button.Visible     = c.Visible;
                button.Text        = c.Text;
                button.Image       = c.Icon;
                button.Enabled     = c.IsEnabled;
            };

            if (!(command is DummyCommand))
            {
                button.Click += (sender, args) => c.Execute();
            }
            return(button);
        }