def add_entry(self, category, entry, undoing=False): self.add_category(category) category_iter = self._get_category_iter(category) entry_pango = markup.convert_to_pango(entry) category_pango = markup.convert_to_pango(category) # If category exists add entry to existing category, else add new category if category_iter is None: category_iter = self.tree_store.append(None, [category_pango]) # Only add entry if there is one if entry_pango: self.tree_store.append(category_iter, [entry_pango]) if not undoing: def undo_func(): self.delete_node(self.find_iter(category, entry), undoing=True) def redo_func(): self.add_entry(category, entry, undoing=True) action = undo.Action(undo_func, redo_func) self.undo_redo_manager.add_action(action) self.tree_view.expand_all()
def on_text_change(self, textbuffer, undoing=False): # Do not record changes while undoing or redoing if undoing: self.old_text = self.get_text() return new_text = self.get_text() old_text = self.old_text[:] #Determine whether to add a save point much_text_changed = abs(len(new_text) - len(old_text)) >= 5 if much_text_changed or self.force_adding_undo_point: def undo_func(): self.set_text(old_text, undoing=True) def redo_func(): self.set_text(new_text, undoing=True) action = undo.Action(undo_func, redo_func, 'day_text_field') self.undo_redo_manager.add_action(action) self.old_text = new_text self.force_adding_undo_point = False
def add_undo_point(self): if not self.last_undo_point_is_dirty(): return new_text = self.get_text() old_text = self.old_text[:] def undo_func(): self.set_text(old_text, undoing=True) def redo_func(): self.set_text(new_text, undoing=True) self.undo_redo_manager.add_action(undo.Action(undo_func, redo_func)) self.old_text = new_text
def delete_node(self, iter, undoing=False): if not iter: # The user has changed the text of the node or deleted it return # Save for undoing ------------------------------------ # An entry is deleted # We want to delete empty categories too if not self.node_on_top_level(iter): deleting_entry = True category_iter = self.tree_store.iter_parent(iter) category = self.get_iter_value(category_iter) entries = [self.get_iter_value(iter)] # A category is deleted else: deleting_entry = False category_iter = iter category = self.get_iter_value(category_iter) entries = self._get_element_content(category_iter).keys() # Delete --------------------------------------------- self.tree_store.remove(iter) # Delete empty category if deleting_entry and self.empty(category_iter): self.tree_store.remove(category_iter) # ---------------------------------------------------- if not undoing: def undo_func(): for entry in entries: self.add_entry(category, entry, undoing=True) def redo_func(): for entry in entries: delete_iter = self.find_iter(category, entry) self.delete_node(delete_iter, undoing=True) action = undo.Action(undo_func, redo_func, 'categories_tree_view') self.undo_redo_manager.add_action(action) # Update cloud self.main_window.cloud.update()
def add_entry(self, category, entry, undoing=False): if category not in self.categories and category is not None: self.categories.insert(0, category) category_iter = self._get_category_iter(category) entry_pango = markup.convert_to_pango(entry) category_pango = markup.convert_to_pango(category) if category_iter is None: # If category does not exist add new category category_iter = self.tree_store.append(None, [category_pango]) entry_node = self.tree_store.append(category_iter, [entry_pango]) else: # If category exists add entry to existing category entry_node = self.tree_store.append(category_iter, [entry_pango]) if not undoing: undo_func = lambda: self.delete_node(self.find_iter(category, entry), undoing=True) redo_func = lambda: self.add_entry(category, entry, undoing=True) action = undo.Action(undo_func, redo_func, 'categories_tree_view') self.undo_redo_manager.add_action(action) self.tree_view.expand_all()