コード例 #1
0
        public SettingsViewModel()
        {
            // command that show folder selection dialog and add selected folder to list
            _addCommand = new CommandHandler(
                o =>
            {
                var dial = new FolderBrowserDialog();
                if (
                    dial.ShowDialog(null) == DialogResult.OK)
                {
                    _mediaPaths.Add(dial.SelectedPath);
                }
            },
                o => true);
            // command that delete selected folder from list
            _delCommand = new CommandHandler(o =>
            {
                if (!String.IsNullOrWhiteSpace(_selectedRow) && _mediaPaths.Contains(_selectedRow))
                {
                    _mediaPaths.Remove(_selectedRow);
                }
            }, o => !String.IsNullOrWhiteSpace(_selectedRow));

            // command that will remove all registry keys
            _removeSettingsCommand = new CommandHandler(o =>
            {
                if (System.Windows.MessageBox.Show("Are you sure you want to remove all settings from registry?", "Remove all settings", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    PreferenceManager.RemoveRegistryKeys();
                    Application.Current.Shutdown();
                }
            }, o => true);

            // command that will save setting to registry
            _saveCommand = new CommandHandler(o =>
            {
                PreferenceManager.WriteVideoSettings(_mediaPaths.ToList());
                PreferenceManager.WriteVolumeSetting((float)Volume / 100F);
                PreferenceManager.WriteAlgorithmSetting(NextMediaAlgorithm);
                PreferenceManager.WriteIntervalSetting(Interval);
                PreferenceManager.WriteVolumeTimeoutSetting(VolumeTimeout);
                Application.Current.Shutdown();
            }, o => true);

            // command that will remove all registry keys
            _cancelCommand = new CommandHandler(o =>
            {
                if (System.Windows.MessageBox.Show("Are you sure you want to close settings and discard changes?", "Exit and discard", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    Application.Current.Shutdown();
                }
            }, o => true);

            // list of folders
            var list = PreferenceManager.ReadVideoSettings();

            foreach (var item in list)
            {
                _mediaPaths.Add(item);
            }

            Volume             = (int)(PreferenceManager.ReadVolumeSetting() * 100);
            NextMediaAlgorithm = PreferenceManager.ReadAlgorithmSetting();
            Interval           = PreferenceManager.ReadIntervalSetting();
            VolumeTimeout      = PreferenceManager.ReadVolumeTimeoutSetting();
        }