Browse Source

SD2-453: ported CustomLineManager from Fidalgo

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@560 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Markus Palme 21 years ago
parent
commit
278feb767e
  1. 2
      src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj
  2. 217
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/CustomLineManager.cs
  3. 72
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/ICustomLineManager.cs
  4. 11
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs
  5. 10
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultTextEditorProperties.cs
  6. 1
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs
  7. 8
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs
  8. 7
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs
  9. 4
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/ITextEditorProperties.cs
  10. 47
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs
  11. 9
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs
  12. 10
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs

2
src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj

@ -46,6 +46,8 @@
<Compile Include="Src\Document\ISegment.cs" /> <Compile Include="Src\Document\ISegment.cs" />
<Compile Include="Src\Document\TextUtilities.cs" /> <Compile Include="Src\Document\TextUtilities.cs" />
<Compile Include="Src\Document\BookmarkManager\BookmarkManager.cs" /> <Compile Include="Src\Document\BookmarkManager\BookmarkManager.cs" />
<Compile Include="Src\Document\CustomLineManager\CustomLineManager.cs" />
<Compile Include="Src\Document\CustomLineManager\ICustomLineManager.cs" />
<Compile Include="Src\Document\BookmarkManager\BookmarkManagerMemento.cs" /> <Compile Include="Src\Document\BookmarkManager\BookmarkManagerMemento.cs" />
<Compile Include="Src\Document\FormattingStrategy\DefaultFormattingStrategy.cs" /> <Compile Include="Src\Document\FormattingStrategy\DefaultFormattingStrategy.cs" />
<Compile Include="Src\Document\FormattingStrategy\IFormattingStrategy.cs" /> <Compile Include="Src\Document\FormattingStrategy\IFormattingStrategy.cs" />

217
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/CustomLineManager.cs

