void InitFolding()
        {
            if (txtResult.SyntaxHighlighting == null)
            {
                foldingStrategyA = null;
            }
            else
            {
                foldingStrategyA = new BraceFoldingStrategy();

            }
            if (foldingStrategyA != null)
            {
                if (foldingManagerA == null)
                    foldingManagerA = FoldingManager.Install(txtResult.TextArea);
                foldingStrategyA.UpdateFoldings(foldingManagerA, textEditorA.Document);
            }
            else
            {
                if (foldingManagerA != null)
                {
                    FoldingManager.Uninstall(foldingManagerA);
                    foldingManagerA = null;
                }
            }            
        }
Example #2
0
        /// <summary>
        /// Creates a new TextEditor instance.
        /// </summary>
        public TextEditor()
            : this(new TextArea())
        {
            Options.ShowTabs = true;

            ShowLineNumbers = true;
            SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.Resources.LUA;
            TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(TextArea));
            TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.LuaIndentationStrategy(this);

            foldingManager = FoldingManager.Install(TextArea);
            foldingStrategy.UpdateFoldings(foldingManager, Document);

            foldingUpdateTimer = new DispatcherTimer();
            foldingUpdateTimer.Interval = TimeSpan.FromSeconds(1);
            foldingUpdateTimer.Tick += (o, e) => {
                if (isUpdated)
                {
                    foldingStrategy.UpdateFoldings(foldingManager, Document);
                    isUpdated = false;
                }
            };
            foldingUpdateTimer.Start();

            bracketRenderer = new BracketHighlightRenderer(TextArea.TextView);
            TextArea.Caret.PositionChanged += HighlightBrackets;

            TextArea.TextEntering += TextEditorTextAreaTextEntering;
            TextArea.PreviewKeyDown += TextArea_PreviewKeyDown;

            TextArea.TextView.MouseHover += TextViewMouseHover;
            TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped;
        }
        //public string SoapAction { get; set; }
        public EditorControl()
        {
            var host = new ElementHost();
              host.Size = new Size(200, 100);
              host.Location = new Point(100, 100);
              host.Dock = DockStyle.Fill;

              _editor = new ICSharpCode.AvalonEdit.TextEditor();
              _editor.FontFamily = new System.Windows.Media.FontFamily("Consolas");
              _editor.FontSize = 12.0;
              _editor.Options.ConvertTabsToSpaces = true;
              _editor.Options.EnableRectangularSelection = true;
              _editor.Options.IndentationSize = 2;
              _editor.ShowLineNumbers = true;
              _editor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinitionByExtension(".xml");
              _editor.TextArea.TextEntering += TextArea_TextEntering;
              _editor.TextArea.TextEntered += TextArea_TextEntered;
              _editor.TextArea.KeyDown += TextArea_KeyDown;
              host.Child = _editor;

              _editor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
              _foldingManager = FoldingManager.Install(_editor.TextArea);
              UpdateFoldings();

              var foldingUpdateTimer = new DispatcherTimer();
              foldingUpdateTimer.Interval = TimeSpan.FromSeconds(2);
              foldingUpdateTimer.Tick += delegate { UpdateFoldings(); };
              foldingUpdateTimer.Start();

              this.Controls.Add(host);
        }
 /// <summary>
 /// Uninstalls the folding manager.
 /// </summary>
 /// <exception cref="ArgumentException">The specified manager was not created using <see cref="Install"/>.</exception>
 public static void Uninstall(FoldingManager manager)
 {
     if (manager == null)
         throw new ArgumentNullException("manager");
     FoldingManagerInstallation installation = manager as FoldingManagerInstallation;
     if (installation != null)
     {
         installation.Uninstall();
     }
     else
     {
         throw new ArgumentException("FoldingManager was not created using FoldingManager.Install");
     }
 }
Example #5
0
        void InstallFoldingManager()
        {
            foldingManager = FoldingManager.Install(TextArea);

            foldingUpdateTimer = new DispatcherTimer();
            foldingUpdateTimer.Interval = TimeSpan.FromSeconds(1);
            foldingUpdateTimer.Tick += (o, e) =>
            {
                if (Document != null)
                    foldingStrategy.UpdateFoldings(foldingManager, Document);
            };
            foldingUpdateTimer.Start();

            TextArea.DocumentChanged += (o, e) => {
                if (foldingManager != null)
                    FoldingManager.Uninstall(foldingManager);
                foldingManager = FoldingManager.Install(o as TextArea);
            };
        }
Example #6
0
        public TextEditorControl()
        {
            InitializeComponent();

            m_helper = new ControlDataHelper<string>(this);
            m_helper.Options.Scrollable = true;
            m_helper.Initialise += new Action(m_helper_Initialise);

            SetSyntaxHighlighting("XML");
            textEditor.HorizontalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Auto;
            textEditor.Padding = new System.Windows.Thickness(5);

            m_foldingManager = FoldingManager.Install(textEditor.TextArea);

            textEditor.TextArea.TextEntering += TextEntering;
            textEditor.TextArea.TextEntered += TextEntered;
            textEditor.TextArea.KeyUp += KeyPressed;

            UpdateUndoRedoEnabled(true);
        }
Example #7
0
        public SvgPage()
        {
            InitializeComponent();

            textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML");
            TextEditorOptions options = textEditor.Options;

            if (options != null)
            {
                //options.AllowScrollBelowDocument = true;
                options.EnableHyperlinks      = true;
                options.EnableEmailHyperlinks = true;
                //options.ShowSpaces = true;
                //options.ShowTabs = true;
                //options.ShowEndOfLine = true;
            }

            textEditor.ShowLineNumbers = true;

            _foldingManager  = FoldingManager.Install(textEditor.TextArea);
            _foldingStrategy = new XmlFoldingStrategy();

            SearchPanel.Install(textEditor);
        }
