Browse Source

Language bindings can now determine on what characters and keywords code completion should be triggered.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@89 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
22f417e362
  1. 43
      data/templates/file/CSharp/CSharp.Interface.xft
  2. 38
      data/templates/file/VBNet/VBNet.Interface.xft
  3. 17
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin
  4. 5
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj
  5. 20
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs
  6. 3
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  7. 12
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs
  8. 2
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs
  9. 7
      src/Main/Base/Project/Src/TextEditor/Actions.cs
  10. 129
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/CodeCompletionBinding.cs
  11. 178
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs

43
data/templates/file/CSharp/CSharp.Interface.xft

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
<?xml version="1.0"?>
<Template author="Daniel Grunwald" version="1.0">
<Config
name = "${res:Templates.File.Interface.Name}"
icon = "C#.File.NewClass"
category = "C#"
defaultname = "Interface${Number}.cs"
language = "C#"/>
<Description>${res:Templates.File.Interface.Description}</Description>
<!--
Special new file templates:
${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension
${FullName} -> Full generated path name
${FileName} -> File name with extension
${FileNameWithoutExtension} -> File name without extension
${Extension} -> Extension in the form ".cs"
${Path} -> Full path of the file
${ClassName} -> Class name (generally FileNameWithoutExtension w/o 'bad' characters)
-->
<Files>
<File name="${FullName}" language="C#"><![CDATA[${StandardHeader.C#}
using System;
namespace ${StandardNamespace}
{
/// <summary>
/// Description of ${ClassName}.
/// </summary>
public interface I${ClassName}
{
}
}
]]></File>
</Files>
<AdditionalOptions/>
</Template>

38
data/templates/file/VBNet/VBNet.Interface.xft

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
<?xml version="1.0"?>
<Template author="Daniel Grunwald" version="1.0">
<Config
name = "${res:Templates.File.Interface.Name}"
icon = "VBNet.File.NewClass"
category = "VB"
defaultname = "Interface${Number}.vb"
language = "VBNET"
/>
<Description>${res:Templates.File.Interface.Description}</Description>
<!--
Special new file templates:
${StandardNamespace} -> Standardnamespace of the current project or FileNameWithoutExtension
${FullName} -> Full generated path name
${FileName} -> File name with extension
${FileNameWithoutExtension} -> File name without extension
${Extension} -> Extension in the form ".cs"
${Path} -> Full path of the file
-->
<Files>
<File name="${FullName}" language="VBNET"><![CDATA[${StandardHeader.VBNET}
Imports System
Namespace ${StandardNamespace}
Public Interface ${ClassName}
End Class
End Namespace
]]></File>
</Files>
<AdditionalOptions/>
</Template>

17
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin

@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
<AddIn name = "SharpDevelop Bindings"
<AddIn name = "C# Binding"
author = "Mike Krueger"
copyright = "GPL"
url = "http://www.icsharpcode.net"
description = "NCvs core module"
description = "Backing binding for C#"
version = "1.0.0">
<Runtime>
<Import assembly = "CSharpBinding.dll"/>
</Runtime>
<Path name = "/SharpDevelop/Workbench/Ambiences">
<Class id = "C#"
class = "ICSharpCode.Core.CSharpAmbience"/>
@ -20,14 +20,19 @@ @@ -20,14 +20,19 @@
name = "${res:SharpDevelop.FileFilter.CSharpFiles}"
extensions = "*.cs"/>
</Path>
<Path name = "/Workspace/Parser">
<Parser id = "C#"
supportedextensions = ".cs"
projectfileextension = ".csproj"
class = "CSharpBinding.Parser.TParser"/>
</Path>
<Path name = "/AddIns/DefaultTextEditor/CodeCompletion">
<Class id = "CSharpCompletionBinding"
class = "CSharpBinding.CSharpCompletionBinding"/>
</Path>
<Path path = "/SharpDevelop/BackendBindings/ProjectOptions/C#">
<DialogPanel id = "Application"
label = "Application"
@ -51,7 +56,7 @@ @@ -51,7 +56,7 @@
label = "Publish"
class = "CSharpBinding.OptionPanels.Publish"/>
</Path>
<Path name = "/AddIns/DefaultTextEditor/Formatter/C#">
<Class id ="CSharpFormatter" insertbefore="DefaultFormatter" class = "CSharpBinding.FormattingStrategy.CSharpFormattingStrategy"/>
</Path>

5
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -79,6 +79,7 @@ @@ -79,6 +79,7 @@
<None Include="CSharpBinding.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="Src\CSharpCompletionBinding.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj">
@ -101,8 +102,6 @@ @@ -101,8 +102,6 @@
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Src\PrettyPrinter\Gui\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />

20
src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version value="$version"/>
// </file>
using System;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
namespace CSharpBinding
{
public class CSharpCompletionBinding : DefaultCodeCompletionBinding
{
public CSharpCompletionBinding() : base(".cs")
{
this.EnableXmlCommentCompletion = true;
}
}
}

3
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -641,6 +641,7 @@ @@ -641,6 +641,7 @@
<Compile Include="Src\TextEditor\Commands\NavigationCommands.cs" />
<Compile Include="Src\Dom\FilePosition.cs" />
<Compile Include="Src\Project\MSBuildEngine.cs" />
<Compile Include="Src\TextEditor\Gui\Editor\CodeCompletionBinding.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Libraries\DockPanel_Src\WinFormsUI\WinFormsUI.csproj">

12
src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs

@ -295,6 +295,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -295,6 +295,8 @@ namespace ICSharpCode.SharpDevelop.Gui
return StringParser.Parse(SelectedTemplate.DefaultName);
}
bool isNameModified = false;
// list view event handlers
void SelectedIndexChange(object sender, EventArgs e)
{
@ -304,8 +306,9 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -304,8 +306,9 @@ namespace ICSharpCode.SharpDevelop.Gui
if (SelectedTemplate.HasProperties) {
ShowPropertyGrid();
}
if (!this.allowUntitledFiles) {
if (!this.allowUntitledFiles && !isNameModified) {
ControlDictionary["fileNameTextBox"].Text = GenerateCurrentFileName();
isNameModified = false;
}
} else {
ControlDictionary["descriptionLabel"].Text = String.Empty;
@ -314,6 +317,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -314,6 +317,11 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
void FileNameChanged(object sender, EventArgs e)
{
isNameModified = true;
}
// button events
void CheckedChange(object sender, EventArgs e)
@ -489,6 +497,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -489,6 +497,7 @@ namespace ICSharpCode.SharpDevelop.Gui
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.NewFileDialog.xfrm"));
} else {
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.NewFileWithNameDialog.xfrm"));
ControlDictionary["fileNameTextBox"].TextChanged += new EventHandler(FileNameChanged);
}
ImageList imglist = new ImageList();
@ -507,7 +516,6 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -507,7 +516,6 @@ namespace ICSharpCode.SharpDevelop.Gui
ControlDictionary["openButton"].Click += new EventHandler(OpenEvent);
((RadioButton)ControlDictionary["largeIconsRadioButton"]).Checked = PropertyService.Get("Dialogs.NewProjectDialog.LargeImages", true);
((RadioButton)ControlDictionary["largeIconsRadioButton"]).CheckedChanged += new EventHandler(CheckedChange);
((RadioButton)ControlDictionary["largeIconsRadioButton"]).FlatStyle = FlatStyle.Standard;

2
src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs

@ -232,6 +232,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -232,6 +232,8 @@ namespace ICSharpCode.SharpDevelop.Gui
if (current != null && !current.ReadOnly) {
string configPath = Path.Combine(PropertyService.ConfigDirectory, "layouts");
if (!Directory.Exists(configPath))
Directory.CreateDirectory(configPath);
dockPanel.SaveAsXml(Path.Combine(configPath, current.FileName));
}
}

7
src/Main/Base/Project/Src/TextEditor/Actions.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Actions @@ -26,7 +26,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Actions
{
SharpDevelopTextAreaControl sdtac = (SharpDevelopTextAreaControl)services.MotherTextEditorControl;
services.AutoClearSelection = false;
sdtac.codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(((Form)WorkbenchSingleton.Workbench), services.MotherTextEditorControl, services.MotherTextEditorControl.FileName, new TemplateCompletionDataProvider(), '\0');
sdtac.ShowCompletionWindow(new TemplateCompletionDataProvider(), '\0');
}
}
@ -36,10 +36,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Actions @@ -36,10 +36,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Actions
{
SharpDevelopTextAreaControl sdtac = (SharpDevelopTextAreaControl)services.MotherTextEditorControl;
sdtac.codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(((Form)WorkbenchSingleton.Workbench),
services.MotherTextEditorControl,
services.MotherTextEditorControl.FileName,
sdtac.CreateCodeCompletionDataProvider(true), '\0');
sdtac.ShowCompletionWindow(sdtac.CreateCodeCompletionDataProvider(true), '\0');
}
}

