Mercurial > hg > octave-nkf
changeset 13649:0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
author | ttl <ttl@justmail.de> |
---|---|
date | Tue, 23 Aug 2011 21:37:27 +0200 |
parents | da69cec2459f |
children | b93bfa9486ad |
files | gui/src/FileEditorMdiSubWindow.cpp gui/src/FileEditorMdiSubWindow.h |
diffstat | 2 files changed, 35 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/FileEditorMdiSubWindow.cpp +++ b/gui/src/FileEditorMdiSubWindow.cpp @@ -93,14 +93,16 @@ { return; // existing file not saved and opening another file canceled by user } - QString openFileName = - QFileDialog::getOpenFileName (this, "Open File", QDir::homePath(), SAVE_FILE_FILTER); - if (openFileName.isEmpty ()) + QString openFileName; + QFileDialog dlg(this); + dlg.setNameFilter(SAVE_FILE_FILTER); + dlg.setAcceptMode(QFileDialog::AcceptOpen); + dlg.setViewMode(QFileDialog::Detail); + if ( dlg.exec() ) { - return; - } - else - { + openFileName = dlg.selectedFiles().at(0); + if (openFileName.isEmpty ()) + return; loadFile(openFileName); } } @@ -178,31 +180,16 @@ } void -FileEditorMdiSubWindow::saveFile (QString fileName) +FileEditorMdiSubWindow::saveFile (QString saveFileName) { // it is a new file with the name "<unnamed>" -> call saveFielAs - if (fileName==UNNAMED_FILE) + if (saveFileName==UNNAMED_FILE || saveFileName.isEmpty ()) { saveFileAs(); return; } - // check for a valid file name to save the contents - QString saveFileName; - if (fileName.isEmpty ()) - { - saveFileName = QFileDialog::getSaveFileName (this, "Save File", fileName,SAVE_FILE_FILTER); - if (saveFileName.isEmpty ()) - return; - if(!saveFileName.endsWith(".m")) - saveFileName.append(".m"); - } - else - { - saveFileName = fileName; - } - - // open the file + // open the file for writing QFile file (saveFileName); if (!file.open (QFile::WriteOnly)) { @@ -226,14 +213,28 @@ void FileEditorMdiSubWindow::saveFileAs () { - QString saveDir(m_fileName); - if (saveDir==UNNAMED_FILE) - saveDir = QDir::homePath(); - QString saveFileName = QFileDialog::getSaveFileName( - this, "Save File As", saveDir,SAVE_FILE_FILTER); - if(saveFileName.isEmpty()) - return; - saveFile(saveFileName); + QString saveFileName(m_fileName); + QFileDialog dlg(this); + if (saveFileName==UNNAMED_FILE || saveFileName.isEmpty ()) + { + saveFileName = QDir::homePath(); + dlg.setDirectory(saveFileName); + } + else + { + dlg.selectFile(saveFileName); + } + dlg.setNameFilter(SAVE_FILE_FILTER); + dlg.setDefaultSuffix("m"); + dlg.setAcceptMode(QFileDialog::AcceptSave); + dlg.setViewMode(QFileDialog::Detail); + if ( dlg.exec() ) + { + saveFileName = dlg.selectedFiles().at(0); + if (saveFileName.isEmpty ()) + return; + saveFile(saveFileName); + } } // handle the run command
--- a/gui/src/FileEditorMdiSubWindow.h +++ b/gui/src/FileEditorMdiSubWindow.h @@ -32,7 +32,7 @@ #include "lexer/lexeroctavegui.h" const char UNNAMED_FILE[] = "<unnamed>"; -const char SAVE_FILE_FILTER[] = "Octave Files *.m(*.m);;All Files *.*(*.*)"; +const char SAVE_FILE_FILTER[] = "Octave Files (*.m);;All Files (*.*)"; enum MARKER { MARKER_BOOKMARK,