private LempDemoPanel AddNewTextEditor(string title, string initialText = "") { var tab = new TabPage(title); // When a tab page gets the focus, move the focus to the editor control // instead when it gets the Enter (focus) event. I use BeginInvoke // because changing the focus directly in the Enter handler doesn't // work. tab.Enter += new EventHandler((sender, e) => { var page = ((TabPage)sender); page.BeginInvoke(new Action <TabPage>(p => p.Controls[0].Focus()), page); }); var panel = new LempDemoPanel(_editorSettings); _editorSettings = panel.EditorSettings; panel.Dock = System.Windows.Forms.DockStyle.Fill; tab.Controls.Add(panel); fileTabs.Controls.Add(tab); panel.Editor.Text = initialText; panel.SetModifiedFlag(false); return(panel); }
/// <summary>Performs an action encapsulated in IEditAction.</summary> /// <remarks> /// There is an implementation of IEditAction for every action that /// the user can invoke using a shortcut key (arrow keys, Ctrl+X, etc.) /// The editor control doesn't provide a public funciton to perform one /// of these actions directly, so I wrote DoEditAction() based on the /// code in TextArea.ExecuteDialogKey(). You can call ExecuteDialogKey /// directly, but it is more fragile because it takes a Keys value (e.g. /// Keys.Left) instead of the action to perform. /// <para/> /// Clipboard commands could also be done by calling methods in /// editor.ActiveTextAreaControl.TextArea.ClipboardHandler. /// </remarks> private void DoEditAction(LempDemoPanel panel, ICSharpCode.TextEditor.Actions.IEditAction action) { TextEditorControl editor = panel.Editor; if (editor != null && action != null) { var area = editor.ActiveTextAreaControl.TextArea; editor.BeginUpdate(); try { lock (editor.Document) { action.Execute(area); if (area.SelectionManager.HasSomethingSelected && area.AutoClearSelection /*&& caretchanged*/) { if (area.Document.TextEditorProperties.DocumentSelectionMode == DocumentSelectionMode.Normal) { area.SelectionManager.ClearSelection(); } } } } finally { editor.EndUpdate(); area.Caret.UpdateCaretPosition(); } } }
private void menuFileSave_Click(object sender, EventArgs e) { LempDemoPanel panel = ActivePage; if (panel != null) { DoSave(panel); } }
/// <summary>Toggles whether the editor control is split in two parts.</summary> /// <remarks>Exercise for the reader: modify TextEditorControl and /// TextAreaControl so it shows a little "splitter stub" like you see in /// other apps, that allows the user to split the text editor by dragging /// it.</remarks> private void menuSplitTextArea_Click(object sender, EventArgs e) { LempDemoPanel editor = ActivePage; if (editor == null) { return; } editor.FocusedEditor.Split(); }
private void menuEditReplace_Click(object sender, EventArgs e) { LempDemoPanel panel = ActivePage; if (panel == null) { return; } _findForm.ShowFor(panel.FocusedEditor, true); }
private bool DoSave(LempDemoPanel panel) { if (string.IsNullOrEmpty(panel.Editor.FileName)) { return(DoSaveAs(panel)); } else { try { panel.Editor.SaveFile(panel.Editor.FileName); panel.SetModifiedFlag(false); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name); return(false); } } }
private bool DoSaveAs(LempDemoPanel panel) { TextEditorControl editor = panel.Editor; saveFileDialog.FileName = editor.FileName; if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { editor.SaveFile(saveFileDialog.FileName); panel.ChooseHighlighter(); // fix syntax highlighting panel.Parent.Text = Path.GetFileName(editor.FileName); panel.SetModifiedFlag(false); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name); } } return(false); }
private bool DoSaveAs(LempDemoPanel panel) { TextEditorControl editor = panel.Editor; saveFileDialog.FileName = editor.FileName; if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { editor.SaveFile(saveFileDialog.FileName); editor.Parent.Text = Path.GetFileName(editor.FileName); panel.SetModifiedFlag(false); // The syntax highlighting strategy doesn't change // automatically, so do it manually. editor.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(editor.FileName); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name); } } return(false); }
private LempDemoPanel AddNewTextEditor(string title, string initialText = "") { var tab = new TabPage(title); // When a tab page gets the focus, move the focus to the editor control // instead when it gets the Enter (focus) event. I use BeginInvoke // because changing the focus directly in the Enter handler doesn't // work. tab.Enter += new EventHandler((sender, e) => { var page = ((TabPage)sender); page.BeginInvoke(new Action<TabPage>(p => p.Controls[0].Focus()), page); }); var panel = new LempDemoPanel(_editorSettings); _editorSettings = panel.EditorSettings; panel.Dock = System.Windows.Forms.DockStyle.Fill; tab.Controls.Add(panel); fileTabs.Controls.Add(tab); panel.Editor.Text = initialText; return panel; }
private void RemoveTextEditor(LempDemoPanel panel) { ((TabControl)panel.Parent.Parent).Controls.Remove(panel.Parent); }
private bool DoSaveAs(LempDemoPanel panel) { TextEditorControl editor = panel.Editor; saveFileDialog.FileName = editor.FileName; if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { editor.SaveFile(saveFileDialog.FileName); editor.Parent.Text = Path.GetFileName(editor.FileName); panel.SetModifiedFlag(false); // The syntax highlighting strategy doesn't change // automatically, so do it manually. editor.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(editor.FileName); return true; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name); } } return false; }
private bool DoSave(LempDemoPanel panel) { if (string.IsNullOrEmpty(panel.Editor.FileName)) return DoSaveAs(panel); else { try { panel.Editor.SaveFile(panel.Editor.FileName); panel.SetModifiedFlag(false); return true; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name); return false; } } }