Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[pyqgis-console] fixes prompt save tab on closing
  • Loading branch information
slarosa committed Apr 16, 2013
1 parent 69dc6ac commit 09fe728
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
6 changes: 4 additions & 2 deletions python/console/console.py
Expand Up @@ -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))

Expand Down
45 changes: 28 additions & 17 deletions python/console/console_editor.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -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:
Expand Down

0 comments on commit 09fe728

Please sign in to comment.