Example #8
0
        public CodeControl()
        {
            var Res = Application.GetResourceStream(new Uri("pack://application:,,,/v8viewer;component/controls/1CV8Syntax.xshd", UriKind.Absolute));

            IHighlightingDefinition v8Highlighting;

            using (var s = Res.Stream)
            {
                using (XmlReader reader = new XmlTextReader(s))
                {
                    v8Highlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.
                                     HighlightingLoader.Load(reader, HighlightingManager.Instance);
                }
            }

            HighlightingManager.Instance.RegisterHighlighting("1CV8", new string[] { ".v8m" }, v8Highlighting);

            InitializeComponent();

            editor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(editor.TextArea));
            editor.ShowLineNumbers = true;

            foldingManager = FoldingManager.Install(editor.TextArea);

            editor.TextChanged += editor_TextChanged;
            editor.TextArea.Options.EnableHyperlinks           = false;
            editor.TextArea.Options.EnableVirtualSpace         = true;
            editor.TextArea.Options.EnableRectangularSelection = true;
            editor.TextArea.SelectionCornerRadius  = 0;
            editor.TextArea.Caret.PositionChanged += Caret_PositionChanged;

            foldingUpdateTimer          = new DispatcherTimer(DispatcherPriority.ContextIdle);
            foldingUpdateTimer.Interval = TimeSpan.FromSeconds(2);
            foldingUpdateTimer.Tick    += foldingUpdateTimer_Tick;
            foldingUpdateTimer.Start();
        }
