diff --git a/CHANGELOG.md b/CHANGELOG.md index 84267e0dd9..3f76cab81a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # QOwnNotes Changelog ## 22.8.4 +- there now is a new scripting command `mainWindow.removeNoteTab(index)` to + close a note tab on a specific index (for [#2592](https://github.com/pbek/QOwnNotes/issues/2592)) + - for more information please take a look at the + [MainWindow scripting documentation](https://www.qownnotes.org/scripting/classes.html#mainwindow) - the snap deployment process is now working again (for [#2588](https://github.com/pbek/QOwnNotes/issues/2588)) ## 22.8.3 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fc19a4a428..89e6681054 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -11910,10 +11910,19 @@ void MainWindow::on_actionNew_note_in_new_tab_triggered() { openCurrentNoteInTab(); } -void MainWindow::removeNoteTab(int index) const { - if (ui->noteEditTabWidget->count() > 1) { - ui->noteEditTabWidget->removeTab(index); +/** + * Close a note tab on a specific index. + * @param index The index of the tab to close. + */ +bool MainWindow::removeNoteTab(int index) const { + const int maxIndex = ui->noteEditTabWidget->count() - 1; + + if (maxIndex <= 0 || index > maxIndex) { + return false; } + + ui->noteEditTabWidget->removeTab(index); + return true; } void MainWindow::on_noteEditTabWidget_tabBarDoubleClicked(int index) { diff --git a/src/mainwindow.h b/src/mainwindow.h index 0ca3b38ba8..55f1945f8a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -222,6 +222,8 @@ class MainWindow : public QMainWindow { void refreshNotePreview(); + Q_INVOKABLE bool removeNoteTab(int index) const; + protected: void changeEvent(QEvent *event) override; @@ -1099,7 +1101,6 @@ class MainWindow : public QMainWindow { void updateCurrentTabData(const Note ¬e) const; bool jumpToTab(const Note ¬e) const; void closeOrphanedTabs() const; - void removeNoteTab(int index) const; void automaticScriptUpdateCheck(); void updateJumpToActionsAvailability(); int getNoteTabIndex(int noteId) const; diff --git a/webpage/src/scripting/classes.md b/webpage/src/scripting/classes.md index d776185742..3905c9fe41 100644 --- a/webpage/src/scripting/classes.md +++ b/webpage/src/scripting/classes.md @@ -147,6 +147,8 @@ class MainWindow { Q_INVOKABLE QString getWorkspaceUuid(const QString &workspaceName); // Sets the current workspace by UUID 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); }; ```