Permalink
Browse files

Updated advancedfind to v3.2.0

  • Loading branch information...
nengxu committed Oct 20, 2011
1 parent 8995e8f commit 23483137bf9213d6b05f994e254744b2e1b0673e
View
@@ -153,6 +153,7 @@
<object class="GtkVButtonBox" id="vbuttonbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="homogeneous">True</property>
<child>
<object class="GtkRadioButton" id="forwardRadiobutton">
<property name="label" translatable="yes">Forward</property>
@@ -238,6 +239,7 @@
<object class="GtkVButtonBox" id="vbuttonbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="homogeneous">True</property>
<child>
<object class="GtkRadioButton" id="currentFileRadiobutton">
<property name="label" translatable="yes">Current Document</property>
View
0 plugins3/advancedfind/__init__.py 100644 → 100755
No changes.
View
@@ -30,6 +30,7 @@
import subprocess
import urllib
import re
+import time
from advancedfind_ui import AdvancedFindUI
@@ -40,11 +41,17 @@
import gettext
APP_NAME = 'advancedfind'
-LOCALE_DIR = '/usr/share/locale'
-#LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locale')
-#if not os.path.exists(LOCALE_DIR):
-# LOCALE_DIR = '/usr/share/locale'
-gettext.install(APP_NAME, LOCALE_DIR, unicode=True)
+#LOCALE_DIR = '/usr/share/locale'
+LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locale')
+if not os.path.exists(LOCALE_DIR):
+ LOCALE_DIR = '/usr/share/locale'
+try:
+ t = gettext.translation(APP_NAME, LOCALE_DIR)
+ _ = t.gettext
+ #Gtk.glade.bindtextdomain(APP_NAME, LOCALE_DIR)
+except:
+ pass
+#gettext.install(APP_NAME, LOCALE_DIR, unicode=True)
# Menu item example, insert a new item in the Edit menu
@@ -226,17 +233,17 @@ def show_message_dialog(self, dlg, text):
dlg.run()
dlg.hide()
- def advanced_find_configure(self, window, tab, data = None):
+ def advanced_find_configure(self, action, data = None):
config_ui = ConfigUI(self._plugin)
- def advanced_find_active(self, window, tab, data = None):
+ def advanced_find_active(self, action, data = None):
doc = self._window.get_active_document()
if not doc:
return
try:
start, end = doc.get_selection_bounds()
- search_text = unicode(doc.get_text(start,end,True))
+ search_text = unicode(doc.get_text(start,end,True), 'utf-8')
except:
search_text = self.current_search_pattern
@@ -368,17 +375,17 @@ def auto_select_word(self, pattern=r'[_a-zA-Z][_a-zA-Z0-9]*'):
return match.group(0)
return ''
- def find_next(self, window, tab, data = None):
+ def find_next(self, action, data = None):
self.advanced_find_in_doc(self._window.get_active_document(), self.current_search_pattern, self.find_options, True, False, False)
- def find_previous(self, window, tab, data = None):
+ def find_previous(self, action, data = None):
self.advanced_find_in_doc(self._window.get_active_document(), self.current_search_pattern, self.find_options, False, False, False)
- def select_find_next(self, window, tab, data = None):
+ def select_find_next(self, action, data = None):
#print self.auto_select_word()
self.advanced_find_in_doc(self._window.get_active_document(), self.auto_select_word(), self.find_options, True, False, False)
- def select_find_previous(self, window, tab, data = None):
+ def select_find_previous(self, action, data = None):
#print self.auto_select_word()
self.advanced_find_in_doc(self._window.get_active_document(), self.auto_select_word(), self.find_options, False, False, False)
@@ -424,6 +431,8 @@ def advanced_find_all_in_doc(self, parent_it, doc, search_pattern, find_options,
line_text = text[line_start_pos:line_end_pos]
self._results_view.append_find_result(tree_it, str(line_num+1), line_text, match.start(), match.end()-match.start(), "", line_start_pos)
start_pos = match.end() + 1
+ if start_pos > end_pos:
+ break
match = regex.search(text, start_pos, end_pos)
else:
results = []
@@ -444,6 +453,8 @@ def advanced_find_all_in_doc(self, parent_it, doc, search_pattern, find_options,
results.append([replace_start_pos, replace_text_len])
replace_offset += replace_text_len - (match.end() - match.start())
start_pos = match.end() + 1
+ if start_pos > end_pos:
+ break
match = regex.search(text, start_pos, end_pos)
doc.end_user_action()
@@ -470,47 +481,48 @@ def check_file_pattern(self,path, pattern_text):
return False
def find_all_in_dir(self, parent_it, dir_path, file_pattern, search_pattern, find_options, replace_flg = False):
+ start_time = time.time()
if search_pattern == "":
return
d_list = []
- f_list = []
file_list = []
for root, dirs, files in os.walk(unicode(dir_path, 'utf-8')):
for d in dirs:
d_list.append(os.path.join(root, d))
for f in files:
- f_list.append(os.path.join(root, f))
+ if self.check_file_pattern(f, unicode(file_pattern, 'utf-8')):
+ if find_options['INCLUDE_SUBFOLDER'] == True:
+ file_list.append(os.path.join(root, f))
+ else:
+ if os.path.dirname(f) not in d_list:
+ file_list.append(os.path.join(root, f))
+ self.find_ui.do_events()
+
+ mid_time = time.time()
+ print 'Use ' + str(mid_time-start_time) + ' seconds to find files.'
- if find_options['INCLUDE_SUBFOLDER'] == True:
- file_list = f_list
- else:
- for f in f_list:
- if os.path.dirname(f) not in d_list:
- file_list.append(f)
for file_path in file_list:
- if self.check_file_pattern(file_path, unicode(file_pattern, 'utf-8')):
- if os.path.isfile(file_path):
- pipe = subprocess.PIPE
- p1 = subprocess.Popen(["file", "-i", file_path], stdout=pipe)
- p2 = subprocess.Popen(["grep", "text"], stdin=p1.stdout, stdout=pipe)
- output = p2.communicate()[0]
- if output:
- temp_doc = Gedit.Document()
- file_uri = "file://" + urllib.pathname2url(file_path.encode('utf-8'))
- temp_doc.load(Gio.file_new_for_uri(file_uri), Gedit.encoding_get_from_charset('utf-8'), 0, 0, False)
- f_temp = open(file_path, 'r')
- try:
- text = unicode(f_temp.read(), 'utf-8')
- except:
- text = f_temp.read()
- f_temp.close()
- temp_doc.set_text(text)
-
- self.advanced_find_all_in_doc(parent_it, temp_doc, search_pattern, find_options, replace_flg)
- self.find_ui.do_events()
+ if os.path.isfile(file_path):
+ temp_doc = Gedit.Document()
+ file_uri = "file://" + urllib.pathname2url(file_path.encode('utf-8'))
+ temp_doc.load(Gio.file_new_for_uri(file_uri), Gedit.encoding_get_from_charset('utf-8'), 0, 0, False)
+ f_temp = open(file_path, 'r')
+ try:
+ text = unicode(f_temp.read(), 'utf-8')
+ except:
+ text = f_temp.read()
+ f_temp.close()
+ temp_doc.set_text(text)
+
+ self.advanced_find_all_in_doc(parent_it, temp_doc, search_pattern, find_options, replace_flg)
+ self.find_ui.do_events()
+
+ end_time = time.time()
+ print 'Use ' + str(end_time-mid_time) + ' seconds to find results.'
+ print 'Total use ' + str(end_time-start_time) + ' seconds.'
def result_highlight_on(self, file_it):
if file_it == None:
View
@@ -223,7 +223,7 @@ def filterEntryIconPress(self, object, icon_pos, event):
def pathEntryIconPress(self, object, icon_pos, event):
self.pathComboboxtext.get_model().clear()
self._instance.file_path_history = []
-
+
def on_findDialog_focus_in_event_action(self, object, event):
object.set_opacity(1)
@@ -245,10 +245,10 @@ def do_events(self):
Gtk.main_iteration()
def add_combobox_list(self):
- find_text = self.findTextComboboxtext.get_active_text()
- replace_text = self.replaceTextComboboxtext.get_active_text()
- file_pattern = self.filterComboboxtext.get_active_text()
- path = self.pathComboboxtext.get_active_text()
+ find_text = unicode(self.findTextComboboxtext.get_active_text(), 'utf-8')
+ replace_text = unicode(self.replaceTextComboboxtext.get_active_text(), 'utf-8')
+ file_pattern = unicode(self.filterComboboxtext.get_active_text(), 'utf-8')
+ path = unicode(self.pathComboboxtext.get_active_text(), 'utf-8')
self._instance.current_search_pattern = find_text
self._instance.current_replace_text = replace_text
#self._instance.current_file_pattern = file_pattern
@@ -316,6 +316,9 @@ def on_findAllButton_clicked_action(self, object):
search_pattern = self.findTextComboboxtext.get_active_text()
if search_pattern == "":
return
+ doc = self._instance._window.get_active_document()
+ if not doc:
+ return
self._instance.set_bottom_panel_label(_('Finding...'), os.path.join(os.path.dirname(__file__), 'loading.gif'))
self._instance._results_view.set_sensitive(False)
@@ -328,15 +331,10 @@ def on_findAllButton_clicked_action(self, object):
it = self._instance._results_view.append_find_pattern(search_pattern)
if self._instance.scopeFlg == 0: #current document
- doc = self._instance._window.get_active_document()
- if not doc:
- return
self._instance.advanced_find_all_in_doc(it, doc, search_pattern, self._instance.find_options)
self._instance._results_view.show_find_result()
elif self._instance.scopeFlg == 1: #all opened documents
docs = self._instance._window.get_documents()
- if not docs:
- return
for doc in docs:
self._instance.advanced_find_all_in_doc(it, doc, search_pattern, self._instance.find_options)
self.do_events()
@@ -347,9 +345,6 @@ def on_findAllButton_clicked_action(self, object):
self._instance.find_all_in_dir(it, dir_path, file_pattern, search_pattern, self._instance.find_options)
self._instance._results_view.show_find_result()
elif self._instance.scopeFlg == 3: #current selected text
- doc = self._instance._window.get_active_document()
- if not doc:
- return
self._instance.advanced_find_all_in_doc(it, doc, search_pattern, self._instance.find_options, False, True)
self._instance._results_view.show_find_result()
@@ -360,6 +355,9 @@ def on_replaceAllButton_clicked_action(self, object):
search_pattern = self.findTextComboboxtext.get_active_text()
if search_pattern == "":
return
+ doc = self._instance._window.get_active_document()
+ if not doc:
+ return
self._instance.set_bottom_panel_label(_('Replacing...'), os.path.join(os.path.dirname(__file__), 'loading.gif'))
self._instance._results_view.set_sensitive(False)
@@ -372,15 +370,10 @@ def on_replaceAllButton_clicked_action(self, object):
it = self._instance._results_view.append_find_pattern(search_pattern, True, self.replaceTextComboboxtext.get_child().get_text())
if self._instance.scopeFlg == 0: #current document
- doc = self._instance._window.get_active_document()
- if not doc:
- return
self._instance.advanced_find_all_in_doc(it, doc, search_pattern, self._instance.find_options, True)
self._instance._results_view.show_find_result()
elif self._instance.scopeFlg == 1: #all opened documents
docs = self._instance._window.get_documents()
- if not docs:
- return
for doc in docs:
self._instance.advanced_find_all_in_doc(it, doc, search_pattern, self._instance.find_options, True)
self._instance._results_view.show_find_result()
@@ -390,9 +383,6 @@ def on_replaceAllButton_clicked_action(self, object):
self._instance._results_view.show_find_result()
self._instance._results_view.findResultTreemodel.set_value(it, 2, _("Replace in this scope is not supported."))
elif self._instance.scopeFlg == 3: #current selected text
- doc = self._instance._window.get_active_document()
- if not doc:
- return
self._instance.advanced_find_all_in_doc(it, doc, search_pattern, self._instance.find_options, True, True)
self._instance._results_view.show_find_result()
View
No changes.
View
No changes.
View
@@ -47,8 +47,8 @@ def __init__(self, plugin):
self.fgColorbutton = UI.get_object("fgColorbutton")
self.bgColorbutton = UI.get_object("bgColorbutton")
- self.fgColorbutton.set_color(Gdk.color_parse(self._instance.result_highlight['FOREGROUND_COLOR'])[1])
- self.bgColorbutton.set_color(Gdk.color_parse(self._instance.result_highlight['BACKGROUND_COLOR'])[1])
+ self.fgColorbutton.set_color(Gdk.color_parse(self._instance.result_highlight['FOREGROUND_COLOR']))
+ self.bgColorbutton.set_color(Gdk.color_parse(self._instance.result_highlight['BACKGROUND_COLOR']))
self.rootFollowFilebrowserCheckbutton = UI.get_object("rootFollowFilebrowserCheckbutton")
self.rootFollowFilebrowserCheckbutton.set_active(self._instance.find_options['ROOT_FOLLOW_FILEBROWSER'])
View
@@ -29,6 +29,21 @@
import config_manager
+import gettext
+APP_NAME = 'advancedfind'
+#LOCALE_DIR = '/usr/share/locale'
+LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locale')
+if not os.path.exists(LOCALE_DIR):
+ LOCALE_DIR = '/usr/share/locale'
+try:
+ t = gettext.translation(APP_NAME, LOCALE_DIR)
+ _ = t.gettext
+ #Gtk.glade.bindtextdomain(APP_NAME, LOCALE_DIR)
+except:
+ pass
+#gettext.install(APP_NAME, LOCALE_DIR, unicode=True)
+
+
class FindResultView(Gtk.HBox):
def __init__(self, window, show_button_option):
Gtk.HBox.__init__(self)
@@ -166,7 +181,12 @@ def do_events(self):
Gtk.main_iteration()
def to_xml_text(self, text):
- return text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
+ # & -> &amp;
+ # < -> &lt;
+ # > -> &gt;
+ # ' -> &apos;
+ # " -> &quot;
+ return text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace("'", '&apos;').replace('"', '&quot;')
def remove_markup(self, text):
regex = re.compile(r'<.+>([^ <>]+)</.+>')
@@ -179,6 +199,7 @@ def on_findResultTreeview_cursor_changed_action(self, object):
try:
m = re.search('.+(<.+>)+([0-9]+)(<.+>)+.*', model.get_value(it, 1))
+ #m = re.search('.+(.+)+([0-9]+)(.+)+.*', model.get_value(it, 1))
line_num = int(m.group(2))
except:
return
@@ -343,20 +364,24 @@ def append_find_pattern(self, pattern, replace_flg = False, replace_text = None)
idx = self.findResultTreemodel.iter_n_children(None)
header = '#' + str(idx) + ' - '
if replace_flg == True:
- mode = self.result_format['MODE_REPLACE'] %{'HEADER' : header, 'PATTERN' : self.to_xml_text(pattern), 'REPLACE_TEXT' : self.to_xml_text(replace_text)}
+ mode = self.result_format['MODE_REPLACE'] %{'HEADER' : header, 'PATTERN' : self.to_xml_text(unicode(pattern, 'utf-8')), 'REPLACE_TEXT' : self.to_xml_text(unicode(replace_text, 'utf-8'))}
+ #mode = header + ' Replace ' + pattern + ' with ' + replace_text
it = self.findResultTreemodel.append(None, [idx, mode, '', None, 0, 0, ''])
else:
- mode = self.result_format['MODE_FIND'] %{'HEADER' : header, 'PATTERN' : self.to_xml_text(pattern)}
+ mode = self.result_format['MODE_FIND'] %{'HEADER' : header, 'PATTERN' : self.to_xml_text(unicode(pattern, 'utf-8'))}
+ #mode = header + ' Search ' + pattern
it = self.findResultTreemodel.append(None, [idx, mode, '', None, 0, 0, ''])
return it
def append_find_result_filename(self, parent_it, filename, tab, uri):
- filename_str = self.result_format['FILENAME'] % {'FILENAME' : self.to_xml_text(filename)}
+ filename_str = self.result_format['FILENAME'] % {'FILENAME' : self.to_xml_text(unicode(filename, 'utf-8'))}
+ #filename_str = filename
it = self.findResultTreemodel.append(parent_it, [0, filename_str, '', tab, 0, 0, uri])
return it
def append_find_result(self, parent_it, line, text, result_offset_start = 0, result_len = 0, uri = "", line_start_pos = 0, replace_flg = False):
result_line = self.result_format['LINE'] % {'LINE_NUM' : line}
+ #result_line = 'Line ' + str(line) + ' : '
markup_start = result_offset_start - line_start_pos
markup_end = markup_start + result_len
@@ -366,9 +391,11 @@ def append_find_result(self, parent_it, line, text, result_offset_start = 0, res
if replace_flg == False:
result_text = (text_header + self.result_format['FIND_RESULT_TEXT'] % {'RESULT_TEXT' : text_marked} + text_footer).rstrip()
+ #result_text = (text_header + text_marked + text_footer).rstrip()
self.findResultTreemodel.append(parent_it, [int(line), result_line, result_text, None, result_offset_start, result_len, uri])
else:
result_text = (text_header + self.result_format['REPLACE_RESULT_TEXT'] % {'RESULT_TEXT' : text_marked} + text_footer).rstrip()
+ #result_text = (text_header + text_marked + text_footer).rstrip()
self.findResultTreemodel.append(parent_it, [int(line), result_line, result_text, None, result_offset_start, result_len, uri])
def show_find_result(self):
@@ -384,8 +411,10 @@ def show_find_result(self):
hits_cnt = self.findResultTreemodel.iter_n_children(it1)
total_hits += hits_cnt
hits_str = self.result_format['HITS_CNT'] % {'HITS_CNT' : str(hits_cnt)}
+ #hits_str = str(hits_cnt) + ' hits'
self.findResultTreemodel.set_value(it1, 2, hits_str)
total_hits_str = self.result_format['TOTAL_HITS'] % {'TOTAL_HITS': str(total_hits), 'FILES_CNT' : str(file_cnt)}
+ #total_hits_str = 'Total ' + str(total_hits) + ' hits in ' + str(file_cnt)
self.findResultTreemodel.set_value(pattern_it, 2, total_hits_str)
def clear_highlight(self):
View
0 plugins3/advancedfind/loading.gif 100644 → 100755
No changes.
View
No changes.

0 comments on commit 2348313

Please sign in to comment.