protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            // Configure XML folding strategy:
            this.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
            var xmlFoldingStrategy = new XmlFoldingStrategy();
            var xmlFoldingManager  = FoldingManager.Install(this.TextArea);

            try
            {
                xmlFoldingStrategy.UpdateFoldings(xmlFoldingManager, this.Document);
            }
            catch (XmlException)
            {
                // Nothing
            }

            if (this.Model != null)
            {
                // This may be the case when the designer in VS wants to render the view
                this.Model.Tick += (object sender, EventArgs args) =>
                {
                    try
                    {
                        xmlFoldingStrategy.UpdateFoldings(xmlFoldingManager, this.Document);
                    }
                    catch (XmlException)
                    {
                        // Nothing. The text in the result does not have to be an XML document.
                    }
                };
            }
        }
Пример #2
0
 public void UpdateFolding()
 {
     try
     {
         _strategy.UpdateFoldings(_sourceXsltFoldingManager, SourceXslt.Document);
         _strategy.UpdateFoldings(_sourceXmlFoldingManager, SourceXml.Document);
         _strategy.UpdateFoldings(_outputXmlFoldingManager, OutputXml.Document);
     }
     catch
     {
         Console.WriteLine(@"Folding error");
     }
 }
Пример #3
0
 public void LoadData()
 {
     if (!_previouslyLoaded)
     {
         _textDocument       = new TextDocument();
         TextEditor.Document = _textDocument;
         _foldingManager     = FoldingManager.Install(TextEditor.TextArea);
         _foldingStrategy    = new XmlFoldingStrategy();
     }
     _textDocument.Text = _documentManager.Document.ToString();
     _foldingStrategy.UpdateFoldings(_foldingManager, TextEditor.Document);
     _previouslyLoaded = true;
 }
Пример #4
0
 public void UpdateFolding()
 {
     if (Syntax == "XML")
     {
         _xmlFoldingStrategy.UpdateFoldings(_foldingManager, Document);
     }
 }
Пример #5
0
 private void UpdateFolding()
 {
     if (foldingStrategy != null)
     {
         foldingStrategy.UpdateFoldings(foldingManager, tbSchema.Document);
     }
 }
Пример #6
0
        public void LoadDocument(string documentFileName)
        {
            if (textEditor == null || string.IsNullOrWhiteSpace(documentFileName))
            {
                return;
            }

            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 void SetText(string text)
        {
            Text            = text;
            textEditor.Text = text;

            if (text.Length > 200 && !text.Contains("\n"))
            {
                wordWrap.IsChecked = true;
            }

            bool looksLikeXml = Utilities.LooksLikeXml(text);

            if (looksLikeXml && !IsXml)
            {
                IsXml = true;

                var highlighting = HighlightingManager.Instance.GetDefinition("XML");
                highlighting.GetNamedColor("XmlTag").Foreground = new SimpleHighlightingBrush(Color.FromRgb(163, 21, 21));
                textEditor.SyntaxHighlighting = highlighting;

                var foldingManager  = FoldingManager.Install(textEditor.TextArea);
                var foldingStrategy = new XmlFoldingStrategy();
                foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);
            }
            else if (!looksLikeXml && IsXml)
            {
                IsXml = false;

                textEditor.SyntaxHighlighting = null;
            }
        }
Пример #8
0
 private void UpdateFolding(ICSharpCode.AvalonEdit.Document.TextDocument doc)
 {
     if (foldingStrategy != null)
     {
         foldingStrategy.UpdateFoldings(foldingManager, doc);
     }
 }
