diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj b/src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj index ad2daa0f37..941f0fb563 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj +++ b/src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj @@ -46,6 +46,8 @@ + + diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/CustomLineManager.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/CustomLineManager.cs new file mode 100644 index 0000000000..b16a0fbed3 --- /dev/null +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/CustomLineManager.cs @@ -0,0 +1,217 @@ +// +// +// +// +// +// + +using System; +using System.Collections; +using System.Drawing; + +namespace ICSharpCode.TextEditor.Document +{ + /// + /// This class is used to store a pair of lineNr and its color + /// + 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; + } + } + + /// + /// This class handles the bookmarks for a buffer + /// + public class CustomLineManager : ICustomLineManager + { + ArrayList lines = new ArrayList(); + + /// + /// Creates a new instance of + /// + public CustomLineManager(ILineManager lineTracker) + { + lineTracker.LineCountChanged += new LineManagerEventHandler(MoveIndices); + } + + /// + /// Contains all custom lines + /// + public ArrayList CustomLines { + get { + return lines; + } + } + + /// + /// Returns the Color if the line lineNr has custom bg color + /// otherwise returns defaultColor + /// + public Color GetCustomColor(int lineNr, Color defaultColor) + { + foreach(CustomLine line in lines) + if (line.StartLineNr <= lineNr && line.EndLineNr >= lineNr) + return line.Color; + return defaultColor; + } + + /// + /// Returns the ReadOnly if the line lineNr is custom + /// otherwise returns default + /// + public bool IsReadOnly(int lineNr, bool defaultReadOnly) + { + foreach(CustomLine line in lines) + if (line.StartLineNr <= lineNr && line.EndLineNr >= lineNr) + return line.ReadOnly; + return defaultReadOnly; + } + + /// + /// Returns true if selection is read only + /// + 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; + } + + /// + /// Clears all custom lines + /// + public void Clear() + { + OnBeforeChanged(); + lines.Clear(); + OnChanged(); + } + + /// + /// Is fired before the change + /// + public event EventHandler BeforeChanged; + + /// + /// Is fired after the change + /// + public event EventHandler Changed; + + + + void OnChanged() + { + if (Changed != null) { + Changed(this, null); + } + } + void OnBeforeChanged() + { + if (BeforeChanged != null) { + BeforeChanged(this, null); + } + } + + /// + /// Set Custom Line at the line lineNr + /// + public void AddCustomLine(int lineNr, Color customColor, bool readOnly) + { + OnBeforeChanged(); + lines.Add(new CustomLine(lineNr, customColor, readOnly)); + OnChanged(); + } + + /// + /// Add Custom Lines from the line startLineNr to the line endLineNr + /// + public void AddCustomLine(int startLineNr, int endLineNr, Color customColor, bool readOnly) + { + OnBeforeChanged(); + lines.Add(new CustomLine(startLineNr, endLineNr, customColor, readOnly)); + OnChanged(); + } + + /// + /// Remove Custom Line at the line lineNr + /// + 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; + } + } + } + + /// + /// This method moves all indices from index upward count lines + /// (useful for deletion/insertion of text) + /// + 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(); + } + } + + } +} diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/ICustomLineManager.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/ICustomLineManager.cs new file mode 100644 index 0000000000..109e4ba6dc --- /dev/null +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/CustomLineManager/ICustomLineManager.cs @@ -0,0 +1,72 @@ +// +// +// +// +// +// + +using System; +using System.Collections; +using System.Drawing; + +namespace ICSharpCode.TextEditor.Document +{ + /// + /// This class handles the custom lines for a buffer + /// + public interface ICustomLineManager + { + /// + /// Contains all custom lines + /// + ArrayList CustomLines { + get; + } + + /// + /// Returns the Color if the line lineNr has custom bg color + /// otherwise returns defaultColor + /// + Color GetCustomColor(int lineNr, Color defaultColor); + + /// + /// Returns true if the line lineNr is read only + /// + bool IsReadOnly(int lineNr, bool defaultReadOnly); + + /// + /// Returns true if selection is read only + /// + bool IsReadOnly(ISelection selection, bool defaultReadOnly); + + /// + /// Add Custom Line at the line lineNr + /// + void AddCustomLine(int lineNr, Color customColor, bool readOnly); + + /// + /// Add Custom Lines from the line startLineNr to the line endLineNr + /// + void AddCustomLine(int startLineNr, int endLineNr, Color customColor, bool readOnly); + + /// + /// Remove Custom Line at the line lineNr + /// + void RemoveCustomLine(int lineNr); + + /// + /// Clears all custom color lines + /// + void Clear(); + + /// + /// Is fired before the change + /// + event EventHandler BeforeChanged; + + /// + /// Is fired after the change + /// + event EventHandler Changed; + } +} diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs index e8c34fb808..3c205d6b69 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs @@ -96,6 +96,7 @@ namespace ICSharpCode.TextEditor.Document bool readOnly = false; ILineManager lineTrackingStrategy = null; + ICustomLineManager customLineManager = null; BookmarkManager bookmarkManager = null; ITextBufferStrategy textBufferStrategy = null; IFormattingStrategy formattingStrategy = null; @@ -203,6 +204,16 @@ namespace ICSharpCode.TextEditor.Document } } + + public ICustomLineManager CustomLineManager { + get { + return customLineManager; + } + set { + customLineManager = value; + } + } + public string TextContent { get { return GetText(0, textBufferStrategy.Length); diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultTextEditorProperties.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultTextEditorProperties.cs index d953cce08d..512f5cc2a0 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultTextEditorProperties.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultTextEditorProperties.cs @@ -51,6 +51,7 @@ namespace ICSharpCode.TextEditor.Document LineViewerStyle lineViewerStyle = LineViewerStyle.None; string lineTerminator = "\r\n"; bool autoInsertCurlyBracket = true; + bool useCustomLine = false; public int TabIndent { get { @@ -273,7 +274,14 @@ namespace ICSharpCode.TextEditor.Document bracketMatchingStyle = value; } } - + public bool UseCustomLine { + get { + return useCustomLine; + } + set { + useCustomLine = value; + } + } } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs index 7b54540571..50d0fb980d 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs @@ -31,6 +31,7 @@ namespace ICSharpCode.TextEditor.Document doc.FoldingManager.FoldingStrategy = null; //new ParserFoldingStrategy(); doc.MarkerStrategy = new MarkerStrategy(doc); doc.BookmarkManager = new BookmarkManager(doc, doc.LineManager); + doc.CustomLineManager = new CustomLineManager(doc.LineManager); return doc; } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs index cf8d750a65..bbf23bba61 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs +++ b/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); // 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["VRuler"] = new HighlightColor("ControlLight", "Window", false, false); environmentColors["InvalidLines"] = new HighlightColor(Color.Red, false, false); @@ -182,7 +182,7 @@ namespace ICSharpCode.TextEditor.Document public HighlightColor GetColorFor(string name) { - if (environmentColors[name] == null) { + if (! environmentColors.ContainsKey(name)) { throw new Exception("Color : " + name + " not found!"); } return (HighlightColor)environmentColors[name]; @@ -660,7 +660,7 @@ namespace ICSharpCode.TextEditor.Document if (c == null) { c = activeSpan.Color; if (c.Color == Color.Transparent) { - c = GetColorFor("Default"); + c = GetColorFor("DefaultBackground"); } hasDefaultColor = true; } @@ -668,7 +668,7 @@ namespace ICSharpCode.TextEditor.Document } else { HighlightColor c = markNext != null ? markNext : GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength); 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 { words.Add(new TextWord(document, currentLine, currentOffset, currentLength, c, false)); } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs index ac5bdfa705..dff8aa834c 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/IDocument.cs @@ -72,6 +72,13 @@ namespace ICSharpCode.TextEditor.Document get; } + /// + /// The attached to the instance + /// + ICustomLineManager CustomLineManager { + get; + } + MarkerStrategy MarkerStrategy { get; } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/ITextEditorProperties.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/ITextEditorProperties.cs index 4b980dd07e..0f67a0ba9b 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/ITextEditorProperties.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/ITextEditorProperties.cs @@ -147,6 +147,10 @@ namespace ICSharpCode.TextEditor.Document get; set; } - + + bool UseCustomLine { + get; + set; + } } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs index 08e00c279f..cf16f9c6e1 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs @@ -454,6 +454,14 @@ namespace ICSharpCode.TextEditor 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 < ' ') { return; } @@ -507,6 +515,29 @@ namespace ICSharpCode.TextEditor 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 IEditAction action = motherTextEditorControl.GetEditAction(keyData); AutoClearSelection = true; @@ -556,6 +587,22 @@ namespace ICSharpCode.TextEditor 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) { return new String(' ', length); diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs index b55bfdaefc..d0ae43efe1 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextView.cs @@ -276,14 +276,19 @@ namespace ICSharpCode.TextEditor return lineNumber == base.textArea.Caret.Line && textArea.MotherTextAreaControl.TextEditorProperties.LineViewerStyle == LineViewerStyle.FullRow; } - Brush GetBgColorBrush(int lineNumber) + Brush GetBgColorBrush(int lineNumber) { if (DrawLineMarkerAtLine(lineNumber)) { HighlightColor caretLine = textArea.Document.HighlightingStrategy.GetColorFor("CaretMarker"); return BrushRegistry.GetBrush(caretLine.Color); } - HighlightBackground background = (HighlightBackground)textArea.Document.HighlightingStrategy.GetColorFor("Default"); - return BrushRegistry.GetBrush(background.BackgroundColor); + HighlightBackground background = (HighlightBackground)textArea.Document.HighlightingStrategy.GetColorFor("DefaultBackground"); + 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) diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs index 912fd5836f..a66dfda5b4 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs @@ -282,6 +282,16 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor properties.Set("BracketMatchingStyle", value); } } + + bool useCustomLine = false; + public bool UseCustomLine { + get { + return useCustomLine; + } + set { + useCustomLine = value; + } + } /*