Browse Source

Fixed SD2-595: Replace in files must use same Encoding detection as text editor

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@878 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
2e2e17e634
  1. 15
      src/AddIns/Misc/NAntAddIn/Test/ProcessRunnerNotStartedTestFixture.cs
  2. 7
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs
  3. 6
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/TextBufferStrategy/StringTextBufferStrategy.cs
  4. 1
      src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs
  5. 11
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/ProvidedDocumentInformation.cs
  6. 1
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs
  7. 43
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs
  8. BIN
      src/Main/StartUp/Project/Resources/StringResources.resources

15
src/AddIns/Misc/NAntAddIn/Test/ProcessRunnerNotStartedTestFixture.cs

@ -36,20 +36,25 @@ namespace ICSharpCode.NAntAddIn.Tests @@ -36,20 +36,25 @@ namespace ICSharpCode.NAntAddIn.Tests
[Test]
public void StandardOutput()
{
Assert.AreEqual(String.Empty, runner.StandardOutput, "Standard output should be empty.");
Assert.AreEqual(String.Empty, runner.StandardOutput, "Standard output should be empty.");
}
[Test]
public void StandardError()
{
Assert.AreEqual(String.Empty, runner.StandardError, "Standard error should be empty.");
}
Assert.AreEqual(String.Empty, runner.StandardError, "Standard error should be empty.");
}
[Test]
[ExpectedException(typeof(ProcessRunnerException), "No process running.")]
public void WaitForExit()
{
runner.WaitForExit();
try {
runner.WaitForExit();
Assert.Fail("Expected ProcessRunnerException");
} catch (ProcessRunnerException ex) {
Assert.AreEqual(ICSharpCode.Core.StringParser.Parse("${res:ICSharpCode.NAntAddIn.ProcessRunner.NoProcessRunningErrorText}"),
ex.Message);
}
}
}
}

7
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
using System;
using System.IO;
using System.Text;
namespace ICSharpCode.TextEditor.Document
{
@ -41,9 +41,8 @@ namespace ICSharpCode.TextEditor.Document @@ -41,9 +41,8 @@ namespace ICSharpCode.TextEditor.Document
public IDocument CreateFromFile(string fileName)
{
IDocument document = CreateDocument();
StreamReader stream = File.OpenText(fileName);
document.TextContent = stream.ReadToEnd();
stream.Close();
Encoding encoding = Encoding.Default;
document.TextContent = Util.FileReader.ReadFileContent(fileName, ref encoding, encoding);
return document;
}
}

6
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/TextBufferStrategy/StringTextBufferStrategy.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.IO;
using System.Diagnostics;
using System.Text;
using ICSharpCode.TextEditor.Undo;
namespace ICSharpCode.TextEditor.Document
@ -75,9 +76,8 @@ namespace ICSharpCode.TextEditor.Document @@ -75,9 +76,8 @@ namespace ICSharpCode.TextEditor.Document
StringTextBufferStrategy(string fileName)
{
StreamReader streamReader = File.OpenText(fileName);
SetContent(streamReader.ReadToEnd());
streamReader.Close();
Encoding encoding = Encoding.Default;
SetContent(Util.FileReader.ReadFileContent(fileName, ref encoding, encoding));
}
public static ITextBufferStrategy CreateTextBufferFromFile(string fileName)

1
src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs

@ -229,6 +229,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -229,6 +229,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (pendingAppendCalls >= 5) {
return;
}
pendingAppendCalls -= 1;
}
if (messageCategories[SelectedCategoryIndex] != category) {
SelectCategory(category.Category, fullText);

11
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/ProvidedDocumentInformation.cs

@ -83,17 +83,6 @@ namespace SearchAndReplace @@ -83,17 +83,6 @@ namespace SearchAndReplace
}
}
public void SaveBuffer()
{
if (document != null) {
} else {
StreamWriter streamWriter = File.CreateText(this.fileName);
streamWriter.Write(textBuffer.GetText(0, textBuffer.Length));
streamWriter.Close();
}
}
public IDocument CreateDocument()
{
if (document != null) {

1
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs

@ -79,7 +79,6 @@ namespace SearchAndReplace @@ -79,7 +79,6 @@ namespace SearchAndReplace
{
if (CurrentDocumentInformation != null && TextIterator != null) {
CurrentDocumentInformation.Replace(offset, length, pattern);
CurrentDocumentInformation.SaveBuffer();
TextIterator.InformReplace(offset, length, pattern.Length);
}
}

43
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs

@ -74,12 +74,15 @@ namespace SearchAndReplace @@ -74,12 +74,15 @@ namespace SearchAndReplace
find.Reset();
if (!find.SearchStrategy.CompilePattern())
return;
while (true) {
for (int count = 0;; count++) {
SearchResult result = SearchReplaceManager.find.FindNext();
if (result == null) {
MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.MarkAllDone}", "${res:Global.FinishedCaptionText}");
if (count == 0) {
ShowNotFoundMessage();
} else {
MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.MarkAllDone}", "${res:Global.FinishedCaptionText}");
}
find.Reset();
return;
} else {
@ -109,15 +112,19 @@ namespace SearchAndReplace @@ -109,15 +112,19 @@ namespace SearchAndReplace
return;
List<TextEditorControl> textAreas = new List<TextEditorControl>();
while (true) {
for (int count = 0;; count++) {
SearchResult result = SearchReplaceManager.find.FindNext();
if (result == null) {
foreach (TextEditorControl textArea in textAreas) {
textArea.EndUpdate();
textArea.Refresh();
if (count == 0) {
ShowNotFoundMessage();
} else {
foreach (TextEditorControl textArea in textAreas) {
textArea.EndUpdate();
textArea.Refresh();
}
MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.ReplaceAllDone}", "${res:Global.FinishedCaptionText}");
}
MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.ReplaceAllDone}", "${res:Global.FinishedCaptionText}");
find.Reset();
return;
} else {
@ -130,9 +137,8 @@ namespace SearchAndReplace @@ -130,9 +137,8 @@ namespace SearchAndReplace
}
string transformedPattern = result.TransformReplacePattern(SearchOptions.ReplacePattern);
find.Replace(result.Offset,
result.Length,
transformedPattern);
find.Replace(result.Offset, result.Length, transformedPattern);
textArea.Document.Replace(result.Offset, result.Length, transformedPattern);
}
}
}
@ -155,11 +161,7 @@ namespace SearchAndReplace @@ -155,11 +161,7 @@ namespace SearchAndReplace
SearchResult result = find.FindNext();
if (result == null) {
MessageBox.Show((Form)WorkbenchSingleton.Workbench,
ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound"),
"Not Found",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
ShowNotFoundMessage();
find.Reset();
} else {
TextEditorControl textArea = OpenTextArea(result.FileName);
@ -181,6 +183,15 @@ namespace SearchAndReplace @@ -181,6 +183,15 @@ namespace SearchAndReplace
lastResult = result;
}
static void ShowNotFoundMessage()
{
MessageBox.Show((Form)WorkbenchSingleton.Workbench,
ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound"),
ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound.Title"),
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
static TextEditorControl OpenTextArea(string fileName)
{
if (fileName != null) {

BIN
src/Main/StartUp/Project/Resources/StringResources.resources

Binary file not shown.
Loading…
Cancel
Save