示例#1
0
文件: plugin.py 项目: bigdrum/snaked
    def on_textview_key_press_event(self, sender, event):
        if event.keyval != gtk.keysyms.Return:
            return False

        cursor = self.editor.cursor
        line_start = cursor.copy()
        line_start.set_line(line_start.get_line())

        text = line_start.get_text(cursor).strip()
        if text and text[-1] == ':':
            end = line_start.copy()
            end.forward_word_end()
            end.backward_word_start()
            ws = line_start.get_text(end)

            if self.editor.view.get_insert_spaces_instead_of_tabs():
                tab = u' ' * self.editor.view.get_tab_width()
            else:
                tab = u'\t'

            self.editor.buffer.begin_user_action()
            self.editor.buffer.insert(cursor, u'\n' + ws + tab)
            self.editor.buffer.end_user_action()

            idle(self.editor.view.scroll_mark_onscreen, self.editor.buffer.get_insert())

            return True

        return False
示例#2
0
文件: gui.py 项目: bigdrum/snaked
 def on_search_entry_changed(self, *args):
     search = self.search_entry.get_text().strip()
     self.current_search = object()
     if search:
         idle(self.fill_filelist, search, self.current_search)
     else:
         idle(self.fill_with_dirs)
示例#3
0
文件: outline.py 项目: hellp/snaked
 def show(self, editor):
     self.editor = weakref.ref(editor)
     self.search_entry.grab_focus()
     
     editor.request_transient_for.emit(self.window)
     self.window.present()
     
     idle(self.fill)
示例#4
0
文件: __init__.py 项目: hellp/snaked
def on_search_changed(sender, editor, widget):
    search = widget.entry.get_text()
    idle(delete_all_marks, editor)

    if search and ( len(search) != 1 or ( not search.isdigit() and not search.isalpha()
            and not search.isspace() ) ):
        idle(add_mark_task, editor, search,
                widget.ignore_case.get_active(), widget.regex.get_active(), False)
示例#5
0
def on_entry_activate(sender, editor, widget):
    idle(hide, editor, widget)
    try:
        line = int(sender.get_text())
        editor.add_spot()
        idle(editor.goto_line, line)
    except ValueError:
        pass
示例#6
0
文件: gui.py 项目: bigdrum/snaked
 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)
示例#7
0
文件: __init__.py 项目: hellp/snaked
def on_buffer_changed(buffer):
    if buffer in stop_managers:
        cursor = get_iter_at_cursor(buffer)
        sm = stop_managers[buffer]
        if sm.cursor_in_snippet_range(cursor):
            if sm.snippet_collapsed():
                del stop_managers[buffer]
            else:
                idle(sm.replace_inserts)
        else:
            del stop_managers[buffer]
示例#8
0
文件: gui.py 项目: bigdrum/snaked
    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()
示例#9
0
文件: prefs.py 项目: bigdrum/snaked
    def edit_context(self, ctx):
        user_snippet_filename = join_to_settings_dir('snippets', ctx + '.snippets')
        if ctx in self.existing_snippets and \
                self.existing_snippets[ctx] != user_snippet_filename:

            import shutil
            make_missing_dirs(user_snippet_filename)
            shutil.copy(self.existing_snippets[ctx], user_snippet_filename)

        idle(self.hide)
        e = self.editor().open_file(user_snippet_filename)
        e.connect('file-saved', on_snippet_saved, ctx)
示例#10
0
def add_job(editor):
    from threading import Thread
    from snaked.util import idle

    def job():
        try:
            problems = get_problem_list(editor.uri)
        except Exception, e:
            idle(editor.message, str(e), 5000)
            return

        idle(mark_problems, editor, "flakes", problems)
示例#11
0
文件: __init__.py 项目: hellp/snaked
def add_job(editor):
    from threading import Thread
    from snaked.util import idle

    def job():
        try:
            problems = get_problem_list(editor.uri, editor.snaked_conf['PYLINT_CMD'])
        except Exception, e:
            idle(editor.message, str(e), 5000)
            return

        idle(mark_problems, editor, 'pylint', problems)
示例#12
0
文件: gui.py 项目: bigdrum/snaked
    def browse_top(self):
        if not self.filelist_tree.is_focus():
            return False

        if self.search_entry.get_text():
            self.editor().message('You are not in browse mode')
            return

        fname, name, top = self.get_selected_file()
        if fname:
            if not top:
                self.editor().message('No way!')
            else:
                place = os.path.basename(os.path.dirname(top)) + '/'
                idle(self.fill_with_dirs, os.path.dirname(os.path.dirname(top)), place)
示例#13
0
文件: gui.py 项目: bigdrum/snaked
    def free_open(self):
        dialog = gtk.FileChooserDialog("Open file...",
            None,
            gtk.FILE_CHOOSER_ACTION_OPEN,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
            gtk.STOCK_OPEN, gtk.RESPONSE_OK))

        dialog.set_default_response(gtk.RESPONSE_OK)

        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            idle(self.editor().open_file, dialog.get_filename())
            idle(self.hide)

        dialog.destroy()
