From d11a01d6a12cc54f9d1008c76b681ca1c7df4439 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sun, 28 Apr 2019 13:25:41 +0200 Subject: [PATCH] Removed the context menu code. --- nw/gui/doctreectx.py | 215 ------------------------------------------ nw/project/item.py | 2 +- nw/project/project.py | 71 -------------- 3 files changed, 1 insertion(+), 287 deletions(-) delete mode 100644 nw/gui/doctreectx.py diff --git a/nw/gui/doctreectx.py b/nw/gui/doctreectx.py deleted file mode 100644 index 9759c5ff..00000000 --- a/nw/gui/doctreectx.py +++ /dev/null @@ -1,215 +0,0 @@ -# -*- coding: utf-8 -*- -"""novelWriter GUI Document Tree Context Menu - - novelWriter – GUI Document Tree Context Menu -============================================== - Class holding the context menu of the left side document tree view - - File History: - Created: 2019-04-14 [0.0.1] - -""" - -import logging -import nw - -from copy import copy - -from PyQt5.QtWidgets import QMenu, QAction - -from nw.enum import nwItemType, nwItemClass, nwItemAction -from nw.constants import nwLabels - -logger = logging.getLogger(__name__) - -class GuiDocTreeCtx(QMenu): - - def __init__(self, theDocTree, theProject, thePosition): - QMenu.__init__(self, theDocTree) - - logger.debug("Initialising DocTree ContextMenu ...") - self.mainConf = nw.CONFIG - self.theProject = theProject - self.theDocTree = theDocTree - - self.selAction = None - self.selClass = None - self.selType = None - self.selTarget = None - - selItems = self.theDocTree.selectedItems() - if len(selItems) == 0: - self.selHandle = None - else: - self.selHandle = selItems[0].text(3) - - self._buildMenu() - - logger.debug("DocTree ContextMenu initialisation complete") - - self.exec_(self.theDocTree.viewport().mapToGlobal(thePosition)) - - return - - def _buildMenu(self): - vActs = self.theProject.getActionList(self.selHandle) - if nwItemAction.RENAME in vActs.keys(): - self._buildMenuRename(vActs) - if nwItemAction.ADD_ROOT in vActs.keys(): - self._buildMenuAddRoot(vActs) - if nwItemAction.ADD_FOLDER in vActs.keys(): - self._buildMenuAddFolder(vActs) - if nwItemAction.ADD_FILE in vActs.keys(): - self._buildMenuAddFile(vActs) - if nwItemAction.MOVE_UP in vActs.keys(): - self._buildMenuMoveUp(vActs) - if nwItemAction.MOVE_DOWN in vActs.keys(): - self._buildMenuMoveDown(vActs) - if nwItemAction.MOVE_TRASH in vActs.keys(): - self._buildMenuMoveTrash(vActs) - if nwItemAction.MOVE_TO in vActs.keys(): - self._buildMenuMoveTo(vActs) - if nwItemAction.SPLIT in vActs.keys(): - self._buildMenuSplit(vActs) - if nwItemAction.MERGE in vActs.keys(): - self._buildMenuMerge(vActs) - if nwItemAction.DELETE in vActs.keys(): - self._buildMenuDelete(vActs) - if nwItemAction.DELETE_ROOT in vActs.keys(): - self._buildMenuDeleteRoot(vActs) - if nwItemAction.EMPTY_TRASH in vActs.keys(): - self._buildMenuEmptyTrash(vActs) - return - - ## - # Build Sub Menus - ## - - def _buildMenuRename(self, vActs): - mnuItem = QAction("Rename", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.RENAME, None, None - )) - self.addAction(mnuItem) - return - - def _buildMenuDelete(self, vActs): - mnuItem = QAction("Delete Permanently", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.DELETE, None, None - )) - self.addAction(mnuItem) - return - - def _buildMenuDeleteRoot(self, vActs): - mnuItem = QAction("Remove Root", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.DELETE_ROOT, None, None - )) - self.addAction(mnuItem) - return - - def _buildMenuEmptyTrash(self, vActs): - mnuItem = QAction("Empty Trash", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.EMPTY_TRASH, None, None - )) - self.addAction(mnuItem) - return - - def _buildMenuSplit(self, vActs): - mnuItem = QAction("Split File", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.SPLIT, None, None - )) - self.addAction(mnuItem) - return - - def _buildMenuMerge(self, vActs): - mnuItem = QAction("Merge Folder", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.MERGE, None, None - )) - self.addAction(mnuItem) - return - - def _buildMenuMoveUp(self, vActs): - mnuItem = QAction("Move Up", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.MOVE_UP, None, None - )) - self.addAction(mnuItem) - return - - def _buildMenuMoveDown(self, vActs): - mnuItem = QAction("Move Down", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.MOVE_DOWN, None, None - )) - self.addAction(mnuItem) - return - - def _buildMenuMoveTrash(self, vActs): - mnuItem = QAction("Move to Trash", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.MOVE_TRASH, None, None - )) - self.addAction(mnuItem) - return - - def _buildMenuMoveTo(self, vActs): - mnuItem = QAction("Move to", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.MOVE_TO, None, None, - None - )) - self.addAction(mnuItem) - return - - def _buildMenuAddFile(self, vActs): - mnuItem = QAction("Add File", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.ADD_FILE, - vActs[nwItemAction.ADD_FILE]["Class"], - nwItemType.FILE - )) - self.addAction(mnuItem) - return - - def _buildMenuAddFolder(self, vActs): - mnuItem = QAction("Add Folder", self) - mnuItem.triggered.connect(lambda: self._ctxSignal( - nwItemAction.ADD_FOLDER, - vActs[nwItemAction.ADD_FOLDER]["Class"], - nwItemType.FOLDER - )) - self.addAction(mnuItem) - return - - def _buildMenuAddRoot(self, vActs): - for itemClass in vActs[nwItemAction.ADD_ROOT]["Class"]: - self._buildSubMenuAddRoot(itemClass) - return - - def _buildSubMenuAddRoot(self, itemClass): - mnuSub = QAction("Add %s Root" % nwLabels.CLASS_NAME[itemClass], self) - mnuSub.triggered.connect(lambda: self._ctxSignal( - nwItemAction.ADD_ROOT, - itemClass, - nwItemType.ROOT - )) - self.addAction(mnuSub) - return - - ## - # Menu Signal - ## - - def _ctxSignal(self, theAction, theClass, theType, theTarget=None): - self.selAction = theAction - self.selClass = theClass - self.selType = theType - self.selTarget = theTarget - return - -# END Class GuiDocTreeCtx diff --git a/nw/project/item.py b/nw/project/item.py index eb2ad27b..f90ff9d9 100644 --- a/nw/project/item.py +++ b/nw/project/item.py @@ -23,7 +23,7 @@ logger = logging.getLogger(__name__) class NWItem(): - MAX_DEPTH = 8 + MAX_DEPTH = 8 def __init__(self): diff --git a/nw/project/project.py b/nw/project/project.py index beed9984..fee396b1 100644 --- a/nw/project/project.py +++ b/nw/project/project.py @@ -272,77 +272,6 @@ class NWProject(): return self.projTree[aRoot].itemHandle return None - def getActionList(self, tHandle): - """Returns a dictionary of possible actions to perform on a give handle. - """ - validActions = {} - - # If we're at root, or didn't select an item, all we can add is root stuff - if tHandle is None: - validActions[nwItemAction.ADD_ROOT] = { - "Type" : nwItemType.ROOT, - "Class" : [x for x in nwItemClass if self.checkRootUnique(x)] - } - return validActions - - # Otherwise, the options depend on the item we had selected - tItem = self.getItem(tHandle) - tType = tItem.itemType - tClass = tItem.itemClass - tDepth = tItem.itemDepth - - # Trash items can only be moved or permanently deleted - if tType == nwItemType.TRASHFOLDER or tType == nwItemType.TRASHFILE: - validActions[nwItemAction.MOVE_TO] = {} - validActions[nwItemAction.DELETE] = {} - validActions[nwItemAction.EMPTY_TRASH] = {} - return validActions - - # Adding folders or files - # - Novels can only have folders under root - # - Files can only be 1 or 2 levels deep - # - Non-novel roots have only have a restriction on max depth - if tClass == nwItemClass.NOVEL: - if tType == nwItemType.ROOT: - validActions[nwItemAction.ADD_FOLDER] = { - "Type" : nwItemType.FOLDER, - "Class" : nwItemClass.NOVEL - } - if tDepth < 2: - validActions[nwItemAction.ADD_FILE] = { - "Type" : nwItemType.FILE, - "Class" : nwItemClass.NOVEL - } - if tType == nwItemType.FOLDER: - validActions[nwItemAction.MERGE] = {} - if tType == nwItemType.FILE: - validActions[nwItemAction.SPLIT] = {} - else: - if tDepth < NWItem.MAX_DEPTH-1 and ( - tType == nwItemType.ROOT or tType == nwItemType.FOLDER - ): - validActions[nwItemAction.ADD_FOLDER] = { - "Type" : nwItemType.FOLDER, - "Class" : tClass - } - if tDepth < NWItem.MAX_DEPTH: - validActions[nwItemAction.ADD_FILE] = { - "Type" : nwItemType.FILE, - "Class" : tClass - } - - # Other actions available to novel or plot items - validActions[nwItemAction.RENAME] = {} - validActions[nwItemAction.MOVE_UP] = {} - validActions[nwItemAction.MOVE_DOWN] = {} - if tType == nwItemType.ROOT: - validActions[nwItemAction.DELETE_ROOT] = {} - else: - validActions[nwItemAction.MOVE_TO] = {} - validActions[nwItemAction.MOVE_TRASH] = {} - - return validActions - def checkRootUnique(self, theClass): """Checks if there already is a root entry of class 'theClass' in the root of the project tree.