Exemple #1
0
    def cycle(self):
        word_to_complete, start = self.get_word_before_cursor()
        
        if not word_to_complete:
            return False

        if not self.start_word or self.start_offset != start.get_offset():
            self.start_word = word_to_complete
            self.start_offset = start.get_offset()

        matches = self.get_matches(self.start_word)
        if matches:
            idx = 0
            try:
                idx = matches.index(word_to_complete)
                idx = (idx + 1) % len(matches)
            except ValueError:
                pass

            if matches[idx] == word_to_complete:
                self.editor.message("Word completed already")
                return False
                
            self.on_buffer_changed_handler.block()             
            
            end = self.editor.cursor
            self.editor.buffer.delete(start, end)
            self.editor.buffer.insert(start, matches[idx])
            
            refresh_gui()
            self.on_buffer_changed_handler.unblock()             
        else:
            self.editor.message("No word to complete")
Exemple #2
0
def search(editor):
    if editor in active_widgets:
        widget = active_widgets[editor]
    else:
        widget = create_widget(editor)
        active_widgets[editor] = widget
        editor.widget.pack_start(widget, False)
        editor.push_escape(hide, widget)
        widget.show_all()

    if editor.buffer.get_has_selection():
        start, end = editor.buffer.get_selection_bounds()
        if start.get_line() == end.get_line():
            refresh_gui()

            search = start.get_text(end)
            if widget.regex.get_active():
                search = re.escape(search)

            editor.buffer.place_cursor(start)
            widget.entry.set_text(search)
        else:
            widget.entry.grab_focus()
    else:
        widget.entry.grab_focus()
Exemple #3
0
    def filter(self, search):
        self.outline.clear()
        
        current_search = object()
        self.current_search = current_search
        
        already_matched = {}
        i = 0
        
        def name_starts(name):
            return name.startswith(search)
            
        def name_contains(name):
            return search in name
        
        outline = list(get_outline(self.editor().text))
        
        for m in (name_starts, name_contains):
            for top, name, line in outline:
                if self.current_search is not current_search:
                    return
                
                if (top, name) in already_matched: continue
                
                if m(name):
                    already_matched[(top, name)] = True            
                    self.outline.append(None, (name, u'/'.join(top), line))
                
                if i % 10 == 0:
                    refresh_gui()
                    
                i += 1

        self.outline_tree.columns_autosize()
Exemple #4
0
    def fill(self):
        self.outline.clear()
        current_search = object()
        self.current_search = current_search
        
        roots = (None, None)
        ptop = ()
        
        i = 0
        for top, name, line in get_outline(self.editor().text):
            if self.current_search is not current_search:
                return

            if len(top) == len(ptop):
                roots = roots[:-1] + (self.outline.append(roots[-2], (name, '', line)),)
            elif len(top) > len(ptop):
                roots = roots + (self.outline.append(roots[-1], (name, '', line)),)
            else:
                delta = len(ptop) - len(top) + 1
                roots = roots[:-delta] + (self.outline.append(roots[-delta-1], (name, '', line)),)

            ptop = top
            
            if i % 10 == 0:
                self.outline_tree.expand_all()
                self.outline_tree.columns_autosize()
                refresh_gui()
                
            i += 1

            self.outline_tree.expand_all()
            self.outline_tree.columns_autosize()
Exemple #5
0
 def open_file(self, *args):
     fname, name, top = self.get_selected_file()
     if fname:
         if os.path.isdir(fname):
             idle(self.fill_with_dirs, os.path.join(top, name), True)
         else:
             self.hide()
             refresh_gui()
             self.editor().open_file(fname)
Exemple #6
0
    def close_editor(self, *args):
        model, pathes = self.editors_view.get_selection().get_selected_rows()
        for p in pathes:
            if p in self.path2uri:
                self.close_editor_by_uri(self.path2uri[p])

        refresh_gui()
        if self.editor_list:
            idle(self.fill)
        else:
            self.hide()
Exemple #7
0
    def fill(self):
        self.outline.clear()
        current_search = object()
        self.current_search = current_search

        roots = {(): None}

        i = 0
        for parent, node in self.get_tree():
            if self.current_search is not current_search:
                return

            roots[parent + (node.name,)] = self.outline.append(roots[parent], (node.name, "", node.lineno))

            if i % 10 == 0:
                self.outline_tree.expand_all()
                self.outline_tree.columns_autosize()
                refresh_gui()

            i += 1

        self.outline_tree.expand_all()
        self.outline_tree.columns_autosize()
Exemple #8
0
 def open_mime(self):
     fname, name, top = self.get_selected_file()
     if fname:
         self.hide()
         refresh_gui()
         open_mime(fname)
Exemple #9
0
 def tick():
     counter[0] += 1
     if counter[0] % 50 == 0:
         refresh_gui()
         if self.current_search is not current_search:
             raise StopIteration()