internal bool Close(EdiViewModel fileToClose) { try { if (this.OnCloseSaveDirtyFile(fileToClose) == false) { return(false); } mFiles.Remove(fileToClose); if (this.mFiles.Count == 0) { this.ActiveDocument = null; } else { this.ActiveDocument = this.mFiles[0]; } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, "Unhandled Error", MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } return(true); }
private void Redirect(StreamReader input, EdiViewModel output) { var sb = new StringBuilder(); var bg = new Thread(a => { var buffer = new char[1]; while (input.Read(buffer, 0, 1) > 0) { output.Document.TextEditor.Dispatcher.Invoke(new Action(delegate { if (buffer[0] != '\0') { sb.Append(new string(buffer)); } if (buffer[0] == '\r' || buffer[0] == '\n' && sb.Length > 0) { output.Document.Insert(output.Document.Text.Length, sb.ToString()); sb.Clear(); } })); } }); bg.Start(); }
internal EdiViewModel LoadOutputWindow(string fileName = "") { // Don't need to load output window when output.js is opening if (IsOutputFile(fileName)) { return(null); } var firstPanel = FindFirstLayoutDocumentPane(Win.dockManager.Layout.RootPanel); var paneGroup = firstPanel.Parent as LayoutDocumentPaneGroup; if (paneGroup == null) { return(null); } var vm = this.mFiles.FirstOrDefault(x => IsOutputFile(x.FileName)); if (vm == null) { string outFilePath = GetOutFilePath(); vm = EdiViewModel.LoadFile(outFilePath); this.mFiles.Add(vm); var outputContent = firstPanel.Children.Last(); var layOutPanel = paneGroup.Parent as LayoutPanel; if (layOutPanel != null) { var newPane = new LayoutDocumentPane(outputContent); paneGroup.InsertChildAt(1, newPane); } } return(vm); }
public static EdiViewModel LoadFile(string filePath) { bool IsFilePathReal = false; try { IsFilePathReal = File.Exists(filePath); } catch { } if (IsFilePathReal == false) { return(null); } EdiViewModel vm = new EdiViewModel(); if (vm.OpenFile(filePath) == true) { return(vm); } return(null); }
private void ShowGotoLineDialog() { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { Window dlg = null; Edi.View.Dialogs.GotoLine.GotoLineViewModel dlgVM = null; try { int iCurrLine = Workspace.GetCurrentEditorLine(f); dlgVM = new Edi.View.Dialogs.GotoLine.GotoLineViewModel(1, f.Document.LineCount, iCurrLine); dlg = ViewSelector.GetDialogView((object)dlgVM); // It is important to either: // 1> Use the InitDialogInputData methode here or // 2> Reset the WindowCloseResult=null property // because otherwise ShowDialog will not work twice // (Symptom: The dialog is closed immeditialy by the attached behaviour) dlgVM.InitDialogInputData(); dlg.DataContext = dlgVM; dlg.Closing += dlgVM.OpenCloseView.OnClosing; dlg.Owner = Application.Current.MainWindow; // Make sure that dialog window appears in front of main window dlg.ShowDialog(); // Copy input if user OK'ed it. This could also be done by a method, equality operator, or copy constructor if (((Edi.View.Dialogs.GotoLine.GotoLineViewModel)dlg.DataContext).OpenCloseView.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) { Edi.Msg.Box.Show(exc, "An unexpected error occured.", MsgBoxButtons.OK, MsgBoxImage.Error); } finally { if (dlg != null) { dlg.Closing -= dlgVM.OpenCloseView.OnClosing; dlg.Close(); } } } }
private bool CanExecuteIfActiveDocumentIsFileViewModel() { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { return(true); } return(false); }
/// <summary> /// Reset file view options in accordance with current program settings /// whenever a new file is internally created (on File Open or New File) /// </summary> /// <param name="vm"></param> private void SetActiveDocumentOnNewFileOrOpenFile(ref EdiViewModel vm) { try { // Set scale factor in default size of text font vm.FontSize.SelectedFontSizeCompute(this.Config.DocumentZoomView); ActiveDocument = vm; } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, "Unhandled Error", MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }
private void OnNew() { try { var vm = new EdiViewModel(); this.mFiles.Add(vm); SetActiveDocumentOnNewFileOrOpenFile(ref vm); LoadOutputWindow(); } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, "Unhandled Error", MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }
/// <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); }
internal bool OnRunScript(EdiViewModel fileToRun, bool saveAsFlag = true) { var target = new MongoTarget(); var start = new ProcessStartInfo(); var vm = ShowOutput(); vm.Document.Text = ""; if (vm.Document.TextEditor == null) { MessageBox.Show("Output window was not open, can't redirect output.\nPlease try again.", "Status", MessageBoxButton.OK, MessageBoxImage.Exclamation); return(false); } if (!Directory.Exists(target.Directory)) { MessageBox.Show("Mongo bin directory was not found.\nPlease configure path in app.config.", "Status", MessageBoxButton.OK, MessageBoxImage.Exclamation); return(false); } if (IsOutputFile(fileToRun.FileName)) { MessageBox.Show("Please selct script to run.", "Status", MessageBoxButton.OK, MessageBoxImage.Exclamation); return(false); } start.FileName = target.Executable; start.Arguments = target.Arguments + "\"" + fileToRun.FilePath + "\""; start.WorkingDirectory = target.Directory; start.UseShellExecute = false; start.CreateNoWindow = target.CreateNoWindow; start.RedirectStandardOutput = true; using (var process = Process.Start(start)) { if (process != null) { Redirect(process.StandardOutput, vm); } } return(true); }
/// <summary> /// Open a file supplied in <paramref name="filePath"/> (without displaying a file open dialog). /// </summary> /// <param name="filePath">file to open</param> /// <param name="AddIntoMRU">indicate whether file is to be added into MRU or not</param> /// <returns></returns> public EdiViewModel Open(string filePath, bool AddIntoMRU = true) { // Verify whether file is already open in editor, and if so, show it var fileViewModel = mFiles.FirstOrDefault(fm => fm.FilePath == filePath); if (fileViewModel != null) { this.ActiveDocument = fileViewModel; // File is already open so shiw it return(fileViewModel); } // try to load the file from file system fileViewModel = EdiViewModel.LoadFile(filePath); if (fileViewModel == null) { if (this.Config.MruList.FindMRUEntry(filePath) != null) { if (Edi.Msg.Box.Show(string.Format(CultureInfo.CurrentCulture, "The file:\n\n'{0}'\n\ndoes not exist or cannot be loaded.\n\nDo you want to remove this file from the list of recent files?", filePath), "Error Loading file", MsgBoxButtons.YesNo) == MsgBoxResult.Yes) { this.Config.MruList.RemoveEntry(filePath); } } return(null); } mFiles.Add(fileViewModel); // reset viewmodel options in accordance to current program settings SetActiveDocumentOnNewFileOrOpenFile(ref fileViewModel); if (AddIntoMRU == true) { this.RecentFiles.AddNewEntryIntoMRU(filePath); } LoadOutputWindow(fileViewModel.FileName); return(fileViewModel); }
/// <summary> /// Check if pre-requisites for closing application are available. /// Save session data on closing and cancel closing process if necessary. /// </summary> /// <returns>true if application is OK to proceed closing with closed, otherwise false.</returns> internal bool Exit_CheckConditions(object sender) { if (this.mShutDownInProgress == true) { return(true); } try { try { App.CreateAppDataFolder(); this.SerializeLayout(sender); // Store the current layout for later retrieval } catch { } 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 for (int i = 0; i < this.mFiles.Count; i++) { EdiViewModel f = this.mFiles[i]; if (this.OnCloseSaveDirtyFile(f) == false) { this.mShutDownInProgress = false; return(false); // Cancel shutdown process (return false) if user cancels saving edits } } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, "Unhandled Error", MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } return(true); }
internal bool OnCloseSaveDirtyFile(EdiViewModel fileToClose) { if (fileToClose.IsDirty && fileToClose.FileName != outFileName) { var res = Edi.Msg.Box.Show(string.Format(CultureInfo.CurrentCulture, "Save changes for file '{0}'?", fileToClose.FileName), this.ApplicationTitle, MsgBoxButtons.YesNoCancel, MsgBoxImage.Question, MsgBoxResult.Yes); if (res == MsgBoxResult.Cancel) { return(false); } if (res == MsgBoxResult.Yes) { return(OnSave(fileToClose)); } } return(true); }
/// <summary> /// Set the active document to the file in <seealso cref="fileNamePath"/> /// if this is currently open. /// </summary> /// <param name="fileNamePath"></param> internal bool SetActiveDocument(string fileNamePath) { try { if (this.Files.Count >= 0) { EdiViewModel fi = this.Files.SingleOrDefault(f => f.FilePath == fileNamePath); if (fi != null && !IsOutputFile(fi.FileName)) { this.ActiveDocument = fi; return(true); } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, "Unhandled Error", MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } return(false); }
private void ShowFindReplaceDialog(bool ShowFind = true) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { Window dlg = null; try { if (this.FindReplaceVM == null) { this.FindReplaceVM = new Edi.View.Dialogs.FindReplace.FindReplaceViewModel(); } this.FindReplaceVM.FindNext = this.FindNext; // determine whether Find or Find/Replace is to be executed this.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) { this.FindReplaceVM.TextToFind = textToFind; } } this.FindReplaceVM.CurrentEditor = f; dlg = ViewSelector.GetDialogView((object)this.FindReplaceVM); // It is important to either: // 1> Use the InitDialogInputData methode here or // 2> Reset the WindowCloseResult=null property // because otherwise ShowDialog will not work twice // (Symptom: The dialog is closed immeditialy by the attached behaviour) this.FindReplaceVM.InitDialogInputData(); dlg.DataContext = this.FindReplaceVM; dlg.Closing += this.FindReplaceVM.OpenCloseView.OnClosing; dlg.Owner = Application.Current.MainWindow; // Make sure that dialog window appears in front of main window dlg.ShowDialog(); } catch (Exception exc) { Edi.Msg.Box.Show(exc, "An unexpected error occured.", MsgBoxButtons.OK, MsgBoxImage.Error); } finally { if (dlg != null) { dlg.Closing -= this.FindReplaceVM.OpenCloseView.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 == EdiViews.FindReplace.SearchScope.CurrentDocument) { return(f.GetCurrentEditor()); } List <object> 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; EdiViewModel fTmp = l[i] as EdiViewModel; // Search text in document if (fTmp != null) { 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) { this.ActiveDocument = l[i] as EdiViewModel; // 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) { this.ActiveDocument.TextEditorSelectionStart = m.Index; this.ActiveDocument.TextEditorSelectionLength = m.Length; // Reset cursor position to make sure we search a document from its beginning this.ActiveDocument.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> /// 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(); })); // Standard File New command binding via ApplicationCommands enumeration win.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, (s, e) => { if (e != null) { e.Handled = true; } this.OnNew(); }, (s, e) => { e.CanExecute = true; } )); // Standard File Open command binding via ApplicationCommands enumeration win.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, (s, e) => { if (e != null) { e.Handled = true; } this.OnOpen(); }, (s, e) => { e.CanExecute = 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 { EdiViewModel f = null; if (e != null) { e.Handled = true; f = e.Parameter as EdiViewModel; } if (f != null) { this.Close(f); } else { if (this.ActiveDocument != null) { this.Close(this.ActiveDocument); } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.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.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } })); win.CommandBindings.Add(new CommandBinding(AppCommand.ViewTheme, (s, e) => this.ChangeThemeCmd_Executed(s, e, win.Dispatcher))); win.CommandBindings.Add(new CommandBinding(AppCommand.LoadFile, (s, e) => { try { if (e == null) { return; } string filename = e.Parameter as string; if (filename == null) { return; } this.Open(filename); } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.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.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, "Unhandled Error", MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.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.ActiveDocument.OnSaveAs() == true) { this.Config.MruList.AddMRUEntry(this.ActiveDocument.FilePath); } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.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.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.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 EdiViewModel activeDoc = this.ActiveDocument; try { for (int i = 0; i < this.mFiles.Count; i++) { EdiViewModel f = this.mFiles[i]; if (f != null) { if (f.IsDirty == true) { this.ActiveDocument = f; this.OnSave(f); } } } } catch (Exception exp) { Edi.Msg.Box.Show(exp.ToString(), "An error occurred", MsgBoxButtons.OK); } finally { if (activeDoc != null) { this.ActiveDocument = activeDoc; } } } // Save program settings this.SaveConfigOnAppClosed(); } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, 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); })); win.CommandBindings.Add(new CommandBinding(AppCommand.AddMruEntry, (s, e) => { try { if (e != null) { e.Handled = true; } if (this.ActiveDocument != null) { this.OnSave(this.ActiveDocument, false); } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, "Unhandled Error", MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { if (e != null) { e.Handled = true; if (this.ActiveDocument != null) { e.CanExecute = this.ActiveDocument.CanSave(); } } })); }
internal bool OnSave(EdiViewModel fileToSave, bool saveAsFlag = false) { string filePath = (fileToSave == null ? string.Empty : fileToSave.FilePath); // Offer SaveAs file dialog if file has never been saved before (was created with new command) if (fileToSave != null) { saveAsFlag = saveAsFlag | !fileToSave.IsFilePathReal; } try { if (filePath == string.Empty || saveAsFlag == true) // Execute SaveAs function { var dlg = new SaveFileDialog(); try { dlg.FileName = System.IO.Path.GetFileName(filePath); } catch { } dlg.InitialDirectory = this.GetDefaultPath(); if (dlg.ShowDialog().GetValueOrDefault() == true) // SaveAs file if user OK'ed it so { filePath = dlg.FileName; fileToSave.SaveFile(filePath); } else { return(false); } } else // Execute Save function { fileToSave.SaveFile(filePath); } this.RecentFiles.AddNewEntryIntoMRU(filePath); return(true); } catch (Exception Exp) { string sMsg = "An unexpected problem has occurred while saving the file"; if (filePath.Length > 0) { sMsg = string.Format(CultureInfo.CurrentCulture, "'{0}'\n" + "has occurred while saving the file\n:'{1}'", Exp.Message, filePath); } else { sMsg = string.Format(CultureInfo.CurrentCulture, "'{0}'\n" + "has occurred while saving a file", Exp.Message); } Edi.Msg.Box.Show(sMsg, "An unexpected problem has occurred while saving the file", MsgBoxButtons.OK); } return(false); }
/// <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.CutItem, * (s, e) => * { * PerformTextAreaEdit(e, TextAreaEdit.Cut); * }, * (s, e) => { CanPerformTextAreaEdit(e, TextAreaEdit.Cut); })); * * win.CommandBindings.Add(new CommandBinding(AppCommand.CopyItem, * (s, e) => * { * PerformTextAreaEdit(e, TextAreaEdit.Copy); * }, * (s, e) => * { CanPerformTextAreaEdit(e, TextAreaEdit.Copy); })); * * win.CommandBindings.Add(new CommandBinding(AppCommand.PasteItem, * (s, e) => * { * PerformTextAreaEdit(e, TextAreaEdit.Paste); * }, * (s, e) => { CanPerformTextAreaEdit(e, TextAreaEdit.Paste); })); * * win.CommandBindings.Add(new CommandBinding(AppCommand.DeleteItem, * (s, e) => * { * PerformTextAreaEdit(e, TextAreaEdit.Delete); * }, * (s, e) => { CanPerformTextAreaEdit(e, TextAreaEdit.Delete); })); ***/ win.CommandBindings.Add(new CommandBinding(AppCommand.WordWrap, // Toggle state command, (s, e) => { try { if (e != null) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { f.WordWrap = !f.WordWrap; } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.ShowLineNumbers, // Toggle state command, (s, e) => { try { if (e != null) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { f.ShowLineNumbers = !f.ShowLineNumbers; } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.ShowEndOfLine, // Toggle state command, (s, e) => { try { if (e != null) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { f.ShowEndOfLine = !f.ShowEndOfLine; } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.ShowTabs, // Toggle state command, (s, e) => { try { if (e != null) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { f.ShowTabs = !f.ShowTabs; } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.ShowSpaces, // Toggle state command, (s, e) => { try { if (e != null) { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { f.ShowSpaces = !f.ShowSpaces; } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.SelectAll, // Select all text in a document (s, e) => { try { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { f.TxtControl.SelectAllText(); } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); /**** * /// <summary> * /// TextArea edit function to be performed on a <seealso cref="ICSharpCode.AvalonEdit.Editing.TextArea"/> view object. * /// </summary> * private enum TextAreaEdit * { * Copy=0, * Cut=1, * Paste=2, * Delete=3 * } * * /// <summary> * /// Perform an edit function (Copy, Pase, Cut, Delete) on an * /// <seealso cref="ICSharpCode.AvalonEdit.Editing.TextArea"/> view object. * /// </summary> * /// <param name="e"></param> * /// <param name="performEdit"></param> * private void PerformTextAreaEdit(ExecutedRoutedEventArgs e, TextAreaEdit performEdit) * { * if (e == null) * return; * * DockingManager dockManager = e.Parameter as DockingManager; * * if (dockManager == null) * return; * * // Some AvalonEdit functions (Cut, Copy, Paste etc) require finding the View and * // Executing code directly on the view. * // * // I am not sure how to find the currently used AvalonEdit TextArea view from here: * // Question: Does dockManager have an API to return the currently active visual? * // * // Using VisualTreeHelper on dockManager does work if the document is docked * // * // Issues: Undock your text document and this does no longer work (What should we do instead?): * ICSharpCode.AvalonEdit.Editing.TextArea textArea = Helpers.FindFocusedElement(dockManager) as ICSharpCode.AvalonEdit.Editing.TextArea; * * if (textArea == null) * return; * * switch (performEdit) * { * case TextAreaEdit.Copy: * ICSharpCode.AvalonEdit.Editing.EditingCommandHandler.OnCopy(textArea, e); * break; * case TextAreaEdit.Cut: * ICSharpCode.AvalonEdit.Editing.EditingCommandHandler.OnCut(textArea, e); * break; * case TextAreaEdit.Paste: * ICSharpCode.AvalonEdit.Editing.EditingCommandHandler.OnPaste(textArea, e); * break; * case TextAreaEdit.Delete: * ICSharpCode.AvalonEdit.Editing.EditingCommandHandler.OnDelete(textArea, e); * break; * * default: * throw new NotImplementedException(performEdit.ToString()); * } * } * * /// <summary> * /// Determine whether an edit function (Copy, Pase, Cut, Delete) on an * /// <seealso cref="ICSharpCode.AvalonEdit.Editing.TextArea"/> view object * /// can be performed or not. * /// </summary> * /// <param name="e"></param> * /// <param name="performEdit"></param> * private void CanPerformTextAreaEdit(CanExecuteRoutedEventArgs e, TextAreaEdit performEdit) * { * if (e == null) * return; * * DockingManager dockManager = e.Parameter as DockingManager; * * if (dockManager == null) * return; * * // Some AvalonEdit functions (Cut, Copy, Paste etc) require finding the View and * // Executing code directly on the view. * // * // I am not sure how to find the currently used AvalonEdit TextArea view from here: * // Question: Does dockManager have an API to return the currently active visual? * // * // Using VisualTreeHelper on dockManager does work if the document is docked * // * // Issues: Undock your text document and this does no longer work (What should we do instead?): * ICSharpCode.AvalonEdit.Editing.TextArea textArea = Helpers.FindFocusedElement(dockManager) as ICSharpCode.AvalonEdit.Editing.TextArea; * * if (textArea == null) * return; * * switch (performEdit) * { * case TextAreaEdit.Copy: * case TextAreaEdit.Cut: * ICSharpCode.AvalonEdit.Editing.EditingCommandHandler.CanCutOrCopy(textArea, e); * break; * case TextAreaEdit.Paste: * ICSharpCode.AvalonEdit.Editing.EditingCommandHandler.CanPaste(textArea, e); * break; * case TextAreaEdit.Delete: * ICSharpCode.AvalonEdit.Editing.EditingCommandHandler.CanDelete(textArea, e); * break; * * default: * throw new NotImplementedException(performEdit.ToString()); * } * } ***/ #endregion Editor Cut/Copy/Paste/Delete/WordWrap/ShowLineNumbers/ShowEndOfLine Commands #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.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.FindText, // Find text in a document (s, e) => { try { e.Handled = true; this.ShowFindReplaceDialog(); } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.FindPreviousText, // Find text in a document (s, e) => { try { e.Handled = true; EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { if (this.FindReplaceVM != null) { this.FindReplaceVM.FindNext(this.FindReplaceVM, true); } else { this.ShowFindReplaceDialog(); } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); win.CommandBindings.Add(new CommandBinding(AppCommand.FindNextText, // Find text in a document (s, e) => { try { e.Handled = true; EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { if (this.FindReplaceVM != null) { this.FindReplaceVM.FindNext(this.FindReplaceVM, false); } else { this.ShowFindReplaceDialog(); } } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); 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.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, App.IssueTrackerText, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { e.CanExecute = CanExecuteIfActiveDocumentIsFileViewModel(); })); #endregion GotoLine FindReplace win.CommandBindings.Add(new CommandBinding(AppCommand.RunScript, (s, e) => { try { if (e != null) { e.Handled = true; } if (this.ActiveDocument != null) { this.OnSave(this.ActiveDocument, false); this.OnRunScript(this.ActiveDocument, true); } } catch (Exception exp) { logger.ErrorException(exp.Message, exp); Edi.Msg.Box.Show(exp, "Unhandled Error", MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, App.IssueTrackerLink, App.IssueTrackerLink, App.IssueTrackerText, null, true); } }, (s, e) => { if (e != null) { e.Handled = true; if (this.ActiveDocument != null) { e.CanExecute = this.ActiveDocument.CanSave(); } } })); }