Ejemplo n.º 1
0
    def accept(self) -> None:
        saveGeom(self, "findreplace")
        save_combo_index_for_session(self.form.field, self.COMBO_NAME + "Field")

        search = save_combo_history(
            self.form.find, self._find_history, self.COMBO_NAME + "Find"
        )
        replace = save_combo_history(
            self.form.replace, self._replace_history, self.COMBO_NAME + "Replace"
        )
        regex = self.form.re.isChecked()
        match_case = not self.form.ignoreCase.isChecked()
        save_is_checked(self.form.re, self.COMBO_NAME + "Regex")
        save_is_checked(self.form.ignoreCase, self.COMBO_NAME + "ignoreCase")

        # tags?
        if self.form.field.currentIndex() == 1:
            find_and_replace_tag(
                parent=self.parentWidget(),
                note_ids=self.note_ids,
                search=search,
                replacement=replace,
                regex=regex,
                match_case=match_case,
            ).run_in_background()
        else:
            # fields
            if self.form.field.currentIndex() == 0:
                field = None
            else:
                field = self.field_names[self.form.field.currentIndex() - 2]

            find_and_replace(
                parent=self.parentWidget(),
                note_ids=self.note_ids,
                search=search,
                replacement=replace,
                regex=regex,
                field_name=field,
                match_case=match_case,
            ).run_in_background()

        super().accept()
Ejemplo n.º 2
0
    def accept(self) -> None:
        saveGeom(self, "findreplace")
        save_combo_index_for_session(self.form.field,
                                     self.COMBO_NAME + "Field")

        search = save_combo_history(self.form.find, self._find_history,
                                    self.COMBO_NAME + "Find")
        replace = save_combo_history(self.form.replace, self._replace_history,
                                     self.COMBO_NAME + "Replace")
        regex = self.form.re.isChecked()
        match_case = not self.form.ignoreCase.isChecked()
        save_is_checked(self.form.re, self.COMBO_NAME + "Regex")
        save_is_checked(self.form.ignoreCase, self.COMBO_NAME + "ignoreCase")

        if not self.form.selected_notes.isChecked():
            # an empty list means *all* notes
            self.note_ids = []

        # tags?
        if self.form.field.currentIndex() == 1:
            op = find_and_replace_tag(
                parent=self.parentWidget(),
                note_ids=self.note_ids,
                search=search,
                replacement=replace,
                regex=regex,
                match_case=match_case,
            )
        else:
            # fields
            if self.form.field.currentIndex() == 0:
                field = None
            else:
                field = self.field_names[self.form.field.currentIndex()]

            op = find_and_replace(
                parent=self.parentWidget(),
                note_ids=self.note_ids,
                search=search,
                replacement=replace,
                regex=regex,
                field_name=field,
                match_case=match_case,
            )

        if not self.note_ids:
            op.success(lambda out: tooltip(
                tr.browsing_notes_updated(count=out.count),
                parent=self.parentWidget(),
            ))
        op.run_in_background()

        super().accept()