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..ab6748c9387 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(); diff --git a/plugins/gui/include/gui/grouping/grouping_manager_widget.h b/plugins/gui/include/gui/grouping/grouping_manager_widget.h index 5f6690018e3..9c010e8c455 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,8 @@ namespace hal QString mDisabledIconStyle; GroupingColorSerializer mColorSerializer; + QShortcut* mShortCutDeleteItem; + GroupingTableEntry getCurrentGrouping(); }; } // 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..0eb15955d34 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,11 @@ namespace hal void handleModuleRemoved(Module* module, u32 module_id); + private Q_SLOTS: + void handleDeleteShortcutOnFocusChanged(QWidget *oldWidget, QWidget *newWidget); + + void deleteSelectedItem(); + private: ModuleTreeView* mTreeView; Searchbar* mSearchbar; @@ -188,8 +195,11 @@ namespace hal ModuleProxyModel* mModuleProxyModel; + QShortcut* mShortCutDeleteItem; + void openModuleInView(const QModelIndex& index); ModuleItem* getModuleItemFromIndex(const QModelIndex& index); + }; } // 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..9d5e80639fc 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 @@ -29,6 +29,7 @@ #include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" #include "hal_core/defines.h" + class QTableWidget; class QStackedWidget; class QSplitter; 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..1d54fd9992a 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,14 @@ 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, &ContextManagerWidget::handleDeleteContextClicked); + + connect(qApp, &QApplication::focusChanged, this, &ContextManagerWidget::handleDeleteShortcutOnFocusChanged); } void ContextManagerWidget::handleCreateContextClicked() @@ -167,6 +176,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 +457,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..7a19e6e76b0 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,14 @@ 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, &GroupingManagerWidget::handleDeleteGroupingClicked); + + connect(qApp, &QApplication::focusChanged, this, &GroupingManagerWidget::handleDeleteShortcutOnFocusChanged); } QList GroupingManagerWidget::createShortcuts() @@ -511,6 +520,10 @@ namespace hal void GroupingManagerWidget::handleDeleteGroupingClicked() { + if (!hasFocus() && !mGroupingTableView->hasFocus()) return; + + 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..223ad8f7ed4 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,15 @@ 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, &ModuleWidget::deleteSelectedItem); + + connect(qApp, &QApplication::focusChanged, this, &ModuleWidget::handleDeleteShortcutOnFocusChanged); + } void ModuleWidget::setupToolbar(Toolbar* toolbar) @@ -324,4 +333,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..7f11d8f1309 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,7 @@ namespace hal connect(mSearchbar, &Searchbar::textEdited, this, &SelectionDetailsWidget::updateSearchIcon); connect(mSelectionTreeView, &SelectionTreeView::itemDoubleClicked, this, &SelectionDetailsWidget::handleTreeViewItemFocusClicked); connect(mSelectionTreeView, &SelectionTreeView::focusItemClicked, this, &SelectionDetailsWidget::handleTreeViewItemFocusClicked); + } void SelectionDetailsWidget::selectionToModuleMenu()