diff options
author | NatsuDrag9 | 2018-05-31 12:45:14 +0530 |
---|---|---|
committer | NatsuDrag9 | 2018-05-31 12:45:14 +0530 |
commit | 0e524c2933a93378f8ab5e4285e9f0eb42025e3e (patch) | |
tree | 26c110973d167a71f3d19a58a955d949617c0223 | |
parent | 0e41f9a700e928970f79b20d8d6a0f9993b16df6 (diff) | |
parent | 82eb7fb321374f9cf1cebfc141e2594a7141a4c0 (diff) | |
download | LDMicroGtk-0e524c2933a93378f8ab5e4285e9f0eb42025e3e.tar.gz LDMicroGtk-0e524c2933a93378f8ab5e4285e9f0eb42025e3e.tar.bz2 LDMicroGtk-0e524c2933a93378f8ab5e4285e9f0eb42025e3e.zip |
File dialogue sync
-rw-r--r-- | ldmicro/ldmicro.cpp | 2 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxLD.h | 14 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 109 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.h | 22 |
4 files changed, 88 insertions, 59 deletions
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index 984ffbb..8add732 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -148,7 +148,7 @@ static void CompileProgram(BOOL compileAs) memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); - ofn.parentWindow = parentWindow; + ofn.parentWindow = NULL; ofn.lpstrTitle = _("Compile To"); if(Prog.mcu && Prog.mcu->whichIsa == ISA_ANSIC) { ofn.lpstrFilter = C_PATTERN; diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h index fc60259..db2a42f 100644 --- a/ldmicro/lib/linuxUI/linuxLD.h +++ b/ldmicro/lib/linuxUI/linuxLD.h @@ -20,17 +20,21 @@ typedef wchar_t WCHAR; typedef char CHAR; typedef CONST WCHAR *LPCWSTR; typedef CONST CHAR *LPCSTR; /// should be __nullterminated + #ifdef UNICODE typedef LPCWSTR LPCTSTR; #else typedef LPCSTR LPCTSTR; #endif -// #ifdef UNICODE -// typedef LPWSTR LPTSTR; -// #else -// typedef LPSTR LPTSTR; -// #endif +typedef WCHAR *LPWSTR; +typedef CHAR *LPSTR; + +#ifdef UNICODE + typedef LPWSTR LPTSTR; +#else + typedef LPSTR LPTSTR; +#endif /// all handles will hold a GtkWindow* type typedef void* PVOID; diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index 3dbe1bb..9d912ea 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -59,51 +59,76 @@ void MessageBox(HWID pWindow, char* message, char* title, UINT mFlags) gtk_widget_destroy (dialog); } -// BOOL GetSaveFileName(OPENFILENAME ofn) -// { -// GtkWidget *dialog; -// GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; - -// dialog = gtk_file_chooser_dialog_new ("Open File", -// GTK_WINDOW(window), -// action, -// "_Cancel", -// GTK_RESPONSE_CANCEL, -// "_Open", -// GTK_RESPONSE_ACCEPT, -// NULL); - -// 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); +BOOL GetSaveFileName(OPENFILENAME *ofn) +{ + GtkWidget *dialog; + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; -// 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); + 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); -// 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); + GtkFileFilter *filter = gtk_file_filter_new (); + char* strFilter = new char[strlen(ofn->lpstrFilter)]; + DWORD strFilterLen = 0; + BOOL filterResetFlag = FALSE; + + 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, "*.hex"); -// gtk_file_filter_set_name (filter, "hex files"); -// gtk_file_chooser_add_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); -// 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); + delete strFilter; + + //g_print("default filter set\n"); + + BOOL exitStatus = gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT; + if (exitStatus) + { + 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); -// BOOL exitStatus = gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT; -// if (exitStatus) -// filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); -// gtk_widget_destroy (dialog); + gtk_widget_destroy (dialog); -// return exitStatus; -// }
\ No newline at end of file + //g_print("exit\n"); + + return exitStatus; +} diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index 18afd60..904599e 100644 --- a/ldmicro/lib/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -30,21 +30,21 @@ /// data types -// typedef struct OpenFileInfoData { -// DWORD lStructSize; -// HWID parentWindow; -// LPCTSTR lpstrFilter; -// LPTSTR lpstrFile; -// DWORD nMaxFile; -// LPCTSTR lpstrTitle; -// DWORD Flags; -// LPCTSTR lpstrDefExt; -// } OPENFILENAME; +typedef struct OpenFileInfoData { + DWORD lStructSize; + HWID parentWindow; + LPTSTR lpstrFile; + LPCTSTR lpstrFilter; + DWORD nMaxFile; + LPCTSTR lpstrTitle; + DWORD Flags; + LPCTSTR lpstrDefExt; +} OPENFILENAME; /// functions BOOL isFocus(HWID); COLORREF RGB(int, int, int); void MessageBox(HWID, char*, char*, UINT); -BOOL GetSaveFileName(HWID, char*); +BOOL GetSaveFileName(OPENFILENAME* ); #endif
\ No newline at end of file |