129
src/Main/Base/Project/Src/TextEditor/Gui/Editor/CodeCompletionBinding.cs

@ -0,0 +1,129 @@ @@ -0,0 +1,129 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version value="$version"/>
// </file>
using System;
using System.IO;
namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
{
/// <summary>
/// Interface that gives backend bindings the possibility to control what characters and
/// keywords invoke code completion.
/// </summary>
public interface ICodeCompletionBinding
{
bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch);
}
public class DefaultCodeCompletionBinding : ICodeCompletionBinding
{
string extension;
public DefaultCodeCompletionBinding(string extension)
{
this.extension = extension;
}
public bool CheckExtension(SharpDevelopTextAreaControl editor)
{
string ext = Path.GetExtension(editor.FileName);
return string.Compare(ext, extension, true) == 0;
}
bool enableMethodInsight = true;
bool enableIndexerInsight = true;
bool enableXmlCommentCompletion = false;
bool enableDotCompletion = true;
public bool EnableMethodInsight {
get {
return enableMethodInsight;
}
set {
enableMethodInsight = value;
}
}
public bool EnableIndexerInsight {
get {
return enableIndexerInsight;
}
set {
enableIndexerInsight = value;
}
}
public bool EnableXmlCommentCompletion {
get {
return enableXmlCommentCompletion;
}
set {
enableXmlCommentCompletion = value;
}
}
public bool EnableDotCompletion {
get {
return enableDotCompletion;
}
set {
enableDotCompletion = value;
}
}
public virtual bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch)
{
if (!CheckExtension(editor))
return false;
switch (ch) {
case '(':
if (enableMethodInsight) {
editor.ShowInsightWindow(new MethodInsightDataProvider());
return true;
} else {
return false;
}
case '[':
if (enableIndexerInsight) {
editor.ShowInsightWindow(new IndexerInsightDataProvider());
return true;
} else {
return false;
}
case '<':
if (enableXmlCommentCompletion) {
editor.ShowCompletionWindow(new CommentCompletionDataProvider(), ch);
return true;
} else {
return false;
}
case '.':
if (enableDotCompletion) {
editor.ShowCompletionWindow(editor.CreateCodeCompletionDataProvider(false), ch);
return true;
} else {
return false;
}
case ' ':
string word = editor.GetWordBeforeCaret();
if (word != null)
return HandleKeyword(editor, word);
else
return false;
default:
return false;
}
}
public virtual bool HandleKeyword(SharpDevelopTextAreaControl editor, string word)
{
// DefaultCodeCompletionBinding does not support Keyword handling, but this
// method can be overridden
return false;
}
}
}

