示例#1
0
 def open_file(self, *args):
     fname, name, root, top = self.get_selected_file()
     if fname:
         if os.path.isdir(fname):
             idle(self.fill_with_dirs, root, os.path.join(top, name), True)
         else:
             self.hide()
             refresh_gui()
             self.pwindow().open_or_activate(fname)
示例#2
0
文件: gui.py 项目: pombredanne/snaked
    def close_editor(self, *args):
        model, pathes = self.editors_view.get_selection().get_selected_rows()
        for p in pathes:
            u, e = model[p][3]
            if e and e():
                e().close()

        refresh_gui()
        if self.editor_list:
            idle(self.fill)
        else:
            self.hide()
示例#3
0
    def open_mime(self):
        fname, name, root, top = self.get_selected_file()
        if fname:
            import gio
            self.hide()
            refresh_gui()

            f = gio.file_parse_name(fname)
            ct = f.query_info(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE).get_content_type()
            ai = gio.app_info_get_default_for_type(ct, False)

            if ai:
                ai.launch([f])
            else:
                self.pwindow().emessage('Unknown content type for launch %s' % ct, 'error')
示例#4
0
def cycle(editor):
    buf, it = editor.buffer, editor.cursor
    word_to_complete, start = get_word_before_cursor(buf, it)

    if not word_to_complete:
        return False

    if getattr(buf, 'complete_words_changed', False):
        editor.complete_words_data = None, None
        buf.complete_words_changed = False

    try:
        start_word, start_offset = editor.complete_words_data
    except AttributeError:
        start_word, start_offset = editor.complete_words_data = None, None

    if not start_word or start_offset != start.get_offset():
        start_word = word_to_complete
        start_offset = start.get_offset()
        editor.complete_words_data = start_word, start_offset

    matches = get_matches(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:
            editor.message("Word completed already")
            return False

        buf.handler_block(buf.complete_words_on_changed_handler_id)

        end = editor.cursor
        buf.delete(start, end)
        buf.insert(start, matches[idx])

        refresh_gui()
        buf.handler_unblock(buf.complete_words_on_changed_handler_id)
    else:
        editor.message("No word to complete")
示例#5
0
    def on_page_removed(self, note, child, idx):
        switch_to = None
        for e in self.editors:
            if e.widget is child:
                spot = self.manager.spot_manager.get_last(None, e)
                if spot:
                    switch_to = note.page_num(spot.editor().widget)

                break

        if switch_to is None and idx > 0:
            switch_to = idx - 1

        if switch_to is not None:
            note.set_current_page(switch_to)
            refresh_gui()

        e = self.get_editor_context()
        if e:
            idle(e.view.grab_focus)
示例#6
0
def search(view):
    if view in active_search_widgets:
        widget = active_search_widgets[view]
    else:
        viewref = weakref.ref(view)
        def on_cancel(_feedback):
            view = viewref()
            if view:
                active_search_widgets.pop(view, None)
                delete_all_marks(view)
                view.grab_focus()

        widget = create_search_widget(view)
        active_search_widgets[view] = widget

        window = view.get_toplevel()
        window.push_escape(
            window.feedback(widget, priority=5, parent=view).on_cancel(on_cancel), 5)

    buf = view.get_buffer()
    if buf.get_has_selection():
        start, end = buf.get_selection_bounds()
        if start.get_line() == end.get_line():
            refresh_gui()

            search = start.get_text(end)
            if is_regex(view):
                search = re.escape(search)

            buf.place_cursor(start)
            update_last_search(view, search)
            widget.entry.set_text(search)
        else:
            set_last_search(view, widget.entry)
            widget.entry.grab_focus()
    else:
        set_last_search(view, widget.entry)
        widget.entry.grab_focus()
示例#7
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 = self.get_tree()

        for m in (name_starts, name_contains):
            for top, node in outline:
                if self.current_search is not current_search:
                    return

                name, line = node.name, node.lineno

                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()
示例#8
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()
示例#9
0
 def tick():
     counter[0] += 1
     if counter[0] % 50 == 0:
         refresh_gui()
         if self.current_search is not current_search:
             raise StopIteration()