public CodeEditor(FileData aModelData)
        {
            InitializeComponent();
            aModelData.AttachEditor(editor);
            this.data = aModelData;
            editor.ShowLineNumbers             = true;
            editor.Options.ConvertTabsToSpaces = true;
            editor.Options.IndentationSize     = 4;
            editor.Foreground         = new SolidColorBrush(Colors.White);
            editor.SyntaxHighlighting = AvalonExtensions.LoadHighlightingDefinition("Debugger.Resources.Angelscript.xshd");
            editor.Text       = data.Code;
            editor.FontFamily = new FontFamily("Consolas");
            editor.TextArea.TextView.CurrentLineBackground = new SolidColorBrush(Colors.LightGray);
            editor.TextArea.TextView.BackgroundRenderers.Add(new LineHighlighter());
            editor.TextArea.LeftMargins.Insert(0, bpMargin = new BreakpointMargin(aModelData));
            SearchPanel panel = SearchPanel.Install(editor.TextArea);

            aModelData.PropertyChanged += aModelData_PropertyChanged;
            foldingManager              = FoldingManager.Install(editor.TextArea);
            codeFolding = new BraceFoldingStrategy();
            UpdateFolding();

            // If using IDE data then give ourselves an IntellisenseSource
            if (Debug.SessionData.inst().Settings.UseIDEData)
            {
                intelSource = IDE.Intellisense.Sources.SourceBuilder.GetSourceForExtension(System.IO.Path.GetExtension(aModelData.SectionName));
            }

            depthScanner = new IDE.Intellisense.DepthScanner();
            depthScanner.Process(editor.Text);

            editor.MouseHover          += editor_MouseHover;
            editor.TextArea.MouseWheel += editor_MouseWheel;
            editor.KeyUp       += editor_KeyUp;
            editor.TextChanged += editor_TextChanged;

            t          = new System.Timers.Timer();
            t.Interval = 175;
            t.Elapsed += t_Elapsed;
            t.Start();
        }
Exemplo n.º 2
0
        public IDEEditor(FileBaseItem aItem)
        {
            InitializeComponent();
            item          = aItem;
            changeChecker = new DataChanged {
                editor = editor
            };
            SetCode(aItem);
            editor.ShowLineNumbers = true;

            editor.Options.ConvertTabsToSpaces = true;
            editor.Options.IndentationSize     = 4;

            editor.FontFamily = new FontFamily("Consolas");
            editor.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFDCDCCC"));
            editor.TextArea.TextView.BackgroundRenderers.Add(new LineHighlighter());
            editor.TextArea.TextView.BackgroundRenderers.Add(new ErrorLineHighlighter(aItem));
            // Buggy
            //editor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy();
            Debugger.Editor.SearchPanel.Install(editor);
            editor.TextChanged += editor_TextChanged;
            scanner             = new DepthScanner();
            scanner.Process(editor.Text);
            editor.MouseHover          += editor_MouseHover;
            editor.TextArea.MouseWheel += editor_MouseWheel;
            editor.KeyUp   += editor_KeyUp;
            editor.MouseUp += editor_MouseUp;
            codeFolding     = new BraceFoldingStrategy();

            if (FOLDED_EXTENSIONS.Contains(System.IO.Path.GetExtension(aItem.Path)))
            {
                foldingManager = FoldingManager.Install(editor.TextArea);
                UpdateFoldings();
            }

            intelSource        = Intellisense.Sources.SourceBuilder.GetSourceForExtension(System.IO.Path.GetExtension(item.Path));
            editor.ContextMenu = new ContextMenu();

            // Hook the source, so we can get context menu commands from it
            if (intelSource != null)
            {
                intelSource.HookEditor(editor, item);
            }

            editor.ContextMenu.Items.Add(new MenuItem
            {
                Header  = "Snippet",
                Command = new RelayCommand(p =>
                {
                    ObservableCollection <Snippets.CodeSnippet> snips = new ObservableCollection <Snippets.CodeSnippet>();
                    string ext = System.IO.Path.GetExtension(item.Path);
                    foreach (Snippets.CodeSnippet snip in Snippets.SnippetData.inst().Snippets)
                    {
                        if (snip.Extension.Equals(ext))
                        {
                            snips.Add(snip);
                        }
                    }
                    if (snips.Count > 0)
                    {
                        Snippets.SnippetDlg dlg = new Snippets.SnippetDlg(editor, snips);
                        dlg.ShowDialog();
                    }
                }, sp =>
                {
                    ObservableCollection <Snippets.CodeSnippet> snips = new ObservableCollection <Snippets.CodeSnippet>();
                    string exte = System.IO.Path.GetExtension(item.Path);
                    foreach (Snippets.CodeSnippet snip in Snippets.SnippetData.inst().Snippets)
                    {
                        if (snip.Extension.Equals(exte))
                        {
                            return(true);
                        }
                    }
                    return(false);
                })
            });

            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Cut",
                Command = ApplicationCommands.Cut
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Copy",
                Command = ApplicationCommands.Copy
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Paste",
                Command = ApplicationCommands.Paste
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Undo",
                Command = ApplicationCommands.Undo
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Redo",
                Command = ApplicationCommands.Redo
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Save",
                Command = ApplicationCommands.Save
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Save As",
                Command = ApplicationCommands.SaveAs
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Open",
                Command = ApplicationCommands.Open
            });
        }