private void ShowFindReplaceDialog(bool showFind = true) { if (ActiveDocument is EdiViewModel) { EdiViewModel f = ActiveDocument as EdiViewModel; Window dlg = null; try { if (FindReplaceVm == null) { FindReplaceVm = new FindReplaceViewModel(_SettingsManager, _MsgBox); } FindReplaceVm.FindNext = FindNext; // determine whether Find or Find/Replace is to be executed FindReplaceVm.ShowAsFind = showFind; if (f.TxtControl != null) // Search by default for currently selected text (if any) { string textToFind; f.TxtControl.GetSelectedText(out textToFind); if (textToFind.Length > 0) { FindReplaceVm.TextToFind = textToFind; } } FindReplaceVm.CurrentEditor = f; dlg = ViewSelector.GetDialogView(FindReplaceVm, Application.Current.MainWindow); dlg.Closing += FindReplaceVm.OnClosing; dlg.ShowDialog(); } catch (Exception exc) { _MsgBox.Show(exc, Util.Local.Strings.STR_MSG_FIND_UNEXPECTED_ERROR, MsgBoxButtons.OK, MsgBoxImage.Error); } finally { if (dlg != null) { dlg.Closing -= FindReplaceVm.OnClosing; dlg.Close(); } } } }
private void OnToggleEditorOption(object parameter) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f == null) { return; } if (parameter == null) { return; } if ((parameter is ToggleEditorOption) == false) { return; } ToggleEditorOption t = (ToggleEditorOption)parameter; if (f != null) { switch (t) { case ToggleEditorOption.WordWrap: f.WordWrap = !f.WordWrap; break; case ToggleEditorOption.ShowLineNumber: f.ShowLineNumbers = !f.ShowLineNumbers; break; case ToggleEditorOption.ShowSpaces: f.TextOptions.ShowSpaces = !f.TextOptions.ShowSpaces; break; case ToggleEditorOption.ShowTabs: f.TextOptions.ShowTabs = !f.TextOptions.ShowTabs; break; case ToggleEditorOption.ShowEndOfLine: f.TextOptions.ShowEndOfLine = !f.TextOptions.ShowEndOfLine; break; default: break; } } }
/// <summary> /// Gets the current line in which the cursor is currently located /// </summary> /// <param name="f"></param> /// <returns></returns> private static int GetCurrentEditorLine(EdiViewModel f) { int iCurrLine = 0; try { int start, length; bool IsRectangularSelection = false; f.TxtControl.CurrentSelection(out start, out length, out IsRectangularSelection); iCurrLine = f.Document.GetLineByOffset(start).LineNumber; } catch (Exception) { } return(iCurrLine); }
private void ShowGotoLineDialog() { if (ActiveDocument is EdiViewModel) { EdiViewModel f = ActiveDocument as EdiViewModel; Window dlg = null; Dialogs.GotoLine.GotoLineViewModel dlgVm = null; try { int iCurrLine = GetCurrentEditorLine(f); dlgVm = new Dialogs.GotoLine.GotoLineViewModel(1, f.Document.LineCount, iCurrLine); dlg = ViewSelector.GetDialogView(dlgVm, Application.Current.MainWindow); dlg.Closing += dlgVm.OnClosing; dlg.ShowDialog(); // Copy input if user OK'ed it. This could also be done by a method, equality operator, or copy constructor if (dlgVm.WindowCloseResult == true) { DocumentLine line = f.Document.GetLineByNumber(dlgVm.LineNumber); f.TxtControl.SelectText(line.Offset, 0); // Select text with length 0 and scroll to where f.TxtControl.ScrollToLine(dlgVm.LineNumber); // we are supposed to be at } } catch (Exception exc) { _MsgBox.Show(exc, Util.Local.Strings.STR_MSG_FIND_UNEXPECTED_ERROR, MsgBoxButtons.OK, MsgBoxImage.Error); } finally { if (dlg != null) { dlg.Closing -= dlgVm.OnClosing; dlg.Close(); } } } }
private IEditor GetNextEditor(FindReplaceViewModel f, bool previous = false ) { // There is no next open document if there is none or only one open if (this.Files.Count <= 1) { return(f.GetCurrentEditor()); } // There is no next open document If the user wants to search the current document only if (f.SearchIn == Edi.Dialogs.FindReplace.SearchScope.CurrentDocument) { return(f.GetCurrentEditor()); } var l = new List <object>(this.Files.Cast <object>()); int idxStart = l.IndexOf(f.CurrentEditor); int i = idxStart; if (i >= 0) { Match m = null; bool textSearchSuccess = false; do { if (previous == true) // Get next/previous document { i = (i < 1 ? l.Count - 1 : i - 1); } else { i = (i >= l.Count - 1 ? 0 : i + 1); } //// i = (i + (previous ? l.Count - 1 : +1)) % l.Count; // Search text in document if (l[i] is EdiViewModel) { EdiViewModel fTmp = l[i] as EdiViewModel; Regex r; m = this.FindNextMatchInText(0, 0, false, fTmp.Text, ref f, out r); textSearchSuccess = m.Success; } }while (i != idxStart && textSearchSuccess != true); // Found a match so activate the corresponding document and select the text with scroll into view if (textSearchSuccess == true && m != null) { var doc = l[i] as EdiViewModel; if (doc != null) { this.ActiveDocument = doc; } // Ensure that no pending calls are in the dispatcher queue // This makes sure that we are blocked until bindings are re-established // Bindings are required to scroll a selection into view Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action) delegate { if (this.ActiveDocument != null && doc != null) { doc.TextEditorSelectionStart = m.Index; doc.TextEditorSelectionLength = m.Length; // Reset cursor position to make sure we search a document from its beginning doc.TxtControl.SelectText(m.Index, m.Length); f.CurrentEditor = l[i] as IEditor; IEditor edi = f.GetCurrentEditor(); if (edi != null) { edi.Select(m.Index, m.Length); } } }); return(f.GetCurrentEditor()); } } return(null); }
/// <summary> /// Set command bindings necessary to perform copy/cut/paste operations /// </summary> /// <param name="win"></param> public void InitEditCommandBinding(Window win) { win.CommandBindings.Add(new CommandBinding(AppCommand.DisableHighlighting, // Select all text in a document (s, e) => { try { if (this.ActiveDocument is EdiViewModel) { EdiViewModel f = this.ActiveDocument as EdiViewModel; f.DisableHighlighting(); } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { if (this.ActiveDocument is EdiViewModel) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f.HighlightingDefinition != null) { e.CanExecute = true; return; } } e.CanExecute = false; })); #region GotoLine FindReplace win.CommandBindings.Add(new CommandBinding(AppCommand.GotoLine, // Goto line n in a document (s, e) => { try { e.Handled = true; this.ShowGotoLineDialog(); } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsEdiViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.FindText, // Find text in a document (s, e) => { try { e.Handled = true; this.ShowFindReplaceDialog(); } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsEdiViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.FindPreviousText, // Find text in a document (s, e) => { try { e.Handled = true; if (this.ActiveDocument is EdiViewModel) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (this.FindReplaceVM != null) { this.FindReplaceVM.FindNext(this.FindReplaceVM, true); } else { this.ShowFindReplaceDialog(); } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsEdiViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.FindNextText, // Find text in a document (s, e) => { try { e.Handled = true; if (this.ActiveDocument is EdiViewModel) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (this.FindReplaceVM != null) { this.FindReplaceVM.FindNext(this.FindReplaceVM, false); } else { this.ShowFindReplaceDialog(); } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsEdiViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.ReplaceText, // Find and replace text in a document (s, e) => { try { e.Handled = true; this.ShowFindReplaceDialog(false); } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsEdiViewModel(); })); #endregion GotoLine FindReplace }
/// <summary> /// Bind a window to some commands to be executed by the viewmodel. /// </summary> /// <param name="win"></param> public void InitCommandBinding(Window win) { this.InitEditCommandBinding(win); win.CommandBindings.Add(new CommandBinding(AppCommand.Exit, (s, e) => { this.AppExit_CommandExecuted(); e.Handled = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.About, (s, e) => { this.AppAbout_CommandExecuted(); e.Handled = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.ProgramSettings, (s, e) => { this.AppProgramSettings_CommandExecuted(); e.Handled = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.ShowToolWindow, (s, e) => { if (e == null) { return; } var toolwindowviewmodel = e.Parameter as IToolWindow; if (toolwindowviewmodel == null) { return; } if (toolwindowviewmodel is IRegisterableToolWindow) { IRegisterableToolWindow registerTW = toolwindowviewmodel as IRegisterableToolWindow; registerTW.SetToolWindowVisibility(this, !toolwindowviewmodel.IsVisible); } else { toolwindowviewmodel.SetToolWindowVisibility(!toolwindowviewmodel.IsVisible); } e.Handled = true; })); // Standard File New command binding via ApplicationCommands enumeration win.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, (s, e) => { TypeOfDocument t = TypeOfDocument.EdiTextEditor; if (e != null) { e.Handled = true; if (e.Parameter != null) { if (e.Parameter is TypeOfDocument) { t = (TypeOfDocument)e.Parameter; } } } this.OnNew(t); } )); // Standard File Open command binding via ApplicationCommands enumeration win.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, (s, e) => { string t = string.Empty; if (e != null) { if (e.Parameter != null) { if (e.Parameter is string) { t = (string)e.Parameter; } } } this.OnOpen(t); e.Handled = true; } )); // Close Document command // Closes the FileViewModel document supplied in e.parameter // or the Active document win.CommandBindings.Add(new CommandBinding(AppCommand.CloseFile, (s, e) => { try { FileBaseViewModel f = null; if (e != null) { e.Handled = true; f = e.Parameter as FileBaseViewModel; } if (f != null) { this.Close(f); } else { if (this.ActiveDocument != null) { this.Close(this.ActiveDocument); } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { try { if (e != null) { e.Handled = true; e.CanExecute = false; EdiViewModel f = null; if (e != null) { e.Handled = true; f = e.Parameter as EdiViewModel; } if (f != null) { e.CanExecute = f.CanClose(); } else { if (this.ActiveDocument != null) { e.CanExecute = this.ActiveDocument.CanClose(); } } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } })); // Change the WPF/TextEditor highlighting theme currently used in the application win.CommandBindings.Add(new CommandBinding(AppCommand.ViewTheme, (s, e) => this.ChangeThemeCmd_Executed(s, e, win.Dispatcher))); win.CommandBindings.Add(new CommandBinding(AppCommand.BrowseURL, (s, e) => { Process.Start(new ProcessStartInfo("https://github.com/Dirkster99/Edi")); })); win.CommandBindings.Add(new CommandBinding(AppCommand.ShowStartPage, (s, e) => { StartPageViewModel spage = this.GetStartPage(true); if (spage != null) { logger.InfoFormat("TRACE Before setting startpage as ActiveDocument"); this.ActiveDocument = spage; logger.InfoFormat("TRACE After setting startpage as ActiveDocument"); } })); win.CommandBindings.Add(new CommandBinding(AppCommand.ToggleOptimizeWorkspace, (s, e) => { logger.InfoFormat("TRACE AppCommand.ToggleOptimizeWorkspace parameter is {0}.", (e == null ? "(null)" : e.ToString())); try { var newViewSetting = !this.IsWorkspaceAreaOptimized; this.IsWorkspaceAreaOptimized = newViewSetting; } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } })); win.CommandBindings.Add(new CommandBinding(AppCommand.LoadFile, (s, e) => { try { logger.InfoFormat("TRACE AppCommand.LoadFile parameter is {0}.", (e == null ? "(null)" : e.ToString())); if (e == null) { return; } string filename = e.Parameter as string; if (filename == null) { return; } logger.InfoFormat("TRACE AppCommand.LoadFile with: '{0}'", filename); this.Open(filename); } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } })); win.CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, (s, e) => { try { if (e != null) { e.Handled = true; } if (this.ActiveDocument != null) { this.OnSave(this.ActiveDocument, false); } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_UnknownError_Caption, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { if (e != null) { e.Handled = true; if (this.ActiveDocument != null) { e.CanExecute = this.ActiveDocument.CanSave(); } } })); win.CommandBindings.Add(new CommandBinding(ApplicationCommands.SaveAs, (s, e) => { try { if (e != null) { e.Handled = true; } if (this.ActiveDocument != null) { if (this.OnSave(this.ActiveDocument, true)) { var mruList = ServiceLocator.Current.GetInstance <IMRUListViewModel>(); mruList.UpdateEntry(this.ActiveDocument.FilePath); this.mSettingsManager.SessionData.LastActiveFile = this.ActiveDocument.FilePath; } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { try { if (e != null) { e.Handled = true; e.CanExecute = false; if (this.ActiveDocument != null) { e.CanExecute = this.ActiveDocument.CanSaveAs(); } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } } )); // Execute a command to save all edited files and current program settings win.CommandBindings.Add(new CommandBinding(AppCommand.SaveAll, (s, e) => { try { // Save all edited documents if (this.mFiles != null) // Close all open files and make sure there are no unsaved edits { // If there are any: Ask user if edits should be saved IFileBaseViewModel activeDoc = this.ActiveDocument; try { for (int i = 0; i < this.Files.Count; i++) { IFileBaseViewModel f = this.Files[i]; if (f != null) { if (f.IsDirty == true && f.CanSaveData == true) { this.ActiveDocument = f; this.OnSave(f); } } } } catch (Exception exp) { _MsgBox.Show(exp.ToString(), Edi.Util.Local.Strings.STR_MSG_UnknownError_Caption, MsgBoxButtons.OK); } finally { if (activeDoc != null) { this.ActiveDocument = activeDoc; } } } // Save program settings this.SaveConfigOnAppClosed(); } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } })); // Execute a command to export UML editor content as image win.CommandBindings.Add(new CommandBinding(AppCommand.ExportUMLToImage, (s, e) => { try { if (this.vm_DocumentViewModel != null) { if ((this.vm_DocumentViewModel.dm_DocumentDataModel.State == DataModel.ModelState.Ready) == true) { this.vm_DocumentViewModel.ExecuteExport(s, e, this.ActiveDocument.FileName + ".png"); } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => // Execute this command only if an UML document is currently active { if (this.vm_DocumentViewModel != null) { e.CanExecute = (this.vm_DocumentViewModel.dm_DocumentDataModel.State == DataModel.ModelState.Ready); } else { e.CanExecute = false; } } )); // Execute a command to export Text editor content as highlighted image content win.CommandBindings.Add(new CommandBinding(AppCommand.ExportTextToHTML, (s, e) => { try { if (this.ActiveEdiDocument != null) { this.ActiveEdiDocument.ExportToHTML(this.ActiveDocument.FileName + ".html", this.mSettingsManager.SettingData.TextToHTML_ShowLineNumbers, this.mSettingsManager.SettingData.TextToHTML_AlternateLineBackground); } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => // Execute this command only if a Text document is currently active { if (this.ActiveEdiDocument != null) { e.CanExecute = true; } else { e.CanExecute = false; } } )); /// <summary> /// Removes ALL MRU entries (even pinned entries) from the current list of entries. /// </summary> win.CommandBindings.Add(new CommandBinding(AppCommand.ClearAllMruItemsCommand, (s, e) => { this.GetToolWindowVM <RecentFilesViewModel>().MruList.Clear(); })); /// <summary> /// Gets a command that removes all items that are older /// than a given <see cref="GroupType"/>. /// Eg.: Remove all MRU entries older than yesterday. /// </summary> win.CommandBindings.Add(new CommandBinding(AppCommand.RemoveItemsOlderThanThisCommand, (s, e) => { if (e.Parameter is GroupType == false) { return; } var param = (GroupType)e.Parameter; this.GetToolWindowVM <RecentFilesViewModel>().MruList.RemoveEntryOlderThanThis(param); }, (s, e) => { if (e.Parameter is GroupType == false) { e.CanExecute = false; return; } e.CanExecute = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.MovePinnedMruItemUPCommand, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { return; } var param = e.Parameter as IMRUEntryViewModel; this.GetToolWindowVM <RecentFilesViewModel>().MruList.MovePinnedEntry(MoveMRUItem.Up, param); }, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { e.CanExecute = false; return; } if ((e.Parameter as IMRUEntryViewModel).IsPinned == 0) //Make sure it is pinned { e.CanExecute = false; return; } e.CanExecute = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.MovePinnedMruItemDownCommand, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { return; } var param = e.Parameter as IMRUEntryViewModel; this.GetToolWindowVM <RecentFilesViewModel>().MruList.MovePinnedEntry(MoveMRUItem.Down, param); }, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { e.CanExecute = false; return; } if ((e.Parameter as IMRUEntryViewModel).IsPinned == 0) //Make sure it is pinned { e.CanExecute = false; return; } e.CanExecute = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.PinItemCommand, (s, e) => { this.GetToolWindowVM <RecentFilesViewModel>().MruList.PinUnpinEntry(true, e.Parameter as IMRUEntryViewModel); }, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { e.CanExecute = false; return; } if ((e.Parameter as IMRUEntryViewModel).IsPinned == 0) //Make sure it is pinned { e.CanExecute = true; return; } e.CanExecute = false; })); win.CommandBindings.Add(new CommandBinding(AppCommand.UnPinItemCommand, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { return; } var param = e.Parameter as IMRUEntryViewModel; this.GetToolWindowVM <RecentFilesViewModel>().MruList.PinUnpinEntry(false, e.Parameter as IMRUEntryViewModel); }, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { e.CanExecute = false; return; } if ((e.Parameter as IMRUEntryViewModel).IsPinned == 0) //Make sure it is pinned { e.CanExecute = false; return; } e.CanExecute = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.PinUnpin, (s, e) => { this.PinCommand_Executed(e.Parameter, e); })); win.CommandBindings.Add(new CommandBinding(AppCommand.RemoveMruEntry, (s, e) => { this.RemoveMRUEntry_Executed(e.Parameter, e); })); win.CommandBindings.Add(new CommandBinding(AppCommand.AddMruEntry, (s, e) => { this.AddMRUEntry_Executed(e.Parameter, e); })); }