Move several selection-related commands from SelectionTool's options panel to the Select menu in EditorSession
This commit is contained in:
parent
5bacc8bf4a
commit
402bdb508a
@ -8,6 +8,7 @@ from PySide.QtCore import Qt
|
||||
from mcedit2 import editortools
|
||||
from mcedit2.command import SimpleRevisionCommand
|
||||
from mcedit2.rendering.blockmodels import BlockModels
|
||||
from mcedit2.editorcommands.fill import fillCommand
|
||||
from mcedit2.editorcommands.find_replace import FindReplaceDialog
|
||||
from mcedit2.editortools.select import SelectCommand
|
||||
from mcedit2.panels.player import PlayerPanel
|
||||
@ -29,6 +30,8 @@ from mcedit2.worldview.cutaway import CutawayWorldViewFrame
|
||||
from mcedit2.worldview.minimap import MinimapWorldView
|
||||
from mcedit2.worldview.overhead import OverheadWorldViewFrame
|
||||
from mceditlib.geometry import Vector
|
||||
from mceditlib.operations import ComposeOperations
|
||||
from mceditlib.operations.entity import RemoveEntitiesOperation
|
||||
from mceditlib.selection import BoundingBox
|
||||
from mceditlib.exceptions import PlayerNotFound
|
||||
from mceditlib.revisionhistory import UndoFolderExists
|
||||
@ -142,10 +145,22 @@ class EditorSession(QtCore.QObject):
|
||||
self.actionPaste_Entities.setShortcut(QtGui.QKeySequence("Ctrl+Alt+V"))
|
||||
self.actionPaste_Entities.setObjectName("actionPaste_Entities")
|
||||
|
||||
self.actionClear = QtGui.QAction(self.tr("Clear"), self, triggered=self.clear, enabled=False)
|
||||
self.actionClear = QtGui.QAction(self.tr("Delete"), self, triggered=self.deleteSelection, enabled=False)
|
||||
self.actionClear.setShortcut(QtGui.QKeySequence.Delete)
|
||||
self.actionClear.setObjectName("actionClear")
|
||||
|
||||
self.actionDeleteBlocks = QtGui.QAction(self.tr("Delete Blocks"), self, triggered=self.deleteBlocks, enabled=False)
|
||||
self.actionDeleteBlocks.setShortcut(QtGui.QKeySequence("Shift+Del"))
|
||||
self.actionDeleteBlocks.setObjectName("actionDeleteBlocks")
|
||||
|
||||
self.actionDeleteEntities = QtGui.QAction(self.tr("Delete Entities"), self, triggered=self.deleteEntities, enabled=False)
|
||||
self.actionDeleteEntities.setShortcut(QtGui.QKeySequence("Shift+Alt+Del"))
|
||||
self.actionDeleteEntities.setObjectName("actionDeleteEntities")
|
||||
|
||||
self.actionFill = QtGui.QAction(self.tr("Fill"), self, triggered=self.fill, enabled=False)
|
||||
self.actionFill.setShortcut(QtGui.QKeySequence("Shift+Ctrl+F"))
|
||||
self.actionFill.setObjectName("actionFill")
|
||||
|
||||
self.actionFindReplace = QtGui.QAction(self.tr("Find/Replace"), self, triggered=self.findReplace, enabled=True)
|
||||
self.actionFindReplace.setShortcut(QtGui.QKeySequence.Find)
|
||||
self.actionFindReplace.setObjectName("actionFindReplace")
|
||||
@ -163,7 +178,12 @@ class EditorSession(QtCore.QObject):
|
||||
self.menuEdit.addAction(self.actionPaste)
|
||||
self.menuEdit.addAction(self.actionPaste_Blocks)
|
||||
self.menuEdit.addAction(self.actionPaste_Entities)
|
||||
self.menuEdit.addSeparator()
|
||||
self.menuEdit.addAction(self.actionClear)
|
||||
self.menuEdit.addAction(self.actionDeleteBlocks)
|
||||
self.menuEdit.addAction(self.actionDeleteEntities)
|
||||
self.menuEdit.addSeparator()
|
||||
self.menuEdit.addAction(self.actionFill)
|
||||
self.menuEdit.addSeparator()
|
||||
self.menuEdit.addAction(self.actionFindReplace)
|
||||
|
||||
@ -175,6 +195,10 @@ class EditorSession(QtCore.QObject):
|
||||
self.actionSelectAll.setShortcut(QtGui.QKeySequence.SelectAll)
|
||||
self.menuSelect.addAction(self.actionSelectAll)
|
||||
|
||||
self.actionDeselect = QtGui.QAction(self.tr("Deselect"), self, triggered=self.deselect)
|
||||
self.actionDeselect.setShortcut(QtGui.QKeySequence("Ctrl+D"))
|
||||
self.menuSelect.addAction(self.actionDeselect)
|
||||
|
||||
self.menus.append(self.menuSelect)
|
||||
|
||||
# --- Resources ---
|
||||
@ -260,6 +284,9 @@ class EditorSession(QtCore.QObject):
|
||||
self.actionPaste_Blocks.setEnabled(enable)
|
||||
self.actionPaste_Entities.setEnabled(enable)
|
||||
self.actionClear.setEnabled(enable)
|
||||
self.actionDeleteBlocks.setEnabled(enable)
|
||||
self.actionDeleteEntities.setEnabled(enable)
|
||||
self.actionFill.setEnabled(enable)
|
||||
|
||||
# --- Menu commands ---
|
||||
|
||||
@ -299,17 +326,45 @@ class EditorSession(QtCore.QObject):
|
||||
def pasteEntities(self):
|
||||
NotImplementedYet()
|
||||
|
||||
def clear(self):
|
||||
self.selectionTool.deleteSelection()
|
||||
|
||||
def findReplace(self):
|
||||
dialog = FindReplaceDialog(self)
|
||||
dialog.exec_()
|
||||
|
||||
def deleteSelection(self):
|
||||
command = SimpleRevisionCommand(self, "Delete")
|
||||
with command.begin():
|
||||
fillTask = self.currentDimension.fillBlocksIter(self.currentSelection, "air")
|
||||
entitiesTask = RemoveEntitiesOperation(self.currentDimension, self.currentSelection)
|
||||
task = ComposeOperations(fillTask, entitiesTask)
|
||||
showProgress("Deleting...", task)
|
||||
self.pushCommand(command)
|
||||
|
||||
def deleteBlocks(self):
|
||||
command = SimpleRevisionCommand(self, "Delete Blocks")
|
||||
with command.begin():
|
||||
fillTask = self.currentDimension.fillBlocksIter(self.currentSelection, "air")
|
||||
showProgress("Deleting...", fillTask)
|
||||
self.pushCommand(command)
|
||||
|
||||
def deleteEntities(self):
|
||||
command = SimpleRevisionCommand(self, "Delete Entities")
|
||||
with command.begin():
|
||||
entitiesTask = RemoveEntitiesOperation(self.currentDimension, self.currentSelection)
|
||||
showProgress("Deleting...", entitiesTask)
|
||||
self.pushCommand(command)
|
||||
|
||||
def fill(self):
|
||||
fillCommand(self)
|
||||
|
||||
# - Select -
|
||||
|
||||
def selectAll(self):
|
||||
command = SelectCommand(self.selectionTool, self.currentDimension.bounds, self.tr("Select All"))
|
||||
command = SelectCommand(self, self.currentDimension.bounds, self.tr("Select All"))
|
||||
self.pushCommand(command)
|
||||
|
||||
def deselect(self):
|
||||
command = SelectCommand(self, None)
|
||||
command.setText(self.tr("Deselect"))
|
||||
self.pushCommand(command)
|
||||
|
||||
# --- Library support ---
|
||||
|
@ -7,8 +7,6 @@ import logging
|
||||
from OpenGL import GL
|
||||
from PySide import QtGui, QtCore
|
||||
|
||||
from mcedit2.command import SimpleRevisionCommand
|
||||
from mcedit2.editorcommands.fill import fillCommand
|
||||
from mcedit2.editortools import EditorTool
|
||||
from mcedit2.handles.boxhandle import BoxHandle
|
||||
from mcedit2.rendering import cubes
|
||||
@ -17,15 +15,12 @@ from mcedit2.util.load_ui import load_ui
|
||||
from mcedit2.util.glutils import gl
|
||||
from mcedit2.rendering.depths import DepthOffset
|
||||
from mcedit2.rendering import scenegraph, rendergraph
|
||||
from mcedit2.util.showprogress import showProgress
|
||||
from mcedit2.widgets import shapewidget
|
||||
from mcedit2.widgets.layout import Column
|
||||
from mcedit2.widgets.shapewidget import ShapeWidget
|
||||
from mceditlib import faces
|
||||
from mceditlib.geometry import Vector
|
||||
from mceditlib.selection import BoundingBox
|
||||
from mceditlib.operations import ComposeOperations
|
||||
from mceditlib.operations.entity import RemoveEntitiesOperation
|
||||
from mceditlib import selection
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -148,21 +143,21 @@ class SelectionCoordinateWidget(QtGui.QWidget):
|
||||
|
||||
|
||||
class SelectCommand(QtGui.QUndoCommand):
|
||||
def __init__(self, selectionTool, box, text=None, *args, **kwargs):
|
||||
def __init__(self, editorSession, box, text=None, *args, **kwargs):
|
||||
QtGui.QUndoCommand.__init__(self, *args, **kwargs)
|
||||
if text is None:
|
||||
text = QtGui.qApp.tr("Box Selection")
|
||||
self.setText(text)
|
||||
self.box = box
|
||||
self.selectionTool = selectionTool
|
||||
self.editorSession = editorSession
|
||||
self.previousBox = None
|
||||
|
||||
def undo(self):
|
||||
self.selectionTool.currentSelection = self.previousBox
|
||||
self.editorSession.currentSelection = self.previousBox
|
||||
|
||||
def redo(self):
|
||||
self.previousBox = self.selectionTool.currentSelection
|
||||
self.selectionTool.currentSelection = self.box
|
||||
self.previousBox = self.editorSession.currentSelection
|
||||
self.editorSession.currentSelection = self.box
|
||||
|
||||
class SelectionTool(EditorTool):
|
||||
name = "Select"
|
||||
@ -183,23 +178,8 @@ class SelectionTool(EditorTool):
|
||||
self.coordInput.boxChanged.connect(self.coordInputChanged)
|
||||
self.shapeInput = ShapeWidget()
|
||||
self.shapeInput.shapeChanged.connect(self.shapeDidChange)
|
||||
self.deselectButton = QtGui.QPushButton(self.tr("Deselect"))
|
||||
self.deselectButton.clicked.connect(self.deselect)
|
||||
self.deleteSelectionButton = QtGui.QPushButton(self.tr("Delete"))
|
||||
self.deleteSelectionButton.clicked.connect(self.deleteSelection)
|
||||
self.deleteBlocksButton = QtGui.QPushButton(self.tr("Delete Blocks"))
|
||||
self.deleteBlocksButton.clicked.connect(self.deleteBlocks)
|
||||
self.deleteEntitiesButton = QtGui.QPushButton(self.tr("Delete Entities"))
|
||||
self.deleteEntitiesButton.clicked.connect(self.deleteEntities)
|
||||
self.fillButton = QtGui.QPushButton(self.tr("Fill"))
|
||||
self.fillButton.clicked.connect(self.fill)
|
||||
self.toolWidget.setLayout(Column(self.coordInput,
|
||||
self.shapeInput,
|
||||
self.deselectButton,
|
||||
self.deleteSelectionButton,
|
||||
self.deleteBlocksButton,
|
||||
self.deleteEntitiesButton,
|
||||
self.fillButton,
|
||||
None))
|
||||
|
||||
self.cursorNode = SelectionCursor()
|
||||
@ -244,8 +224,6 @@ class SelectionTool(EditorTool):
|
||||
def currentSelection(self, value):
|
||||
self.editorSession.currentSelection = value
|
||||
|
||||
self.boxHandleNode.bounds = None if value is None else BoundingBox(value.origin, value.size)
|
||||
|
||||
def coordInputChanged(self, box):
|
||||
self.currentSelection = self.createShapedSelection(box)
|
||||
|
||||
@ -256,30 +234,14 @@ class SelectionTool(EditorTool):
|
||||
def updateNodes(self):
|
||||
box = self.currentSelection
|
||||
if box:
|
||||
self.boxHandleNode.bounds = BoundingBox(box.origin, box.size)
|
||||
self.selectionNode.visible = True
|
||||
self.selectionNode.selection = box
|
||||
else:
|
||||
self.boxHandleNode.bounds = None
|
||||
self.selectionNode.visible = False
|
||||
self.faceHoverNode.visible = False
|
||||
|
||||
def deleteSelection(self):
|
||||
command = SimpleRevisionCommand(self.editorSession, "Delete")
|
||||
with command.begin():
|
||||
fillTask = self.editorSession.currentDimension.fillBlocksIter(self.editorSession.currentSelection, "air")
|
||||
entitiesTask = RemoveEntitiesOperation(self.editorSession.currentDimension, self.editorSession.currentSelection)
|
||||
task = ComposeOperations(fillTask, entitiesTask)
|
||||
showProgress("Deleting...", task)
|
||||
self.editorSession.pushCommand(command)
|
||||
|
||||
def deleteBlocks(self):
|
||||
pass
|
||||
|
||||
def deleteEntities(self):
|
||||
pass
|
||||
|
||||
def fill(self):
|
||||
fillCommand(self.editorSession)
|
||||
|
||||
def boxHandleResized(self, box):
|
||||
if box is not None:
|
||||
self.selectionNode.selection = self.createShapedSelection(box)
|
||||
@ -287,7 +249,7 @@ class SelectionTool(EditorTool):
|
||||
def boxHandleResizedDone(self, box, newSelection):
|
||||
if box is not None:
|
||||
selection = self.createShapedSelection(box)
|
||||
command = SelectCommand(self, selection)
|
||||
command = SelectCommand(self.editorSession, selection)
|
||||
if not newSelection:
|
||||
command.setText(self.tr("Resize Selection"))
|
||||
self.editorSession.undoStack.push(command)
|
||||
@ -310,12 +272,6 @@ class SelectionTool(EditorTool):
|
||||
self.boxHandleNode.mouseRelease(event)
|
||||
|
||||
|
||||
def deselect(self):
|
||||
editor = self.editorSession
|
||||
command = SelectCommand(self, None)
|
||||
command.setText(self.tr("Deselect"))
|
||||
editor.undoStack.push(command)
|
||||
|
||||
selectionColor = (0.8, 0.8, 1.0)
|
||||
alpha = 0.33
|
||||
|
||||
|
Reference in New Issue
Block a user