Skip to content

Commit

Permalink
Update removeNoteTab method (#2592)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed Aug 25, 2022
1 parent 341652a commit 1677aaf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
15 changes: 12 additions & 3 deletions src/mainwindow.cpp
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.h
Expand Up @@ -222,6 +222,8 @@ class MainWindow : public QMainWindow {

void refreshNotePreview();

Q_INVOKABLE bool removeNoteTab(int index) const;

protected:
void changeEvent(QEvent *event) override;

Expand Down Expand Up @@ -1099,7 +1101,6 @@ class MainWindow : public QMainWindow {
void updateCurrentTabData(const Note &note) const;
bool jumpToTab(const Note &note) const;
void closeOrphanedTabs() const;
void removeNoteTab(int index) const;
void automaticScriptUpdateCheck();
void updateJumpToActionsAvailability();
int getNoteTabIndex(int noteId) const;
Expand Down
2 changes: 2 additions & 0 deletions webpage/src/scripting/classes.md
Expand Up @@ -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);
};
```
Expand Down

0 comments on commit 1677aaf

Please sign in to comment.