Example #9
0
        public void Execute(TextViewContext context)
        {
            var textView = context.TextView;

            if (null == textView)
            {
                return;
            }
            var            editor         = textView.textEditor;
            FoldingManager foldingManager = context.TextView.FoldingManager;

            if (null == foldingManager)
            {
                return;
            }
            // TODO: or use Caret if position is not given?
            var posBox = context.Position;

            if (null == posBox)
            {
                return;
            }
            TextViewPosition pos = posBox.Value;
            // look for folding on this line:
            FoldingSection folding = foldingManager.GetNextFolding(editor.Document.GetOffset(pos.Line, 1));

            if (folding == null || editor.Document.GetLineByOffset(folding.StartOffset).LineNumber != pos.Line)
            {
                // no folding found on current line: find innermost folding containing the mouse position
                folding = foldingManager.GetFoldingsContaining(editor.Document.GetOffset(pos.Line, pos.Column)).LastOrDefault();
            }
            if (folding != null)
            {
                folding.IsFolded = !folding.IsFolded;
            }
        }
        private void Items_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            try
            {
                var item = (DetailItem)Items.SelectedItem;
                if (item != null)
                {
                    var text = item.Name;
                    if (foldingManager != null)
                    {
                        FoldingManager.Uninstall(foldingManager);
                    }
                    TextViewer.Document = new ICSharpCode.AvalonEdit.Document.TextDocument(item.Content);
                    foldingManager      = FoldingManager.Install(TextViewer.TextArea);
                    foldingStrategy.UpdateFoldings(foldingManager, TextViewer.Document);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #11
0
        /// <summary>
        /// constructor for type window
        /// </summary>
        public TypeWindow()
        {
            InitializeComponent();

            EditTimeTypeTextEditor.TextArea.TextEntering += TextEditor_TextEntering;
            EditTimeTypeTextEditor.TextArea.TextEntered  += EditTimeTypeTextEditor_TextEntered;
            RunTimeTypeTextEditor.TextArea.TextEntering  += TextEditor_TextEntering;
            RunTimeTypeTextEditor.TextArea.TextEntered   += RunTimeTypeTextEditor_TextEntered;

            EditTimeTypeTextEditor.Options.EnableHyperlinks      = false;
            EditTimeTypeTextEditor.Options.EnableEmailHyperlinks = false;
            RunTimeTypeTextEditor.Options.EnableHyperlinks       = false;
            RunTimeTypeTextEditor.Options.EnableEmailHyperlinks  = false;

            folding = new BraceFoldingStrategy();
            edittimeFoldingManager = FoldingManager.Install(EditTimeTypeTextEditor.TextArea);
            runtimeFoldingManager  = FoldingManager.Install(RunTimeTypeTextEditor.TextArea);
            folding.UpdateFoldings(edittimeFoldingManager, EditTimeTypeTextEditor.Document);
            folding.UpdateFoldings(runtimeFoldingManager, RunTimeTypeTextEditor.Document);

            //setip ctrl-f to single page code find
            edittimePanel = SearchPanel.Install(EditTimeTypeTextEditor);
            runtimePanel  = SearchPanel.Install(EditTimeTypeTextEditor);
        }
        /// <summary>
        /// Initializes the graph instance, setting default styles
        /// and creating a small sample graph.
        /// </summary>
        protected virtual void InitializeGraph()
        {
            // create the manager for the folding operations
            FoldingManager foldingManager = new FoldingManager();

            // create a view
            foldingView = foldingManager.CreateFoldingView();

            // and set it to the GraphControl
            graphControl.Graph = foldingView.Graph;

            // decorate the behavior of nodes
            NodeDecorator nodeDecorator = graphControl.Graph.GetDecorator().NodeDecorator;

            // adjust the insets so that labels are considered
            nodeDecorator.InsetsProviderDecorator.SetImplementationWrapper(
                delegate(INode node, INodeInsetsProvider insetsProvider) {
                if (insetsProvider != null)
                {
                    InsetsD insets = insetsProvider.GetInsets(node);
                    return(new LabelInsetsProvider(insets));
                }
                else
                {
                    return(new LabelInsetsProvider());
                }
            });

            //Constrain group nodes to at least the size of their labels
            nodeDecorator.SizeConstraintProviderDecorator.SetImplementationWrapper(
                (node, oldImpl) => new LabelSizeConstraintProvider(oldImpl));

            fixedGroupNodeLayout = graphControl.Graph.MapperRegistry.CreateMapper <INode, RectD?>("NodeLayouts");
            ReadSampleGraph();
            incrementalNodes.UnionWith(graphControl.Graph.Nodes);
        }
Example #13
0
		/// <summary>
		/// Creates a new SearchPanel and attaches it to a text area.
		/// </summary>
		public SearchPanel(TextArea textArea)
		{
			if (textArea == null)
				throw new ArgumentNullException("textArea");
			this.textArea = textArea;
			DataContext = this;
			InitializeComponent();
			
			textArea.TextView.Layers.Add(this);
			foldingManager = textArea.GetService(typeof(FoldingManager)) as FoldingManager;
			
			renderer = new SearchResultBackgroundRenderer();
			textArea.TextView.BackgroundRenderers.Add(renderer);
			textArea.Document.TextChanged += delegate { DoSearch(false); };
			this.Loaded += delegate { searchTextBox.Focus(); };
			
			useRegex.Checked     += ValidateSearchText;
			matchCase.Checked    += ValidateSearchText;
			wholeWords.Checked   += ValidateSearchText;
			
			useRegex.Unchecked   += ValidateSearchText;
			matchCase.Unchecked  += ValidateSearchText;
			wholeWords.Unchecked += ValidateSearchText;
		}
Example #14
0
        /// <summary>
        /// Creates a new TextEditor instance.
        /// </summary>
        public TextEditor()
            : this(new TextArea())
        {
            this.ShowLineNumbers = true;
            this.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.Resources.LUA;
            this.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(this.TextArea));
            this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.LuaIndentationStrategy(this);

            foldingManager = FoldingManager.Install(this.TextArea);
            foldingStrategy.UpdateFoldings(foldingManager, this.Document);

            foldingUpdateTimer = new DispatcherTimer();
            foldingUpdateTimer.Interval = TimeSpan.FromSeconds(1);
            foldingUpdateTimer.Tick += (o, e) => {
                if (this.isUpdated)
                {
                    foldingStrategy.UpdateFoldings(foldingManager, this.Document);
                    isUpdated = false;
                }
            };
            foldingUpdateTimer.Start();

            this.TextArea.TextEntering += TextEditorTextAreaTextEntering;
            this.TextArea.PreviewKeyDown += TextArea_PreviewKeyDown;

            this.TextArea.TextView.MouseHover += TextViewMouseHover;
            this.TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped;

            //#warning hack
            //var style = (Style)Application.Current.Resources.MergedDictionaries[0]["KamillaStyleControls"];
            //this.mToolTipStype = (Style)style.Resources[typeof(ToolTip)];
        }
Example #15
0
 private void TextArea_DocumentChanged(object sender, EventArgs e)
 {
     this.FoldingManager = FoldingManager.Install(this.AvalonEditor.TextArea);
     UpdateDocumentFoldings();
 }
Example #16
0
 protected CodeFoldingStrategy(CodeEditor codeEditor)
 {
     this.codeEditor = codeEditor;
     foldingManager  = FoldingManager.Install(codeEditor.TextEditor.TextArea);
 }
Example #17
0
 public FragmentView()
 {
     InitializeComponent();
     _foldingStrategy = new XmlFoldingStrategy();
     _foldingManager  = FoldingManager.Install(_edtFragment.TextArea);
 }
Example #18
0
 public void UpdateFolding(FoldingManager manager, TextDocument document)
 {
     foldingStrategy.UpdateFoldings(manager, document);
 }
Example #19
0
        /// <summary>
        /// Determine whether or not highlighting can be
        /// suppported by a particular folding strategy.
        /// </summary>
        /// <param name="syntaxHighlighting"></param>
        public void SetFolding(IHighlightingDefinition syntaxHighlighting)
        {
            if (syntaxHighlighting == null)
            {
                this.mFoldingStrategy = null;
            }
            else
            {
                switch (syntaxHighlighting.Name)
                {
                case "XML":
                case "HTML":
                    mFoldingStrategy = new XmlFoldingStrategy()
                    {
                        ShowAttributesWhenFolded = true
                    };
                    this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
                    break;

                case "C#":
                    this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(this.Options);
                    mFoldingStrategy = new CSharpBraceFoldingStrategy();
                    break;

                case "C++":
                case "PHP":
                case "Java":
                    this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(this.Options);
                    mFoldingStrategy = new CSharpBraceFoldingStrategy();
                    break;

                case "VBNET":
                    this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(this.Options);
                    mFoldingStrategy = new VBNetFoldingStrategy();
                    break;

                default:
                    this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
                    mFoldingStrategy = null;
                    break;
                }

                if (mFoldingStrategy != null)
                {
                    if (this.Document != null)
                    {
                        if (mFoldingManager == null)
                        {
                            mFoldingManager = FoldingManager.Install(this.TextArea);
                        }

                        this.mFoldingStrategy.UpdateFoldings(mFoldingManager, this.Document);
                    }
                    else
                    {
                        this.mInstallFoldingManager = true;
                    }
                }
                else
                {
                    if (mFoldingManager != null)
                    {
                        FoldingManager.Uninstall(mFoldingManager);
                        mFoldingManager = null;
                    }
                }
            }
        }
Example #20
0
        public void UpdateFoldings(FoldingManager manager, TextDocument document)
        {
            IEnumerable <NewFolding> foldings = CreateNewFoldings(document, out int firstErrorOffset);

            manager.UpdateFoldings(foldings, firstErrorOffset);
        }
Example #21
0
        public void LoadDocument(string documentFileName)
        {
            if (textEditor == null || String.IsNullOrEmpty(documentFileName))
            {
                return;
            }

            this.UnloadDocument();

            string fileExt = Path.GetExtension(documentFileName);

            if (String.Equals(fileExt, ".zaml", StringComparison.OrdinalIgnoreCase))
            {
                using (FileStream fileStream = File.OpenRead(documentFileName))
                {
                    using (GZipStream zipStream =
                               new GZipStream(fileStream, CompressionMode.Decompress))
                    {
                        // Text Editor does not work with this stream, so we read the data to memory stream...
                        MemoryStream memoryStream = new MemoryStream();
                        // Use this method is used to read all bytes from a stream.
                        int    totalCount = 0;
                        int    bufferSize = 512;
                        byte[] buffer     = new byte[bufferSize];
                        while (true)
                        {
                            int bytesRead = zipStream.Read(buffer, 0, bufferSize);
                            if (bytesRead == 0)
                            {
                                break;
                            }
                            else
                            {
                                memoryStream.Write(buffer, 0, bytesRead);
                            }
                            totalCount += bytesRead;
                        }

                        if (totalCount > 0)
                        {
                            memoryStream.Position = 0;
                        }

                        textEditor.Load(memoryStream);

                        memoryStream.Close();
                    }
                }
            }
            else
            {
                textEditor.Load(documentFileName);
            }

            if (_foldingManager == null || _foldingStrategy == null)
            {
                _foldingManager  = FoldingManager.Install(textEditor.TextArea);
                _foldingStrategy = new XmlFoldingStrategy();
            }

            _foldingStrategy.UpdateFoldings(_foldingManager, textEditor.Document);
        }
		public ParserFoldingStrategy(TextArea textArea)
		{
			this.textArea = textArea;
			foldingManager = FoldingManager.Install(textArea);
		}
Example #23
0
        /// <summary>
        /// Method is invoked when the Document or SyntaxHighlightingDefinition dependency property is changed.
        /// This change should always lead to removing and re-installing the correct folding manager and strategy.
        /// </summary>
        /// <param name="e"></param>
        private void OnChangedFoldingInstance(DependencyPropertyChangedEventArgs e)
        {
            try
            {
                // Clean up last installation of folding manager and strategy
                if (mFoldingManager != null)
                {
                    FoldingManager.Uninstall(mFoldingManager);
                    mFoldingManager = null;
                }

                this.mFoldingStrategy = null;
            }
            catch
            {
            }

#pragma warning disable CS8073 // The result of the expression is always the same since a value of this type is never equal to 'null'
            if (e == null)
#pragma warning restore CS8073 // The result of the expression is always the same since a value of this type is never equal to 'null'
            {
                return;
            }

            var syntaxHighlighting = e.NewValue as IHighlightingDefinition;
            if (syntaxHighlighting == null)
            {
                return;
            }

            switch (syntaxHighlighting.Name)
            {
            case "XML":
                mFoldingStrategy = new XmlFoldingStrategy();
                this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
                break;

            case "C#":
            case "C++":
            case "PHP":
            case "Java":
                this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(this.Options);
                mFoldingStrategy = new BraceFoldingStrategy();
                break;

            default:
                this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
                mFoldingStrategy = null;
                break;
            }

            if (mFoldingStrategy != null)
            {
                if (mFoldingManager == null)
                {
                    mFoldingManager = FoldingManager.Install(this.TextArea);
                }

                UpdateFoldings();
            }
            else
            {
                if (mFoldingManager != null)
                {
                    FoldingManager.Uninstall(mFoldingManager);
                    mFoldingManager = null;
                }
            }
        }
 internal void SetAvalonTextEditor(TextEditor editor)
 {
     AvalonTextEditor = editor;
     _foldingManager  = FoldingManager.Install(this.AvalonTextEditor.TextArea);
     _xmlFolding      = new XmlFoldingStrategy();
 }
    public CodeEditor()
    {
      InitializeComponent();

      _foldingManager = FoldingManager.Install(this.editor.TextArea);
      UpdateFoldings();

      _foldingUpdateTimer.Interval = TimeSpan.FromSeconds(2);
      _foldingUpdateTimer.Tick += delegate { UpdateFoldings(); };
      _foldingUpdateTimer.Start();

      Editor.FontFamily = _fixedWidth;
      Editor.FontSize = 12.0;
      Editor.Options.ConvertTabsToSpaces = true;
      Editor.Options.EnableRectangularSelection = true;
      Editor.Options.IndentationSize = 2;
      Editor.ShowLineNumbers = true;
      Editor.TextArea.MouseRightButtonDown += TextArea_MouseRightButtonDown;
      Editor.TextArea.PreviewKeyDown += TextArea_PreviewKeyDown;
      Editor.TextArea.TextEntering += TextArea_TextEntering;
      Editor.TextArea.TextEntered += TextArea_TextEntered;
      Editor.TextArea.KeyDown += TextArea_KeyDown;
      Editor.TextArea.TextView.MouseHover += TextView_MouseHover;
      //Editor.TextArea.TextView.MouseHoverStopped += TextView_MouseHoverStopped;
      //Editor.TextArea.TextView.VisualLinesChanged += TextView_VisualLinesChanged;
      Editor.TextArea.SelectionChanged += TextArea_SelectionChanged;
      Editor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
      //Editor.TextChanged += editor_TextChanged;

      Editor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
    }
        private async void files_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //files.IsEnabled = false;
            e.Handled = true;
            try
            {
                var entry = files.SelectedItem as BarEntry;
                if (entry == null)
                {
                    ImageViewer.Visibility = Visibility.Collapsed;
                    XMLViewer.Visibility   = Visibility.Collapsed;
                    //files.IsEnabled = true;
                    return;
                }
                var entries = files.SelectedItems.Cast <BarEntry>().ToList();
                SelectedSize = entries.Sum(x => (long)x.FileSize2);
                await file.readFile(entry);

                if (outputDevice != null)
                {
                    outputDevice.Dispose();
                    outputDevice = null;
                }
                if (mp3File != null)
                {
                    mp3File.Dispose();
                    mp3File = null;
                }
                if (waveFile != null)
                {
                    waveFile.Dispose();
                    waveFile = null;
                }
                point      = new Point();
                validPoint = false;
                ImagePreview.RenderTransform = new TranslateTransform();

                if (file.Preview != null)
                {
                    XMLViewer.Text = file.Preview.Text;
                    if (foldingManager != null)
                    {
                        FoldingManager.Uninstall(foldingManager);
                        foldingManager = null;
                    }
                    foldingManager = FoldingManager.Install(XMLViewer.TextArea);
                    if (entry.Extension == ".XMB" || entry.Extension == ".XML" || entry.Extension == ".SHP" || entry.Extension == ".LGT" || entry.Extension == ".TXT" || entry.Extension == ".CFG" || entry.Extension == ".XAML" || entry.Extension == ".PY")
                    {
                        var foldingStrategy = new XmlFoldingStrategy();
                        foldingStrategy.UpdateFoldings(foldingManager, XMLViewer.Document);
                    }
                    else
                    if (entry.Extension == ".XS")
                    {
                        var foldingStrategy = new BraceFoldingStrategy();
                        foldingStrategy.UpdateFoldings(foldingManager, XMLViewer.Document);
                    }
                }

                if (entry.Extension == ".WAV")
                {
                    using (outputDevice = new WaveOutEvent())
                        using (waveFile = new WaveFileReader(file.audio))
                        {
                            outputDevice.Init(waveFile);
                            outputDevice.Play();
                            while (outputDevice.PlaybackState == PlaybackState.Playing)
                            {
                                await Task.Delay(500);
                            }
                        }
                    ImageViewer.Visibility = Visibility.Collapsed;
                    XMLViewer.Visibility   = Visibility.Collapsed;
                }
                if (entry.Extension == ".MP3")
                {
                    //var w = new WaveFormat(new BinaryReader(file.audio));
                    //MessageBox.Show(w.Encoding.ToString());
                    using (outputDevice = new WaveOutEvent())
                        using (mp3File = new Mp3FileReader(file.audio))
                        {
                            outputDevice.Init(mp3File);
                            outputDevice.Play();
                            while (outputDevice.PlaybackState == PlaybackState.Playing)
                            {
                                await Task.Delay(500);
                            }
                        }
                    ImageViewer.Visibility = Visibility.Collapsed;
                    XMLViewer.Visibility   = Visibility.Collapsed;
                }
                else
                if (entry.Extension == ".DDT")
                {
                    ImagePreview.Source    = file.PreviewDdt.Bitmap;
                    XMLViewer.Visibility   = Visibility.Collapsed;
                    ImageViewer.Visibility = Visibility.Visible;
                }
                else
                if (entry.Extension == ".TGA" || entry.Extension == ".BMP" || entry.Extension == ".PNG" || entry.Extension == ".CUR" || entry.Extension == ".JPG")
                {
                    ImagePreview.Source    = file.PreviewImage;
                    XMLViewer.Visibility   = Visibility.Collapsed;
                    ImageViewer.Visibility = Visibility.Visible;
                }
                else
                if (entry.Extension == ".XMB" || entry.Extension == ".XML" || entry.Extension == ".SHP" || entry.Extension == ".LGT" || entry.Extension == ".XS" || entry.Extension == ".TXT" || entry.Extension == ".CFG" || entry.Extension == ".XAML" || entry.Extension == ".PY")
                {
                    ImageViewer.Visibility = Visibility.Collapsed;
                    XMLViewer.Visibility   = Visibility.Visible;
                }
                else
                {
                    ImageViewer.Visibility = Visibility.Collapsed;
                    XMLViewer.Visibility   = Visibility.Collapsed;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            //files.IsEnabled = true;
        }
Example #27
0
 public void UpdateFoldings(FoldingManager manager, TextDocument document)
 {
     manager.UpdateFoldings(CreateNewFoldings(document), 0);
 }
Example #28
0
        /// <summary>
        /// Shows the given output in the text view.
        /// </summary>
        void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null, DecompilerTextViewState state = null)
        {
            Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength);
            Stopwatch w = Stopwatch.StartNew();

            ClearLocalReferenceMarks();
            textEditor.ScrollToHome();
            if (foldingManager != null)
            {
                FoldingManager.Uninstall(foldingManager);
                foldingManager = null;
            }
            textEditor.Document                  = null; // clear old document while we're changing the highlighting
            uiElementGenerator.UIElements        = textOutput.UIElements;
            referenceElementGenerator.References = textOutput.References;
            references       = textOutput.References;
            definitionLookup = textOutput.DefinitionLookup;
            textEditor.SyntaxHighlighting = highlighting;

            // Change the set of active element generators:
            foreach (var elementGenerator in activeCustomElementGenerators)
            {
                textEditor.TextArea.TextView.ElementGenerators.Remove(elementGenerator);
            }
            activeCustomElementGenerators.Clear();

            foreach (var elementGenerator in textOutput.elementGenerators)
            {
                textEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator);
                activeCustomElementGenerators.Add(elementGenerator);
            }

            Debug.WriteLine("  Set-up: {0}", w.Elapsed); w.Restart();
            textEditor.Document = textOutput.GetDocument();
            Debug.WriteLine("  Assigning document: {0}", w.Elapsed); w.Restart();
            if (textOutput.Foldings.Count > 0)
            {
                if (state != null)
                {
                    state.RestoreFoldings(textOutput.Foldings);
                    textEditor.ScrollToVerticalOffset(state.VerticalOffset);
                    textEditor.ScrollToHorizontalOffset(state.HorizontalOffset);
                }
                foldingManager = FoldingManager.Install(textEditor.TextArea);
                foldingManager.UpdateFoldings(textOutput.Foldings.OrderBy(f => f.StartOffset), -1);
                Debug.WriteLine("  Updating folding: {0}", w.Elapsed); w.Restart();
            }

            // update debugger info
            DebugInformation.CodeMappings = textOutput.DebuggerMemberMappings.ToDictionary(m => m.MetadataToken);

            // update class bookmarks
            var document = textEditor.Document;

            manager.Bookmarks.Clear();
            foreach (var pair in textOutput.DefinitionLookup.definitions)
            {
                MemberReference member = pair.Key as MemberReference;
                int             offset = pair.Value;
                if (member != null)
                {
                    int line = document.GetLocation(offset).Line;
                    manager.Bookmarks.Add(new MemberBookmark(member, line));
                }
            }
        }
