Browse Source

Port StringResourceToolAddIn to SharpDevelop 4.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4536 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
36da479bad
  1. 29
      src/Tools/StringResourceToolAddIn/Src/Command.cs
  2. 8
      src/Tools/StringResourceToolAddIn/StringResourceToolAddIn.csproj

29
src/Tools/StringResourceToolAddIn/Src/Command.cs

@ -5,17 +5,16 @@
* Time: 16:34 * Time: 16:34
*/ */
using ICSharpCode.SharpDevelop.Editor;
using System; using System;
using System.Collections; using System.Collections;
using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Resources; using System.Resources;
using System.Text; using System.Text;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.TextEditor;
namespace StringResourceToolAddIn namespace StringResourceToolAddIn
{ {
@ -25,18 +24,18 @@ namespace StringResourceToolAddIn
{ {
// Here an example that shows how to access the current text document: // Here an example that shows how to access the current text document:
ITextEditorControlProvider tecp = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorControlProvider; ITextEditorProvider tecp = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorProvider;
if (tecp == null) { if (tecp == null) {
// active content is not a text editor control // active content is not a text editor control
return; return;
} }
// Get the active text area from the control: // Get the active text area from the control:
TextArea textArea = tecp.TextEditorControl.ActiveTextAreaControl.TextArea; ITextEditor textEditor = tecp.TextEditor;
if (!textArea.SelectionManager.HasSomethingSelected) if (textEditor.SelectionLength == 0)
return; return;
// get the selected text: // get the selected text:
string text = textArea.SelectionManager.SelectedText; string text = textEditor.SelectedText;
string sdSrcPath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), string sdSrcPath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location),
"../../../.."); "../../../..");
@ -47,7 +46,7 @@ namespace StringResourceToolAddIn
// Goes through the enumerator, printing out the key and value pairs. // Goes through the enumerator, printing out the key and value pairs.
while (en.MoveNext()) { while (en.MoveNext()) {
if (object.Equals(en.Value, text)) { if (object.Equals(en.Value, text)) {
SetText(textArea, en.Key.ToString(), text); SetText(textEditor, en.Key.ToString(), text);
return; return;
} }
} }
@ -61,7 +60,7 @@ namespace StringResourceToolAddIn
string purpose = MessageService.ShowInputBox("Add Resource", "Enter resource purpose (may be empty)", ""); string purpose = MessageService.ShowInputBox("Add Resource", "Enter resource purpose (may be empty)", "");
if (purpose == null) return; if (purpose == null) return;
SetText(textArea, resourceName, text); SetText(textEditor, resourceName, text);
string path = Path.GetFullPath(Path.Combine(sdSrcPath, "Tools/StringResourceTool/bin/Debug")); string path = Path.GetFullPath(Path.Combine(sdSrcPath, "Tools/StringResourceTool/bin/Debug"));
ProcessStartInfo info = new ProcessStartInfo(path + "\\StringResourceTool.exe", ProcessStartInfo info = new ProcessStartInfo(path + "\\StringResourceTool.exe",
@ -76,19 +75,15 @@ namespace StringResourceToolAddIn
} }
} }
void SetText(TextArea textArea, string resourceName, string oldText) void SetText(ITextEditor textEditor, string resourceName, string oldText)
{ {
// ensure caret is at start of selection // ensure caret is at start of selection / deselect text
textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition; textEditor.Select(textEditor.SelectionStart, 0);
// deselect text
textArea.SelectionManager.ClearSelection();
// replace the selected text with the new text: // replace the selected text with the new text:
// Replace() takes the arguments: start offset to replace, length of the text to remove, new text // Replace() takes the arguments: start offset to replace, length of the text to remove, new text
textArea.Document.Replace(textArea.Caret.Offset, textEditor.Document.Replace(textEditor.Caret.Offset,
oldText.Length, oldText.Length,
"$" + "{res:" + resourceName + "}"); "$" + "{res:" + resourceName + "}");
// Redraw:
textArea.Refresh();
} }
} }
} }

8
src/Tools/StringResourceToolAddIn/StringResourceToolAddIn.csproj

@ -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" ToolsVersion="4.0">
<PropertyGroup> <PropertyGroup>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<RootNamespace>StringResourceToolAddIn</RootNamespace> <RootNamespace>StringResourceToolAddIn</RootNamespace>
@ -15,6 +15,7 @@
<FileAlignment>4096</FileAlignment> <FileAlignment>4096</FileAlignment>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Optimize>False</Optimize> <Optimize>False</Optimize>
@ -48,11 +49,6 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="ICSharpCode.TextEditor">
<HintPath>..\..\..\bin\ICSharpCode.TextEditor.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="StringResourceToolAddIn.addin"> <None Include="StringResourceToolAddIn.addin">

Loading…
Cancel
Save