Esempio n. 1
0
 def find_in_selected_node(self):
     """Search for a pattern in the selected Node"""
     entry_hint = ""
     if not self.from_find_iterated:
         self.latest_node_offset = {}
         iter_insert = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_insert())
         iter_bound = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_selection_bound())
         entry_predefined_text = self.dad.curr_buffer.get_text(iter_insert, iter_bound)
         if entry_predefined_text:
             self.dad.search_replace_dict['find'] = entry_predefined_text
         if self.replace_active: title = _("Replace in Current Node...")
         else: title = _("Search in Current Node...")
         pattern = self.dad.dialog_search(title, self.replace_active)
         if entry_predefined_text != "":
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_insert(), iter_insert)
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_selection_bound(), iter_bound)
         if pattern != None: self.curr_find = ["in_selected_node", pattern]
         else: return
     else: pattern = self.curr_find[1]
     forward = self.dad.search_replace_dict['fw']
     if self.from_find_back:
         forward = not forward
         self.from_find_back = False
     first_fromsel = self.dad.search_replace_dict['a_ff_fa'] == 1
     all_matches = self.dad.search_replace_dict['a_ff_fa'] == 0
     self.matches_num = 0
     # searching start
     if self.dad.user_active:
         self.dad.user_active = False
         user_active_restore = True
     else: user_active_restore = False
     if all_matches:
         self.liststore.clear()
         self.all_matches_first_in_node = True
         while self.parse_node_content_iter(self.dad.curr_tree_iter, self.dad.curr_buffer, pattern, forward, first_fromsel, all_matches, True):
             self.matches_num += 1
     elif self.parse_node_content_iter(self.dad.curr_tree_iter, self.dad.curr_buffer, pattern, forward, first_fromsel, all_matches, True):
         self.matches_num = 1
     if self.matches_num == 0:
         support.dialog_info(_("The pattern '%s' was not found") % pattern, self.dad.window)
     elif all_matches:
         self.allmatchesdialog.set_title(str(self.matches_num) + cons.CHAR_SPACE + _("Matches"))
         self.allmatchesdialog.run()
         self.allmatchesdialog.hide()
     elif self.dad.search_replace_dict['idialog']:
         self.iterated_find_dialog()
     if user_active_restore: self.dad.user_active = True
Esempio n. 2
0
 def find_in_selected_node(self):
     """Search for a pattern in the selected Node"""
     entry_hint = ""
     if not self.from_find_iterated:
         self.latest_node_offset = {}
         iter_insert = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_insert())
         iter_bound = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_selection_bound())
         entry_predefined_text = self.dad.curr_buffer.get_text(iter_insert, iter_bound)
         if entry_predefined_text:
             self.dad.search_replace_dict['find'] = entry_predefined_text
         if self.replace_active: title = _("Replace in Current Node...")
         else: title = _("Search in Current Node...")
         pattern = self.dad.dialog_search(title, self.replace_active)
         if entry_predefined_text != "":
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_insert(), iter_insert)
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_selection_bound(), iter_bound)
         if pattern != None: self.curr_find = ["in_selected_node", pattern]
         else: return
     else: pattern = self.curr_find[1]
     forward = self.dad.search_replace_dict['fw']
     if self.from_find_back:
         forward = not forward
         self.from_find_back = False
     first_fromsel = self.dad.search_replace_dict['a_ff_fa'] == 1
     all_matches = self.dad.search_replace_dict['a_ff_fa'] == 0
     self.matches_num = 0
     # searching start
     if self.dad.user_active:
         self.dad.user_active = False
         user_active_restore = True
     else: user_active_restore = False
     if all_matches:
         self.liststore.clear()
         self.all_matches_first_in_node = True
         while self.parse_node_content_iter(self.dad.curr_tree_iter, self.dad.curr_buffer, pattern, forward, first_fromsel, all_matches, True):
             self.matches_num += 1
     elif self.parse_node_content_iter(self.dad.curr_tree_iter, self.dad.curr_buffer, pattern, forward, first_fromsel, all_matches, True):
         self.matches_num = 1
     if self.matches_num == 0:
         support.dialog_info(_("The pattern '%s' was not found") % pattern, self.dad.window)
     elif all_matches:
         self.allmatchesdialog.set_title(str(self.matches_num) + cons.CHAR_SPACE + _("Matches"))
         self.allmatchesdialog.run()
         self.allmatchesdialog.hide()
     elif self.dad.search_replace_dict['idialog']:
         self.iterated_find_dialog()
     if user_active_restore: self.dad.user_active = True