Пример #9
0
        private void SyntaxModeCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Language language = (Language)_syntaxModeCombo.SelectedItem;

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

            string scopeName = _registryOptions.GetScopeByLanguageId(language.Id);

            _textMateInstallation.SetGrammar(null);
            _textEditor.Document = new TextDocument(ResourceLoader.LoadSampleFile(scopeName));
            _textMateInstallation.SetGrammar(scopeName);

            if (language.Id == "xml")
            {
                _foldingManager = FoldingManager.Install(_textEditor.TextArea);

                var strategy = new XmlFoldingStrategy();
                strategy.UpdateFoldings(_foldingManager, _textEditor.Document);
                return;
            }
        }
        public EditorView(ITextMarkerService textMarkerService)
        {
            _textMarkerService = textMarkerService;

            InitializeComponent();

            ErrorsRow.Height = new GridLength(0);

            var rowStyle = new Style(typeof(DataGridRow), (Style)FindResource("MetroDataGridRow"));

            rowStyle.Setters.Add(new EventSetter(MouseDoubleClickEvent,
                                                 new MouseButtonEventHandler(OnErrorsGridMouseDoubleClick)));
            ErrorsGrid.RowStyle = rowStyle;

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

            TextEditor.TextChanged += (sender, args) =>
            {
                _foldingStrategy.UpdateFoldings(_foldingManager, TextEditor.Document);
            };

            _textMarkerService.SetTextEditor(TextEditor);

            var textView = TextEditor.TextArea.TextView;

            textView.BackgroundRenderers.Add(_textMarkerService);
            textView.LineTransformers.Add(_textMarkerService);
            textView.Services.AddService(typeof(ITextMarkerService), _textMarkerService);

            textView.MouseHover         += MouseHover;
            textView.MouseHoverStopped  += TextEditorMouseHoverStopped;
            textView.VisualLinesChanged += VisualLinesChanged;
        }
Пример #11
0
 private void UpdateFolding()
 {
     if (foldingStrategy != null && !string.IsNullOrEmpty(FileContents))
     {
         foldingStrategy.UpdateFoldings(foldingManager, tbDocument.Document);
     }
 }
Пример #12
0
        private void init()
        {
            foldingStrategy = new XmlFoldingStrategy();
            textEditor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
            foldingManager = FoldingManager.Install(textEditor.TextArea);

            if (foldingStrategy != null)
            {
                if (foldingManager == null)
                {
                    foldingManager = FoldingManager.Install(textEditor.TextArea);
                }
                foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);
            }
            else
            {
                if (foldingManager != null)
                {
                    FoldingManager.Uninstall(foldingManager);
                    foldingManager = null;
                }
            }

            DispatcherTimer foldingUpdateTimer = new DispatcherTimer();

            foldingUpdateTimer.Interval = TimeSpan.FromSeconds(2);
            foldingUpdateTimer.Tick    += foldingUpdateTimer_Tick;
            foldingUpdateTimer.Start();

            RawlerLib.UIData.UISyncContext = UISyncContext;
        }
Пример #13
0
 void foldingUpdateTimer_Tick(object sender, EventArgs e)
 {
     if (foldingStrategy != null)
     {
         foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);
     }
 }
Пример #14
0
        /// <summary>
        /// Prepares preview control by registering syntax highlighting and foldings
        /// </summary>
        public void Setup()
        {
            IHighlightingDefinition customHighlighting;
            string resourceName = Assembly.GetExecutingAssembly().GetManifestResourceNames().Single(str => str.EndsWith("sql.xshd", StringComparison.InvariantCultureIgnoreCase));

            using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                if (s == null)
                {
                    throw new InvalidOperationException("Could not find embedded resource");
                }
                using (XmlReader reader = new XmlTextReader(s))
                {
                    customHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
                }
            }
            // and register it in the HighlightingManager
            HighlightingManager.Instance.RegisterHighlighting("Custom Highlighting", new string[] { ".cool" }, customHighlighting);

            _editor.SyntaxHighlighting = customHighlighting;

            // folding
            var mgr   = FoldingManager.Install(_editor.TextArea);
            var strat = new XmlFoldingStrategy();

            strat.UpdateFoldings(mgr, _editor.Document);
        }
Пример #15
0
        internal void EnableFolding(bool enableFolding)
        {
            if (enableFolding)
            {
                switch (innerType)
                {
                case Enumerations.WebResourceType.Script:
                case Enumerations.WebResourceType.Css:
                {
                    if (!foldingManagerInstalled)
                    {
                        foldingManager          = FoldingManager.Install(textEditor.TextArea);
                        foldingManagerInstalled = true;
                    }

                    foldingManager.UpdateFoldings(CreateBraceFoldings(textEditor.Document), -1);
                }
                break;

                case Enumerations.WebResourceType.WebPage:
                {
                    if (!foldingManagerInstalled)
                    {
                        foldingManager          = FoldingManager.Install(textEditor.TextArea);
                        foldingManagerInstalled = true;
                    }

                    htmlFoldingStrategy = new HtmlFoldingStrategy();
                    htmlFoldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);
                }
                break;

                case Enumerations.WebResourceType.Data:
                case Enumerations.WebResourceType.Xsl:
                {
                    if (!foldingManagerInstalled)
                    {
                        foldingManager          = FoldingManager.Install(textEditor.TextArea);
                        foldingManagerInstalled = true;
                    }

                    xmlFoldingStrategy = new XmlFoldingStrategy();
                    xmlFoldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);
                }
                break;
                }

                FoldingEnabled = true;
            }
            else
            {
                if (foldingManager != null)
                {
                    foldingManager.Clear();
                }

                FoldingEnabled = false;
            }
        }
 private void UpdateFoldings()
 {
     if (_foldingManager == null || _foldingStrategy == null)
     {
         _foldingManager  = FoldingManager.Install(textEditor.TextArea);
         _foldingStrategy = new XmlFoldingStrategy();
     }
     _foldingStrategy.UpdateFoldings(_foldingManager, textEditor.Document);
 }
Пример #17
0
        private void UpdateDocumentView(WsdlDocument document)
        {
            StringWriter writer = new StringWriter();

            document.serviceDescription.Write(writer);
            wsdlEditor.Text = writer.GetStringBuilder().ToString();

            foldingStrategy.UpdateFoldings(foldingManager, wsdlEditor.Document);
        }
Пример #18
0
 private void Initialise()
 {
     if (m_useFolding)
     {
         m_foldingStrategy.UpdateFoldings(m_foldingManager, textEditor.Document);
     }
     UpdateUndoRedoEnabled();
     m_textWasSaved = false;
 }
Пример #19
0
 private void InitTimer()
 {
     activityTimer          = new System.Timers.Timer(1000);
     activityTimer.Elapsed += delegate {
         if (ticks > 0)
         {
             ticks--;
         }
         else if (ticks == 0)
         {
             ticks = -1;
             App.Current.Dispatcher.Invoke(delegate {
                 RebuildTree();
                 foldingStrategy.UpdateFoldings(foldingManager, text.Document);
             });
         }
     };
     activityTimer.Start();
 }
Пример #20
0
        private void _init()
        {
            if (_textEditor.SyntaxHighlighting == null)
            {
                _foldingStrategy = null;
            }
            else
            {
                switch (_textEditor.SyntaxHighlighting.Name)
                {
                case "XML":
                    _foldingStrategy = new XmlFoldingStrategy();
                    _textEditor.TextArea.IndentationStrategy = new DefaultIndentationStrategy();
                    break;

                default:
                    _textEditor.TextArea.IndentationStrategy = new DefaultIndentationStrategy();
                    _foldingStrategy = null;
                    break;
                }
            }
            if (_foldingStrategy != null)
            {
                if (_foldingManager == null)
                {
                    _foldingManager = FoldingManager.Install(_textEditor.TextArea);
                }
                _foldingStrategy.UpdateFoldings(_foldingManager, _textEditor.Document);
            }
            else
            {
                if (_foldingManager != null)
                {
                    FoldingManager.Uninstall(_foldingManager);
                    _foldingManager = null;
                }
            }

            _foldingUpdateTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(2)
            };
        }
Пример #21
0
        private void OnTextChanged(object sender, EventArgs e)
        {
            if (myFoldingManager == null)
            {
                myFoldingManager  = FoldingManager.Install(myTextEditor.TextArea);
                myFoldingStrategy = new XmlFoldingStrategy();
            }

            myFoldingStrategy.UpdateFoldings(myFoldingManager, myTextEditor.Document);
        }
Пример #22
0
        public MiniXamlPage()
        {
            InitializeComponent();
            DataContext = this;
            var foldingManager  = FoldingManager.Install(textEditor.TextArea);
            var foldingStrategy = new XmlFoldingStrategy();

            foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);
            textEditor.Options.HighlightCurrentLine = true;
            textEditor.ShowLineNumbers = true;
        }
Пример #23
0
        private void RefreshFoldings()
        {
            if (_partTextEditor == null || !AllowFolding)
            {
                return;
            }

            InstallFolding();

            _foldingStrategy.UpdateFoldings(_foldingManager, _partTextEditor.Document);
        }
Пример #24
0
        /// <summary>
        /// 窗体载入3
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            Visible = true;

            eleCodeBox.Child = codebox;
            eleConsole.Child = console;

            // Fast search
            SearchPanel.Install(codebox.TextArea);
            SearchPanel.Install(console.TextArea);

            // Syntax rule
            int i = 1;

            while (i <= 2)
            {
                string   name     = Assembly.GetExecutingAssembly().GetName().Name + (i == 1 ? ".Python.xshd" : ".Console.xshd");
                Assembly assembly = Assembly.GetExecutingAssembly();
                using (Stream s = assembly.GetManifestResourceStream(name))
                {
                    using (XmlTextReader reader = new XmlTextReader(s))
                    {
                        var xshd = HighlightingLoader.LoadXshd(reader);
                        (i == 1 ? codebox : console).SyntaxHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance);
                    }
                }
                i++;
            }

            // 在构造函数中
            codebox.TextArea.TextEntering += codebox_TextArea_TextEntering;
            codebox.TextArea.TextEntered  += codebox_TextArea_TextEntered;

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

            #region 多线程
            Thread ThreadTimingEvent = new Thread(timingEventEvent);
            ThreadTimingEvent.Start();
            ThreadTimingEvent.IsBackground = true;
            #endregion

            codebox.KeyUp += new System.Windows.Input.KeyEventHandler(run_KeyUp);
            console.KeyUp += new System.Windows.Input.KeyEventHandler(run_KeyUp);

            // 获取 python 编译环境地址, 缓存到 CommonSymbolSet 类的 PythonPyCodeTargetPath & PythonLocationTargetPath 变量
            PyCode.CommonSymbolSet.PythonPyCodeTargetPath   = PyCodeConfig.Config.readConfiguration(Application.StartupPath + @"\Important\Configuration\Preferences.ini", "path", "python-use-pycode");
            PyCode.CommonSymbolSet.PythonLocationTargetPath = PyCodeConfig.Config.readConfiguration(Application.StartupPath + @"\Important\Configuration\Preferences.ini", "path", "python-use-location");
        }
Пример #25
0
        private static void EditorTextChanged(object sender, EventArgs e)
        {
            var ed = sender as TextEditor;

            if (ed != null)
            {
                XmlFoldingStrategy fs = ed.Attached().FoldingStrategy;
                FoldingManager     fm = ed.Attached().FoldingManager;
                if (fs != null && fm != null)
                {
                    fs.UpdateFoldings(fm, ed.Document);
                }
            }
        }
Пример #26
0
        private void RefreshFoldings()
        {
            if (_partTextEditor == null)
            {
                return;
            }

            if (_foldingManager == null)
            {
                _foldingManager = FoldingManager.Install(_partTextEditor.TextArea);
            }

            _foldingStrategy.UpdateFoldings(_foldingManager, _partTextEditor.Document);
        }
Пример #27
0
        public ReportEditor()
        {
            //if (report == null) report = new PDFReport();
            InitializeComponent();

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

            DispatcherTimer foldingUpdateTimer = new DispatcherTimer();

            foldingUpdateTimer.Interval = TimeSpan.FromSeconds(2);
            foldingUpdateTimer.Tick    += foldingUpdateTimer_Tick;
            foldingUpdateTimer.Start( );
        }
Пример #28
0
 private void UpdateFolding()
 {
     try
     {
         if (foldingStrategy != null)
         {
             if (!string.IsNullOrEmpty(tbOldDoc.Text))
             {
                 foldingStrategy.UpdateFoldings(foldingManager, tbOldDoc.Document);
             }
             if (!string.IsNullOrEmpty(tbNewDoc.Text))
             {
                 foldingStrategy.UpdateFoldings(foldingManager, tbNewDoc.Document);
             }
             if (!string.IsNullOrEmpty(tbXslt.Text))
             {
                 foldingStrategy.UpdateFoldings(foldingManager, tbXslt.Document);
             }
         }
     }
     catch (Exception)
     {
     }
 }
        public ProgramCalculator()
        {
            InitializeComponent();
            settingswid.Width = new GridLength(0d);

            var foldingManager  = FoldingManager.Install(CodeTextBox.TextArea);
            var foldingStrategy = new XmlFoldingStrategy();

            foldingStrategy.UpdateFoldings(foldingManager, CodeTextBox.Document);

            var foldingManager2  = FoldingManager.Install(OutputTextBox.TextArea);
            var foldingStrategy2 = new XmlFoldingStrategy();

            foldingStrategy2.UpdateFoldings(foldingManager2, OutputTextBox.Document);
        }
        public virtual void Display(string message)
        {
            if (message == null)
            {
                return;
            }

            var doc  = new XmlDocument();
            var text = message;

            try
            {
                doc.LoadXml(message);
                text = doc.GetFormatted();
            }
            catch (XmlException)
            {
                // It looks like we having issues parsing the xml
                // Best to do in this circunstances is to still display the text
            }

            document.Document.Text = text;
            foldingStrategy.UpdateFoldings(foldingManager, document.Document);
        }