Exemple #1
0
        protected override void OnViewLoaded(object view)
        {
            editorView = (EditorView)view;
            textEditor = editorView.textEditor;
            if (System.IO.File.Exists(path))
            {
                textEditor.OpenFile(path);
            }
            originalText = textEditor.Text;

            textEditor.TextChanged += delegate
            {
                IsDirty = string.Compare(originalText, textEditor.Text) != 0;
            };

            //some other settings
            textEditor.ShowLineNumbers    = true;
            textEditor.SyntaxHighlighting = GetHighlighting(Path.GetExtension(path));

            if (CShell.Shell.Workspace != null && CShell.Shell.Workspace.ScriptingEngine.CodeCompletion != null)
            {
                textEditor.Completion = CShell.Shell.Workspace.ScriptingEngine.CodeCompletion;
            }

            //debug to see what commands are available in the editor
            //var c = textEditor.TextArea.CommandBindings;
            //foreach (System.Windows.Input.CommandBinding cmd in c)
            //{
            //    var rcmd = cmd.Command as RoutedCommand;
            //    if(rcmd != null)
            //    {
            //        Debug.Print(rcmd.Name + "  "+ rcmd.InputGestures.ToString());
            //    }
            //}
        }
Exemple #2
0
        private void OpenScript(string scriptName)
        {
            foreach (ClosableTab t in tabs.Items)
            {
                if (t.Title == scriptName)
                {
                    tabs.SelectedItem = t;
                    return;
                }
            }
            _tempFileCounter++;
            var fn  = System.IO.Path.Combine(Settings.Settings.Default.SettingsFolder, string.Format("script{0}.cs", _tempFileCounter));
            var scr = Settings.Settings.Default.GetScriptItem(scriptName);

            if (scr != null)
            {
                System.IO.File.WriteAllText(fn, scr.Code);

                var editor = new CodeTextEditor();
                editor.FontFamily = new FontFamily("Consolas");
                editor.FontSize   = 12;
                editor.Completion = _completion;
                editor.OpenFile(fn);
                editor.SyntaxHighlighting           = HighlightingManager.Instance.GetDefinition("C#");
                editor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy();

                var tabItem = new ClosableTab();
                tabItem.Content = editor;
                tabItem.Title   = scriptName;
                tabs.Items.Add(tabItem);
                tabs.SelectedItem   = tabItem;
                tabItem.MouseLeave += tabs_MouseLeave;
            }
        }
Exemple #3
0
        private void BuildEditor()
        {
            CodeTextEditor editor = new CodeTextEditor();

            try
            {
                editor.OpenFile(ProjectItem.Path);

                editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
                editor.Margin             = new Thickness(0, 6, 0, 6);

                editor.IsReadOnly = _IsReadOnly;

                editor.TextChanged       += Editor_TextChanged;
                editor.TextArea.GotFocus += Editor_GotFocus;

                editor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(editor.TextArea));

                Content = editor;

                UpdateEditorConfig();
            }
            catch (Exception ex)
            {
                string message = String.Format("Unable to open file '{0}'", editor.FileName);
                Services.MessageBox.ShowError(message, ex);
            }
        }
Exemple #4
0
 private void replaceButton_Click(object sender, EventArgs e)
 {
     if (this.FindNext(this.replaceWhatText.Text, false) == true)
     {
         CodeTextEditor editor = Workspace.CurrentEditor.TextEditor;
         editor.Document.Replace(editor.Text.IndexOf(this.replaceWhatText.Text, editor.SelectionStart, editor.SelectionLength), this.replaceWhatText.Text.Length, this.replaceWithText.Text);
     }
 }
 protected void Closed()
 {
     parent.Controls.Remove(host);
     host   = null;
     editor = null;
     // TODO: Fix this hardcoded language name and generalize with how editors are handled.
     ServiceManager.Get <IFlowSharpCodeService>().EditorWindowClosed("C#");
 }
        private void OpenFile(string fileName)
        {
            var editor = new CodeTextEditor();

            editor.FontFamily = new FontFamily("Consolas");
            editor.FontSize   = 12;
            editor.Completion = completion;
            editor.OpenFile(fileName);
            editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");

            var tabItem = new TabItem();

            tabItem.Content = editor;
            tabItem.Header  = System.IO.Path.GetFileName(fileName);
            tabs.Items.Add(tabItem);
        }
        public void CreateEditor(Control parent)
        {
            ElementHost host = new ElementHost();

            host.Dock = DockStyle.Fill;

            completion = new CSharpCompletion(new ScriptProvider());

            editor                    = new CodeTextEditor();
            editor.FontFamily         = new FontFamily("Consolas");
            editor.FontSize           = 12;
            editor.Completion         = completion;
            editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
            editor.TextChanged       += OnTextChanged;

            // Very important!  The code completer throws exceptions if the document does not have a filename.
            editor.Document.FileName = "foo.cs";

            host.Child = editor;
            parent.Controls.Add(host);
        }