Esempio n. 3
0
 def find_a_node(self):
     """Search for a pattern between all the Node's Names"""
     if not self.from_find_iterated:
         if self.replace_active: title = _("Replace in Node Names...")
         else: title = _("Search For a Node Name...")
         pattern_clean = self.dad.dialog_search(title, self.replace_active)
         if pattern_clean != None: self.curr_find = ["a_node", pattern_clean]
         else: return
     else: pattern_clean = self.curr_find[1]
     if not self.dad.search_replace_dict['reg_exp']: # NOT REGULAR EXPRESSION
         pattern_ready = re.escape(pattern_clean) # backslashes all non alphanum chars => to not spoil re
         if self.dad.search_replace_dict['whole_word']: # WHOLE WORD
             pattern_ready = r'\b' + pattern_ready + r'\b'
         elif self.dad.search_replace_dict['start_word']: # START WORD
             pattern_ready = r'\b' + pattern_ready
     else: pattern_ready = pattern_clean
     if self.dad.search_replace_dict['match_case']: # CASE SENSITIVE
         pattern = re.compile(pattern_ready, re.UNICODE|re.MULTILINE)
     else: pattern = re.compile(pattern_ready, re.IGNORECASE|re.UNICODE|re.MULTILINE)
     forward = self.dad.search_replace_dict['fw']
     if self.from_find_back:
         forward = not forward
         self.from_find_back = False
     first_fromsel = self.dad.search_replace_dict['a_ff_fa'] == 1
     all_matches = self.dad.search_replace_dict['a_ff_fa'] == 0
     if first_fromsel:
         if forward: node_iter = self.dad.treestore.iter_next(self.dad.curr_tree_iter)
         else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, self.dad.curr_tree_iter)
         top_node_iter = self.dad.curr_tree_iter.copy()
         while not node_iter:
             node_iter = top_node_iter.copy()
             if forward: node_iter = self.dad.treestore.iter_next(node_iter)
             else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
             top_node_iter = self.dad.treestore.iter_parent(top_node_iter)
             if not top_node_iter: break
     else:
         if forward: node_iter = self.dad.treestore.get_iter_first()
         else: node_iter = self.dad.get_tree_iter_last_sibling(None)
     self.matches_num = 0
     if all_matches: self.liststore.clear()
     # searching start
     while node_iter != None:
         if self.parse_node_name(node_iter, pattern, forward, all_matches):
             self.matches_num += 1
             if not all_matches: break
         last_top_node_iter = node_iter.copy() # we need this if we start from a node that is not in top level
         if forward: node_iter = self.dad.treestore.iter_next(node_iter)
         else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
         # code that, in case we start from a node that is not top level, climbs towards the top
         while node_iter == None:
             node_iter = self.dad.treestore.iter_parent(last_top_node_iter)
             if node_iter != None:
                 last_top_node_iter = node_iter.copy()
                 # we do not check the father on purpose, only the uncles in the proper direction
                 if forward: node_iter = self.dad.treestore.iter_next(node_iter)
                 else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
             else: break
     self.dad.objects_buffer_refresh()
     if self.matches_num == 0:
         support.dialog_info(_("The pattern '%s' was not found") % pattern_clean, self.dad.window)
     elif all_matches:
         self.allmatchesdialog.set_title(str(self.matches_num) + cons.CHAR_SPACE + _("Matches"))
         self.allmatchesdialog.run()
         self.allmatchesdialog.hide()
     elif self.dad.search_replace_dict['idialog']:
         self.iterated_find_dialog()
     if self.matches_num and self.replace_active: self.dad.update_window_save_needed()
