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
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)
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)
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)
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
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)
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]
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()
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)
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)
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)
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)
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()
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
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)
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
def job(): try: problems = get_problem_list(editor.uri) except Exception, e: idle(editor.message, str(e), 5000) return
def on_delete_event(self, *args): idle(self.hide) return True
def on_key_press(sender, event, editor, widget): if event.keyval == gtk.keysyms.Escape: idle(hide, editor, widget) return True return False
def on_focus_out(sender, event, editor, widget): idle(hide, editor, widget)
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])
def activate_editor(self, path): if path in self.path2uri: idle(self.editor().open_file, self.path2uri[path]) idle(self.hide)
def __init__(self, editor): self.editor = editor idle(connect_all, self, view=editor.view) idle(self.init_completion)
def on_item_activate(item, editor, tool): idle(run, editor(), tool) idle(item.get_parent().destroy)
def job(): try: problems = get_problem_list(editor.uri, editor.snaked_conf['PYLINT_CMD']) except Exception, e: idle(editor.message, str(e), 5000) return
def on_search_entry_changed(self, *args): what = self.search_entry.get_text().strip() if what: idle(self.filter, what) else: idle(self.fill)
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)
def editor_opened(editor): idle(add_update_job, editor) h = Plugin(editor) handlers[editor] = h
def on_search_entry_changed(self, *args): search = self.search_entry.get_text().strip().lower() idle(self.fill_snippets, search)
def escape(self): if hasattr(self.editor(), 'on_dialog_escape'): idle(self.editor().on_dialog_escape, self) self.hide()