Skip to content

Commit

Permalink
Suggest sensible defaults in file dialogs
Browse files Browse the repository at this point in the history
Went through first the diff of the referenced commit,
then all instances of "Create(Open|Save)FileDialog";
added SuggestFilename() calls where a default exists

This has been previously removed in
6b5db58
Closes #538
  • Loading branch information
nabijaczleweli committed May 4, 2020
1 parent a7eeef1 commit ef26dc6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/file.cpp
Expand Up @@ -893,11 +893,13 @@ bool SolveSpaceUI::ReloadAllLinked(const Platform::Path &saveFile, bool canCance
}
} else if(linkMap.count(g.linkFile) == 0) {
// The file was moved; prompt the user for its new location.
switch(LocateImportedFile(g.linkFile.RelativeTo(saveFile), canCancel)) {
const auto linkFileRelative = g.linkFile.RelativeTo(saveFile);
switch(LocateImportedFile(linkFileRelative, canCancel)) {
case Platform::MessageDialog::Response::YES: {
Platform::FileDialogRef dialog = Platform::CreateOpenFileDialog(SS.GW.window);
dialog->AddFilters(Platform::SolveSpaceModelFileFilters);
dialog->ThawChoices(settings, "LinkSketch");
dialog->SuggestFilename(linkFileRelative);
if(dialog->RunModal()) {
dialog->FreezeChoices(settings, "LinkSketch");
linkMap[g.linkFile] = dialog->GetFilename();
Expand Down Expand Up @@ -974,6 +976,7 @@ bool SolveSpaceUI::ReloadLinkedImage(const Platform::Path &saveFile,
Platform::FileDialogRef dialog = Platform::CreateOpenFileDialog(SS.GW.window);
dialog->AddFilters(Platform::RasterFileFilters);
dialog->ThawChoices(settings, "LinkImage");
dialog->SuggestFilename(filename->RelativeTo(saveFile));
if(dialog->RunModal()) {
dialog->FreezeChoices(settings, "LinkImage");
*filename = dialog->GetFilename();
Expand Down
1 change: 1 addition & 0 deletions src/platform/gui.h
Expand Up @@ -354,6 +354,7 @@ class FileDialog {

virtual Platform::Path GetFilename() = 0;
virtual void SetFilename(Platform::Path path) = 0;
virtual void SuggestFilename(Platform::Path path) = 0;

virtual void AddFilter(std::string name, std::vector<std::string> extensions) = 0;
void AddFilter(const FileFilter &filter);
Expand Down
4 changes: 4 additions & 0 deletions src/platform/guigtk.cpp
Expand Up @@ -1245,6 +1245,10 @@ class FileDialogImplGtk : public FileDialog {
gtkChooser->set_filename(path.raw);
}

void SuggestFilename(Platform::Path path) override {
SetFilename(path.WithExtension("")); // TODO
}

void AddFilter(std::string name, std::vector<std::string> extensions) override {
Glib::RefPtr<Gtk::FileFilter> gtkFilter = Gtk::FileFilter::create();
Glib::ustring desc;
Expand Down
4 changes: 4 additions & 0 deletions src/platform/guimac.mm
Expand Up @@ -1261,6 +1261,10 @@ void SetFilename(Platform::Path path) override {
nsPanel.nameFieldStringValue = Wrap(path.FileStem());
}

void SuggestFilename(Platform::Path path) override {
SetFilename(path.WithExtension(""));
}

void FreezeChoices(SettingsRef settings, const std::string &key) override {
settings->FreezeString("Dialog_" + key + "_Folder",
[nsPanel.directoryURL.absoluteString UTF8String]);
Expand Down
4 changes: 4 additions & 0 deletions src/platform/guiwin.cpp
Expand Up @@ -1575,6 +1575,10 @@ class FileDialogImplWin32 final : public FileDialog {
wcsncpy(filenameWC, Widen(path.raw).c_str(), sizeof(filenameWC) / sizeof(wchar_t) - 1);
}

void SuggestFilename(Platform::Path path) override {
SetFilename(path.WithExtension(""));
}

void AddFilter(std::string name, std::vector<std::string> extensions) override {
std::string desc, patterns;
for(auto extension : extensions) {
Expand Down
7 changes: 7 additions & 0 deletions src/solvespace.cpp
Expand Up @@ -599,6 +599,7 @@ void SolveSpaceUI::MenuFile(Command id) {
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
dialog->AddFilters(Platform::RasterFileFilters);
dialog->ThawChoices(settings, "ExportImage");
dialog->SuggestFilename(SS.saveFile);
if(dialog->RunModal()) {
dialog->FreezeChoices(settings, "ExportImage");
SS.ExportAsPngTo(dialog->GetFilename());
Expand All @@ -610,6 +611,7 @@ void SolveSpaceUI::MenuFile(Command id) {
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
dialog->AddFilters(Platform::VectorFileFilters);
dialog->ThawChoices(settings, "ExportView");
dialog->SuggestFilename(SS.saveFile);
if(!dialog->RunModal()) break;
dialog->FreezeChoices(settings, "ExportView");

Expand All @@ -633,6 +635,7 @@ void SolveSpaceUI::MenuFile(Command id) {
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
dialog->AddFilters(Platform::Vector3dFileFilters);
dialog->ThawChoices(settings, "ExportWireframe");
dialog->SuggestFilename(SS.saveFile);
if(!dialog->RunModal()) break;
dialog->FreezeChoices(settings, "ExportWireframe");

Expand All @@ -644,6 +647,7 @@ void SolveSpaceUI::MenuFile(Command id) {
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
dialog->AddFilters(Platform::VectorFileFilters);
dialog->ThawChoices(settings, "ExportSection");
dialog->SuggestFilename(SS.saveFile);
if(!dialog->RunModal()) break;
dialog->FreezeChoices(settings, "ExportSection");

Expand All @@ -655,6 +659,7 @@ void SolveSpaceUI::MenuFile(Command id) {
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
dialog->AddFilters(Platform::MeshFileFilters);
dialog->ThawChoices(settings, "ExportMesh");
dialog->SuggestFilename(SS.saveFile);
if(!dialog->RunModal()) break;
dialog->FreezeChoices(settings, "ExportMesh");

Expand All @@ -666,6 +671,7 @@ void SolveSpaceUI::MenuFile(Command id) {
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
dialog->AddFilters(Platform::SurfaceFileFilters);
dialog->ThawChoices(settings, "ExportSurfaces");
dialog->SuggestFilename(SS.saveFile);
if(!dialog->RunModal()) break;
dialog->FreezeChoices(settings, "ExportSurfaces");

Expand Down Expand Up @@ -879,6 +885,7 @@ void SolveSpaceUI::MenuAnalyze(Command id) {
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
dialog->AddFilters(Platform::CsvFileFilters);
dialog->ThawChoices(settings, "Trace");
dialog->SetFilename(SS.saveFile);
if(dialog->RunModal()) {
dialog->FreezeChoices(settings, "Trace");

Expand Down

0 comments on commit ef26dc6

Please sign in to comment.