[mapguide-commits] r7159 - in trunk/Tools/Maestro: Maestro.Base/Commands Maestro.Editors Maestro.Editors/Generic Maestro.Editors/Generic/XmlEditor Thirdparty/SharpDevelop/ICSharpCode.TextEditor/Src/Gui

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Oct 26 12:40:55 PDT 2012


Author: jng
Date: 2012-10-26 12:40:55 -0700 (Fri, 26 Oct 2012)
New Revision: 7159

Added:
   trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlEditorOptions.cs
   trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlFoldingStrategy.cs
   trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlFormattingStrategy.cs
Modified:
   trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs
   trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.Designer.cs
   trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.cs
   trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.resx
   trunk/Tools/Maestro/Maestro.Editors/Generic/XmlTextEditorControl.cs
   trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
   trunk/Tools/Maestro/Thirdparty/SharpDevelop/ICSharpCode.TextEditor/Src/Gui/Ime.cs
Log:
This submission implements code folding for the Generic XML editor allowing for XML elements to be collapsed. Like the overhauled IronPython REPL, this was mostly grafted from the SharpDevelop 3.2.1 release (being the last major WinForms-based release of SharpDevelop)

This submission also fixes an NRE in the ICSharpCode.TextEditor IME

Modified: trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs	2012-10-26 16:44:21 UTC (rev 7158)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs	2012-10-26 19:40:55 UTC (rev 7159)
@@ -42,7 +42,7 @@
             ResourceService.RegisterNeutralStrings(Strings.ResourceManager);
 
             ResourcePreviewerFactory.RegisterPreviewer("Maestro.Http", new DefaultResourcePreviewer()); //NOXLATE