Exemple #8
0
        /// <summary>
        /// Move caret to offset.
        /// </summary>
        /// <param name="findText">Text which was finded.</param>
        /// <param name="offset">Offset where the text is.</param>
        /// <param name="scrollToCaret">If true editor will scroll to caret.</param>
        /// <returns>Returns true if the caret was moved, false otherwise.</returns>
        /// <remarks>This function will return false if the finded text need to be 'whole word' and it isn't.</remarks>
        private bool MoveCaret(string findText, int offset, bool scrollToCaret)
        {
            CodeTextEditor editor = Workspace.CurrentEditor.TextEditor;

            editor.Select(offset, findText.Length);

            // Check if we need the whole word, if we need it let's compare with the selection.
            if (this.wholeWordCheckBox.Checked == true && string.Compare(editor.SelectedText, findText) != 0)
            {
                editor.TextArea.ClearSelection();
                return(false);
            }

            if (scrollToCaret == true)
            {
                DocumentLine documentLine = editor.TextArea.Document.GetLineByOffset(offset);
                editor.ScrollTo(documentLine.LineNumber, 0);
            }

            return(true);
        }
Exemple #9
0
        public static CodeTextEditor CreateEditor(string fileName)
        {
            var editor = new CodeTextEditor();

            editor.FontFamily = new FontFamily("Consolas");
            editor.FontSize   = 20;
            byte[] r = Encoding.Default.GetBytes("40");
            byte[] g = Encoding.Default.GetBytes("3C");
            byte[] b = Encoding.Default.GetBytes("3B");
            editor.Background      = new SolidColorBrush(Color.FromRgb(r[0], g[0], b[0]));
            editor.ShowLineNumbers = true;
            try
            {
                if (fileName != "New")
                {
                    FileAttributes attr = File.GetAttributes(fileName);
                    if (((attr & FileAttributes.Directory) == FileAttributes.Directory))
                    {
                        return(null);
                    }
                    else
                    {
                        editor.OpenFile(fileName);
                    }
                }

                editor.SyntaxHighlighting = HighlightingLoader.Load(new XmlTextReader(Environment.CurrentDirectory + "\\Python-Mode.xshd"), HighlightingManager.Instance);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }

            return(editor);
        }
Exemple #10
0
        public bool FindNext(string findText, bool scrollToCaret)
        {
            CodeTextEditor editor     = Workspace.CurrentEditor.TextEditor;
            string         editorText = editor.Text;

            if (string.IsNullOrEmpty(findText) == true)
            {
                findText = this.findWhatText.Text;
            }

            if (this.caseSentitiveCheckBox.Checked == false)
            {
                editorText = editorText.ToLower();
                findText   = findText.ToLower();
            }

            if (string.IsNullOrEmpty(findText) == true || string.IsNullOrEmpty(editorText) == true)
            {
                return(false);
            }

            int offset = editor.CaretOffset + 1;
            int index  = editorText.IndexOf(findText, offset > editor.Text.Length ? 0 : offset);

            if (index == -1)
            {
                index = editorText.IndexOf(findText, 0);
            }

            if (index > -1)
            {
                return(MoveCaret(findText, index, scrollToCaret));
            }

            return(false);
        }
        /// <summary>
        /// Scroll to correct line in the editor. This could be called from a DispatcherTimer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GotoDefinition_ScrollToLine(object sender = null, EventArgs e = null)
        {
            var timer = sender as DispatcherTimer;

            if (timer != null)
            {
                timer.Stop();
            }

            var args = _gotoDefinitionArgs;

            if (CodeTextEditor != null)
            {
                if (args.LineNumber != -1)
                {
                    ICSharpCode.AvalonEdit.Document.DocumentLine line = CodeTextEditor.Document.GetLineByNumber(args.LineNumber);

                    CodeTextEditor.Select(line.Offset, line.Length);
                    CodeTextEditor.CaretOffset = line.Offset;
                    CodeTextEditor.ScrollToLine(args.LineNumber);
                    CodeTextEditor.Focus();
                }
            }
        }