Skip to content

Commit

Permalink
Make FileChooser pre-select the filter matching the default file exte…
Browse files Browse the repository at this point in the history
…nsion (non-map formats).
  • Loading branch information
codereader committed Aug 15, 2017
1 parent 351379b commit adbef33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 14 additions & 9 deletions libs/wxutil/FileChooser.cpp
Expand Up @@ -11,6 +11,7 @@
#include "MultiMonitor.h"
#include "dialog/MessageBox.h"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/format.hpp>
#include <wx/app.h>

Expand All @@ -21,15 +22,8 @@ FileChooser::FileChooser(const std::string& title,
bool open,
const std::string& fileType,
const std::string& defaultExt) :
_dialog(new wxFileDialog(GlobalMainFrame().getWxTopLevelWindow(), title, wxEmptyString,
wxEmptyString, wxFileSelectorDefaultWildcardStr, getStyle(open))),
_title(title),
_fileType(fileType),
_defaultExt(defaultExt),
_open(open)
{
construct();
}
FileChooser(GlobalMainFrame().getWxTopLevelWindow(), title, open, fileType, defaultExt)
{}

FileChooser::FileChooser(wxWindow* parentWindow,
const std::string& title,
Expand Down Expand Up @@ -65,6 +59,9 @@ void FileChooser::construct()
_title = _open ? _("Open File") : _("Save File");
}

// Make default extension lowercase
boost::algorithm::to_lower(_defaultExt);

int defaultFormatIdx = 0;
int curFormatIdx = 0;

Expand Down Expand Up @@ -107,7 +104,15 @@ void FileChooser::construct()
filter.caption = i->name + " (" + i->pattern + ")";
filter.filter = i->pattern;

// Pre-select the filter matching the default extension
if (i->extension == _defaultExt)
{
defaultFormatIdx = curFormatIdx;
}

_fileFilters.push_back(filter);

++curFormatIdx;
}
}

Expand Down
4 changes: 2 additions & 2 deletions libs/wxutil/FileChooser.h
Expand Up @@ -97,15 +97,15 @@ class FileChooser :
void askForOverwrite(bool ask);

/**
* greebo: Displays the dialog and enters the GTK main loop.
* greebo: Displays the dialog and enters a blocking loop.
* Returns the filename or "" if the user hit cancel.
*
* The returned file name is normalised using the os::standardPath() method.
*/
virtual std::string display();

private:
long getStyle(bool open);
static long getStyle(bool open);

void construct(); // shared constructor stuff
};
Expand Down

0 comments on commit adbef33

Please sign in to comment.