Example #29
0
        void TextEditorMouseHover(object sender, MouseEventArgs e)
        {
            Debug.Assert(sender == this);
            ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(this.Adapter);
            var pos = this.TextArea.TextView.GetPositionFloor(e.GetPosition(this.TextArea.TextView) + this.TextArea.TextView.ScrollOffset);

            args.InDocument = pos.HasValue;
            if (pos.HasValue)
            {
                args.LogicalPosition = AvalonEditDocumentAdapter.ToLocation(pos.Value.Location);
            }

            if (args.InDocument)
            {
                int offset = args.Editor.Document.PositionToOffset(args.LogicalPosition.Line, args.LogicalPosition.Column);

                FoldingManager foldings = this.Adapter.GetService(typeof(FoldingManager)) as FoldingManager;
                if (foldings != null)
                {
                    var            foldingsAtOffset = foldings.GetFoldingsAt(offset);
                    FoldingSection collapsedSection = foldingsAtOffset.FirstOrDefault(section => section.IsFolded);

                    if (collapsedSection != null)
                    {
                        args.SetToolTip(GetTooltipTextForCollapsedSection(collapsedSection));
                    }
                }

                TextMarkerService textMarkerService = this.Adapter.GetService(typeof(ITextMarkerService)) as TextMarkerService;
                if (textMarkerService != null)
                {
                    var         markersAtOffset   = textMarkerService.GetMarkersAtOffset(offset);
                    ITextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);

                    if (markerWithToolTip != null)
                    {
                        args.SetToolTip(markerWithToolTip.ToolTip);
                    }
                }
            }

            if (!args.Handled)
            {
                // if request wasn't handled by a marker, pass it to the ToolTipRequestService
                ToolTipRequestService.RequestToolTip(args);
            }

            if (args.ContentToShow != null)
            {
                var contentToShowITooltip = args.ContentToShow as ITooltip;

                if (contentToShowITooltip != null && contentToShowITooltip.ShowAsPopup)
                {
                    if (!(args.ContentToShow is UIElement))
                    {
                        throw new NotSupportedException("Content to show in Popup must be UIElement: " + args.ContentToShow);
                    }
                    if (popup == null)
                    {
                        popup = CreatePopup();
                    }
                    // if popup was only first level, hovering somewhere else closes it
                    if (TryCloseExistingPopup(false))
                    {
                        // when popup content decides to close, close the popup
                        contentToShowITooltip.Closed += (closedSender, closedArgs) => { popup.IsOpen = false; };
                        popup.Child = (UIElement)args.ContentToShow;
                        //ICSharpCode.SharpDevelop.Debugging.DebuggerService.CurrentDebugger.IsProcessRunningChanged
                        SetPopupPosition(popup, e);
                        popup.IsOpen = true;
                    }
                    e.Handled = true;
                }
                else
                {
                    if (toolTip == null)
                    {
                        toolTip         = new ToolTip();
                        toolTip.Closed += ToolTipClosed;
                    }
                    toolTip.PlacementTarget = this;                     // required for property inheritance

                    if (args.ContentToShow is string)
                    {
                        toolTip.Content = new TextBlock
                        {
                            Text         = args.ContentToShow as string,
                            TextWrapping = TextWrapping.Wrap
                        };
                    }
                    else
                    {
                        toolTip.Content = args.ContentToShow;
                    }

                    toolTip.IsOpen = true;
                    e.Handled      = true;
                }
            }
            else
            {
                // close popup if mouse hovered over empty area
                if (popup != null)
                {
                    e.Handled = true;
                }
                TryCloseExistingPopup(false);
            }
        }
