Skip to content

Commit

Permalink
Merge pull request #327 from ntrel/open-file-exists
Browse files Browse the repository at this point in the history
Allow user to edit open dialog filename when file doesn't exist
  • Loading branch information
ntrel committed Sep 1, 2014
2 parents d2ce3d6 + 7047152 commit a733bf9
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/dialogs.c
Expand Up @@ -123,8 +123,10 @@ static void file_chooser_set_filter_idx(GtkFileChooser *chooser, guint idx)
}


static void open_file_dialog_handle_response(GtkWidget *dialog, gint response)
static gboolean open_file_dialog_handle_response(GtkWidget *dialog, gint response)
{
gboolean ret = TRUE;

if (response == GTK_RESPONSE_ACCEPT || response == GEANY_RESPONSE_VIEW)
{
GSList *filelist;
Expand All @@ -150,14 +152,26 @@ static void open_file_dialog_handle_response(GtkWidget *dialog, gint response)
filelist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
if (filelist != NULL)
{
document_open_files(filelist, ro, ft, charset);
const gchar *first = filelist->data;

// When there's only one filename it may have been typed manually
if (!filelist->next && !g_file_test(first, G_FILE_TEST_EXISTS))
{
dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("\"%s\" was not found."), first);
ret = FALSE;
}
else
{
document_open_files(filelist, ro, ft, charset);
}
g_slist_foreach(filelist, (GFunc) g_free, NULL); /* free filenames */
}
g_slist_free(filelist);
}
if (app->project && !EMPTY(app->project->base_path))
gtk_file_chooser_remove_shortcut_folder(GTK_FILE_CHOOSER(dialog),
app->project->base_path, NULL);
return ret;
}


Expand Down Expand Up @@ -456,7 +470,6 @@ void dialogs_show_open_file(void)
#endif
{
GtkWidget *dialog = create_open_file_dialog();
gint response;

open_file_dialog_apply_settings(dialog);

Expand All @@ -467,8 +480,8 @@ void dialogs_show_open_file(void)
gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog),
app->project->base_path, NULL);

response = gtk_dialog_run(GTK_DIALOG(dialog));
open_file_dialog_handle_response(dialog, response);
while (!open_file_dialog_handle_response(dialog,
gtk_dialog_run(GTK_DIALOG(dialog))));
gtk_widget_destroy(dialog);
}
g_free(initdir);
Expand Down

0 comments on commit a733bf9

Please sign in to comment.