Skip to content

Commit

Permalink
[window] in open file dialog use folder of currently open file, fix #43
Browse files Browse the repository at this point in the history
If there is already an open file and the user wants to open another file,
use the currently open file's folder as a preset in the dialog. Otherwise
set it to the user's home folder.
  • Loading branch information
gkarsay committed Aug 31, 2018
1 parent 2111c33 commit 111cd6a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/pt-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ open_cb (GSimpleAction *action,
GtkWidget *dialog;
GtkWindow *win;
const char *home_path;
GFile *home;
gchar *current_uri = NULL;
GFile *current, *dir;
GtkFileFilter *filter_audio;
GtkFileFilter *filter_all;
gchar *uri = NULL;
Expand All @@ -135,10 +136,20 @@ open_cb (GSimpleAction *action,
_("_Open"), GTK_RESPONSE_ACCEPT,
NULL);

/* Set current folder to user's home directory */
home_path = g_get_home_dir ();
home = g_file_new_for_path (home_path);
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog), home, NULL);
/* Set current folder to the folder with the currently open file
or to user's home directory */
current_uri = pt_window_get_uri (PT_WINDOW (win));
if (current_uri) {
current = g_file_new_for_uri (current_uri);
dir = g_file_get_parent (current);
g_free (current_uri);
g_object_unref (current);
} else {
home_path = g_get_home_dir ();
dir = g_file_new_for_path (home_path);
}
gtk_file_chooser_set_current_folder_file (
GTK_FILE_CHOOSER (dialog), dir, NULL);

filter_audio = gtk_file_filter_new ();
filter_all = gtk_file_filter_new ();
Expand All @@ -154,7 +165,7 @@ open_cb (GSimpleAction *action,
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
}

g_object_unref (home);
g_object_unref (dir);
gtk_widget_destroy (dialog);

if (uri) {
Expand Down
6 changes: 6 additions & 0 deletions src/pt-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@ open_cb (PtPlayer *player,
pt_window_ready_to_play (win, TRUE);
}

gchar*
pt_window_get_uri (PtWindow *win)
{
return pt_player_get_uri (win->priv->player);
}

void
pt_window_open_file (PtWindow *win,
gchar *uri)
Expand Down
2 changes: 2 additions & 0 deletions src/pt-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void pt_error_message (PtWindow *parent,
void pt_window_open_file (PtWindow *win,
gchar *uri);

gchar *pt_window_get_uri (PtWindow *win);

PtWindow *pt_window_new (PtApp *app);

#endif

0 comments on commit 111cd6a

Please sign in to comment.