diff options
author | Rr42 | 2018-05-31 12:33:57 +0530 |
---|---|---|
committer | Rr42 | 2018-05-31 12:33:57 +0530 |
commit | 82eb7fb321374f9cf1cebfc141e2594a7141a4c0 (patch) | |
tree | 1e0d3b56d989836755f43815430b373cc04a2326 /ldmicro/lib/linuxUI/linuxUI.cpp | |
parent | 7ddc1d90221f8300c7717c0e5dd86e7bcc59e4a7 (diff) | |
download | LDMicroGtk-82eb7fb321374f9cf1cebfc141e2594a7141a4c0.tar.gz LDMicroGtk-82eb7fb321374f9cf1cebfc141e2594a7141a4c0.tar.bz2 LDMicroGtk-82eb7fb321374f9cf1cebfc141e2594a7141a4c0.zip |
Added File selection dialogue
Diffstat (limited to 'ldmicro/lib/linuxUI/linuxUI.cpp')
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index 6dabd80..747b52e 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -94,51 +94,76 @@ void MessageBox(HWID pWindow, char* message, char* title, UINT mFlags) gtk_widget_destroy (dialog); } -BOOL GetSaveFileName(OPENFILENAME ofn) +BOOL GetSaveFileName(OPENFILENAME *ofn) { GtkWidget *dialog; GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; - dialog = gtk_file_chooser_dialog_new ("Open File", - GTK_WINDOW(window), + dialog = gtk_file_chooser_dialog_new (ofn->lpstrTitle, + GTK_WINDOW(ofn->parentWindow), action, "_Cancel", GTK_RESPONSE_CANCEL, "_Open", GTK_RESPONSE_ACCEPT, NULL); + //g_print("filter created\n"); + + if (ofn->Flags & OFN_OVERWRITEPROMPT == OFN_OVERWRITEPROMPT) + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); GtkFileFilter *filter = gtk_file_filter_new (); - gtk_file_filter_add_pattern (filter, "*"); - gtk_file_filter_set_name (filter, "All files"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); - - filter = gtk_file_filter_new (); - gtk_file_filter_add_pattern (filter, "*.c"); - gtk_file_filter_add_pattern (filter, "*.cpp"); - gtk_file_filter_set_name (filter, "C source files"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); - - filter = gtk_file_filter_new (); - gtk_file_filter_add_pattern (filter, "*.h"); - gtk_file_filter_set_name (filter, "C hedder files"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + char* strFilter = new char[strlen(ofn->lpstrFilter)]; + DWORD strFilterLen = 0; + BOOL filterResetFlag = FALSE; - filter = gtk_file_filter_new (); - gtk_file_filter_add_pattern (filter, "*.hex"); - gtk_file_filter_set_name (filter, "hex files"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + for (int i = 0; !(ofn->lpstrFilter[i] == '\0' && ofn->lpstrFilter[i-1] == '\0'); ++i) + { + memcpy (strFilter + strFilterLen, &ofn->lpstrFilter[i], 1 ); + ++strFilterLen; + if (ofn->lpstrFilter[i] == '\0') + if (filterResetFlag) + { + gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), strFilter); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter); + filter = gtk_file_filter_new (); + strFilterLen = 0; + //g_print("filter pat: %s\n", strFilter); + //g_print("filter reset\n"); + filterResetFlag = FALSE; + } + else + { + gtk_file_filter_set_name (GTK_FILE_FILTER(filter), strFilter); + //g_print("filter name: %s\n", strFilter); + strFilterLen = 0; + filterResetFlag = TRUE; + } + } + //g_print("filter rules added\n"); - filter = gtk_file_filter_new (); - gtk_file_filter_add_pattern (filter, "*.int"); - gtk_file_filter_set_name (filter, "int files"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter); + sprintf(strFilter, "*.%s", ofn->lpstrDefExt); + gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), strFilter); + //gtk_file_filter_set_name (filter, "int files"); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(dialog), filter); - BOOL exitStatus = gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT; + delete strFilter; + + //g_print("default filter set\n"); + + BOOL exitStatus = gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT; if (exitStatus) - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + { + char* str; + str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)); + strcpy(ofn->lpstrFile, str); + g_free(str); + } + //g_print("file path saved: %s\n", ofn->lpstrFile); + gtk_widget_destroy (dialog); + //g_print("exit\n"); + return exitStatus; }
\ No newline at end of file |