コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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();
                }
            }
        }
コード例 #3
0
        private void menuFileSave_Click(object sender, EventArgs e)
        {
            LempDemoPanel panel = ActivePage;

            if (panel != null)
            {
                DoSave(panel);
            }
        }
コード例 #4
0
        /// <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();
        }
コード例 #5
0
        private void menuEditReplace_Click(object sender, EventArgs e)
        {
            LempDemoPanel panel = ActivePage;

            if (panel == null)
            {
                return;
            }
            _findForm.ShowFor(panel.FocusedEditor, true);
        }
コード例 #6
0
 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);
         }
     }
 }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: LempDemoForm.cs プロジェクト: Shaykh/Loyc
		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;
		}
コード例 #10
0
 private void RemoveTextEditor(LempDemoPanel panel)
 {
     ((TabControl)panel.Parent.Parent).Controls.Remove(panel.Parent);
 }
コード例 #11
0
ファイル: LempDemoForm.cs プロジェクト: Shaykh/Loyc
		/// <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();
				}
			}
		}
コード例 #12
0
ファイル: LempDemoForm.cs プロジェクト: Shaykh/Loyc
		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;
		}
コード例 #13
0
ファイル: LempDemoForm.cs プロジェクト: Shaykh/Loyc
		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;
				}
			}
		}
コード例 #14
0
ファイル: LempDemoForm.cs プロジェクト: Shaykh/Loyc
		private void RemoveTextEditor(LempDemoPanel panel)
		{
			((TabControl)panel.Parent.Parent).Controls.Remove(panel.Parent);
		}