Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[pyqgis-console] fix for save as in tabbar context menu
  • Loading branch information
slarosa committed May 22, 2013
1 parent 2a9e0ae commit 022ca43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion python/console/console.py
Expand Up @@ -640,8 +640,10 @@ def saveScriptFile(self):
.arg(unicode(tabWidget.path)).arg(error.strerror)
self.callWidgetMessageBarEditor(msgText, 2, False)

def saveAsScriptFile(self):
def saveAsScriptFile(self, index=None):
tabWidget = self.tabEditorWidget.currentWidget()
if index:
tabWidget = self.tabEditorWidget.widget(index)
index = self.tabEditorWidget.currentIndex()
if tabWidget is None:
return
Expand Down
15 changes: 10 additions & 5 deletions python/console/console_editor.py
Expand Up @@ -742,10 +742,10 @@ def loadFile(self, filename, modified):
self.newEditor.recolor()

def save(self, fileName=None):
index = self.tw.indexOf(self)
if fileName:
self.path = fileName
if self.path is None:
index = self.tw.currentIndex()
saveTr = QCoreApplication.translate('PythonConsole',
'Python Console: Save file')
self.path = str(QFileDialog().getSaveFileName(self,
Expand All @@ -756,6 +756,7 @@ def save(self, fileName=None):
if len(self.path) == 0:
self.path = None
return
self.tw.setCurrentWidget(self)
msgText = QCoreApplication.translate('PythonConsole',
'Script was correctly saved.')
self.pc.callWidgetMessageBarEditor(msgText, 0, True)
Expand All @@ -782,8 +783,8 @@ def save(self, fileName=None):
if self.newEditor.isReadOnly():
self.newEditor.setReadOnly(False)
fN = path.split('/')[-1]
self.tw.setTabTitle(self.tw.currentIndex(), fN)
self.tw.setTabToolTip(self.tw.currentIndex(), path)
self.tw.setTabTitle(index, fN)
self.tw.setTabToolTip(index, path)
self.newEditor.setModified(False)
self.pc.saveFileButton.setEnabled(False)
self.newEditor.lastModified = QFileInfo(path).lastModified()
Expand Down Expand Up @@ -931,7 +932,7 @@ def contextMenuEvent(self, e):
saveAction = menu.addAction("Save",
cW.save)
saveAsAction = menu.addAction("Save As",
self.parent.saveAsScriptFile)
self.saveAs)
closeTabAction.setEnabled(False)
closeAllTabAction.setEnabled(False)
closeOthersTabAction.setEnabled(False)
Expand All @@ -957,7 +958,11 @@ def closeAll(self):
self._removeTab(i)
self.newTabEditor(tabName='Untitled-0')
self._removeTab(0)


def saveAs(self):
idx = self.idx
self.parent.saveAsScriptFile(idx)

def enableSaveIfModified(self, tab):
tabWidget = self.widget(tab)
if tabWidget:
Expand Down

0 comments on commit 022ca43

Please sign in to comment.