|
6 | 6 | public class Music.MainWindow : Gtk.ApplicationWindow { |
7 | 7 | public const string ACTION_PREFIX = "win."; |
8 | 8 | public const string ACTION_OPEN = "action-open"; |
| 9 | + public const string ACTION_OPEN_FOLDER = "action-open-folder"; |
9 | 10 |
|
10 | 11 | private QueueView queue_view; |
11 | 12 |
|
@@ -61,8 +62,13 @@ public class Music.MainWindow : Gtk.ApplicationWindow { |
61 | 62 | open_action.activate.connect (open_files); |
62 | 63 | add_action (open_action); |
63 | 64 |
|
| 65 | + var open_folder_action = new SimpleAction (ACTION_OPEN_FOLDER, null); |
| 66 | + open_folder_action.activate.connect (open_folder); |
| 67 | + add_action (open_folder_action); |
| 68 | + |
64 | 69 | unowned var app = ((Gtk.Application) GLib.Application.get_default ()); |
65 | 70 | app.set_accels_for_action (ACTION_PREFIX + ACTION_OPEN, {"<Ctrl>O"}); |
| 71 | + app.set_accels_for_action (ACTION_PREFIX + ACTION_OPEN_FOLDER, {"<Ctrl><Shift>O"}); |
66 | 72 | } |
67 | 73 |
|
68 | 74 | public void start_search () { |
@@ -96,30 +102,59 @@ public class Music.MainWindow : Gtk.ApplicationWindow { |
96 | 102 | try { |
97 | 103 | var files = file_dialog.open_multiple.end (res); |
98 | 104 |
|
99 | | - File[] file_array = {}; |
100 | | - for (int i = 0; i < files.get_n_items (); i++) { |
101 | | - file_array += (File)(files.get_item (i)); |
102 | | - } |
| 105 | + handle_selected_files (files); |
| 106 | + } catch (Error e) { |
| 107 | + handle_file_dialog_error (e); |
| 108 | + } |
| 109 | + }); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Same as open_files, except there is not filter and it uses the Folder dialog : |
| 114 | + * No folder/file is pre-selected when entering a directory and individual files cannot be selected |
| 115 | + */ |
| 116 | + private void open_folder () { |
| 117 | + var file_dialog = new Gtk.FileDialog () { |
| 118 | + accept_label = _("Open"), |
| 119 | + modal = true, |
| 120 | + title = _("Open folder(s) containing audio files") |
| 121 | + }; |
| 122 | + |
| 123 | + file_dialog.select_multiple_folders.begin (this, null, (obj, res) => { |
| 124 | + try { |
| 125 | + var folders = file_dialog.select_multiple_folders.end (res); |
103 | 126 |
|
104 | | - var files_to_play = Application.loop_through_files (file_array); |
105 | | - PlaybackManager.get_default ().queue_files (files_to_play); |
| 127 | + handle_selected_files (folders); |
106 | 128 | } catch (Error e) { |
107 | | - if (e.matches (Gtk.DialogError.quark (), Gtk.DialogError.DISMISSED)) { |
108 | | - return; |
109 | | - } |
110 | | - |
111 | | - var dialog = new Granite.MessageDialog ( |
112 | | - _("Couldn't add audio files"), |
113 | | - e.message, |
114 | | - new ThemedIcon ("document-open") |
115 | | - ) { |
116 | | - badge_icon = new ThemedIcon ("dialog-error"), |
117 | | - modal = true, |
118 | | - transient_for = this |
119 | | - }; |
120 | | - dialog.present (); |
121 | | - dialog.response.connect (dialog.destroy); |
| 129 | + handle_file_dialog_error (e); |
122 | 130 | } |
123 | 131 | }); |
124 | 132 | } |
| 133 | + |
| 134 | + private void handle_selected_files (GLib.ListModel files) { |
| 135 | + File[] file_array = {}; |
| 136 | + for (int i = 0; i < files.get_n_items (); i++) { |
| 137 | + file_array += (File)(files.get_item (i)); |
| 138 | + } |
| 139 | + var files_to_play = Application.loop_through_files (file_array); |
| 140 | + PlaybackManager.get_default ().queue_files (files_to_play); |
| 141 | + } |
| 142 | + |
| 143 | + private void handle_file_dialog_error (Error e) { |
| 144 | + if (e.matches (Gtk.DialogError.quark (), Gtk.DialogError.DISMISSED)) { |
| 145 | + return; |
| 146 | + } |
| 147 | + |
| 148 | + var dialog = new Granite.MessageDialog ( |
| 149 | + _("Couldn't add audio files"), |
| 150 | + e.message, |
| 151 | + new ThemedIcon ("document-open") |
| 152 | + ) { |
| 153 | + badge_icon = new ThemedIcon ("dialog-error"), |
| 154 | + modal = true, |
| 155 | + transient_for = this |
| 156 | + }; |
| 157 | + dialog.present (); |
| 158 | + dialog.response.connect (dialog.destroy); |
| 159 | + } |
125 | 160 | } |
0 commit comments