@ -0,0 +1,217 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Ivo Kovacka" email="ivok@internet.sk"/>
// <version value="$version"/>
// </file>
using System;
using System.Collections;
using System.Drawing;
namespace ICSharpCode.TextEditor.Document
{
/// <summary>
/// This class is used to store a pair of lineNr and its color
/// </summary>
public class CustomLine
{
public int StartLineNr;
public int EndLineNr;
public Color Color;
public bool ReadOnly;
public CustomLine(int lineNr, Color customColor, bool readOnly)
{
this.StartLineNr = this.EndLineNr = lineNr;
this.Color = customColor;
this.ReadOnly = readOnly;
}
public CustomLine(int startLineNr, int endLineNr, Color customColor, bool readOnly)
{
this.StartLineNr = startLineNr;
this.EndLineNr = endLineNr;
this.Color = customColor;
this.ReadOnly = readOnly;
}
}
/// <summary>
/// This class handles the bookmarks for a buffer
/// </summary>
public class CustomLineManager : ICustomLineManager
{
ArrayList lines = new ArrayList();
/// <summary>
/// Creates a new instance of <see cref="CustomLineManager"/>
/// </summary>
public CustomLineManager(ILineManager lineTracker)
{
lineTracker.LineCountChanged += new LineManagerEventHandler(MoveIndices);
}
/// <value>
/// Contains all custom lines
/// </value>
public ArrayList CustomLines {
get {
return lines;
}
}
/// <remarks>
/// Returns the Color if the line <code>lineNr</code> has custom bg color
/// otherwise returns <code>defaultColor</code>
/// </remarks>
public Color GetCustomColor(int lineNr, Color defaultColor)
{
foreach(CustomLine line in lines)
if (line.StartLineNr <= lineNr && line.EndLineNr >= lineNr)
return line.Color;
return defaultColor;
}
/// <remarks>
/// Returns the ReadOnly if the line <code>lineNr</code> is custom
/// otherwise returns <code>default</code>
/// </remarks>
public bool IsReadOnly(int lineNr, bool defaultReadOnly)
{
foreach(CustomLine line in lines)
if (line.StartLineNr <= lineNr && line.EndLineNr >= lineNr)
return line.ReadOnly;
return defaultReadOnly;
}
/// <remarks>
/// Returns true if <code>selection</code> is read only
/// </remarks>
public bool IsReadOnly(ISelection selection, bool defaultReadOnly)
{
int startLine = selection.StartPosition.Y;
int endLine = selection.EndPosition.Y;
foreach (CustomLine customLine in lines) {
if (customLine.ReadOnly == false)
continue;
if (startLine < customLine.StartLineNr && endLine < customLine.StartLineNr)
continue;
if (startLine > customLine.EndLineNr && endLine > customLine.EndLineNr)
continue;
return true;
}
return defaultReadOnly;
}
/// <remarks>
/// Clears all custom lines
/// </remarks>
public void Clear()
{
OnBeforeChanged();
lines.Clear();
OnChanged();
}
/// <remarks>
/// Is fired before the change
/// </remarks>
public event EventHandler BeforeChanged;
/// <remarks>
/// Is fired after the change
/// </remarks>
public event EventHandler Changed;
void OnChanged()
{
if (Changed != null) {
Changed(this, null);
}
}
void OnBeforeChanged()
{
if (BeforeChanged != null) {
BeforeChanged(this, null);
}
}
/// <remarks>
/// Set Custom Line at the line <code>lineNr</code>
/// </remarks>
public void AddCustomLine(int lineNr, Color customColor, bool readOnly)
{
OnBeforeChanged();
lines.Add(new CustomLine(lineNr, customColor, readOnly));
OnChanged();
}
/// <remarks>
/// Add Custom Lines from the line <code>startLineNr</code> to the line <code>endLineNr</code>
/// </remarks>
public void AddCustomLine(int startLineNr, int endLineNr, Color customColor, bool readOnly)
{
OnBeforeChanged();
lines.Add(new CustomLine(startLineNr, endLineNr, customColor, readOnly));
OnChanged();
}
/// <remarks>
/// Remove Custom Line at the line <code>lineNr</code>
/// </remarks>
public void RemoveCustomLine(int lineNr)
{
for (int i = 0; i < lines.Count; ++i) {
if (((CustomLine)lines[i]).StartLineNr <= lineNr && ((CustomLine)lines[i]).EndLineNr >= lineNr) {
OnBeforeChanged();
lines.RemoveAt(i);
OnChanged();
return;
}
}
}
/// <summary>
/// This method moves all indices from index upward count lines
/// (useful for deletion/insertion of text)
/// </summary>
void MoveIndices(object sender,LineManagerEventArgs e)
{
bool changed = false;
OnBeforeChanged();
for (int i = 0; i < lines.Count; ++i) {
int startLineNr = ((CustomLine)lines[i]).StartLineNr;
int endLineNr = ((CustomLine)lines[i]).EndLineNr;
if (e.LineStart >= startLineNr && e.LineStart < endLineNr) {
changed = true;
((CustomLine)lines[i]).EndLineNr += e.LinesMoved;
}
else if (e.LineStart < startLineNr) {
((CustomLine)lines[i]).StartLineNr += e.LinesMoved;
((CustomLine)lines[i]).EndLineNr += e.LinesMoved;
}
else {
}
/*
if (e.LinesMoved < 0 && lineNr == e.LineStart) {
lines.RemoveAt(i);
--i;
changed = true;
} else if (lineNr > e.LineStart + 1 || (e.LinesMoved < 0 && lineNr > e.LineStart)) {
changed = true;
((CustomLine)lines[i]).StartLineNr += e.LinesMoved;
((CustomLine)lines[i]).EndLineNr += e.LinesMoved;
}
*/
}
if (changed) {
OnChanged();
}
}
}
}

72
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/ICustomLineManager.cs