Esempio n. 4
0
 def find_in_all_nodes(self, father_tree_iter):
     """Search for a pattern in all the Tree Nodes"""
     if not self.from_find_iterated:
         iter_insert = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_insert())
         iter_bound = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_selection_bound())
         entry_predefined_text = self.dad.curr_buffer.get_text(iter_insert, iter_bound)
         if entry_predefined_text:
             self.dad.search_replace_dict['find'] = entry_predefined_text
         if self.replace_active:
             if father_tree_iter: title = _("Replace in Selected Node and Subnodes")
             else: title = _("Replace in All Nodes")
         else:
             if father_tree_iter: title = _("Search in Selected Node and Subnodes")
             else: title = _("Search in All Nodes")
         pattern = self.dad.dialog_search(title, self.replace_active)
         if entry_predefined_text != "":
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_insert(), iter_insert)
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_selection_bound(), iter_bound)
         if pattern != None:
             if not father_tree_iter: self.curr_find = ["in_all_nodes", pattern]
             else: self.curr_find = ["in_sel_nod_n_sub", pattern]
         else: return
     else: pattern = self.curr_find[1]
     starting_tree_iter = self.dad.curr_tree_iter.copy()
     current_cursor_pos = self.dad.curr_buffer.get_property(cons.STR_CURSOR_POSITION)
     forward = self.dad.search_replace_dict['fw']
     if self.from_find_back:
         forward = not forward
         self.from_find_back = False
     first_fromsel = self.dad.search_replace_dict['a_ff_fa'] == 1
     all_matches = self.dad.search_replace_dict['a_ff_fa'] == 0
     if first_fromsel or father_tree_iter:
         self.first_useful_node = False # no one node content was parsed yet
         node_iter = self.dad.curr_tree_iter.copy()
     else:
         self.first_useful_node = True # all range will be parsed so no matter
         if forward: node_iter = self.dad.treestore.get_iter_first()
         else: node_iter = self.dad.get_tree_iter_last_sibling(None)
     self.matches_num = 0
     if all_matches: self.liststore.clear()
     config.get_tree_expanded_collapsed_string(self.dad)
     # searching start
     if self.dad.user_active:
         self.dad.user_active = False
         user_active_restore = True
     else: user_active_restore = False
     self.processed_nodes = 0
     self.latest_matches = 0
     self.dad.update_num_nodes()
     if all_matches:
         self.dad.progressbar.set_text("0")
         self.dad.progresstop.show()
         self.dad.progressbar.show()
         while gtk.events_pending(): gtk.main_iteration()
     search_start_time = time.time()
     while node_iter:
         self.all_matches_first_in_node = True
         while self.parse_given_node_content(node_iter, pattern, forward, first_fromsel, all_matches):
             self.matches_num += 1
             if not all_matches or self.dad.progress_stop: break
         if self.matches_num == 1 and not all_matches: break
         if father_tree_iter and not self.from_find_iterated: break
         last_top_node_iter = node_iter.copy() # we need this if we start from a node that is not in top level
         if forward: node_iter = self.dad.treestore.iter_next(node_iter)
         else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
         if not node_iter and father_tree_iter: break
         # code that, in case we start from a node that is not top level, climbs towards the top
         while not node_iter:
             node_iter = self.dad.treestore.iter_parent(last_top_node_iter)
             if node_iter:
                 last_top_node_iter = node_iter.copy()
                 # we do not check the father on purpose, only the uncles in the proper direction
                 if forward: node_iter = self.dad.treestore.iter_next(node_iter)
                 else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
             else: break
         if self.dad.progress_stop: break
         self.processed_nodes += 1
         if all_matches:
             self.update_all_matches_progress()
     search_end_time = time.time()
     print search_end_time - search_start_time, "sec"
     if user_active_restore: self.dad.user_active = True
     config.set_tree_expanded_collapsed_string(self.dad)
     if not self.matches_num or all_matches:
         self.dad.treeview_safe_set_cursor(starting_tree_iter)
         self.dad.objects_buffer_refresh()
         self.dad.sourceview.grab_focus()
         self.dad.curr_buffer.place_cursor(self.dad.curr_buffer.get_iter_at_offset(current_cursor_pos))
         self.dad.sourceview.scroll_to_mark(self.dad.curr_buffer.get_insert(), 0.3)
     if not self.matches_num:
         support.dialog_info(_("The pattern '%s' was not found") % pattern, self.dad.window)
     else:
         if all_matches:
             self.allmatchesdialog.set_title(str(self.matches_num) + cons.CHAR_SPACE + _("Matches"))
             self.allmatchesdialog.run()
             self.allmatchesdialog.hide()
         else:
             self.dad.treeview_safe_set_cursor(self.dad.curr_tree_iter)
             if self.dad.search_replace_dict['idialog']:
                 self.iterated_find_dialog()
     if all_matches:
         assert self.processed_nodes == self.dad.num_nodes or self.dad.progress_stop
         self.dad.progresstop.hide()
         self.dad.progressbar.hide()
         self.dad.progress_stop = False
