Skip to content

Commit 09f5ee6

Browse files
committedMay 10, 2013
[pyqgis-console] disables the save button if the document is not modified
1 parent 839343b commit 09f5ee6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
 

‎python/console/console_editor.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ def save(self):
687687
self.tw.setTabTitle(self, fN)
688688
self.tw.setTabToolTip(self.tw.currentIndex(), path)
689689
self.newEditor.setModified(False)
690+
self.pc.saveFileButton.setEnabled(False)
690691
self.newEditor.mtime = os.stat(path).st_mtime
691692
self.pc.updateTabListScript(path, action='append')
692693
self.tw.listObject(self)
@@ -792,8 +793,7 @@ def __init__(self, parent):
792793
self.fileTabButton.setMenu(self.fileTabMenu)
793794
self.setCornerWidget(self.fileTabButton, Qt.TopRightCorner)
794795
self.connect(self, SIGNAL("tabCloseRequested(int)"), self._removeTab)
795-
self.connect(self, SIGNAL('currentChanged(int)'), self.listObject)
796-
self.connect(self, SIGNAL('currentChanged(int)'), self.changeLastDirPath)
796+
self.connect(self, SIGNAL('currentChanged(int)'), self._currentWidgetChanged)
797797

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

809+
def _currentWidgetChanged(self, tab):
810+
self.listObject(tab)
811+
self.changeLastDirPath(tab)
812+
self.enableSaveIfModified(tab)
813+
809814
def contextMenuEvent(self, e):
810815
tabBar = self.tabBar()
811816
self.idx = tabBar.tabAt(e.pos())
@@ -830,10 +835,13 @@ def contextMenuEvent(self, e):
830835
closeTabAction.setEnabled(False)
831836
closeAllTabAction.setEnabled(False)
832837
closeOthersTabAction.setEnabled(False)
838+
saveAction.setEnabled(False)
833839
if self.count() > 1:
834840
closeTabAction.setEnabled(True)
835841
closeAllTabAction.setEnabled(True)
836842
closeOthersTabAction.setEnabled(True)
843+
if self.widget(self.idx).newEditor.isModified():
844+
saveAction.setEnabled(True)
837845
action = menu.exec_(self.mapToGlobal(e.pos()))
838846

839847
def closeOthers(self):
@@ -850,6 +858,9 @@ def closeAll(self):
850858
self.newTabEditor(tabName='Untitled-0')
851859
self._removeTab(0)
852860

861+
def enableSaveIfModified(self, tab):
862+
self.parent.saveFileButton.setEnabled(self.widget(tab).newEditor.isModified())
863+
853864
def enableToolBarEditor(self, enable):
854865
if self.topFrame.isVisible():
855866
enable = False
@@ -872,11 +883,13 @@ def newTabEditor(self, tabName=None, filename=None):
872883
self.setTabToolTip(self.currentIndex(), unicode(filename))
873884
else:
874885
self.setTabToolTip(self.currentIndex(), tabName)
886+
self.parent.saveFileButton.setEnabled(False)
875887

876888
def tabModified(self, tab, modified):
877889
index = self.indexOf(tab)
878890
color = Qt.darkGray if modified else Qt.black
879891
self.tabBar().setTabTextColor(index, color)
892+
self.parent.saveFileButton.setEnabled(modified)
880893

881894
def closeTab(self, tab):
882895
# Check if file has been saved

0 commit comments

Comments
 (0)
Please sign in to comment.