Example #30
0
 private IniFoldingStrategy(TextEditor editor)
 {
     _foldingManager      = FoldingManager.Install(_editor.TextArea);
     _editor              = editor;
     _editor.TextChanged += OnTextChanged;
 }
 public ParserFoldingStrategy(TextArea textArea)
 {
     this.textArea  = textArea;
     foldingManager = FoldingManager.Install(textArea);
 }
Example #32
0
        public bool LoadDocument(string documentFileName)
        {
            if (textEditor == null || string.IsNullOrWhiteSpace(documentFileName))
            {
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(_currentFileName) && File.Exists(_currentFileName))
            {
                // Prevent reloading the same file, just in case we are editing...
                if (string.Equals(documentFileName, _currentFileName, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            string fileExt = Path.GetExtension(documentFileName);

            if (string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase))
            {
                using (FileStream fileStream = File.OpenRead(documentFileName))
                {
                    using (GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Decompress))
                    {
                        // Text Editor does not work with this stream, so we read the data to memory stream...
                        MemoryStream memoryStream = new MemoryStream();
                        // Use this method is used to read all bytes from a stream.
                        int    totalCount = 0;
                        int    bufferSize = 512;
                        byte[] buffer     = new byte[bufferSize];
                        while (true)
                        {
                            int bytesRead = zipStream.Read(buffer, 0, bufferSize);
                            if (bytesRead == 0)
                            {
                                break;
                            }
                            else
                            {
                                memoryStream.Write(buffer, 0, bytesRead);
                            }
                            totalCount += bytesRead;
                        }

                        if (totalCount > 0)
                        {
                            memoryStream.Position = 0;
                        }

                        textEditor.Load(memoryStream);

                        memoryStream.Close();
                    }
                }
            }
            else
            {
                textEditor.Load(documentFileName);
            }

            if (_foldingManager == null || _foldingStrategy == null)
            {
                _foldingManager  = FoldingManager.Install(textEditor.TextArea);
                _foldingStrategy = new XmlFoldingStrategy();
            }
            _foldingStrategy.UpdateFoldings(_foldingManager, textEditor.Document);

            _currentFileName = documentFileName;

            txtFileName.Text = _currentFileName;

            return(true);
        }
Example #33
0
 public static IFoldingView CreateManagedView(this FoldingManager manager)
 {
     return(manager.CreateFoldingView());
 }
 public void ResetFoldingManager()
 {
   if (_foldingManager != null)
     FoldingManager.Uninstall(_foldingManager);
   _foldingManager = FoldingManager.Install(this.editor.TextArea);
   UpdateFoldings();
 }
 private void SetDefaultFoldings()
 {
     this._foldingStrategy = new CommandFoldingStrategy();
     this._foldingManager  = FoldingManager.Install(this.TextArea);
     this._foldingStrategy.UpdateFoldings(this._foldingManager, this.Document);
 }
 public void Dispose()
 {
   _helper = null;
   _foldingManager = null;
   _foldingStrategy = null;
   if (_foldingUpdateTimer != null)
     _foldingUpdateTimer.Stop();
   _foldingUpdateTimer = null;
 }
        public CSLEditorControl()
        {
            InitializeComponent();

            // Toolbar
            ButtonNew.Icon        = Icons.GetAppIcon(Icons.New);
            ButtonNew.Caption     = "New";
            ButtonNew.Click      += ButtonNew_Click;
            ButtonOpen.Caption    = "Open";
            ButtonOpen.Icon       = Icons.GetAppIcon(Icons.Open);
            ButtonOpen.Click     += ButtonOpen_Click;
            ButtonSave.Caption    = "Save ";
            ButtonSave.Icon       = Icons.GetAppIcon(Icons.Save);
            ButtonSave.Click     += ButtonSave_Click;
            ButtonSaveAs.Caption  = "Save As";
            ButtonSaveAs.Icon     = Icons.GetAppIcon(Icons.SaveAs);
            ButtonSaveAs.Click   += ButtonSaveAs_Click;
            ButtonRefresh.Caption = "Refresh (F5)";
            ButtonRefresh.Icon    = Icons.GetAppIcon(Icons.Refresh);
            ButtonRefresh.Click  += ButtonRefresh_Click;
            ButtonHelp.Caption    = "Help";
            ButtonHelp.Icon       = Icons.GetAppIcon(Icons.Help);
            ButtonHelp.Click     += ButtonHelp_Click;



            // Fix the DualTab
            DualTabTags.Children.Clear();
            DualTabTags.AddContent("CSL", "CSL", null, false, false, ObjCSLEditorPanel);
            DualTabTags.AddContent("BibTeX", "BibTeX", null, false, false, ObjBibTexEditorPanel);
            DualTabTags.AddContent("JavaScript", "JavaScript", null, false, false, ObjJavaScriptEditorPanel);
            DualTabTags.MakeActive("CSL");
            DualTabTags.TabPosition = DualTabbedLayout.TabPositions.Sides;

            DragToEditorManager.RegisterControl(ObjCSLEditor);
            DragToEditorManager.RegisterControl(ObjBibTexEditor);
            DragToEditorManager.RegisterControl(ObjJavaScriptEditor);

            // Code folding
            folding_manager  = FoldingManager.Install(ObjCSLEditor.TextArea);
            folding_strategy = new XmlFoldingStrategy();
            folding_strategy.ShowAttributesWhenFolded = true;
            ObjCSLEditor.TextArea.Options.ShowSpaces  = true;
            ObjCSLEditor.TextArea.Options.ShowTabs    = true;
            ObjCSLEditor.TextArea.Options.ShowBoxForControlCharacters             = true;
            ObjCSLEditor.TextArea.Options.EnableHyperlinks                        = true;
            ObjCSLEditor.TextArea.Options.EnableEmailHyperlinks                   = true;
            ObjCSLEditor.TextArea.Options.RequireControlModifierForHyperlinkClick = true;
            ObjCSLEditor.TextArea.Options.EnableRectangularSelection              = true;
            ObjCSLEditor.TextArea.Options.EnableTextDragDrop                      = true;
            ObjCSLEditor.TextArea.Options.CutCopyWholeLine                        = true;

            // Events
            ObjCSLEditor.TextChanged    += ObjCSLEditor_TextChanged;
            ObjBibTexEditor.TextChanged += ObjBibTexEditor_TextChanged;

            // Load the samples
            string sample_csl_filename = ConfigurationManager.Instance.StartupDirectoryForQiqqa + @"InCite\styles\apa.csl";

            ObjCSLEditor.Text = File.ReadAllText(sample_csl_filename);
            string sample_bibtex_filename = ConfigurationManager.Instance.StartupDirectoryForQiqqa + @"InCite\CSLEditorStuff\SampleBibTeX.txt";

            ObjBibTexEditor.Text = File.ReadAllText(sample_bibtex_filename);

            // Bind the keys
            this.PreviewKeyDown += CSLEditorControl_PreviewKeyDown;
        }
Example #38
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
            });
        }
