コード例 #1
0
 private void SetModifiedFlag(TextEditorControl editor, bool flag)
 {
     if (IsModified(editor) != flag)
     {
         var p = editor.Parent;
         if (IsModified(editor))
         {
             p.Text = p.Text.Substring(0, p.Text.Length - 1);
         }
         else
         {
             p.Text += "*";
         }
     }
 }
コード例 #2
0
 private bool DoSave(TextEditorControl editor)
 {
     if (string.IsNullOrEmpty(editor.FileName))
     {
         return(DoSaveAs(editor));
     }
     else
     {
         try {
             editor.SaveFile(editor.FileName);
             SetModifiedFlag(editor, false);
             return(true);
         } catch (Exception ex) {
             MessageBox.Show(ex.Message, ex.GetType().Name);
             return(false);
         }
     }
 }
コード例 #3
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);
        }
コード例 #4
0
        private bool DoSaveAs(TextEditorControl editor)
        {
            saveFileDialog.FileName = editor.FileName;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                try {
                    editor.SaveFile(saveFileDialog.FileName);
                    editor.Parent.Text = Path.GetFileName(editor.FileName);
                    SetModifiedFlag(editor, 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);
        }
コード例 #5
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(TextEditorControl editor, ICSharpCode.TextEditor.Actions.IEditAction action)
 {
     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();
         }
     }
 }
コード例 #6
0
ファイル: FindAndReplaceForm.cs プロジェクト: pre078/ApsimX
        public void ShowFor(TextEditorControl editor, bool replaceMode)
        {
            Editor = editor;

            _search.ClearScanRegion();
            var sm = editor.ActiveTextAreaControl.SelectionManager;

            if (sm.HasSomethingSelected && sm.SelectionCollection.Count == 1)
            {
                var sel = sm.SelectionCollection[0];
                if (sel.StartPosition.Line == sel.EndPosition.Line)
                {
                    txtLookFor.Text = sm.SelectedText;
                }
                else
                {
                    _search.SetScanRegion(sel);
                }
            }
            else
            {
                // Get the current word that the caret is on
                Caret caret = editor.ActiveTextAreaControl.Caret;
                int   start = TextUtilities.FindWordStart(editor.Document, caret.Offset);
                int   endAt = TextUtilities.FindWordEnd(editor.Document, caret.Offset);
                txtLookFor.Text = editor.Document.GetText(start, endAt - start);
            }

            ReplaceMode = replaceMode;

            this.Owner = (Form)editor.TopLevelControl;
            this.Show();

            txtLookFor.SelectAll();
            txtLookFor.Focus();
        }
コード例 #7
0
ファイル: FindAndReplaceForm.cs プロジェクト: pre078/ApsimX
 public HighlightGroup(TextEditorControl editor)
 {
     _editor   = editor;
     _document = editor.Document;
 }
コード例 #8
0
 /// <summary>Gets whether the file in the specified editor is modified.</summary>
 /// <remarks>TextEditorControl doesn't maintain its own internal modified
 /// flag, so we use the '*' shown after the file name to represent the
 /// modified state.</remarks>
 private bool IsModified(TextEditorControl editor)
 {
     // TextEditorControl doesn't seem to contain its own 'modified' flag, so
     // instead we'll treat the "*" on the filename as the modified flag.
     return(editor.Parent.Text.EndsWith("*"));
 }
コード例 #9
0
 private void RemoveTextEditor(TextEditorControl editor)
 {
     ((TabControl)editor.Parent.Parent).Controls.Remove(editor.Parent);
 }