Browse Source

remove unused paths from SearchAndReplace.addin and reimplement IsSearchable with MIME detection

pull/23/head
Siegfried Pammer 15 years ago
parent
commit
7c4f588e5b
  1. 29
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceUtilities.cs
  2. 23
      src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.addin

29
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceUtilities.cs

@ -1,13 +1,15 @@ @@ -1,13 +1,15 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using ICSharpCode.SharpDevelop.Editor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
namespace SearchAndReplace
@ -38,7 +40,7 @@ namespace SearchAndReplace @@ -38,7 +40,7 @@ namespace SearchAndReplace
public static bool IsWholeWordAt(IDocument document, int offset, int length)
{
return (offset - 1 < 0 || !IsWordPart(document.GetCharAt(offset - 1))) &&
(offset + length + 1 >= document.TextLength || !IsWordPart(document.GetCharAt(offset + length)));
(offset + length + 1 >= document.TextLength || !IsWordPart(document.GetCharAt(offset + length)));
}
public static ISearchStrategy CreateSearchStrategy(SearchStrategyType type)
@ -89,25 +91,22 @@ namespace SearchAndReplace @@ -89,25 +91,22 @@ namespace SearchAndReplace
}
}
static List<string> excludedFileExtensions;
public static bool IsSearchable(string fileName)
{
if (fileName == null)
const int BUFFER_LENGTH = 4 * 1024;
if (!File.Exists(fileName))
return false;
if (excludedFileExtensions == null) {
excludedFileExtensions = AddInTree.BuildItems<string>("/AddIns/DefaultTextEditor/Search/ExcludedFileExtensions", null, false);
}
string extension = Path.GetExtension(fileName);
if (extension != null) {
foreach (string excludedExtension in excludedFileExtensions) {
if (String.Compare(excludedExtension, extension, true) == 0) {
return false;
}
using (var stream = File.OpenRead(fileName)) {
string mime = "text/plain";
if (stream.Length > 0) {
stream.Position = 0;
mime = MimeTypeDetection.FindMimeType(new BinaryReader(stream).ReadBytes(BUFFER_LENGTH));
}
return mime.StartsWith("text/", StringComparison.OrdinalIgnoreCase);
}
return true;
}
}
}

23
src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.addin

@ -37,19 +37,6 @@ @@ -37,19 +37,6 @@
class = "SearchAndReplace.Replace"/>
</Path>
<Path name = "/SharpDevelop/DefaultEditor/SearchAndReplace/WildcardHelpPath">
<MenuItem id = "*Char"
label = "* Zero or more of any character" />
<MenuItem id = "?Char"
label = "? Any single character" />
<MenuItem id = "#Char"
label = "# Any single digit" />
<MenuItem id = "[]Char"
label = "[] Any one character in the set" />
<MenuItem id = "[!]Char"
label = "[!] Any one character not in the set" />
</Path>
<Path name = "/SharpDevelop/Workbench/ToolBar/Standard">
<ToolbarItem id = "FindSeparator" type = "Separator" />
<ToolbarItem id = "Find"
@ -58,16 +45,6 @@ @@ -58,16 +45,6 @@
class = "SearchAndReplace.Find"/>
</Path>
<!-- File extensions that should not be searched since they are not opened
in a text editor -->
<Path name="/AddIns/DefaultTextEditor/Search/ExcludedFileExtensions">
<String text=".resx"/>
<String text=".resources"/>
<String text=".exe"/>
<String text=".dll"/>
<String text=".pdb"/>
</Path>
<Path name="/SharpDevelop/Pads/SearchResultPad/Factories">
<Class id="DefaultSearchResultFactory" class="SearchAndReplace.DefaultSearchResultFactory"/>
</Path>

Loading…
Cancel
Save