Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make document tabs closable #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ MainWindow::MainWindow(QWidget *parent)
m_palette->showPalette();
});
connect(ui->actionCloseDocument, &QAction::triggered, this, &MainWindow::closeDocument);
connect(ui->tabWidget, &QTabWidget::tabCloseRequested, this, &MainWindow::closeDocument);

// Script
ui->apiExecutorWidget->hide();
Expand Down Expand Up @@ -513,12 +514,25 @@ void MainWindow::saveDocument()
document->save();
}

void MainWindow::closeDocument()
void MainWindow::closeDocument(int closeIndex)
{
const int currentIndex = ui->tabWidget->currentIndex();
bool differentIndex = false;
if (closeIndex == 0)
closeIndex = currentIndex;
else
differentIndex = currentIndex != closeIndex;
if (differentIndex)
ui->tabWidget->setCurrentIndex(closeIndex);

auto document = Core::Project::instance()->currentDocument();
if (document)
if (document) {
document->close();
ui->tabWidget->removeTab(ui->tabWidget->currentIndex());
ui->tabWidget->removeTab(closeIndex);
}

if (differentIndex)
ui->tabWidget->setCurrentIndex(currentIndex - (closeIndex < currentIndex ? 1 : 0));
}

void MainWindow::createQrc()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MainWindow : public QMainWindow
void openProject();
void saveDocument();
void saveAllDocuments();
void closeDocument();
void closeDocument(int);
void openOptions();
void returnToEditor();

Expand Down
3 changes: 3 additions & 0 deletions src/gui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<property name="documentMode">
<bool>true</bool>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
Expand Down