@ -0,0 +1,72 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Ivo Kovacka" email="ivok@internet.sk"/>
// <version value="$version"/>
// </file>
using System;
using System.Collections;
using System.Drawing;
namespace ICSharpCode.TextEditor.Document
{
/// <summary>
/// This class handles the custom lines for a buffer
/// </summary>
public interface ICustomLineManager
{
/// <value>
/// Contains all custom lines
/// </value>
ArrayList CustomLines {
get;
}
/// <remarks>
/// Returns the Color if the line <code>lineNr</code> has custom bg color
/// otherwise returns <code>defaultColor</code>
/// </remarks>
Color GetCustomColor(int lineNr, Color defaultColor);
/// <remarks>
/// Returns true if the line <code>lineNr</code> is read only
/// </remarks>
bool IsReadOnly(int lineNr, bool defaultReadOnly);
/// <remarks>
/// Returns true if <code>selection</code> is read only
/// </remarks>
bool IsReadOnly(ISelection selection, bool defaultReadOnly);
/// <remarks>
/// Add Custom Line at the line <code>lineNr</code>
/// </remarks>
void AddCustomLine(int lineNr, Color customColor, bool readOnly);
/// <remarks>
/// Add Custom Lines from the line <code>startLineNr</code> to the line <code>endLineNr</code>
/// </remarks>
void AddCustomLine(int startLineNr, int endLineNr, Color customColor, bool readOnly);
/// <remarks>
/// Remove Custom Line at the line <code>lineNr</code>
/// </remarks>
void RemoveCustomLine(int lineNr);
/// <remarks>
/// Clears all custom color lines
/// </remarks>
void Clear();
/// <remarks>
/// Is fired before the change
/// </remarks>
event EventHandler BeforeChanged;
/// <remarks>
/// Is fired after the change
/// </remarks>
event EventHandler Changed;
}
}

11
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs

@ -96,6 +96,7 @@ namespace ICSharpCode.TextEditor.Document
bool readOnly = false; bool readOnly = false;
ILineManager lineTrackingStrategy = null; ILineManager lineTrackingStrategy = null;
ICustomLineManager customLineManager = null;
BookmarkManager bookmarkManager = null; BookmarkManager bookmarkManager = null;
ITextBufferStrategy textBufferStrategy = null; ITextBufferStrategy textBufferStrategy = null;
IFormattingStrategy formattingStrategy = null; IFormattingStrategy formattingStrategy = null;
@ -203,6 +204,16 @@ namespace ICSharpCode.TextEditor.Document
} }
} }
public ICustomLineManager CustomLineManager {
get {
return customLineManager;
}
set {
customLineManager = value;
}
}
public string TextContent { public string TextContent {
get { get {
return GetText(0, textBufferStrategy.Length); return GetText(0, textBufferStrategy.Length);

10
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultTextEditorProperties.cs

@ -51,6 +51,7 @@ namespace ICSharpCode.TextEditor.Document
LineViewerStyle lineViewerStyle = LineViewerStyle.None; LineViewerStyle lineViewerStyle = LineViewerStyle.None;
string lineTerminator = "\r\n"; string lineTerminator = "\r\n";
bool autoInsertCurlyBracket = true; bool autoInsertCurlyBracket = true;
bool useCustomLine = false;
public int TabIndent { public int TabIndent {
get { get {
@ -274,6 +275,13 @@ namespace ICSharpCode.TextEditor.Document
} }
} }
public bool UseCustomLine {
get {
return useCustomLine;
}
set {
useCustomLine = value;
}
}
} }
} }

1
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs

@ -31,6 +31,7 @@ namespace ICSharpCode.TextEditor.Document
doc.FoldingManager.FoldingStrategy = null; //new ParserFoldingStrategy(); doc.FoldingManager.FoldingStrategy = null; //new ParserFoldingStrategy();
doc.MarkerStrategy = new MarkerStrategy(doc); doc.MarkerStrategy = new MarkerStrategy(doc);
doc.BookmarkManager = new BookmarkManager(doc, doc.LineManager); doc.BookmarkManager = new BookmarkManager(doc, doc.LineManager);
doc.CustomLineManager = new CustomLineManager(doc.LineManager);
return doc; return doc;
} }

