Browse Source
Improved dot code completion (sort completion entries, group overloaded methods). git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3907 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
27 changed files with 968 additions and 139 deletions
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.Tests.Utils |
||||
{ |
||||
[TestFixture] |
||||
public class IndentationStringTests |
||||
{ |
||||
[Test] |
||||
public void IndentWithSingleTab() |
||||
{ |
||||
var options = new TextEditorOptions { IndentationSize = 4, ConvertTabsToSpaces = false }; |
||||
Assert.AreEqual("\t", options.IndentationString); |
||||
Assert.AreEqual("\t", options.GetIndentationString(1)); |
||||
Assert.AreEqual("\t", options.GetIndentationString(2)); |
||||
Assert.AreEqual("\t", options.GetIndentationString(3)); |
||||
Assert.AreEqual("\t", options.GetIndentationString(4)); |
||||
Assert.AreEqual("\t", options.GetIndentationString(5)); |
||||
} |
||||
|
||||
[Test] |
||||
public void IndentWith4Spaces() |
||||
{ |
||||
var options = new TextEditorOptions { IndentationSize = 4, ConvertTabsToSpaces = true }; |
||||
Assert.AreEqual(" ", options.IndentationString); |
||||
Assert.AreEqual(" ", options.GetIndentationString(1)); |
||||
Assert.AreEqual(" ", options.GetIndentationString(2)); |
||||
Assert.AreEqual(" ", options.GetIndentationString(3)); |
||||
Assert.AreEqual(" ", options.GetIndentationString(4)); |
||||
Assert.AreEqual(" ", options.GetIndentationString(5)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.AvalonEdit.Utils; |
||||
using System; |
||||
using System.ComponentModel; |
||||
using ICSharpCode.AvalonEdit.Document; |
||||
|
||||
namespace ICSharpCode.AvalonEdit |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a text editor control (<see cref="TextEditor"/>, <see cref="TextArea"/>
|
||||
/// or <see cref="Gui.TextView"/>).
|
||||
/// </summary>
|
||||
public interface ITextEditorComponent |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the document being edited.
|
||||
/// </summary>
|
||||
TextDocument Document { get; } |
||||
|
||||
/// <summary>
|
||||
/// Occurs when the Document property changes (when the text editor is connected to another
|
||||
/// document - not when the document content changes).
|
||||
/// </summary>
|
||||
event EventHandler DocumentChanged; |
||||
|
||||
/// <summary>
|
||||
/// Gets the options of the text editor.
|
||||
/// </summary>
|
||||
TextEditorOptions Options { get; } |
||||
|
||||
/// <summary>
|
||||
/// Occurs when the Options property changes, or when an option inside the current option list
|
||||
/// changes.
|
||||
/// </summary>
|
||||
event PropertyChangedEventHandler OptionChanged; |
||||
} |
||||
} |
@ -0,0 +1,163 @@
@@ -0,0 +1,163 @@
|
||||
// <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.ComponentModel; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.AvalonEdit |
||||
{ |
||||
/// <summary>
|
||||
/// A container for the text editor options.
|
||||
/// </summary>
|
||||
[Serializable] |
||||
public class TextEditorOptions : INotifyPropertyChanged |
||||
{ |
||||
#region PropertyChanged handling
|
||||
/// <inheritdoc/>
|
||||
public event PropertyChangedEventHandler PropertyChanged; |
||||
|
||||
/// <summary>
|
||||
/// Raises the PropertyChanged event.
|
||||
/// </summary>
|
||||
/// <param name="propertyName">The name of the changed property.</param>
|
||||
protected void OnPropertyChanged(string propertyName) |
||||
{ |
||||
OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Raises the PropertyChanged event.
|
||||
/// </summary>
|
||||
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) |
||||
{ |
||||
if (PropertyChanged != null) { |
||||
PropertyChanged(this, e); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region ShowSpaces / ShowTabs / ShowBoxForControlCharacters
|
||||
bool showSpaces; |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets whether to show · for spaces.
|
||||
/// </summary>
|
||||
/// <remarks>The default value is <c>false</c>.</remarks>
|
||||
[DefaultValue(false)] |
||||
public virtual bool ShowSpaces { |
||||
get { return showSpaces; } |
||||
set { |
||||
if (showSpaces != value) { |
||||
showSpaces = value; |
||||
OnPropertyChanged("ShowSpaces"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool showTabs; |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets whether to show » for tabs.
|
||||
/// </summary>
|
||||
/// <remarks>The default value is <c>false</c>.</remarks>
|
||||
[DefaultValue(false)] |
||||
public virtual bool ShowTabs { |
||||
get { return showTabs; } |
||||
set { |
||||
if (showTabs != value) { |
||||
showTabs = value; |
||||
OnPropertyChanged("ShowTabs"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool showBoxForControlCharacters = true; |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets whether to show a box with the hex code for control characters.
|
||||
/// </summary>
|
||||
/// <remarks>The default value is <c>true</c>.</remarks>
|
||||
[DefaultValue(true)] |
||||
public virtual bool ShowBoxForControlCharacters { |
||||
get { return showBoxForControlCharacters; } |
||||
set { |
||||
if (showBoxForControlCharacters != value) { |
||||
showBoxForControlCharacters = value; |
||||
OnPropertyChanged("ShowBoxForControlCharacters"); |
||||
} |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region TabSize / IndentationSize / ConvertTabsToSpaces / GetIndentationString
|
||||
// I'm using '_' prefixes for the fields here to avoid confusion with the local variables
|
||||
// in the methods below.
|
||||
// The fields should be accessed only by their property - the fields might not be used
|
||||
// if someone overrides the property.
|
||||
|
||||
int _indentationSize = 4; |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the width of one indentation unit.
|
||||
/// </summary>
|
||||
/// <remarks>The default value is 4.</remarks>
|
||||
[DefaultValue(4)] |
||||
public virtual int IndentationSize { |
||||
get { return _indentationSize; } |
||||
set { |
||||
if (value < 1) |
||||
throw new ArgumentOutOfRangeException("value", value, "value must be positive"); |
||||
if (_indentationSize != value) { |
||||
_indentationSize = value; |
||||
OnPropertyChanged("IndentationSize"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool _convertTabsToSpaces; |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets whether to use spaces for indentation instead of tabs.
|
||||
/// </summary>
|
||||
/// <remarks>The default value is <c>false</c>.</remarks>
|
||||
[DefaultValue(false)] |
||||
public virtual bool ConvertTabsToSpaces { |
||||
get { return _convertTabsToSpaces; } |
||||
set { |
||||
if (_convertTabsToSpaces != value) { |
||||
_convertTabsToSpaces = value; |
||||
OnPropertyChanged("ConvertTabsToSpaces"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the text used for indentation.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] |
||||
public string IndentationString { |
||||
get { return GetIndentationString(0); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets text required to indent from the specified <paramref name="column"/> to the next indentation level.
|
||||
/// </summary>
|
||||
public virtual string GetIndentationString(int column) |
||||
{ |
||||
if (column < 0) |
||||
throw new ArgumentOutOfRangeException("column", column, "Value must be non-negative."); |
||||
int indentationSize = this.IndentationSize; |
||||
if (ConvertTabsToSpaces) { |
||||
return new string(' ', indentationSize - (column % indentationSize)); |
||||
} else { |
||||
return "\t"; |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// <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.ComponentModel; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// WeakEventManager for INotifyPropertyChanged.PropertyChanged.
|
||||
/// </summary>
|
||||
public sealed class PropertyChangedWeakEventManager : WeakEventManagerBase<PropertyChangedWeakEventManager, INotifyPropertyChanged> |
||||
{ |
||||
/// <inheritdoc/>
|
||||
protected override void StartListening(INotifyPropertyChanged source) |
||||
{ |
||||
source.PropertyChanged += DeliverEvent; |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void StopListening(INotifyPropertyChanged source) |
||||
{ |
||||
source.PropertyChanged -= DeliverEvent; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue