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

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

@ -37,19 +37,6 @@
class = "SearchAndReplace.Replace"/> class = "SearchAndReplace.Replace"/>
</Path> </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"> <Path name = "/SharpDevelop/Workbench/ToolBar/Standard">
<ToolbarItem id = "FindSeparator" type = "Separator" /> <ToolbarItem id = "FindSeparator" type = "Separator" />
<ToolbarItem id = "Find" <ToolbarItem id = "Find"
@ -58,16 +45,6 @@
class = "SearchAndReplace.Find"/> class = "SearchAndReplace.Find"/>
</Path> </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"> <Path name="/SharpDevelop/Pads/SearchResultPad/Factories">
<Class id="DefaultSearchResultFactory" class="SearchAndReplace.DefaultSearchResultFactory"/> <Class id="DefaultSearchResultFactory" class="SearchAndReplace.DefaultSearchResultFactory"/>
</Path> </Path>

Loading…
Cancel
Save