def _on_row_activated(self, tree, path, column): model = tree.get_model() i = model.get_iter(path) if model.iter_has_child(i): if tree.row_expanded(path): tree.collapse_row(path) else: tree.expand_row(path, False) else: info = model.get(i, 2, 3) if info[1] != Gio.FileType.DIRECTORY: Gedit.commands_load_location(self.window, info[0], None, -1, -1)
def on_view_button_press_event(self, view, event): if event.button != 1 or event.type != Gdk.BUTTON_PRESS or \ event.window != view.get_window(Gtk.TextWindowType.TEXT): return False link = self.get_link_at_location(view, int(event.x), int(event.y)) if link is None: return False gfile = self.file_lookup.lookup(link.path) if gfile: Gedit.commands_load_location(self.window, gfile, None, link.line_nr, -1) GObject.idle_add(self.idle_grab_focus)
def on_view_button_press_event(self, view, event): if event.button != 1 or event.type != Gdk.EventType.BUTTON_PRESS or \ event.window != view.get_window(Gtk.TextWindowType.TEXT): return False link = self.get_link_at_location(view, int(event.x), int(event.y)) if link is None: return False gfile = self.file_lookup.lookup(link.path) if gfile: Gedit.commands_load_location(self.window, gfile, None, link.line_nr, link.col_nr) GLib.idle_add(self.idle_grab_focus)
def _edit_command(view, mod, func=None): try: location = Gio.file_new_for_path(inspect.getsourcefile(mod)) except: return False if not func: Gedit.commands_load_location(view.get_toplevel(), location, None, 0, 0) else: try: lines = inspect.getsourcelines(func) line = lines[-1] except: line = 0 Gedit.commands_load_location(view.get_toplevel(), location, None, line, 0) return True
def on_row_activated(self, widget, path, col): selectedIter = self.treeStore.get_iter(path) parentIter = self.treeStore.iter_parent(selectedIter) lineno = 0 if parentIter == None: file = self.treeStore.get_value(selectedIter, 1) else: file = self.treeStore.get_value(parentIter, 1) lineno = self.treeStore.get_value(selectedIter, 2) if not (file): return uri = "file://%s" % quote(file) location = Gio.file_new_for_uri(uri) Gedit.commands_load_location(self._window, location, None, lineno, -1) # use an Idle handler so the document has time to load: GLib.idle_add(self.onDocumentOpenedCb)
def on_activated(self, gfile, user_data=None): Gedit.commands_load_location(self.window, gfile, None, -1, -1) return True
def on_reopen_action_activate(self, action, window, summary): # line and column pos start from 1, for some reason Gedit.commands_load_location( window, summary['location'], summary['encoding'], summary['line_pos'] + 1, summary['column_pos'] + 1)
def _open_file(self, filename): uri = self._rootdir + "/" + pathname2url(filename) openfile = Gio.file_new_for_uri(uri) Gedit.commands_load_location(self._window, openfile, self._encoding, -1, -1)
def open_uri(widget, row, cell): Gedit.commands_load_location(self._window, Gio.file_new_for_uri(widget.model[row][4].get_property("uri")), None, 0, 0)
def open_uri(widget, row, cell): Gedit.commands_load_location( self._window, Gio.file_new_for_uri(widget.model[row][4].get_property("uri")), None, 0, 0)
def open(self, item): Gedit.commands_load_location(self._window, item._file_object, None, -1, -1)
def __open_mark_confirm(self, widget, win, ls, logic): '''Open files by mark: minor dialogue for choosing among search results''' dprint(3, "\n__open_mark_confirm") dprint(3, "\n"+str(ls)) if ls: if logic == "or": notes = self.data.open_from_toc(ls) else: notes = self.data.open_from_toc_intersection(ls) if not notes: last = self.data.get_last_error() if last: msg = Gtk.MessageDialog(win, Gtk.DialogFlags(2), 0, (Gtk.STOCK_OK, Gtk.ResponseType.OK), "Error: " + str(last)) msg.run() msg.destroy() dprint(2, "\nOpen error: " + str(last)) else: failure = ", ".join(ls) if logic == "or": msg = Gtk.MessageDialog(win, Gtk.DialogFlags(2), 0, (Gtk.STOCK_OK, Gtk.ResponseType.OK), "Unable to find files for any of the following marks: " + failure) msg.run() msg.destroy() dprint(2, "\nOpen failure") else: msg = Gtk.MessageDialog(win, Gtk.DialogFlags(2), 0, (Gtk.STOCK_OK, Gtk.ResponseType.OK), "Unable to find files containing each of the following marks: " + failure) msg.run() msg.destroy() dprint(2, "Unable to find files containing each of the following marks: " + failure) dprint(2, "...returning") return Gtk.ResponseType.CANCEL else: for nt in notes: dprint(3, nt.ID) confdialog = Gtk.Dialog("Confirm files to open", None, 0, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.APPLY)) confdialog.add_button("Open All", Gtk.ResponseType.YES) confdialog.set_default_size(*(win.get_size())) chooser_list = Gtk.ListStore(str) for i,nt in enumerate(notes): chooser_list.append(["{:>5}{:<32}".format(str(i+1)+". ", str(os.path.basename(nt.ID)) + " (" + str(os.path.dirname(nt.ID)) + ")")]) chooser_tree = Gtk.TreeView(chooser_list) chooser_tree_select = chooser_tree.get_selection() chooser_tree_select.set_mode(Gtk.SelectionMode.MULTIPLE) chooser_rend = Gtk.CellRendererText() chooser_column = Gtk.TreeViewColumn("Please select from the following:", chooser_rend,text=0) chooser_tree.append_column(chooser_column) chooser_view = Gtk.ScrolledWindow() chooser_view.add(chooser_tree) chooser_view.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) box = confdialog.get_content_area() box.add(chooser_view) box.set_child_packing(chooser_view, expand=True, fill=True, padding=0, pack_type=Gtk.PackType(1)) confdialog.show_all() value = confdialog.run() if (value != Gtk.ResponseType.CANCEL) and (value != Gtk.ResponseType.NONE): # get each note and open a tab gfilelist = None if value == Gtk.ResponseType.YES: gfilelist = [ Gio.file_new_for_path(nt.ID) for nt in notes ] self.__open_notes += notes elif value == Gtk.ResponseType.APPLY: gfilelist = [] for j in chooser_tree_select.get_selected_rows()[1]: tmp_nt = notes[j.get_indices()[0]] self.__open_notes.append(tmp_nt) gfilelist.append(Gio.file_new_for_path(tmp_nt.ID)) if gfilelist: for gf in gfilelist: Gedit.commands_load_location(self.__window, gf, None, -1, -1) confdialog.destroy() return value return Gtk.ResponseType.APPLY
def on_editproject_action_activate(self, action, data=None): Gedit.commands_load_location(self.window, Gio.File.new_for_path(self._project.get_path()), None, -1, -1)
def action_handler(self, text: str, state: DictonatorStates, msg: str): """ Handle what to do with the state/msg that we get. Based on output by the decide_action we choose action.""" if state is not DictonatorStates.fatal_error and state is not DictonatorStates.recognised: # simple msg self.bottom_bar_text_set(msg) if state is DictonatorStates.fatal_error: # fatal error, we will stop listening self.on_stop_activate(None) self.bottom_bar_text_set(msg) if state == DictonatorStates.recognised: if not self.recogniser.is_listening: # if by chance user stops before the results come return self.bottom_bar_text_set("Speak!") if text == "": return curr_action, num, special = DictonatorActions.decide_action(text) self.bottom_bar_add(time.strftime("%H:%M:%S"), text, curr_action) if curr_action == "continue_dictation": self.inserttext(text, True) elif curr_action == "start_dictation": self.on_listen_activate(None) elif curr_action == "stop_dictation": self.on_stop_activate(None) elif curr_action == "hold_dictation": pass elif curr_action == "put": if special != "": for _ in range(num): if 'digit' in special: # using the format how digits are saved self.inserttext(DictonatorActions.digits[special][0]) else: # sure that the special is not a digit, again using the format how specials are saved self.inserttext(DictonatorActions.special_chars[special][0]) self.inserttext(' ') elif curr_action == "scroll_to_cursor": vi = self.view if not vi: return vi.scroll_to_cursor() elif curr_action == "goto_line": self.document.goto_line(num) elif curr_action == "undo": doc = self.document if not doc: return for _ in range(num): if doc.can_undo(): doc.undo() elif curr_action == "redo": doc = self.document if not doc: return for _ in range(num): if doc.can_redo(): doc.redo() elif curr_action == "cut_clipboard": vi = self.view if not vi: return vi.cut_clipboard() elif curr_action == "copy_clipboard": vi = self.view if not vi: return vi.copy_clipboard() elif curr_action == "paste_clipboard": vi = self.view if not vi: return vi.paste_clipboard() elif curr_action == "delete_selection": vi = self.view if not vi: return vi.delete_selection() elif curr_action == "select_all": vi = self.view if not vi: return vi.select_all() elif curr_action == "sentence_end": self.inserttext('. ') elif curr_action == "line_end": self.inserttext('\n') elif curr_action == "delete_line": doc = self.document if not doc: return for _ in range(num): doc.begin_user_action() ei = self.get_cursor_position(doc) si = self.get_cursor_position(doc) si.set_line(ei.get_line()) ei.forward_to_line_end() doc.delete(si, ei) doc.end_user_action() elif curr_action == "delete_sentence": doc = self.document if not doc: return for _ in range(num): doc.begin_user_action() ei = self.get_cursor_position(doc) si = self.get_cursor_position(doc) if not si.starts_sentence(): si.backward_sentence_start() si.backward_char() ei.forward_sentence_end() doc.delete(si, ei) doc.end_user_action() elif curr_action == "delete_word": doc = self.document if not doc: return for _ in range(num): doc.begin_user_action() ei = self.get_cursor_position(doc) si = self.get_cursor_position(doc) si.backward_word_start() si.backward_char() ei.forward_word_end() doc.delete(si, ei) doc.end_user_action() elif curr_action == "clear_document": doc = self.document if not doc: return doc.begin_user_action() doc.set_text('') doc.end_user_action() elif curr_action == "new_document": self.window.create_tab(True) elif curr_action == "save_document": doc = self.document if not doc: return Gedit.commands_save_document(self.window, doc) elif curr_action == "save_as_document": # get complete text from current document doc = self.document txt = doc.get_text(doc.get_start_iter(), doc.get_end_iter(), False) gfile_path = FileSaveAsDialog(self.window).file_dialog_handler(txt) if gfile_path is not None: # the file has been created by above function and we load it Gedit.commands_load_location(self.window, gfile_path, None, 0, 0) elif curr_action == "close_document": doc = self.document if not doc: return tab = self.tab if not tab: return u_docs = self.window.get_unsaved_documents() if self.document not in u_docs: self.window.close_tab(tab) else: # to prevent data loss self.bottom_bar_text_set("You might want to save this document before closing it.") elif curr_action == "force_close_document": tab = self.tab if not tab: return self.window.close_tab(tab) elif curr_action == "exit": u_docs = self.window.get_unsaved_documents() if len(u_docs) == 0: sys.exit() else: self.bottom_bar_text_set("You might want to save all documents before quitting.") else: self.bottom_bar_text_set("WEIRD STATE! How did you reach this state? O_O") return
def action_handler(self, text: str, state: DictonatorStates, msg: str): """ Handle what to do with the state/msg that we get. Based on output by the decide_action we choose action.""" if state is not DictonatorStates.fatal_error and state is not DictonatorStates.recognised: # simple msg self.bottom_bar_text_set(msg) if state is DictonatorStates.fatal_error: # fatal error, we will stop listening self.on_stop_activate(None) self.bottom_bar_text_set(msg) if state == DictonatorStates.recognised: if not self.recogniser.is_listening: # if by chance user stops before the results come return self.bottom_bar_text_set("Speak!") if text == "": return curr_action, num, special = DictonatorActions.decide_action(text) self.bottom_bar_add(time.strftime("%H:%M:%S"), text, curr_action) if curr_action == "continue_dictation": self.inserttext(text, True) elif curr_action == "start_dictation": self.on_listen_activate(None) elif curr_action == "stop_dictation": self.on_stop_activate(None) elif curr_action == "hold_dictation": pass elif curr_action == "put": if special != "": for _ in range(num): if 'digit' in special: # using the format how digits are saved self.inserttext( DictonatorActions.digits[special][0]) else: # sure that the special is not a digit, again using the format how specials are saved self.inserttext( DictonatorActions.special_chars[special][0]) self.inserttext(' ') elif curr_action == "scroll_to_cursor": vi = self.view if not vi: return vi.scroll_to_cursor() elif curr_action == "goto_line": self.document.goto_line(num) elif curr_action == "undo": doc = self.document if not doc: return for _ in range(num): if doc.can_undo(): doc.undo() elif curr_action == "redo": doc = self.document if not doc: return for _ in range(num): if doc.can_redo(): doc.redo() elif curr_action == "cut_clipboard": vi = self.view if not vi: return vi.cut_clipboard() elif curr_action == "copy_clipboard": vi = self.view if not vi: return vi.copy_clipboard() elif curr_action == "paste_clipboard": vi = self.view if not vi: return vi.paste_clipboard() elif curr_action == "delete_selection": vi = self.view if not vi: return vi.delete_selection() elif curr_action == "select_all": vi = self.view if not vi: return vi.select_all() elif curr_action == "sentence_end": self.inserttext('. ') elif curr_action == "line_end": self.inserttext('\n') elif curr_action == "delete_line": doc = self.document if not doc: return for _ in range(num): doc.begin_user_action() ei = self.get_cursor_position(doc) si = self.get_cursor_position(doc) si.set_line(ei.get_line()) ei.forward_to_line_end() doc.delete(si, ei) doc.end_user_action() elif curr_action == "delete_sentence": doc = self.document if not doc: return for _ in range(num): doc.begin_user_action() ei = self.get_cursor_position(doc) si = self.get_cursor_position(doc) if not si.starts_sentence(): si.backward_sentence_start() si.backward_char() ei.forward_sentence_end() doc.delete(si, ei) doc.end_user_action() elif curr_action == "delete_word": doc = self.document if not doc: return for _ in range(num): doc.begin_user_action() ei = self.get_cursor_position(doc) si = self.get_cursor_position(doc) si.backward_word_start() si.backward_char() ei.forward_word_end() doc.delete(si, ei) doc.end_user_action() elif curr_action == "clear_document": doc = self.document if not doc: return doc.begin_user_action() doc.set_text('') doc.end_user_action() elif curr_action == "new_document": self.window.create_tab(True) elif curr_action == "save_document": doc = self.document if not doc: return Gedit.commands_save_document(self.window, doc) elif curr_action == "save_as_document": # get complete text from current document doc = self.document txt = doc.get_text(doc.get_start_iter(), doc.get_end_iter(), False) gfile_path = FileSaveAsDialog( self.window).file_dialog_handler(txt) if gfile_path is not None: # the file has been created by above function and we load it Gedit.commands_load_location(self.window, gfile_path, None, 0, 0) elif curr_action == "close_document": doc = self.document if not doc: return tab = self.tab if not tab: return u_docs = self.window.get_unsaved_documents() if self.document not in u_docs: self.window.close_tab(tab) else: # to prevent data loss self.bottom_bar_text_set( "You might want to save this document before closing it." ) elif curr_action == "force_close_document": tab = self.tab if not tab: return self.window.close_tab(tab) elif curr_action == "exit": u_docs = self.window.get_unsaved_documents() if len(u_docs) == 0: sys.exit() else: self.bottom_bar_text_set( "You might want to save all documents before quitting." ) else: self.bottom_bar_text_set( "WEIRD STATE! How did you reach this state? O_O") return
def open_file(self, filename, line): if os.path.exists(filename): gio_file = Gio.File.new_for_path(filename) Gedit.commands_load_location(self.window, gio_file, None, line, -1)
def _open_file( self, filename ): uri = self._rootdir + "/" + pathname2url(filename) openfile = Gio.file_new_for_uri(uri) Gedit.commands_load_location(self._window, openfile, self._encoding, -1, -1)