Skip to content

Commit

Permalink
Fix Editor/EditorTab never deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ authored and nyalldawson committed Feb 21, 2023
1 parent 7f23109 commit 28146b5
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions python/console/console_editor.py
Expand Up @@ -698,10 +698,10 @@ def newTabEditor(self, tabName=None, filename=None):
nr = self.count()
if not tabName:
tabName = QCoreApplication.translate('PythonConsole', 'Untitled-{0}').format(nr)
self.tab = EditorTab(self, self.parent, filename, readOnly)
tab = EditorTab(self, self.parent, filename, readOnly)
self.iconTab = QgsApplication.getThemeIcon('console/iconTabEditorConsole.svg')
self.addTab(self.tab, self.iconTab, tabName + ' (ro)' if readOnly else tabName)
self.setCurrentWidget(self.tab)
self.addTab(tab, self.iconTab, tabName + ' (ro)' if readOnly else tabName)
self.setCurrentWidget(tab)
if filename:
self.setTabToolTip(self.currentIndex(), filename)
else:
Expand All @@ -713,14 +713,6 @@ def tabModified(self, tab, modified):
self.setTabTitle(index, '*{}'.format(s) if modified else re.sub(r'^(\*)', '', s))
self.parent.saveFileButton.setEnabled(modified)

def closeTab(self, tab):
if self.count() < 2:
self.removeTab(self.indexOf(tab))
self.newTabEditor()
else:
self.removeTab(self.indexOf(tab))
self.currentWidget().setFocus(Qt.TabFocusReason)

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

Expand All @@ -736,10 +728,10 @@ def _removeTab(self, tab, tab2index=False):
res = QMessageBox.question(self, txtSaveOnRemove,
txtMsgSaveOnRemove,
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
if res == QMessageBox.Cancel:
return
if res == QMessageBox.Save:
tabWidget.save()
elif res == QMessageBox.Cancel:
return
if tabWidget.path:
self.parent.updateTabListScript(tabWidget.path, action='remove')
self.removeTab(tab)
Expand All @@ -753,6 +745,8 @@ def _removeTab(self, tab, tab2index=False):
self.newTabEditor()
else:
self.removeTab(tab)

tabWidget.deleteLater()
self.currentWidget().newEditor.setFocus(Qt.TabFocusReason)

def buttonClosePressed(self):
Expand Down

0 comments on commit 28146b5

Please sign in to comment.