예제 #1
0
파일: tree.py 프로젝트: rye761/anki
 def _maybe_add_search_actions(self, menu: QMenu) -> None:
     nodes = [
         item.search_node for item in self._selected_items() if item.search_node
     ]
     if not nodes:
         return
     if len(nodes) == 1:
         menu.addAction(tr.actions_search(), lambda: self.update_search(*nodes))
         return
     sub_menu = menu.addMenu(tr.actions_search())
     sub_menu.addAction(
         tr.actions_all_selected(), lambda: self.update_search(*nodes)
     )
     sub_menu.addAction(
         tr.actions_any_selected(),
         lambda: self.update_search(*nodes, joiner="OR"),
     )
예제 #2
0
    def onFindDupes(self) -> None:
        import anki.find

        d = QDialog(self)
        self.mw.garbage_collect_on_dialog_finish(d)
        frm = aqt.forms.finddupes.Ui_Dialog()
        frm.setupUi(d)
        restoreGeom(d, "findDupes")
        disable_help_button(d)
        searchHistory = restore_combo_history(frm.search, "findDupesFind")

        fields = sorted(anki.find.fieldNames(self.col, downcase=False),
                        key=lambda x: x.lower())
        frm.fields.addItems(fields)
        restore_combo_index_for_session(frm.fields, fields, "findDupesFields")
        self._dupesButton: Optional[QPushButton] = None

        # links
        frm.webView.set_title("find duplicates")
        web_context = FindDupesDialog(dialog=d, browser=self)
        frm.webView.set_bridge_command(self.dupeLinkClicked, web_context)
        frm.webView.stdHtml("", context=web_context)

        def onFin(code: Any) -> None:
            saveGeom(d, "findDupes")

        qconnect(d.finished, onFin)

        def onClick() -> None:
            search_text = save_combo_history(frm.search, searchHistory,
                                             "findDupesFind")
            save_combo_index_for_session(frm.fields, "findDupesFields")
            field = fields[frm.fields.currentIndex()]
            self.duplicatesReport(frm.webView, field, search_text, frm,
                                  web_context)

        search = frm.buttonBox.addButton(tr.actions_search(),
                                         QDialogButtonBox.ActionRole)
        qconnect(search.clicked, onClick)
        d.show()