Esempio n. 5
0
 def find_a_node(self):
     """Search for a pattern between all the Node's Names"""
     if not self.from_find_iterated:
         if self.replace_active: title = _("Replace in Node Names...")
         else: title = _("Search For a Node Name...")
         pattern_clean = self.dad.dialog_search(title, self.replace_active)
         if pattern_clean != None: self.curr_find = ["a_node", pattern_clean]
         else: return
     else: pattern_clean = self.curr_find[1]
     if not self.dad.search_replace_dict['reg_exp']: # NOT REGULAR EXPRESSION
         pattern_ready = re.escape(pattern_clean) # backslashes all non alphanum chars => to not spoil re
         if self.dad.search_replace_dict['whole_word']: # WHOLE WORD
             pattern_ready = r'\b' + pattern_ready + r'\b'
         elif self.dad.search_replace_dict['start_word']: # START WORD
             pattern_ready = r'\b' + pattern_ready
     else: pattern_ready = pattern_clean
     if self.dad.search_replace_dict['match_case']: # CASE SENSITIVE
         pattern = re.compile(pattern_ready, re.UNICODE|re.MULTILINE)
     else: pattern = re.compile(pattern_ready, re.IGNORECASE|re.UNICODE|re.MULTILINE)
     forward = self.dad.search_replace_dict['fw']
     if self.from_find_back:
         forward = not forward
         self.from_find_back = False
     first_fromsel = self.dad.search_replace_dict['a_ff_fa'] == 1
     all_matches = self.dad.search_replace_dict['a_ff_fa'] == 0
     if first_fromsel:
         if forward: node_iter = self.dad.treestore.iter_next(self.dad.curr_tree_iter)
         else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, self.dad.curr_tree_iter)
         top_node_iter = self.dad.curr_tree_iter.copy()
         while not node_iter:
             node_iter = top_node_iter.copy()
             if forward: node_iter = self.dad.treestore.iter_next(node_iter)
             else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
             top_node_iter = self.dad.treestore.iter_parent(top_node_iter)
             if not top_node_iter: break
     else:
         if forward: node_iter = self.dad.treestore.get_iter_first()
         else: node_iter = self.dad.get_tree_iter_last_sibling(None)
     self.matches_num = 0
     if all_matches: self.liststore.clear()
     # searching start
     while node_iter != None:
         if self.parse_node_name(node_iter, pattern, forward, all_matches):
             self.matches_num += 1
             if not all_matches: break
         last_top_node_iter = node_iter.copy() # we need this if we start from a node that is not in top level
         if forward: node_iter = self.dad.treestore.iter_next(node_iter)
         else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
         # code that, in case we start from a node that is not top level, climbs towards the top
         while node_iter == None:
             node_iter = self.dad.treestore.iter_parent(last_top_node_iter)
             if node_iter != None:
                 last_top_node_iter = node_iter.copy()
                 # we do not check the father on purpose, only the uncles in the proper direction
                 if forward: node_iter = self.dad.treestore.iter_next(node_iter)
                 else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
             else: break
     self.dad.objects_buffer_refresh()
     if self.matches_num == 0:
         support.dialog_info(_("The pattern '%s' was not found") % pattern_clean, self.dad.window)
     elif all_matches:
         self.allmatchesdialog.set_title(str(self.matches_num) + cons.CHAR_SPACE + _("Matches"))
         self.allmatchesdialog.run()
         self.allmatchesdialog.hide()
     elif self.dad.search_replace_dict['idialog']:
         self.iterated_find_dialog()
     if self.matches_num and self.replace_active: self.dad.update_window_save_needed()
