Skip to content
Permalink
Browse files

[pyqgis-console] fixes prompt save tab on closing

  • Loading branch information
slarosa committed Apr 16, 2013
1 parent 69dc6ac commit 09fe7281042fb47de0b7b8f854acd95121e15c5e
Showing with 32 additions and 19 deletions.
  1. +4 −2 python/console/console.py
  2. +28 −17 python/console/console_editor.py
@@ -432,11 +432,13 @@ def callWidgetMessageBar(self, text):
def callWidgetMessageBarEditor(self, text):
self.tabEditorWidget.widgetMessageBar(iface, text)

def updateTabListScript(self, script):
def updateTabListScript(self, script, action=None):
if script == 'empty':
self.tabListScript = []
if script is not None and script != 'empty':
if script is not None and not action and script != 'empty':
self.tabListScript.remove(script)
if action:
self.tabListScript.append(script)
self.settings.setValue("pythonConsole/tabScripts",
QVariant(self.tabListScript))

@@ -433,6 +433,7 @@ def save(self):
return
msgText = QCoreApplication.translate('PythonConsole',
'Script was correctly saved.')
self.pc.updateTabListScript(self.path, action='append')
self.pc.callWidgetMessageBarEditor(msgText)
# Rename the original file, if it exists
overwrite = os.path.exists(self.path)
@@ -601,26 +602,36 @@ def closeTab(self, tab):
else:
self.removeTab(self.indexOf(tab))
self.currentWidget().setFocus(Qt.TabFocusReason)

def setTabTitle(self, tab, title):
self.setTabText(self.indexOf(tab), title)

def _removeTab(self, tab):
if self.widget(tab).path in self.restoreTabList:
#print currWidget.path
self.parent.updateTabListScript(self.widget(tab).path)
if self.count() <= 2:
self.setTabsClosable(False)
self.removeTab(tab)
if self.widget(tab).newEditor.isModified():
res = QMessageBox.question( self, 'Save Script',
'The script "%s" has been modified, save changes ?'
% self.tabText(tab),
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel )
if res == QMessageBox.Save:
self.widget(tab).save()
elif res == QMessageBox.Cancel:
return
else:
self.parent.updateTabListScript(self.widget(tab).path)
self.removeTab(tab)
else:
self.removeTab(tab)

self.currentWidget().setFocus(Qt.TabFocusReason)

if self.widget(tab).path in self.restoreTabList:
self.parent.updateTabListScript(self.widget(tab).path)
if self.count() <= 2:
self.setTabsClosable(False)
self.removeTab(tab)
else:
self.removeTab(tab)
self.currentWidget().setFocus(Qt.TabFocusReason)

def buttonClosePressed(self):
self.closeCurrentWidget()

def closeCurrentWidget(self):
currWidget = self.currentWidget()
if currWidget and currWidget.close():
@@ -631,24 +642,24 @@ def closeCurrentWidget(self):
if currWidget.path in self.restoreTabList:
#print currWidget.path
self.parent.updateTabListScript(currWidget.path)

def restoreTabs(self):
for script in self.restoreTabList:
pathFile = str(script.toString())
tabName = pathFile.split('/')[-1]
self.newTabEditor(tabName, pathFile)
self.topFrame.close()

def closeRestore(self):
self.parent.updateTabListScript('empty')
self.topFrame.close()

def showFileTabMenu(self):
self.fileTabMenu.clear()
for index in range(self.count()):
action = self.fileTabMenu.addAction(self.tabIcon(index), self.tabText(index))
action.setData(QVariant(index))

def showFileTabMenuTriggered(self, action):
index, ok = action.data().toInt()
if ok:

0 comments on commit 09fe728

Please sign in to comment.
You can’t perform that action at this time.