42 changed files with 659 additions and 924 deletions
@ -1,122 +0,0 @@ |
|||||||
<Components version="1.0"> |
|
||||||
<System.Windows.Forms.UserControl> |
|
||||||
<Name value="MyUserControl" /> |
|
||||||
<GridSize value="{Width=8, Height=8}" /> |
|
||||||
<DockPadding value="" /> |
|
||||||
<DrawGrid value="True" /> |
|
||||||
<Size value="{Width=304, Height=208}" /> |
|
||||||
<SnapToGrid value="True" /> |
|
||||||
<Controls> |
|
||||||
<System.Windows.Forms.ComboBox> |
|
||||||
<Name value="actionComboBox" /> |
|
||||||
<Anchor value="Top, Right" /> |
|
||||||
<TabIndex value="7" /> |
|
||||||
<Location value="{X=192,Y=176}" /> |
|
||||||
<Size value="{Width=104, Height=21}" /> |
|
||||||
<DropDownStyle value="DropDownList" /> |
|
||||||
<Items> |
|
||||||
<System.String value="${res:Dialog.Options.CombineOptions.Startup.Action.None}" /> |
|
||||||
<System.String value="${res:Dialog.Options.CombineOptions.Startup.Action.Execute}" /> |
|
||||||
</Items> |
|
||||||
</System.Windows.Forms.ComboBox> |
|
||||||
<System.Windows.Forms.Label> |
|
||||||
<Name value="label" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.ActionLabel}" /> |
|
||||||
<Anchor value="Top, Right" /> |
|
||||||
<TabIndex value="6" /> |
|
||||||
<Size value="{Width=104, Height=23}" /> |
|
||||||
<Location value="{X=192,Y=152}" /> |
|
||||||
</System.Windows.Forms.Label> |
|
||||||
<System.Windows.Forms.Button> |
|
||||||
<Name value="moveDownButton" /> |
|
||||||
<Location value="{X=192,Y=112}" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.MoveDownButton}" /> |
|
||||||
<Anchor value="Top, Right" /> |
|
||||||
<TabIndex value="5" /> |
|
||||||
</System.Windows.Forms.Button> |
|
||||||
<System.Windows.Forms.Button> |
|
||||||
<Name value="moveUpButton" /> |
|
||||||
<Location value="{X=192,Y=80}" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.MoveUpButton}" /> |
|
||||||
<Anchor value="Top, Right" /> |
|
||||||
<TabIndex value="4" /> |
|
||||||
</System.Windows.Forms.Button> |
|
||||||
<System.Windows.Forms.ListView> |
|
||||||
<Name value="entryListView" /> |
|
||||||
<GridLines value="True" /> |
|
||||||
<Anchor value="Top, Left, Right" /> |
|
||||||
<TabIndex value="3" /> |
|
||||||
<View value="Details" /> |
|
||||||
<FullRowSelect value="True" /> |
|
||||||
<Location value="{X=24,Y=80}" /> |
|
||||||
<Size value="{Width=160, Height=120}" /> |
|
||||||
<Columns> |
|
||||||
<System.Windows.Forms.ColumnHeader> |
|
||||||
<Width value="156" /> |
|
||||||
<Name value="columnHeader" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.EntryColumnHeader}" /> |
|
||||||
</System.Windows.Forms.ColumnHeader> |
|
||||||
<System.Windows.Forms.ColumnHeader> |
|
||||||
<Width value="62" /> |
|
||||||
<Name value="columnHeader2" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.ActionColumnHeader}" /> |
|
||||||
</System.Windows.Forms.ColumnHeader> |
|
||||||
</Columns> |
|
||||||
</System.Windows.Forms.ListView> |
|
||||||
<System.Windows.Forms.RadioButton> |
|
||||||
<Name value="multipleRadioButton" /> |
|
||||||
<Location value="{X=8,Y=56}" /> |
|
||||||
<Size value="{Width=288, Height=24}" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.MultipleStartupRadioButton}" /> |
|
||||||
<Anchor value="Top, Left, Right" /> |
|
||||||
<TabIndex value="2" /> |
|
||||||
</System.Windows.Forms.RadioButton> |
|
||||||
<System.Windows.Forms.ComboBox> |
|
||||||
<Name value="singleComboBox" /> |
|
||||||
<Anchor value="Top, Left, Right" /> |
|
||||||
<TabIndex value="1" /> |
|
||||||
<Location value="{X=24,Y=32}" /> |
|
||||||
<Size value="{Width=272, Height=21}" /> |
|
||||||
<DropDownStyle value="DropDownList" /> |
|
||||||
</System.Windows.Forms.ComboBox> |
|
||||||
<System.Windows.Forms.RadioButton> |
|
||||||
<Name value="singleRadioButton" /> |
|
||||||
<Location value="{X=8,Y=8}" /> |
|
||||||
<Size value="{Width=288, Height=24}" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.SingleStartupRadioButton}" /> |
|
||||||
<Anchor value="Top, Left, Right" /> |
|
||||||
<TabIndex value="0" /> |
|
||||||
</System.Windows.Forms.RadioButton> |
|
||||||
</Controls> |
|
||||||
</System.Windows.Forms.UserControl> |
|
||||||
<System.Windows.Forms.ColumnHeader> |
|
||||||
<Width value="62" /> |
|
||||||
<Name value="columnHeader3" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.ActionColumnHeader}" /> |
|
||||||
</System.Windows.Forms.ColumnHeader> |
|
||||||
<System.Windows.Forms.ColumnHeader> |
|
||||||
<Width value="62" /> |
|
||||||
<Name value="columnHeader2" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.ActionColumnHeader}" /> |
|
||||||
</System.Windows.Forms.ColumnHeader> |
|
||||||
<System.Windows.Forms.ColumnHeader> |
|
||||||
<Width value="156" /> |
|
||||||
<Name value="columnHeader6" /> |
|
||||||
<Text value="Name" /> |
|
||||||
</System.Windows.Forms.ColumnHeader> |
|
||||||
<System.Windows.Forms.ColumnHeader> |
|
||||||
<Width value="156" /> |
|
||||||
<Name value="columnHeader5" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.EntryColumnHeader}" /> |
|
||||||
</System.Windows.Forms.ColumnHeader> |
|
||||||
<System.Windows.Forms.ColumnHeader> |
|
||||||
<Width value="62" /> |
|
||||||
<Name value="columnHeader4" /> |
|
||||||
<Text value="Action" /> |
|
||||||
</System.Windows.Forms.ColumnHeader> |
|
||||||
<System.Windows.Forms.ColumnHeader> |
|
||||||
<Width value="156" /> |
|
||||||
<Name value="columnHeader" /> |
|
||||||
<Text value="${res:Dialog.Options.CombineOptions.Startup.EntryColumnHeader}" /> |
|
||||||
</System.Windows.Forms.ColumnHeader> |
|
||||||
</Components> |
|
@ -0,0 +1,281 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <author name="Daniel Grunwald"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.NRefactory; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Editor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Read-only implementation of IDocument.
|
||||||
|
/// </summary>
|
||||||
|
sealed class ReadOnlyDocument : IDocument |
||||||
|
{ |
||||||
|
ITextBuffer textBuffer; |
||||||
|
int[] lines; |
||||||
|
|
||||||
|
public ReadOnlyDocument(ITextBuffer textBuffer) |
||||||
|
{ |
||||||
|
// ensure that underlying buffer is immutable
|
||||||
|
this.textBuffer = textBuffer.CreateSnapshot(); |
||||||
|
List<int> lines = new List<int>(); |
||||||
|
lines.Add(0); |
||||||
|
int offset = 0; |
||||||
|
string newlineType; |
||||||
|
var textSource = DocumentUtilitites.GetTextSource(this.textBuffer); |
||||||
|
while ((offset = ICSharpCode.AvalonEdit.Document.TextUtilities.FindNextNewLine(textSource, offset, out newlineType)) >= 0) { |
||||||
|
offset += newlineType.Length; |
||||||
|
lines.Add(offset); |
||||||
|
} |
||||||
|
this.lines = lines.ToArray(); |
||||||
|
} |
||||||
|
|
||||||
|
public IDocumentLine GetLine(int lineNumber) |
||||||
|
{ |
||||||
|
if (lineNumber < 1 || lineNumber > lines.Length) |
||||||
|
throw new ArgumentOutOfRangeException("lineNumber", lineNumber, "Value must be between 1 and " + lines.Length); |
||||||
|
return new ReadOnlyDocumentLine(this, lineNumber); |
||||||
|
} |
||||||
|
|
||||||
|
sealed class ReadOnlyDocumentLine : IDocumentLine |
||||||
|
{ |
||||||
|
readonly ReadOnlyDocument doc; |
||||||
|
readonly int lineNumber; |
||||||
|
|
||||||
|
public ReadOnlyDocumentLine(ReadOnlyDocument doc, int lineNumber) |
||||||
|
{ |
||||||
|
this.doc = doc; |
||||||
|
this.lineNumber = lineNumber; |
||||||
|
} |
||||||
|
|
||||||
|
public int Offset { |
||||||
|
get { |
||||||
|
return doc.GetStartOffset(lineNumber); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int Length { |
||||||
|
get { |
||||||
|
return doc.GetEndOffset(lineNumber) - doc.GetStartOffset(lineNumber); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int EndOffset { |
||||||
|
get { |
||||||
|
return doc.GetEndOffset(lineNumber); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int TotalLength { |
||||||
|
get { |
||||||
|
return doc.GetTotalEndOffset(lineNumber) - doc.GetStartOffset(lineNumber); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int DelimiterLength { |
||||||
|
get { |
||||||
|
return doc.GetTotalEndOffset(lineNumber) - doc.GetEndOffset(lineNumber); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int LineNumber { |
||||||
|
get { return lineNumber; } |
||||||
|
} |
||||||
|
|
||||||
|
public string Text { |
||||||
|
get { |
||||||
|
return doc.GetText(this.Offset, this.Length); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int GetStartOffset(int lineNumber) |
||||||
|
{ |
||||||
|
return lines[lineNumber-1]; |
||||||
|
} |
||||||
|
|
||||||
|
int GetTotalEndOffset(int lineNumber) |
||||||
|
{ |
||||||
|
return lineNumber < lines.Length ? lines[lineNumber] : textBuffer.TextLength; |
||||||
|
} |
||||||
|
|
||||||
|
int GetEndOffset(int lineNumber) |
||||||
|
{ |
||||||
|
if (lineNumber == lines.Length) |
||||||
|
return textBuffer.TextLength; |
||||||
|
int off = lines[lineNumber] - 1; |
||||||
|
if (off > 0 && textBuffer.GetCharAt(off - 1) == '\r' && textBuffer.GetCharAt(off) == '\n') |
||||||
|
off--; |
||||||
|
return off; |
||||||
|
} |
||||||
|
|
||||||
|
public IDocumentLine GetLineForOffset(int offset) |
||||||
|
{ |
||||||
|
return GetLine(GetLineNumberForOffset(offset)); |
||||||
|
} |
||||||
|
|
||||||
|
int GetLineNumberForOffset(int offset) |
||||||
|
{ |
||||||
|
int r = Array.BinarySearch(lines, offset); |
||||||
|
return r < 0 ? ~r : r + 1; |
||||||
|
} |
||||||
|
|
||||||
|
public int PositionToOffset(int line, int column) |
||||||
|
{ |
||||||
|
if (line < 1 || line > lines.Length) |
||||||
|
throw new ArgumentOutOfRangeException("line", line, "Value must be between 1 and " + lines.Length); |
||||||
|
int lineStart = GetStartOffset(line); |
||||||
|
if (column <= 0) |
||||||
|
return lineStart; |
||||||
|
int lineEnd = GetEndOffset(line); |
||||||
|
if (column >= lineEnd - lineStart) |
||||||
|
return lineEnd; |
||||||
|
return lineStart + column - 1; |
||||||
|
} |
||||||
|
|
||||||
|
public Location OffsetToPosition(int offset) |
||||||
|
{ |
||||||
|
if (offset < 0 || offset > textBuffer.TextLength) |
||||||
|
throw new ArgumentOutOfRangeException("offset", offset, "Value must be between 0 and " + textBuffer.TextLength); |
||||||
|
int line = GetLineNumberForOffset(offset); |
||||||
|
return new Location(offset-GetStartOffset(line)+1, line); |
||||||
|
} |
||||||
|
|
||||||
|
public event EventHandler<TextChangeEventArgs> Changing { add {} remove {} } |
||||||
|
|
||||||
|
public event EventHandler<TextChangeEventArgs> Changed { add {} remove {} } |
||||||
|
|
||||||
|
public event EventHandler TextChanged { add {} remove {} } |
||||||
|
|
||||||
|
public string Text { |
||||||
|
get { return textBuffer.Text; } |
||||||
|
set { |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int TotalNumberOfLines { |
||||||
|
get { return lines.Length; } |
||||||
|
} |
||||||
|
|
||||||
|
public ITextBufferVersion Version { |
||||||
|
get { return null; } |
||||||
|
} |
||||||
|
|
||||||
|
public int TextLength { |
||||||
|
get { return textBuffer.TextLength; } |
||||||
|
} |
||||||
|
|
||||||
|
public void Insert(int offset, string text) |
||||||
|
{ |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public void Remove(int offset, int length) |
||||||
|
{ |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public void Replace(int offset, int length, string newText) |
||||||
|
{ |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public void StartUndoableAction() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public void EndUndoableAction() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public IDisposable OpenUndoGroup() |
||||||
|
{ |
||||||
|
return new CallbackOnDispose(EndUndoableAction); |
||||||
|
} |
||||||
|
|
||||||
|
public ITextAnchor CreateAnchor(int offset) |
||||||
|
{ |
||||||
|
return new ReadOnlyDocumentTextAnchor(OffsetToPosition(offset), offset); |
||||||
|
} |
||||||
|
|
||||||
|
sealed class ReadOnlyDocumentTextAnchor : ITextAnchor |
||||||
|
{ |
||||||
|
readonly Location location; |
||||||
|
readonly int offset; |
||||||
|
|
||||||
|
public ReadOnlyDocumentTextAnchor(Location location, int offset) |
||||||
|
{ |
||||||
|
this.location = location; |
||||||
|
this.offset = offset; |
||||||
|
} |
||||||
|
|
||||||
|
public event EventHandler Deleted { add {} remove {} } |
||||||
|
|
||||||
|
public Location Location { |
||||||
|
get { return location; } |
||||||
|
} |
||||||
|
|
||||||
|
public int Offset { |
||||||
|
get { return offset; } |
||||||
|
} |
||||||
|
|
||||||
|
public AnchorMovementType MovementType { get; set; } |
||||||
|
|
||||||
|
public bool SurviveDeletion { get; set; } |
||||||
|
|
||||||
|
public bool IsDeleted { |
||||||
|
get { return false; } |
||||||
|
} |
||||||
|
|
||||||
|
public int Line { |
||||||
|
get { return location.Line; } |
||||||
|
} |
||||||
|
|
||||||
|
public int Column { |
||||||
|
get { return location.Column; } |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public ITextBuffer CreateSnapshot() |
||||||
|
{ |
||||||
|
return this; // ReadOnlyDocument is immutable
|
||||||
|
} |
||||||
|
|
||||||
|
public ITextBuffer CreateSnapshot(int offset, int length) |
||||||
|
{ |
||||||
|
return textBuffer.CreateSnapshot(offset, length); |
||||||
|
} |
||||||
|
|
||||||
|
public System.IO.TextReader CreateReader() |
||||||
|
{ |
||||||
|
return textBuffer.CreateReader(); |
||||||
|
} |
||||||
|
|
||||||
|
public System.IO.TextReader CreateReader(int offset, int length) |
||||||
|
{ |
||||||
|
return textBuffer.CreateReader(offset, length); |
||||||
|
} |
||||||
|
|
||||||
|
public char GetCharAt(int offset) |
||||||
|
{ |
||||||
|
return textBuffer.GetCharAt(offset); |
||||||
|
} |
||||||
|
|
||||||
|
public string GetText(int offset, int length) |
||||||
|
{ |
||||||
|
return textBuffer.GetText(offset, length); |
||||||
|
} |
||||||
|
|
||||||
|
public object GetService(Type serviceType) |
||||||
|
{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <author name="Daniel Grunwald"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.NRefactory; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Tests |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ReadOnlyDocumentTests |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void EmptyReadOnlyDocument() |
||||||
|
{ |
||||||
|
IDocument document = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(new StringTextBuffer(string.Empty)); |
||||||
|
Assert.AreEqual(string.Empty, document.Text); |
||||||
|
Assert.AreEqual(0, document.TextLength); |
||||||
|
Assert.AreEqual(1, document.TotalNumberOfLines); |
||||||
|
Assert.AreEqual(0, document.PositionToOffset(1, 1)); |
||||||
|
Assert.AreEqual(new Location(1, 1), document.OffsetToPosition(0)); |
||||||
|
|
||||||
|
Assert.AreEqual(0, document.GetLine(1).Offset); |
||||||
|
Assert.AreEqual(0, document.GetLine(1).EndOffset); |
||||||
|
Assert.AreEqual(0, document.GetLine(1).Length); |
||||||
|
Assert.AreEqual(0, document.GetLine(1).TotalLength); |
||||||
|
Assert.AreEqual(0, document.GetLine(1).DelimiterLength); |
||||||
|
Assert.AreEqual(1, document.GetLine(1).LineNumber); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void SimpleDocument() |
||||||
|
{ |
||||||
|
string text = "Hello\nWorld!\r\n"; |
||||||
|
IDocument document = DocumentUtilitites.LoadReadOnlyDocumentFromBuffer(new StringTextBuffer(text)); |
||||||
|
Assert.AreEqual(text, document.Text); |
||||||
|
Assert.AreEqual(3, document.TotalNumberOfLines); |
||||||
|
|
||||||
|
Assert.AreEqual(0, document.GetLine(1).Offset); |
||||||
|
Assert.AreEqual(5, document.GetLine(1).EndOffset); |
||||||
|
Assert.AreEqual(5, document.GetLine(1).Length); |
||||||
|
Assert.AreEqual(6, document.GetLine(1).TotalLength); |
||||||
|
Assert.AreEqual(1, document.GetLine(1).DelimiterLength); |
||||||
|
Assert.AreEqual(1, document.GetLine(1).LineNumber); |
||||||
|
|
||||||
|
Assert.AreEqual(6, document.GetLine(2).Offset); |
||||||
|
Assert.AreEqual(12, document.GetLine(2).EndOffset); |
||||||
|
Assert.AreEqual(6, document.GetLine(2).Length); |
||||||
|
Assert.AreEqual(8, document.GetLine(2).TotalLength); |
||||||
|
Assert.AreEqual(2, document.GetLine(2).DelimiterLength); |
||||||
|
Assert.AreEqual(2, document.GetLine(2).LineNumber); |
||||||
|
|
||||||
|
Assert.AreEqual(14, document.GetLine(3).Offset); |
||||||
|
Assert.AreEqual(14, document.GetLine(3).EndOffset); |
||||||
|
Assert.AreEqual(0, document.GetLine(3).Length); |
||||||
|
Assert.AreEqual(0, document.GetLine(3).TotalLength); |
||||||
|
Assert.AreEqual(0, document.GetLine(3).DelimiterLength); |
||||||
|
Assert.AreEqual(3, document.GetLine(3).LineNumber); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue