/// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            IRepositoryStorageService repositoryService = Ioc.GetOrCreate <IRepositoryStorageService>();

            _scrollToNote = variables?.GetValueOrDefault(ControllerParameters.NoteId);

            RepositoryStorageLoadResult loadResult = repositoryService.LoadRepositoryOrDefault(out _);

            if (loadResult != RepositoryStorageLoadResult.InvalidRepository)
            {
                _viewModel = new NoteRepositoryViewModel(
                    Ioc.GetOrCreate <INavigationService>(),
                    Ioc.GetOrCreate <ILanguageService>(),
                    Ioc.GetOrCreate <ISvgIconService>(),
                    Ioc.GetOrCreate <IThemeService>(),
                    Ioc.GetOrCreate <IBaseUrlService>(),
                    Ioc.GetOrCreate <IStoryBoardService>(),
                    Ioc.GetOrCreate <IFeedbackService>(),
                    Ioc.GetOrCreate <ISettingsService>(),
                    Ioc.GetOrCreate <IEnvironmentService>(),
                    Ioc.GetOrCreate <ICryptoRandomService>(),
                    repositoryService);

                VueBindingShortcut[] shortcuts = new[]
                {
                    new VueBindingShortcut("s", nameof(_viewModel.SynchronizeCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("n", nameof(_viewModel.NewNoteCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("l", nameof(_viewModel.NewChecklistCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("r", nameof(_viewModel.ShowRecycleBinCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("i", nameof(_viewModel.ShowInfoCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut(VueBindingShortcut.KeyHome, "ScrollToTop")
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut(VueBindingShortcut.KeyEnd, "ScrollToBottom")
                    {
                        Ctrl = true
                    },
                };
                VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
                VueBindings.DeclareAdditionalVueMethod("ScrollToTop", "scrollToTop();");
                VueBindings.DeclareAdditionalVueMethod("ScrollToBottom", "scrollToBottom();");
                _viewModel.VueDataBindingScript        = VueBindings.BuildVueScript();
                VueBindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler;
                VueBindings.ViewLoadedEvent           += ViewLoadedEventHandler;
                VueBindings.StartListening();

                _viewModel.PropertyChanged += ViewmodelPropertyChangedEventHandler;

                string html = _viewService.GenerateHtml(_viewModel);
                View.LoadHtml(html);
            }
            else
            {
                // Show error message and stop loading the application
                _stopViewModel = new StopViewModel(
                    Ioc.GetOrCreate <INavigationService>(),
                    Ioc.GetOrCreate <ILanguageService>(),
                    Ioc.GetOrCreate <ISvgIconService>(),
                    Ioc.GetOrCreate <IThemeService>(),
                    Ioc.GetOrCreate <IBaseUrlService>());
                string html = _viewStop.GenerateHtml(_stopViewModel);
                View.LoadHtml(html);
            }
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            ISettingsService settingsService = Ioc.GetOrCreate <ISettingsService>();

            _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository);

            variables.TryGetValue(ControllerParameters.SearchFilter, out _startingSearchFilter);

            // Get the note from the repository
            Guid      noteId = new Guid(variables[ControllerParameters.NoteId]);
            NoteModel note   = noteRepository.Notes.FindById(noteId);

            ICryptor cryptor = new Cryptor(NoteModel.CryptorPackageName, Ioc.GetOrCreate <ICryptoRandomService>());

            _viewModel = new NoteViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                null,
                _repositoryService,
                Ioc.GetOrCreate <IFeedbackService>(),
                settingsService,
                cryptor,
                noteRepository.Safes,
                noteRepository.CollectActiveTags(),
                note);
            SetHtmlViewBackgroundColor(htmlView);

            VueBindingShortcut[] shortcuts = new[]
            {
                new VueBindingShortcut("f", "ToggleSearchDialogCommand")
                {
                    Ctrl = true
                },
                new VueBindingShortcut(VueBindingShortcut.KeyEscape, "CloseSearchDialogCommand"),
                new VueBindingShortcut(VueBindingShortcut.KeyHome, "ScrollToTop")
                {
                    Ctrl = true
                },
                new VueBindingShortcut(VueBindingShortcut.KeyEnd, "ScrollToBottom")
                {
                    Ctrl = true
                },
            };
            VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
            VueBindings.DeclareAdditionalVueData("PrettyTimeAgoVisible", "true");
            VueBindings.DeclareAdditionalVueData("Header1Active", "false");
            VueBindings.DeclareAdditionalVueData("Header2Active", "false");
            VueBindings.DeclareAdditionalVueData("Header3Active", "false");
            VueBindings.DeclareAdditionalVueData("BoldActive", "false");
            VueBindings.DeclareAdditionalVueData("ItalicActive", "false");
            VueBindings.DeclareAdditionalVueData("ListOrderedActive", "false");
            VueBindings.DeclareAdditionalVueData("ListBulletActive", "false");
            VueBindings.DeclareAdditionalVueData("CodeActive", "false");
            VueBindings.DeclareAdditionalVueData("QuoteActive", "false");
            VueBindings.DeclareAdditionalVueData("UnderlineActive", "false");
            VueBindings.DeclareAdditionalVueData("StrikeActive", "false");
            VueBindings.DeclareAdditionalVueMethod("ToggleSearchDialogCommand", "toggleSearchDialog();");
            VueBindings.DeclareAdditionalVueMethod("CloseSearchDialogCommand", "showSearchDialog(false);");
            VueBindings.DeclareAdditionalVueMethod("ScrollToTop", "scrollToTop();");
            VueBindings.DeclareAdditionalVueMethod("ScrollToBottom", "scrollToBottom();");
            VueBindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler;
            VueBindings.ViewLoadedEvent           += ViewLoadedEventHandler;
            _viewModel.VueDataBindingScript        = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }