Skip to content
Permalink
Browse files

[pyqgis-console] disables the save button if the document is not modi…

…fied
  • Loading branch information
slarosa committed May 10, 2013
1 parent 839343b commit 09f5ee62966603d97be345a1bcc59bbb1a371696
Showing with 15 additions and 2 deletions.
  1. +15 −2 python/console/console_editor.py
@@ -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)
@@ -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()
@@ -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())
@@ -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):
@@ -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
@@ -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

0 comments on commit 09f5ee6

Please sign in to comment.
You can’t perform that action at this time.