Delete components in tree
This commit is contained in:
@@ -61,6 +61,12 @@ class DocumentTreeController(QObject):
|
||||
document.icon_changed.connect(self._on_icon_changed)
|
||||
self.model.rename_document_requested.connect(self.document.rename)
|
||||
self.model.rename_component_requested.connect(self.document.rename_component)
|
||||
window.ui.actionDelete.triggered.connect(self.delete_selected_component)
|
||||
|
||||
# Add deselection with esc to this widget
|
||||
window.ui.actionEscape.setShortcutContext(Qt.ShortcutContext.WidgetWithChildrenShortcut)
|
||||
window.ui.documentTree.addAction(window.ui.actionEscape)
|
||||
window.ui.actionEscape.triggered.connect(self.deselect)
|
||||
|
||||
window.ui.documentTree.setHeaderHidden(True)
|
||||
window.ui.documentTree.setIconSize(QSize(48, 48))
|
||||
@@ -167,5 +173,15 @@ class DocumentTreeController(QObject):
|
||||
def _add_equation_component(self, component: Component) -> None:
|
||||
self.document.add_empty_equation_component(component)
|
||||
|
||||
def deselect(self) -> None:
|
||||
self.window.ui.documentTree.selectionModel().clear()
|
||||
|
||||
def delete_selected_component(self) -> None:
|
||||
index = self.window.ui.documentTree.currentIndex()
|
||||
component = self.model.value(index)
|
||||
focused = self.window.ui.documentTree.hasFocus()
|
||||
if focused and isinstance(component, Component):
|
||||
self._delete_component(component)
|
||||
|
||||
def _delete_component(self, component: Component) -> None:
|
||||
self.document.delete_component(component)
|
||||
|
||||
BIN
src/bedit_gui/resources/icons/edit-delete.png
Normal file
BIN
src/bedit_gui/resources/icons/edit-delete.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -1,5 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="icons">
|
||||
<file>icons/edit-delete.png</file>
|
||||
<file>icons/dialog-close.png</file>
|
||||
<file>icons/list-remove.png</file>
|
||||
<file>icons/list-add.png</file>
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
<addaction name="actionUndo"/>
|
||||
<addaction name="actionRedo"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionDelete"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSettings"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuView">
|
||||
@@ -294,6 +296,35 @@
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDelete">
|
||||
<property name="icon">
|
||||
<iconset resource="../../resources/resources.qrc">
|
||||
<normaloff>:/icons/icons/edit-delete.png</normaloff>:/icons/icons/edit-delete.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Delete selected</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Del</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEscape">
|
||||
<property name="text">
|
||||
<string>Escape</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Esc</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../resources/resources.qrc"/>
|
||||
|
||||
Reference in New Issue
Block a user