Ejemplo n.º 1
0
        protected override void OnPreLoad(EventArgs e)
        {
            base.OnPreLoad(e);

            // Menu Commands
            _connect    = ToolboxApp.Services.Get <ConnectCommand>();
            _disconnect = ToolboxApp.Services.Get <DisconnectCommand>();

            var log      = ToolboxApp.Services.Get <ShowLogViewerCommand>();
            var quit     = ToolboxApp.Services.Get <QuitCommand>();
            var settings = ToolboxApp.Services.Get <SettingsCommand>();
            var onTop    = ToolboxApp.Services.Get <ToggleStayOnTopCommand>();

            _newPage = ToolboxApp.Services.Get <NewPageCommand>();
            _save    = ToolboxApp.Services.Get <SaveXamlCommand>();

            var feedback     = new FeedbackCommand();
            var update       = new UpdateCommand();
            var releaseNotes = new ReleaseNotesCommand();
            var lpac         = new LoadProjectAssembliesCommand();
            var newType      = new RegisterNewTypeCommand();
            var newView      = new RegisterNewViewCommand();

            // Styling
            _save.Enabled    = false;
            _newPage.Enabled = false;

            Title       = AppResource.Title_disconnected;
            Padding     = new Padding(5);
            Maximizable = false;
            Resizable   = true;
            Icon        = AppImages.Xf;
            ClientSize  = new Size(FormWidth, FormHeight);
            Location    = GetFormLocation();

            // Menubar
            Menu = new MenuBar
            {
                Items =
                {
                    // File
                    new ButtonMenuItem
                    {
                        Text  = AppResource.File_menu_label,
                        Items =
                        {
                            _connect,
                            _disconnect,
                            new SeparatorMenuItem(),
                            _newPage,
                            new SeparatorMenuItem(),
                            _save
                        }
                    },

                    new ButtonMenuItem
                    {
                        Text  = "&Edit",
                        Items =
                        {
                            new ButtonMenuItem {
                                Text = "&Undo", Enabled = false
                            },
                            new ButtonMenuItem {
                                Text = "&Redo", Enabled = false
                            },
                            new SeparatorMenuItem(),
                            new ButtonMenuItem {
                                Text = "&Cut", Enabled = false
                            },
                            new ButtonMenuItem {
                                Text = "&Copy", Enabled = false
                            },
                            new ButtonMenuItem {
                                Text = "&Paste", Enabled = false
                            },
                        }
                    },

                    // Tools
                    new ButtonMenuItem
                    {
                        Text  = AppResource.Tools_menu_label,
                        Items =
                        {
                            newView,
                            newType,
                            lpac,
                            new SeparatorMenuItem(),
                            settings
                        }
                    },

                    // Plugins
                    // This item will be replaced on connect & disconnect from a design server
                    new ButtonMenuItem
                    {
                        Text    = AppResource.Plugins_menu_label,
                        Enabled = false
                    },

                    // Window
                    new ButtonMenuItem
                    {
                        Text  = AppResource.Window_menu_label,
                        Items =
                        {
                            onTop,
                            new SeparatorMenuItem(),
                            new ResetViewCommand()
                        }
                    }
                },

                // Help
                HelpItems =
                {
                    feedback,
                    releaseNotes,
                    log,
                    new SeparatorMenuItem(),
                    update
                },

                QuitItem  = quit,
                AboutItem = new AboutCommand(),
            };

            ToolBar = new ToolBar
            {
                Items =
                {
                    _connect,
                    _newPage,
                    _save,
                    settings,
                    new SeparatorToolItem(),
                    onTop,
                    feedback,
                }
            };

            Application.Instance.Terminating += (s, _) => ToolboxApp.IsTerminating = true;
        }
        public MainVM()
        {
            if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
            {
                Notes = new ObservableCollection <Note>();
                Notes.Add(new Note()
                {
                    Name = "note1", DateTime = DateTime.Now.ToShortDateString()
                });
                Notes.Add(new Note()
                {
                    Name = "note2", DateTime = DateTime.Now.ToShortDateString()
                });
                Notes.Add(new Note()
                {
                    Name = "note3", DateTime = DateTime.Now.ToShortDateString()
                });

                Pages = new ObservableCollection <Page>();
                Pages.Add(new Page()
                {
                    Name = "Screenshot", DateTime = DateTime.Now.ToShortDateString()
                });
                Pages.Add(new Page()
                {
                    Name = "Screenshot", DateTime = DateTime.Now.ToShortDateString()
                });
                Pages.Add(new Page()
                {
                    Name = "Screenshot", DateTime = DateTime.Now.ToShortDateString()
                });
                IsEditingNoteName = false;
                IsEditingVocab    = false;

                Vocabs = new ObservableCollection <Vocab>();
                Vocabs.Add(new Vocab()
                {
                    PageId = 1, Word = "123", Explaination = "321", Pronounciation = "aaa"
                });
                Vocabs.Add(new Vocab()
                {
                    PageId = 1, Word = "456", Explaination = "654", Pronounciation = "bbb"
                });
                Vocabs.Add(new Vocab()
                {
                    PageId = 1, Word = "789", Explaination = "987", Pronounciation = "ccc"
                });
            }
            else
            {
                WindowState                      = System.Windows.WindowState.Normal;
                NewNoteCommand                   = new NewNoteCommand(this);
                DeleteNoteCommand                = new DeleteNoteCommand(this);
                NewPageCommand                   = new NewPageCommand(this);
                DeletePageCommand                = new DeletePageCommand(this);
                RenameNoteCommand                = new RenameNoteCommand(this);
                ScreenCapCommand                 = new ScreenCapCommand(this);
                HasEditedNoteNameCommand         = new HasEditedNoteNameCommand(this);
                UsePreviousSelectionCommand      = new UsePreviousSelectionCommand(this);
                DoNotUsePreviousSelectionCommand = new DoNotUsePreviousSelectionCommand(this);
                CheckDictionaryCommand           = new CheckDictionaryCommand(this);
                GoogleTranslateCommand           = new GoogleTranslateCommand(this);
                DeleteVocabCommand               = new DeleteVocabCommand(this);
                NewVocabCommand                  = new NewVocabCommand(this);
                StartUpdateVocabCommand          = new StartUpdateVocabCommand(this);
                EndUpdateVocabCommand            = new EndUpdateVocabCommand(this);
                CropOriginalScreenshotCommand    = new CropOriginalScreenshotCommand(this);
                NewPageViaScreenshotCommand      = new NewPageViaScreenshotCommand(this);
                CaptureMoreTextCommand           = new CaptureMoreTextCommand(this);
                StartRenamePageCommand           = new StartRenamePageCommand(this);
                EndRenamePageCommand             = new EndRenamePageCommand(this);
                ToggleUpdateVocabCommand         = new ToggleUpdateVocabCommand(this);
                CheckDictionaryLittleDCommand    = new CheckDictionaryLittleDCommand(this);
                SyncVocabsCommand                = new SyncVocabsCommand(this);

                Notes  = new ObservableCollection <Note>();
                Pages  = new ObservableCollection <Page>();
                Vocabs = new ObservableCollection <Vocab>();
                ReadNotes();
                ReadPages();
                IsEditingNoteName              = false;
                IsEditingVocab                 = false;
                DisplayIndex                   = 0;
                DoUsePreviousSelection         = false;
                browserAddress                 = "";
                DictionaryBaseUrl_JapanDict    = "https://www.japandict.com/";
                DictionaryBaseUrl_littleD      = "http://dict.hjenglish.com/jp/jc/";
                SelectedPageIndex              = 0;
                NoPreviousCropButtonIsSelected = true;
                IsRenamingPage                 = false;
            }
        }