EditorSession now provides menus, so it can toggle menuAction.enabled as needed
This commit is contained in:
parent
4c5b81847e
commit
767a966bba
@ -100,6 +100,7 @@ class MCEditApp(QtGui.QApplication):
|
||||
|
||||
# --- Sessions
|
||||
|
||||
self._currentSession = None
|
||||
self.sessions = []
|
||||
self.sessionDockWidgets = []
|
||||
self.sessionChanged.connect(self.sessionDidChange)
|
||||
@ -193,31 +194,6 @@ class MCEditApp(QtGui.QApplication):
|
||||
mainWindow.actionExit_MCEdit.triggered.connect(self.exitEditor)
|
||||
mainWindow.actionExit_MCEdit.setShortcut(QtGui.QKeySequence.Quit)
|
||||
|
||||
# -- Edit menu --
|
||||
mainWindow.actionUndo.triggered.connect(self.undo)
|
||||
mainWindow.actionUndo.setShortcut(QtGui.QKeySequence.Undo)
|
||||
|
||||
mainWindow.actionRedo.triggered.connect(self.redo)
|
||||
mainWindow.actionRedo.setShortcut(QtGui.QKeySequence.Redo)
|
||||
|
||||
mainWindow.actionCut.triggered.connect(self.cut)
|
||||
mainWindow.actionCut.setShortcut(QtGui.QKeySequence.Cut)
|
||||
|
||||
mainWindow.actionCopy.triggered.connect(self.copy)
|
||||
mainWindow.actionCopy.setShortcut(QtGui.QKeySequence.Copy)
|
||||
|
||||
mainWindow.actionPaste.triggered.connect(self.paste)
|
||||
mainWindow.actionPaste.setShortcut(QtGui.QKeySequence.Paste)
|
||||
|
||||
mainWindow.actionPaste_Blocks.triggered.connect(self.pasteBlocks)
|
||||
mainWindow.actionPaste_Blocks.setShortcut(QtGui.QKeySequence("Ctrl+Shift+V"))
|
||||
|
||||
mainWindow.actionPaste_Entities.triggered.connect(self.pasteEntities)
|
||||
mainWindow.actionPaste_Entities.setShortcut(QtGui.QKeySequence("Ctrl+Alt+V"))
|
||||
|
||||
mainWindow.actionClear.triggered.connect(self.clear)
|
||||
mainWindow.actionClear.setShortcut(QtGui.QKeySequence.Quit)
|
||||
|
||||
# -- Help menu --
|
||||
mainWindow.actionAbout_MCEdit.triggered.connect(self.showAbout)
|
||||
mainWindow.actionAbout_MCEdit.setShortcut(QtGui.QKeySequence.Quit)
|
||||
@ -319,10 +295,6 @@ class MCEditApp(QtGui.QApplication):
|
||||
except EnvironmentError as e:
|
||||
log.info("%r", e)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def updateStatusLabel(self, pos=None, blocktype=None, cps=None, fps=None):
|
||||
if pos is not None:
|
||||
self.positionLabel.setText("%s" % (tuple(pos),))
|
||||
@ -353,12 +325,21 @@ class MCEditApp(QtGui.QApplication):
|
||||
log.debug("Loading timer idle (no chunks)")
|
||||
self.loadTimer.setInterval(self.idleTime)
|
||||
|
||||
def sessionDidChange(self, session):
|
||||
def sessionDidChange(self, session, previousSession):
|
||||
"""
|
||||
:type session: EditorSession
|
||||
"""
|
||||
view = session.editorTab.currentView()
|
||||
|
||||
menuBar = self.mainWindow.menuBar()
|
||||
if previousSession:
|
||||
for menu in previousSession.menus:
|
||||
menuBar.removeAction(menu.menuAction())
|
||||
log.info("Adding session menus: %s", session.menus)
|
||||
for menu in session.menus:
|
||||
menuBar.insertMenu(self.mainWindow.menuWindow.menuAction(), menu)
|
||||
|
||||
|
||||
self.mainWindow.toolsToolBar.clear()
|
||||
for action in session.toolActions:
|
||||
self.mainWindow.toolsToolBar.addAction(action)
|
||||
@ -484,14 +465,15 @@ class MCEditApp(QtGui.QApplication):
|
||||
if self.tabWidget.count() == 0:
|
||||
self.showWorldList()
|
||||
|
||||
sessionChanged = QtCore.Signal(EditorSession)
|
||||
sessionChanged = QtCore.Signal(EditorSession, EditorSession)
|
||||
|
||||
def tabChanged(self):
|
||||
session = self.currentSession()
|
||||
if session:
|
||||
if hasattr(session, 'undoStack'):
|
||||
self.undoGroup.setActiveStack(session.undoStack)
|
||||
self.sessionChanged.emit(session)
|
||||
self.sessionChanged.emit(session, self._currentSession)
|
||||
self._currentSession = session
|
||||
|
||||
def currentTab(self):
|
||||
"""
|
||||
@ -604,35 +586,6 @@ class MCEditApp(QtGui.QApplication):
|
||||
self.mainWindow.saveSettings()
|
||||
raise SystemExit
|
||||
|
||||
# --- Edit Menu Actions ---
|
||||
|
||||
def undo(self):
|
||||
self.currentSession().undo()
|
||||
|
||||
def redo(self):
|
||||
self.currentSession().redo()
|
||||
|
||||
def cut(self):
|
||||
self.currentSession().cut()
|
||||
|
||||
def copy(self):
|
||||
self.currentSession().copy()
|
||||
|
||||
def paste(self):
|
||||
self.currentSession().paste()
|
||||
|
||||
def pasteBlocks(self):
|
||||
self.currentSession().pasteBlocks()
|
||||
|
||||
def pasteEntities(self):
|
||||
self.currentSession().pasteEntities()
|
||||
|
||||
def clear(self):
|
||||
self.currentSession().clear()
|
||||
|
||||
|
||||
|
||||
|
||||
# --- Help Menu Actions ---
|
||||
|
||||
def showAbout(self):
|
||||
|
@ -78,6 +78,49 @@ class EditorSession(QtCore.QObject):
|
||||
self.loader.chunkCompleted.connect(self.chunkDidComplete)
|
||||
self.loader.allChunksDone.connect(lambda: self.editorTab.currentView().update())
|
||||
|
||||
# --- Menus ---
|
||||
|
||||
self.menus = []
|
||||
|
||||
self.menuEdit = QtGui.QMenu(self.tr("Edit"))
|
||||
self.menuEdit.setObjectName("menuEdit")
|
||||
self.actionUndo = QtGui.QAction(self.tr("Undo"), self, triggered=self.undo, enabled=False)
|
||||
self.actionUndo.setObjectName("actionUndo")
|
||||
self.actionRedo = QtGui.QAction(self.tr("Redo"), self, triggered=self.redo, enabled=False)
|
||||
self.actionRedo.setObjectName("actionRedo")
|
||||
self.actionCut = QtGui.QAction(self.tr("Cut"), self, triggered=self.cut, enabled=False)
|
||||
self.actionCut.setObjectName("actionCut")
|
||||
self.actionCopy = QtGui.QAction(self.tr("Copy"), self, triggered=self.copy, enabled=False)
|
||||
self.actionCopy.setObjectName("actionCopy")
|
||||
self.actionPaste = QtGui.QAction(self.tr("Paste"), self, triggered=self.paste, enabled=False)
|
||||
self.actionPaste.setObjectName("actionPaste")
|
||||
self.actionPaste_Blocks = QtGui.QAction(self.tr("Paste Blocks"), self, triggered=self.pasteBlocks, enabled=False)
|
||||
self.actionPaste_Blocks.setObjectName("actionPaste_Blocks")
|
||||
self.actionPaste_Entities = QtGui.QAction(self.tr("Paste Entities"), self, triggered=self.pasteEntities, enabled=False)
|
||||
self.actionPaste_Entities.setObjectName("actionPaste_Entities")
|
||||
self.actionClear = QtGui.QAction(self.tr("Clear"), self, triggered=self.clear, enabled=False)
|
||||
self.actionClear.setObjectName("actionClear")
|
||||
self.menuEdit.addAction(self.actionUndo)
|
||||
self.menuEdit.addAction(self.actionRedo)
|
||||
self.menuEdit.addSeparator()
|
||||
self.menuEdit.addAction(self.actionCut)
|
||||
self.menuEdit.addAction(self.actionCopy)
|
||||
self.menuEdit.addAction(self.actionPaste)
|
||||
self.menuEdit.addAction(self.actionPaste_Blocks)
|
||||
self.menuEdit.addAction(self.actionPaste_Entities)
|
||||
self.menuEdit.addAction(self.actionClear)
|
||||
|
||||
self.actionUndo.setShortcut(QtGui.QKeySequence.Undo)
|
||||
self.actionRedo.setShortcut(QtGui.QKeySequence.Redo)
|
||||
self.actionCut.setShortcut(QtGui.QKeySequence.Cut)
|
||||
self.actionCopy.setShortcut(QtGui.QKeySequence.Copy)
|
||||
self.actionPaste.setShortcut(QtGui.QKeySequence.Paste)
|
||||
self.actionPaste_Blocks.setShortcut(QtGui.QKeySequence("Ctrl+Shift+V"))
|
||||
self.actionPaste_Entities.setShortcut(QtGui.QKeySequence("Ctrl+Alt+V"))
|
||||
self.actionClear.setShortcut(QtGui.QKeySequence.Quit)
|
||||
|
||||
self.menus.append(self.menuEdit)
|
||||
|
||||
# --- Resources ---
|
||||
|
||||
i, v, p = self.versionInfo
|
||||
@ -197,6 +240,9 @@ class EditorSession(QtCore.QObject):
|
||||
def pasteEntities(self):
|
||||
NotImplementedYet()
|
||||
|
||||
def clear(self):
|
||||
self.selectionTool.deleteSelection()
|
||||
|
||||
# --- Undo support ---
|
||||
|
||||
def pushCommand(self, command):
|
||||
@ -362,6 +408,7 @@ class EditorSession(QtCore.QObject):
|
||||
self.worldEditor = None
|
||||
return True
|
||||
|
||||
|
||||
class EditorTab(QtGui.QWidget):
|
||||
"""
|
||||
EditorTab is the widget containing the editor viewports, the minimap, and
|
||||
@ -433,10 +480,6 @@ class EditorTab(QtGui.QWidget):
|
||||
self.cameraViewFrame = CameraWorldViewFrame(editorSession.currentDimension, editorSession.textureAtlas, editorSession.geometryCache, self.miniMap)
|
||||
self.cameraViewFrame.worldView.viewID = "Cam"
|
||||
self._addView(self.cameraViewFrame)
|
||||
#
|
||||
# self.isoViewFrame = IsoWorldViewFrame(editorSession.currentDimension, editorSession.textureAtlas, editorSession.geometryCache, self.miniMap)
|
||||
# self.isoViewFrame.worldView.viewID = "Iso"
|
||||
# self._addView(self.isoViewFrame)
|
||||
|
||||
self.viewStack.currentChanged.connect(self._viewChanged)
|
||||
self.viewChanged.connect(self.viewDidChange)
|
||||
|
@ -53,20 +53,6 @@
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit_MCEdit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuEdit">
|
||||
<property name="title">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<addaction name="actionUndo"/>
|
||||
<addaction name="actionRedo"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionCut"/>
|
||||
<addaction name="actionCopy"/>
|
||||
<addaction name="actionPaste"/>
|
||||
<addaction name="actionPaste_Blocks"/>
|
||||
<addaction name="actionPaste_Entities"/>
|
||||
<addaction name="actionClear"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuHelp">
|
||||
<property name="title">
|
||||
<string>Help</string>
|
||||
@ -79,7 +65,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="menuMCEdit"/>
|
||||
<addaction name="menuEdit"/>
|
||||
<addaction name="menuWindow"/>
|
||||
<addaction name="menuHelp"/>
|
||||
</widget>
|
||||
@ -144,46 +129,6 @@
|
||||
<string>Exit MCEdit</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionUndo">
|
||||
<property name="text">
|
||||
<string>Undo</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRedo">
|
||||
<property name="text">
|
||||
<string>Redo</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCut">
|
||||
<property name="text">
|
||||
<string>Cut</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCopy">
|
||||
<property name="text">
|
||||
<string>Copy</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPaste">
|
||||
<property name="text">
|
||||
<string>Paste</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPaste_Blocks">
|
||||
<property name="text">
|
||||
<string>Paste Blocks</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPaste_Entities">
|
||||
<property name="text">
|
||||
<string>Paste Entities</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClear">
|
||||
<property name="text">
|
||||
<string>Clear</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout_MCEdit">
|
||||
<property name="text">
|
||||
<string>About MCEdit 2...</string>
|
||||
|
Reference in New Issue
Block a user