示例#14
0
文件: __init__.py 项目: hellp/snaked
def get_matcher(editor, search, ignore_case, regex, show_feedback=True):
    flags = re.UNICODE
    if ignore_case:
        flags |= re.IGNORECASE

    if regex:
        try:
            return re.compile(unicode(search), flags)
        except Exception, e:
            if show_feedback:
                editor.message('Bad regex: ' + str(e), 3000)
                if editor in active_widgets:
                    idle(active_widgets[editor].entry.grab_focus)

            return None
示例#15
0
文件: gui.py 项目: bigdrum/snaked
    def toggle_hidden(self):
        if self.search_entry.get_text():
            self.editor().message('You are not in browse mode')
            return

        conf = self.editor().snaked_conf
        conf['QUICK_OPEN_SHOW_HIDDEN'] = not conf['QUICK_OPEN_SHOW_HIDDEN']

        self.editor().message('Show hidden files' if conf['QUICK_OPEN_SHOW_HIDDEN'] else
            'Do not show hidden files' )

        fname, name, top = self.get_selected_file()
        if fname:
            idle(self.fill_with_dirs, top, name)
        else:
            if len(self.filelist):
                name, top = self.filelist[0]
                idle(self.fill_with_dirs, top)
示例#16
0
文件: __init__.py 项目: hellp/snaked
def mark_occurences(editor, search, ignore_case, regex, show_feedback=True):
    mark_task_is_in_queue[0] = False
    matcher = get_matcher(editor, search, ignore_case, regex, show_feedback)
    if not matcher:
        return False

    count = 0
    for m in matcher.finditer(editor.utext):
        editor.buffer.apply_tag(get_tag(editor),
            *map(editor.buffer.get_iter_at_offset, m.span()))

        count += 1

    if count == 1:
        if show_feedback:
            idle(editor.message, 'One occurrence is marked')
    elif count > 1:
        if show_feedback:
            idle(editor.message, '%d occurrences are marked' % count)
    else:
        if show_feedback:
            idle(editor.message, 'Text not found')
        return False

    return True
示例#17
0
 def job():
     try:
         problems = get_problem_list(editor.uri)
     except Exception, e:
         idle(editor.message, str(e), 5000)
         return
示例#18
0
 def on_delete_event(self, *args):
     idle(self.hide)
     return True
示例#19
0
def on_key_press(sender, event, editor, widget):
    if event.keyval == gtk.keysyms.Escape:
        idle(hide, editor, widget)
        return True
    
    return False
示例#20
0
def on_focus_out(sender, event, editor, widget):
    idle(hide, editor, widget)
示例#21
0
文件: gui.py 项目: bigdrum/snaked
 def on_editors_view_cursor_changed(self, *args):
     editor = self.editor()
     if editor and editor.snaked_conf['EDITOR_LIST_SWITCH_ON_SELECT'] and not self.block_cursor:
         path, _ = self.editors_view.get_cursor()
         if path in self.path2uri:
             idle(editor.open_file, self.path2uri[path])
示例#22
0
文件: gui.py 项目: bigdrum/snaked
 def activate_editor(self, path):
     if path in self.path2uri:
         idle(self.editor().open_file, self.path2uri[path])
         idle(self.hide)
示例#23
0
文件: plugin.py 项目: bigdrum/snaked
 def __init__(self, editor):
     self.editor = editor
     idle(connect_all, self, view=editor.view)
     idle(self.init_completion)
示例#24
0
文件: __init__.py 项目: hellp/snaked
def on_item_activate(item, editor, tool):
    idle(run, editor(), tool)
    idle(item.get_parent().destroy)
示例#25
0
文件: __init__.py 项目: hellp/snaked
 def job():
     try:
         problems = get_problem_list(editor.uri, editor.snaked_conf['PYLINT_CMD'])
     except Exception, e:
         idle(editor.message, str(e), 5000)
         return
示例#26
0
文件: outline.py 项目: hellp/snaked
 def on_search_entry_changed(self, *args):
     what = self.search_entry.get_text().strip()
     if what:
         idle(self.filter, what)
     else:
         idle(self.fill)
示例#27
0
文件: __init__.py 项目: hellp/snaked
def add_mark_task(editor, search, ignore_case, regex, show_feedback=True):
    if not mark_task_is_in_queue[0]:
        mark_task_is_in_queue[0] = True
        idle(mark_occurences, editor, search, ignore_case, regex,
            show_feedback, priority=glib.PRIORITY_LOW)
示例#28
0
def editor_opened(editor):
    idle(add_update_job, editor)
    h = Plugin(editor)
    handlers[editor] = h
示例#29
0
文件: prefs.py 项目: bigdrum/snaked
 def on_search_entry_changed(self, *args):
     search = self.search_entry.get_text().strip().lower()
     idle(self.fill_snippets, search)
示例#30
0
文件: gui.py 项目: bigdrum/snaked
 def escape(self):
     if hasattr(self.editor(), 'on_dialog_escape'):
         idle(self.editor().on_dialog_escape, self)
     self.hide()