Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: GitHub noreply@github.com Date: Sat, 17 Sep 2022 09:57:33 UTC Commit: 465e60bef6018b99f5e9b3432134bf8dbaad9bb3 https://github.com/geany/geany/commit/465e60bef6018b99f5e9b3432134bf8dbaad9b...
Log Message: ----------- Remove native file and color dialogs on Windows (#3219)
Their implementation was buggy, use very old Windows APIs and require double implementation and maintenance efforts for us The GTK dialogs work well for all other users already, so they probably will also for Windows users.
Closes #3209.
Modified Paths: -------------- doc/geany.txt src/dialogs.c src/keyfile.c src/prefs.c src/project.c src/tools.c src/ui_utils.h src/win32.c src/win32.h
Modified: doc/geany.txt 4 lines changed, 0 insertions(+), 4 deletions(-) =================================================================== @@ -1903,10 +1903,6 @@ Suppress status messages in the status bar reshows the document statistics on the status bar. See `Focus keybindings`_.
-Use Windows File Open/Save dialogs - Defines whether to use the native Windows File Open/Save dialogs or - whether to use the GTK default dialogs. - Auto-focus widgets (focus follows mouse) Give the focus automatically to widgets below the mouse cursor. This works for the main editor widget, the scribble, the toolbar search field
Modified: src/dialogs.c 46 lines changed, 11 insertions(+), 35 deletions(-) =================================================================== @@ -449,6 +449,7 @@ static void open_file_dialog_apply_settings(GtkWidget *dialog) void dialogs_show_open_file(void) { gchar *initdir; + GtkWidget *dialog;
/* set dialog directory to the current file's directory, if present */ initdir = utils_get_current_file_dir_utf8(); @@ -460,27 +461,20 @@ void dialogs_show_open_file(void)
SETPTR(initdir, utils_get_locale_from_utf8(initdir));
-#ifdef G_OS_WIN32 - if (interface_prefs.use_native_windows_dialogs) - win32_show_document_open_dialog(GTK_WINDOW(main_widgets.window), _("Open File"), initdir); - else -#endif - { - GtkWidget *dialog = create_open_file_dialog(); + dialog = create_open_file_dialog(); + open_file_dialog_apply_settings(dialog);
- open_file_dialog_apply_settings(dialog); + if (initdir != NULL && g_path_is_absolute(initdir)) + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), initdir);
- if (initdir != NULL && g_path_is_absolute(initdir)) - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), initdir); + if (app->project && !EMPTY(app->project->base_path)) + gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog), + app->project->base_path, NULL);
- if (app->project && !EMPTY(app->project->base_path)) - gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog), - app->project->base_path, NULL); + while (!open_file_dialog_handle_response(dialog, + gtk_dialog_run(GTK_DIALOG(dialog)))); + gtk_widget_destroy(dialog);
- while (!open_file_dialog_handle_response(dialog, - gtk_dialog_run(GTK_DIALOG(dialog)))); - gtk_widget_destroy(dialog); - } g_free(initdir); }
@@ -671,16 +665,6 @@ gboolean dialogs_show_save_as(void)
g_return_val_if_fail(doc, FALSE);
-#ifdef G_OS_WIN32 - if (interface_prefs.use_native_windows_dialogs) - { - gchar *utf8_name = win32_show_document_save_as_dialog(GTK_WINDOW(main_widgets.window), - _("Save File"), doc); - if (utf8_name != NULL) - result = handle_save_as(utf8_name, FALSE); - } - else -#endif result = show_save_as_gtk(doc); return result; } @@ -875,14 +859,6 @@ on_font_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) /* This shows the font selection dialog to choose a font. */ void dialogs_show_open_font(void) { -#ifdef G_OS_WIN32 - if (interface_prefs.use_native_windows_dialogs) - { - win32_show_font_dialog(); - return; - } -#endif - if (ui_widgets.open_fontsel == NULL) { GtkWidget *apply_button;
Modified: src/keyfile.c 2 lines changed, 0 insertions(+), 2 deletions(-) =================================================================== @@ -537,7 +537,6 @@ static void save_dialog_prefs(GKeyFile *config) g_key_file_set_boolean(config, PACKAGE, "tab_order_beside", file_prefs.tab_order_beside); g_key_file_set_integer(config, PACKAGE, "tab_pos_editor", interface_prefs.tab_pos_editor); g_key_file_set_integer(config, PACKAGE, "tab_pos_msgwin", interface_prefs.tab_pos_msgwin); - g_key_file_set_boolean(config, PACKAGE, "use_native_windows_dialogs", interface_prefs.use_native_windows_dialogs);
/* display */ g_key_file_set_boolean(config, PACKAGE, "show_indent_guide", editor_prefs.show_indent_guide); @@ -886,7 +885,6 @@ static void load_dialog_prefs(GKeyFile *config) interface_prefs.editor_font = utils_get_setting_string(config, PACKAGE, "editor_font", GEANY_DEFAULT_FONT_EDITOR); interface_prefs.tagbar_font = utils_get_setting_string(config, PACKAGE, "tagbar_font", GEANY_DEFAULT_FONT_SYMBOL_LIST); interface_prefs.msgwin_font = utils_get_setting_string(config, PACKAGE, "msgwin_font", GEANY_DEFAULT_FONT_MSG_WINDOW); - interface_prefs.use_native_windows_dialogs = utils_get_setting_boolean(config, PACKAGE, "use_native_windows_dialogs", FALSE);
/* display, editor */ editor_prefs.long_line_enabled = utils_get_setting_boolean(config, PACKAGE, "long_line_enabled", TRUE);
Modified: src/prefs.c 8 lines changed, 0 insertions(+), 8 deletions(-) =================================================================== @@ -434,10 +434,6 @@ static void prefs_init_dialog(void) widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_focus"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.auto_focus);
- widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_native_windows_dialogs"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), - interface_prefs.use_native_windows_dialogs); - widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction"); gtk_entry_set_text(GTK_ENTRY(widget), tool_prefs.context_action_cmd);
@@ -916,10 +912,6 @@ on_prefs_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_auto_focus"); prefs.auto_focus = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
- widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_native_windows_dialogs"); - interface_prefs.use_native_windows_dialogs = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction"); g_free(tool_prefs.context_action_cmd); tool_prefs.context_action_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
Modified: src/project.c 105 lines changed, 36 insertions(+), 69 deletions(-) =================================================================== @@ -43,7 +43,6 @@ #include "support.h" #include "ui_utils.h" #include "utils.h" -#include "win32.h"
#include <string.h> #include <unistd.h> @@ -341,66 +340,46 @@ static void run_open_dialog(GtkDialog *dialog) void project_open(void) { const gchar *dir = local_prefs.project_file_path; + gchar *locale_path; + GtkWidget *dialog; + GtkFileFilter *filter; + + dialog = gtk_file_chooser_dialog_new(_("Open Project"), GTK_WINDOW(main_widgets.window), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + gtk_widget_set_name(dialog, "GeanyDialogProject");
-#ifdef G_OS_WIN32 - if (interface_prefs.use_native_windows_dialogs) + /* set default Open, so pressing enter can open multiple files */ + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); + gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); + gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE); + gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_widgets.window)); + gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); + + /* add FileFilters */ + filter = gtk_file_filter_new(); + gtk_file_filter_set_name(filter, _("All files")); + gtk_file_filter_add_pattern(filter, "*"); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); + filter = gtk_file_filter_new(); + gtk_file_filter_set_name(filter, _("Project files")); + gtk_file_filter_add_pattern(filter, "*." GEANY_PROJECT_EXT); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); + gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); + + locale_path = utils_get_locale_from_utf8(dir); + if (g_file_test(locale_path, G_FILE_TEST_EXISTS) && + g_file_test(locale_path, G_FILE_TEST_IS_DIR)) { - gchar *file = win32_show_project_open_dialog(main_widgets.window, _("Open Project"), dir, FALSE, TRUE); - if (file != NULL) - { - if (app->project && !project_close(FALSE)) {} - /* try to load the config */ - else if (! project_load_file_with_session(file)) - { - SHOW_ERR1(_("Project file "%s" could not be loaded."), file); - } - g_free(file); - } + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path); } - else -#endif - { - GtkWidget *dialog; - GtkFileFilter *filter; - gchar *locale_path; - - dialog = gtk_file_chooser_dialog_new(_("Open Project"), GTK_WINDOW(main_widgets.window), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - gtk_widget_set_name(dialog, "GeanyDialogProject"); - - /* set default Open, so pressing enter can open multiple files */ - gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); - gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); - gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE); - gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); - gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_widgets.window)); - gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); - - /* add FileFilters */ - filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, _("All files")); - gtk_file_filter_add_pattern(filter, "*"); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); - filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, _("Project files")); - gtk_file_filter_add_pattern(filter, "*." GEANY_PROJECT_EXT); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); - gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); - - locale_path = utils_get_locale_from_utf8(dir); - if (g_file_test(locale_path, G_FILE_TEST_EXISTS) && - g_file_test(locale_path, G_FILE_TEST_IS_DIR)) - { - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path); - } - g_free(locale_path); + g_free(locale_path);
- gtk_widget_show_all(dialog); - run_open_dialog(GTK_DIALOG(dialog)); - gtk_widget_destroy(GTK_WIDGET(dialog)); - } + gtk_widget_show_all(dialog); + run_open_dialog(GTK_DIALOG(dialog)); + gtk_widget_destroy(GTK_WIDGET(dialog)); }
@@ -896,7 +875,6 @@ static gboolean update_config(const PropertyDialogElements *e, gboolean new_proj }
-#ifndef G_OS_WIN32 static void run_dialog(GtkWidget *dialog, GtkWidget *entry) { /* set filename in the file chooser dialog */ @@ -947,20 +925,10 @@ static void run_dialog(GtkWidget *dialog, GtkWidget *entry) } gtk_widget_destroy(dialog); } -#endif
static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e) { -#ifdef G_OS_WIN32 - gchar *path = win32_show_project_open_dialog(e->dialog, _("Choose Project Filename"), - gtk_entry_get_text(GTK_ENTRY(e->file_name)), TRUE, TRUE); - if (path != NULL) - { - gtk_entry_set_text(GTK_ENTRY(e->file_name), path); - g_free(path); - } -#else GtkWidget *dialog;
/* initialise the dialog */ @@ -975,7 +943,6 @@ static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElement gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
run_dialog(dialog, e->file_name); -#endif }
Modified: src/tools.c 9 lines changed, 0 insertions(+), 9 deletions(-) =================================================================== @@ -36,7 +36,6 @@ #include "support.h" #include "ui_utils.h" #include "utils.h" -#include "win32.h"
#include <stdlib.h> #include <unistd.h> @@ -831,14 +830,6 @@ void tools_color_chooser(const gchar *color) GdkColor gc; GtkWidget *colorsel;
-#ifdef G_OS_WIN32 - if (interface_prefs.use_native_windows_dialogs) - { - win32_show_color_dialog(color); - return; - } -#endif - if (ui_widgets.open_colorsel == NULL) { ui_widgets.open_colorsel = gtk_color_selection_dialog_new(_("Color Chooser"));
Modified: src/ui_utils.h 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -63,7 +63,7 @@ typedef struct GeanyInterfacePrefs gboolean msgwin_compiler_visible; /**< whether message window's compiler tab is visible */ gboolean msgwin_messages_visible; /**< whether message window's messages tab is visible */ gboolean msgwin_scribble_visible; /**< whether message window's scribble tab is visible */ - /** whether to use native Windows' dialogs (only used on Windows) */ + /** whether to use native Windows' dialogs - ignored and not used anymore */ gboolean use_native_windows_dialogs; /** whether compiler messages window is automatically scrolled to show new messages */ gboolean compiler_tab_autoscroll;
Modified: src/win32.c 443 lines changed, 4 insertions(+), 439 deletions(-) =================================================================== @@ -76,7 +76,7 @@ G_INLINE_FUNC void win32_dialog_reset_timer(HWND hwnd) }
-VOID CALLBACK +static VOID CALLBACK win32_dialog_update_main_window(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { gint i; @@ -117,116 +117,20 @@ G_INLINE_FUNC UINT_PTR win32_dialog_queue_main_window_redraw(HWND dlg, UINT msg,
/* This function is called for OPENFILENAME lpfnHook function and it establishes * a timer that is reset each time which will update the main window loop eventually. */ -UINT_PTR CALLBACK win32_dialog_explorer_hook_proc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) +static UINT_PTR CALLBACK win32_dialog_explorer_hook_proc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) { return win32_dialog_queue_main_window_redraw(dlg, msg, wParam, lParam, TRUE); }
/* This function is called for old-school win32 dialogs that accept a proper * lpfnHook function for all messages, it doesn't use a timer. */ -UINT_PTR CALLBACK win32_dialog_hook_proc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) +static UINT_PTR CALLBACK win32_dialog_hook_proc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) { return win32_dialog_queue_main_window_redraw(dlg, msg, wParam, lParam, FALSE); }
-static wchar_t *get_file_filters(void) -{ - gchar *string; - guint i, j, len; - static wchar_t title[4096]; - GString *str = g_string_sized_new(100); - GString *all_patterns = g_string_sized_new(100); - GSList *node; - gchar *tmp; - - /* create meta file filter "All files" */ - g_string_append_printf(str, "%s\t*\t", _("All files")); - /* create meta file filter "All Source" (skip GEANY_FILETYPES_NONE) */ - for (i = GEANY_FILETYPES_NONE + 1; i < filetypes_array->len; i++) - { - for (j = 0; filetypes[i]->pattern[j] != NULL; j++) - { - g_string_append(all_patterns, filetypes[i]->pattern[j]); - g_string_append_c(all_patterns, ';'); - } - } - g_string_append_printf(str, "%s\t%s\t", _("All Source"), all_patterns->str); - g_string_free(all_patterns, TRUE); - /* add 'usual' filetypes */ - foreach_slist(node, filetypes_by_title) - { - GeanyFiletype *ft = node->data; - - if (G_UNLIKELY(ft->id == GEANY_FILETYPES_NONE)) - continue; - tmp = g_strjoinv(";", ft->pattern); - g_string_append_printf(str, "%s\t%s\t", ft->title, tmp); - g_free(tmp); - } - g_string_append_c(str, '\t'); /* the final \0 byte to mark the end of the string */ - string = str->str; - g_string_free(str, FALSE); - - /* replace all "\t"s by \0 */ - len = strlen(string); - g_strdelimit(string, "\t", '\0'); - g_assert(string[len - 1] == 0x0); - MultiByteToWideChar(CP_UTF8, 0, string, len, title, G_N_ELEMENTS(title)); - g_free(string); - - return title; -} - - -static wchar_t *get_file_filter_all_files(void) -{ - guint len; - static wchar_t title[4096]; - gchar *filter; - - /* create meta file filter "All files" */ - filter = g_strdup_printf("%s\t*\t", _("All files")); - - len = strlen(filter); - g_strdelimit(filter, "\t", '\0'); - g_assert(filter[len - 1] == 0x0); - MultiByteToWideChar(CP_UTF8, 0, filter, len, title, G_N_ELEMENTS(title)); - g_free(filter); - - return title; -} - - -static wchar_t *get_filters(gboolean project_files) -{ - gchar *string; - gint len; - static wchar_t title[1024]; - - if (project_files) - { - string = g_strconcat(_("Geany project files"), "\t", "*." GEANY_PROJECT_EXT, "\t", - _("All files"), "\t", "*", "\t", NULL); - } - else - { - string = g_strconcat(_("Executables"), "\t", "*.exe;*.bat;*.cmd", "\t", - _("All files"), "\t", "*", "\t", NULL); - } - - /* replace all "\t"s by \0 */ - len = strlen(string); - g_strdelimit(string, "\t", '\0'); - g_assert(string[len - 1] == 0x0); - MultiByteToWideChar(CP_UTF8, 0, string, len, title, G_N_ELEMENTS(title)); - g_free(string); - - return title; -} - - /* Converts the given UTF-8 filename or directory name into something usable for Windows and * returns the directory part of the given filename. */ static wchar_t *get_dir_for_path(const gchar *utf8_filename) @@ -252,7 +156,7 @@ static wchar_t *get_dir_for_path(const gchar *utf8_filename) * be done with BROWSEINFO.pidlRoot and SHParseDisplayName but SHParseDisplayName is not available * on systems below Windows XP. So, we go the hard way by creating a callback which will set up the * folder when the dialog is initialised. Yeah, I like Windows. */ -INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) +static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) { win32_dialog_hook_proc(hwnd, uMsg, lp, pData); switch (uMsg) @@ -317,216 +221,6 @@ gchar *win32_show_folder_dialog(GtkWidget *parent, const gchar *title, const gch }
-/* Shows a file open dialog. - * If allow_new_file is set, the file to be opened doesn't have to exist. - * initial_dir is expected in UTF-8 - * The selected file name is returned. - * If project_file_filter is set, the file open dialog will have a file filter for Geany project - * files, a filter for executables otherwise. */ -gchar *win32_show_project_open_dialog(GtkWidget *parent, const gchar *title, - const gchar *initial_dir, gboolean allow_new_file, - gboolean project_file_filter) -{ - OPENFILENAMEW of; - gint retval; - wchar_t fname[MAX_PATH]; - wchar_t w_title[512]; - gchar *filename; - - fname[0] = '\0'; - - MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title)); - - if (parent == NULL) - parent = main_widgets.window; - - /* initialise file dialog info struct */ - memset(&of, 0, sizeof of); - of.lStructSize = sizeof of; - of.hwndOwner = GDK_WINDOW_HWND(gtk_widget_get_window(parent)); - of.lpstrFilter = get_filters(project_file_filter); - - of.lpstrCustomFilter = NULL; - of.nFilterIndex = 0; - of.lpstrFile = fname; - of.lpstrInitialDir = get_dir_for_path(initial_dir); - of.nMaxFile = 2048; - of.lpstrFileTitle = NULL; - of.lpstrTitle = w_title; - of.lpstrDefExt = L""; - of.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_HIDEREADONLY | - OFN_ENABLEHOOK | OFN_ENABLESIZING; - of.lpfnHook = win32_dialog_explorer_hook_proc; - if (! allow_new_file) - of.Flags |= OFN_FILEMUSTEXIST; - - retval = GetOpenFileNameW(&of); - - if (! retval) - { - if (CommDlgExtendedError()) - { - gchar *error; - error = g_strdup_printf("File dialog box error (%x)", (int)CommDlgExtendedError()); - win32_message_dialog(NULL, GTK_MESSAGE_ERROR, error); - g_free(error); - } - return NULL; - } - /* convert the resulting filename into UTF-8 (from whatever encoding it has at this moment) */ - filename = g_malloc0(MAX_PATH * 2); - WideCharToMultiByte(CP_UTF8, 0, fname, -1, filename, MAX_PATH * 2, NULL, NULL); - - return filename; -} - - -/* initial_dir can be NULL to use the current working directory. - * Returns: TRUE if the dialog was not cancelled. */ -gboolean win32_show_document_open_dialog(GtkWindow *parent, const gchar *title, const gchar *initial_dir) -{ - OPENFILENAMEW of; - gint retval; - guint x; - gchar tmp[MAX_PATH]; - wchar_t fname[MAX_PATH]; - wchar_t w_dir[MAX_PATH]; - wchar_t w_title[512]; - - fname[0] = '\0'; - - if (initial_dir != NULL) - MultiByteToWideChar(CP_UTF8, 0, initial_dir, -1, w_dir, G_N_ELEMENTS(w_dir)); - - MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title)); - - /* initialise file dialog info struct */ - memset(&of, 0, sizeof of); - of.lStructSize = sizeof of; - of.hwndOwner = GDK_WINDOW_HWND(gtk_widget_get_window(GTK_WIDGET(parent))); - of.lpstrFilter = get_file_filters(); - - of.lpstrCustomFilter = NULL; - of.nFilterIndex = GEANY_FILETYPES_NONE + 1; - of.lpstrFile = fname; - of.lpstrInitialDir = (initial_dir != NULL) ? w_dir : NULL; - of.nMaxFile = 2048; - of.lpstrFileTitle = NULL; - of.lpstrTitle = w_title; - of.lpstrDefExt = L""; - of.Flags = OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_EXPLORER | - OFN_ENABLEHOOK | OFN_ENABLESIZING; - of.lpfnHook = win32_dialog_explorer_hook_proc; - - retval = GetOpenFileNameW(&of); - - if (!retval) - { - if (CommDlgExtendedError()) - { - gchar error[100]; - g_snprintf(error, sizeof error, "File dialog box error (%x)", (int)CommDlgExtendedError()); - win32_message_dialog(NULL, GTK_MESSAGE_ERROR, error); - } - return FALSE; - } - - x = of.nFileOffset - 1; - if (x != wcslen(fname)) - { /* open a single file */ - WideCharToMultiByte(CP_UTF8, 0, fname, -1, tmp, sizeof(tmp), NULL, NULL); - document_open_file(tmp, of.Flags & OFN_READONLY, NULL, NULL); - } - else - { /* open multiple files */ - gchar file_name[MAX_PATH]; - gchar dir_name[MAX_PATH]; - - WideCharToMultiByte(CP_UTF8, 0, fname, of.nFileOffset, - dir_name, sizeof(dir_name), NULL, NULL); - for (; ;) - { - if (! fname[x]) - { - if (! fname[x + 1]) - break; - - WideCharToMultiByte(CP_UTF8, 0, fname + x + 1, -1, - tmp, sizeof(tmp), NULL, NULL); - g_snprintf(file_name, 511, "%s\%s", dir_name, tmp); - - /* convert the resulting filename into UTF-8 */ - document_open_file(file_name, of.Flags & OFN_READONLY, NULL, NULL); - } - x++; - } - } - return (retval != 0); -} - - -gchar *win32_show_document_save_as_dialog(GtkWindow *parent, const gchar *title, - GeanyDocument *doc) -{ - OPENFILENAMEW of; - gint retval; - gchar tmp[MAX_PATH]; - wchar_t w_file[MAX_PATH]; - wchar_t w_title[512]; - int n; - - w_file[0] = '\0'; - - /* Convert the name of the file for of.lpstrFile */ - n = MultiByteToWideChar(CP_UTF8, 0, DOC_FILENAME(doc), -1, w_file, G_N_ELEMENTS(w_file)); - - /* If creating a new file name, convert and append the extension if any */ - if (! doc->file_name && doc->file_type && doc->file_type->extension && - n + 1 < (int)G_N_ELEMENTS(w_file)) - { - w_file[n - 1] = L'.'; - MultiByteToWideChar(CP_UTF8, 0, doc->file_type->extension, -1, &w_file[n], - G_N_ELEMENTS(w_file) - n - 1); - } - - MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title)); - - /* initialise file dialog info struct */ - memset(&of, 0, sizeof of); - of.lStructSize = sizeof of; - of.hwndOwner = GDK_WINDOW_HWND(gtk_widget_get_window(GTK_WIDGET(parent))); - - of.lpstrFilter = get_file_filter_all_files(); - of.lpstrCustomFilter = NULL; - of.nFilterIndex = 0; - - of.lpstrFile = w_file; - of.nMaxFile = 2048; - of.lpstrFileTitle = NULL; - of.lpstrTitle = w_title; - of.lpstrDefExt = L""; - of.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_ENABLESIZING; - of.lpfnHook = win32_dialog_explorer_hook_proc; - retval = GetSaveFileNameW(&of); - - if (! retval) - { - if (CommDlgExtendedError()) - { - gchar *error = g_strdup_printf( - "File dialog box error (%x)", (gint) CommDlgExtendedError()); - win32_message_dialog(NULL, GTK_MESSAGE_ERROR, error); - g_free(error); - } - return NULL; - } - - WideCharToMultiByte(CP_UTF8, 0, w_file, -1, tmp, sizeof(tmp), NULL, NULL); - - return g_strdup(tmp); -} - - /* initial_dir can be NULL to use the current working directory. * Returns: the selected filename */ gchar *win32_show_file_dialog(GtkWindow *parent, const gchar *title, const gchar *initial_file) @@ -576,135 +270,6 @@ gchar *win32_show_file_dialog(GtkWindow *parent, const gchar *title, const gchar }
-void win32_show_font_dialog(void) -{ - gint retval; - CHOOSEFONT cf; - LOGFONT lf; /* logical font structure */ - - memset(&lf, 0, sizeof lf); - /* TODO: init lf members */ - - memset(&cf, 0, sizeof cf); - cf.lStructSize = sizeof cf; - cf.hwndOwner = GDK_WINDOW_HWND(gtk_widget_get_window(main_widgets.window)); - cf.lpLogFont = &lf; - /* support CF_APPLY? */ - cf.Flags = CF_NOSCRIPTSEL | CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_ENABLEHOOK; - cf.lpfnHook = win32_dialog_hook_proc; - - retval = ChooseFont(&cf); - - if (retval) - { - gchar *editorfont = g_strdup_printf("%s %d", lf.lfFaceName, (cf.iPointSize / 10)); - ui_set_editor_font(editorfont); - g_free(editorfont); - } -} - - -void win32_show_color_dialog(const gchar *colour) -{ - CHOOSECOLOR cc; - static COLORREF acr_cust_clr[16]; - static DWORD rgb_current; - gchar *hex = g_malloc0(12); - GeanyDocument *doc = document_get_current(); - - /* Initialize CHOOSECOLOR */ - memset(&cc, 0, sizeof cc); - cc.lStructSize = sizeof(cc); - cc.hwndOwner = GDK_WINDOW_HWND(gtk_widget_get_window(main_widgets.window)); - cc.lpCustColors = (LPDWORD) acr_cust_clr; - cc.rgbResult = (colour != NULL) ? utils_parse_color_to_bgr(colour) : 0; - cc.Flags = CC_FULLOPEN | CC_RGBINIT | CC_ENABLEHOOK; - cc.lpfnHook = win32_dialog_hook_proc; - - if (ChooseColor(&cc)) - { - rgb_current = cc.rgbResult; - g_snprintf(hex, 11, "#%02X%02X%02X", - GetRValue(rgb_current), GetGValue(rgb_current), GetBValue(rgb_current)); - editor_insert_color(doc->editor, hex); - } - g_free(hex); -} - - -void win32_show_pref_file_dialog(GtkEntry *item) -{ - OPENFILENAMEW of; - gint retval, len; - wchar_t fname[MAX_PATH]; - gchar tmp[MAX_PATH]; - gchar **field, *filename; - - fname[0] = '\0'; - - /* cut the options from the command line */ - field = g_strsplit(gtk_entry_get_text(GTK_ENTRY(item)), " ", 2); - if (field[0]) - { - filename = g_find_program_in_path(field[0]); - if (filename != NULL && g_file_test(filename, G_FILE_TEST_EXISTS)) - { - MultiByteToWideChar(CP_UTF8, 0, filename, -1, fname, G_N_ELEMENTS(fname)); - g_free(filename); - } - } - - /* initialize file dialog info struct */ - memset(&of, 0, sizeof of); - of.lStructSize = sizeof of; - of.hwndOwner = GDK_WINDOW_HWND(gtk_widget_get_window(ui_widgets.prefs_dialog)); - - of.lpstrFilter = get_filters(FALSE); - of.lpstrCustomFilter = NULL; - of.nFilterIndex = 1; - - of.lpstrFile = fname; - of.nMaxFile = 2048; - of.lpstrFileTitle = NULL; - /*of.lpstrInitialDir = g_get_home_dir();*/ - of.lpstrInitialDir = NULL; - of.lpstrTitle = NULL; - of.lpstrDefExt = L"exe"; - of.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER | - OFN_ENABLEHOOK | OFN_ENABLESIZING; - of.lpfnHook = win32_dialog_explorer_hook_proc; - retval = GetOpenFileNameW(&of); - - if (!retval) - { - if (CommDlgExtendedError()) - { - gchar error[100]; - g_snprintf(error, sizeof error, "File dialog box error (%x)", (int)CommDlgExtendedError()); - win32_message_dialog(NULL, GTK_MESSAGE_ERROR, error); - } - g_strfreev(field); - return; - } - - len = WideCharToMultiByte(CP_UTF8, 0, fname, -1, tmp, sizeof(tmp), NULL, NULL); - if ((of.nFileOffset - 1) != len) - { - if (g_strv_length(field) > 1) - /* add the command line args of the old command */ - /** TODO this fails badly when the old command contained spaces, we need quoting here */ - filename = g_strconcat(tmp, " ", field[1], NULL); - else - { - filename = g_strdup(tmp); - } - gtk_entry_set_text(GTK_ENTRY(item), filename); - g_free(filename); - } - g_strfreev(field); -} - - /* Creates a native Windows message box of the given type and returns always TRUE * or FALSE representing th pressed Yes or No button. * If type is not GTK_MESSAGE_QUESTION, it returns always TRUE. */
Modified: src/win32.h 14 lines changed, 0 insertions(+), 14 deletions(-) =================================================================== @@ -30,26 +30,12 @@
G_BEGIN_DECLS
-void win32_show_pref_file_dialog(GtkEntry *item); - gchar *win32_show_file_dialog(GtkWindow *parent, const gchar *title, const gchar *initial_dir);
-gboolean win32_show_document_open_dialog(GtkWindow *parent, const gchar *title, const gchar *initial_dir); - -gchar *win32_show_document_save_as_dialog(GtkWindow *parent, const gchar *title, - GeanyDocument *doc); - -void win32_show_font_dialog(void); - -void win32_show_color_dialog(const gchar *colour); - gboolean win32_message_dialog(GtkWidget *parent, GtkMessageType type, const gchar *msg);
void win32_open_browser(const gchar *uri);
-gchar *win32_show_project_open_dialog(GtkWidget *parent, const gchar *title, - const gchar *initial_dir, gboolean allow_new_file, - gboolean project_file_filter);
gchar *win32_show_folder_dialog(GtkWidget *parent, const gchar *title, const gchar *initial_dir);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).