public NameResolver(Globals globals, DepthScanner aScanner)
 {
     scanner_ = aScanner;
     globals_ = globals;
 }
        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 = Intellisense.Sources.SourceBuilder.GetFoldingStrategyForExtension(System.IO.Path.GetExtension(item.Path));

            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
            });
        }
Esempio n. 3
0
 public NameResolver(Globals globals, DepthScanner aScanner)
 {
     scanner_ = aScanner;
     globals_ = globals;
 }
 void editor_TextChanged(object sender, EventArgs e)
 {
     string text = editor.Text;
     new Thread(delegate()
     {
         DepthScanner newScan = new DepthScanner();
         newScan.Process(text);
         MainWindow.inst().Dispatcher.BeginInvoke((System.Windows.Forms.MethodInvoker)delegate()
         {
             changeChecker.Recheck();
             scanner = newScan;
         });
     }).Start();
     UpdateFoldings();
 }