Esempio n. 1
0
        public IDEEditor OpenFile(FileBaseItem aFile, int aLine)
        {
            IDEEditor ret = OpenFile(aFile);

            ret.Editor.TextArea.Caret.Line = aLine;
            ret.Editor.ScrollToLine(aLine);
            ret.InvalidateArrange();
            return(ret);
        }
        private void fileTree_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            FileBaseItem item = fileTree.SelectedItem as FileBaseItem;

            if (sender is TreeViewItem && ((TreeViewItem)sender).DataContext is FileLeafItem)
            {
                e.Handled = true;
                ideTabs.OpenFile(item);
            }
        }
        void onEditFile(object sender, EventArgs e)
        {
            MenuItem     item   = sender as MenuItem;
            ContextMenu  menu   = item.CommandParameter as ContextMenu;
            FileBaseItem target = (menu.PlacementTarget as StackPanel).Tag as FileBaseItem;

            if (target is FileLeafItem)
            {
                ideTabs.OpenFile(target);
            }
        }
Esempio n. 4
0
 public IDEEditor OpenFile(FileBaseItem aFile, int aLine)
 {
     if (aFile.Name.Contains(".as"))
     {
         IDEEditor ret = OpenFile(aFile);
         ret.Editor.TextArea.Caret.Line = aLine;
         ret.Editor.ScrollToLine(aLine);
         ret.InvalidateArrange();
         return(ret);
     }
     return(null);
 }
Esempio n. 5
0
 public void SetCode(FileBaseItem item)
 {
     try {
         this.item             = item;
         editor.Text           = File.ReadAllText(item.Path);
         changeChecker.code    = editor.Text;
         changeChecker.IsDirty = false;
     }
     catch (Exception ex) {
         ErrorHandler.inst().Error(ex);
     }
 }
Esempio n. 6
0
        private void fileTree_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            FileBaseItem item = fileTree.SelectedItem as FileBaseItem;

            if (item is FileLeafItem)
            {
                if (item.Path.EndsWith(".as") || item.Path.EndsWith(".xml") || item.Path.EndsWith(".csv") || item.Path.EndsWith(".txt"))
                {
                    ideTabs.OpenFile(item);
                }
            }
        }
Esempio n. 7
0
        void onNewFolder(object sender, EventArgs e)
        {
            MenuItem     item   = sender as MenuItem;
            ContextMenu  menu   = item.CommandParameter as ContextMenu;
            FileBaseItem target = (menu.PlacementTarget as StackPanel).Tag as FileBaseItem;

            string r = Debugger.Dlg.InputDlg.Show("Create Folder", "Name of new folder:");

            if (r != null)
            {
                System.IO.Directory.CreateDirectory(System.IO.Path.Combine(target.Path, r));
            }
        }
Esempio n. 8
0
        public IDEEditor OpenFile(FileBaseItem aFile)
        {
            foreach (TabItem item in tabs.Items)
            {
                if (item.Tag.Equals(aFile.Path))
                {
                    tabs.SelectedItem = item;
                    ((IDEEditor)((TabItem)tabs.SelectedItem).Content).SetCode(aFile);
                    return((IDEEditor)((TabItem)tabs.SelectedItem).Content);
                }
            }
            Grid grid = new Grid();

            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());

            IDEEditor ideEditor = new IDEEditor(aFile);

            TextBlock txt = new TextBlock {
                Text = aFile.Name
            };

            txt.DataContext = ideEditor.changeChecker;
            txt.Foreground  = FindResource("ButtonText") as Brush;
            txt.Style       = FindResource("IDETabHeader") as Style;

            grid.Children.Add(txt);
            Button close = new Button {
                Content = "X", Padding = new Thickness(0), Foreground = new SolidColorBrush(Colors.LightGray), FontWeight = FontWeights.Bold, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Right
            };

            close.MinHeight  = close.MinWidth = 18;
            close.MaxHeight  = close.MaxWidth = 18;
            close.Background = close.BorderBrush = null;
            close.Click     += onCloseTab;
            Grid.SetColumn(txt, 0);
            Grid.SetColumn(close, 1);
            grid.Children.Add(close);

            tabs.Items.Add(new TabItem {
                Tag     = aFile.Path,
                Header  = grid,
                Content = ideEditor,
            });
            ((TabItem)tabs.Items[tabs.Items.Count - 1]).MouseUp += EditorTabs_MouseUp;
            tabs.SelectedItem = tabs.Items[tabs.Items.Count - 1];
            return((IDEEditor)((TabItem)tabs.SelectedItem).Content);
        }
        void onNewFile(object sender, EventArgs e)
        {
            MenuItem     item   = sender as MenuItem;
            ContextMenu  menu   = item.CommandParameter as ContextMenu;
            FileBaseItem target = (menu.PlacementTarget as StackPanel).Tag as FileBaseItem;

            {
                Dlg.NewFileDlg d      = new Dlg.NewFileDlg(target.Path);
                bool?          result = d.ShowDialog();
                if (result.HasValue && result.Value)
                {
                    ideTabs.OpenFile(new FileBaseItem {
                        Path = d.Path, Name = System.IO.Path.GetFileName(d.Path)
                    });
                }
            }
        }
