コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: Visic/NotepadSharp
        private void CloseTopTab(string tabId, ViewModelBase vm, Action closeCallback = null)
        {
            var button = _buttonLookup[tabId];

            _buttonLookup.Remove(tabId);

            var tabIndex = TopTabs.IndexOf(button);

            TopTabs.Remove(button);
            if (TopPanelContent.Value == vm)
            {
                //select the next tab and update the top panel content
                var nextTab = TopTabs.ElementAtOrDefault(tabIndex) ?? TopTabs.ElementAtOrDefault(tabIndex - 1);
                if (nextTab == null)
                {
                    TopPanelContent.Value = null;
                }
                else
                {
                    nextTab.Command.Execute(null);
                }
            }
            closeCallback?.Invoke();

            _currentViewModels.Remove(vm);
            vm.Dispose();
        }
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: Visic/NotepadSharp
        private void AddOrSelectDocumentButton(string filePath)
        {
            ISelectableButtonViewModel button;

            if (!_buttonLookup.TryGetValue(filePath, out button))
            {
                var vm = new Lazy <DocumentViewModel>(() => NewVm(
                                                          new DocumentViewModel(
                                                              filePath,
                                                              (oldPath, newPath) => {
                    _buttonLookup.Remove(oldPath);
                    _buttonLookup[newPath] = button;
                    filePath = newPath;
                }
                                                              )
                                                          ));

                var cmd = new RelayCommand(x => TopPanelContent.Value = vm.Value);

                var closeCmd = new RelayCommand(x => {
                    if (_currentViewModels.Count(y => y is DocumentViewModel) == 1)
                    {
                        NewDocument();
                    }
                    CloseTopTab(filePath, vm.Value, vm.Value.Close);
                });

                _buttonLookup[filePath] = button = new FileTabButtonViewModel(cmd, closeCmd, vm.Value);
                TopTabs.Add(button);
            }
            button.IsSelected.Value = true;
        }
コード例 #3
0
ファイル: MainViewModel.cs プロジェクト: Visic/NotepadSharp
        private void AddOrSelectTopPanelButton(string text, Func <ViewModelBase> vmGenerator)
        {
            ISelectableButtonViewModel button;

            if (!_buttonLookup.TryGetValue(text, out button))
            {
                var vm       = new Lazy <ViewModelBase>(() => NewVm(vmGenerator()));
                var cmd      = new RelayCommand(x => TopPanelContent.Value = vm.Value);
                var closeCmd = new RelayCommand(x => CloseTopTab(text, vm.Value));
                _buttonLookup[text] = button = new SelectableCloseableButtonViewModel(text, cmd, closeCmd);
                TopTabs.Add(button);
            }
            button.IsSelected.Value = true;
        }
コード例 #4
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!filterContext.IsChildAction)
            {
                _stopStep(_betweenInitializeAndActionExecuting);
                _betweenActionExecutingAndExecuted = _startStep(nameof(OnActionExecuting));
                TopTabs.SetCurrent(filterContext.Controller.GetType());
            }

            var iSettings = SettingsModule as ModuleSettings;

            if (iSettings?.Enabled == false)
            {
                filterContext.Result = DefaultAction();
            }
            else
            {
                base.OnActionExecuting(filterContext);
            }
        }
コード例 #5
0
ファイル: MainViewModel.cs プロジェクト: Visic/NotepadSharp
 private void NewDocument()
 {
     AddOrSelectDocumentButton(UniqueNameGenerator.FirstAvailableNumbered("Untitled ", TopTabs.Select(x => x.Text.Value)));
 }
コード例 #6
0
ファイル: MainViewModel.cs プロジェクト: Visic/NotepadSharp
        public MainViewModel()
        {
            ApplicationState.SetMessageAreaText      = msg => MessageAreaText.Value = msg;
            ApplicationState.SetMessageAreaTextColor = color => MessageAreaTextColor.Value = color;
            ApplicationState.OpenDocument            = x => {
                if (!File.Exists(x))
                {
                    throw new FileNotFoundException($"File [{x}] not found.");
                }
                AddOrSelectDocumentButton(x);
            };

            AddLeftPanelToggleButton("Menu", ApplicationState.MainMenu);

            var fileExplorer = NewVm(new FileExplorerViewModel(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)));

            AddLeftPanelToggleButton(
                "Files",
                fileExplorer,
                x => fileExplorer.IsExpanded.Value = x
                );

            var newDocumentCommand = new RelayCommand(y => NewDocument());

            ApplicationState.MainMenu.SetMenuButton(
                "New File",
                new ButtonViewModel(
                    "New File",
                    newDocumentCommand
                    )
                );
            ApplicationState.NewDocument = () => newDocumentCommand.Execute(null);

            ApplicationState.MainMenu.SetMenuButton(
                "Bindings",
                new ButtonViewModel(
                    "Key Bindings",
                    new RelayCommand(x => AddOrSelectTopPanelButton("Key Bindings", () => new KeyBindingsViewModel()))
                    )
                );

            if (ArgsAndSettings.CachedFiles.Count() == 0 && string.IsNullOrEmpty(ArgsAndSettings.OpenOnStartup))  //nothing to load
            {
                newDocumentCommand.Execute(null);
            }
            else
            {
                if (!string.IsNullOrEmpty(ArgsAndSettings.OpenOnStartup))
                {
                    AddOrSelectDocumentButton(ArgsAndSettings.OpenOnStartup);
                }

                //load previously open files
                foreach (var fileInfo in ArgsAndSettings.CachedFiles.ToArray())
                {
                    AddOrSelectDocumentButton(fileInfo.OriginalFilePath ?? fileInfo.CachedFilePath);
                }
            }

            TopTabs.First().IsSelected.Value = true;
        }