コード例 #1
0
        public TaskbarIconViewModel(ViewManager manager, ProgramSettings settings, IDialogService dialogService)
        {
            _manager       = manager;
            _dialogService = dialogService;
            _settings      = settings;

            ExitCommand = new DelegateCommand(() => Application.Current.Shutdown());

            SettingsCommand = new DelegateCommand(() =>
            {
                var dialog = _dialogService.CreateDialog <SettingsViewModel, SettingsView>(_manager.Settings);
                if (dialog.ShowDialog() == true)
                {
                    manager.ApplySettings(dialog);
                }
            });

            AboutCommand = new DelegateCommand(() =>
            {
                var dialog = _dialogService.CreateDialog <AboutViewModel, AboutView>();
                dialog.ShowDialog();
            });

            StartStopCommand = new DelegateCommand(() =>
            {
                if (manager.IsWindowVisible)
                {
                    manager.Stop();
                }
                else
                {
                    manager.Start();
                }
                RaisePropertyChanged(nameof(MenuItemStartStopText));
                RaisePropertyChanged(nameof(MenuItemStartStopIcon));
            });

            AutoStartCommand = new DelegateCommand(() =>
            {
                if (StartUpManager.IsInStartup())
                {
                    StartUpManager.RemoveFromStartup();
                }
                else
                {
                    StartUpManager.AddToStartup();
                }
                RaisePropertyChanged(nameof(AutoStart));
            });
        }
コード例 #2
0
        private void MenuItemSettingsClick(object sender, EventArgs e)
        {
            if (_settingsForm == null || _settingsForm.IsDisposed || !_settingsForm.IsHandleCreated)
            {
                if (_settings != null)
                {
                    _settings.AutoStartProgram = StartUpManager.IsInStartup(AssemblyUtils.AssemblyProductName, AssemblyUtils.AssemblyLocation);
                }
                Environment.CurrentDirectory = AssemblyUtils.AssemblyDirectory;
                _settingsForm = new ProgramSettingsForm(_settings);
            }

            if (!_settingsForm.Visible)
            {
                DialogResult result = _settingsForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    try
                    {
                        ProgramSettings.Write(_settingsForm.Settings);
                    }
                    catch
                    {
                        MessageBox.Show("Failed to save program settings.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (_settingsForm.Settings.AutoStartProgram)
                    {
                        StartUpManager.AddToStartup(AssemblyUtils.AssemblyProductName, AssemblyUtils.AssemblyLocation);
                    }
                    else
                    if (StartUpManager.IsInStartup(AssemblyUtils.AssemblyProductName, AssemblyUtils.AssemblyLocation))
                    {
                        StartUpManager.RemoveFromStartup(AssemblyUtils.AssemblyProductName);
                    }
                    Stop();
                    Start();
                }
            }
        }
コード例 #3
0
        public TaskbarIconViewModel(ViewManager manager, ProgramSettings settings, IDialogService dialogService)
        {
            _manager       = manager;
            _dialogService = dialogService;
            _settings      = settings;

            RefreshCommand = new DelegateCommand(() => _manager.Refresh());
            ExitCommand    = new DelegateCommand(() => Application.Current.Shutdown());

            SettingsCommand = new DelegateCommand(() =>
            {
                var dialog = _dialogService.CreateDialog <SettingsViewModel, SettingsView>(_manager.Settings);
                dialog.SelectedTabIndex = _manager.Settings.WallpaperType == WallpaperType.SystemInformation ? 1 : _manager.Settings.WallpaperType == WallpaperType.Image ? 2 : _manager.Settings.WallpaperType == WallpaperType.Gallery ? 3 : _manager.Settings.WallpaperType == WallpaperType.Video ? 4 : 0;
                if (dialog.ShowDialog() == true)
                {
                    manager.ApplySettings(dialog);
                }
            });

            PlayCommand = new DelegateCommand(() => {
                if (_settings.WallpaperType == WallpaperType.Video)
                {
                    _manager.VideoPlay();
                }
                if (_settings.WallpaperType == WallpaperType.Gallery)
                {
                    _manager.GalleryPlay();
                }
            });

            PauseCommand = new DelegateCommand(() => {
                if (_settings.WallpaperType == WallpaperType.Video)
                {
                    _manager.VideoPause();
                }
                if (_settings.WallpaperType == WallpaperType.Gallery)
                {
                    _manager.GalleryPause();
                }
            });

            StopCommand = new DelegateCommand(() => {
                if (_settings.WallpaperType == WallpaperType.Video)
                {
                    _manager.VideoStop();
                }
                if (_settings.WallpaperType == WallpaperType.Gallery)
                {
                    _manager.GalleryStop();
                }
            });

            AboutCommand = new DelegateCommand(() =>
            {
                var dialog = _dialogService.CreateDialog <AboutViewModel, AboutView>();
                dialog.ShowDialog();
            });

            ShowHideCommand = new DelegateCommand(() =>
            {
                manager.ShowWindow(!manager.IsWindowVisible);
                RaisePropertyChanged(nameof(MenuItemShowHideText));
            });

            AutoStartCommand = new DelegateCommand(() =>
            {
                if (StartUpManager.IsInStartup())
                {
                    StartUpManager.RemoveFromStartup();
                }
                else
                {
                    StartUpManager.AddToStartup();
                }
                RaisePropertyChanged(nameof(AutoStart));
            });

            EnableInteractiveModeCommand = new DelegateCommand(() =>
            {
                _settings.InteractiveMode = !_settings.InteractiveMode;
                manager.EnableInteractive(_settings.InteractiveMode);
                manager.Update();
                RaisePropertyChanged(nameof(MenuItemInteractiveModeText));
            });
        }