From 48aa8ef6bb9d85b73f8b058580e0b67e6a355a28 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 13 Sep 2023 15:13:14 +0200 Subject: [PATCH] create shortcuts for deleting items in widgets --- .../gui/content_manager/content_manager.h | 1 + .../context_manager_widget.h | 9 ++++ .../gui/grouping/grouping_manager_widget.h | 6 +++ .../include/gui/module_widget/module_widget.h | 8 ++++ .../selection_details_widget.h | 5 ++- .../src/content_manager/content_manager.cpp | 11 +++++ .../context_manager_widget.cpp | 29 +++++++++++++ .../src/grouping/grouping_manager_widget.cpp | 28 +++++++++++++ .../gui/src/module_widget/module_widget.cpp | 42 ++++++++++++++++++- .../selection_details_widget.cpp | 8 ++++ 10 files changed, 145 insertions(+), 2 deletions(-) diff --git a/plugins/gui/include/gui/content_manager/content_manager.h b/plugins/gui/include/gui/content_manager/content_manager.h index 73294023a38..9b74ab890b2 100644 --- a/plugins/gui/include/gui/content_manager/content_manager.h +++ b/plugins/gui/include/gui/content_manager/content_manager.h @@ -168,6 +168,7 @@ namespace hal public: static SettingsItemKeybind* sSettingSearch; + static SettingsItemKeybind* sSettingDeleteItem; void addExternalWidget(ContentFactory* factory); private: diff --git a/plugins/gui/include/gui/context_manager_widget/context_manager_widget.h b/plugins/gui/include/gui/context_manager_widget/context_manager_widget.h index fdb6c690533..1866580c580 100644 --- a/plugins/gui/include/gui/context_manager_widget/context_manager_widget.h +++ b/plugins/gui/include/gui/context_manager_widget/context_manager_widget.h @@ -33,6 +33,7 @@ #include "gui/context_manager_widget/models/context_table_model.h" #include "gui/context_manager_widget/models/context_table_proxy_model.h" #include "gui/searchbar/searchbar.h" +#include "gui/settings/settings_items/settings_item_keybind.h" #include #include @@ -166,6 +167,11 @@ namespace hal */ void updateSearchIcon(); + private Q_SLOTS: + + void handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget); + + private: GraphTabWidget* mTabView; @@ -201,6 +207,8 @@ namespace hal QString mSearchIconStyle; QString mSearchActiveIconStyle; + QShortcut* mShortCutDeleteItem; + void handleCreateContextClicked(); void handleRenameContextClicked(); void handleDuplicateContextClicked(); @@ -214,5 +222,6 @@ namespace hal void toggleSearchbar(); QList createShortcuts() override; + void deleteSelectedContext(); }; } diff --git a/plugins/gui/include/gui/grouping/grouping_manager_widget.h b/plugins/gui/include/gui/grouping/grouping_manager_widget.h index 5f6690018e3..413d37480d8 100644 --- a/plugins/gui/include/gui/grouping/grouping_manager_widget.h +++ b/plugins/gui/include/gui/grouping/grouping_manager_widget.h @@ -28,6 +28,7 @@ #include "gui/content_widget/content_widget.h" #include "gui/grouping/grouping_table_model.h" #include "hal_core/defines.h" +#include "gui/settings/settings_items/settings_item_keybind.h" #include #include "gui/grouping/grouping_color_serializer.h" @@ -315,6 +316,8 @@ namespace hal */ void handleDoubleClicked(const QModelIndex& index); + void handleDeleteShortcutOnFocusChanged(QWidget *oldWidget, QWidget *newWidget); + private: class ToolboxModuleHash { @@ -375,6 +378,9 @@ namespace hal QString mDisabledIconStyle; GroupingColorSerializer mColorSerializer; + QShortcut* mShortCutDeleteItem; + GroupingTableEntry getCurrentGrouping(); + void deleteSelectedGrouping(); }; } // namespace hal diff --git a/plugins/gui/include/gui/module_widget/module_widget.h b/plugins/gui/include/gui/module_widget/module_widget.h index 475fef1b1ef..d5cbea42f3a 100644 --- a/plugins/gui/include/gui/module_widget/module_widget.h +++ b/plugins/gui/include/gui/module_widget/module_widget.h @@ -32,6 +32,8 @@ #include "gui/selection_relay/selection_relay.h" #include "gui/module_widget/module_tree_view.h" #include "hal_core/netlist/module.h" +#include "gui/settings/settings_items/settings_item_keybind.h" + #include #include @@ -170,6 +172,9 @@ namespace hal void handleModuleRemoved(Module* module, u32 module_id); + private Q_SLOTS: + void handleDeleteShortcutOnFocusChanged(QWidget *oldWidget, QWidget *newWidget); + private: ModuleTreeView* mTreeView; Searchbar* mSearchbar; @@ -188,8 +193,11 @@ namespace hal ModuleProxyModel* mModuleProxyModel; + QShortcut* mShortCutDeleteItem; + void openModuleInView(const QModelIndex& index); ModuleItem* getModuleItemFromIndex(const QModelIndex& index); + void deleteSelectedItem(); }; } // namespace hal diff --git a/plugins/gui/include/gui/selection_details_widget/selection_details_widget.h b/plugins/gui/include/gui/selection_details_widget/selection_details_widget.h index 9f7df1984ce..7fb8fed623c 100644 --- a/plugins/gui/include/gui/selection_details_widget/selection_details_widget.h +++ b/plugins/gui/include/gui/selection_details_widget/selection_details_widget.h @@ -28,6 +28,8 @@ #include "gui/content_widget/content_widget.h" #include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" #include "hal_core/defines.h" +#include "gui/settings/settings_items/settings_item_keybind.h" + class QTableWidget; class QStackedWidget; @@ -76,7 +78,8 @@ namespace hal * * @param parent - The widget's parent. */ - SelectionDetailsWidget(QWidget* parent = nullptr); + SelectionDetailsWidget( + QWidget* parent = nullptr); /** * Overrides the ContentWidget's setupToolbar method. Adds its specific actions to the given toolbar diff --git a/plugins/gui/src/content_manager/content_manager.cpp b/plugins/gui/src/content_manager/content_manager.cpp index 859802fe29c..8b2d13a7a0a 100644 --- a/plugins/gui/src/content_manager/content_manager.cpp +++ b/plugins/gui/src/content_manager/content_manager.cpp @@ -38,6 +38,7 @@ namespace hal { + ExternalContent* ExternalContent::inst = nullptr; ExternalContent* ExternalContent::instance() @@ -60,6 +61,7 @@ namespace hal SettingsItemDropdown* ContentManager::sSettingSortMechanism; SettingsItemKeybind* ContentManager::sSettingSearch; + SettingsItemKeybind* ContentManager::sSettingDeleteItem; bool ContentManager::sSettingsInitialized = initializeSettings(); bool ContentManager::initializeSettings() { @@ -74,12 +76,21 @@ namespace hal "Keybindings:Global", "Keybind for toggeling the searchbar in widgets where available (Selection Details Widget, Modules Widget, Python Editor, Views Widget, Grouping Widget)."); + + sSettingDeleteItem = + new SettingsItemKeybind("Delete Item", + "keybinds/item_delete", + QKeySequence("Del"), + "Keybindings:Global", + "Keybind for deleting the focused Item."); return true; } ContentManager::ContentManager(MainWindow* parent) : QObject(parent), mMainWindow(parent), mExternalIndex(0), mContextSerializer(nullptr) { + + // has to be created this early in order to receive deserialization by the core signals mPythonWidget = new PythonEditor(); diff --git a/plugins/gui/src/context_manager_widget/context_manager_widget.cpp b/plugins/gui/src/context_manager_widget/context_manager_widget.cpp index e11c9dbeb31..b53f7413e90 100644 --- a/plugins/gui/src/context_manager_widget/context_manager_widget.cpp +++ b/plugins/gui/src/context_manager_widget/context_manager_widget.cpp @@ -32,6 +32,7 @@ #include "gui/user_action/action_rename_object.h" #include "gui/user_action/user_action_compound.h" #include +#include namespace hal { @@ -110,6 +111,16 @@ namespace hal connect(mSearchbar, &Searchbar::textEdited, mContextTableProxyModel, &ContextTableProxyModel::handleFilterTextChanged); connect(mSearchbar, &Searchbar::textEdited, this, &ContextManagerWidget::updateSearchIcon); + + mShortCutDeleteItem = new QShortcut(ContentManager::sSettingDeleteItem->value().toString(), this); + mShortCutDeleteItem->setEnabled(false); + + connect(ContentManager::sSettingDeleteItem, &SettingsItemKeybind::keySequenceChanged, mShortCutDeleteItem, &QShortcut::setKey); + connect(mShortCutDeleteItem, &QShortcut::activated, [&]() { + this->handleDeleteContextClicked(); + }); + + connect(qApp, &QApplication::focusChanged, this, &ContextManagerWidget::handleDeleteShortcutOnFocusChanged); } void ContextManagerWidget::handleCreateContextClicked() @@ -167,6 +178,8 @@ namespace hal void ContextManagerWidget::handleDeleteContextClicked() { + QModelIndex current = mContextTableView->currentIndex(); + if (!current.isValid()) return; GraphContext* clicked_context = getCurrentContext(); ActionDeleteObject* act = new ActionDeleteObject; act->setObject(UserActionObject(clicked_context->id(),UserActionObjectType::Context)); @@ -446,4 +459,20 @@ namespace hal { mSearchActiveIconStyle = style; } + + void ContextManagerWidget::handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget) + { + if(!newWidget) return; + if(newWidget->parent() == this) + { + mShortCutDeleteItem->setEnabled(true); + return; + } + else + { + mShortCutDeleteItem->setEnabled(false); + return; + } + } + } diff --git a/plugins/gui/src/grouping/grouping_manager_widget.cpp b/plugins/gui/src/grouping/grouping_manager_widget.cpp index bb03553ecef..acc9836de59 100644 --- a/plugins/gui/src/grouping/grouping_manager_widget.cpp +++ b/plugins/gui/src/grouping/grouping_manager_widget.cpp @@ -20,6 +20,7 @@ #include "gui/selection_details_widget/tree_navigation/selection_tree_view.h" #include +#include #include #include #include @@ -114,6 +115,16 @@ namespace hal connect(mGroupingTableModel, &GroupingTableModel::newEntryAdded, this, &GroupingManagerWidget::handleNewEntryAdded); connect(mGroupingTableView, &QTableView::doubleClicked, this, &GroupingManagerWidget::handleDoubleClicked); handleCurrentChanged(); + + mShortCutDeleteItem = new QShortcut(ContentManager::sSettingDeleteItem->value().toString(), this); + mShortCutDeleteItem->setEnabled(false); + + connect(ContentManager::sSettingDeleteItem, &SettingsItemKeybind::keySequenceChanged, mShortCutDeleteItem, &QShortcut::setKey); + connect(mShortCutDeleteItem, &QShortcut::activated, [&]() { + this->handleDeleteGroupingClicked(); + }); + + connect(qApp, &QApplication::focusChanged, this, &GroupingManagerWidget::handleDeleteShortcutOnFocusChanged); } QList GroupingManagerWidget::createShortcuts() @@ -511,6 +522,8 @@ namespace hal void GroupingManagerWidget::handleDeleteGroupingClicked() { + QModelIndex current = mGroupingTableView->currentIndex(); + if (!current.isValid()) return; int irow = mProxyModel->mapToSource(mGroupingTableView->currentIndex()).row(); u32 grpId = mGroupingTableModel->groupingAt(irow).id(); ActionDeleteObject* act = new ActionDeleteObject; @@ -835,4 +848,19 @@ namespace hal { mTableIconStyle = style; } + + void GroupingManagerWidget::handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget) + { + if(!newWidget) return; + if(newWidget->parent() == this) + { + mShortCutDeleteItem->setEnabled(true); + return; + } + else + { + mShortCutDeleteItem->setEnabled(false); + return; + } + } } // namespace hal diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index f5948460a20..1d68a242e98 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -14,6 +14,7 @@ #include "hal_core/netlist/module.h" #include "hal_core/netlist/net.h" #include "gui/module_model/module_model.h" +#include #include #include #include @@ -24,7 +25,6 @@ #include #include #include -#include "hal_core/utilities/log.h" namespace hal { @@ -73,6 +73,17 @@ namespace hal connect(mSearchAction, &QAction::triggered, this, &ModuleWidget::toggleSearchbar); connect(mSearchbar, &Searchbar::textEdited, this, &ModuleWidget::updateSearchIcon); + + mShortCutDeleteItem = new QShortcut(ContentManager::sSettingDeleteItem->value().toString(), this); + mShortCutDeleteItem->setEnabled(false); + + connect(ContentManager::sSettingDeleteItem, &SettingsItemKeybind::keySequenceChanged, mShortCutDeleteItem, &QShortcut::setKey); + connect(mShortCutDeleteItem, &QShortcut::activated, [&]() { + this->deleteSelectedItem(); + }); + + connect(qApp, &QApplication::focusChanged, this, &ModuleWidget::handleDeleteShortcutOnFocusChanged); + } void ModuleWidget::setupToolbar(Toolbar* toolbar) @@ -324,4 +335,33 @@ namespace hal { mSearchActiveIconStyle = style; } + + void ModuleWidget::deleteSelectedItem() + { + if(!mTreeView->currentIndex().isValid()) + { + return; + } + + ModuleItem* selectedItem = getModuleItemFromIndex(mTreeView->currentIndex()); + if(selectedItem->parent() != nullptr) + { + gNetlistRelay->deleteModule(getModuleItemFromIndex(mTreeView->currentIndex())->id()); + } + } + + void ModuleWidget::handleDeleteShortcutOnFocusChanged(QWidget* oldWidget, QWidget* newWidget) + { + if(!newWidget) return; + if(newWidget->parent() == this) + { + mShortCutDeleteItem->setEnabled(true); + return; + } + else + { + mShortCutDeleteItem->setEnabled(false); + return; + } + } } diff --git a/plugins/gui/src/selection_details_widget/selection_details_widget.cpp b/plugins/gui/src/selection_details_widget/selection_details_widget.cpp index 56dfae249cc..686a6b0d7d9 100644 --- a/plugins/gui/src/selection_details_widget/selection_details_widget.cpp +++ b/plugins/gui/src/selection_details_widget/selection_details_widget.cpp @@ -143,6 +143,14 @@ namespace hal connect(mSearchbar, &Searchbar::textEdited, this, &SelectionDetailsWidget::updateSearchIcon); connect(mSelectionTreeView, &SelectionTreeView::itemDoubleClicked, this, &SelectionDetailsWidget::handleTreeViewItemFocusClicked); connect(mSelectionTreeView, &SelectionTreeView::focusItemClicked, this, &SelectionDetailsWidget::handleTreeViewItemFocusClicked); + + QShortcut* shortCutDeleteItem = new QShortcut(ContentManager::sSettingDeleteItem->value().toString(), this); + shortCutDeleteItem->setEnabled(false); + + connect(ContentManager::sSettingDeleteItem, &SettingsItemKeybind::keySequenceChanged, shortCutDeleteItem, &QShortcut::setKey); + connect(shortCutDeleteItem, &QShortcut::activated, [&]() { + + }); } void SelectionDetailsWidget::selectionToModuleMenu()