Example #39
0
        private void addPage()
        {
            try
            {
                if (build == max)
                {
                    sendMsgToStatus("已自动拦截超出的载体");
                    return;
                }
                #region start
                // 1 : 1.1
                MetroFramework.Controls.MetroTabPage         nPage = new MetroFramework.Controls.MetroTabPage();
                System.Windows.Forms.Integration.ElementHost nHost = new System.Windows.Forms.Integration.ElementHost();

                // 1.2
                //nHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                //| System.Windows.Forms.AnchorStyles.Left)
                //| System.Windows.Forms.AnchorStyles.Right)));
                nHost.Dock          = DockStyle.Fill;
                nHost.BackColor     = System.Drawing.Color.White;
                nHost.Location      = new System.Drawing.Point(0, 0);
                nHost.Name          = "eleHost" + build;
                nHost.Size          = new System.Drawing.Size(756, 313);
                nHost.TabIndex      = 2;
                nHost.ChildChanged += new System.EventHandler <System.Windows.Forms.Integration.ChildChangedEventArgs>(this.eleCodeBox_ChildChanged);
                nHost.Child         = null;

                // 1.3
                this.mtp.Controls.Add(nPage);

                // 1.4
                nPage.Controls.Add(nHost);
                nPage.HorizontalScrollbarBarColor         = true;
                nPage.HorizontalScrollbarHighlightOnWheel = false;
                nPage.HorizontalScrollbarSize             = 10;
                nPage.Location = new System.Drawing.Point(4, 38);
                nPage.Name     = "nPage" + build;
                nPage.Size     = new System.Drawing.Size(756, 313);
                nPage.TabIndex = 0;
                nPage.Text     = "AreaCode" + (build + 1);
                nPage.UseVisualStyleBackColor           = true;
                nPage.VerticalScrollbarBarColor         = true;
                nPage.VerticalScrollbarHighlightOnWheel = false;
                nPage.VerticalScrollbarSize             = 10;
                // done

                // 2
                this.codeArea[build] = new TextEditor
                {
                    HorizontalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Hidden,
                    ShowLineNumbers = true,
                    Padding         = new System.Windows.Thickness(15),
                    FontFamily      = new FontFamily("Consolas"),
                    FontSize        = 13
                };
                // done


                // 3 : 3.1
                nHost.Child = codeArea[build];
                SearchPanel.Install(codeArea[build].TextArea);

                // 3.2
                string   name     = Assembly.GetExecutingAssembly().GetName().Name + ".Python.xshd";
                Assembly assembly = Assembly.GetExecutingAssembly();
                using (Stream s = assembly.GetManifestResourceStream(name))
                {
                    using (XmlTextReader reader = new XmlTextReader(s))
                    {
                        var xshd = HighlightingLoader.LoadXshd(reader);
                        codeArea[build].SyntaxHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance);
                    }
                }

                // 3.3
                codeArea[build].TextArea.TextEntering += codebox_TextArea_TextEntering;
                codeArea[build].TextArea.TextEntered  += codebox_TextArea_TextEntered;

                // 3.4
                foldingManager = FoldingManager.Install(codeArea[build].TextArea);
                foldingStrategy.UpdateFoldings(foldingManager, codeArea[build].Document);

                // 3.5
                codeArea[build].KeyUp += new System.Windows.Input.KeyEventHandler(run_KeyUp);
                // done
                #endregion
                ++build;
            }
            catch (Exception ex)
            {
                PyCodeConfig.Config.writeConfiguration(LogPath, DateTime.Now.Date.ToString(), DateTime.Now.TimeOfDay.ToString(), ex.ToString());
            }
        }
        public void UpdateFoldings(FoldingManager manager, TextDocument document)
        {
            var newFoldings = CreateNewFoldings(document, out var firstErrorOffset);

            manager.UpdateFoldings(newFoldings, firstErrorOffset);
        }
