Fix no response with Project dialogs when the user enters invalid

information (oops).


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1469 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2007-04-21 16:27:38 +00:00
parent 492cc39a9e
commit c95b33301e
2 changed files with 164 additions and 153 deletions

View File

@ -2,6 +2,9 @@
* src/project.c, src/project.h, src/keyfile.c, src/main.c: * src/project.c, src/project.h, src/keyfile.c, src/main.c:
Restore the current project when restarting Geany. Restore the current project when restarting Geany.
* src/project.c:
Fix no response with Project dialogs when the user enters invalid
information (oops).
2007-04-20 Nick Treleaven <nick.treleaven@btinternet.com> 2007-04-20 Nick Treleaven <nick.treleaven@btinternet.com>

View File

@ -60,14 +60,10 @@ typedef struct _PropertyDialogElements
static void on_properties_dialog_response(GtkDialog *dialog, gint response, static gboolean update_config(const PropertyDialogElements *e);
PropertyDialogElements *e);
static void on_file_save_button_clicked(GtkButton *button, GtkWidget *entry); 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_folder_open_button_clicked(GtkButton *button, GtkWidget *entry);
static void on_file_open_button_clicked(GtkButton *button, GtkWidget *entry); static void on_file_open_button_clicked(GtkButton *button, GtkWidget *entry);
#ifndef G_OS_WIN32
static void on_open_dialog_response(GtkDialog *dialog, gint response, gpointer user_data);
#endif
static gboolean close_open_project(); static gboolean close_open_project();
static gboolean load_config(const gchar *filename); static gboolean load_config(const gchar *filename);
static gboolean write_config(); static gboolean write_config();
@ -186,11 +182,47 @@ void project_new()
g_signal_connect((gpointer) e->base_path, "changed", G_CALLBACK(on_entries_changed), e); g_signal_connect((gpointer) e->base_path, "changed", G_CALLBACK(on_entries_changed), e);
gtk_widget_show_all(e->dialog); gtk_widget_show_all(e->dialog);
retry:
response = gtk_dialog_run(GTK_DIALOG(e->dialog)); response = gtk_dialog_run(GTK_DIALOG(e->dialog));
on_properties_dialog_response(GTK_DIALOG(e->dialog), response, e); if (response == GTK_RESPONSE_OK)
if (! update_config(e))
goto retry;
gtk_widget_destroy(e->dialog);
g_free(e);
} }
#ifndef G_OS_WIN32
static void run_open_dialog(GtkDialog *dialog)
{
gint response;
retry:
response = gtk_dialog_run(dialog);
if (response == GTK_RESPONSE_ACCEPT)
{
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
// try to load the config
if (! project_load_file(filename))
{
gchar *utf8_filename = utils_get_utf8_from_locale(filename);
SHOW_ERR(_("Project file \"%s\" could not be loaded."), utf8_filename);
gtk_widget_grab_focus(GTK_WIDGET(dialog));
g_free(utf8_filename);
g_free(filename);
goto retry;
}
g_free(filename);
}
}
#endif
void project_open() void project_open()
{ {
gchar *dir = g_strconcat(GEANY_HOME_DIR, G_DIR_SEPARATOR_S, PROJECT_DIR, NULL); gchar *dir = g_strconcat(GEANY_HOME_DIR, G_DIR_SEPARATOR_S, PROJECT_DIR, NULL);
@ -199,7 +231,6 @@ void project_open()
#else #else
GtkWidget *dialog; GtkWidget *dialog;
GtkFileFilter *filter; GtkFileFilter *filter;
gint response;
#endif #endif
if (! close_open_project()) return; if (! close_open_project()) return;
@ -239,8 +270,8 @@ void project_open()
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir);
gtk_widget_show_all(dialog); gtk_widget_show_all(dialog);
response = gtk_dialog_run(GTK_DIALOG(dialog)); run_open_dialog(GTK_DIALOG(dialog));
on_open_dialog_response(GTK_DIALOG(dialog), response, NULL); gtk_widget_destroy(GTK_WIDGET(dialog));
#endif #endif
g_free(dir); g_free(dir);
@ -432,8 +463,15 @@ void project_properties()
gtk_entry_set_text(GTK_ENTRY(e->run_cmd), p->run_cmd); gtk_entry_set_text(GTK_ENTRY(e->run_cmd), p->run_cmd);
gtk_widget_show_all(e->dialog); gtk_widget_show_all(e->dialog);
retry:
response = gtk_dialog_run(GTK_DIALOG(e->dialog)); response = gtk_dialog_run(GTK_DIALOG(e->dialog));
on_properties_dialog_response(GTK_DIALOG(e->dialog), response, e); if (response == GTK_RESPONSE_OK)
if (! update_config(e))
goto retry;
gtk_widget_destroy(e->dialog);
g_free(e);
} }
@ -461,30 +499,30 @@ static gboolean close_open_project()
} }
/* Also used for New Project dialog response. */ /* Verifies data for New & Properties dialogs.
static void on_properties_dialog_response(GtkDialog *dialog, gint response, * Returns: FALSE if the user needs to change any data. */
PropertyDialogElements *e) static gboolean update_config(const PropertyDialogElements *e)
{ {
if (response == GTK_RESPONSE_OK && e != NULL)
{
const gchar *name, *file_name, *base_path; const gchar *name, *file_name, *base_path;
gint name_len; gint name_len;
gboolean new_project = FALSE; gboolean new_project = FALSE;
GeanyProject *p; GeanyProject *p;
g_return_val_if_fail(e != NULL, TRUE);
name = gtk_entry_get_text(GTK_ENTRY(e->name)); name = gtk_entry_get_text(GTK_ENTRY(e->name));
name_len = strlen(name); name_len = strlen(name);
if (name_len == 0) if (name_len == 0)
{ {
SHOW_ERR(_("The specified project name is too short.")); SHOW_ERR(_("The specified project name is too short."));
gtk_widget_grab_focus(e->name); gtk_widget_grab_focus(e->name);
return; return FALSE;
} }
else if (name_len > MAX_NAME_LEN) else if (name_len > MAX_NAME_LEN)
{ {
SHOW_ERR(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN); SHOW_ERR(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN);
gtk_widget_grab_focus(e->name); gtk_widget_grab_focus(e->name);
return; return FALSE;
} }
file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name)); file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name));
@ -492,7 +530,7 @@ static void on_properties_dialog_response(GtkDialog *dialog, gint response,
{ {
SHOW_ERR(_("You have specified an invalid project filename.")); SHOW_ERR(_("You have specified an invalid project filename."));
gtk_widget_grab_focus(e->file_name); gtk_widget_grab_focus(e->file_name);
return; return FALSE;
} }
base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path)); base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path));
@ -500,7 +538,7 @@ static void on_properties_dialog_response(GtkDialog *dialog, gint response,
{ {
SHOW_ERR(_("You have specified an invalid project base path.")); SHOW_ERR(_("You have specified an invalid project base path."));
gtk_widget_grab_focus(e->base_path); gtk_widget_grab_focus(e->base_path);
return; return FALSE;
} }
else else
{ // check whether the given directory actually exists { // check whether the given directory actually exists
@ -516,7 +554,7 @@ static void on_properties_dialog_response(GtkDialog *dialog, gint response,
{ {
g_free(locale_path); g_free(locale_path);
gtk_widget_grab_focus(e->base_path); gtk_widget_grab_focus(e->base_path);
return; return FALSE;
} }
} }
g_free(locale_path); g_free(locale_path);
@ -527,7 +565,7 @@ static void on_properties_dialog_response(GtkDialog *dialog, gint response,
{ {
SHOW_ERR(_("Project file could not be written.")); SHOW_ERR(_("Project file could not be written."));
gtk_widget_grab_focus(e->file_name); gtk_widget_grab_focus(e->file_name);
return; return FALSE;
} }
if (app->project == NULL) if (app->project == NULL)
@ -576,10 +614,8 @@ static void on_properties_dialog_response(GtkDialog *dialog, gint response,
msgwin_status_add(_("Project \"%s\" created."), p->name); msgwin_status_add(_("Project \"%s\" created."), p->name);
else else
msgwin_status_add(_("Project \"%s\" saved."), p->name); msgwin_status_add(_("Project \"%s\" saved."), p->name);
}
gtk_widget_destroy(GTK_WIDGET(dialog)); return TRUE;
g_free(e);
} }
@ -747,34 +783,6 @@ static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e)
} }
#ifndef G_OS_WIN32
static void on_open_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
{
if (response == GTK_RESPONSE_ACCEPT)
{
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
// try to load the config
if (project_load_file(filename))
{
gtk_widget_destroy(GTK_WIDGET(dialog));
}
else
{
gchar *utf8_filename = utils_get_utf8_from_locale(filename);
SHOW_ERR(_("Project file \"%s\" could not be loaded."), utf8_filename);
gtk_widget_grab_focus(GTK_WIDGET(dialog));
g_free(utf8_filename);
}
g_free(filename);
}
else
gtk_widget_destroy(GTK_WIDGET(dialog));
}
#endif
gboolean project_load_file(const gchar *locale_file_name) gboolean project_load_file(const gchar *locale_file_name)
{ {
g_return_val_if_fail(locale_file_name != NULL, FALSE); g_return_val_if_fail(locale_file_name != NULL, FALSE);