178
src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs

@ -239,29 +239,23 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -239,29 +239,23 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
// }
//// ALex: end of mod
InsightWindow insightWindow = null;
internal CodeCompletionWindow codeCompletionWindow = null;
static ICodeCompletionBinding[] codeCompletionBindings;
// some other languages could support it
protected virtual bool SupportsNew {
public static ICodeCompletionBinding[] CodeCompletionBindings {
get {
return false;
if (codeCompletionBindings == null) {
try {
codeCompletionBindings = (ICodeCompletionBinding[])(AddInTree.GetTreeNode("/AddIns/DefaultTextEditor/CodeCompletion").BuildChildItems(null)).ToArray(typeof(ICodeCompletionBinding));
} catch (TreePathNotFoundException) {
codeCompletionBindings = new ICodeCompletionBinding[] {};
}
}
return codeCompletionBindings;
}
}
// some other languages could support it
protected virtual bool SupportsDot {
get {
return false;
}
}
// some other languages could support it
protected virtual bool SupportsRoundBracket {
get {
return false;
}
}
InsightWindow insightWindow = null;
CodeCompletionWindow codeCompletionWindow = null;
bool HandleKeyPress(char ch)
{
@ -269,120 +263,58 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -269,120 +263,58 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
if (codeCompletionWindow != null && !codeCompletionWindow.IsDisposed) {
codeCompletionWindow.ProcessKeyEvent(ch);
}
bool isCSharpOrVBNet = Path.GetExtension(fileName) == ".cs" || Path.GetExtension(fileName) == ".vb";
switch (ch) {
case ' ':
//TextEditorProperties.AutoInsertTemplates
string word = GetWordBeforeCaret();
try {
if ((isCSharpOrVBNet||SupportsNew) && word.ToLower() == "new") {
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion) {
codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(((Form)WorkbenchSingleton.Workbench), this, this.FileName, new CodeCompletionDataProvider(true, true), ch);
if (codeCompletionWindow != null) {
codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
}
return false;
}
} else {
if (word != null) {
CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(FileName);
if (templateGroup != null) {
foreach (CodeTemplate template in templateGroup.Templates) {
if (template.Shortcut == word) {
if (word.Length > 0) {
int newCaretOffset = DeleteWordBeforeCaret();
//// set new position in text area
ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(newCaretOffset);
}
InsertTemplate(template);
return true;
}
}
}
}
}
} catch (Exception e) {
LogException(e);
}
goto case '.';
case '<':
try {
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion) {
codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(((Form)WorkbenchSingleton.Workbench), this, fileName, new CommentCompletionDataProvider(), '<');
if (codeCompletionWindow != null) {
codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
}
}
} catch (Exception e) {
LogException(e);
}
return false;
case '(':
try {
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion) {
if (insightWindow == null || insightWindow.IsDisposed) {
insightWindow = new InsightWindow(((Form)WorkbenchSingleton.Workbench), this, fileName);
if (insightWindow != null) {
insightWindow.Closed += new EventHandler(CloseInsightWindow);
}
}
if (insightWindow != null) {
insightWindow.AddInsightDataProvider(new MethodInsightDataProvider());
insightWindow.ShowInsightWindow();
}
}
} catch (Exception e) {
LogException(e);
}
return false;
case '[':
try {
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion) {
if (insightWindow == null || insightWindow.IsDisposed) {
insightWindow = new InsightWindow(((Form)WorkbenchSingleton.Workbench), this, fileName);
if (insightWindow != null) {
insightWindow.Closed += new EventHandler(CloseInsightWindow);
try {
foreach (ICodeCompletionBinding ccBinding in CodeCompletionBindings) {
if (ccBinding.HandleKeyPress(this, ch))
return false;
}
string word = GetWordBeforeCaret();
if (word != null) {
CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(FileName);
if (templateGroup != null) {
foreach (CodeTemplate template in templateGroup.Templates) {
if (template.Shortcut == word) {
if (word.Length > 0) {
int newCaretOffset = DeleteWordBeforeCaret();
//// set new position in text area
ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(newCaretOffset);
}
}
if (insightWindow != null) {
insightWindow.AddInsightDataProvider(new IndexerInsightDataProvider());
insightWindow.ShowInsightWindow();
}
}
} catch (Exception e) {
LogException(e);
}
return false;
case '.':
try {
// TextAreaPainter.IHaveTheFocusLock = true;
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion && (isCSharpOrVBNet||SupportsDot)) {
codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(((Form)WorkbenchSingleton.Workbench), this, fileName, CreateCodeCompletionDataProvider(false), ch);
if (codeCompletionWindow != null) {
codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
InsertTemplate(template);
return true;
}
}
// TextAreaPainter.IHaveTheFocusLock = false;
} catch (Exception e) {
LogException(e);
}
return false;
//// Alex: reparse file on ; - end of statement
// case '}':
// case ';':
// case ')': // reparse on closing bracket for foreach and for definitions
// PulseParser();
// return false;
//// Alex: end of mod
}
} catch (Exception ex) {
LogException(ex);
}
return false;
}
public void ShowInsightWindow(IInsightDataProvider insightDataProvider)
{
if (insightWindow == null || insightWindow.IsDisposed) {
insightWindow = new InsightWindow(((Form)WorkbenchSingleton.Workbench), this, FileName);
if (insightWindow != null) {
insightWindow.Closed += new EventHandler(CloseInsightWindow);
}
}
if (insightWindow != null) {
insightWindow.AddInsightDataProvider(insightDataProvider);
insightWindow.ShowInsightWindow();
}
}
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char ch)
{
codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow((Form)WorkbenchSingleton.Workbench, this, this.FileName, completionDataProvider, ch);
if (codeCompletionWindow != null) {
codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
}
}
private void LogException(Exception ex)
{
ICSharpCode.Core.MessageService.ShowError(ex);

Loading…
Cancel
Save