Пример #1
0
        public SdeEditor() : base("Server database editor", "cde.ico", SizeToContent.Manual, ResizeMode.CanResize)
        {
            SplashDialog loading = new SplashDialog();

            loading.Show();
            Loaded += delegate {
                loading.Terminate();
            };

            try {
                ApplicationShortcut.OverrideBindings(SdeAppConfiguration.Remapper);
            }
            catch (Exception err) {
                SdeAppConfiguration.Remapper.Clear();
                ApplicationShortcut.OverrideBindings(SdeAppConfiguration.Remapper);
                ErrorHandler.HandleException("Failed to load the custom key bindings. The bindings will be reset to their default values.", err);
            }

            string configFile = _parseCommandLineArguments();

            GrfPath.Delete(ProjectConfiguration.DefaultFileName);

            InitializeComponent();
            Instance      = this;
            ShowInTaskbar = true;

            _asyncOperation = new AsyncOperation(_progressBar);
            _clientDatabase = new SdeDatabase(_metaGrf);
            _loadMenu();

            if (configFile == null)
            {
                ProjectConfiguration.ConfigAsker = new ConfigAsker(ProjectConfiguration.DefaultFileName);

                if (SdeAppConfiguration.AlwaysReopenLatestProject)
                {
                    if (_recentFilesManager.Files.Count > 0 && File.Exists(_recentFilesManager.Files[0]))
                    {
                        ProjectConfiguration.ConfigAsker = new ConfigAsker(configFile = _recentFilesManager.Files[0]);
                    }
                }
            }
            else if (File.Exists(configFile))
            {
                ProjectConfiguration.ConfigAsker = new ConfigAsker(configFile);
            }

            _loadSettingsTab();
            if (configFile != null)
            {
                ReloadSettings(configFile);
            }
            _loadGenericTab();

            _clientDatabase.Commands.ModifiedStateChanged += new AbstractCommand <IGenericDbCommand> .AbstractCommandsEventHandler(_commands_ModifiedStateChanged);

            ApplicationShortcut.Link(ApplicationShortcut.Undo, () => _clientDatabase.Commands.Undo(), this);
            ApplicationShortcut.Link(ApplicationShortcut.UndoGlobal, () => _clientDatabase.Commands.Undo(), this);
            ApplicationShortcut.Link(ApplicationShortcut.Redo, () => _clientDatabase.Commands.Redo(), this);
            ApplicationShortcut.Link(ApplicationShortcut.RedoGlobal, () => _clientDatabase.Commands.Redo(), this);
            ApplicationShortcut.Link(ApplicationShortcut.Search, () => _execute(v => v.Search()), this);
            ApplicationShortcut.Link(ApplicationShortcut.Delete, () => _execute(v => v.DeleteItems()), this);
            ApplicationShortcut.Link(ApplicationShortcut.Rename, () => _execute(v => v.ChangeId()), this);
            ApplicationShortcut.Link(ApplicationShortcut.NavigationBackward, () => _tabEngine.Undo(), this);
            ApplicationShortcut.Link(ApplicationShortcut.NavigationBackward2, () => _tabEngine.Redo(), this);
            ApplicationShortcut.Link(ApplicationShortcut.NavigationForward, () => _tabEngine.Redo(), this);
            ApplicationShortcut.Link(ApplicationShortcut.Change, () => _execute(v => v.ChangeId()), this);
            ApplicationShortcut.Link(ApplicationShortcut.Restrict, () => _execute(v => v.ShowSelectedOnly()), this);
            ApplicationShortcut.Link(ApplicationShortcut.CopyTo, () => _execute(v => v.CopyItemTo()), this);
            ApplicationShortcut.Link(ApplicationShortcut.New, () => _execute(v => v.AddNewItem()), this);
            ApplicationShortcut.Link(ApplicationShortcut.Save, () => _menuItemDatabaseSave_Click(this, null), this);
            ApplicationShortcut.Link(ApplicationShortcut.Replace, () => { if (_menuItemReplaceAll.IsEnabled)
                                                                          {
                                                                              _menuItemReplaceAll_Click(this, null);
                                                                          }
                                     }, this);
            ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Enter", "Select next entry"), () => _execute(v => v.SelectNext()), this);
            ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Shift-Enter", "Select previous entry"), () => _execute(v => v.SelectPrevious()), this);
            Configuration.EnableDebuggerTrace = false;

            _tnbUndo.SetUndo(_tabEngine);
            _tnbRedo.SetRedo(_tabEngine);

            _tmbUndo.SetUndo(_clientDatabase.Commands);
            _tmbRedo.SetRedo(_clientDatabase.Commands);

            Extensions.GenerateListViewTemplate(_debugList, new ListViewDataTemplateHelper.GeneralColumnInfo[] {
                new ListViewDataTemplateHelper.GeneralColumnInfo {
                    Header = "#", DisplayExpression = "ErrorNumber", SearchGetAccessor = "ErrorNumber", FixedWidth = 35, ToolTipBinding = "ErrorNumber", TextAlignment = TextAlignment.Right
                },
                new ListViewDataTemplateHelper.ImageColumnInfo {
                    Header = "", DisplayExpression = "DataImage", SearchGetAccessor = "Exception", FixedWidth = 20, MaxHeight = 24
                },
                new ListViewDataTemplateHelper.RangeColumnInfo {
                    Header = "Exception", DisplayExpression = "Exception", SearchGetAccessor = "Exception", IsFill = true, TextAlignment = TextAlignment.Left, ToolTipBinding = "OriginalException", TextWrapping = TextWrapping.Wrap, MinWidth = 120
                },
                new ListViewDataTemplateHelper.GeneralColumnInfo {
                    Header = "Id", DisplayExpression = "Id", SearchGetAccessor = "Id", FixedWidth = 90, TextAlignment = TextAlignment.Left, ToolTipBinding = "Id", TextWrapping = TextWrapping.Wrap
                },
                new ListViewDataTemplateHelper.GeneralColumnInfo {
                    Header = "File", DisplayExpression = "FileName", SearchGetAccessor = "FilePath", FixedWidth = 145, TextAlignment = TextAlignment.Left, ToolTipBinding = "FilePath", TextWrapping = TextWrapping.Wrap
                },
                new ListViewDataTemplateHelper.GeneralColumnInfo {
                    Header = "Line", DisplayExpression = "Line", SearchGetAccessor = "Line", FixedWidth = 40, TextAlignment = TextAlignment.Left, ToolTipBinding = "Line"
                },
            }, null, new string[] { "Added", "Blue", "Default", "Black" });

            ApplicationShortcut.Link(ApplicationShortcut.Copy, () => WpfUtils.CopyContent(_debugList), _debugList);

            _debugItems            = new ObservableCollection <DebugItemView>();
            _debugList.ItemsSource = _debugItems;

            DbIOErrorHandler.ClearListeners();
            DbIOErrorHandler.AddListener(this);

            _clientDatabase.PreviewReloaded += delegate {
                this.BeginDispatch(delegate {
                    foreach (TabItem tabItem in _mainTabControl.Items)
                    {
                        tabItem.IsEnabled = true;

                        var tabItemHeader = tabItem.Header as DisplayLabel;

                        if (tabItemHeader != null)
                        {
                            tabItemHeader.ResetEnabled();
                        }
                    }
                });
            };

            _clientDatabase.Reloaded += delegate {
                _mainTabControl.Dispatch(p => p.RaiseEvent(new SelectionChangedEventArgs(Selector.SelectionChangedEvent, new List <object>(), _mainTabControl.SelectedItem == null ? new List <object>() : new List <object> {
                    _mainTabControl.SelectedItem
                })));
                ServerType serverType = DbPathLocator.GetServerType();
                bool       renewal    = DbPathLocator.GetIsRenewal();
                string     header     = String.Format("Current ({0} - {1})", serverType == ServerType.RAthena ? "rA" : "Herc", renewal ? "Renewal" : "Pre-Renewal");

                this.BeginDispatch(delegate {
                    _menuItemExportDbCurrent.IsEnabled = true;
                    _menuItemExportDbCurrent.Header    = header;

                    _menuItemExportSqlCurrent.IsEnabled = true;
                    _menuItemExportSqlCurrent.Header    = header;
                });
            };

            SelectionChanged += _sdeEditor_SelectionChanged;
        }