Browse Source

make work folding in XML files

newNRvisualizers
Siegfried Pammer 14 years ago
parent
commit
3f0243369b
  1. 21
      SharpDevelop.sln
  2. 17
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/DefaultParserService.cs
  3. 33
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/FoldingRegion.cs
  4. 13
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/IParserService.cs
  5. 4
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/IXmlFoldParser.cs
  6. 3
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeTextMarker.cs
  7. 4
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs
  8. 7
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs
  9. 3
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCommentFold.cs
  10. 4
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlElementFold.cs
  11. 14
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFoldParser.cs
  12. 27
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFoldingManager.cs
  13. 10
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs
  14. 1
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeView.cs
  15. 3
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs
  16. 7
      src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj

21
SharpDevelop.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.2.0.8658-Beta 2
# SharpDevelop 4.2.0.8662-Beta 2
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
@ -161,6 +161,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvalonEdit.AddIn", "src\Add @@ -161,6 +161,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvalonEdit.AddIn", "src\Add
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HexEditor", "src\AddIns\DisplayBindings\HexEditor\Project\HexEditor.csproj", "{E618A9CD-A39F-4925-A538-E8A3FEF24E54}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "src\AddIns\DisplayBindings\XmlEditor\Project\XmlEditor.csproj", "{DCA2703D-250A-463E-A68A-07ED105AE6BD}"
EndProject
Project("{00000000-0000-0000-0000-000000000000}") = "Tools", "src\Tools\Tools.build", "{3DF4060F-5EE0-41CF-8096-F27355FD5511}"
EndProject
Global
@ -523,6 +525,22 @@ Global @@ -523,6 +525,22 @@ Global
{70966F84-74C9-4067-A379-0C674A929233}.Release|x86.ActiveCfg = Release|Any CPU
{70966F84-74C9-4067-A379-0C674A929233}.Release|Debug.Build.0 = Release|Any CPU
{70966F84-74C9-4067-A379-0C674A929233}.Release|Debug.ActiveCfg = Release|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Debug|Win32.Build.0 = Debug|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Debug|Win32.ActiveCfg = Debug|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Debug|x86.Build.0 = Debug|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Debug|x86.ActiveCfg = Debug|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Debug|Debug.Build.0 = Debug|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Debug|Debug.ActiveCfg = Debug|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Release|Any CPU.Build.0 = Release|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Release|Win32.Build.0 = Release|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Release|Win32.ActiveCfg = Release|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Release|x86.Build.0 = Release|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Release|x86.ActiveCfg = Release|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Release|Debug.Build.0 = Release|Any CPU
{DCA2703D-250A-463E-A68A-07ED105AE6BD}.Release|Debug.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -568,5 +586,6 @@ Global @@ -568,5 +586,6 @@ Global
{0008FCE9-9EB4-4E2E-979B-553278E5BBA6} = {59A30AA6-D600-41AB-B7A1-9543469DBE36}
{0162E499-42D0-409B-AA25-EED21F75336B} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{E618A9CD-A39F-4925-A538-E8A3FEF24E54} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{DCA2703D-250A-463E-A68A-07ED105AE6BD} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
EndGlobalSection
EndGlobal

17
src/AddIns/DisplayBindings/XmlEditor/Project/Src/DefaultParserService.cs

@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.XmlEditor
{
public class DefaultParserService : IParserService
{
public ParseInformation GetExistingParseInformation(IProjectContent content, string fileName)
{
return ParserService.GetExistingParseInformation(content, fileName);
}
}
}

33
src/AddIns/DisplayBindings/XmlEditor/Project/Src/FoldingRegion.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.XmlEditor
{
/// <summary>
/// Description of FoldingRegion.
/// </summary>
public class FoldingRegion
{
DomRegion region;
string name;
public DomRegion Region {
get { return region; }
set { region = value; }
}
public string Name {
get { return name; }
set { name = value; }
}
public FoldingRegion(string name, DomRegion region)
{
this.region = region;
this.name = name;
}
}
}

