Use open folder dialog for project base path instead of create folder

dialog (better for choosing existing directories, and can still
create new folders).
Add optional title parameter for open dialog with ui_path_box_new()
and ui_setup_open_button_callback().
Use Windows folder dialog in ui_path_box_open_clicked().


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1526 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2007-05-11 16:34:18 +00:00
parent 479066fb19
commit 9570443c7b
5 changed files with 71 additions and 75 deletions

View File

@ -14,6 +14,13 @@
Prevent double loading of common styles when filetype none is used
before other filetypes.
Replace init_styles() with direct initialization of style_sets.
* src/ui_utils.h, src/project.c, src/search.c, src/ui_utils.c:
Use open folder dialog for project base path instead of create folder
dialog (better for choosing existing directories, and can still
create new folders).
Add optional title parameter for open dialog with ui_path_box_new()
and ui_setup_open_button_callback().
Use Windows folder dialog in ui_path_box_open_clicked().
2007-05-10 Nick Treleaven <nick.treleaven@btinternet.com>

View File

@ -68,7 +68,6 @@ typedef struct _PropertyDialogElements
static gboolean update_config(const PropertyDialogElements *e);
static void on_file_save_button_clicked(GtkButton *button, GtkWidget *entry);
static void on_folder_open_button_clicked(GtkButton *button, GtkWidget *entry);
static void on_file_open_button_clicked(GtkButton *button, GtkWidget *entry);
static gboolean close_open_project();
static gboolean load_config(const gchar *filename);
@ -165,14 +164,8 @@ void project_new()
gtk_tooltips_set_tip(tooltips, e->base_path,
_("Base directory of all files that make up the project. "
"This can be a new path, or an existing directory tree."), NULL);
button = gtk_button_new();
g_signal_connect((gpointer) button, "clicked",
G_CALLBACK(on_folder_open_button_clicked), e->base_path);
image = gtk_image_new_from_stock("gtk-open", GTK_ICON_SIZE_BUTTON);
gtk_container_add(GTK_CONTAINER(button), image);
bbox = gtk_hbox_new(FALSE, 6);
gtk_box_pack_start_defaults(GTK_BOX(bbox), e->base_path);
gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
bbox = ui_path_box_new(_("Choose Project Base Path"),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path));
gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 2, 3,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
@ -384,14 +377,8 @@ void project_properties()
gtk_tooltips_set_tip(tooltips, e->base_path,
_("Directory to run Make All from. "
"Leave blank to use the default command."), NULL);
button = gtk_button_new();
g_signal_connect((gpointer) button, "clicked",
G_CALLBACK(on_folder_open_button_clicked), e->base_path);
image = gtk_image_new_from_stock("gtk-open", GTK_ICON_SIZE_BUTTON);
gtk_container_add(GTK_CONTAINER(button), image);
bbox = gtk_hbox_new(FALSE, 6);
gtk_box_pack_start_defaults(GTK_BOX(bbox), e->base_path);
gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
bbox = ui_path_box_new(_("Choose Project Base Path"),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path));
gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 3, 4,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
@ -695,34 +682,6 @@ static void on_file_save_button_clicked(GtkButton *button, GtkWidget *entry)
}
static void on_folder_open_button_clicked(GtkButton *button, GtkWidget *entry)
{
#ifdef G_OS_WIN32
gchar *path = win32_show_project_folder_dialog(_("Choose Project Base Path"),
gtk_entry_get_text(GTK_ENTRY(entry)));
if (path != NULL)
{
gtk_entry_set_text(GTK_ENTRY(entry), path);
g_free(path);
}
#else
GtkWidget *dialog;
// initialise the dialog
dialog = gtk_file_chooser_dialog_new(_("Choose Project Base Path"), NULL,
GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
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_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
run_dialog(dialog, entry);
#endif
}
static void on_file_open_button_clicked(GtkButton *button, GtkWidget *entry)
{
#ifdef G_OS_WIN32
@ -939,8 +898,8 @@ void project_setup_prefs()
g_return_if_fail(local_prefs.project_file_path != NULL);
gtk_entry_set_text(GTK_ENTRY(path_entry), local_prefs.project_file_path);
ui_setup_open_button_callback(path_btn, GTK_ENTRY(path_entry),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
ui_setup_open_button_callback(path_btn, NULL,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(path_entry));
}

View File

@ -573,7 +573,8 @@ void search_show_find_in_files_dialog()
g_object_set_data_full(G_OBJECT(widgets.find_in_files_dialog), "dir_combo",
gtk_widget_ref(dir_combo), (GDestroyNotify)gtk_widget_unref);
dbox = ui_path_box_new(GTK_ENTRY(entry), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
dbox = ui_path_box_new(NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_ENTRY(entry));
gtk_box_pack_start(GTK_BOX(dbox), label1, FALSE, FALSE, 0);
label = gtk_label_new(_("Search for:"));

View File

@ -1124,8 +1124,8 @@ void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str)
/* Creates a GtkHBox with entry packed into it and an open button which runs a
* file chooser, replacing entry text if successful.
* entry can be the child of an unparented widget, such as GtkComboBoxEntry.
* action is the GtkFileChooser mode to use. */
GtkWidget *ui_path_box_new(GtkEntry *entry, GtkFileChooserAction action)
* See ui_setup_open_button_callback() for details. */
GtkWidget *ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry)
{
GtkWidget *vbox, *dirbtn, *openimg, *hbox, *path_entry;
@ -1146,7 +1146,7 @@ GtkWidget *ui_path_box_new(GtkEntry *entry, GtkFileChooserAction action)
dirbtn = gtk_button_new();
openimg = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
gtk_container_add(GTK_CONTAINER(dirbtn), openimg);
ui_setup_open_button_callback(dirbtn, entry, action);
ui_setup_open_button_callback(dirbtn, title, action, entry);
gtk_box_pack_end(GTK_BOX(hbox), dirbtn, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
@ -1158,40 +1158,35 @@ static void ui_path_box_open_clicked(GtkButton *button, gpointer user_data);
/* Setup a GtkButton to run a GtkFileChooser, setting entry text if successful.
* title can be NULL.
* action is the file chooser mode to use. */
void ui_setup_open_button_callback(GtkWidget *open_btn, GtkEntry *entry,
GtkFileChooserAction action)
void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title,
GtkFileChooserAction action, GtkEntry *entry)
{
GtkWidget *path_entry = GTK_WIDGET(entry);
g_object_set_data_full(G_OBJECT(open_btn), "entry",
gtk_widget_ref(path_entry), (GDestroyNotify)gtk_widget_unref);
if (title)
g_object_set_data_full(G_OBJECT(open_btn), "title",
g_strdup(title), (GDestroyNotify) g_free);
g_object_set_data(G_OBJECT(open_btn), "action", (gpointer) action);
g_object_set_data_full(G_OBJECT(open_btn), "entry",
gtk_widget_ref(path_entry), (GDestroyNotify) gtk_widget_unref);
g_signal_connect(G_OBJECT(open_btn), "clicked",
G_CALLBACK(ui_path_box_open_clicked), open_btn);
}
static void ui_path_box_open_clicked(GtkButton *button, gpointer user_data)
#ifndef G_OS_WIN32
static gchar *run_file_chooser(const gchar *title, GtkFileChooserAction action,
const gchar *utf8_path)
{
GtkWidget *path_box = GTK_WIDGET(user_data);
GtkFileChooserAction action =
(GtkFileChooserAction) g_object_get_data(G_OBJECT(path_box), "action");
GtkEntry *entry =
(GtkEntry *) g_object_get_data(G_OBJECT(path_box), "entry");
const gchar *title = (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ?
_("Select Folder") : _("Select File");
GtkWidget *dialog = gtk_file_chooser_dialog_new(title,
GTK_WINDOW(app->window), action,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
gchar *locale_path;
const gchar *utf8_path;
gchar *ret_path = NULL;
// TODO: extend for other actions
g_return_if_fail(action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
utf8_path = gtk_entry_get_text(GTK_ENTRY(entry));
locale_path = utils_get_locale_from_utf8(utf8_path);
if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
{
@ -1202,15 +1197,49 @@ static void ui_path_box_open_clicked(GtkButton *button, gpointer user_data)
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
{
gchar *dir_utf8, *dir_locale;
gchar *dir_locale;
dir_locale = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog));
dir_utf8 = utils_get_utf8_from_locale(dir_locale);
gtk_entry_set_text(GTK_ENTRY(entry), dir_utf8);
g_free(dir_utf8);
ret_path = utils_get_utf8_from_locale(dir_locale);
g_free(dir_locale);
}
gtk_widget_destroy(dialog);
return ret_path;
}
#endif
static void ui_path_box_open_clicked(GtkButton *button, gpointer user_data)
{
GtkWidget *path_box = GTK_WIDGET(user_data);
GtkFileChooserAction action =
(GtkFileChooserAction) g_object_get_data(G_OBJECT(path_box), "action");
GtkEntry *entry =
(GtkEntry *) g_object_get_data(G_OBJECT(path_box), "entry");
const gchar *title = g_object_get_data(G_OBJECT(path_box), "title");
gchar *utf8_path;
// TODO: extend for other actions
g_return_if_fail(action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
if (title == NULL)
title = (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ?
_("Select Folder") : _("Select File");
#ifdef G_OS_WIN32
utf8_path = win32_show_project_folder_dialog(title,
gtk_entry_get_text(GTK_ENTRY(entry)));
#else
utf8_path = run_file_chooser(title, action, gtk_entry_get_text(GTK_ENTRY(entry)));
#endif
if (utf8_path != NULL)
{
gtk_entry_set_text(GTK_ENTRY(entry), utf8_path);
g_free(utf8_path);
}
}
void ui_statusbar_showhide(gboolean state)
{

View File

@ -99,10 +99,10 @@ void ui_hbutton_box_copy_layout(GtkButtonBox *master, GtkButtonBox *copy);
void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text);
GtkWidget *ui_path_box_new(GtkEntry *entry, GtkFileChooserAction action);
GtkWidget *ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry);
void ui_setup_open_button_callback(GtkWidget *open_btn, GtkEntry *entry,
GtkFileChooserAction action);
void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title,
GtkFileChooserAction action, GtkEntry *entry);
void ui_update_tab_status(gint idx);