-
+            
             Workbench.WorkbenchInitialized += (sender, e) =>
             {
                 ServiceRegistry.GetService<NewItemTemplateService>().InitUserTemplates();

Added: trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlEditorOptions.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlEditorOptions.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlEditorOptions.cs	2012-10-26 19:40:55 UTC (rev 7159)
@@ -0,0 +1,51 @@
+#region Disclaimer / License
+// Copyright (C) 2012, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// Original code from SharpDevelop 3.2.1 licensed under the same terms (LGPL 2.1)
+// Copyright 2002-2010 by
+//
+//  AlphaSierraPapa, Christoph Wille
+//  Vordernberger Strasse 27/8
+//  A-8700 Leoben
+//  Austria
+//
+//  email: office at alphasierrapapa.com
+//  court of jurisdiction: Landesgericht Leoben
+//
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Maestro.Editors.Generic.XmlEditor
+{
+    public class XmlEditorOptions
+    {
+        static XmlEditorOptions()
+        {
+            ShowSchemaAnnotation = true;
+            ShowAttributesWhenFolded = true;
+        }
+
+        public static bool ShowSchemaAnnotation { get; set; }
+
+        public static bool ShowAttributesWhenFolded { get; set; }
+    }
+}

Added: trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlFoldingStrategy.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlFoldingStrategy.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlFoldingStrategy.cs	2012-10-26 19:40:55 UTC (rev 7159)
@@ -0,0 +1,318 @@
+#region Disclaimer / License
+// Copyright (C) 2012, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// Original code from SharpDevelop 3.2.1 licensed under the same terms (LGPL 2.1)
+// Copyright 2002-2010 by
+//
+//  AlphaSierraPapa, Christoph Wille
+//  Vordernberger Strasse 27/8
+//  A-8700 Leoben
+//  Austria
+//
+//  email: office at alphasierrapapa.com
+//  court of jurisdiction: Landesgericht Leoben
+//
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using ICSharpCode.TextEditor.Document;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Xml;
+
+namespace Maestro.Editors.Generic.XmlEditor
+{
+    /// <summary>
+    /// Holds information about the start of a fold in an xml string.
+    /// </summary>
+    public class XmlFoldStart
+    {
+        int line = 0;
+        int col = 0;
+        string prefix = String.Empty;
+        string name = String.Empty;
+        string foldText = String.Empty;
+
+        public XmlFoldStart(string prefix, string name, int line, int col)
+        {
+            this.line = line;
+            this.col = col;
+            this.prefix = prefix;
+            this.name = name;
+        }
+
+        /// <summary>
+        /// The line where the fold should start.  Lines start from 0.
+        /// </summary>
+        public int Line
+        {
+            get
+            {
+                return line;
+            }
+        }
+
+        /// <summary>
+        /// The column where the fold should start.  Columns start from 0.
+        /// </summary>
+        public int Column
+        {
+            get
+            {
+                return col;
+            }
+        }
+
+        /// <summary>
+        /// The name of the xml item with its prefix if it has one.
+        /// </summary>
+        public string Name
+        {
+            get
+            {
+                if (prefix.Length > 0)
+                {
+                    return String.Concat(prefix, ":", name);
+                }
+                else
+                {
+                    return name;
+                }
+            }
+        }
+
+        /// <summary>
+        /// The text to be displayed when the item is folded.
+        /// </summary>
+        public string FoldText
+        {
+            get
+            {
+                return foldText;
+            }
+
+            set
+            {
+                foldText = value;
+            }
+        }
+    }
+
+    /// <summary>
+    /// Determines folds for an xml string in the editor.
+    /// </summary>
+    public class XmlFoldingStrategy : IFoldingStrategy
+    {
+        /// <summary>
+        /// Flag indicating whether attributes should be displayed on folded
+        /// elements.
+        /// </summary>
+        bool showAttributesWhenFolded = false;
+
+        public XmlFoldingStrategy()
+        {
+        }
+
+        #region IFoldingStrategy
+
+        /// <summary>
+        /// Adds folds to the text editor around each start-end element pair.
+        /// </summary>
+        /// <remarks>
+        /// <para>If the xml is not well formed then no folds are created.</para> 
+        /// <para>Note that the xml text reader lines and positions start 
+        /// from 1 and the SharpDevelop text editor line information starts
+        /// from 0.</para>
+        /// </remarks>
+        public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)
+        {
+            showAttributesWhenFolded = XmlEditorOptions.ShowAttributesWhenFolded;
+
+            List<FoldMarker> foldMarkers = new List<FoldMarker>();
+            Stack stack = new Stack();
+
+            try
+            {
+                string xml = document.TextContent;
+                XmlTextReader reader = new XmlTextReader(new StringReader(xml));
+                while (reader.Read())
+                {
+                    switch (reader.NodeType)
+                    {
+                        case XmlNodeType.Element:
+                            if (!reader.IsEmptyElement)
+                            {
+                                XmlFoldStart newFoldStart = CreateElementFoldStart(reader);
+                                stack.Push(newFoldStart);
+                            }
+                            break;
+
+                        case XmlNodeType.EndElement:
+                            XmlFoldStart foldStart = (XmlFoldStart)stack.Pop();
+                            CreateElementFold(document, foldMarkers, reader, foldStart);
+                            break;
+
+                        case XmlNodeType.Comment:
+                            CreateCommentFold(document, foldMarkers, reader);
+                            break;
+                    }
+                }
+            }
+            catch (Exception)
+            {
+                // If the xml is not well formed keep the foldings 
+                // that already exist in the document.
+                return new List<FoldMarker>(document.FoldingManager.FoldMarker);
+            }
+
+            return foldMarkers;
+        }
+
+        #endregion
+
+        /// <summary>
+        /// Creates a comment fold if the comment spans more than one line.
+        /// </summary>
+        /// <remarks>The text displayed when the comment is folded is the first 
+        /// line of the comment.</remarks>
+        void CreateCommentFold(IDocument document, List<FoldMarker> foldMarkers, XmlTextReader reader)
+        {
+            if (reader.Value != null)
+            {
+                string comment = reader.Value.Replace("\r\n", "\n");
+                string[] lines = comment.Split('\n');
+                if (lines.Length > 1)
+                {
+
+                    // Take off 5 chars to get the actual comment start (takes
+                    // into account the <!-- chars.
+
+                    int startCol = reader.LinePosition - 5;
+                    int startLine = reader.LineNumber - 1;
+
+                    // Add 3 to the end col value to take into account the '-->'
+                    int endCol = lines[lines.Length - 1].Length + startCol + 3;
+                    int endLine = startLine + lines.Length - 1;
+                    string foldText = String.Concat("<!--", lines[0], "-->");
+                    FoldMarker foldMarker = new FoldMarker(document, startLine, startCol, endLine, endCol, FoldType.TypeBody, foldText);
+                    foldMarkers.Add(foldMarker);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Creates an XmlFoldStart for the start tag of an element.
+        /// </summary>
+        XmlFoldStart CreateElementFoldStart(XmlTextReader reader)
+        {
+            // Take off 2 from the line position returned 
+            // from the xml since it points to the start
+            // of the element name and not the beginning 
+            // tag.
+            XmlFoldStart newFoldStart = new XmlFoldStart(reader.Prefix, reader.LocalName, reader.LineNumber - 1, reader.LinePosition - 2);
+
+            if (showAttributesWhenFolded && reader.HasAttributes)
+            {
+                newFoldStart.FoldText = String.Concat("<", newFoldStart.Name, " ", GetAttributeFoldText(reader), ">");
+            }
+            else
+            {
+                newFoldStart.FoldText = String.Concat("<", newFoldStart.Name, ">");
+            }
+
+            return newFoldStart;
+        }
+
+        /// <summary>
+        /// Create an element fold if the start and end tag are on 
+        /// different lines.
+        /// </summary>
+        void CreateElementFold(IDocument document, List<FoldMarker> foldMarkers, XmlTextReader reader, XmlFoldStart foldStart)
+        {
+            int endLine = reader.LineNumber - 1;
+            if (endLine > foldStart.Line)
+            {
+                int endCol = reader.LinePosition + foldStart.Name.Length;
+                FoldMarker foldMarker = new FoldMarker(document, foldStart.Line, foldStart.Column, endLine, endCol, FoldType.TypeBody, foldStart.FoldText);
+                foldMarkers.Add(foldMarker);
+            }
+        }
+
+        /// <summary>
+        /// Gets the element's attributes as a string on one line that will
+        /// be displayed when the element is folded.
+        /// </summary>
+        /// <remarks>
+        /// Currently this puts all attributes from an element on the same
+        /// line of the start tag.  It does not cater for elements where attributes
+        /// are not on the same line as the start tag.
+        /// </remarks>
+        string GetAttributeFoldText(XmlTextReader reader)
+        {
+            StringBuilder text = new StringBuilder();
+
+            for (int i = 0; i < reader.AttributeCount; ++i)
+            {
+                reader.MoveToAttribute(i);
+
+                text.Append(reader.Name);
+                text.Append("=");
+                text.Append(reader.QuoteChar.ToString());
+                text.Append(XmlEncodeAttributeValue(reader.Value, reader.QuoteChar));
+                text.Append(reader.QuoteChar.ToString());
+
+                // Append a space if this is not the
+                // last attribute.
+                if (i < reader.AttributeCount - 1)
+                {
+                    text.Append(" ");
+                }
+            }
+
+            return text.ToString();
+        }
+
+        /// <summary>
+        /// Xml encode the attribute string since the string returned from
+        /// the XmlTextReader is the plain unencoded string and .NET
+        /// does not provide us with an xml encode method.
+        /// </summary>
+        static string XmlEncodeAttributeValue(string attributeValue, char quoteChar)
+        {
+            StringBuilder encodedValue = new StringBuilder(attributeValue);
+
+            encodedValue.Replace("&", "&");
+            encodedValue.Replace("<", "<");
+            encodedValue.Replace(">", ">");
+
+            if (quoteChar == '"')
+            {
+                encodedValue.Replace("\"", """);
+            }
+            else
+            {
+                encodedValue.Replace("'", "'");
+            }
+
+            return encodedValue.ToString();
+        }
+    }
+}

Added: trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlFormattingStrategy.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlFormattingStrategy.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditor/XmlFormattingStrategy.cs	2012-10-26 19:40:55 UTC (rev 7159)
@@ -0,0 +1,254 @@
+#region Disclaimer / License
+// Copyright (C) 2012, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// Original code from SharpDevelop 3.2.1 licensed under the same terms (LGPL 2.1)
+// Copyright 2002-2010 by
+//
+//  AlphaSierraPapa, Christoph Wille
+//  Vordernberger Strasse 27/8
+//  A-8700 Leoben
+//  Austria
+//
+//  email: office at alphasierrapapa.com
+//  court of jurisdiction: Landesgericht Leoben
+//
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using ICSharpCode.TextEditor;
+using ICSharpCode.TextEditor.Actions;
+using ICSharpCode.TextEditor.Document;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Xml;
+
+namespace Maestro.Editors.Generic.XmlEditor
+{
+    /// <summary>
+    /// This class currently inserts the closing tags to typed openening tags
+    /// and does smart indentation for xml files.
+    /// </summary>
+    public class XmlFormattingStrategy : DefaultFormattingStrategy
+    {
+        public override void FormatLine(TextArea textArea, int lineNr, int caretOffset, char charTyped) // used for comment tag formater/inserter
+        {
+            textArea.Document.UndoStack.StartUndoGroup();
+            try
+            {
+                if (charTyped == '>')
+                {
+                    StringBuilder stringBuilder = new StringBuilder();
+                    int offset = Math.Min(caretOffset - 2, textArea.Document.TextLength - 1);
+                    while (true)
+                    {
+                        if (offset < 0)
+                        {
+                            break;
+                        }
+                        char ch = textArea.Document.GetCharAt(offset);
+                        if (ch == '<')
+                        {
+                            string reversedTag = stringBuilder.ToString().Trim();
+                            if (!reversedTag.StartsWith("/") && !reversedTag.EndsWith("/"))
+                            {
+                                bool validXml = true;
+                                try
+                                {
+                                    XmlDocument doc = new XmlDocument();
+                                    doc.LoadXml(textArea.Document.TextContent);
+                                }
+                                catch (Exception)
+                                {
+                                    validXml = false;
+                                }
+                                // only insert the tag, if something is missing
+                                if (!validXml)
+                                {
+                                    StringBuilder tag = new StringBuilder();
+                                    for (int i = reversedTag.Length - 1; i >= 0 && !Char.IsWhiteSpace(reversedTag[i]); --i)
+                                    {
+                                        tag.Append(reversedTag[i]);
+                                    }
+                                    string tagString = tag.ToString();
+                                    if (tagString.Length > 0 && !tagString.StartsWith("!") && !tagString.StartsWith("?"))
+                                    {
+                                        textArea.Document.Insert(caretOffset, "</" + tagString + ">");
+                                    }
+                                }
+                            }
+                            break;
+                        }
+                        stringBuilder.Append(ch);
+                        --offset;
+                    }
+                }
+            }
+            catch (Exception e)
+            { // Insanity check
+                Debug.Assert(false, e.ToString());
+            }
+            if (charTyped == '\n')
+            {
+                textArea.Caret.Column = IndentLine(textArea, lineNr);
+            }
+            textArea.Document.UndoStack.EndUndoGroup();
+        }
+
+        /// <summary>
+        /// Define XML specific smart indenting for a line :)
+        /// </summary>
+        protected override int SmartIndentLine(TextArea textArea, int lineNr)
+        {
+            if (lineNr <= 0) return AutoIndentLine(textArea, lineNr);
+            try
+            {
+                TryIndent(textArea, lineNr, lineNr);
+                return GetIndentation(textArea, lineNr).Length;
+            }
+            catch (XmlException)
+            {
+                return AutoIndentLine(textArea, lineNr);
+            }
+        }
+
+        /// <summary>
+        /// This function sets the indentlevel in a range of lines.
+        /// </summary>
+        public override void IndentLines(TextArea textArea, int begin, int end)
+        {
+            textArea.Document.UndoStack.StartUndoGroup();
+            try
+            {
+                TryIndent(textArea, begin, end);
+            }
+            catch (XmlException ex)
+            {
+                Debug.WriteLine(ex.ToString());
+            }
+            finally
+            {
+                textArea.Document.UndoStack.EndUndoGroup();
+            }
+        }
+
+        #region Smart Indentation
+        private void TryIndent(TextArea textArea, int begin, int end)
+        {
+            string currentIndentation = "";
+            Stack tagStack = new Stack();
+            IDocument document = textArea.Document;
+            string tab = Tab.GetIndentationString(document);
+            int nextLine = begin; // in #dev coordinates
+            bool wasEmptyElement = false;
+            XmlNodeType lastType = XmlNodeType.XmlDeclaration;
+            // TextReader line number begin with 1, #dev line numbers with 0
+            using (StringReader stringReader = new StringReader(document.TextContent))
+            {
+                XmlTextReader r = new XmlTextReader(stringReader);
+                r.XmlResolver = null; // prevent XmlTextReader from loading external DTDs
+                while (r.Read())
+                {
+                    if (wasEmptyElement)
+                    {
+                        wasEmptyElement = false;
+                        if (tagStack.Count == 0)
+                            currentIndentation = "";
+                        else
+                            currentIndentation = (string)tagStack.Pop();
+                    }
+                    if (r.NodeType == XmlNodeType.EndElement)
+                    {
+                        if (tagStack.Count == 0)
+                            currentIndentation = "";
+                        else
+                            currentIndentation = (string)tagStack.Pop();
+                    }
+
+                    while (r.LineNumber > nextLine)
+                    { // caution: here we compare 1-based and 0-based line numbers
+                        if (nextLine > end) break;
+                        if (lastType == XmlNodeType.CDATA || lastType == XmlNodeType.Comment)
+                        {
+                            nextLine += 1;
+                            continue;
+                        }
+                        // set indentation of 'nextLine'
+                        LineSegment line = document.GetLineSegment(nextLine);
+                        string lineText = document.GetText(line);
+
+                        string newText;
+                        // special case: opening tag has closing bracket on extra line: remove one indentation level
+                        if (lineText.Trim() == ">")
+                            newText = (string)tagStack.Peek() + lineText.Trim();
+                        else
+                            newText = currentIndentation + lineText.Trim();
+
+                        if (newText != lineText)
+                        {
+                            document.Replace(line.Offset, line.Length, newText);
+                        }
+                        nextLine += 1;
+                    }
+                    if (r.LineNumber > end)
+                        break;
+                    wasEmptyElement = r.NodeType == XmlNodeType.Element && r.IsEmptyElement;
+                    string attribIndent = null;
+                    if (r.NodeType == XmlNodeType.Element)
+                    {
+                        tagStack.Push(currentIndentation);
+                        if (r.LineNumber < begin)
+                            currentIndentation = GetIndentation(textArea, r.LineNumber - 1);
+                        if (r.Name.Length < 16)
+                            attribIndent = currentIndentation + new String(' ', 2 + r.Name.Length);
+                        else
+                            attribIndent = currentIndentation + tab;
+                        currentIndentation += tab;
+                    }
+                    lastType = r.NodeType;
+                    if (r.NodeType == XmlNodeType.Element && r.HasAttributes)
+                    {
+                        int startLine = r.LineNumber;
+                        r.MoveToAttribute(0); // move to first attribute
+                        if (r.LineNumber != startLine)
+                            attribIndent = currentIndentation; // change to tab-indentation
+                        r.MoveToAttribute(r.AttributeCount - 1);
+                        while (r.LineNumber > nextLine)
+                        { // caution: here we compare 1-based and 0-based line numbers
+                            if (nextLine > end) break;
+                            // set indentation of 'nextLine'
+                            LineSegment line = document.GetLineSegment(nextLine);
+                            string lineText = document.GetText(line);
+                            string newText = attribIndent + lineText.Trim();
+                            if (newText != lineText)
+                            {
+                                document.Replace(line.Offset, line.Length, newText);
+                            }
+                            nextLine += 1;
+                        }
+                    }
+                }
+                r.Close();
+            }
+        }
+        #endregion
+    }
+}

Modified: trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.Designer.cs	2012-10-26 16:44:21 UTC (rev 7158)
+++ trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.Designer.cs	2012-10-26 19:40:55 UTC (rev 7159)
@@ -45,7 +45,7 @@
             this.btnFindAndReplace = new System.Windows.Forms.ToolStripButton();
             this.resDataCtrl = new Maestro.Editors.Generic.ResourceDataPanel();
             this.nodeNumericUpDown1 = new Aga.Controls.Tree.NodeControls.NodeNumericUpDown();
-            this.txtXmlContent = new XmlTextEditorControl();
+            this.txtXmlContent = new Maestro.Editors.Generic.XmlTextEditorControl();
             this.ctxXmlEditor = new System.Windows.Forms.ContextMenuStrip(this.components);
             this.cutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
             this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -194,6 +194,7 @@
             resources.ApplyResources(this.txtXmlContent, "txtXmlContent");
             this.txtXmlContent.IsReadOnly = false;
             this.txtXmlContent.Name = "txtXmlContent";
+            this.txtXmlContent.TextChanged += new System.EventHandler(this.txtXmlContent_TextChanged);
             // 
             // ctxXmlEditor
             // 

Modified: trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.cs	2012-10-26 16:44:21 UTC (rev 7158)
+++ trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.cs	2012-10-26 19:40:55 UTC (rev 7159)
@@ -34,6 +34,7 @@
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using OSGeo.MapGuide.ObjectModels;
 using ICSharpCode.TextEditor.Actions;
+using Maestro.Editors.Generic.XmlEditor;
 
 namespace Maestro.Editors.Generic
 {
@@ -87,12 +88,13 @@
             InitializeComponent();
             txtXmlContent.RegisterAction(Keys.Control | Keys.F, new FindAction(this));
             txtXmlContent.RegisterAction(Keys.Control | Keys.H, new FindAndReplaceAction(this));
-            txtXmlContent.SetHighlighting("XML"); //NOXLATE
-            txtXmlContent.EnableFolding = true;
-            txtXmlContent.ShowInvalidLines = true;
-            txtXmlContent.ShowSpaces = true;
-            txtXmlContent.ShowTabs = true;
-            txtXmlContent.LineViewerStyle = LineViewerStyle.FullRow;
+
+            var props = TextEditorProperties.CreateDefault(txtXmlContent.Font);
+            props.LineViewerStyle = LineViewerStyle.FullRow;
+            props.ShowInvalidLines = true;
+
+            txtXmlContent.ApplySettings(props);
+
             txtXmlContent.TextChanged += new EventHandler(OnTextContentChanged);
         }
         
@@ -209,7 +211,7 @@
         {
             UpdateTextPosition();
             EvaluateCommands();
-
+            txtXmlContent.UpdateFolding();
             if (_ready) 
                 OnResourceChanged();
         }

Modified: trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.resx	2012-10-26 16:44:21 UTC (rev 7158)
+++ trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.resx	2012-10-26 19:40:55 UTC (rev 7159)
@@ -262,40 +262,40 @@
     <value>105, 0</value>
   </metadata>
   <data name="cutToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
-    <value>152, 22</value>
+    <value>143, 22</value>
   </data>
   <data name="cutToolStripMenuItem.Text" xml:space="preserve">
     <value>Cut</value>
   </data>
   <data name="copyToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
-    <value>152, 22</value>
+    <value>143, 22</value>
   </data>
   <data name="copyToolStripMenuItem.Text" xml:space="preserve">
     <value>Copy</value>
   </data>
   <data name="pasteToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
-    <value>152, 22</value>
+    <value>143, 22</value>
   </data>
   <data name="pasteToolStripMenuItem.Text" xml:space="preserve">
     <value>Paste</value>
   </data>
   <data name="toolStripSeparator4.Size" type="System.Drawing.Size, System.Drawing">
-    <value>149, 6</value>
+    <value>140, 6</value>
   </data>
   <data name="findToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
-    <value>152, 22</value>
+    <value>143, 22</value>
   </data>
   <data name="findToolStripMenuItem.Text" xml:space="preserve">
     <value>Find</value>
   </data>
   <data name="findReplaceToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
-    <value>152, 22</value>
+    <value>143, 22</value>
   </data>
   <data name="findReplaceToolStripMenuItem.Text" xml:space="preserve">
     <value>Find/Replace</value>
   </data>
   <data name="ctxXmlEditor.Size" type="System.Drawing.Size, System.Drawing">
-    <value>153, 142</value>
+    <value>144, 120</value>
   </data>
   <data name=">>ctxXmlEditor.Name" xml:space="preserve">
     <value>ctxXmlEditor</value>
@@ -319,7 +319,7 @@
     <value>txtXmlContent</value>
   </data>
   <data name=">>txtXmlContent.Type" xml:space="preserve">
-    <value>ICSharpCode.TextEditor.TextEditorControl, ICSharpCode.TextEditor, Version=4.2.0.8783, Culture=neutral, PublicKeyToken=4d61825e8dd49f1a</value>
+    <value>Maestro.Editors.Generic.XmlTextEditorControl, Maestro.Editors, Version=5.0.0.6640, Culture=neutral, PublicKeyToken=f526c48929fda856</value>
   </data>
   <data name=">>txtXmlContent.Parent" xml:space="preserve">
     <value>$this</value>

Modified: trunk/Tools/Maestro/Maestro.Editors/Generic/XmlTextEditorControl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Generic/XmlTextEditorControl.cs	2012-10-26 16:44:21 UTC (rev 7158)
+++ trunk/Tools/Maestro/Maestro.Editors/Generic/XmlTextEditorControl.cs	2012-10-26 19:40:55 UTC (rev 7159)
@@ -25,6 +25,11 @@
 using ICSharpCode.TextEditor.Actions;
 using System.Windows.Forms;
 using System.ComponentModel;
+using ICSharpCode.TextEditor.Document;
+using Maestro.Shared.UI;
+using ICSharpCode.TextEditor.Gui.CompletionWindow;
+using Maestro.Editors.Generic.XmlEditor;
+using System.Drawing;
 
 namespace Maestro.Editors.Generic
 {
@@ -38,13 +43,258 @@
         /// Initializes a new instance
         /// </summary>
         public XmlTextEditorControl()
-        { 
-        
+        {
+            XmlFormattingStrategy strategy = new XmlFormattingStrategy();
+            Document.FormattingStrategy = (IFormattingStrategy)strategy;
+            Document.HighlightingStrategy = HighlightingManager.Manager.FindHighlighter("XML");
+            Document.FoldingManager.FoldingStrategy = new XmlFoldingStrategy();
         }
 
+        public void ApplySettings(ITextEditorProperties props)
+        {
+            this.TextEditorProperties = props;
+        }
+
         internal void RegisterAction(Keys k, IEditAction action)
         {
             editactions[k] = action;
         }
+
+        /// <summary>
+        /// Forces the editor to update its folds.
+        /// </summary>
+        internal void UpdateFolding()
+        {
+            this.Document.FoldingManager.UpdateFoldings(String.Empty, null);
+            RefreshMargin();
+        }
+
+        /// <summary>
+        /// Repaints the folds in the margin.
+        /// </summary>
+        internal void RefreshMargin()
+        {
+            Action action = () => 
+            {
+                this.ActiveTextAreaControl.TextArea.Refresh(this.ActiveTextAreaControl.TextArea.FoldMargin);
+            };
+            if (this.InvokeRequired)
+                this.BeginInvoke(action);
+            else
+                action();
+        }
     }
+
+    public class TextEditorProperties : ITextEditorProperties
+    {
+        public bool CaretLine
+        {
+            get;
+            set;
+        }
+
+        public bool AutoInsertCurlyBracket
+        {
+            get;
+            set;
+        }
+
+        public bool HideMouseCursor
+        {
+            get;
+            set;
+        }
+
+        public bool IsIconBarVisible
+        {
+            get;
+            set;
+        }
+
+        public bool AllowCaretBeyondEOL
+        {
+            get;
+            set;
+        }
+
+        public bool ShowMatchingBracket
+        {
+            get;
+            set;
+        }
+
+        public bool CutCopyWholeLine
+        {
+            get;
+            set;
+        }
+
+        public System.Drawing.Text.TextRenderingHint TextRenderingHint
+        {
+            get;
+            set;
+        }
+
+        public bool MouseWheelScrollDown
+        {
+            get;
+            set;
+        }
+
+        public bool MouseWheelTextZoom
+        {
+            get;
+            set;
+        }
+
+        public string LineTerminator
+        {
+            get;
+            set;
+        }
+
+        public LineViewerStyle LineViewerStyle
+        {
+            get;
+            set;
+        }
+
+        public bool ShowInvalidLines
+        {
+            get;
+            set;
+        }
+
+        public int VerticalRulerRow
+        {
+            get;
+            set;
+        }
+
+        public bool ShowSpaces
+        {
+            get;
+            set;
+        }
+
+        public bool ShowTabs
+        {
+            get;
+            set;
+        }
+
+        public bool ShowEOLMarker
+        {
+            get;
+            set;
+        }
+
+        public bool ConvertTabsToSpaces
+        {
+            get;
+            set;
+        }
+
+        public bool ShowHorizontalRuler
+        {
+            get;
+            set;
+        }
+
+        public bool ShowVerticalRuler
+        {
+            get;
+            set;
+        }
+
+        public Encoding Encoding
+        {
+            get;
+            set;
+        }
+
+        public bool EnableFolding
+        {
+            get;
+            set;
+        }
+
+        public bool ShowLineNumbers
+        {
+            get;
+            set;
+        }
+
+        public int TabIndent
+        {
+            get;
+            set;
+        }
+
+        public int IndentationSize
+        {
+            get;
+            set;
+        }
+
+        public IndentStyle IndentStyle
+        {
+            get;
+            set;
+        }
+
+        public DocumentSelectionMode DocumentSelectionMode
+        {
+            get;
+            set;
+        }
+
+        public System.Drawing.Font Font
+        {
+            get;
+            set;
+        }
+
+        public FontContainer FontContainer
+        {
+            get;
+            private set;
+        }
+
+        public BracketMatchingStyle BracketMatchingStyle
+        {
+            get;
+            set;
+        }
+
+        public bool SupportReadOnlySegments
+        {
+            get;
+            set;
+        }
+
+        public static ITextEditorProperties CreateDefault(Font font)
+        {
+            return new TextEditorProperties()
+            {
+                EnableFolding = true,
+                ShowLineNumbers  = true,
+                ShowHorizontalRuler = false,
+                ShowVerticalRuler = false,
+                ShowSpaces = true,
+                ShowTabs = true,
+                ShowInvalidLines = true,
+                ShowMatchingBracket = true,
+                IsIconBarVisible = true,
+                IndentationSize = 2,
+                DocumentSelectionMode = ICSharpCode.TextEditor.Document.DocumentSelectionMode.Normal,
+                LineViewerStyle = ICSharpCode.TextEditor.Document.LineViewerStyle.FullRow,
+                ConvertTabsToSpaces = true,
+                MouseWheelScrollDown = true,
+                MouseWheelTextZoom = false,
+                FontContainer = new FontContainer(font),
+                Encoding = Encoding.UTF8
+            };
+        }
+    }
 }

Modified: trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj	2012-10-26 16:44:21 UTC (rev 7158)
+++ trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj	2012-10-26 19:40:55 UTC (rev 7159)
@@ -653,6 +653,9 @@
     <Compile Include="Fusion\WidgetSettingsCtrl.Designer.cs">
       <DependentUpon>WidgetSettingsCtrl.cs</DependentUpon>
     </Compile>
+    <Compile Include="Generic\XmlEditor\XmlEditorOptions.cs" />
+    <Compile Include="Generic\XmlEditor\XmlFoldingStrategy.cs" />
+    <Compile Include="Generic\XmlEditor\XmlFormattingStrategy.cs" />
     <Compile Include="Generic\XmlTextEditorControl.cs">
       <SubType>UserControl</SubType>
     </Compile>

Modified: trunk/Tools/Maestro/Thirdparty/SharpDevelop/ICSharpCode.TextEditor/Src/Gui/Ime.cs
===================================================================
--- trunk/Tools/Maestro/Thirdparty/SharpDevelop/ICSharpCode.TextEditor/Src/Gui/Ime.cs	2012-10-26 16:44:21 UTC (rev 7158)
+++ trunk/Tools/Maestro/Thirdparty/SharpDevelop/ICSharpCode.TextEditor/Src/Gui/Ime.cs	2012-10-26 19:40:55 UTC (rev 7159)
@@ -39,7 +39,7 @@
 				return font;
 			}
 			set {
-				if (!value.Equals(font)) {
+				if (!Font.Equals(value, font)) {
 					font = value;
 					lf = null;
 					SetIMEWindowFont(value);



More information about the mapguide-commits mailing list