Skip to content

Commit c6008cd

Browse files
committed
Linux save file support
1 parent 7eb856b commit c6008cd

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed
Binary file not shown.

Plugins/Linux/StandaloneFileBrowser/library.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const char*
3535
GTKOpenPanel(const char* title, const char* directory, const char* extension, bool multiselect,
3636
GtkFileChooserAction action);
3737

38+
const char*
39+
GTKSavePanel(const char* title, const char* directory, const char* defaultName, const char* filters);
40+
3841
void GTKSetFilters(const char* extension, GtkWidget* dialog);
3942

4043
const char* DialogOpenFilePanel(const char* title, const char* directory, const char* extension,
@@ -50,7 +53,7 @@ const char* DialogOpenFolderPanel(const char* title, const char* directory, bool
5053

5154
const char* DialogSaveFilePanel(const char* title, const char* directory, const char* defaultName,
5255
const char* filters) {
53-
return "NOT IMPLEMENTED";
56+
return GTKSavePanel(title, directory, defaultName, filters);
5457
}
5558

5659
void DialogOpenFilePanelAsync(const char* title, const char* directory, const char* extension,
@@ -72,7 +75,7 @@ void DialogOpenFolderPanelAsync(const char* title, const char* directory, bool m
7275
void DialogSaveFilePanelAsync(const char* title, const char* directory, const char* defaultName,
7376
const char* filters, callbackFunc cb) {
7477
// TODO Add async capability
75-
cb("NOT IMPLEMENTED");
78+
cb(GTKSavePanel(title, directory, defaultName, filters));
7679
}
7780

7881
const char*
@@ -136,6 +139,49 @@ GTKOpenPanel(const char* title, const char* directory, const char* extensions, b
136139
return filename;
137140
}
138141

142+
const char*
143+
GTKSavePanel(const char* title, const char* directory, const char* defaultName, const char* filters) {
144+
char* filename = NULL;
145+
GtkWidget *dialog;
146+
GtkFileChooser *chooser;
147+
gint res;
148+
149+
dialog = gtk_file_chooser_dialog_new ("Save File",
150+
NULL,
151+
GTK_FILE_CHOOSER_ACTION_SAVE,
152+
("_Cancel"),
153+
GTK_RESPONSE_CANCEL,
154+
("_Save"),
155+
GTK_RESPONSE_ACCEPT,
156+
NULL);
157+
chooser = GTK_FILE_CHOOSER (dialog);
158+
159+
gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
160+
gtk_file_chooser_set_current_name(chooser, defaultName);
161+
gtk_file_chooser_set_current_folder(chooser, directory);
162+
163+
GTKSetFilters(filters, dialog);
164+
165+
res = gtk_dialog_run (GTK_DIALOG (dialog));
166+
if (res == GTK_RESPONSE_ACCEPT)
167+
{
168+
char* name = gtk_file_chooser_get_filename(chooser);
169+
filename = malloc(strlen(name) * sizeof(char));
170+
strcpy(filename, name);
171+
g_free(name);
172+
}
173+
else if (res == GTK_RESPONSE_CANCEL) {
174+
filename = malloc(sizeof(char));
175+
filename[0] = '\0';
176+
}
177+
178+
gtk_widget_destroy (dialog);
179+
180+
while (gtk_events_pending ())
181+
gtk_main_iteration ();
182+
return filename;
183+
}
184+
139185
void GTKSetFilters(const char* extensions, GtkWidget* dialog) {
140186
if (extensions == NULL || strlen(extensions) == 0) {
141187
return;

0 commit comments

Comments
 (0)