Example #41
0
        public EditorElement(string filePath)
        {
            InitializeComponent();

            bracketSearcher                     = new SPBracketSearcher();
            bracketHighlightRenderer            = new BracketHighlightRenderer(editor.TextArea.TextView);
            editor.TextArea.IndentationStrategy = new EditorIndetationStrategy();

            FadeJumpGridIn  = (Storyboard)Resources["FadeJumpGridIn"];
            FadeJumpGridOut = (Storyboard)Resources["FadeJumpGridOut"];

            KeyDown += EditorElement_KeyDown;

            editor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
            editor.TextArea.SelectionChanged      += TextArea_SelectionChanged;
            editor.TextArea.PreviewKeyDown        += TextArea_PreviewKeyDown;
            editor.PreviewMouseWheel     += PrevMouseWheel;
            editor.MouseDown             += editor_MouseDown;
            editor.TextArea.TextEntered  += TextArea_TextEntered;
            editor.TextArea.TextEntering += TextArea_TextEntering;

            var fInfo = new FileInfo(filePath);

            if (fInfo.Exists)
            {
                fileWatcher = new FileSystemWatcher(fInfo.DirectoryName)
                {
                    IncludeSubdirectories = false
                };
                fileWatcher.NotifyFilter        = NotifyFilters.Size | NotifyFilters.LastWrite;
                fileWatcher.Filter              = "*" + fInfo.Extension;
                fileWatcher.Changed            += fileWatcher_Changed;
                fileWatcher.EnableRaisingEvents = true;
            }
            else
            {
                fileWatcher = null;
            }

            _FullFilePath = filePath;
            editor.Options.ConvertTabsToSpaces      = false;
            editor.Options.EnableHyperlinks         = false;
            editor.Options.EnableEmailHyperlinks    = false;
            editor.Options.HighlightCurrentLine     = true;
            editor.Options.AllowScrollBelowDocument = true;
            editor.Options.ShowSpaces             = Program.OptionsObject.Editor_ShowSpaces;
            editor.Options.ShowTabs               = Program.OptionsObject.Editor_ShowTabs;
            editor.Options.IndentationSize        = Program.OptionsObject.Editor_IndentationSize;
            editor.TextArea.SelectionCornerRadius = 0.0;
            editor.Options.ConvertTabsToSpaces    = Program.OptionsObject.Editor_ReplaceTabsToWhitespace;

            Brush currentLineBackground = new SolidColorBrush(Color.FromArgb(0x20, 0x88, 0x88, 0x88));
            Brush currentLinePenBrush   = new SolidColorBrush(Color.FromArgb(0x30, 0x88, 0x88, 0x88));

            currentLinePenBrush.Freeze();
            var currentLinePen = new Pen(currentLinePenBrush, 1.0);

            currentLineBackground.Freeze();
            currentLinePen.Freeze();
            editor.TextArea.TextView.CurrentLineBackground = currentLineBackground;
            editor.TextArea.TextView.CurrentLineBorder     = currentLinePen;

            editor.FontFamily = new FontFamily(Program.OptionsObject.Editor_FontFamily);
            editor.WordWrap   = Program.OptionsObject.Editor_WordWrap;
            UpdateFontSize(Program.OptionsObject.Editor_FontSize, false);

            colorizeSelection = new ColorizeSelection();
            editor.TextArea.TextView.LineTransformers.Add(colorizeSelection);
            editor.SyntaxHighlighting = new AeonEditorHighlighting();

            LoadAutoCompletes();

            using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var reader = FileReader.OpenStream(fs, Encoding.UTF8))
                {
                    var source = reader.ReadToEnd();
                    source = source.Replace("\r\n", "\n").Replace("\r", "\n")
                             .Replace("\n", "\r\n"); //normalize line endings
                    editor.Text = source;
                }
            }

            _NeedsSave = false;

            Language_Translate(true); //The Fontsize and content must be loaded

            var encoding = new UTF8Encoding(false);

            editor.Encoding = encoding; //let them read in whatever encoding they want - but save in UTF8

            foldingManager  = FoldingManager.Install(editor.TextArea);
            foldingStrategy = new SPFoldingStrategy();
            foldingStrategy.UpdateFoldings(foldingManager, editor.Document);

            regularyTimer          = new Timer(500.0);
            regularyTimer.Elapsed += regularyTimer_Elapsed;
            regularyTimer.Start();

            AutoSaveTimer          = new Timer();
            AutoSaveTimer.Elapsed += AutoSaveTimer_Elapsed;
            StartAutoSaveTimer();

            CompileBox.IsChecked = filePath.EndsWith(".sp");
        }
