Browse Source

XML Editor now selects the first completion list item by default.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2130 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
942330a947
  1. 5
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs
  2. 1
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCompletionDataProvider.cs
  3. 92
      src/AddIns/DisplayBindings/XmlEditor/Test/Completion/FirstCompletionListItemSelectedTestFixture.cs
  4. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

5
src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs

@ -82,6 +82,11 @@ namespace ICSharpCode.XmlEditor @@ -82,6 +82,11 @@ namespace ICSharpCode.XmlEditor
declarationViewWindow.ShowDeclarationViewWindow();
control.Focus();
CodeCompletionListViewSelectedItemChanged(this, EventArgs.Empty);
if (completionDataProvider.DefaultIndex >= 0) {
codeCompletionListView.SelectIndex(completionDataProvider.DefaultIndex);
}
if (completionDataProvider.PreSelection != null) {
CaretOffsetChanged(this, EventArgs.Empty);
}

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

@ -28,6 +28,7 @@ namespace ICSharpCode.XmlEditor @@ -28,6 +28,7 @@ namespace ICSharpCode.XmlEditor
this.schemaCompletionDataItems = schemaCompletionDataItems;
this.defaultSchemaCompletionData = defaultSchemaCompletionData;
this.defaultNamespacePrefix = defaultNamespacePrefix;
DefaultIndex = 0;
}
public override ImageList ImageList {

92
src/AddIns/DisplayBindings/XmlEditor/Test/Completion/FirstCompletionListItemSelectedTestFixture.cs

@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
using XmlEditor.Tests.Utils;
namespace XmlEditor.Tests.Completion
{
/// <summary>
/// Tests that the first item in the completion list view is selected by
/// default. When coding in C# the default is to not selected the
/// first item in the completion list. With XML there tends to not
/// be very many items in the completion list so selecting the first
/// one can often make editing quicker.
/// </summary>
[TestFixture]
public class FirstCompletionListItemSelectedTestFixture
{
XmlCompletionDataProvider provider;
ICompletionData selectedCompletionData;
ICompletionData[] completionDataItems;
[TestFixtureSetUp]
public void SetUpFixture()
{
Form parentForm = new Form();
parentForm.CreateControl();
XmlSchemaCompletionData schema = new XmlSchemaCompletionData(ResourceManager.GetXhtmlStrictSchema());
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
schemas.Add(schema);
provider = new XmlCompletionDataProvider(schemas, schema, String.Empty);
TextEditorControl textEditor = new TextEditorControl();
completionDataItems = provider.GenerateCompletionData(@"C:\Test.xml", textEditor.ActiveTextAreaControl.TextArea, '<');
using (ICSharpCode.XmlEditor.CodeCompletionWindow completionWindow = ICSharpCode.XmlEditor.CodeCompletionWindow.ShowCompletionWindow(parentForm, textEditor, @"C:\Test.xml", provider, '<')) {
CodeCompletionListView listView = (CodeCompletionListView)completionWindow.Controls[0];
selectedCompletionData = listView.SelectedCompletionData;
completionWindow.Close();
}
}
/// <summary>
/// Sanity check to make sure that we actually have some completion
/// data items from the xml completion data provider.
/// </summary>
[Test]
public void HasGeneratedCompletionDataItems()
{
Assert.IsNotNull(completionDataItems);
Assert.IsTrue(completionDataItems.Length > 0);
}
/// <summary>
/// Default index should be zero so that the first item in the
/// list view is selected.
/// </summary>
[Test]
public void DefaultIndex()
{
Assert.AreEqual(0, provider.DefaultIndex);
}
[Test]
public void SelectedCompletionDataExists()
{
Assert.IsNotNull(selectedCompletionData);
}
/// <summary>
/// First item returned from completion list view should correspond
/// to the first completion item returned from the xml completion
/// data provider after those items have been sorted.
/// </summary>
[Test]
public void SelectedCompletionDataMatches()
{
List<ICompletionData> items = new List<ICompletionData>(completionDataItems);
items.Sort();
Assert.AreEqual(items[0].Text, selectedCompletionData.Text);
}
}
}

2
src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

@ -44,6 +44,7 @@ @@ -44,6 +44,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Completion\FirstCompletionListItemSelectedTestFixture.cs" />
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" />
<Compile Include="Schema\ElementWithAttributeSchemaTestFixture.cs" />
<Compile Include="Schema\NestedElementSchemaTestFixture.cs" />
@ -164,6 +165,7 @@ @@ -164,6 +165,7 @@
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Completion" />
<Folder Include="Schema\" />
<Folder Include="Parser\" />
<Folder Include="Paths\" />

Loading…
Cancel
Save