示例#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());
            //    }
            //}
        }
示例#2
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);
            }
        }
示例#3
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;
            }
        }
        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);
        }
示例#5
0
        public void UpdateContent()
        {
            if (!IgnoreUpdates)
            {
                try
                {
                    int start = _Editor.SelectionStart;

                    _Editor.OpenFile(ProjectItem.Path);
                    _Editor.SelectionStart = start;

                    _Editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");

                    IsModified = false;
                }
                catch (Exception ex)
                {
                    string message = String.Format("Unable to open file '{0}'", _Editor.FileName);
                    Services.MessageBox.ShowError(message, ex);
                }
            }
        }
示例#6
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);
        }