Example #42
0
        public static void UpdateFolding(FoldingManager manager, TextDocument document, IDocumentItem morestachioDocument)
        {
            var foldings = CreateNewFoldings(document, morestachioDocument);

            manager.UpdateFoldings(foldings, -1);
        }
Example #43
0
        private void UpdateFolds()
        {
            var editorOptions = Options as EditorOptions;
            var flag = editorOptions != null && editorOptions.EnableFolding;
            if (SyntaxHighlighting == null)
            {
                _foldingStrategy = null;
            }
            if (File.Exists(Filename))
            {
                if (Path.GetExtension(Filename) == ".xml" || Path.GetExtension(Filename) == ".cfg")
                {
                    _foldingStrategy = new XmlFoldingStrategy();
                }
                else
                {
                    if (FileLanguage != null)
                    {
                        _foldingStrategy = FileLanguage.FoldingStrategy;
                    }
                }
                if (_foldingStrategy != null && flag)
                {
                    if (_foldingManager == null)
                    {
                        _foldingManager = FoldingManager.Install(TextArea);
                    }

                    var xmlStrategy = _foldingStrategy as XmlFoldingStrategy;
                    if (xmlStrategy != null)
                    {
                        xmlStrategy.UpdateFoldings(_foldingManager, Document);
                    }
                    else
                    {
                        ((AbstractFoldingStrategy)_foldingStrategy).UpdateFoldings(_foldingManager, Document);
                    }

                    RegisterFoldTitles();
                }
                else
                {
                    if (_foldingManager != null)
                    {
                        FoldingManager.Uninstall(_foldingManager);
                        _foldingManager = null;
                    }
                }
            }
        }