# HG changeset patch # User Teemu Piippo # Date 1656363484 -10800 # Node ID 304386ff96a4e695b1ff9dadbb669ead00541fb1 # Parent 3406191af523fdaa9b4ef4468ffda6e156b67009 Make editing tools disabled until a document is selected diff -r 3406191af523 -r 304386ff96a4 src/main.cpp --- a/src/main.cpp Mon Jun 27 23:57:47 2022 +0300 +++ b/src/main.cpp Mon Jun 27 23:58:04 2022 +0300 @@ -172,7 +172,7 @@ } } -ModelData* findModelData(DocumentManager* documents, ModelId modelId) +static ModelData* findModelData(const DocumentManager* documents, ModelId modelId) { return documents->findPayload(modelId); } @@ -183,7 +183,7 @@ return qobject_cast(w); } -static ModelData* currentModelData(Ui_MainWindow* ui, DocumentManager* documents) +static ModelData* currentModelData(Ui_MainWindow* ui, const DocumentManager* documents) { if (auto* const activeSubWindow = currentModelSubWindow(ui)) { return findModelData(documents, activeSubWindow->modelId); @@ -333,7 +333,7 @@ const auto& editingModeInfo = editingModesInfo[i]; QAction* action = new QAction{editingModeInfo.name, parent}; action->setCheckable(true); - action->setChecked(i == 0); + action->setEnabled(false); action->setData(static_cast(i)); action->setToolTip(editingModeInfo.tooltip); action->setIcon(QPixmap{editingModeInfo.icon}); @@ -670,9 +670,11 @@ updateRenderPreferences(&ui, &renderPreferences, &documents); }); } - const auto checkEditingModeAction = [&ui](EditingMode mode) { + const auto checkEditingModeAction = [&ui, &documents](EditingMode mode) { + const bool hasDocument = currentModelData(&ui, &documents) != nullptr; for (QAction* action : ui.editingModesToolBar->actions()) { - action->setChecked(action->data().value() == mode); + action->setEnabled(hasDocument); + action->setChecked(hasDocument and action->data().value() == mode); } }; initializeTools(&ui, &toolWidgets, &mainWindow);