Skip to content

Commit

Permalink
find: replace: Allow "replace all" in any non-binary (text) file - fixes
Browse files Browse the repository at this point in the history
 #467

rn=
  • Loading branch information
mitchell-as committed May 2, 2018
1 parent e35dd79 commit 455cfa7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
8 changes: 0 additions & 8 deletions src/chrome/komodo/content/find/confirmrepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,6 @@ function onTreeContextMenuShowing()
var ignore_menuitem = document.getElementById("context_menu_ignore");
assoc_menuitem.setAttribute("disabled", "true");
ignore_menuitem.setAttribute("disabled", "true");
var selected_indeces = _get_selected_indeces();
if (selected_indeces.length == 1) {
var idx = selected_indeces[0];
if (_g_replacer.getSkippedReason(idx) == Components.interfaces.koIConfirmReplacerInFiles.SKIPPED_UNKNOWN_LANG) {
assoc_menuitem.removeAttribute("disabled");
ignore_menuitem.removeAttribute("disabled");
}
}
} catch(ex) {
log.exception(ex);
}
Expand Down
19 changes: 6 additions & 13 deletions src/find/findlib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def find(paths, includes=None, excludes=None, env=None):

def grep(regex, paths, files_with_matches=False,
treat_binary_files_as_text=False,
skip_unknown_lang_paths=False,
skip_binary_files=False,
skip_filesizes_larger_than=None,
first_on_line=False,
includes=None, excludes=None,
Expand All @@ -144,8 +144,8 @@ def grep(regex, paths, files_with_matches=False,
Default is false.
@param treat_binary_files_as_text {boolean} indicates that binary files
should be search. By default they are skipped.
@param skip_unknown_lang_paths {boolean} can be set True to skip
grepping in files for which the lang could not be determined.
@param skip_binary_files {boolean} can be set True to skip
grepping in binary files.
This is useful when doing *replacements* to be safe about not
wrecking havoc in binary files that happen to look like plain
text.
Expand Down Expand Up @@ -188,8 +188,8 @@ def grep(regex, paths, files_with_matches=False,
yield SkipPath(path, "error determining file info: %s" % ex)
continue

if skip_unknown_lang_paths and ti.lang is None:
yield SkipUnknownLangPath(path)
if not ti.is_text and skip_binary_files:
yield SkipBinaryPath(path)
continue
if includes:
unmatched_includes = [field for field, value in includes
Expand Down Expand Up @@ -292,7 +292,7 @@ def replace(regex, repl, paths,
"""
journal = None
grepper = grep(regex, paths, skip_unknown_lang_paths=True,
grepper = grep(regex, paths, skip_binary_files=True,
skip_filesizes_larger_than=skip_filesizes_larger_than,
first_on_line=first_on_line,
includes=includes, excludes=excludes,
Expand Down Expand Up @@ -587,13 +587,6 @@ class SkipBinaryPath(SkipPath):
def __init__(self, path):
SkipPath.__init__(self, path, "binary")

class SkipUnknownLangPath(SkipPath):
"""Event yielded when skipping a path because its lang could not be
identified.
"""
def __init__(self, path):
SkipPath.__init__(self, path, "unknown language")

class SkipLargeFilePath(SkipPath):
"""Event yielded when skipping a path because its filesize is too large."""
def __init__(self, path, size):
Expand Down
11 changes: 2 additions & 9 deletions src/find/koFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,7 @@ def _replace_in_paths(self, regex, repl, desc, paths):
continue
elif isinstance(event, findlib2.SkipPath):
self.num_paths_searched += 1
if isinstance(event, findlib2.SkipUnknownLangPath):
self.num_paths_skipped += 1
self._cache_skipped_path(event)
elif isinstance(event, findlib2.SkipBinaryPath):
if isinstance(event, findlib2.SkipBinaryPath):
#TODO: put these as warning rows in the UI?
log.debug("Skip `%s' (binary).", event.path)
elif not isinstance(event, findlib2.Hit):
Expand Down Expand Up @@ -604,9 +601,7 @@ def run(self):
continue
elif isinstance(event, findlib2.SkipPath):
self.num_paths_searched += 1
if isinstance(event, findlib2.SkipUnknownLangPath):
self._add_skipped_path(event)
elif isinstance(event, findlib2.SkipLargeFilePath):
if isinstance(event, findlib2.SkipLargeFilePath):
self._add_skipped_path(event)
elif isinstance(event, findlib2.SkipBinaryPath):
#TODO: put these as warning rows in the UI?
Expand Down Expand Up @@ -634,8 +629,6 @@ def getSkippedReason(self, row_idx):
return components.interfaces.koIConfirmReplacerInFiles.SKIPPED_LARGE_FILE
if isinstance(event, findlib2.SkipBinaryPath):
return components.interfaces.koIConfirmReplacerInFiles.SKIPPED_BINARY_FILE
if isinstance(event, findlib2.SkipUnknownLangPath):
return components.interfaces.koIConfirmReplacerInFiles.SKIPPED_UNKNOWN_LANG
return 0

def toggle_mark(self, row_idx):
Expand Down
1 change: 0 additions & 1 deletion src/find/koIFinder.idl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ interface koIConfirmReplacerInFiles : nsITreeView {

const long SKIPPED_LARGE_FILE = 1;
const long SKIPPED_BINARY_FILE = 2;
const long SKIPPED_UNKNOWN_LANG = 3;

readonly attribute koIConfirmReplaceController controller;

Expand Down

2 comments on commit 455cfa7

@th3coop
Copy link
Member

@th3coop th3coop commented on 455cfa7 May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! So the functionality was already in there? I'm sorry I missed this. I've been all over this code but I guess I wasn't close enough attention.

@mitchell-as
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it looks like it was already in there!

Please sign in to comment.