Example #1
0
    def contextmenu(self, pos):
        if self.db is None:
            return
        if self.currentuid is None:
            return
        menu = QMenu(parent=self)
        si = self.selectedIndexes()

        if len(si) == 0:
            return

        item = self.model.itemFromIndex(si[0])
        data = item.data()
        if type(data) is not tuple:
            return

        target = data[2]
        flags = data[3]
        is_suspect = 'suspect' in flags

        act = menu.addAction(self.icons.ArrowForward,
                             'Go to {}'.format(str(target.uid)))
        act.triggered.connect(lambda: self.goto(target.uid))
        if target.uid in self.db.find(self.currentuid).links:
            act = menu.addAction('Mark link as reviewed')
            act.setEnabled(is_suspect)
            act.triggered.connect(lambda: self.review_link(target.uid))
        else:
            act = menu.addAction("Can't mark child links as reviewed")
            act.setEnabled(False)
        act = menu.addAction(self.icons.DialogCloseButton, 'Remove link')
        act.triggered.connect(self.remove_selected_link)
        menu.popup(self.mapToGlobal(pos))
Example #2
0
 def dblclicked(index):
     item = self.model.itemFromIndex(index)
     data = item.data()
     if data is None or item.isEditable():
         return
     data = data[1]
     self.goto(data.uid)
Example #3
0
    def data(self, index, role=Qt.DisplayRole):
        if role == Qt.DisplayRole:
            item = self.itemFromIndex(index)
            data = item.data()
            if type(data) is str:
                return data
            elif type(data) is tuple:
                is_parent_link = data[0]
                uid = data[1]
                target = data[2]
                flags = data[3]
                title = ''
                if target is not None:
                    title = QTextDocument()
                    title.setHtml(markdown(target.text.split('\n')[0]))
                    title = title.toPlainText()
                if 'broken' in flags:
                    extra = '[broken] '
                elif 'suspect' in flags:
                    extra = '[needs review] '
                else:
                    extra = ''
                text = extra + str(uid) + '\t' + title
                if is_parent_link:
                    return '→ ' + text
                else:
                    return '← ' + text
            return ''

        return super(LinkItemModel, self).data(index, role)
Example #4
0
        def dataChanged(index):
            if self.db is None:
                return
            if self.currentuid is None:
                return
            item = self.model.itemFromIndex(index)
            data = item.data()
            uid = item.text()
            doc = self.db.find(uid)
            if doc is not None:
                self.db.root.link_items(self.currentuid, uid)

            self.read(self.currentuid)
Example #5
0
    def remove_selected_link(self):
        if self.db is None:
            return
        if self.currentuid is None:
            return
        si = self.selectedIndexes()

        if len(si) == 0:
            return

        item = self.model.itemFromIndex(si[0])
        data = item.data()
        if type(data) is not tuple:
            return
        uid = data[1]
        if uid not in self.db.find(self.currentuid).links:
            return

        self.db.root.unlink_items(self.currentuid, uid)
        self.read(self.currentuid)