8
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.TextEditor.Document
digitColor = new HighlightBackground("WindowText", "Window", false, false); digitColor = new HighlightBackground("WindowText", "Window", false, false);
// set small 'default color environment' // set small 'default color environment'
environmentColors["Default"] = new HighlightBackground("WindowText", "Window", false, false); environmentColors["DefaultBackground"]= new HighlightBackground("WindowText", "Window", false, false);
environmentColors["Selection"] = new HighlightColor("HighlightText", "Highlight", false, false); environmentColors["Selection"] = new HighlightColor("HighlightText", "Highlight", false, false);
environmentColors["VRuler"] = new HighlightColor("ControlLight", "Window", false, false); environmentColors["VRuler"] = new HighlightColor("ControlLight", "Window", false, false);
environmentColors["InvalidLines"] = new HighlightColor(Color.Red, false, false); environmentColors["InvalidLines"] = new HighlightColor(Color.Red, false, false);
@ -182,7 +182,7 @@ namespace ICSharpCode.TextEditor.Document
public HighlightColor GetColorFor(string name) public HighlightColor GetColorFor(string name)
{ {
if (environmentColors[name] == null) { if (! environmentColors.ContainsKey(name)) {
throw new Exception("Color : " + name + " not found!"); throw new Exception("Color : " + name + " not found!");
} }
return (HighlightColor)environmentColors[name]; return (HighlightColor)environmentColors[name];
@ -660,7 +660,7 @@ namespace ICSharpCode.TextEditor.Document
if (c == null) { if (c == null) {
c = activeSpan.Color; c = activeSpan.Color;
if (c.Color == Color.Transparent) { if (c.Color == Color.Transparent) {
c = GetColorFor("Default"); c = GetColorFor("DefaultBackground");
} }
hasDefaultColor = true; hasDefaultColor = true;
} }
@ -668,7 +668,7 @@ namespace ICSharpCode.TextEditor.Document
} else { } else {
HighlightColor c = markNext != null ? markNext : GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength); HighlightColor c = markNext != null ? markNext : GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
if (c == null) { if (c == null) {
words.Add(new TextWord(document, currentLine, currentOffset, currentLength, GetColorFor("Default"), true)); words.Add(new TextWord(document, currentLine, currentOffset, currentLength, GetColorFor("DefaultBackground"), true));
} else { } else {
words.Add(new TextWord(document, currentLine, currentOffset, currentLength, c, false)); words.Add(new TextWord(document, currentLine, currentOffset, currentLength, c, false));
} }

7
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs

@ -72,6 +72,13 @@ namespace ICSharpCode.TextEditor.Document
get; get;
} }
/// <summary>
/// The <see cref="ICustomColorLineManager"/> attached to the <see cref="IDocument"/> instance
/// </summary>
ICustomLineManager CustomLineManager {
get;
}
MarkerStrategy MarkerStrategy { MarkerStrategy MarkerStrategy {
get; get;
} }

4
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/ITextEditorProperties.cs

@ -148,5 +148,9 @@ namespace ICSharpCode.TextEditor.Document
set; set;
} }
bool UseCustomLine {
get;
set;
}
} }
} }

47
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs

