def __init__(self, window, panel, all_docs, node): self._window = window self._panel = panel self._node = node self._error = False self._signal_ids = {} self._counter = 0 if all_docs: docs = window.get_documents() else: docs = [window.get_active_document()] docs_to_save = [doc for doc in docs if doc.get_modified()] signals = {} for doc in docs_to_save: signals[doc] = doc.connect('saving', self.on_document_saving) if len(docs_to_save) == len(docs) and len(docs) != 0: Gedit.commands_save_all_documents(window) else: for doc in docs_to_save: Gedit.commands_save_document(window, doc) for doc in docs_to_save: doc.disconnect(signals[doc]) self.run_tool()
def __init__(self, window, panel, all_docs, node): self._window = window self._panel = panel self._node = node self._error = False self._signal_ids = {} self._counter = 0 if all_docs: docs = window.get_documents() else: docs = [window.get_active_document()] docs_to_save = [doc for doc in docs if doc.get_modified()] signals = {} for doc in docs_to_save: signals[doc] = doc.connect('saving', self.on_document_saving) if len(docs_to_save) == len(docs) and len(docs) != 0: Gedit.commands_save_all_documents(window) else: for doc in docs_to_save: Gedit.commands_save_document(window, doc) for doc in docs_to_save: doc.disconnect(signals[doc]) self.run_tool()
def save_file(self): """ Trigger the 'Save' action (used by ToolAction before tool run) """ tab = self._active_tab_decorator.tab Gedit.commands_save_document(tab.get_toplevel(), tab.get_document())
def save_file(self): """ Trigger the 'Save' action (used by ToolAction before tool run) """ tab = self._active_tab_decorator.tab Gedit.commands_save_document(tab.get_toplevel(), tab.get_document())
def on_focus_out_event(self, widget, focus): for doc in self.window.get_unsaved_documents(): if doc.is_untouched(): # nothing to do continue if doc.is_untitled(): # provide a default filename now = datetime.datetime.now() filename = now.strftime("/tmp/gedit.unsaved.%Y%m%d-%H%M%S.txt") doc.set_location(Gio.file_parse_name(filename)) # save the document Gedit.commands_save_document(self.window, doc)
def on_focus_out_event(self, widget, focus): for n, doc in enumerate(self.window.get_unsaved_documents()): if doc.is_untouched(): # nothing to do continue if doc.is_untitled(): # provide a default filename now = datetime.datetime.now() assure_path_exists(dirname) filename = now.strftime(dirname + "%Y%m%d-%H%M%S-%%d.txt") % (n + 1) doc.set_location(Gio.file_parse_name(filename)) # save the document Gedit.commands_save_document(self.window, doc)
def on_focus_out_event(self, widget, focus): for n, doc in enumerate(self.window.get_unsaved_documents()): if doc.is_untouched(): # nothing to do continue if doc.is_untitled(): # provide a default filename now = datetime.datetime.now() assure_path_exists(dirname) filename = now.strftime(dirname + "%Y%m%d-%H%M%S-%%d.txt") % (n + 1) doc.set_location(Gio.file_parse_name(filename)) # save the document Gedit.commands_save_document(self.window, doc)
def saveAndBuild(self): self.outputPanel.activate() self.outputPanel.setText("") unsavedDocuments = self.window.get_unsaved_documents() total = len(unsavedDocuments) if(total==0): self.build() else: self.counter = 0 self.handlers = {} for doc in unsavedDocuments: if doc.is_untouched() or doc.is_untitled(): continue self.handlers[doc.get_uri_for_display()] = doc.connect("saved", self.onSaved, total) Gedit.commands_save_document(self.window, doc)
def __init__(self, window, panel, docs, node): self._window = window self._panel = panel self._node = node self._error = False self._counter = len(docs) self._signal_ids = {} self._counter = 0 signals = {} for doc in docs: signals[doc] = doc.connect('saving', self.on_document_saving) Gedit.commands_save_document(window, doc) doc.disconnect(signals[doc])
def __init__(self, window, panel, docs, node): self._window = window self._panel = panel self._node = node self._error = False self._counter = len(docs) self._signal_ids = {} self._counter = 0 signals = {} for doc in docs: signals[doc] = doc.connect('saving', self.on_document_saving) Gedit.commands_save_document(window, doc) doc.disconnect(signals[doc])
def save(self): if not self.doc.is_untouched(): Gedit.commands_save_document(self.window, self.doc) self.timeouts['save'] = None return False
def save(self): if self.doc.get_modified(): Gedit.commands_save_document(self.window, self.doc) self.timeout = None return False
def save(view): window = view.get_toplevel() Gedit.commands_save_document(window, view.get_buffer()) return commander.commands.result.HIDE
def save(view): window = view.get_toplevel() Gedit.commands_save_document(window, view.get_buffer()) return commander.commands.result.HIDE
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 on_unfocused(self, *args): for d in self.window.get_unsaved_documents(): f = d.get_file() if d.get_modified( ) and not f.is_readonly() and not d.is_untitled(): Gedit.commands_save_document(self.window, d)