Skip to content

Commit

Permalink
Do not allow for father tabs to be closed before child tab and fix IC…
Browse files Browse the repository at this point in the history
… save
  • Loading branch information
Maycon authored and darktorres committed Feb 9, 2025
1 parent 0c5f819 commit 0cf2b83
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
33 changes: 30 additions & 3 deletions app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ void MainWindow::save(const QString &fileName)
while (true) {
auto fatherICs = m_icsTabTree.keys(c_tab);

if (fatherICs.size() != 1) { break; }
if (fatherICs.size() != 1) {
c_tab->save(c_tab->fileInfo().fileName());
break;
};

auto fatherIC = fatherICs.at(0);
c_tab->m_EmbeddedIc->m_fileData.clear();
Expand Down Expand Up @@ -402,6 +405,19 @@ int MainWindow::confirmSave(const bool multiple)
return msgBox.exec();
}

int MainWindow::warnAboutOpenChildIcs()
{
QMessageBox msgBox;
msgBox.setParent(this);

msgBox.setStandardButtons(QMessageBox::Ok);

msgBox.setText(tr("This workspace has open child ICs, please close them first!"));
msgBox.setWindowModality(Qt::WindowModal);
msgBox.setDefaultButton(QMessageBox::Ok);
return msgBox.exec();
}

void MainWindow::on_actionNew_triggered()
{
createNewTab();
Expand Down Expand Up @@ -754,9 +770,20 @@ void MainWindow::updateICList(QString dirPath)

bool MainWindow::closeTab(const int tabIndex)
{
auto fatherTab = m_icsTabTree.keys(m_currentTab);

if (fatherTab.size() > 0 && m_icsTabTree.remove(fatherTab.at(0), m_currentTab) != 1) { return false; }
auto tabToClose = qobject_cast<WorkSpace *>(m_ui->tab->widget(tabIndex));
auto fatherTab = m_icsTabTree.keys(tabToClose);

//Check if there is an open child tab

for (auto &tab : m_icsTabTree.keys()) {
if (tab.second == tabToClose) {
warnAboutOpenChildIcs();
return false;
}
}

if (fatherTab.size() > 0 && m_icsTabTree.remove(fatherTab.at(0), tabToClose) != 1) { return false; }

qCDebug(zero) << "Closing tab " << tabIndex + 1 << ", #tabs: " << m_ui->tab->count();
m_ui->tab->setCurrentIndex(tabIndex);
Expand Down
1 change: 1 addition & 0 deletions app/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MainWindow : public QMainWindow
WorkSpace *getCurrentTab();
bool closeFiles();
bool event(QEvent *event) override;
int warnAboutOpenChildIcs();
void exportToWaveFormTerminal();
void loadEmbeddedIC(const QString &fileName, IC *source_ic);
void loadTranslation(const QString &language);
Expand Down

0 comments on commit 0cf2b83

Please sign in to comment.