Skip to content

Commit 09fe728

Browse files
committed
[pyqgis-console] fixes prompt save tab on closing
1 parent 69dc6ac commit 09fe728

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

python/console/console.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,13 @@ def callWidgetMessageBar(self, text):
432432
def callWidgetMessageBarEditor(self, text):
433433
self.tabEditorWidget.widgetMessageBar(iface, text)
434434

435-
def updateTabListScript(self, script):
435+
def updateTabListScript(self, script, action=None):
436436
if script == 'empty':
437437
self.tabListScript = []
438-
if script is not None and script != 'empty':
438+
if script is not None and not action and script != 'empty':
439439
self.tabListScript.remove(script)
440+
if action:
441+
self.tabListScript.append(script)
440442
self.settings.setValue("pythonConsole/tabScripts",
441443
QVariant(self.tabListScript))
442444

python/console/console_editor.py

+28-17
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ def save(self):
433433
return
434434
msgText = QCoreApplication.translate('PythonConsole',
435435
'Script was correctly saved.')
436+
self.pc.updateTabListScript(self.path, action='append')
436437
self.pc.callWidgetMessageBarEditor(msgText)
437438
# Rename the original file, if it exists
438439
overwrite = os.path.exists(self.path)
@@ -601,26 +602,36 @@ def closeTab(self, tab):
601602
else:
602603
self.removeTab(self.indexOf(tab))
603604
self.currentWidget().setFocus(Qt.TabFocusReason)
604-
605+
605606
def setTabTitle(self, tab, title):
606607
self.setTabText(self.indexOf(tab), title)
607-
608+
608609
def _removeTab(self, tab):
609-
if self.widget(tab).path in self.restoreTabList:
610-
#print currWidget.path
611-
self.parent.updateTabListScript(self.widget(tab).path)
612-
if self.count() <= 2:
613-
self.setTabsClosable(False)
614-
self.removeTab(tab)
610+
if self.widget(tab).newEditor.isModified():
611+
res = QMessageBox.question( self, 'Save Script',
612+
'The script "%s" has been modified, save changes ?'
613+
% self.tabText(tab),
614+
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel )
615+
if res == QMessageBox.Save:
616+
self.widget(tab).save()
617+
elif res == QMessageBox.Cancel:
618+
return
619+
else:
620+
self.parent.updateTabListScript(self.widget(tab).path)
621+
self.removeTab(tab)
615622
else:
616-
self.removeTab(tab)
617-
618-
self.currentWidget().setFocus(Qt.TabFocusReason)
619-
623+
if self.widget(tab).path in self.restoreTabList:
624+
self.parent.updateTabListScript(self.widget(tab).path)
625+
if self.count() <= 2:
626+
self.setTabsClosable(False)
627+
self.removeTab(tab)
628+
else:
629+
self.removeTab(tab)
630+
self.currentWidget().setFocus(Qt.TabFocusReason)
620631

621632
def buttonClosePressed(self):
622633
self.closeCurrentWidget()
623-
634+
624635
def closeCurrentWidget(self):
625636
currWidget = self.currentWidget()
626637
if currWidget and currWidget.close():
@@ -631,24 +642,24 @@ def closeCurrentWidget(self):
631642
if currWidget.path in self.restoreTabList:
632643
#print currWidget.path
633644
self.parent.updateTabListScript(currWidget.path)
634-
645+
635646
def restoreTabs(self):
636647
for script in self.restoreTabList:
637648
pathFile = str(script.toString())
638649
tabName = pathFile.split('/')[-1]
639650
self.newTabEditor(tabName, pathFile)
640651
self.topFrame.close()
641-
652+
642653
def closeRestore(self):
643654
self.parent.updateTabListScript('empty')
644655
self.topFrame.close()
645-
656+
646657
def showFileTabMenu(self):
647658
self.fileTabMenu.clear()
648659
for index in range(self.count()):
649660
action = self.fileTabMenu.addAction(self.tabIcon(index), self.tabText(index))
650661
action.setData(QVariant(index))
651-
662+
652663
def showFileTabMenuTriggered(self, action):
653664
index, ok = action.data().toInt()
654665
if ok:

0 commit comments

Comments
 (0)