Esempio n. 10
0
        void onRenameFile(object sender, EventArgs e)
        {
            MenuItem     item    = sender as MenuItem;
            ContextMenu  menu    = item.CommandParameter as ContextMenu;
            FileBaseItem target  = (menu.PlacementTarget as StackPanel).Tag as FileBaseItem;
            string       newName = RenameDlg.Show(target.Name);

            if (newName.Length > 0)
            {
                try {
                    string dir = System.IO.Path.GetDirectoryName(target.Path);
                    File.Move(target.Path, System.IO.Path.Combine(dir, newName));
                } catch (Exception ex) {
                    ErrorHandler.inst().Error(ex);
                }
            }
        }
Esempio n. 11
0
        void onNewFile(object sender, EventArgs e)
        {
            MenuItem     item   = sender as MenuItem;
            ContextMenu  menu   = item.CommandParameter as ContextMenu;
            FileBaseItem target = (menu.PlacementTarget as StackPanel).Tag as FileBaseItem;

            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.InitialDirectory = target.Path;
            dlg.DefaultExt       = "as";
            dlg.Filter           = "Script (*.as)|*.as|Material (*.xml)|*.xml";
            if (dlg.ShowDialog() == true)
            {
                File.WriteAllText(dlg.FileName, "");
                ideTabs.OpenFile(new FileBaseItem {
                    Path = dlg.FileName, Name = dlg.FileName
                });
            }
        }
Esempio n. 12
0
        void onDeleteFile(object sender, EventArgs e)
        {
            MenuItem     item   = sender as MenuItem;
            ContextMenu  menu   = item.CommandParameter as ContextMenu;
            FileBaseItem target = (menu.PlacementTarget as StackPanel).Tag as FileBaseItem;

            if (ConfirmDlg.Show(string.Format("Delete {1} '{0}'?", target.Name, (target is Folder) ? "folder" : "file")) == true)
            {
                try {
                    if (target.Parent is Folder)
                    {
                        ((Folder)target.Parent).Children.Remove(target);
                    }
                    FileOperationAPIWrapper.MoveToRecycleBin(target.Path);
                } catch (Exception ex) {
                    ErrorHandler.inst().Error(ex);
                }
            }
        }
 public IDEEditor OpenFile(FileBaseItem aFile, int aLine)
 {
     if (Intellisense.Sources.SourceBuilder.HandlesExtension(System.IO.Path.GetExtension(aFile.Path)))
     {
         IDEEditor ret = OpenFile(aFile);
         ret.InvalidateArrange();
         new Thread(delegate()
         {
             Thread.Sleep(10);
             MainWindow.inst().Dispatcher.Invoke(delegate()
             {
                 ret.Editor.TextArea.Caret.Line = aLine;
                 ret.Editor.ScrollToLine(aLine);
                 ret.InvalidateArrange();
             });
         }).Start();
         return(ret);
     }
     return(null);
 }
