Skip to content

Commit

Permalink
[pyqgis-console] disables the save button if the document is not modi…
Browse files Browse the repository at this point in the history
…fied
  • Loading branch information
slarosa committed May 10, 2013
1 parent 839343b commit 09f5ee6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions python/console/console_editor.py
Expand Up @@ -687,6 +687,7 @@ def save(self):
self.tw.setTabTitle(self, fN)
self.tw.setTabToolTip(self.tw.currentIndex(), path)
self.newEditor.setModified(False)
self.pc.saveFileButton.setEnabled(False)
self.newEditor.mtime = os.stat(path).st_mtime
self.pc.updateTabListScript(path, action='append')
self.tw.listObject(self)
Expand Down Expand Up @@ -792,8 +793,7 @@ def __init__(self, parent):
self.fileTabButton.setMenu(self.fileTabMenu)
self.setCornerWidget(self.fileTabButton, Qt.TopRightCorner)
self.connect(self, SIGNAL("tabCloseRequested(int)"), self._removeTab)
self.connect(self, SIGNAL('currentChanged(int)'), self.listObject)
self.connect(self, SIGNAL('currentChanged(int)'), self.changeLastDirPath)
self.connect(self, SIGNAL('currentChanged(int)'), self._currentWidgetChanged)

# Open button
self.newTabButton = QToolButton()
Expand All @@ -806,6 +806,11 @@ def __init__(self, parent):
self.setCornerWidget(self.newTabButton, Qt.TopLeftCorner)
self.connect(self.newTabButton, SIGNAL('clicked()'), self.newTabEditor)

def _currentWidgetChanged(self, tab):
self.listObject(tab)
self.changeLastDirPath(tab)
self.enableSaveIfModified(tab)

def contextMenuEvent(self, e):
tabBar = self.tabBar()
self.idx = tabBar.tabAt(e.pos())
Expand All @@ -830,10 +835,13 @@ def contextMenuEvent(self, e):
closeTabAction.setEnabled(False)
closeAllTabAction.setEnabled(False)
closeOthersTabAction.setEnabled(False)
saveAction.setEnabled(False)
if self.count() > 1:
closeTabAction.setEnabled(True)
closeAllTabAction.setEnabled(True)
closeOthersTabAction.setEnabled(True)
if self.widget(self.idx).newEditor.isModified():
saveAction.setEnabled(True)
action = menu.exec_(self.mapToGlobal(e.pos()))

def closeOthers(self):
Expand All @@ -850,6 +858,9 @@ def closeAll(self):
self.newTabEditor(tabName='Untitled-0')
self._removeTab(0)

def enableSaveIfModified(self, tab):
self.parent.saveFileButton.setEnabled(self.widget(tab).newEditor.isModified())

def enableToolBarEditor(self, enable):
if self.topFrame.isVisible():
enable = False
Expand All @@ -872,11 +883,13 @@ def newTabEditor(self, tabName=None, filename=None):
self.setTabToolTip(self.currentIndex(), unicode(filename))
else:
self.setTabToolTip(self.currentIndex(), tabName)
self.parent.saveFileButton.setEnabled(False)

def tabModified(self, tab, modified):
index = self.indexOf(tab)
color = Qt.darkGray if modified else Qt.black
self.tabBar().setTabTextColor(index, color)
self.parent.saveFileButton.setEnabled(modified)

def closeTab(self, tab):
# Check if file has been saved
Expand Down

0 comments on commit 09f5ee6

Please sign in to comment.