13
src/AddIns/DisplayBindings/XmlEditor/Project/Src/IParserService.cs

@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.XmlEditor
{
public interface IParserService
{
ParseInformation GetExistingParseInformation(IProjectContent content, string fileName);
}
}

4
src/AddIns/DisplayBindings/XmlEditor/Project/Src/IXmlFoldParser.cs

@ -4,14 +4,14 @@ @@ -4,14 +4,14 @@
using System;
using System.Collections.Generic;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.XmlEditor
{
public interface IXmlFoldParser
{
IList<FoldingRegion> GetFolds(ITextBuffer textBuffer);
IList<FoldingRegion> GetFolds(ITextSource textSource);
}
}

3
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeTextMarker.cs

@ -5,6 +5,7 @@ using System; @@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Windows.Media;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.XmlEditor
@ -35,7 +36,7 @@ namespace ICSharpCode.XmlEditor @@ -35,7 +36,7 @@ namespace ICSharpCode.XmlEditor
public void AddMarker(XPathNodeMatch node)
{
if (node.HasLineInfo() && node.Value.Length > 0) {
int offset = document.PositionToOffset(node.LineNumber + 1, node.LinePosition + 1);
int offset = document.GetOffset(node.LineNumber + 1, node.LinePosition + 1);
if (markerService != null) {
ITextMarker marker = markerService.Create(offset, node.Value.Length);
marker.Tag = typeof(XPathNodeTextMarker);

4
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs

@ -594,9 +594,9 @@ namespace ICSharpCode.XmlEditor @@ -594,9 +594,9 @@ namespace ICSharpCode.XmlEditor
if (view != null) {
ITextEditor editor = view.TextEditor;
if (editor == null) return;
int corLine = Math.Min(line + 1, editor.Document.TotalNumberOfLines - 1);
int corLine = Math.Min(line + 1, editor.Document.LineCount - 1);
editor.JumpTo(corLine, column + 1);
if (length > 0 && line < editor.Document.TotalNumberOfLines) {
if (length > 0 && line < editor.Document.LineCount) {
int offset = editor.Document.PositionToOffset(line + 1, column + 1);
editor.Select(offset, length);
}

7
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs

@ -12,7 +12,7 @@ using ICSharpCode.SharpDevelop.Editor.CodeCompletion; @@ -12,7 +12,7 @@ using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
namespace ICSharpCode.XmlEditor
{
public class XmlCodeCompletionBinding : ICodeCompletionBinding
{
{
XmlSchemaFileAssociations schemaFileAssociations;
XmlSchemaCompletionCollection schemas;
@ -86,5 +86,10 @@ namespace ICSharpCode.XmlEditor @@ -86,5 +86,10 @@ namespace ICSharpCode.XmlEditor
}
return false;
}
public bool HandleKeyPressed(ITextEditor editor, char ch)
{
return false;
}
}
}

3
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCommentFold.cs

@ -3,7 +3,8 @@ @@ -3,7 +3,8 @@
using System;
using System.Xml;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.XmlEditor
{

4
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlElementFold.cs

@ -4,7 +4,9 @@ @@ -4,7 +4,9 @@
using System;
using System.Text;
using System.Xml;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.XmlEditor
{

14
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFoldParser.cs

@ -7,8 +7,8 @@ using System.IO; @@ -7,8 +7,8 @@ using System.IO;
using System.Text;
using System.Xml;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.XmlEditor
@ -28,12 +28,12 @@ namespace ICSharpCode.XmlEditor @@ -28,12 +28,12 @@ namespace ICSharpCode.XmlEditor
public XmlFoldParser()
: this(XmlEditorService.XmlEditorOptions)
{
}
}
public IList<FoldingRegion> GetFolds(ITextBuffer textBuffer)
public IList<FoldingRegion> GetFolds(ITextSource textSource)
{
try {
GetFolds(textBuffer.CreateReader());
GetFolds(textSource.CreateReader());
return folds;
} catch (XmlException) {
}
@ -52,7 +52,7 @@ namespace ICSharpCode.XmlEditor @@ -52,7 +52,7 @@ namespace ICSharpCode.XmlEditor
case XmlNodeType.Element:
AddElementFoldToStackIfNotEmptyElement();
break;
case XmlNodeType.EndElement:
CreateElementFoldingRegionIfNotSingleLine();
break;
@ -64,7 +64,7 @@ namespace ICSharpCode.XmlEditor @@ -64,7 +64,7 @@ namespace ICSharpCode.XmlEditor
}
folds.Sort(CompareFoldingRegion);
}
void CreateXmlTextReaderWithNoNamespaceSupport(TextReader textReader)
{
reader = new XmlTextReader(textReader);
@ -102,7 +102,7 @@ namespace ICSharpCode.XmlEditor @@ -102,7 +102,7 @@ namespace ICSharpCode.XmlEditor
/// <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
/// <remarks>The text displayed when the comment is folded is the first
/// line of the comment.</remarks>
void CreateCommentFoldingRegionIfNotSingleLine()
{

27
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFoldingManager.cs

@ -4,9 +4,11 @@ @@ -4,9 +4,11 @@
using System;
using System.Collections.Generic;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.XmlEditor
@ -29,7 +31,7 @@ namespace ICSharpCode.XmlEditor @@ -29,7 +31,7 @@ namespace ICSharpCode.XmlEditor
public XmlFoldingManager(ITextEditor textEditor, IFoldingManager foldingManager, IXmlFoldParser xmlFoldParser)
{
document = textEditor.Document;
document.Changed += DocumentChanged;
document.TextChanged += DocumentChanged;
this.foldingManager = foldingManager;
this.xmlFoldParser = xmlFoldParser;
@ -45,38 +47,33 @@ namespace ICSharpCode.XmlEditor @@ -45,38 +47,33 @@ namespace ICSharpCode.XmlEditor
set { documentHasChangedSinceLastFoldUpdate = value; }
}
public ITextBuffer CreateTextEditorSnapshot()
public ITextSource CreateTextEditorSnapshot()
{
return document.CreateSnapshot();
}
public void Dispose()
{
document.Changed -= DocumentChanged;
document.TextChanged -= DocumentChanged;
foldingManager.Dispose();
}
public IList<FoldingRegion> GetFolds(ITextBuffer textBuffer)
public IList<FoldingRegion> GetFolds(ITextSource textSource)
{
return xmlFoldParser.GetFolds(textBuffer);
return xmlFoldParser.GetFolds(textSource);
}
public void UpdateFolds(IEnumerable<FoldingRegion> folds)
{
IList<NewFolding> newFolds = ConvertFoldRegionsToNewFolds(folds);
UpdateFolds(newFolds);
}
public void UpdateFolds(IEnumerable<NewFolding> folds)
{
int firstErrorOffset = NoFirstErrorOffset;
foldingManager.UpdateFoldings(folds, firstErrorOffset);
foldingManager.UpdateFoldings(ConvertFoldRegionsToNewFolds(folds), firstErrorOffset);
}
public void UpdateFolds()
{
ITextBuffer textBuffer = CreateTextEditorSnapshot();
IList<FoldingRegion> folds = GetFolds(textBuffer);
ITextSource textSource = CreateTextEditorSnapshot();
IList<FoldingRegion> folds = GetFolds(textSource);
if (folds != null) {
UpdateFolds(folds);
}

10
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs

@ -11,6 +11,8 @@ using System.Xml; @@ -11,6 +11,8 @@ using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.XmlEditor
@ -140,7 +142,7 @@ namespace ICSharpCode.XmlEditor @@ -140,7 +142,7 @@ namespace ICSharpCode.XmlEditor
}
// set indentation of 'nextLine'
IDocumentLine line = document.GetLine(nextLine);
string lineText = line.Text;
string lineText = document.GetText(line);
string newText;
// special case: opening tag has closing bracket on extra line: remove one indentation level
@ -152,8 +154,8 @@ namespace ICSharpCode.XmlEditor @@ -152,8 +154,8 @@ namespace ICSharpCode.XmlEditor
if (newText != lineText) {
int extraCharsToBeAddedAtStartedOfLine = newText.Length - lineText.Length;
document.Replace(line.Offset, line.Length, newText);
Location caretPosition = document.OffsetToPosition(line.Offset + extraCharsToBeAddedAtStartedOfLine);
editor.Caret.Position = caretPosition;
TextLocation caretLocation = document.GetLocation(line.Offset + extraCharsToBeAddedAtStartedOfLine);
editor.Caret.Location = caretLocation;
}
nextLine++;
}
@ -182,7 +184,7 @@ namespace ICSharpCode.XmlEditor @@ -182,7 +184,7 @@ namespace ICSharpCode.XmlEditor
if (nextLine > end) break;
// set indentation of 'nextLine'
IDocumentLine line = document.GetLine(nextLine);
string newText = attribIndent + line.Text.Trim();
string newText = attribIndent + document.GetText(line).Trim();
document.SmartReplaceLine(line, newText);
nextLine++;
}

1
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeView.cs

@ -9,6 +9,7 @@ using System.Xml; @@ -9,6 +9,7 @@ using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.Core.WinForms;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;

3
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs

@ -13,6 +13,7 @@ using System.Xml.XPath; @@ -13,6 +13,7 @@ using System.Xml.XPath;
using System.Xml.Xsl;
using ICSharpCode.Core;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
@ -154,7 +155,7 @@ namespace ICSharpCode.XmlEditor @@ -154,7 +155,7 @@ namespace ICSharpCode.XmlEditor
static void AddTask(string fileName, string message, int column, int line, TaskType taskType)
{
TaskService.Add(new Task(FileName.Create(fileName), message, column, line, taskType));
TaskService.Add(new SDTask(FileName.Create(fileName), message, column, line, taskType));
}
#region XmlView methods

7
src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj

@ -86,13 +86,13 @@ @@ -86,13 +86,13 @@
<Compile Include="Src\CopyXmlTreeNode.cs" />
<Compile Include="Src\CreateSchemaCommand.cs" />
<Compile Include="Src\CutXmlTreeNode.cs" />
<Compile Include="Src\DefaultParserService.cs" />
<Compile Include="Src\DefaultXmlFileExtensions.cs" />
<Compile Include="Src\DefaultXmlSchemaFileAssociations.cs" />
<Compile Include="Src\DeleteXmlTreeNode.cs" />
<Compile Include="Src\EncodedStringWriter.cs" />
<Compile Include="Src\FileSystem.cs" />
<Compile Include="Src\FoldingManagerAdapter.cs" />
<Compile Include="Src\FoldingRegion.cs" />
<Compile Include="Src\FormatXmlCommand.cs" />
<Compile Include="Src\GoToSchemaDefinitionCommand.cs" />
<Compile Include="Src\GoToSchemaDefinitionEditAction.cs" />
@ -105,7 +105,6 @@ @@ -105,7 +105,6 @@
<Compile Include="Src\InsertElementBeforeCommand.cs" />
<Compile Include="Src\InsertTextNodeAfterCommand.cs" />
<Compile Include="Src\InsertTextNodeBeforeCommand.cs" />
<Compile Include="Src\IParserService.cs" />
<Compile Include="Src\ISelectXmlSchemaWindow.cs" />
<Compile Include="Src\IXmlFoldParser.cs" />
<Compile Include="Src\IXmlSchemaCompletionDataFactory.cs" />
@ -200,6 +199,10 @@ @@ -200,6 +199,10 @@
<Name>ICSharpCode.AvalonEdit</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>

Loading…
Cancel
Save