def __init__(self, parent, plugin, doc): self.plugin = plugin dataDir = plugin.get_data_dir() self.doc = doc self.builder = gtk.Builder() self.builder.add_from_file(os.path.join(dataDir, "browsedialog.glade")) dic = { "on_hpaned_files_size_allocate" : self.on_hpaned_files_size_allocate, "on_combobox1_changed" : self.on_combobox1_changed, "on_browse_clicked" : self.on_browse_clicked, "on_window_main_response" : self.on_window_main_response } self["dialog"].set_transient_for(parent) self.builder.connect_signals(dic) self.doc1 = gedit.Document() self.doc2 = gedit.Document() copy(doc, self.doc1) copy(doc, self.doc2) self.doc1.goto_line(0) self.doc2.goto_line(0) self.view1 = gedit.View(self.doc1) self.view2 = gedit.View(self.doc2) self["h_scrolledwindow1"].add(self.view1) self["h_scrolledwindow2"].add(self.view2) self.doc1.readonly = True self.doc2.readonly = True self["dialog"].set_default_response(gtk.RESPONSE_OK) self["dialog"].add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) self["dialog"].add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.load_encs() self["combobox1"].set_active(0) self["combobox1"].grab_focus() cell = gtk.CellRendererText() self["combobox1"].pack_start(cell, True) self["combobox1"].add_attribute(cell, 'text', 1)
def load_other_file(self, source): current_tab = self.window.get_active_tab() self.same_document[current_tab] = False self.split_views[current_tab].remove(self.split_views[current_tab].get_children()[1]) new_document = gedit.Document()#.gedit_document_new() new_document.load("file://" + source.replace(" ", "%20"), self.encoding, 1, True) new_view = gedit.View(new_document)#.gedit_view_new(new_document) new_document.connect("mark-set", self.update_line_column_data) #new_document.save(0) self.alt_views[current_tab] = new_document sw = gtk.ScrolledWindow() sw.add(new_view) self.split_views[current_tab].add2(sw) self.label_other_document.set_label(os.path.basename(source).replace("%20", " ")) self.window.get_active_tab().show_all()
def do_get_info_widget(self, proposal): if not self.info_widget: view = gedit.View(gedit.Document()) manager = get_language_manager() lang = manager.get_language('snippets') view.get_buffer().set_language(lang) sw = gtk.ScrolledWindow() sw.add(view) self.info_view = view self.info_widget = sw return self.info_widget
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 = [] file_list = [] if find_options['INCLUDE_SUBFOLDER'] == True: grep_cmd = ['grep', '-E', '-l', '-R', search_pattern, dir_path] else: grep_cmd = ['grep', '-E', '-l', search_pattern, dir_path] p = subprocess.Popen(grep_cmd, stdout=subprocess.PIPE) for f in p.stdout: if self.check_file_pattern(f, unicode(file_pattern, 'utf-8')): file_list.append(f[:-1]) ''' 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: 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.' for file_path in file_list: if os.path.isfile(file_path): temp_doc = gedit.Document() #file_uri = "file://" + urllib.pathname2url(file_path.encode('utf-8')) #file_uri = ('file://' + file_path).encode('utf-8') file_uri = gnomevfs.get_uri_from_local_path(file_path) try: temp_doc.load(file_uri, gedit.encoding_get_from_charset('utf-8'), 0, False) except: print 'Can not open ' + file_uri + '.' continue 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()