Esempio n. 6
0
 def find_in_all_nodes(self, father_tree_iter):
     """Search for a pattern in all the Tree Nodes"""
     if not self.from_find_iterated:
         iter_insert = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_insert())
         iter_bound = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_selection_bound())
         entry_predefined_text = self.dad.curr_buffer.get_text(iter_insert, iter_bound)
         if entry_predefined_text:
             self.dad.search_replace_dict['find'] = entry_predefined_text
         if self.replace_active:
             if father_tree_iter: title = _("Replace in Selected Node and Subnodes")
             else: title = _("Replace in All Nodes")
         else:
             if father_tree_iter: title = _("Search in Selected Node and Subnodes")
             else: title = _("Search in All Nodes")
         pattern = self.dad.dialog_search(title, self.replace_active)
         if entry_predefined_text != "":
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_insert(), iter_insert)
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_selection_bound(), iter_bound)
         if pattern != None:
             if not father_tree_iter: self.curr_find = ["in_all_nodes", pattern]
             else: self.curr_find = ["in_sel_nod_n_sub", pattern]
         else: return
     else: pattern = self.curr_find[1]
     starting_tree_iter = self.dad.curr_tree_iter.copy()
     current_cursor_pos = self.dad.curr_buffer.get_property(cons.STR_CURSOR_POSITION)
     forward = self.dad.search_replace_dict['fw']
     if self.from_find_back:
         forward = not forward
         self.from_find_back = False
     first_fromsel = self.dad.search_replace_dict['a_ff_fa'] == 1
     all_matches = self.dad.search_replace_dict['a_ff_fa'] == 0
     if first_fromsel or father_tree_iter:
         self.first_useful_node = False # no one node content was parsed yet
         node_iter = self.dad.curr_tree_iter.copy()
     else:
         self.first_useful_node = True # all range will be parsed so no matter
         if forward: node_iter = self.dad.treestore.get_iter_first()
         else: node_iter = self.dad.get_tree_iter_last_sibling(None)
     self.matches_num = 0
     if all_matches: self.liststore.clear()
     config.get_tree_expanded_collapsed_string(self.dad)
     # searching start
     if self.dad.user_active:
         self.dad.user_active = False
         user_active_restore = True
     else: user_active_restore = False
     while node_iter:
         self.all_matches_first_in_node = True
         while self.parse_given_node_content(node_iter, pattern, forward, first_fromsel, all_matches):
             self.matches_num += 1
             if not all_matches: break
         if self.matches_num == 1 and not all_matches: break
         if father_tree_iter and not self.from_find_iterated: break
         last_top_node_iter = node_iter.copy() # we need this if we start from a node that is not in top level
         if forward: node_iter = self.dad.treestore.iter_next(node_iter)
         else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
         if not node_iter and father_tree_iter: break
         # code that, in case we start from a node that is not top level, climbs towards the top
         while not node_iter:
             node_iter = self.dad.treestore.iter_parent(last_top_node_iter)
             if node_iter:
                 last_top_node_iter = node_iter.copy()
                 # we do not check the father on purpose, only the uncles in the proper direction
                 if forward: node_iter = self.dad.treestore.iter_next(node_iter)
                 else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
             else: break
     if user_active_restore: self.dad.user_active = True
     config.set_tree_expanded_collapsed_string(self.dad)
     if not self.matches_num or all_matches:
         self.dad.treeview_safe_set_cursor(starting_tree_iter)
         self.dad.objects_buffer_refresh()
         self.dad.sourceview.grab_focus()
         self.dad.curr_buffer.place_cursor(self.dad.curr_buffer.get_iter_at_offset(current_cursor_pos))
         self.dad.sourceview.scroll_to_mark(self.dad.curr_buffer.get_insert(), 0.3)
     if not self.matches_num:
         support.dialog_info(_("The pattern '%s' was not found") % pattern, self.dad.window)
     else:
         if all_matches:
             self.allmatchesdialog.set_title(str(self.matches_num) + cons.CHAR_SPACE + _("Matches"))
             self.allmatchesdialog.run()
             self.allmatchesdialog.hide()
         else:
             self.dad.treeview_safe_set_cursor(self.dad.curr_tree_iter)
             if self.dad.search_replace_dict['idialog']:
                 self.iterated_find_dialog()