Remember last used file type for all export dialogs.

This commit is contained in:
whitequark 2016-01-11 08:23:51 +00:00
parent 310fa9a817
commit 259d8e0d38
5 changed files with 37 additions and 20 deletions

View File

@ -704,7 +704,8 @@ bool MenuBarIsVisible(void) {
/* Save/load */ /* Save/load */
bool SolveSpace::GetOpenFile(std::string &file, const char *defExtension, const char *selPattern) { bool SolveSpace::GetOpenFile(std::string &file, const std::string &defExtension,
const char *selPattern) {
NSOpenPanel *panel = [NSOpenPanel openPanel]; NSOpenPanel *panel = [NSOpenPanel openPanel];
NSMutableArray *filters = [[NSMutableArray alloc] init]; NSMutableArray *filters = [[NSMutableArray alloc] init];
for(NSString *filter in [[NSString stringWithUTF8String:selPattern] for(NSString *filter in [[NSString stringWithUTF8String:selPattern]
@ -745,10 +746,11 @@ bool SolveSpace::GetOpenFile(std::string &file, const char *defExtension, const
} }
@end @end
bool SolveSpace::GetSaveFile(std::string &file, const char *defExtension, const char *selPattern) { bool SolveSpace::GetSaveFile(std::string &file, const std::string &defExtension,
const char *selPattern) {
NSSavePanel *panel = [NSSavePanel savePanel]; NSSavePanel *panel = [NSSavePanel savePanel];
[panel setNameFieldStringValue:[@"untitled" [panel setNameFieldStringValue:[@"untitled"
stringByAppendingPathExtension:[NSString stringWithUTF8String:defExtension]]]; stringByAppendingPathExtension:[NSString stringWithUTF8String:defExtension.c_str()]]];
SaveFormatController *controller = SaveFormatController *controller =
[[SaveFormatController alloc] initWithNibName:@"SaveFormatAccessory" bundle:nil]; [[SaveFormatController alloc] initWithNibName:@"SaveFormatAccessory" bundle:nil];
@ -772,7 +774,7 @@ bool SolveSpace::GetSaveFile(std::string &file, const char *defExtension, const
[extensions addObject:[filterExtensions objectAtIndex:0]]; [extensions addObject:[filterExtensions objectAtIndex:0]];
} }
[button selectItemAtIndex:[extensions [button selectItemAtIndex:[extensions
indexOfObject:[NSString stringWithUTF8String:defExtension]]]; indexOfObject:[NSString stringWithUTF8String:defExtension.c_str()]]];
if([panel runModal] == NSFileHandlingPanelOKButton) { if([panel runModal] == NSFileHandlingPanelOKButton) {
file = [[NSFileManager defaultManager] file = [[NSFileManager defaultManager]

View File

@ -1023,9 +1023,9 @@ void RefreshRecentMenus(void) {
/* Save/load */ /* Save/load */
static void FiltersFromPattern(const char *active, const char *patterns, static void FiltersFromPattern(const std::string &active, const char *patterns,
Gtk::FileChooser &chooser) { Gtk::FileChooser &chooser) {
Glib::ustring uactive = "*." + Glib::ustring(active); Glib::ustring uactive = "*." + active;
Glib::ustring upatterns = patterns; Glib::ustring upatterns = patterns;
#ifdef HAVE_GTK3 #ifdef HAVE_GTK3
@ -1077,7 +1077,7 @@ static void FiltersFromPattern(const char *active, const char *patterns,
} }
} }
bool GetOpenFile(std::string &file, const char *active, const char *patterns) { bool GetOpenFile(std::string &file, const std::string &active, const char *patterns) {
Gtk::FileChooserDialog chooser(*GW, "SolveSpace - Open File"); Gtk::FileChooserDialog chooser(*GW, "SolveSpace - Open File");
chooser.set_filename(file); chooser.set_filename(file);
chooser.add_button("_Cancel", Gtk::RESPONSE_CANCEL); chooser.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
@ -1133,7 +1133,7 @@ static void ChooserFilterChanged(Gtk::FileChooserDialog *chooser)
} }
} }
bool GetSaveFile(std::string &file, const char *active, const char *patterns) { bool GetSaveFile(std::string &file, const std::string &active, const char *patterns) {
Gtk::FileChooserDialog chooser(*GW, "SolveSpace - Save File", Gtk::FileChooserDialog chooser(*GW, "SolveSpace - Save File",
Gtk::FILE_CHOOSER_ACTION_SAVE); Gtk::FILE_CHOOSER_ACTION_SAVE);
chooser.set_do_overwrite_confirmation(true); chooser.set_do_overwrite_confirmation(true);

View File

@ -455,9 +455,10 @@ void SolveSpaceUI::MenuFile(int id) {
} }
case GraphicsWindow::MNU_EXPORT_VIEW: { case GraphicsWindow::MNU_EXPORT_VIEW: {
std::string exportFile = CnfThawString("", "2DExportFormat"); std::string exportFile;
if(!GetSaveFile(exportFile, VEC_EXT, VEC_PATTERN)) break; std::string exportFormat = CnfThawString(VEC_EXT, "ViewExportFormat");
CnfFreezeString(Extension(exportFile), "2DExportFormat"); if(!GetSaveFile(exportFile, exportFormat, VEC_PATTERN)) break;
CnfFreezeString(Extension(exportFile), "ViewExportFormat");
// If the user is exporting something where it would be // If the user is exporting something where it would be
// inappropriate to include the constraints, then warn. // inappropriate to include the constraints, then warn.
@ -477,28 +478,40 @@ void SolveSpaceUI::MenuFile(int id) {
case GraphicsWindow::MNU_EXPORT_WIREFRAME: { case GraphicsWindow::MNU_EXPORT_WIREFRAME: {
std::string exportFile; std::string exportFile;
if(!GetSaveFile(exportFile, V3D_EXT, V3D_PATTERN)) break; std::string exportFormat = CnfThawString(V3D_EXT, "WireframeExportFormat");
if(!GetSaveFile(exportFile, exportFormat, V3D_PATTERN)) break;
CnfFreezeString(Extension(exportFile), "WireframeExportFormat");
SS.ExportViewOrWireframeTo(exportFile, true); SS.ExportViewOrWireframeTo(exportFile, true);
break; break;
} }
case GraphicsWindow::MNU_EXPORT_SECTION: { case GraphicsWindow::MNU_EXPORT_SECTION: {
std::string exportFile; std::string exportFile;
if(!GetSaveFile(exportFile, VEC_EXT, VEC_PATTERN)) break; std::string exportFormat = CnfThawString(VEC_EXT, "SectionExportFormat");
if(!GetSaveFile(exportFile, exportFormat, VEC_PATTERN)) break;
CnfFreezeString(Extension(exportFile), "SectionExportFormat");
SS.ExportSectionTo(exportFile); SS.ExportSectionTo(exportFile);
break; break;
} }
case GraphicsWindow::MNU_EXPORT_MESH: { case GraphicsWindow::MNU_EXPORT_MESH: {
std::string exportFile; std::string exportFile;
if(!GetSaveFile(exportFile, MESH_EXT, MESH_PATTERN)) break; std::string exportFormat = CnfThawString(MESH_EXT, "MeshExportFormat");
if(!GetSaveFile(exportFile, exportFormat, MESH_PATTERN)) break;
CnfFreezeString(Extension(exportFile), "MeshExportFormat");
SS.ExportMeshTo(exportFile); SS.ExportMeshTo(exportFile);
break; break;
} }
case GraphicsWindow::MNU_EXPORT_SURFACES: { case GraphicsWindow::MNU_EXPORT_SURFACES: {
std::string exportFile; std::string exportFile;
if(!GetSaveFile(exportFile, SRF_EXT, SRF_PATTERN)) break; std::string exportFormat = CnfThawString(SRF_EXT, "SurfacesExportFormat");
if(!GetSaveFile(exportFile, exportFormat, SRF_PATTERN)) break;
CnfFreezeString(Extension(exportFile), "SurfacesExportFormat");
StepFileWriter sfw = {}; StepFileWriter sfw = {};
sfw.ExportSurfacesTo(exportFile); sfw.ExportSurfacesTo(exportFile);
break; break;

View File

@ -216,8 +216,10 @@ int LoadAutosaveYesNo(void);
// Comma-separated value, like a spreadsheet would use // Comma-separated value, like a spreadsheet would use
#define CSV_PATTERN PAT1("CSV File", "csv") ENDPAT #define CSV_PATTERN PAT1("CSV File", "csv") ENDPAT
#define CSV_EXT "csv" #define CSV_EXT "csv"
bool GetSaveFile(std::string &filename, const char *defExtension, const char *selPattern); bool GetSaveFile(std::string &filename, const std::string &defExtension,
bool GetOpenFile(std::string &filename, const char *defExtension, const char *selPattern); const char *selPattern);
bool GetOpenFile(std::string &filename, const std::string &defExtension,
const char *selPattern);
void LoadAllFontFiles(void); void LoadAllFontFiles(void);
void OpenWebsite(const char *url); void OpenWebsite(const char *url);

View File

@ -972,7 +972,7 @@ static size_t strlen2(const char *p) {
} }
static bool OpenSaveFile(bool isOpen, std::string &filename, static bool OpenSaveFile(bool isOpen, std::string &filename,
const char *defExtension, const char *selPattern) { const std::string &defExtension, const char *selPattern) {
// UNC paths may be as long as 32767 characters. // UNC paths may be as long as 32767 characters.
// Unfortunately, the Get*FileName API does not provide any way to use it // Unfortunately, the Get*FileName API does not provide any way to use it
// except with a preallocated buffer of fixed size, so we use something // except with a preallocated buffer of fixed size, so we use something
@ -1013,13 +1013,13 @@ static bool OpenSaveFile(bool isOpen, std::string &filename,
} }
bool SolveSpace::GetOpenFile(std::string &filename, bool SolveSpace::GetOpenFile(std::string &filename,
const char *defExtension, const char *selPattern) const std::string &defExtension, const char *selPattern)
{ {
return OpenSaveFile(true, filename, defExtension, selPattern); return OpenSaveFile(true, filename, defExtension, selPattern);
} }
bool SolveSpace::GetSaveFile(std::string &filename, bool SolveSpace::GetSaveFile(std::string &filename,
const char *defExtension, const char *selPattern) const std::string &defExtension, const char *selPattern)
{ {
return OpenSaveFile(false, filename, defExtension, selPattern); return OpenSaveFile(false, filename, defExtension, selPattern);
} }