Esempio n. 14
0
        private void fileTree_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            FileBaseItem item = fileTree.SelectedItem as FileBaseItem;

            if (item is FileLeafItem)
            {
                if (item.Path.EndsWith(".as") || item.Path.EndsWith(".xml") || item.Path.EndsWith(".txt"))
                {
                    ideTabs.OpenFile(item);
                }
                foreach (PluginLib.IFileEditor editor in PluginManager.inst().FileEditors)
                {
                    if (editor.CanEditFile(item.Path, System.IO.Path.GetExtension(item.Path)))
                    {
                        //\todo create an editing tab of some type here
                        ideTabs.OpenFile(item);
                        break;
                    }
                }
            }
        }
Esempio n. 15
0
 public ErrorLineHighlighter(FileBaseItem aFile)
 {
     file = aFile;
 }
Esempio n. 16
0
        public IDEEditor(FileBaseItem aItem)
        {
            InitializeComponent();
            item          = aItem;
            changeChecker = new DataChanged {
                editor = editor
            };
            SetCode(aItem);
            editor.ShowLineNumbers = true;
            if (aItem.Name.EndsWith(".as"))
            {
                editor.SyntaxHighlighting = LoadHighlightingDefinition("Debugger.Resources.Angelscript.xshd");
            }
            else if (aItem.Name.EndsWith(".xml"))
            {
                editor.SyntaxHighlighting = LoadHighlightingDefinition("Debugger.Resources.XML.xshd");
            }
            else
            {
                editor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinitionByExtension(item.Path.Substring(item.Path.LastIndexOf('.')));
            }

            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));
            Debugger.Editor.SearchPanel.Install(editor);
            editor.TextChanged += editor_TextChanged;
            scanner             = new DepthScanner();
            scanner.Process(editor.Text);
            editor.MouseHover += editor_MouseHover;
            editor.KeyUp      += editor_KeyUp;

            editor.ContextMenu = new ContextMenu();
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Compile",
                Command = new RelayCommand(p =>
                {
                    IDEView.Compile();
                })
            });
            editor.ContextMenu.Items.Add(new Separator());
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "New ScriptObject",
                Command = new RelayCommand(p => {
                    editor.Document.BeginUpdate();
                    editor.Document.Insert(editor.CaretOffset, SOScript);
                    editor.Document.EndUpdate();
                })
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Insert #include",
                Command = new RelayCommand(p => {
                    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                    dlg.DefaultExt = "*";
                    dlg.Filter     = "All files (*.*)|*.*";
                    if (dlg.ShowDialog() == true)
                    {
                        editor.Document.BeginUpdate();
                        editor.Document.Insert(editor.CaretOffset, string.Format("#include \"{0}\"", dlg.FileName));
                        editor.Document.EndUpdate();
                    }
                })
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Doxygen Comment",
                Command = new RelayCommand(p => {
                    editor.Document.BeginUpdate();
                    editor.Document.Insert(editor.CaretOffset,
                                           @"/////////////////////////////////////////////////
/// DOCUMENT_HERE
/////////////////////////////////////////////////", AnchorMovementType.AfterInsertion);
                    editor.Document.EndUpdate();
                })
            });
            editor.ContextMenu.Items.Add(new MenuItem {
                Header  = "Property Comment",
                Command = new RelayCommand(p => {
                    editor.Document.BeginUpdate();
                    editor.Document.Insert(editor.CaretOffset, "///< DOCUMENT", AnchorMovementType.AfterInsertion);
                    editor.Document.EndUpdate();
                })
            });
            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
            });
        }
        public IDEEditor OpenFile(FileBaseItem aFile)
        {
            if (Intellisense.Sources.SourceBuilder.HandlesExtension(System.IO.Path.GetExtension(aFile.Path)))
            {
                foreach (TabItem item in tabs.Items)
                {
                    if (item.Tag.Equals(aFile.Path))
                    {
                        tabs.SelectedItem = item;
                        ((IDEEditor)((TabItem)tabs.SelectedItem).Content).SetCode(aFile);
                        return((IDEEditor)((TabItem)tabs.SelectedItem).Content);
                    }
                }
                Grid grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.ColumnDefinitions.Add(new ColumnDefinition());

                IDEEditor ideEditor = new IDEEditor(aFile);

                TextBlock txt = new TextBlock {
                    Text = aFile.Name
                };
                txt.DataContext = ideEditor.changeChecker;
                txt.Foreground  = FindResource("ButtonText") as Brush;
                txt.Style       = FindResource("IDETabHeader") as Style;

                grid.Children.Add(txt);
                Button close = new Button {
                    Content = "X", Padding = new Thickness(0), Foreground = new SolidColorBrush(Colors.LightGray), FontWeight = FontWeights.Bold, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Right
                };
                close.MinHeight  = close.MinWidth = 18;
                close.MaxHeight  = close.MaxWidth = 18;
                close.Background = close.BorderBrush = null;
                close.Click     += onCloseTab;
                Grid.SetColumn(txt, 0);
                Grid.SetColumn(close, 1);
                grid.Children.Add(close);

                tabs.Items.Add(new TabItem
                {
                    Tag     = aFile.Path,
                    Header  = grid,
                    Content = ideEditor,
                });
                ((TabItem)tabs.Items[tabs.Items.Count - 1]).MouseUp += EditorTabs_MouseUp;
                tabs.SelectedItem = tabs.Items[tabs.Items.Count - 1];
                return((IDEEditor)((TabItem)tabs.SelectedItem).Content);
            }
            else
            {
                foreach (PluginLib.IFileEditor editor in PluginManager.inst().FileEditors)
                {
                    if (editor.CanEditFile(aFile.Path, System.IO.Path.GetExtension(aFile.Name)))
                    {
                        object ud = null;
                        PluginLib.IExternalControlData externalControl = editor.CreateEditorContent(aFile.Path);

                        Grid grid = new Grid();
                        grid.ColumnDefinitions.Add(new ColumnDefinition());
                        grid.ColumnDefinitions.Add(new ColumnDefinition());

                        TextBlock txt = new TextBlock {
                            Text = aFile.Name
                        };
                        txt.DataContext = externalControl;
                        txt.Foreground  = FindResource("ButtonText") as Brush;
                        txt.Style       = FindResource("IDETabHeader") as Style;

                        grid.Children.Add(txt);
                        Button close = new Button {
                            Content = "X", Padding = new Thickness(0), Foreground = new SolidColorBrush(Colors.LightGray), FontWeight = FontWeights.Bold, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Right
                        };
                        close.MinHeight  = close.MinWidth = 18;
                        close.MaxHeight  = close.MaxWidth = 18;
                        close.Background = close.BorderBrush = null;
                        close.Click     += onCloseTab;
                        Grid.SetColumn(txt, 0);
                        Grid.SetColumn(close, 1);
                        grid.Children.Add(close);

                        tabs.Items.Add(new TabItem
                        {
                            Tag     = aFile.Path,
                            Header  = grid,
                            Content = externalControl.Control,
                        });
                        ((TabItem)tabs.Items[tabs.Items.Count - 1]).MouseUp += EditorTabs_MouseUp;
                        tabs.SelectedItem = tabs.Items[tabs.Items.Count - 1];
                        return(null);
                    }
                }
                return(null);
            }
        }
        public IDEEditor OpenFile(FileBaseItem aFile)
        {
            PluginLib.IFileEditor editorPlugin = PluginManager.inst().GetFileEditor(aFile.Path);
            string extension = System.IO.Path.GetExtension(aFile.Path);

            // Check for priority, or if a fallback when a plugin is not present
            if (Intellisense.Sources.SourceBuilder.HandlesExtension(extension) ||
                (Intellisense.Sources.SourceBuilder.HandlesExtensionAsFallback(extension) && editorPlugin == null))
            {
                foreach (TabItem item in tabs.Items)
                {
                    if (item.Tag.Equals(aFile.Path))
                    {
                        tabs.SelectedItem = item;
                        ((IDEEditor)((TabItem)tabs.SelectedItem).Content).SetCode(aFile);
                        return ((IDEEditor)((TabItem)tabs.SelectedItem).Content);
                    }
                }
                Grid grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.ColumnDefinitions.Add(new ColumnDefinition());

                IDEEditor ideEditor = new IDEEditor(aFile);

                TextBlock txt = new TextBlock { Text = aFile.Name };
                txt.DataContext = ideEditor.changeChecker;
                txt.Foreground = FindResource("ButtonText") as Brush;
                txt.Style = FindResource("IDETabHeader") as Style;

                grid.Children.Add(txt);
                Button close = new Button { Content = "X", Padding = new Thickness(0), Foreground = new SolidColorBrush(Colors.LightGray), FontWeight = FontWeights.Bold, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Right };
                close.MinHeight = close.MinWidth = 18;
                close.MaxHeight = close.MaxWidth = 18;
                close.Background = close.BorderBrush = null;
                close.Click += onCloseTab;
                Grid.SetColumn(txt, 0);
                Grid.SetColumn(close, 1);
                grid.Children.Add(close);

                tabs.Items.Add(new TabItem
                {
                    Tag = aFile.Path,
                    Header = grid,
                    Content = ideEditor,
                });
                ((TabItem)tabs.Items[tabs.Items.Count - 1]).MouseUp += EditorTabs_MouseUp;
                tabs.SelectedItem = tabs.Items[tabs.Items.Count - 1];
                return ((IDEEditor)((TabItem)tabs.SelectedItem).Content);
            }
            else if (editorPlugin != null)
            {
                object ud = null;
                PluginLib.IExternalControlData externalControl = editorPlugin.CreateEditorContent(aFile.Path);

                Grid grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.ColumnDefinitions.Add(new ColumnDefinition());

                TextBlock txt = new TextBlock { Text = aFile.Name };
                txt.DataContext = externalControl;
                txt.Foreground = FindResource("ButtonText") as Brush;
                txt.Style = FindResource("IDETabHeader") as Style;

                grid.Children.Add(txt);
                Button close = new Button { Content = "X", Padding = new Thickness(0), Foreground = new SolidColorBrush(Colors.LightGray), FontWeight = FontWeights.Bold, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Right };
                close.MinHeight = close.MinWidth = 18;
                close.MaxHeight = close.MaxWidth = 18;
                close.Background = close.BorderBrush = null;
                close.Click += onCloseTab;
                Grid.SetColumn(txt, 0);
                Grid.SetColumn(close, 1);
                grid.Children.Add(close);

                tabs.Items.Add(new TabItem
                {
                    Tag = aFile.Path,
                    Header = grid,
                    Content = externalControl.Control,
                });
                ((TabItem)tabs.Items[tabs.Items.Count - 1]).MouseUp += EditorTabs_MouseUp;
                tabs.SelectedItem = tabs.Items[tabs.Items.Count - 1];
                return null;
            }
            return null;
        }
 public IDEEditor OpenFile(FileBaseItem aFile, int aLine)
 {
     if (Intellisense.Sources.SourceBuilder.HandlesExtension(System.IO.Path.GetExtension(aFile.Path)))
     {
         IDEEditor ret = OpenFile(aFile);
         ret.InvalidateArrange();
         new Thread(delegate()
         {
             Thread.Sleep(10);
             MainWindow.inst().Dispatcher.Invoke(delegate()
             {
                 ret.Editor.TextArea.Caret.Line = aLine;
                 ret.Editor.ScrollToLine(aLine);
                 ret.InvalidateArrange();
             });
         }).Start();
         return ret;
     }
     return null;
 }
 public ErrorLineHighlighter(FileBaseItem aFile)
 {
     file = aFile;
 }
        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. 22
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
            });
        }
 public void SetCode(FileBaseItem item)
 {
     try {
         this.item = item;
         editor.Text = File.ReadAllText(item.Path);
         changeChecker.code = editor.Text;
         changeChecker.IsDirty = false;
     }
     catch (Exception ex) {
         ErrorHandler.inst().Error(ex);
     }
 }