예제 #1
0
        private void MyWindow_Loaded(object sender1, RoutedEventArgs e1)
        {
            _bindObj     = new ChoWPFBindableConfigObject <ChoAppSettings>();
            _appSettings = _bindObj.UnderlyingSource;
            _appSettings.Init();
            if (!SettingsFilePath.IsNullOrWhiteSpace() && File.Exists(SettingsFilePath))
            {
                _appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
            }
            else
            {
                _appSettings.Reset();
            }

            DataContext   = this;
            _mainUIThread = Thread.CurrentThread;

            btnNewFile_Click(null, null);

            _dispatcherTimer          = new System.Windows.Threading.DispatcherTimer();
            _dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
            _dispatcherTimer.Start();

            string x = _appSettings.SourceDirectory;
            ChoShellExtCmdLineArgs cmdLineArgs = new ChoShellExtCmdLineArgs();

            if (!cmdLineArgs.Directory.IsNullOrWhiteSpace())
            {
                _appSettings.SourceDirectory = cmdLineArgs.Directory;
            }

            IsDirty = false;
        }
예제 #2
0
        private void MyWindow_Loaded(object sender1, RoutedEventArgs e1)
        {
            _bindObj     = new ChoWPFBindableConfigObject <ChoAppSettings>();
            _appSettings = _bindObj.UnderlyingSource;
            _appSettings.Init();
            if (!SettingsFilePath.IsNullOrWhiteSpace() && File.Exists(SettingsFilePath))
            {
                _appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
            }
            else
            {
                _appSettings.Reset();
            }

            this.DataContext = _appSettings;
            _appSettings.BeforeConfigurationObjectLoaded += ((o, e) =>
            {
                e.Cancel = (bool)this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                                        new Func <bool>(() =>
                {
                    if (IsDirty)
                    {
                        if (MessageBox.Show("Configuration settings has been modified outside of the tool. {0}Do you want to reload it and lose the changes made in the tool?".FormatString(Environment.NewLine),
                                            Title, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                        {
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    }

                    return(false);
                }));
            });

            _appSettings.AfterConfigurationObjectMemberSet += ((o, e) =>
            {
                if (_wndLoaded)
                {
                    IsDirty = true;
                }
                this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                            new Action(() =>
                {
                    txtRoboCopyCmd.Text = _appSettings.GetCmdLineText();
                }));
            });

            _appSettings.ConfigurationObjectMemberLoadError += _appSettings_ConfigurationObjectMemberLoadError;
            _appSettings.AfterConfigurationObjectPersisted  += _appSettings_AfterConfigurationObjectPersisted;
            _appSettings.AfterConfigurationObjectLoaded     += ((o, e) =>
            {
                if (_wndLoaded)
                {
                    this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                           new Action(() =>
                    {
                        this.DataContext = null;
                        this.DataContext = _appSettings;
                        txtRoboCopyCmd.Text = _appSettings.GetCmdLineText();
                        IsDirty = false;
                    }));
                }
                else
                {
                    this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                           new Action(() =>
                    {
                        txtRoboCopyCmd.Text = _appSettings.GetCmdLineText();
                    }));
                }
            });

            _mainUIThread = Thread.CurrentThread;

            _dispatcherTimer          = new System.Windows.Threading.DispatcherTimer();
            _dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
            _dispatcherTimer.Start();

            string x = _appSettings.SourceDirectory;
            ChoShellExtCmdLineArgs cmdLineArgs = new ChoShellExtCmdLineArgs();

            if (!cmdLineArgs.Directory.IsNullOrWhiteSpace())
            {
                _appSettings.SourceDirectory = cmdLineArgs.Directory;
            }

            IsDirty = false;
        }