Commit 798879aa authored by Mike Kremer's avatar Mike Kremer

Prevent loadWidget from acting strange if filename or directory suggestions...

Prevent loadWidget from acting strange if filename or directory suggestions have been entered and enter-key has been hit.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9347 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3b200d2f
......@@ -193,7 +193,7 @@ void LoadWidget::slotSetSaveFilters(DataType _type){
/// find suitable plugin for loading current file
void LoadWidget::loadFile(){
//get selection
QStringList files = selectedFiles();
......@@ -472,14 +472,39 @@ int LoadWidget::showSave(IdList _ids, QString _filename){
return this->exec();
}
void LoadWidget::accept() {
if ( loadMode_ )
loadFile();
else
saveFile();
bool LoadWidget::validFilename() {
// Only proceed if selected file is REALLY a file
// Consider two cases:
// Case 1: Filename is neither a valid file nor a directory -> continue and wait for valid file
// Case 2: Entered filename is a directory -> Change to directory and wait for valid file
QString firstEntered = selectedFiles()[0];
// Test if directory exists
QDir testdir(firstEntered);
if(testdir.exists()) {
setDirectory(testdir);
return false;
}
// Test if file exists
QFile file(firstEntered);
if(!file.exists()) return false;
return true;
}
void LoadWidget::accept() {
if(validFilename()) {
if ( loadMode_ )
loadFile();
else
saveFile();
QFileDialog::accept();
QFileDialog::accept();
}
}
void LoadWidget::slotSetPluginForExtension(QString _extension, int _pluginId ){
......
......@@ -81,6 +81,8 @@ class LoadWidget : public QFileDialog
int showSave(int _id, QString _filename);
int showSave(IdList _ids, QString _filename);
bool validFilename();
public slots :
virtual void accept();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment