Add method mainWindow.jumpToTag (#2584)

This commit is contained in:
Patrizio Bekerle 2022-09-13 18:07:42 +02:00
parent 913b684fb3
commit 4e7b370970
No known key found for this signature in database
GPG key ID: 2E9FFD770DABE838
5 changed files with 42 additions and 0 deletions

View file

@ -3,6 +3,10 @@
## 22.9.1
- the tag name line edit will now be properly hidden after an existing tag was
recognized and added when pressing <kbd>Tab</kbd> (for [#2607](https://github.com/pbek/QOwnNotes/issues/2607))
- there now is a new scripting command `mainWindow.jumpToTag(tagId)` to
jump to a tag in the tag tree (for [#2584](https://github.com/pbek/QOwnNotes/issues/2584))
- for more information please take a look at the
[MainWindow scripting documentation](https://www.qownnotes.org/scripting/classes.html#mainwindow)
- the tooltip for specifying file patterns of note files to ignore as regular expressions
in the *Panels settings* was fixed (for [#2580](https://github.com/pbek/QOwnNotes/issues/2580))

View file

@ -23,6 +23,8 @@ QtObject {
script.registerCustomAction("transformTextRot13", "Transform selected text with rot13", "rot13", "text-wrap", true);
script.registerCustomAction("noteSubFolder", "Show active note subfolder information", "Subfolder");
script.registerCustomAction("setActiveTag", "Set active tag", "Active tag");
}
/**
@ -83,6 +85,12 @@ QtObject {
script.log(subFolder.fullPath());
script.log(subFolder.relativePath());
break;
// jump to the tag "test" in the tag tree
case "setActiveTag":
var tag = script.getTagByNameBreadcrumbList(["test"]);
mainWindow.jumpToTag(tag.id);
break;
}
}
}

View file

@ -8488,6 +8488,27 @@ void MainWindow::on_tagTreeWidget_currentItemChanged(
filterNotes();
}
/**
* Jumps to a tag in the tag tree
*
* @param tagId
* @return
*/
bool MainWindow::jumpToTag(int tagId) {
QTreeWidgetItem *item = Utils::Gui::getTreeWidgetItemWithUserData(
ui->tagTreeWidget, tagId);
if (item != nullptr) {
// If the selection isn't cleared then the old subfolder is still selected too
ui->tagTreeWidget->clearSelection();
ui->tagTreeWidget->setCurrentItem(item);
return true;
}
return false;
}
/**
* Triggers filtering when multiple tags are selected
*/

View file

@ -224,6 +224,8 @@ class MainWindow : public QMainWindow {
Q_INVOKABLE bool removeNoteTab(int index) const;
Q_INVOKABLE bool jumpToTag(int tagId);
protected:
void changeEvent(QEvent *event) override;

View file

@ -149,6 +149,8 @@ class MainWindow {
Q_INVOKABLE void setCurrentWorkspace(const QString &uuid);
// Closes a note tab on a specific index (returns true if successful)
Q_INVOKABLE bool removeNoteTab(int index);
// Jumps to a tag in the tag tree
Q_INVOKABLE bool jumpToTag(int tagId);
};
```
@ -165,4 +167,9 @@ mainWindow.insertHtmlAsMarkdownIntoCurrentNote("<h2>my headline</h2>some text");
// Set 'Edit' workspace as current workspace
mainWindow.setCurrentWorkspace(mainWindow.getWorkspaceUuid("Edit"));
// Jump to the tag "test" in the tag tree
// There is an example in https://github.com/pbek/QOwnNotes/blob/develop/docs/scripting/examples/custom-actions.qml
var tag = script.getTagByNameBreadcrumbList(["test"]);
mainWindow.jumpToTag(tag.id);
```