@ -454,6 +454,14 @@ namespace ICSharpCode.TextEditor
return; return;
} }
if (TextEditorProperties.UseCustomLine == true) {
if (SelectionManager.HasSomethingSelected) {
if (Document.CustomLineManager.IsReadOnly(SelectionManager.SelectionCollection[0], false))
return;
} else if (Document.CustomLineManager.IsReadOnly(Caret.Line, false) == true)
return;
}
if (ch < ' ') { if (ch < ' ') {
return; return;
} }
@ -507,6 +515,29 @@ namespace ICSharpCode.TextEditor
return true; return true;
} }
if (keyData == Keys.Back || keyData == Keys.Delete || keyData == Keys.Enter) {
if (TextEditorProperties.UseCustomLine == true) {
if (SelectionManager.HasSomethingSelected) {
if (Document.CustomLineManager.IsReadOnly(SelectionManager.SelectionCollection[0], false))
return true;
} else {
int curLineNr = Document.GetLineNumberForOffset(Caret.Offset);
if (Document.CustomLineManager.IsReadOnly(curLineNr, false) == true)
return true;
if ((Caret.Column == 0) && (curLineNr - 1 >= 0) && keyData == Keys.Back &&
Document.CustomLineManager.IsReadOnly(curLineNr - 1, false) == true)
return true;
if (keyData == Keys.Delete) {
LineSegment curLine = Document.GetLineSegment(curLineNr);
if (curLine.Offset + curLine.Length == Caret.Offset &&
Document.CustomLineManager.IsReadOnly(curLineNr + 1, false) == true) {
return true;
}
}
}
}
}
// if not (or the process was 'silent', use the standard edit actions // if not (or the process was 'silent', use the standard edit actions
IEditAction action = motherTextEditorControl.GetEditAction(keyData); IEditAction action = motherTextEditorControl.GetEditAction(keyData);
AutoClearSelection = true; AutoClearSelection = true;
@ -556,6 +587,22 @@ namespace ICSharpCode.TextEditor
motherTextEditorControl.EndUpdate(); motherTextEditorControl.EndUpdate();
} }
public bool EnableCutOrPaste
{
get {
if (TextEditorProperties.UseCustomLine == true) {
if (SelectionManager.HasSomethingSelected == true) {
if (Document.CustomLineManager.IsReadOnly(SelectionManager.SelectionCollection[0], false))
return false;
}
if (Document.CustomLineManager.IsReadOnly(Caret.Line, false) == true)
return false;
}
return true;
}
}
string GenerateWhitespaceString(int length) string GenerateWhitespaceString(int length)
{ {
return new String(' ', length); return new String(' ', length);

9
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs

@ -282,8 +282,13 @@ namespace ICSharpCode.TextEditor
HighlightColor caretLine = textArea.Document.HighlightingStrategy.GetColorFor("CaretMarker"); HighlightColor caretLine = textArea.Document.HighlightingStrategy.GetColorFor("CaretMarker");
return BrushRegistry.GetBrush(caretLine.Color); return BrushRegistry.GetBrush(caretLine.Color);
} }
HighlightBackground background = (HighlightBackground)textArea.Document.HighlightingStrategy.GetColorFor("Default"); HighlightBackground background = (HighlightBackground)textArea.Document.HighlightingStrategy.GetColorFor("DefaultBackground");
return BrushRegistry.GetBrush(background.BackgroundColor); Color bgColor = background.BackgroundColor;
if (textArea.MotherTextAreaControl.TextEditorProperties.UseCustomLine == true)
{
bgColor = textArea.Document.CustomLineManager.GetCustomColor(lineNumber, bgColor);
}
return BrushRegistry.GetBrush(bgColor);
} }
float PaintFoldingText(Graphics g, int lineNumber, float physicalXPos, Rectangle lineRectangle, string text, bool drawSelected) float PaintFoldingText(Graphics g, int lineNumber, float physicalXPos, Rectangle lineRectangle, string text, bool drawSelected)

10
src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs

@ -283,6 +283,16 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
} }
} }
bool useCustomLine = false;
public bool UseCustomLine {
get {
return useCustomLine;
}
set {
useCustomLine = value;
}
}
/* /*
<Property key="DoubleBuffer" value="True" /> <Property key="DoubleBuffer" value="True" />
<Property key="ShowErrors" value="True" /> <Property key="ShowErrors" value="True" />

Loading…
Cancel
Save