Skip to content

Commit

Permalink
[processing] Improved script editor dialog title
Browse files Browse the repository at this point in the history
- show filename in title, or 'Untitled Script' for new
scripts
- show unsaved ('*') indicator when unsaved changes present
  • Loading branch information
nyalldawson committed May 21, 2018
1 parent 28b23d0 commit 8416384
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions python/plugins/processing/script/ScriptEditorDialog.py
Expand Up @@ -111,13 +111,27 @@ def __init__(self, filePath=None, parent=None):
self.btnReplace.clicked.connect(self.replace)
self.lastSearch = None

self.filePath = filePath
if self.filePath is not None:
self._loadFile(self.filePath)
self.filePath = None
if filePath is not None:
self._loadFile(filePath)

self.needUpdate = False
self.setHasChanged(False)

def update_dialog_title(self):
"""
Updates the script editor dialog title
"""
if self.filePath:
path, file_name = os.path.split(self.filePath)
else:
file_name = self.tr('Untitled Script')

if self.hasChanged:
file_name = '*' + file_name

self.setWindowTitle(self.tr('{} - Processing Script Editor').format(file_name))

def closeEvent(self, event):
settings = QgsSettings()
settings.setValue("/Processing/stateScriptEditor", self.saveState())
Expand Down Expand Up @@ -165,7 +179,6 @@ def openScript(self):

with OverrideCursor(Qt.WaitCursor):
self._loadFile(fileName)
self.filePath = fileName

def save(self):
self.saveScript(False)
Expand Down Expand Up @@ -205,6 +218,7 @@ def saveScript(self, saveAs):
def setHasChanged(self, hasChanged):
self.hasChanged = hasChanged
self.actionSaveScript.setEnabled(hasChanged)
self.update_dialog_title()

def runAlgorithm(self):
d = {}
Expand Down Expand Up @@ -275,3 +289,6 @@ def _loadFile(self, filePath):
self.hasChanged = False
self.editor.setModified(False)
self.editor.recolor()

self.filePath = filePath
self.update_dialog_title()

0 comments on commit 8416384

Please sign in to comment.