Skip to content

Commit

Permalink
Display * in tab title when document is modified and unsaved
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Oct 28, 2019
1 parent 4ce08ec commit a066115
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ReText/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ def printError(self):
print('Exception occurred while parsing document:', file=sys.stderr)
traceback.print_exc()

def updateTabTitle(self, ind, tab):
changed = tab.editBox.document().isModified()
if changed:
title = tab.getBaseName() + '*'
else:
title = tab.getBaseName()
self.tabWidget.setTabText(ind, title)

def tabFileNameChanged(self, tab):
'''
Expand All @@ -465,7 +472,7 @@ def tabFileNameChanged(self, tab):
if globalSettings.windowTitleFullPath:
self.setWindowTitle(tab.fileName + '[*]')
self.setWindowFilePath(tab.fileName)
self.tabWidget.setTabText(self.ind, tab.getBaseName())
self.updateTabTitle(self.ind, tab)
self.tabWidget.setTabToolTip(self.ind, tab.fileName)
QDir.setCurrent(QFileInfo(tab.fileName).dir().path())
else:
Expand Down Expand Up @@ -496,11 +503,13 @@ def tabModificationStateChanged(self, tab):
Perform all UI state changes that need to be done when the
modification state of the current tab has changed.
'''

if tab == self.currentTab:
changed = tab.editBox.document().isModified()
if self.autoSaveActive(tab):
changed = False
self.actionSave.setEnabled(changed)
self.updateTabTitle(self.ind, tab)
self.setWindowModified(changed)

def createTab(self, fileName):
Expand Down Expand Up @@ -870,10 +879,13 @@ def saveFileAs(self):
self.saveFile(dlg=True)

def saveAll(self):
ind = 0
for tab in self.iterateTabs():
if (tab.fileName and tab.editBox.document().isModified()
and QFileInfo(tab.fileName).isWritable()):
tab.saveTextToFile()
self.updateTabTitle(ind, tab)
ind += 1

def saveFile(self, dlg=False):
fileNameToSave = self.currentTab.fileName
Expand Down Expand Up @@ -912,6 +924,7 @@ def saveFile(self, dlg=False):
if fileNameToSave:
if self.currentTab.saveTextToFile(fileNameToSave):
self.moveToTopOfRecentFileList(self.currentTab.fileName)
self.updateTabTitle(self.ind, tab)
return True
else:
QMessageBox.warning(self, '',
Expand Down Expand Up @@ -1196,6 +1209,7 @@ def maybeSave(self, ind):
tab = self.tabWidget.widget(ind)
if self.autoSaveActive(tab):
tab.saveTextToFile()
self.updateTabTitle(ind, tab)
return True
if not tab.editBox.document().isModified():
return True
Expand Down

0 comments on commit a066115

Please sign in to comment.