Remember last used file type for all export dialogs.
This commit is contained in:
parent
310fa9a817
commit
259d8e0d38
@ -704,7 +704,8 @@ bool MenuBarIsVisible(void) {
|
||||
|
||||
/* 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];
|
||||
NSMutableArray *filters = [[NSMutableArray alloc] init];
|
||||
for(NSString *filter in [[NSString stringWithUTF8String:selPattern]
|
||||
@ -745,10 +746,11 @@ bool SolveSpace::GetOpenFile(std::string &file, const char *defExtension, const
|
||||
}
|
||||
@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];
|
||||
[panel setNameFieldStringValue:[@"untitled"
|
||||
stringByAppendingPathExtension:[NSString stringWithUTF8String:defExtension]]];
|
||||
stringByAppendingPathExtension:[NSString stringWithUTF8String:defExtension.c_str()]]];
|
||||
|
||||
SaveFormatController *controller =
|
||||
[[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]];
|
||||
}
|
||||
[button selectItemAtIndex:[extensions
|
||||
indexOfObject:[NSString stringWithUTF8String:defExtension]]];
|
||||
indexOfObject:[NSString stringWithUTF8String:defExtension.c_str()]]];
|
||||
|
||||
if([panel runModal] == NSFileHandlingPanelOKButton) {
|
||||
file = [[NSFileManager defaultManager]
|
||||
|
@ -1023,9 +1023,9 @@ void RefreshRecentMenus(void) {
|
||||
|
||||
/* Save/load */
|
||||
|
||||
static void FiltersFromPattern(const char *active, const char *patterns,
|
||||
static void FiltersFromPattern(const std::string &active, const char *patterns,
|
||||
Gtk::FileChooser &chooser) {
|
||||
Glib::ustring uactive = "*." + Glib::ustring(active);
|
||||
Glib::ustring uactive = "*." + active;
|
||||
Glib::ustring upatterns = patterns;
|
||||
|
||||
#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");
|
||||
chooser.set_filename(file);
|
||||
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::FILE_CHOOSER_ACTION_SAVE);
|
||||
chooser.set_do_overwrite_confirmation(true);
|
||||
|
@ -455,9 +455,10 @@ void SolveSpaceUI::MenuFile(int id) {
|
||||
}
|
||||
|
||||
case GraphicsWindow::MNU_EXPORT_VIEW: {
|
||||
std::string exportFile = CnfThawString("", "2DExportFormat");
|
||||
if(!GetSaveFile(exportFile, VEC_EXT, VEC_PATTERN)) break;
|
||||
CnfFreezeString(Extension(exportFile), "2DExportFormat");
|
||||
std::string exportFile;
|
||||
std::string exportFormat = CnfThawString(VEC_EXT, "ViewExportFormat");
|
||||
if(!GetSaveFile(exportFile, exportFormat, VEC_PATTERN)) break;
|
||||
CnfFreezeString(Extension(exportFile), "ViewExportFormat");
|
||||
|
||||
// If the user is exporting something where it would be
|
||||
// inappropriate to include the constraints, then warn.
|
||||
@ -477,28 +478,40 @@ void SolveSpaceUI::MenuFile(int id) {
|
||||
|
||||
case GraphicsWindow::MNU_EXPORT_WIREFRAME: {
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
case GraphicsWindow::MNU_EXPORT_SECTION: {
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
case GraphicsWindow::MNU_EXPORT_MESH: {
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
case GraphicsWindow::MNU_EXPORT_SURFACES: {
|
||||
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 = {};
|
||||
sfw.ExportSurfacesTo(exportFile);
|
||||
break;
|
||||
|
@ -216,8 +216,10 @@ int LoadAutosaveYesNo(void);
|
||||
// Comma-separated value, like a spreadsheet would use
|
||||
#define CSV_PATTERN PAT1("CSV File", "csv") ENDPAT
|
||||
#define CSV_EXT "csv"
|
||||
bool GetSaveFile(std::string &filename, const char *defExtension, const char *selPattern);
|
||||
bool GetOpenFile(std::string &filename, const char *defExtension, const char *selPattern);
|
||||
bool GetSaveFile(std::string &filename, const std::string &defExtension,
|
||||
const char *selPattern);
|
||||
bool GetOpenFile(std::string &filename, const std::string &defExtension,
|
||||
const char *selPattern);
|
||||
void LoadAllFontFiles(void);
|
||||
|
||||
void OpenWebsite(const char *url);
|
||||
|
@ -972,7 +972,7 @@ static size_t strlen2(const char *p) {
|
||||
}
|
||||
|
||||
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.
|
||||
// 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
|
||||
@ -1013,13 +1013,13 @@ static bool OpenSaveFile(bool isOpen, 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user