Skip to content

Commit

Permalink
Add method mainWindow.jumpToTag (pbek#2584)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed Sep 13, 2022
1 parent 913b684 commit 4e7b370
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
8 changes: 8 additions & 0 deletions docs/scripting/examples/custom-actions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand Down Expand Up @@ -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;
}
}
}
21 changes: 21 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions webpage/src/scripting/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
```
Expand All @@ -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);
```

0 comments on commit 4e7b370

Please sign in to comment.