diff --git a/plugins/gui/include/gui/file_status_manager/file_status_manager.h b/plugins/gui/include/gui/file_status_manager/file_status_manager.h index 4a1ed7294fc..857ff0a703c 100644 --- a/plugins/gui/include/gui/file_status_manager/file_status_manager.h +++ b/plugins/gui/include/gui/file_status_manager/file_status_manager.h @@ -45,6 +45,9 @@ namespace hal class FileStatusManager : public QObject { Q_OBJECT + Q_SIGNALS: + void status_changed(bool gateLibrary, bool isDirty); + public: /** * The constructor. @@ -92,6 +95,26 @@ namespace hal */ void netlistSaved(); + /** + * Resets the netlist-modified flag that affects the modifiedFilesExisting() method. + */ + void netlistClosed(); + + /** + * Sets the gate-library-modified flag that can be queried by isGatelibModified() method. + */ + void gatelibChanged(); + + /** + * Unsets the gate-library-modified flag that can be queried by isGatelibModified() method. + */ + void gatelibSaved(); + + /** + * Query method whether GateLibraryManager has unsaved changes. + */ + bool isGatelibModified() const; + /** * Removes all registered files and unsets every modified-flag, effectively resetting * the state of the manager. @@ -111,5 +134,6 @@ namespace hal QMap mModifiedFilesDescriptors; bool mNetlistModified; + bool mGatelibModified; }; } diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_content_widget.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_content_widget.h index 9b8f1b8bd84..c89bb80d58f 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_content_widget.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_content_widget.h @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -55,10 +54,6 @@ namespace hal Q_PROPERTY(QString searchActiveIconStyle READ searchActiveIconStyle WRITE setSearchActiveIconStyle) Q_PROPERTY(QString deleteIconPath READ deleteIconPath WRITE setDeleteIconPath); Q_PROPERTY(QString deleteIconStyle READ deleteIconStyle WRITE setDeleteIconStyle); - Q_PROPERTY(QString saveIconPath READ saveIconPath WRITE setSaveIconPath); - Q_PROPERTY(QString saveIconStyle READ saveIconStyle WRITE setSaveIconStyle); - Q_PROPERTY(QString saveAsIconPath READ saveAsIconPath WRITE setSaveAsIconPath); - Q_PROPERTY(QString saveAsIconStyle READ saveAsIconStyle WRITE setSaveAsIconStyle); friend class GateLibraryManager; @@ -83,10 +78,6 @@ namespace hal QString mSearchActiveIconStyle; QString mDeleteIconPath; QString mDeleteIconStyle; - QString mSaveIconPath; - QString mSaveIconStyle; - QString mSaveAsIconPath; - QString mSaveAsIconStyle; bool mReadOnly = false; @@ -102,9 +93,11 @@ namespace hal void handleDeleteAction(); void handleCurrentSelectionChanged(QModelIndex prevIndex); void handleDoubleClicked(QModelIndex index); + void handleUnsavedChanges(); + + public Q_SLOTS: void handleSaveAction(); void handleSaveAsAction(); - void handleUnsavedChanges(); public: GatelibraryContentWidget(GatelibraryTableModel* model, QWidget* parent = nullptr); @@ -117,8 +110,6 @@ namespace hal void toggleSelection(bool selected); - void setUuid(QUuid uid); - void setGateLibrary(GateLibrary* gl); void setGateLibraryPath(std::filesystem::path p); @@ -141,14 +132,6 @@ namespace hal QString deleteIconStyle() const; - QString saveIconPath() const; - - QString saveIconStyle() const; - - QString saveAsIconPath() const; - - QString saveAsIconStyle() const; - void setDisabledIconStyle(const QString& s); void setEnabledIconStyle(const QString& s); @@ -167,19 +150,8 @@ namespace hal void setDeleteIconStyle(const QString& s); - void setSaveIconPath(const QString& s); - - void setSaveIconStyle(const QString& s); - - void setSaveAsIconPath(const QString& s); - - void setSaveAsIconStyle(const QString& s); - private: - QUuid mUuid; GateLibrary* mGateLibrary; std::filesystem::path mPath; - - bool mDirty; }; } diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h index 212602b3ce7..56fdace988c 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h @@ -68,7 +68,6 @@ namespace hal bool initialize(GateLibrary* gateLibrary = nullptr, bool readOnly = false); u32 getNextGateId(); void updateTabs(GateType* gateType); - QUuid getUuid(); public Q_SLOTS: /** @@ -89,6 +88,9 @@ namespace hal */ void handleCancelClicked(); + void handleSaveAction(); + void handleSaveAsAction(); + Q_SIGNALS: /** * Q_SIGNAL that is emitted when either the Save or Cancel button is clicked. diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h index 2e2cccc7aa9..f07481e4db2 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h @@ -74,7 +74,6 @@ namespace hal GateType* getRecentCreatedGate(); void accept() override; int nextId() const override; - QUuid getUuid(); Q_SIGNALS: void triggerUnsavedChanges(); private: @@ -94,7 +93,5 @@ namespace hal PinModel* mPinModel; GateLibraryTabPin* mPinTab; GateType* mNewGateType; - - QUuid mUuid; }; } diff --git a/plugins/gui/include/gui/main_window/file_actions.h b/plugins/gui/include/gui/main_window/file_actions.h new file mode 100644 index 00000000000..60109d7ef31 --- /dev/null +++ b/plugins/gui/include/gui/main_window/file_actions.h @@ -0,0 +1,140 @@ +// MIT License +// +// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved. +// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved. +// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved. +// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once +#include "gui/action/action.h" +#include + + +namespace hal { + class MainWindow; + class GateLibraryManager; + class SettingsItemKeybind; + + class FileActions : public QWidget + { + Q_OBJECT + Q_PROPERTY(QString saveIconPath READ saveIconPath WRITE setSaveIconPath) + Q_PROPERTY(QString saveAsIconPath READ saveAsIconPath WRITE setSaveAsIconPath) + Q_PROPERTY(QString enabledIconStyle READ enabledIconStyle WRITE setEnabledIconStyle) + Q_PROPERTY(QString disabledIconStyle READ disabledIconStyle WRITE setDisabledIconStyle) + + MainWindow* mMainWindowReference; + GateLibraryManager* mGatelibReference; + + Action* mActionSave; + Action* mActionSaveAs; + QString mSaveIconPath; + QString mSaveAsIconPath; + + QString mEnabledIconStyle; + QString mDisabledIconStyle; + SettingsItemKeybind* mSettingSaveFile; + + private Q_SLOTS: + + /** + * Q_SLOT to save the current project as a .hal file. + * call to FileManager::emitSaveTriggered(). + */ + void handleSaveTriggered(); + + /** + * Q_SLOT to save the current project as a new .hal file. + * Will query for new name. + * call to FileManager::emitSaveTriggered(). + */ + void handleSaveAsTriggered(); + + public Q_SLOTS: + void handleFileStatusChanged(bool gateLibrary, bool isDirty); + + public: + FileActions(QWidget* parent = nullptr); + + /** + * Q_PROPERTY READ function for the 'Save File'-icon path. + * + * @returns the 'SaveFile'-icon path + */ + QString saveIconPath() const {return mSaveIconPath; } + + /** + * Q_PROPERTY READ function for the 'SaveAs File'-icon path. + * + * @returns the 'SaveAsFile'-icon path + */ + QString saveAsIconPath() const { return mSaveAsIconPath; } + + /** + * Q_PROPERTY READ function for the 'Enabled'-icon style. + * + * @returns the 'Enabled'-icon style + */ + QString enabledIconStyle() const { return mEnabledIconStyle; } + + /** + * Q_PROPERTY READ function for the 'Disabled'-icon style. + * + * @returns the 'Disabled'-icon style + */ + QString disabledIconStyle() const { return mDisabledIconStyle; } + + /** + * Q_PROPERTY WRITE function for the 'Save File'-icon path. + * + * @param path - The new path + */ + void setSaveIconPath(const QString& path) { mSaveIconPath = path; } + + /** + * Q_PROPERTY WRITE function for the 'SaveAs File'-icon path. + * + * @param path - The new path + */ + void setSaveAsIconPath(const QString& path) { mSaveAsIconPath = path; } + + /** + * Q_PROPERTY WRITE function for the 'Enabled'-icon style. + * + * @param style - The new style + */ + void setEnabledIconStyle(const QString& style) { mEnabledIconStyle = style; } + + /** + * Q_PROPERTY WRITE function for the 'Disabled'-icon style. + * + * @param style - The new style + */ + void setDisabledIconStyle(const QString& style) { mDisabledIconStyle = style; } + + Action* save() const { return mActionSave; } + Action* saveAs() const { return mActionSaveAs; } + + void setup(GateLibraryManager* glcw = nullptr); + + void repolish(); + }; +} diff --git a/plugins/gui/include/gui/main_window/main_window.h b/plugins/gui/include/gui/main_window/main_window.h index 24c727a777e..de54d51a754 100644 --- a/plugins/gui/include/gui/main_window/main_window.h +++ b/plugins/gui/include/gui/main_window/main_window.h @@ -45,6 +45,7 @@ namespace hal class plugin_manager_dialog; class PythonEditor; class FileManager; + class FileActions; class ContentManager; class WelcomeScreen; class SettingsItemKeybind; @@ -72,10 +73,6 @@ namespace hal Q_PROPERTY(QString openFileIconStyle READ openFileIconStyle WRITE setOpenFileIconStyle) Q_PROPERTY(QString openProjIconPath READ openProjIconPath WRITE setOpenProjIconPath) Q_PROPERTY(QString openProjIconStyle READ openProjIconStyle WRITE setOpenProjIconStyle) - Q_PROPERTY(QString saveIconPath READ saveIconPath WRITE setSaveIconPath) - Q_PROPERTY(QString saveIconStyle READ saveIconStyle WRITE setSaveIconStyle) - Q_PROPERTY(QString saveAsIconPath READ saveAsIconPath WRITE setSaveAsIconPath) - Q_PROPERTY(QString saveAsIconStyle READ saveAsIconStyle WRITE setSaveAsIconStyle) Q_PROPERTY(QString closeIconPath READ closeIconPath WRITE setCloseIconPath) Q_PROPERTY(QString closeIconStyle READ closeIconStyle WRITE setCloseIconStyle) Q_PROPERTY(QString quitIconPath READ quitIconPath WRITE setQuitIconPath) @@ -161,32 +158,6 @@ namespace hal */ QString openProjIconStyle() const; - /** - * Q_PROPERTY READ function for the 'Save File'-icon path. - * - * @returns the 'SaveFile'-icon path - */ - QString saveIconPath() const; - /** - * Q_PROPERTY READ function for the 'Save File'-icon style. - * - * @returns the 'Save File'-icon style - */ - QString saveIconStyle() const; - - /** - * Q_PROPERTY READ function for the 'SaveAs File'-icon path. - * - * @returns the 'SaveAsFile'-icon path - */ - QString saveAsIconPath() const; - /** - * Q_PROPERTY READ function for the 'SaveAs File'-icon style. - * - * @returns the 'SaveAs File'-icon style - */ - QString saveAsIconStyle() const; - /** * Q_PROPERTY READ function for the 'Close Project'-icon path. * @@ -297,32 +268,6 @@ namespace hal */ void setOpenProjIconStyle(const QString& style); - /** - * Q_PROPERTY WRITE function for the 'Save File'-icon path. - * - * @param path - The new path - */ - void setSaveIconPath(const QString& path); - /** - * Q_PROPERTY WRITE function for the 'Save File'-icon style. - * - * @param style - The new style - */ - void setSaveIconStyle(const QString& style); - - /** - * Q_PROPERTY WRITE function for the 'SaveAs File'-icon path. - * - * @param path - The new path - */ - void setSaveAsIconPath(const QString& path); - /** - * Q_PROPERTY WRITE function for the 'SaveAs File'-icon style. - * - * @param style - The new style - */ - void setSaveAsIconStyle(const QString& style); - /** * Q_PROPERTY WRITE function for the 'Close Project'-icon path. * @@ -621,11 +566,10 @@ namespace hal QToolBar* mRightToolBar; ContentLayoutArea* mLayoutArea; + FileActions* mFileActions; Action* mActionNew; Action* mActionOpenProject; Action* mActionImportNetlist; - Action* mActionSave; - Action* mActionSaveAs; Action* mActionGateLibraryManager; Action* mActionAbout; Action* mActionStartRecording; @@ -657,12 +601,6 @@ namespace hal QString mOpenProjIconPath; QString mOpenProjIconStyle; - QString mSaveIconPath; - QString mSaveIconStyle; - - QString mSaveAsIconPath; - QString mSaveAsIconStyle; - QString mCloseIconPath; QString mCloseIconStyle; @@ -685,7 +623,6 @@ namespace hal SettingsItemKeybind* mSettingCreateFile; SettingsItemKeybind* mSettingOpenFile; - SettingsItemKeybind* mSettingSaveFile; SettingsItemKeybind* mSettingUndoLast; }; diff --git a/plugins/gui/resources/stylesheet/dark.qss b/plugins/gui/resources/stylesheet/dark.qss index 73fd1e9cbe5..8e05b6fdac7 100755 --- a/plugins/gui/resources/stylesheet/dark.qss +++ b/plugins/gui/resources/stylesheet/dark.qss @@ -935,10 +935,6 @@ hal--GatelibraryContentWidget qproperty-searchActiveIconStyle: "all->#30ac4f"; qproperty-deleteIconStyle: "all->#e8e8e8"; qproperty-deleteIconPath: ":/icons/trashcan"; - qproperty-saveIconPath: ":/icons/folder-down"; - qproperty-saveIconStyle: "all->#e8e8e8"; - qproperty-saveAsIconPath: ":/icons/save-as"; - qproperty-saveAsIconStyle: "all->#e8e8e8"; } hal--GeneralInfoWizardPage @@ -1292,12 +1288,6 @@ hal--MainWindow qproperty-openFileIconStyle: "all->#AFB1B3"; qproperty-openFileIconPath: ":/icons/detach"; - qproperty-saveIconStyle: "all->#3192C5"; - qproperty-saveIconPath: ":/icons/folder-down"; - - qproperty-saveAsIconStyle: "all->#3192C5"; - qproperty-saveAsIconPath: ":/icons/save-as"; - qproperty-closeIconStyle: "all->#AFB1B3"; qproperty-closeIconPath: ":/icons/cross"; @@ -1319,6 +1309,14 @@ hal--MainWindow qproperty-neGateIconPath: ":/icons/ne_gate"; } +hal--FileActions +{ + qproperty-saveIconPath: ":/icons/folder-down"; + qproperty-saveAsIconPath: ":/icons/save-as"; + qproperty-enabledIconStyle: "all->#3192C5"; + qproperty-disabledIconStyle: "all->#515050"; +} + hal--PythonQssAdapter { /*qproperty-textColor: #DEE9AF;*/ diff --git a/plugins/gui/src/file_status_manager/file_status_manager.cpp b/plugins/gui/src/file_status_manager/file_status_manager.cpp index 2a49f29a872..a173b3204c5 100644 --- a/plugins/gui/src/file_status_manager/file_status_manager.cpp +++ b/plugins/gui/src/file_status_manager/file_status_manager.cpp @@ -7,7 +7,7 @@ namespace hal { FileStatusManager::FileStatusManager(QObject* parent) : QObject(parent), mModifiedFilesUuid(QSet()), mModifiedFilesDescriptors(QMap()), - mNetlistModified(false) + mNetlistModified(false), mGatelibModified(false) {;} FileStatusManager::~FileStatusManager() @@ -15,14 +15,20 @@ namespace hal void FileStatusManager::fileChanged(const QUuid uuid, const QString& descriptor) { + bool before = modifiedFilesExisting(); mModifiedFilesUuid.insert(uuid); mModifiedFilesDescriptors.insert(uuid, descriptor); + if (before != modifiedFilesExisting()) + Q_EMIT status_changed(false, true); } void FileStatusManager::fileSaved(const QUuid uuid) { + bool before = modifiedFilesExisting(); mModifiedFilesUuid.remove(uuid); mModifiedFilesDescriptors.remove(uuid); + if (before != modifiedFilesExisting()) + Q_EMIT status_changed(false, false); } bool FileStatusManager::modifiedFilesExisting() const @@ -42,12 +48,41 @@ namespace hal void FileStatusManager::netlistChanged() { + bool before = modifiedFilesExisting(); mNetlistModified = true; + if (before != modifiedFilesExisting()) + Q_EMIT status_changed(false, true); } void FileStatusManager::netlistSaved() { + bool before = modifiedFilesExisting(); mNetlistModified = false; + if (before != modifiedFilesExisting()) + Q_EMIT status_changed(false, false); + } + + void FileStatusManager::netlistClosed() + { + mNetlistModified = false; + Q_EMIT status_changed(false, false); + } + + void FileStatusManager::gatelibChanged() + { + mGatelibModified = true; + Q_EMIT status_changed(true, true); + } + + void FileStatusManager::gatelibSaved() + { + mGatelibModified = false; + Q_EMIT status_changed(true, false); + } + + bool FileStatusManager::isGatelibModified() const + { + return mGatelibModified; } QList FileStatusManager::getUnsavedChangeDescriptors() const diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_content_widget.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_content_widget.cpp index eade1b0e0c5..5579dc161cf 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_content_widget.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_content_widget.cpp @@ -47,9 +47,6 @@ namespace hal mDeleteAction = new QAction("Delete gate type", this); mSearchAction = new QAction("Search", this); - mSaveAction = new QAction("Save", this); - mSaveAsAction = new QAction("Save as...", this); - //connections connect(mTableView, &QTableView::customContextMenuRequested, this, &GatelibraryContentWidget::handleContextMenuRequested); connect(mTableView, &QTableView::doubleClicked, this, &GatelibraryContentWidget::handleDoubleClicked); @@ -60,8 +57,6 @@ namespace hal connect(mDeleteAction, &QAction::triggered, this, &GatelibraryContentWidget::handleUnsavedChanges); - connect(mSaveAction, &QAction::triggered, this, &GatelibraryContentWidget::handleSaveAction); - connect(mSaveAsAction, &QAction::triggered, this, &GatelibraryContentWidget::handleSaveAsAction); connect(mSearchbar, &Searchbar::triggerNewSearch, mPinProxyModel, &SearchProxyModel::startSearch); mToolbar->addAction(mAddAction); @@ -69,10 +64,6 @@ namespace hal mToolbar->addAction(mDeleteAction); mToolbar->addAction(mSearchAction); - mToolbar->addAction(mSaveAction); - mToolbar->addAction(mSaveAsAction); - mDirty = false; - layout->addWidget(mToolbar); layout->addWidget(mTableView); layout->addWidget(mSearchbar); @@ -97,11 +88,6 @@ namespace hal menu.exec(); } - void GatelibraryContentWidget::setUuid(QUuid uid) - { - mUuid = uid; - } - void GatelibraryContentWidget::setGateLibrary(GateLibrary *gl) { mGateLibrary = gl; @@ -145,18 +131,10 @@ namespace hal msg.setWindowTitle("Save"); msg.setText("Gate library saved successfully"); - gFileStatusManager->fileSaved(mUuid); + gFileStatusManager->gatelibSaved(); HGLWriter* writer = new HGLWriter(); if(writer->write(mGateLibrary, mPath)) msg.exec(); - - mDirty = false; - mSaveAction->setEnabled(mDirty); - mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveIconPath)); - - mSaveAsAction->setEnabled(mDirty); - mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveAsIconPath)); - } void GatelibraryContentWidget::handleSaveAsAction() @@ -167,27 +145,13 @@ namespace hal path = QString::fromUtf8(gldpath.readAll()); QString filename = QFileDialog::getSaveFileName(this, "Save as", path, "HGL *.hgl"); - gFileStatusManager->fileSaved(mUuid); + gFileStatusManager->gatelibSaved(); HGLWriter* writer = new HGLWriter(); writer->write(mGateLibrary, std::filesystem::path(filename.toStdString())); - - mDirty = false; - mSaveAction->setEnabled(mDirty); - mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveIconPath)); - - mSaveAsAction->setEnabled(mDirty); - mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveAsIconPath)); } void GatelibraryContentWidget::handleUnsavedChanges() - { - mDirty = true; - mSaveAction->setEnabled(mDirty); - mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle,mSaveIconPath)); - - mSaveAsAction->setEnabled(mDirty); - mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle,mSaveAsIconPath)); - } + {;} void GatelibraryContentWidget::toggleSearchbar() { @@ -231,20 +195,6 @@ namespace hal mAddAction->setEnabled(!readOnly); mAddAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mAddTypeIconPath)); - if (mDirty) - { - mSaveAction->setEnabled(!readOnly); - mSaveAsAction->setEnabled(!readOnly); - mSaveAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mSaveIconPath)); - mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mSaveAsIconPath)); - } - else - { - mSaveAction->setEnabled(mDirty); - mSaveAsAction->setEnabled(mDirty); - mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveIconPath)); - mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveAsIconPath)); - } } void GatelibraryContentWidget::toggleSelection(bool selected) @@ -301,26 +251,6 @@ namespace hal return mDeleteIconStyle; } - QString GatelibraryContentWidget::saveIconPath() const - { - return mSaveIconPath; - } - - QString GatelibraryContentWidget::saveIconStyle() const - { - return mSaveIconStyle; - } - - QString GatelibraryContentWidget::saveAsIconPath() const - { - return mSaveAsIconPath; - } - - QString GatelibraryContentWidget::saveAsIconStyle() const - { - return mSaveAsIconStyle; - } - void GatelibraryContentWidget::setDisabledIconStyle(const QString& s) { mDisabledIconStyle = s; @@ -365,24 +295,4 @@ namespace hal { mDeleteIconStyle = s; } - - void GatelibraryContentWidget::setSaveIconPath(const QString& s) - { - mSaveIconPath = s; - } - - void GatelibraryContentWidget::setSaveIconStyle(const QString& s) - { - mSaveIconStyle = s; - } - - void GatelibraryContentWidget::setSaveAsIconPath(const QString& s) - { - mSaveAsIconPath = s; - } - - void GatelibraryContentWidget::setSaveAsIconStyle(const QString& s) - { - mSaveAsIconStyle = s; - } } diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp index 00c771ad07f..9e804166b3e 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp @@ -99,6 +99,16 @@ namespace hal s->polish(this); } + void GateLibraryManager::handleSaveAction() + { + mContentWidget->handleSaveAction(); + } + + void GateLibraryManager::handleSaveAsAction() + { + mContentWidget->handleSaveAsAction(); + } + bool GateLibraryManager::initialize(GateLibrary* gateLibrary, bool readOnly) { if(!gateLibrary) @@ -162,11 +172,6 @@ namespace hal return true; } - QUuid GateLibraryManager::getUuid() - { - return mWizard->getUuid(); - } - void GateLibraryManager::handleEditWizard(const QModelIndex& index) { if(mReadOnly) @@ -178,7 +183,6 @@ namespace hal initialize(mEditableGatelibrary); mContentWidget->mTableView->selectRow(index.row()); - mContentWidget->setUuid(mWizard->getUuid()); mContentWidget->setGateLibrary(mEditableGatelibrary); mContentWidget->setGateLibraryPath(mPath); } @@ -196,7 +200,6 @@ namespace hal if(mTableModel->getGateTypeAtIndex(r) == mWizard->getRecentCreatedGate()) mContentWidget->mTableView->selectRow(r); } - mContentWidget->setUuid(mWizard->getUuid()); mContentWidget->setGateLibrary(mEditableGatelibrary); mContentWidget->setGateLibraryPath(mPath); } @@ -206,6 +209,7 @@ namespace hal GateType* gate = mTableModel->getGateTypeAtIndex(index.row()); mEditableGatelibrary->remove_gate_type(gate->get_name()); initialize(mEditableGatelibrary); + gFileStatusManager->gatelibChanged(); //qInfo() << "handleDeleteType " << QString::fromStdString(gate->get_name()) << ":" << gate->get_id(); } @@ -245,7 +249,7 @@ namespace hal void GateLibraryManager::handleCancelClicked() { - if(!mContentWidget->mDirty) + if(!gFileStatusManager->isGatelibModified()) Q_EMIT close(); else { diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp index a7b06d752d5..fd58d6b866a 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp @@ -123,15 +123,10 @@ namespace hal } this->close(); - mUuid = QUuid::createUuid(); - gFileStatusManager->fileChanged(mUuid, QString("GateLibrary %1 modified").arg(QString::fromStdString(mGateLibrary->get_name()))); + gFileStatusManager->gatelibChanged(); Q_EMIT triggerUnsavedChanges(); } - QUuid GateLibraryWizard::getUuid(){ - return mUuid; - } - GateType* GateLibraryWizard::getRecentCreatedGate(){ return mNewGateType; } diff --git a/plugins/gui/src/main_window/file_actions.cpp b/plugins/gui/src/main_window/file_actions.cpp new file mode 100644 index 00000000000..b660518cfcf --- /dev/null +++ b/plugins/gui/src/main_window/file_actions.cpp @@ -0,0 +1,74 @@ +#include "gui/main_window/file_actions.h" +#include "gui/main_window/main_window.h" +#include "gui/gui_utils/graphics.h" +#include "gui/settings/settings_items/settings_item_keybind.h" +#include "gui/gatelibrary_management/gatelibrary_content_widget.h" +#include "gui/file_status_manager/file_status_manager.h" +#include "gui/gui_globals.h" + +#include + +namespace hal { + + FileActions::FileActions(QWidget *parent) + : QWidget(parent), mGatelibReference(nullptr) + { + repolish(); + mMainWindowReference = dynamic_cast(parent); + mActionSave = new Action(this); + mActionSaveAs = new Action(this); + + mActionSave->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle, mSaveIconPath, mDisabledIconStyle)); + mActionSaveAs->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle, mSaveAsIconPath, mDisabledIconStyle)); + + mSettingSaveFile = + new SettingsItemKeybind("HAL Shortcut 'Save File'", "keybinds/project_save_file", QKeySequence("Ctrl+S"), "Keybindings:Global", "Keybind for saving the currently opened file."); + QShortcut* shortCutSaveFile = new QShortcut(mSettingSaveFile->value().toString(), this); + connect(mSettingSaveFile, &SettingsItemKeybind::keySequenceChanged, shortCutSaveFile, &QShortcut::setKey); + connect(shortCutSaveFile, &QShortcut::activated, mActionSave, &QAction::trigger); + connect(gFileStatusManager, &FileStatusManager::status_changed, this, &FileActions::handleFileStatusChanged); + setup(); + hide(); + } + + void FileActions::repolish() + { + QStyle* s = style(); + + s->unpolish(this); + s->polish(this); + } + + void FileActions::handleFileStatusChanged(bool gateLibrary, bool isDirty) + { + if (gateLibrary == (mGatelibReference==nullptr)) return; + + mActionSave->setEnabled(isDirty); + mActionSaveAs->setEnabled(isDirty); + } + + void FileActions::setup(GateLibraryManager *glcw) + { + mGatelibReference = glcw; + mActionSave->disconnect(); + mActionSaveAs->disconnect(); + if (mGatelibReference) + { + mActionSave->setText("Save Gate Libraray"); + mActionSaveAs->setText("Save Gate Library As"); + connect(mActionSave, &Action::triggered, mGatelibReference, &GateLibraryManager::handleSaveAction); + connect(mActionSaveAs, &Action::triggered, mGatelibReference, &GateLibraryManager::handleSaveAsAction); + mActionSave->setEnabled(gFileStatusManager->isGatelibModified()); + mActionSaveAs->setEnabled(gFileStatusManager->isGatelibModified()); + } + else + { + mActionSave->setText("Save HAL Project"); + mActionSaveAs->setText("Save HAL Project As"); + connect(mActionSave, &Action::triggered, mMainWindowReference, &MainWindow::handleSaveTriggered); + connect(mActionSaveAs, &Action::triggered, mMainWindowReference, &MainWindow::handleSaveAsTriggered); + mActionSave->setEnabled(gFileStatusManager->modifiedFilesExisting()); + mActionSaveAs->setEnabled(gFileStatusManager->modifiedFilesExisting()); + } + } +} diff --git a/plugins/gui/src/main_window/main_window.cpp b/plugins/gui/src/main_window/main_window.cpp index 7fe4f374580..bb5e7a23943 100644 --- a/plugins/gui/src/main_window/main_window.cpp +++ b/plugins/gui/src/main_window/main_window.cpp @@ -13,6 +13,7 @@ #include "gui/gui_globals.h" #include "gui/logger/logger_widget.h" #include "gui/main_window/about_dialog.h" +#include "gui/main_window/file_actions.h" #include "gui/main_window/plugin_parameter_dialog.h" #include "gui/plugin_relay/gui_plugin_manager.h" #include "gui/python/python_editor.h" @@ -60,6 +61,7 @@ namespace hal MainWindow::MainWindow(QWidget* parent) : QWidget(parent) { + mFileActions = new FileActions(this); ensurePolished(); // ADD REPOLISH METHOD connect(FileManager::get_instance(), &FileManager::fileOpened, this, &MainWindow::handleFileOpened); connect(FileManager::get_instance(), &FileManager::projectOpened, this, &MainWindow::handleProjectOpened); @@ -140,8 +142,6 @@ namespace hal mActionNew = new Action(this); mActionOpenProject = new Action(this); mActionImportNetlist = new Action(this); - mActionSave = new Action(this); - mActionSaveAs = new Action(this); mActionExportProject = new Action(this); mActionImportProject = new Action(this); mActionGateLibraryManager = new Action(this); @@ -186,8 +186,6 @@ namespace hal mActionOpenProject->setIcon(gui_utility::getStyledSvgIcon(mOpenProjIconStyle, mOpenProjIconPath)); mActionImportNetlist->setIcon(gui_utility::getStyledSvgIcon(mOpenFileIconStyle, mOpenFileIconPath)); mActionImportProject->setIcon(gui_utility::getStyledSvgIcon(mOpenProjIconStyle, mOpenProjIconPath)); - mActionSave->setIcon(gui_utility::getStyledSvgIcon(mSaveIconStyle, mSaveIconPath)); - mActionSaveAs->setIcon(gui_utility::getStyledSvgIcon(mSaveAsIconStyle, mSaveAsIconPath)); mActionClose->setIcon(gui_utility::getStyledSvgIcon(mCloseIconStyle, mCloseIconPath)); mActionQuit->setIcon(gui_utility::getStyledSvgIcon(mQuitIconStyle, mQuitIconPath)); mActionGateLibraryManager->setIcon(gui_utility::getStyledSvgIcon(mNeGateIconStyle, mNeGateIconPath)); @@ -207,8 +205,8 @@ namespace hal mMenuFile->addAction(mActionNew); mMenuFile->addAction(mActionOpenProject); mMenuFile->addAction(mActionClose); - mMenuFile->addAction(mActionSave); - mMenuFile->addAction(mActionSaveAs); + mMenuFile->addAction(mFileActions->save()); + mMenuFile->addAction(mFileActions->saveAs()); mMenuFile->addAction(mActionGateLibraryManager); QMenu* menuImport = new QMenu("Import …", this); @@ -269,8 +267,8 @@ namespace hal mMenuHelp->addAction(mActionPlugins); mLeftToolBar->addAction(mActionNew); mLeftToolBar->addAction(mActionOpenProject); - mLeftToolBar->addAction(mActionSave); - mLeftToolBar->addAction(mActionSaveAs); + mLeftToolBar->addAction(mFileActions->save()); + mLeftToolBar->addAction(mFileActions->saveAs()); mLeftToolBar->addAction(mActionUndo); mRightToolBar->addAction(mActionPlugins); mRightToolBar->addAction(mActionSettings); @@ -287,8 +285,6 @@ namespace hal setWindowTitle("HAL"); mActionNew->setText("New Project"); mActionOpenProject->setText("Open Project"); - mActionSave->setText("Save"); - mActionSaveAs->setText("Save As"); mActionImportNetlist->setText("Import Netlist"); mActionImportProject->setText("Import Project"); mActionExportProject->setText("Export Project"); @@ -314,24 +310,18 @@ namespace hal mSettingOpenFile = new SettingsItemKeybind("HAL Shortcut 'Open File'", "keybinds/project_open_file", QKeySequence("Ctrl+O"), "Keybindings:Global", "Keybind for opening a new File in HAL."); - mSettingSaveFile = - new SettingsItemKeybind("HAL Shortcut 'Save File'", "keybinds/project_save_file", QKeySequence("Ctrl+S"), "Keybindings:Global", "Keybind for saving the currently opened file."); - mSettingUndoLast = new SettingsItemKeybind("Undo Last Action", "keybinds/action_undo", QKeySequence("Ctrl+Z"), "Keybindings:Global", "Keybind for having last user interaction undone."); QShortcut* shortCutNewFile = new QShortcut(mSettingCreateFile->value().toString(), this); QShortcut* shortCutOpenFile = new QShortcut(mSettingOpenFile->value().toString(), this); - QShortcut* shortCutSaveFile = new QShortcut(mSettingSaveFile->value().toString(), this); QShortcut* shortCutUndoLast = new QShortcut(mSettingUndoLast->value().toString(), this); connect(mSettingCreateFile, &SettingsItemKeybind::keySequenceChanged, shortCutNewFile, &QShortcut::setKey); connect(mSettingOpenFile, &SettingsItemKeybind::keySequenceChanged, shortCutOpenFile, &QShortcut::setKey); - connect(mSettingSaveFile, &SettingsItemKeybind::keySequenceChanged, shortCutSaveFile, &QShortcut::setKey); connect(mSettingUndoLast, &SettingsItemKeybind::keySequenceChanged, shortCutUndoLast, &QShortcut::setKey); connect(shortCutNewFile, &QShortcut::activated, mActionNew, &QAction::trigger); connect(shortCutOpenFile, &QShortcut::activated, mActionOpenProject, &QAction::trigger); - connect(shortCutSaveFile, &QShortcut::activated, mActionSave, &QAction::trigger); connect(shortCutUndoLast, &QShortcut::activated, mActionUndo, &QAction::trigger); connect(mActionNew, &Action::triggered, this, &MainWindow::handleActionNew); @@ -342,8 +332,6 @@ namespace hal connect(mActionPlugins, &Action::triggered, this, &MainWindow::openPluginManager); connect(mSettings, &MainSettingsWidget::close, this, &MainWindow::closeSettings); connect(mGateLibraryManager, &GateLibraryManager::close, this, &MainWindow::closeGateLibraryManager); - connect(mActionSave, &Action::triggered, this, &MainWindow::handleSaveTriggered); - connect(mActionSaveAs, &Action::triggered, this, &MainWindow::handleSaveAsTriggered); connect(mActionExportProject, &Action::triggered, this, &MainWindow::handleExportProjectTriggered); connect(mActionImportProject, &Action::triggered, this, &MainWindow::handleImportProjectTriggered); connect(mActionGateLibraryManager, &Action::triggered, this, &MainWindow::handleActionGatelibraryManager); @@ -422,26 +410,6 @@ namespace hal return mOpenFileIconStyle; } - QString MainWindow::saveIconPath() const - { - return mSaveIconPath; - } - - QString MainWindow::saveIconStyle() const - { - return mSaveIconStyle; - } - - QString MainWindow::saveAsIconPath() const - { - return mSaveAsIconPath; - } - - QString MainWindow::saveAsIconStyle() const - { - return mSaveAsIconStyle; - } - QString MainWindow::closeIconPath() const { return mCloseIconPath; @@ -546,26 +514,6 @@ namespace hal mOpenProjIconStyle = style; } - void MainWindow::setSaveIconPath(const QString& path) - { - mSaveIconPath = path; - } - - void MainWindow::setSaveIconStyle(const QString& style) - { - mSaveIconStyle = style; - } - - void MainWindow::setSaveAsIconPath(const QString& path) - { - mSaveAsIconPath = path; - } - - void MainWindow::setSaveAsIconStyle(const QString& style) - { - mSaveAsIconStyle = style; - } - void MainWindow::setCloseIconPath(const QString& path) { mCloseIconPath = path; @@ -684,6 +632,7 @@ namespace hal mStackedWidget->setCurrentWidget(mLayoutArea); else mStackedWidget->setCurrentWidget(mWelcomeScreen); + mFileActions->setup(); } void MainWindow::openPluginManager() @@ -838,7 +787,10 @@ namespace hal void MainWindow::handleActionGatelibraryManager() { if(mGateLibraryManager->initialize()) + { mStackedWidget->setCurrentWidget(mGateLibraryManager); + mFileActions->setup(mGateLibraryManager); + } } void MainWindow::handleImportProjectTriggered() @@ -1031,7 +983,7 @@ namespace hal bool MainWindow::tryToCloseFile() { - if (gFileStatusManager->modifiedFilesExisting()) + if (gFileStatusManager->modifiedFilesExisting() || gFileStatusManager->isGatelibModified()) { QMessageBox msgBox(this); msgBox.setStyleSheet("QLabel{min-width: 600px;}"); @@ -1042,8 +994,11 @@ namespace hal msgBox.setText("There are unsaved modifications."); QString detailed_text = "The following modifications have not been saved yet:\n"; + if (gFileStatusManager->isGatelibModified()) + detailed_text.append(" -> modified Gate Library\n"); for (const auto& s : gFileStatusManager->getUnsavedChangeDescriptors()) detailed_text.append(" -> " + s + "\n"); + msgBox.setDetailedText(detailed_text); for (const auto& button : msgBox.buttons()) @@ -1083,6 +1038,7 @@ namespace hal FileManager::get_instance()->closeFile(); setWindowTitle("HAL"); + gFileStatusManager->netlistClosed(); // disable save actions mStackedWidget->setCurrentWidget(mWelcomeScreen);