def on_document_delete_activated(self, sender: Gtk.Widget = None, event=None) -> None: """Permanently remove document from storage. Non-recoverable. :param sender: :param event: :return: """ doc = self.document_grid.selected_document prompt = MessageDialog( f"Permanently delete “{doc.title}”?", "Deleted items are not sent to Archive and not recoverable at all", "dialog-warning", ) if doc: result = prompt.run() prompt.destroy() if result == Gtk.ResponseType.APPLY and storage.update( doc_id=doc._id, data={'archived': True}): self.document_grid.reload_items() self.check_documents_count()
def on_document_rename_activated(self, sender: Gtk.Widget = None, event=None) -> None: """Rename currently selected document. Show rename dialog and update document's title if user puts new one in the entry. :param sender: :param event: :return: """ doc = self.document_grid.selected_document if doc: popover = RenameDialog(doc.title) response = popover.run() try: if response == Gtk.ResponseType.APPLY: new_title = popover.entry.get_text() if storage.update(doc_id=doc._id, data={'title': new_title}): self.document_grid.reload_items() except Exception as e: Logger.debug(e) finally: popover.destroy()
def save_document(self) -> bool: if not self.document: return False text = self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter(), True).strip() # New document has id == -1 # No need to save new empty documents if self.document.document_id == -1 and len(text) == 0: # storage.delete(self.document.document_id) return False if self.document.title in ('', 'Nameless'): try: self.document.title = text.partition('\n')[0].lstrip( ' #') or "Nameless" except TypeError: pass # Save new document to get ID before continue if self.document.document_id == -1: self.document.document_id = storage.add(self.document) if storage.update(self.document.document_id, { "content": text, 'title': self.document.title }): self.document.content = text Logger.debug('Document %s saved', self.document.document_id) return True
def on_document_rename_activated(self, sender: Gtk.Widget, title: str): sender.destroy() doc = self.document_grid.selected_document or self.editor.document if not doc: return if storage.update(doc_id=doc.document_id, data={'title': title}): self.document_grid.reload_items()
def save_document(self) -> bool: if not self.document: return False text = self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter(), True) if storage.update(self.document._id, {"content": text}): self.document.content = text Logger.debug('Document %s saved', self.document._id) return True
def on_document_unarchive_activated(self, sender: Gtk.Widget = None, event=None) -> None: """Unarchive document. :param sender: :param event: :return: """ doc = self.document_grid.selected_document if doc: if storage.update(doc_id=doc.document_id, data={'archived': False}): self.check_documents_count() self.document_grid.reload_items()
def on_document_archive_activated(self, sender: Gtk.Widget = None, event=None) -> None: """Marks document as archived. Recoverable. :param sender: :param event: :return: """ doc = self.document_grid.selected_document if doc: if storage.update(doc_id=doc._id, data={'archived': True}): self.check_documents_count() self.document_grid.reload_items()
def save_document(self) -> bool: if not self.document: return False text = self.buffer.get_text( self.buffer.get_start_iter(), self.buffer.get_end_iter(), True ) if self.document.title in ('', 'Nameless'): try: self.document.title = text.partition('\n')[0].lstrip(' #') except TypeError: pass if storage.update(self.document.document_id, {"content": text, 'title': self.document.title}): self.document.content = text Logger.debug('Document %s saved', self.document.document_id) return True