def __apply(self,obj): if self.objname != "note": selected_prop = self._resolve_radio(self.group) propname = selected_prop.propname getpropfunc, setpropfunc = self.get_propfuncs(self.objname, propname) if getpropfunc is None: OkDialog("failed","") return if self.objname == "note" and self.use_regex.get_active(): getpropfunc, setpropfunc = self.get_propfuncs(self.objname, "text") with DbTxn(_("Setting properties"), self.dbstate.db) as self.trans: selected_handles = self.uistate.viewmanager.active_page.selected_handles() num_objects = len(selected_handles) for handle in selected_handles: obj = self.getfunc(handle) old_text = self.old_text.get_text() new_text = self.new_text.get_text() if self.objname == "note" and not self.use_regex.get_active(): next_text = obj.get_styledtext().replace(old_text, StyledText(new_text)) obj.set_styledtext(next_text) self.commitfunc(obj,self.trans) continue orig_text = getpropfunc(obj) if self.use_regex.get_active(): try: next_text = re.sub(old_text,new_text,orig_text) except Exception as e: traceback.print_exc() raise RuntimeError(_("Regex operation failed: {}").format(e)) else: next_text = orig_text.replace(old_text,new_text) setpropfunc(obj, next_text) self.commitfunc(obj,self.trans)
def _handle_redo(self, redo_action): """ redo of apply of style """ s_text = StyledText( Gtk.TextBuffer.get_text(self, self.get_start_iter(), self.get_end_iter(), True), redo_action.tags_after) self.set_text(s_text) self.place_cursor(self.get_iter_at_offset(redo_action.offset_after))
def _redo_insert(self, redo_action): s_text = StyledText( Gtk.TextBuffer.get_text(self, self.get_start_iter(), self.get_end_iter(), True), redo_action.tags) self.set_text(s_text) start = self.get_iter_at_offset(redo_action.offset) self.insert(start, redo_action.text) new_cursor_pos = self.get_iter_at_offset(redo_action.offset + redo_action.length) self.place_cursor(new_cursor_pos)
def _undo_insert(self, undo_action): start = self.get_iter_at_offset(undo_action.offset) stop = self.get_iter_at_offset(undo_action.offset + undo_action.length) self.delete(start, stop) #the text is correct again, now we create correct styled text s_text = StyledText( Gtk.TextBuffer.get_text(self, self.get_start_iter(), self.get_end_iter(), True), undo_action.tags) self.set_text(s_text) self.place_cursor(self.get_iter_at_offset(undo_action.offset))
def _undo_delete(self, undo_action): start = self.get_iter_at_offset(undo_action.start) self.insert(start, undo_action.text) #the text is correct again, now we create correct styled text s_text = StyledText( Gtk.TextBuffer.get_text(self, self.get_start_iter(), self.get_end_iter(), True), undo_action.tags) self.set_text(s_text) if undo_action.delete_key_used: self.place_cursor(self.get_iter_at_offset(undo_action.start)) else: self.place_cursor(self.get_iter_at_offset(undo_action.end))