Merge lp:~tintou/scratch/filemanager into lp:~elementary-apps/scratch/scratch
- filemanager
- Merge into scratch
Status: | Rejected |
---|---|
Rejected by: | Zisu Andrei |
Proposed branch: | lp:~tintou/scratch/filemanager |
Merge into: | lp:~elementary-apps/scratch/scratch |
Diff against target: |
1566 lines (+330/-994) 19 files modified
plugins/CMakeLists.txt (+0/-1) plugins/filemanager/CMakeLists.txt (+2/-0) plugins/filemanager/File.vala (+3/-3) plugins/filemanager/FileItem.vala (+52/-0) plugins/filemanager/FileManagerPlugin.vala (+68/-46) plugins/filemanager/FileView.vala (+39/-210) plugins/filemanager/FolderItem.vala (+154/-0) plugins/filemanager/Settings.vala (+1/-1) plugins/folder-manager/CMakeLists.txt (+0/-29) plugins/folder-manager/File.vala (+0/-207) plugins/folder-manager/FileView.vala (+0/-312) plugins/folder-manager/FolderManagerPlugin.vala (+0/-122) plugins/folder-manager/Settings.vala (+0/-36) plugins/folder-manager/folder-manager.plugin (+0/-10) plugins/outline/OutlinePlugin.vala (+4/-1) plugins/source-tree/SourceTreePlugin.vala (+3/-1) schemas/CMakeLists.txt (+0/-1) schemas/org.pantheon.scratch.plugins.file-manager.gschema.xml (+4/-4) schemas/org.pantheon.scratch.plugins.folder-manager.gschema.xml (+0/-10) |
To merge this branch: | bzr merge lp:~tintou/scratch/filemanager |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danielle Foré | ux | Needs Fixing | |
Zisu Andrei (community) | Needs Fixing | ||
Review via email: mp+304845@code.launchpad.net |
Commit message
Description of the change
- 1748. By Corentin Noël
-
Fix CMake warnings in the plugins
Corentin Noël (tintou) wrote : | # |
Aaand it's ready for a new review.
Danielle Foré (danrabbit) wrote : | # |
Hm, unsure what the intended behavior is here. After installing this branch, the File Manager plugin appears to be completely empty and do nothing. I don't notice any changes to the Folder Manager plugin.
Danielle Foré (danrabbit) wrote : | # |
This is definitely needs fixing on UX:
* It seems like you can only add one folder at a time. I really think the button to add a folder in the headerbar needs to come back. It's simple and obvious.
* Having this welcome screen in the sidebar is really bad. Especially if you don't have a file open you can have two welcome screens side-by-side. This is a pretty big annoyance from the previous behavior where it was possible to not have any folders open. This new behavior requires turning the plugin on and off. It's really annoying.
- 1749. By Corentin Noël
-
Unified the file manager and folder manager.
Danielle Foré (danrabbit) wrote : | # |
This is way better than it was before.
One thing I still don't like is the open folder button disappearing from the headerbar. I don't like the actions moving around like this. It means that once I perform the action I now have to go hunt to figure out how to perform that action again. The UI is not predictable.
Zisu Andrei (matzipan) wrote : | # |
Rejected because I branched and wrapped up the changes here: https:/
Unmerged revisions
- 1749. By Corentin Noël
-
Unified the file manager and folder manager.
Preview Diff
1 | === modified file 'plugins/CMakeLists.txt' | |||
2 | --- plugins/CMakeLists.txt 2016-09-03 10:30:53 +0000 | |||
3 | +++ plugins/CMakeLists.txt 2016-09-03 22:26:31 +0000 | |||
4 | @@ -8,7 +8,6 @@ | |||
5 | 8 | add_subdirectory (contractor) | 8 | add_subdirectory (contractor) |
6 | 9 | add_subdirectory (pastebin) | 9 | add_subdirectory (pastebin) |
7 | 10 | add_subdirectory (filemanager) | 10 | add_subdirectory (filemanager) |
8 | 11 | add_subdirectory (folder-manager) | ||
9 | 12 | add_subdirectory (terminal) | 11 | add_subdirectory (terminal) |
10 | 13 | add_subdirectory (browser-preview) | 12 | add_subdirectory (browser-preview) |
11 | 14 | add_subdirectory (strip-trailing-save) | 13 | add_subdirectory (strip-trailing-save) |
12 | 15 | 14 | ||
13 | === modified file 'plugins/filemanager/CMakeLists.txt' | |||
14 | --- plugins/filemanager/CMakeLists.txt 2016-09-03 10:30:53 +0000 | |||
15 | +++ plugins/filemanager/CMakeLists.txt 2016-09-03 22:26:31 +0000 | |||
16 | @@ -8,6 +8,8 @@ | |||
17 | 8 | File.vala | 8 | File.vala |
18 | 9 | Settings.vala | 9 | Settings.vala |
19 | 10 | FileView.vala | 10 | FileView.vala |
20 | 11 | FileItem.vala | ||
21 | 12 | FolderItem.vala | ||
22 | 11 | PACKAGES | 13 | PACKAGES |
23 | 12 | gtk+-3.0 | 14 | gtk+-3.0 |
24 | 13 | gee-0.8 | 15 | gee-0.8 |
25 | 14 | 16 | ||
26 | === modified file 'plugins/filemanager/File.vala' | |||
27 | --- plugins/filemanager/File.vala 2013-07-16 15:56:38 +0000 | |||
28 | +++ plugins/filemanager/File.vala 2016-09-03 22:26:31 +0000 | |||
29 | @@ -23,7 +23,7 @@ | |||
30 | 23 | /** | 23 | /** |
31 | 24 | * Class for easily dealing with files. | 24 | * Class for easily dealing with files. |
32 | 25 | */ | 25 | */ |
34 | 26 | internal class File : GLib.Object { | 26 | public class File : GLib.Object { |
35 | 27 | 27 | ||
36 | 28 | public GLib.File file; | 28 | public GLib.File file; |
37 | 29 | private GLib.FileInfo info; | 29 | private GLib.FileInfo info; |
38 | @@ -179,13 +179,13 @@ | |||
39 | 179 | } | 179 | } |
40 | 180 | } | 180 | } |
41 | 181 | 181 | ||
43 | 182 | /*public void trash () { | 182 | public void trash () { |
44 | 183 | try { | 183 | try { |
45 | 184 | file.trash (); | 184 | file.trash (); |
46 | 185 | } catch (GLib.Error error) { | 185 | } catch (GLib.Error error) { |
47 | 186 | warning (error.message); | 186 | warning (error.message); |
48 | 187 | } | 187 | } |
50 | 188 | }*/ | 188 | } |
51 | 189 | 189 | ||
52 | 190 | public void reset_cache () { | 190 | public void reset_cache () { |
53 | 191 | _name = null; | 191 | _name = null; |
54 | 192 | 192 | ||
55 | === added file 'plugins/filemanager/FileItem.vala' | |||
56 | --- plugins/filemanager/FileItem.vala 1970-01-01 00:00:00 +0000 | |||
57 | +++ plugins/filemanager/FileItem.vala 2016-09-03 22:26:31 +0000 | |||
58 | @@ -0,0 +1,52 @@ | |||
59 | 1 | // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- | ||
60 | 2 | /*- | ||
61 | 3 | * Copyright (c) 2016 elementary LLC. (https://elementary.io) | ||
62 | 4 | * | ||
63 | 5 | * This program is free software: you can redistribute it and/or modify | ||
64 | 6 | * it under the terms of the GNU General Public License as published by | ||
65 | 7 | * the Free Software Foundation, either version 3 of the License, or | ||
66 | 8 | * (at your option) any later version. | ||
67 | 9 | * | ||
68 | 10 | * This program is distributed in the hope that it will be useful, | ||
69 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
70 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
71 | 13 | * GNU General Public License for more details. | ||
72 | 14 | * | ||
73 | 15 | * You should have received a copy of the GNU General Public License | ||
74 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
75 | 17 | * | ||
76 | 18 | * Authored by: Corentin Noël <corentin@elementary.io> | ||
77 | 19 | */ | ||
78 | 20 | |||
79 | 21 | public class Scratch.Plugins.FileManager.FileItem : Item { | ||
80 | 22 | public FileItem (Scratch.Plugins.FileManager.File file, Scratch.Plugins.FileManager.FileView view) requires (file.is_valid_textfile) { | ||
81 | 23 | Object (file: file, view: view); | ||
82 | 24 | |||
83 | 25 | this.selectable = true; | ||
84 | 26 | this.editable = true; | ||
85 | 27 | this.name = file.name; | ||
86 | 28 | this.icon = file.icon; | ||
87 | 29 | } | ||
88 | 30 | |||
89 | 31 | public override Gtk.Menu? get_context_menu () { | ||
90 | 32 | var menu = new Gtk.Menu (); | ||
91 | 33 | var open_item = new Gtk.MenuItem.with_label (_("Rename")); | ||
92 | 34 | open_item.activate.connect (() => view.start_editing_item (this)); | ||
93 | 35 | menu.append (open_item); | ||
94 | 36 | var delete_item = new Gtk.MenuItem.with_label (_("Move to Trash")); | ||
95 | 37 | delete_item.activate.connect (() => do_remove ()); | ||
96 | 38 | menu.append (delete_item); | ||
97 | 39 | menu.show_all (); | ||
98 | 40 | return menu; | ||
99 | 41 | } | ||
100 | 42 | |||
101 | 43 | public void rename (string new_name) { | ||
102 | 44 | string new_uri = file.file.get_parent ().get_uri () + "/" + new_name; | ||
103 | 45 | debug (new_uri); | ||
104 | 46 | file.rename (new_name); | ||
105 | 47 | } | ||
106 | 48 | |||
107 | 49 | private void do_remove () { | ||
108 | 50 | file.trash (); | ||
109 | 51 | } | ||
110 | 52 | } | ||
111 | 0 | 53 | ||
112 | === modified file 'plugins/filemanager/FileManagerPlugin.vala' | |||
113 | --- plugins/filemanager/FileManagerPlugin.vala 2016-09-03 11:50:58 +0000 | |||
114 | +++ plugins/filemanager/FileManagerPlugin.vala 2016-09-03 22:26:31 +0000 | |||
115 | @@ -24,9 +24,9 @@ | |||
116 | 24 | namespace Scratch.Plugins { | 24 | namespace Scratch.Plugins { |
117 | 25 | public class FileManagerPlugin : Peas.ExtensionBase, Peas.Activatable { | 25 | public class FileManagerPlugin : Peas.ExtensionBase, Peas.Activatable { |
118 | 26 | public Scratch.Services.Interface plugins; | 26 | public Scratch.Services.Interface plugins; |
121 | 27 | 27 | Gtk.Button button; | |
120 | 28 | Gtk.Box box; | ||
122 | 29 | FileManager.FileView view; | 28 | FileManager.FileView view; |
123 | 29 | Gtk.Grid main_grid; | ||
124 | 30 | 30 | ||
125 | 31 | public Object object { owned get; construct; } | 31 | public Object object { owned get; construct; } |
126 | 32 | 32 | ||
127 | @@ -37,11 +37,19 @@ | |||
128 | 37 | public void activate () { | 37 | public void activate () { |
129 | 38 | plugins = (Scratch.Services.Interface) object; | 38 | plugins = (Scratch.Services.Interface) object; |
130 | 39 | plugins.hook_notebook_sidebar.connect (on_hook_sidebar); | 39 | plugins.hook_notebook_sidebar.connect (on_hook_sidebar); |
131 | 40 | plugins.hook_toolbar.connect (on_hook_toolbar); | ||
132 | 40 | } | 41 | } |
133 | 41 | 42 | ||
134 | 42 | public void deactivate () { | 43 | public void deactivate () { |
137 | 43 | if (box != null) | 44 | if (main_grid != null) { |
138 | 44 | box.destroy(); | 45 | main_grid.destroy(); |
139 | 46 | main_grid = null; | ||
140 | 47 | } | ||
141 | 48 | |||
142 | 49 | if (button != null) { | ||
143 | 50 | button.destroy(); | ||
144 | 51 | button = null; | ||
145 | 52 | } | ||
146 | 45 | } | 53 | } |
147 | 46 | 54 | ||
148 | 47 | public void update_state () { | 55 | public void update_state () { |
149 | @@ -49,59 +57,73 @@ | |||
150 | 49 | } | 57 | } |
151 | 50 | 58 | ||
152 | 51 | void on_hook_sidebar (Gtk.Notebook notebook) { | 59 | void on_hook_sidebar (Gtk.Notebook notebook) { |
154 | 52 | if (view != null) | 60 | if (main_grid != null) |
155 | 53 | return; | 61 | return; |
156 | 54 | 62 | ||
157 | 55 | box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); | ||
158 | 56 | |||
159 | 57 | // File View | 63 | // File View |
160 | 58 | view = new FileManager.FileView (); | 64 | view = new FileManager.FileView (); |
165 | 59 | 65 | view.select.connect ((file) => plugins.open_file (file)); | |
166 | 60 | view.select.connect ((a) => { | 66 | view.welcome_visible.connect ((visible) => { |
167 | 61 | var file = GLib.File.new_for_path (a); | 67 | if (visible) { |
168 | 62 | plugins.open_file (file); | 68 | button.no_show_all = false; |
169 | 69 | button.show_all (); | ||
170 | 70 | main_grid.parent.remove (main_grid); | ||
171 | 71 | } else if (main_grid.parent == null) { | ||
172 | 72 | button.no_show_all = true; | ||
173 | 73 | button.hide (); | ||
174 | 74 | main_grid.show_all (); | ||
175 | 75 | var icon = new Gtk.Image.from_icon_name ("folder-symbolic", Gtk.IconSize.MENU); | ||
176 | 76 | icon.tooltip_text = _("File Manager"); | ||
177 | 77 | notebook.append_page (main_grid, icon); | ||
178 | 78 | } | ||
179 | 63 | }); | 79 | }); |
180 | 64 | 80 | ||
181 | 65 | // Toolbar | ||
182 | 66 | var toolbar = new Gtk.Toolbar (); | 81 | var toolbar = new Gtk.Toolbar (); |
183 | 67 | toolbar.set_icon_size (Gtk.IconSize.SMALL_TOOLBAR); | 82 | toolbar.set_icon_size (Gtk.IconSize.SMALL_TOOLBAR); |
196 | 68 | toolbar.get_style_context ().add_class ("inline-toolbar"); | 83 | toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_INLINE_TOOLBAR); |
185 | 69 | |||
186 | 70 | var parent = new Gtk.ToolButton (null, null); | ||
187 | 71 | parent.tooltip_text = _("Go to parent"); | ||
188 | 72 | parent.icon_name = "go-up-symbolic"; | ||
189 | 73 | parent.clicked.connect (() => { | ||
190 | 74 | view.open_parent (); | ||
191 | 75 | parent.sensitive = !(view.folder.file.file.get_path () == "/"); | ||
192 | 76 | }); | ||
193 | 77 | |||
194 | 78 | var spacer = new Gtk.ToolItem (); | ||
195 | 79 | spacer.set_expand (true); | ||
197 | 80 | 84 | ||
198 | 81 | var add = new Gtk.ToolButton (null, null); | 85 | var add = new Gtk.ToolButton (null, null); |
200 | 82 | add.tooltip_text = _("Add file"); | 86 | add.tooltip_text = _("Add a folder"); |
201 | 83 | add.icon_name = "list-add-symbolic"; | 87 | add.icon_name = "list-add-symbolic"; |
223 | 84 | add.clicked.connect (() => { | 88 | add.clicked.connect (() => open_dialog ()); |
224 | 85 | view.add_file (); | 89 | |
225 | 86 | }); | 90 | toolbar.add (add); |
226 | 87 | 91 | ||
227 | 88 | var remove = new Gtk.ToolButton (null, null); | 92 | main_grid = new Gtk.Grid (); |
228 | 89 | remove.tooltip_text = _("Remove file"); | 93 | main_grid.orientation = Gtk.Orientation.VERTICAL; |
229 | 90 | remove.icon_name = "edit-delete-symbolic"; | 94 | main_grid.add (view); |
230 | 91 | remove.clicked.connect (() => { | 95 | main_grid.add (toolbar); |
231 | 92 | view.remove_file (); | 96 | |
232 | 93 | }); | 97 | view.restore_settings (); |
233 | 94 | 98 | } | |
234 | 95 | toolbar.insert (parent, -1); | 99 | |
235 | 96 | toolbar.insert (spacer, -1); | 100 | void on_hook_toolbar (Gtk.HeaderBar toolbar) { |
236 | 97 | toolbar.insert (add, -1); | 101 | if (button != null) |
237 | 98 | toolbar.insert (remove, -1); | 102 | return; |
238 | 99 | 103 | ||
239 | 100 | box.pack_start (view, true, true, 0); | 104 | button = new Gtk.Button.from_icon_name ("folder-saved-search", Gtk.IconSize.LARGE_TOOLBAR); |
240 | 101 | box.pack_start (toolbar, false, false, 0); | 105 | button.tooltip_text = _("Open a folder"); |
241 | 102 | box.show_all (); | 106 | button.clicked.connect (() => open_dialog ()); |
242 | 103 | 107 | button.show_all (); | |
243 | 104 | notebook.append_page (box, new Gtk.Label (_("File Manager"))); | 108 | toolbar.pack_start (button); |
244 | 109 | } | ||
245 | 110 | |||
246 | 111 | private void open_dialog () { | ||
247 | 112 | Gtk.Window window = plugins.manager.window; | ||
248 | 113 | Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog ( | ||
249 | 114 | "Select a folder.", window, Gtk.FileChooserAction.SELECT_FOLDER, | ||
250 | 115 | _("_Cancel"), Gtk.ResponseType.CANCEL, | ||
251 | 116 | _("_Open"), Gtk.ResponseType.ACCEPT); | ||
252 | 117 | chooser.select_multiple = true; | ||
253 | 118 | |||
254 | 119 | if (chooser.run () == Gtk.ResponseType.ACCEPT) { | ||
255 | 120 | chooser.get_files ().foreach ((file) => { | ||
256 | 121 | var folder = new Scratch.Plugins.FileManager.File (file.get_path ()); | ||
257 | 122 | view.open_folder (folder); | ||
258 | 123 | }); | ||
259 | 124 | } | ||
260 | 125 | |||
261 | 126 | chooser.close (); | ||
262 | 105 | } | 127 | } |
263 | 106 | } | 128 | } |
264 | 107 | } | 129 | } |
265 | 108 | 130 | ||
266 | === modified file 'plugins/filemanager/FileView.vala' | |||
267 | --- plugins/filemanager/FileView.vala 2016-09-03 11:50:58 +0000 | |||
268 | +++ plugins/filemanager/FileView.vala 2016-09-03 22:26:31 +0000 | |||
269 | @@ -24,30 +24,30 @@ | |||
270 | 24 | /** | 24 | /** |
271 | 25 | * SourceList that displays folders and their contents. | 25 | * SourceList that displays folders and their contents. |
272 | 26 | */ | 26 | */ |
276 | 27 | internal class FileView : Granite.Widgets.SourceList { | 27 | public class FileView : Granite.Widgets.SourceList { |
277 | 28 | public FolderItem? folder = null; | 28 | public signal void select (GLib.File file); |
278 | 29 | public signal void select (string file); | 29 | public signal void welcome_visible (bool visible); |
279 | 30 | public FileView () { | 30 | public FileView () { |
281 | 31 | this.width_request = 180; | 31 | width_request = 180; |
282 | 32 | 32 | ||
285 | 33 | this.item_selected.connect ((item) => { | 33 | item_selected.connect ((item) => { |
286 | 34 | select ((item as FileItem).path); | 34 | if (item is FileItem) { |
287 | 35 | select ((item as FileItem).file.file); | ||
288 | 36 | } | ||
289 | 35 | }); | 37 | }); |
290 | 36 | 38 | ||
292 | 37 | this.root.child_removed.connect (() => { | 39 | root.child_removed.connect (() => { |
293 | 38 | this.selected = null; | 40 | this.selected = null; |
294 | 41 | if (root.n_children == 0) { | ||
295 | 42 | welcome_visible (true); | ||
296 | 43 | } | ||
297 | 44 | |||
298 | 45 | write_settings (); | ||
299 | 39 | }); | 46 | }); |
300 | 40 | 47 | ||
301 | 41 | settings = new Settings (); | 48 | settings = new Settings (); |
302 | 42 | restore_settings (); | ||
303 | 43 | } | 49 | } |
304 | 44 | 50 | ||
305 | 45 | public void open_parent () { | ||
306 | 46 | GLib.File parent = this.folder.file.file.get_parent (); | ||
307 | 47 | this.root.remove (this.folder); | ||
308 | 48 | open_folder (new File (parent.get_path ())); | ||
309 | 49 | } | ||
310 | 50 | |||
311 | 51 | public void open_folder (File folder, bool expand = true) { | 51 | public void open_folder (File folder, bool expand = true) { |
312 | 52 | if (is_open (folder)) { | 52 | if (is_open (folder)) { |
313 | 53 | warning ("Folder '%s' is already open.", folder.path); | 53 | warning ("Folder '%s' is already open.", folder.path); |
314 | @@ -57,49 +57,25 @@ | |||
315 | 57 | return; | 57 | return; |
316 | 58 | } | 58 | } |
317 | 59 | 59 | ||
327 | 60 | // Clean the SourceList before start adding something | 60 | var folder_item = new FolderItem (folder, this); |
328 | 61 | if (this.folder != null) { | 61 | root.add (folder_item); |
329 | 62 | this.root.remove (this.folder); | 62 | welcome_visible (false); |
330 | 63 | } | 63 | |
331 | 64 | 64 | folder_item.expanded = expand; | |
323 | 65 | this.folder = new FolderItem (folder, this); | ||
324 | 66 | this.root.add (this.folder); | ||
325 | 67 | |||
326 | 68 | this.folder.expanded = expand; | ||
332 | 69 | write_settings (); | 65 | write_settings (); |
333 | 70 | } | 66 | } |
366 | 71 | 67 | ||
367 | 72 | public void add_file () { | 68 | public void restore_settings () { |
368 | 73 | string path = folder.file.file.get_path () + _("/New File"); | 69 | foreach (var folder_path in settings.opened_folders) { |
369 | 74 | var file = GLib.File.new_for_path (path); | 70 | if (folder_path == null) { |
370 | 75 | int n = 1; | 71 | continue; |
371 | 76 | while (file.query_exists ()) { | 72 | } |
372 | 77 | file = GLib.File.new_for_path (path + n.to_string ()); | 73 | |
373 | 78 | n++; | 74 | var folder = new File (folder_path); |
374 | 79 | } | 75 | if (folder.is_valid_directory) { |
375 | 80 | 76 | open_folder (folder); | |
376 | 81 | try { | 77 | } |
377 | 82 | file.create (FileCreateFlags.NONE); | 78 | } |
346 | 83 | } catch (Error e) { | ||
347 | 84 | warning (e.message); | ||
348 | 85 | } | ||
349 | 86 | |||
350 | 87 | var item = new FileItem (new File (file.get_path ())); | ||
351 | 88 | this.folder.add (item); | ||
352 | 89 | } | ||
353 | 90 | |||
354 | 91 | public void remove_file () { | ||
355 | 92 | if (this.selected is FileItem) { | ||
356 | 93 | var file = GLib.File.new_for_path (((FileItem)selected).file.file.get_path ()); | ||
357 | 94 | try { | ||
358 | 95 | file.delete (); | ||
359 | 96 | this.root.remove (selected); | ||
360 | 97 | } catch (Error e) { | ||
361 | 98 | warning (e.message); | ||
362 | 99 | } | ||
363 | 100 | } | ||
364 | 101 | |||
365 | 102 | this.selected = null; | ||
378 | 103 | } | 79 | } |
379 | 104 | 80 | ||
380 | 105 | private bool is_open (File folder) { | 81 | private bool is_open (File folder) { |
381 | @@ -113,24 +89,23 @@ | |||
382 | 113 | } | 89 | } |
383 | 114 | 90 | ||
384 | 115 | private void write_settings () { | 91 | private void write_settings () { |
392 | 116 | settings.opened_folder = this.folder.file.file.get_path (); | 92 | string[] paths = {}; |
393 | 117 | } | 93 | foreach (var child in this.root.children) { |
394 | 118 | 94 | if (child is FolderItem) { | |
395 | 119 | private void restore_settings () { | 95 | paths += ((FolderItem) child).path; |
396 | 120 | var folder = new File (settings.opened_folder); | 96 | } |
390 | 121 | if (settings.opened_folder == "" || settings.opened_folder == null || !folder.is_valid_directory) { | ||
391 | 122 | settings.opened_folder = GLib.Environment.get_home_dir (); | ||
397 | 123 | } | 97 | } |
398 | 124 | 98 | ||
400 | 125 | open_folder (new File (settings.opened_folder)); | 99 | settings.opened_folders = paths; |
401 | 126 | } | 100 | } |
402 | 127 | } | 101 | } |
403 | 128 | 102 | ||
404 | 129 | /** | 103 | /** |
405 | 130 | * Common abstract class for normal and expandable items. | 104 | * Common abstract class for normal and expandable items. |
406 | 131 | */ | 105 | */ |
408 | 132 | internal class Item : Granite.Widgets.SourceList.ExpandableItem, Granite.Widgets.SourceListSortable { | 106 | public class Item : Granite.Widgets.SourceList.ExpandableItem, Granite.Widgets.SourceListSortable { |
409 | 133 | public File file { get; construct; } | 107 | public File file { get; construct; } |
410 | 108 | public Scratch.Plugins.FileManager.FileView view { get; construct; } | ||
411 | 134 | public string path { get { return file.path; } } | 109 | public string path { get { return file.path; } } |
412 | 135 | 110 | ||
413 | 136 | public int compare (Granite.Widgets.SourceList.Item a, Granite.Widgets.SourceList.Item b) { | 111 | public int compare (Granite.Widgets.SourceList.Item a, Granite.Widgets.SourceList.Item b) { |
414 | @@ -148,150 +123,4 @@ | |||
415 | 148 | } | 123 | } |
416 | 149 | } | 124 | } |
417 | 150 | 125 | ||
418 | 151 | /** | ||
419 | 152 | * Normal item in the source list, represents a textfile. | ||
420 | 153 | * TODO Remove, Rename | ||
421 | 154 | */ | ||
422 | 155 | internal class FileItem : Item { | ||
423 | 156 | //Gtk.Menu menu; | ||
424 | 157 | //Gtk.MenuItem item_trash; | ||
425 | 158 | public FileItem (File file) requires (file.is_valid_textfile) { | ||
426 | 159 | Object (file: file); | ||
427 | 160 | |||
428 | 161 | this.selectable = true; | ||
429 | 162 | this.editable = true; | ||
430 | 163 | this.name = file.name; | ||
431 | 164 | this.icon = file.icon; | ||
432 | 165 | } | ||
433 | 166 | |||
434 | 167 | public void rename (string new_name) { | ||
435 | 168 | string new_uri = file.file.get_parent ().get_uri () + "/" + new_name; | ||
436 | 169 | debug (new_uri); | ||
437 | 170 | file.rename (new_name); | ||
438 | 171 | } | ||
439 | 172 | |||
440 | 173 | /*public override Gtk.Menu? get_context_menu () { | ||
441 | 174 | menu = new Gtk.Menu (); | ||
442 | 175 | item_trash = new Gtk.MenuItem.with_label (_("Move to Trash")); | ||
443 | 176 | menu.append (item_trash); | ||
444 | 177 | item_trash.activate.connect (() => { file.trash (); }); | ||
445 | 178 | menu.show_all (); | ||
446 | 179 | return menu; | ||
447 | 180 | }*/ | ||
448 | 181 | } | ||
449 | 182 | |||
450 | 183 | /** | ||
451 | 184 | * Expandable item in the source list, represents a folder. | ||
452 | 185 | * Monitored for changes inside the directory. | ||
453 | 186 | * TODO remove, rename, create new file | ||
454 | 187 | */ | ||
455 | 188 | internal class FolderItem : Item { | ||
456 | 189 | public signal void folder_open (GLib.File folder); | ||
457 | 190 | public FileView view { get; construct; } | ||
458 | 191 | |||
459 | 192 | private GLib.FileMonitor monitor; | ||
460 | 193 | private bool children_loaded = false; | ||
461 | 194 | |||
462 | 195 | //Gtk.Menu menu; | ||
463 | 196 | //Gtk.MenuItem item_trash; | ||
464 | 197 | //Gtk.MenuItem item_create; | ||
465 | 198 | |||
466 | 199 | public FolderItem (File file, FileView view) requires (file.is_valid_directory) { | ||
467 | 200 | Object (file: file, view: view); | ||
468 | 201 | |||
469 | 202 | this.editable = false; | ||
470 | 203 | this.selectable = false; | ||
471 | 204 | this.name = file.name; | ||
472 | 205 | this.icon = file.icon; | ||
473 | 206 | |||
474 | 207 | this.add (new Granite.Widgets.SourceList.Item ("")); // dummy | ||
475 | 208 | this.toggled.connect (() => { | ||
476 | 209 | if (this.expanded && this.n_children <= 1) { | ||
477 | 210 | this.clear (); | ||
478 | 211 | this.add_children (); | ||
479 | 212 | children_loaded = true; | ||
480 | 213 | } | ||
481 | 214 | }); | ||
482 | 215 | |||
483 | 216 | try { | ||
484 | 217 | monitor = file.file.monitor_directory (GLib.FileMonitorFlags.NONE); | ||
485 | 218 | monitor.changed.connect ((s,d,e) => { on_changed (s,d,e); }); | ||
486 | 219 | } catch (GLib.Error e) { | ||
487 | 220 | warning (e.message); | ||
488 | 221 | } | ||
489 | 222 | } | ||
490 | 223 | |||
491 | 224 | public override Gtk.Menu? get_context_menu () { | ||
492 | 225 | if (this == this.view.root.children.to_array ()[0]) { | ||
493 | 226 | return null; | ||
494 | 227 | } | ||
495 | 228 | |||
496 | 229 | var menu = new Gtk.Menu (); | ||
497 | 230 | var item = new Gtk.MenuItem.with_label (_("Open")); | ||
498 | 231 | item.activate.connect (() => { this.folder_open (this.file.file); }); | ||
499 | 232 | menu.append (item); | ||
500 | 233 | menu.show_all (); | ||
501 | 234 | return menu; | ||
502 | 235 | } | ||
503 | 236 | |||
504 | 237 | internal void add_children () { | ||
505 | 238 | foreach (var child in file.children) { | ||
506 | 239 | if (child.is_valid_directory) { | ||
507 | 240 | var item = new FolderItem (child, view); | ||
508 | 241 | item.folder_open.connect (() => { | ||
509 | 242 | this.view.open_folder (child); | ||
510 | 243 | }); | ||
511 | 244 | |||
512 | 245 | add (item); | ||
513 | 246 | } else if (child.is_valid_textfile) { | ||
514 | 247 | var item = new FileItem (child); | ||
515 | 248 | add (item); | ||
516 | 249 | item.edited.connect (item.rename); | ||
517 | 250 | } | ||
518 | 251 | } | ||
519 | 252 | } | ||
520 | 253 | |||
521 | 254 | private void on_changed (GLib.File source, GLib.File? dest, GLib.FileMonitorEvent event) { | ||
522 | 255 | if (!children_loaded) { | ||
523 | 256 | this.file.reset_cache (); | ||
524 | 257 | return; | ||
525 | 258 | } | ||
526 | 259 | |||
527 | 260 | switch (event) { | ||
528 | 261 | case GLib.FileMonitorEvent.DELETED: | ||
529 | 262 | var children_tmp = new Gee.ArrayList<Granite.Widgets.SourceList.Item> (); | ||
530 | 263 | children_tmp.add_all (children); | ||
531 | 264 | foreach (var item in children_tmp) { | ||
532 | 265 | if ((item as Item).path == source.get_path ()) { | ||
533 | 266 | remove (item); | ||
534 | 267 | } | ||
535 | 268 | } | ||
536 | 269 | |||
537 | 270 | break; | ||
538 | 271 | case GLib.FileMonitorEvent.CREATED: | ||
539 | 272 | if (source.query_exists () == false) { | ||
540 | 273 | return; | ||
541 | 274 | } | ||
542 | 275 | |||
543 | 276 | var file = new File (source.get_path ()); | ||
544 | 277 | var exists = false; | ||
545 | 278 | foreach (var item in children) { | ||
546 | 279 | if ((item as Item).path == file.path) { | ||
547 | 280 | exists = true; | ||
548 | 281 | } | ||
549 | 282 | } | ||
550 | 283 | |||
551 | 284 | if (!exists) { | ||
552 | 285 | if (file.is_valid_textfile) { | ||
553 | 286 | this.add (new FileItem (file)); | ||
554 | 287 | } else if (file.is_valid_directory) { | ||
555 | 288 | this.add (new FolderItem (file, view)); | ||
556 | 289 | } | ||
557 | 290 | } | ||
558 | 291 | |||
559 | 292 | break; | ||
560 | 293 | } | ||
561 | 294 | } | ||
562 | 295 | } | ||
563 | 296 | |||
564 | 297 | } | 126 | } |
565 | 298 | 127 | ||
566 | === added file 'plugins/filemanager/FolderItem.vala' | |||
567 | --- plugins/filemanager/FolderItem.vala 1970-01-01 00:00:00 +0000 | |||
568 | +++ plugins/filemanager/FolderItem.vala 2016-09-03 22:26:31 +0000 | |||
569 | @@ -0,0 +1,154 @@ | |||
570 | 1 | // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- | ||
571 | 2 | /*- | ||
572 | 3 | * Copyright (c) 2016 elementary LLC. (https://elementary.io) | ||
573 | 4 | * | ||
574 | 5 | * This program is free software: you can redistribute it and/or modify | ||
575 | 6 | * it under the terms of the GNU General Public License as published by | ||
576 | 7 | * the Free Software Foundation, either version 3 of the License, or | ||
577 | 8 | * (at your option) any later version. | ||
578 | 9 | * | ||
579 | 10 | * This program is distributed in the hope that it will be useful, | ||
580 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
581 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
582 | 13 | * GNU General Public License for more details. | ||
583 | 14 | * | ||
584 | 15 | * You should have received a copy of the GNU General Public License | ||
585 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
586 | 17 | * | ||
587 | 18 | * Authored by: Corentin Noël <corentin@elementary.io> | ||
588 | 19 | */ | ||
589 | 20 | |||
590 | 21 | public class Scratch.Plugins.FileManager.FolderItem : Item { | ||
591 | 22 | public signal void folder_open (GLib.File folder); | ||
592 | 23 | |||
593 | 24 | private GLib.FileMonitor monitor; | ||
594 | 25 | private bool children_loaded = false; | ||
595 | 26 | |||
596 | 27 | public FolderItem (Scratch.Plugins.FileManager.File file, Scratch.Plugins.FileManager.FileView view) requires (file.is_valid_directory) { | ||
597 | 28 | Object (file: file, view: view); | ||
598 | 29 | |||
599 | 30 | this.editable = false; | ||
600 | 31 | this.selectable = false; | ||
601 | 32 | this.name = file.name; | ||
602 | 33 | this.icon = file.icon; | ||
603 | 34 | |||
604 | 35 | this.add (new Granite.Widgets.SourceList.Item ("")); // dummy | ||
605 | 36 | this.toggled.connect (() => { | ||
606 | 37 | if (this.expanded && this.n_children <= 1) { | ||
607 | 38 | this.clear (); | ||
608 | 39 | this.add_children (); | ||
609 | 40 | children_loaded = true; | ||
610 | 41 | } | ||
611 | 42 | }); | ||
612 | 43 | |||
613 | 44 | try { | ||
614 | 45 | monitor = file.file.monitor_directory (GLib.FileMonitorFlags.NONE); | ||
615 | 46 | monitor.changed.connect ((s,d,e) => { on_changed (s,d,e); }); | ||
616 | 47 | } catch (GLib.Error e) { | ||
617 | 48 | warning (e.message); | ||
618 | 49 | } | ||
619 | 50 | } | ||
620 | 51 | |||
621 | 52 | public override Gtk.Menu? get_context_menu () { | ||
622 | 53 | var menu = new Gtk.Menu (); | ||
623 | 54 | if (this.parent == this.view.root) { | ||
624 | 55 | var item = new Gtk.MenuItem.with_label (_("Close Folder")); | ||
625 | 56 | item.activate.connect (() => { | ||
626 | 57 | monitor.cancel (); | ||
627 | 58 | parent.remove (this); | ||
628 | 59 | }); | ||
629 | 60 | menu.append (item); | ||
630 | 61 | } else { | ||
631 | 62 | var item = new Gtk.MenuItem.with_label (_("Open")); | ||
632 | 63 | item.activate.connect (() => folder_open (this.file.file)); | ||
633 | 64 | menu.append (item); | ||
634 | 65 | } | ||
635 | 66 | |||
636 | 67 | var new_file_item = new Gtk.MenuItem.with_label (_("Add file")); | ||
637 | 68 | new_file_item.activate.connect (() => add_file ()); | ||
638 | 69 | menu.append (new_file_item); | ||
639 | 70 | menu.show_all (); | ||
640 | 71 | return menu; | ||
641 | 72 | } | ||
642 | 73 | |||
643 | 74 | internal void add_children () { | ||
644 | 75 | foreach (var child in file.children) { | ||
645 | 76 | if (child.is_valid_directory) { | ||
646 | 77 | var item = new FolderItem (child, view); | ||
647 | 78 | item.folder_open.connect (() => { | ||
648 | 79 | this.view.open_folder (child); | ||
649 | 80 | }); | ||
650 | 81 | |||
651 | 82 | add (item); | ||
652 | 83 | } else if (child.is_valid_textfile) { | ||
653 | 84 | var item = new FileItem (child, view); | ||
654 | 85 | add (item); | ||
655 | 86 | item.edited.connect (item.rename); | ||
656 | 87 | } | ||
657 | 88 | } | ||
658 | 89 | } | ||
659 | 90 | |||
660 | 91 | private void on_changed (GLib.File source, GLib.File? dest, GLib.FileMonitorEvent event) { | ||
661 | 92 | if (!children_loaded) { | ||
662 | 93 | this.file.reset_cache (); | ||
663 | 94 | return; | ||
664 | 95 | } | ||
665 | 96 | |||
666 | 97 | switch (event) { | ||
667 | 98 | case GLib.FileMonitorEvent.DELETED: | ||
668 | 99 | var children_tmp = new Gee.ArrayList<Granite.Widgets.SourceList.Item> (); | ||
669 | 100 | children_tmp.add_all (children); | ||
670 | 101 | foreach (var item in children_tmp) { | ||
671 | 102 | if ((item as Item).path == source.get_path ()) { | ||
672 | 103 | remove (item); | ||
673 | 104 | } | ||
674 | 105 | } | ||
675 | 106 | |||
676 | 107 | break; | ||
677 | 108 | case GLib.FileMonitorEvent.CREATED: | ||
678 | 109 | if (source.query_exists () == false) { | ||
679 | 110 | return; | ||
680 | 111 | } | ||
681 | 112 | |||
682 | 113 | var file = new File (source.get_path ()); | ||
683 | 114 | var exists = false; | ||
684 | 115 | foreach (var item in children) { | ||
685 | 116 | if ((item as Item).path == file.path) { | ||
686 | 117 | exists = true; | ||
687 | 118 | } | ||
688 | 119 | } | ||
689 | 120 | |||
690 | 121 | if (!exists) { | ||
691 | 122 | if (file.is_valid_textfile) { | ||
692 | 123 | this.add (new FileItem (file, view)); | ||
693 | 124 | } else if (file.is_valid_directory) { | ||
694 | 125 | this.add (new FolderItem (file, view)); | ||
695 | 126 | } | ||
696 | 127 | } | ||
697 | 128 | |||
698 | 129 | break; | ||
699 | 130 | } | ||
700 | 131 | } | ||
701 | 132 | |||
702 | 133 | private void add_file () { | ||
703 | 134 | var child = file.file.get_child (_("New File")); | ||
704 | 135 | |||
705 | 136 | int n = 1; | ||
706 | 137 | while (child.query_exists ()) { | ||
707 | 138 | child = file.file.get_child (_("New File (%d)").printf (n)); | ||
708 | 139 | n++; | ||
709 | 140 | } | ||
710 | 141 | |||
711 | 142 | try { | ||
712 | 143 | child.create (FileCreateFlags.NONE); | ||
713 | 144 | } catch (Error e) { | ||
714 | 145 | warning (e.message); | ||
715 | 146 | } | ||
716 | 147 | |||
717 | 148 | if (children_loaded) { | ||
718 | 149 | var item = new FileItem (new File (child.get_path ()), view); | ||
719 | 150 | this.add (item); | ||
720 | 151 | view.start_editing_item (item); | ||
721 | 152 | } | ||
722 | 153 | } | ||
723 | 154 | } | ||
724 | 0 | 155 | ||
725 | === modified file 'plugins/filemanager/Settings.vala' | |||
726 | --- plugins/filemanager/Settings.vala 2013-07-16 15:56:38 +0000 | |||
727 | +++ plugins/filemanager/Settings.vala 2016-09-03 22:26:31 +0000 | |||
728 | @@ -27,7 +27,7 @@ | |||
729 | 27 | 27 | ||
730 | 28 | private const string SCHEMA = "org.pantheon.scratch.plugins.file-manager"; | 28 | private const string SCHEMA = "org.pantheon.scratch.plugins.file-manager"; |
731 | 29 | 29 | ||
733 | 30 | public string opened_folder { get; set; } | 30 | public string[] opened_folders { get; set; } |
734 | 31 | 31 | ||
735 | 32 | public Settings () { | 32 | public Settings () { |
736 | 33 | base (SCHEMA); | 33 | base (SCHEMA); |
737 | 34 | 34 | ||
738 | === removed directory 'plugins/folder-manager' | |||
739 | === removed file 'plugins/folder-manager/CMakeLists.txt' | |||
740 | --- plugins/folder-manager/CMakeLists.txt 2016-09-03 10:30:53 +0000 | |||
741 | +++ plugins/folder-manager/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
742 | @@ -1,29 +0,0 @@ | |||
743 | 1 | add_definitions(${NORMAL_CFLAGS}) | ||
744 | 2 | link_directories(${NORMAL_LINK_DIRS}) | ||
745 | 3 | |||
746 | 4 | set (PLUGIN_NAME "folder-manager") | ||
747 | 5 | |||
748 | 6 | vala_precompile(VALA_C ${PLUGIN_NAME} | ||
749 | 7 | FolderManagerPlugin.vala | ||
750 | 8 | File.vala | ||
751 | 9 | Settings.vala | ||
752 | 10 | FileView.vala | ||
753 | 11 | PACKAGES | ||
754 | 12 | gtk+-3.0 | ||
755 | 13 | gee-0.8 | ||
756 | 14 | granite | ||
757 | 15 | scratchcore | ||
758 | 16 | libpeas-1.0 | ||
759 | 17 | gtksourceview-3.0 | ||
760 | 18 | ${ZEITGEIST_DEPS} | ||
761 | 19 | OPTIONS | ||
762 | 20 | ${DEFAULT_PLUGIN_OPTIONS} | ||
763 | 21 | ) | ||
764 | 22 | |||
765 | 23 | add_library(${PLUGIN_NAME} MODULE ${VALA_C}) | ||
766 | 24 | add_dependencies(${PLUGIN_NAME} ${LIBNAME}) | ||
767 | 25 | |||
768 | 26 | install(TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGINDIR}/${PLUGIN_NAME}) | ||
769 | 27 | install(FILES ${PLUGIN_NAME}.plugin DESTINATION ${PLUGINDIR}/${PLUGIN_NAME}) | ||
770 | 28 | |||
771 | 29 | message("-- Folder Manager plugin will be compiled") | ||
772 | 30 | 0 | ||
773 | === removed file 'plugins/folder-manager/File.vala' | |||
774 | --- plugins/folder-manager/File.vala 2013-06-02 13:07:08 +0000 | |||
775 | +++ plugins/folder-manager/File.vala 1970-01-01 00:00:00 +0000 | |||
776 | @@ -1,207 +0,0 @@ | |||
777 | 1 | // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- | ||
778 | 2 | /*** | ||
779 | 3 | BEGIN LICENSE | ||
780 | 4 | |||
781 | 5 | Copyright (C) 2013 Julien Spautz <spautz.julien@gmail.com> | ||
782 | 6 | This program is free software: you can redistribute it and/or modify it | ||
783 | 7 | under the terms of the GNU Lesser General Public License version 3, as published | ||
784 | 8 | by the Free Software Foundation. | ||
785 | 9 | |||
786 | 10 | This program is distributed in the hope that it will be useful, but | ||
787 | 11 | WITHOUT ANY WARRANTY; without even the implied warranties of | ||
788 | 12 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
789 | 13 | PURPOSE. See the GNU General Public License for more details. | ||
790 | 14 | |||
791 | 15 | You should have received a copy of the GNU General Public License along | ||
792 | 16 | with this program. If not, see <http://www.gnu.org/licenses/> | ||
793 | 17 | |||
794 | 18 | END LICENSE | ||
795 | 19 | ***/ | ||
796 | 20 | |||
797 | 21 | namespace Scratch.Plugins.FolderManager { | ||
798 | 22 | |||
799 | 23 | /** | ||
800 | 24 | * Class for easily dealing with files. | ||
801 | 25 | */ | ||
802 | 26 | internal class File : GLib.Object { | ||
803 | 27 | |||
804 | 28 | public GLib.File file; | ||
805 | 29 | private GLib.FileInfo info; | ||
806 | 30 | |||
807 | 31 | private enum Type { | ||
808 | 32 | VALID_FILE, | ||
809 | 33 | VALID_FOLDER, | ||
810 | 34 | UNKNOWN, | ||
811 | 35 | INVALID | ||
812 | 36 | } | ||
813 | 37 | |||
814 | 38 | public File (string path) { | ||
815 | 39 | file = GLib.File.new_for_path (path); | ||
816 | 40 | |||
817 | 41 | info = new FileInfo (); | ||
818 | 42 | try { | ||
819 | 43 | info = file.query_info ( | ||
820 | 44 | GLib.FileAttribute.STANDARD_CONTENT_TYPE + "," + | ||
821 | 45 | GLib.FileAttribute.STANDARD_IS_BACKUP + "," + | ||
822 | 46 | GLib.FileAttribute.STANDARD_IS_HIDDEN + "," + | ||
823 | 47 | GLib.FileAttribute.STANDARD_DISPLAY_NAME + "," + | ||
824 | 48 | GLib.FileAttribute.STANDARD_TYPE, | ||
825 | 49 | FileQueryInfoFlags.NONE); | ||
826 | 50 | } catch (GLib.Error error) { | ||
827 | 51 | info = null; | ||
828 | 52 | warning (error.message); | ||
829 | 53 | } | ||
830 | 54 | } | ||
831 | 55 | |||
832 | 56 | // returns the path the file | ||
833 | 57 | string _path = null; | ||
834 | 58 | public string path { | ||
835 | 59 | get { return _path != null ? _path : _path = file.get_path (); } | ||
836 | 60 | } | ||
837 | 61 | |||
838 | 62 | // returns the basename of the file | ||
839 | 63 | string _name = null; | ||
840 | 64 | public string name { | ||
841 | 65 | get { return _name != null ? _name : _name = info.get_display_name (); } | ||
842 | 66 | } | ||
843 | 67 | |||
844 | 68 | // returns the icon of the file's content type | ||
845 | 69 | GLib.Icon _icon = null; | ||
846 | 70 | public GLib.Icon icon { | ||
847 | 71 | get { | ||
848 | 72 | if (_icon != null) | ||
849 | 73 | return _icon; | ||
850 | 74 | //var content_type = info.get_attribute_string (FileAttribute.STANDARD_FAST_CONTENT_TYPE); | ||
851 | 75 | var content_type = info.get_content_type (); | ||
852 | 76 | return _icon = GLib.ContentType.get_icon (content_type); | ||
853 | 77 | } | ||
854 | 78 | } | ||
855 | 79 | |||
856 | 80 | // checks if file exists | ||
857 | 81 | public bool exists { | ||
858 | 82 | get { return file.query_exists (); } | ||
859 | 83 | } | ||
860 | 84 | |||
861 | 85 | Type _type = Type.UNKNOWN; | ||
862 | 86 | // checks if we're dealing with a non-hidden, non-backup directory | ||
863 | 87 | public bool is_valid_directory { | ||
864 | 88 | get { | ||
865 | 89 | if (_type == Type.VALID_FILE) | ||
866 | 90 | return false; | ||
867 | 91 | if (_type == Type.VALID_FOLDER) | ||
868 | 92 | return true; | ||
869 | 93 | if (_type == Type.INVALID) | ||
870 | 94 | return false; | ||
871 | 95 | |||
872 | 96 | if (info.get_file_type () != FileType.DIRECTORY || | ||
873 | 97 | info.get_is_hidden () || info.get_is_backup ()) { | ||
874 | 98 | return false; | ||
875 | 99 | } | ||
876 | 100 | |||
877 | 101 | bool has_valid_children = false; | ||
878 | 102 | |||
879 | 103 | foreach (var child in children) { | ||
880 | 104 | if (child.is_valid_textfile) { | ||
881 | 105 | _type = Type.VALID_FOLDER; | ||
882 | 106 | return has_valid_children = true; | ||
883 | 107 | } | ||
884 | 108 | } | ||
885 | 109 | |||
886 | 110 | foreach (var child in children) { | ||
887 | 111 | if (child.is_valid_directory) { | ||
888 | 112 | has_valid_children = true; | ||
889 | 113 | _type = Type.VALID_FOLDER; | ||
890 | 114 | return has_valid_children = true; | ||
891 | 115 | } | ||
892 | 116 | } | ||
893 | 117 | |||
894 | 118 | return false; | ||
895 | 119 | } | ||
896 | 120 | } | ||
897 | 121 | |||
898 | 122 | // checks if we're dealing with a textfile | ||
899 | 123 | public bool is_valid_textfile { | ||
900 | 124 | get { | ||
901 | 125 | if (_type == Type.VALID_FILE) | ||
902 | 126 | return true; | ||
903 | 127 | if (_type == Type.VALID_FOLDER) | ||
904 | 128 | return false; | ||
905 | 129 | if (_type == Type.INVALID) | ||
906 | 130 | return false; | ||
907 | 131 | |||
908 | 132 | if (info.get_file_type () == FileType.REGULAR) { | ||
909 | 133 | //var content_type = info.get_attribute_string (FileAttribute.STANDARD_FAST_CONTENT_TYPE); | ||
910 | 134 | var content_type = info.get_content_type (); | ||
911 | 135 | if (ContentType.is_a (content_type, "text/*") && | ||
912 | 136 | !info.get_is_backup () && | ||
913 | 137 | !info.get_is_hidden ()) { | ||
914 | 138 | _type = Type.VALID_FILE; | ||
915 | 139 | return true; | ||
916 | 140 | } | ||
917 | 141 | } | ||
918 | 142 | |||
919 | 143 | return false; | ||
920 | 144 | } | ||
921 | 145 | } | ||
922 | 146 | |||
923 | 147 | // returns a list of all children of a directory | ||
924 | 148 | GLib.List <File> _children = null; | ||
925 | 149 | public GLib.List <File> children { | ||
926 | 150 | get { | ||
927 | 151 | if (_children != null) | ||
928 | 152 | return _children; | ||
929 | 153 | |||
930 | 154 | var parent = GLib.File.new_for_path (file.get_path ()); | ||
931 | 155 | try { | ||
932 | 156 | var enumerator = parent.enumerate_children ( | ||
933 | 157 | GLib.FileAttribute.STANDARD_NAME, | ||
934 | 158 | FileQueryInfoFlags.NONE | ||
935 | 159 | ); | ||
936 | 160 | |||
937 | 161 | var file_info = new FileInfo (); | ||
938 | 162 | while ((file_info = enumerator.next_file ()) != null) { | ||
939 | 163 | var child = parent.get_child (file_info.get_name ()); | ||
940 | 164 | _children.append (new File (child.get_path ())); | ||
941 | 165 | } | ||
942 | 166 | } catch (GLib.Error error) { | ||
943 | 167 | warning (error.message); | ||
944 | 168 | } | ||
945 | 169 | |||
946 | 170 | return _children; | ||
947 | 171 | } | ||
948 | 172 | } | ||
949 | 173 | |||
950 | 174 | /*public void rename (string name) { | ||
951 | 175 | try { | ||
952 | 176 | file.set_display_name (name); | ||
953 | 177 | } catch (GLib.Error error) { | ||
954 | 178 | warning (error.message); | ||
955 | 179 | } | ||
956 | 180 | } | ||
957 | 181 | |||
958 | 182 | public void trash () { | ||
959 | 183 | try { | ||
960 | 184 | file.trash (); | ||
961 | 185 | } catch (GLib.Error error) { | ||
962 | 186 | warning (error.message); | ||
963 | 187 | } | ||
964 | 188 | }*/ | ||
965 | 189 | |||
966 | 190 | public void reset_cache () { | ||
967 | 191 | _name = null; | ||
968 | 192 | _path = null; | ||
969 | 193 | _icon = null; | ||
970 | 194 | _children = null; | ||
971 | 195 | _type = Type.UNKNOWN; | ||
972 | 196 | } | ||
973 | 197 | |||
974 | 198 | public static int compare (File a, File b) { | ||
975 | 199 | if (a.is_valid_directory && b.is_valid_textfile) | ||
976 | 200 | return -1; | ||
977 | 201 | if (a.is_valid_textfile && b.is_valid_directory) | ||
978 | 202 | return 1; | ||
979 | 203 | return strcmp (a.path.collate_key_for_filename (), | ||
980 | 204 | b.path.collate_key_for_filename ()); | ||
981 | 205 | } | ||
982 | 206 | } | ||
983 | 207 | } | ||
984 | 208 | 0 | ||
985 | === removed file 'plugins/folder-manager/FileView.vala' | |||
986 | --- plugins/folder-manager/FileView.vala 2015-09-16 01:11:55 +0000 | |||
987 | +++ plugins/folder-manager/FileView.vala 1970-01-01 00:00:00 +0000 | |||
988 | @@ -1,312 +0,0 @@ | |||
989 | 1 | // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- | ||
990 | 2 | /*** | ||
991 | 3 | BEGIN LICENSE | ||
992 | 4 | |||
993 | 5 | Copyright (C) 2013 Julien Spautz <spautz.julien@gmail.com> | ||
994 | 6 | This program is free software: you can redistribute it and/or modify it | ||
995 | 7 | under the terms of the GNU Lesser General Public License version 3, as published | ||
996 | 8 | by the Free Software Foundation. | ||
997 | 9 | |||
998 | 10 | This program is distributed in the hope that it will be useful, but | ||
999 | 11 | WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1000 | 12 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1001 | 13 | PURPOSE. See the GNU General Public License for more details. | ||
1002 | 14 | |||
1003 | 15 | You should have received a copy of the GNU General Public License along | ||
1004 | 16 | with this program. If not, see <http://www.gnu.org/licenses/> | ||
1005 | 17 | |||
1006 | 18 | END LICENSE | ||
1007 | 19 | ***/ | ||
1008 | 20 | |||
1009 | 21 | namespace Scratch.Plugins.FolderManager { | ||
1010 | 22 | Settings settings; | ||
1011 | 23 | |||
1012 | 24 | /** | ||
1013 | 25 | * SourceList that displays folders and their contents. | ||
1014 | 26 | */ | ||
1015 | 27 | internal class FileView : Granite.Widgets.SourceList { | ||
1016 | 28 | |||
1017 | 29 | public signal void select (string file); | ||
1018 | 30 | |||
1019 | 31 | public FileView () { | ||
1020 | 32 | this.width_request = 180; | ||
1021 | 33 | this.item_selected.connect ((item) => { | ||
1022 | 34 | select ((item as FileItem).path); | ||
1023 | 35 | }); | ||
1024 | 36 | |||
1025 | 37 | settings = new Settings (); | ||
1026 | 38 | } | ||
1027 | 39 | |||
1028 | 40 | public void restore_saved_state () { | ||
1029 | 41 | foreach (var path in settings.opened_folders) | ||
1030 | 42 | add_folder (new File (path), false); | ||
1031 | 43 | } | ||
1032 | 44 | |||
1033 | 45 | public void open_folder (File folder) { | ||
1034 | 46 | if (is_open (folder)) { | ||
1035 | 47 | warning ("Folder '%s' is already open.", folder.path); | ||
1036 | 48 | return; | ||
1037 | 49 | } else if (!folder.is_valid_directory) { | ||
1038 | 50 | warning ("Cannot open invalid directory."); | ||
1039 | 51 | return; | ||
1040 | 52 | } | ||
1041 | 53 | |||
1042 | 54 | add_folder (folder, true); | ||
1043 | 55 | write_settings (); | ||
1044 | 56 | } | ||
1045 | 57 | |||
1046 | 58 | private void add_folder (File folder, bool expand) { | ||
1047 | 59 | if (is_open (folder)) { | ||
1048 | 60 | warning ("Folder '%s' is already open.", folder.path); | ||
1049 | 61 | return; | ||
1050 | 62 | } else if (!folder.is_valid_directory) { | ||
1051 | 63 | warning ("Cannot open invalid directory."); | ||
1052 | 64 | return; | ||
1053 | 65 | } | ||
1054 | 66 | |||
1055 | 67 | var folder_root = new MainFolderItem (folder); | ||
1056 | 68 | this.root.add (folder_root); | ||
1057 | 69 | |||
1058 | 70 | folder_root.expanded = expand; | ||
1059 | 71 | folder_root.closed.connect (() => { | ||
1060 | 72 | root.remove (folder_root); | ||
1061 | 73 | write_settings (); | ||
1062 | 74 | }); | ||
1063 | 75 | } | ||
1064 | 76 | |||
1065 | 77 | private bool is_open (File folder) { | ||
1066 | 78 | foreach (var child in root.children) | ||
1067 | 79 | if (folder.path == (child as Item).path) | ||
1068 | 80 | return true; | ||
1069 | 81 | return false; | ||
1070 | 82 | } | ||
1071 | 83 | |||
1072 | 84 | private void write_settings () { | ||
1073 | 85 | string[] to_save = {}; | ||
1074 | 86 | |||
1075 | 87 | foreach (var main_folder in root.children) { | ||
1076 | 88 | var saved = false; | ||
1077 | 89 | |||
1078 | 90 | foreach (var saved_folder in to_save) { | ||
1079 | 91 | if ((main_folder as Item).path == saved_folder) { | ||
1080 | 92 | saved = true; | ||
1081 | 93 | break; | ||
1082 | 94 | } | ||
1083 | 95 | } | ||
1084 | 96 | |||
1085 | 97 | if (!saved) { | ||
1086 | 98 | to_save += (main_folder as Item).path; | ||
1087 | 99 | } | ||
1088 | 100 | } | ||
1089 | 101 | |||
1090 | 102 | settings.opened_folders = to_save; | ||
1091 | 103 | } | ||
1092 | 104 | } | ||
1093 | 105 | |||
1094 | 106 | /** | ||
1095 | 107 | * Common abstract class for file and filder items. | ||
1096 | 108 | */ | ||
1097 | 109 | internal class Item: Granite.Widgets.SourceList.ExpandableItem, Granite.Widgets.SourceListSortable { | ||
1098 | 110 | public File file { get; construct; } | ||
1099 | 111 | public string path { get { return file.path; } } | ||
1100 | 112 | |||
1101 | 113 | public int compare (Granite.Widgets.SourceList.Item a, Granite.Widgets.SourceList.Item b) { | ||
1102 | 114 | if (a is FolderItem && b is FileItem) { | ||
1103 | 115 | return -1; | ||
1104 | 116 | } else if (a is FileItem && b is FolderItem) { | ||
1105 | 117 | return 1; | ||
1106 | 118 | } | ||
1107 | 119 | |||
1108 | 120 | return File.compare ((a as Item).file, (b as Item).file); | ||
1109 | 121 | } | ||
1110 | 122 | |||
1111 | 123 | public bool allow_dnd_sorting () { | ||
1112 | 124 | return false; | ||
1113 | 125 | } | ||
1114 | 126 | } | ||
1115 | 127 | |||
1116 | 128 | /** | ||
1117 | 129 | * Normal item in the source list, represents a textfile. | ||
1118 | 130 | * TODO Remove, Rename | ||
1119 | 131 | */ | ||
1120 | 132 | internal class FileItem : Item { | ||
1121 | 133 | |||
1122 | 134 | //Gtk.Menu menu; | ||
1123 | 135 | //Gtk.MenuItem item_trash; | ||
1124 | 136 | |||
1125 | 137 | public FileItem (File file) requires (file.is_valid_textfile) { | ||
1126 | 138 | Object (file: file); | ||
1127 | 139 | |||
1128 | 140 | this.selectable = true; | ||
1129 | 141 | //this.editable = true; | ||
1130 | 142 | this.name = file.name; | ||
1131 | 143 | this.icon = file.icon; | ||
1132 | 144 | } | ||
1133 | 145 | |||
1134 | 146 | /*public void rename (string new_name) { | ||
1135 | 147 | file.rename (new_name); | ||
1136 | 148 | }*/ | ||
1137 | 149 | |||
1138 | 150 | /*public override Gtk.Menu? get_context_menu () { | ||
1139 | 151 | menu = new Gtk.Menu (); | ||
1140 | 152 | item_trash = new Gtk.MenuItem.with_label (_("Move to Trash")); | ||
1141 | 153 | menu.append (item_trash); | ||
1142 | 154 | item_trash.activate.connect (() => { file.trash (); }); | ||
1143 | 155 | menu.show_all (); | ||
1144 | 156 | return menu; | ||
1145 | 157 | }*/ | ||
1146 | 158 | } | ||
1147 | 159 | |||
1148 | 160 | /** | ||
1149 | 161 | * Expandable item in the source list, represents a folder. | ||
1150 | 162 | * Monitored for changes inside the directory. | ||
1151 | 163 | * TODO remove, rename, create new file | ||
1152 | 164 | */ | ||
1153 | 165 | internal class FolderItem : Item { | ||
1154 | 166 | |||
1155 | 167 | //Gtk.Menu menu; | ||
1156 | 168 | //Gtk.MenuItem item_trash; | ||
1157 | 169 | //Gtk.MenuItem item_create; | ||
1158 | 170 | |||
1159 | 171 | private GLib.FileMonitor monitor; | ||
1160 | 172 | private bool children_loaded = false; | ||
1161 | 173 | |||
1162 | 174 | public FolderItem (File file) requires (file.is_valid_directory) { | ||
1163 | 175 | Object (file: file); | ||
1164 | 176 | |||
1165 | 177 | this.editable = false; | ||
1166 | 178 | this.selectable = false; | ||
1167 | 179 | this.name = file.name; | ||
1168 | 180 | this.icon = file.icon; | ||
1169 | 181 | |||
1170 | 182 | this.add (new Granite.Widgets.SourceList.Item ("")); // dummy | ||
1171 | 183 | this.toggled.connect (() => { | ||
1172 | 184 | if (this.expanded && this.n_children <= 1) { | ||
1173 | 185 | this.clear (); | ||
1174 | 186 | this.add_children (); | ||
1175 | 187 | children_loaded = true; | ||
1176 | 188 | } | ||
1177 | 189 | }); | ||
1178 | 190 | |||
1179 | 191 | try { | ||
1180 | 192 | monitor = file.file.monitor_directory (GLib.FileMonitorFlags.NONE); | ||
1181 | 193 | monitor.changed.connect ((s,d,e) => { on_changed (s,d,e); }); | ||
1182 | 194 | } catch (GLib.Error e) { | ||
1183 | 195 | warning (e.message); | ||
1184 | 196 | } | ||
1185 | 197 | } | ||
1186 | 198 | |||
1187 | 199 | /*public override Gtk.Menu? get_context_menu () { | ||
1188 | 200 | menu = new Gtk.Menu (); | ||
1189 | 201 | item_trash = new Gtk.MenuItem.with_label (_("Move to Trash")); | ||
1190 | 202 | item_create = new Gtk.MenuItem.with_label (_("Create new File")); | ||
1191 | 203 | menu.append (item_trash); | ||
1192 | 204 | menu.append (item_create); | ||
1193 | 205 | item_trash.activate.connect (() => { file.trash (); }); | ||
1194 | 206 | item_create.activate.connect (() => { | ||
1195 | 207 | var new_file = GLib.File.new_for_path (file.path + "/new File"); | ||
1196 | 208 | |||
1197 | 209 | try { | ||
1198 | 210 | FileOutputStream os = new_file.create (FileCreateFlags.NONE); | ||
1199 | 211 | } catch (Error e) { | ||
1200 | 212 | warning ("Error: %s\n", e.message); | ||
1201 | 213 | } | ||
1202 | 214 | }); | ||
1203 | 215 | menu.show_all (); | ||
1204 | 216 | return menu; | ||
1205 | 217 | }*/ | ||
1206 | 218 | |||
1207 | 219 | internal void add_children () { | ||
1208 | 220 | foreach (var child in file.children) { | ||
1209 | 221 | if (child.is_valid_directory) { | ||
1210 | 222 | var item = new FolderItem (child); | ||
1211 | 223 | add (item); | ||
1212 | 224 | } else if (child.is_valid_textfile) { | ||
1213 | 225 | var item = new FileItem (child); | ||
1214 | 226 | add (item); | ||
1215 | 227 | //item.edited.connect (item.rename); | ||
1216 | 228 | } | ||
1217 | 229 | } | ||
1218 | 230 | } | ||
1219 | 231 | |||
1220 | 232 | private void on_changed (GLib.File source, GLib.File? dest, GLib.FileMonitorEvent event) { | ||
1221 | 233 | |||
1222 | 234 | if (!children_loaded) { | ||
1223 | 235 | this.file.reset_cache (); | ||
1224 | 236 | return; | ||
1225 | 237 | } | ||
1226 | 238 | |||
1227 | 239 | switch (event) { | ||
1228 | 240 | case GLib.FileMonitorEvent.DELETED: | ||
1229 | 241 | var children_tmp = new Gee.ArrayList<Granite.Widgets.SourceList.Item> (); | ||
1230 | 242 | children_tmp.add_all (children); | ||
1231 | 243 | foreach (var item in children_tmp) { | ||
1232 | 244 | if ((item as Item).path == source.get_path ()) { | ||
1233 | 245 | remove (item); | ||
1234 | 246 | } | ||
1235 | 247 | } | ||
1236 | 248 | |||
1237 | 249 | break; | ||
1238 | 250 | case GLib.FileMonitorEvent.CREATED: | ||
1239 | 251 | if (source.query_exists () == false) { | ||
1240 | 252 | return; | ||
1241 | 253 | } | ||
1242 | 254 | |||
1243 | 255 | var file = new File (source.get_path ()); | ||
1244 | 256 | var exists = false; | ||
1245 | 257 | foreach (var item in children) { | ||
1246 | 258 | if ((item as Item).path == file.path) { | ||
1247 | 259 | exists = true; | ||
1248 | 260 | break; | ||
1249 | 261 | } | ||
1250 | 262 | } | ||
1251 | 263 | |||
1252 | 264 | if (!exists) { | ||
1253 | 265 | if (file.is_valid_textfile) { | ||
1254 | 266 | this.add (new FileItem (file)); | ||
1255 | 267 | } else if (file.is_valid_directory) { | ||
1256 | 268 | this.add (new FolderItem (file)); | ||
1257 | 269 | } | ||
1258 | 270 | } | ||
1259 | 271 | |||
1260 | 272 | break; | ||
1261 | 273 | } | ||
1262 | 274 | } | ||
1263 | 275 | } | ||
1264 | 276 | |||
1265 | 277 | /** | ||
1266 | 278 | * Special root folder. | ||
1267 | 279 | * TODO rename, create new file | ||
1268 | 280 | */ | ||
1269 | 281 | internal class MainFolderItem : FolderItem { | ||
1270 | 282 | public signal void closed (); | ||
1271 | 283 | |||
1272 | 284 | Gtk.Menu menu; | ||
1273 | 285 | Gtk.MenuItem item_close; | ||
1274 | 286 | //Gtk.MenuItem item_create; | ||
1275 | 287 | |||
1276 | 288 | public MainFolderItem (File file) requires (file.is_valid_directory) { | ||
1277 | 289 | base (file); | ||
1278 | 290 | } | ||
1279 | 291 | |||
1280 | 292 | public override Gtk.Menu? get_context_menu () { | ||
1281 | 293 | menu = new Gtk.Menu (); | ||
1282 | 294 | item_close = new Gtk.MenuItem.with_label (_("Close Folder")); | ||
1283 | 295 | //item_create = new Gtk.MenuItem.with_label (_("Create new File")); | ||
1284 | 296 | menu.append (item_close); | ||
1285 | 297 | //menu.append (item_create); | ||
1286 | 298 | item_close.activate.connect (() => { closed (); }); | ||
1287 | 299 | /*item_create.activate.connect (() => { | ||
1288 | 300 | var new_file = GLib.File.new_for_path (file.path + "/new File"); | ||
1289 | 301 | |||
1290 | 302 | try { | ||
1291 | 303 | FileOutputStream os = new_file.create (FileCreateFlags.NONE); | ||
1292 | 304 | } catch (Error e) { | ||
1293 | 305 | warning ("Error: %s\n", e.message); | ||
1294 | 306 | } | ||
1295 | 307 | });*/ | ||
1296 | 308 | menu.show_all (); | ||
1297 | 309 | return menu; | ||
1298 | 310 | } | ||
1299 | 311 | } | ||
1300 | 312 | } | ||
1301 | 313 | 0 | ||
1302 | === removed file 'plugins/folder-manager/FolderManagerPlugin.vala' | |||
1303 | --- plugins/folder-manager/FolderManagerPlugin.vala 2015-12-01 11:37:53 +0000 | |||
1304 | +++ plugins/folder-manager/FolderManagerPlugin.vala 1970-01-01 00:00:00 +0000 | |||
1305 | @@ -1,122 +0,0 @@ | |||
1306 | 1 | // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- | ||
1307 | 2 | /*** | ||
1308 | 3 | BEGIN LICENSE | ||
1309 | 4 | |||
1310 | 5 | Copyright (C) 2013 Julien Spautz <spautz.julien@gmail.com> | ||
1311 | 6 | This program is free software: you can redistribute it and/or modify it | ||
1312 | 7 | under the terms of the GNU Lesser General Public License version 3, as published | ||
1313 | 8 | by the Free Software Foundation. | ||
1314 | 9 | |||
1315 | 10 | This program is distributed in the hope that it will be useful, but | ||
1316 | 11 | WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1317 | 12 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1318 | 13 | PURPOSE. See the GNU General Public License for more details. | ||
1319 | 14 | |||
1320 | 15 | You should have received a copy of the GNU General Public License along | ||
1321 | 16 | with this program. If not, see <http://www.gnu.org/licenses/> | ||
1322 | 17 | |||
1323 | 18 | END LICENSE | ||
1324 | 19 | ***/ | ||
1325 | 20 | |||
1326 | 21 | public const string NAME = _("Folder Manager"); | ||
1327 | 22 | public const string DESCRIPTION = _("Basic folder manager with file browsing"); | ||
1328 | 23 | |||
1329 | 24 | namespace Scratch.Plugins { | ||
1330 | 25 | public class FolderManagerPlugin : Peas.ExtensionBase, Peas.Activatable { | ||
1331 | 26 | |||
1332 | 27 | FolderManager.FileView view; | ||
1333 | 28 | Gtk.ToolButton tool_button; | ||
1334 | 29 | |||
1335 | 30 | int index = 0; | ||
1336 | 31 | |||
1337 | 32 | Scratch.Services.Interface plugins; | ||
1338 | 33 | public Object object { owned get; construct; } | ||
1339 | 34 | |||
1340 | 35 | public FolderManagerPlugin () { | ||
1341 | 36 | message ("Starting Folder Manager Plugin"); | ||
1342 | 37 | } | ||
1343 | 38 | |||
1344 | 39 | public void activate () { | ||
1345 | 40 | plugins = (Scratch.Services.Interface) object; | ||
1346 | 41 | plugins.hook_notebook_sidebar.connect (on_hook_sidebar); | ||
1347 | 42 | plugins.hook_toolbar.connect (on_hook_toolbar); | ||
1348 | 43 | } | ||
1349 | 44 | |||
1350 | 45 | public void deactivate () { | ||
1351 | 46 | if (view != null) | ||
1352 | 47 | view.destroy(); | ||
1353 | 48 | if (tool_button != null) { | ||
1354 | 49 | //(tool_button.parent as Scratch.Widgets.Toolbar).open_button.visible = true; | ||
1355 | 50 | tool_button.destroy (); | ||
1356 | 51 | } | ||
1357 | 52 | } | ||
1358 | 53 | |||
1359 | 54 | public void update_state () { | ||
1360 | 55 | } | ||
1361 | 56 | |||
1362 | 57 | void on_hook_sidebar (Gtk.Notebook notebook) { | ||
1363 | 58 | if (view != null) | ||
1364 | 59 | return; | ||
1365 | 60 | |||
1366 | 61 | view = new FolderManager.FileView (); | ||
1367 | 62 | |||
1368 | 63 | view.select.connect ((a) => { | ||
1369 | 64 | var file = GLib.File.new_for_path (a); | ||
1370 | 65 | plugins.open_file (file); | ||
1371 | 66 | }); | ||
1372 | 67 | |||
1373 | 68 | view.root.child_added.connect (() => { | ||
1374 | 69 | if (view.get_n_visible_children (view.root) == 0) { | ||
1375 | 70 | index = notebook.append_page (view, new Gtk.Label (_("Folders"))); | ||
1376 | 71 | } | ||
1377 | 72 | }); | ||
1378 | 73 | |||
1379 | 74 | view.root.child_removed.connect (() => { | ||
1380 | 75 | if (view.get_n_visible_children (view.root) == 1) | ||
1381 | 76 | notebook.remove_page (index); | ||
1382 | 77 | }); | ||
1383 | 78 | |||
1384 | 79 | view.restore_saved_state (); | ||
1385 | 80 | } | ||
1386 | 81 | |||
1387 | 82 | void on_hook_toolbar (Gtk.HeaderBar toolbar) { | ||
1388 | 83 | if (tool_button != null) | ||
1389 | 84 | return; | ||
1390 | 85 | |||
1391 | 86 | //(toolbar as Scratch.Widgets.Toolbar).open_button.visible = false; | ||
1392 | 87 | var icon = new Gtk.Image.from_icon_name ("folder-saved-search", Gtk.IconSize.LARGE_TOOLBAR); | ||
1393 | 88 | tool_button = new Gtk.ToolButton (icon, _("Open a folder")); | ||
1394 | 89 | tool_button.tooltip_text = _("Open a folder"); | ||
1395 | 90 | tool_button.clicked.connect (() => { | ||
1396 | 91 | Gtk.Window window = plugins.manager.window; | ||
1397 | 92 | Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog ( | ||
1398 | 93 | "Select a folder.", window, Gtk.FileChooserAction.SELECT_FOLDER, | ||
1399 | 94 | _("_Cancel"), Gtk.ResponseType.CANCEL, | ||
1400 | 95 | _("_Open"), Gtk.ResponseType.ACCEPT); | ||
1401 | 96 | chooser.select_multiple = true; | ||
1402 | 97 | |||
1403 | 98 | if (chooser.run () == Gtk.ResponseType.ACCEPT) { | ||
1404 | 99 | SList<string> uris = chooser.get_uris (); | ||
1405 | 100 | foreach (unowned string uri in uris) { | ||
1406 | 101 | var folder = new FolderManager.File (uri.replace ("file:///", "/")); | ||
1407 | 102 | view.open_folder (folder); // emit signal | ||
1408 | 103 | } | ||
1409 | 104 | } | ||
1410 | 105 | |||
1411 | 106 | chooser.close (); | ||
1412 | 107 | }); | ||
1413 | 108 | |||
1414 | 109 | icon.show (); | ||
1415 | 110 | tool_button.show (); | ||
1416 | 111 | |||
1417 | 112 | toolbar.pack_start (tool_button); | ||
1418 | 113 | //toolbar.insert (tool_button, 1); | ||
1419 | 114 | } | ||
1420 | 115 | } | ||
1421 | 116 | } | ||
1422 | 117 | |||
1423 | 118 | [ModuleInit] | ||
1424 | 119 | public void peas_register_types (GLib.TypeModule module) { | ||
1425 | 120 | var objmodule = module as Peas.ObjectModule; | ||
1426 | 121 | objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.FolderManagerPlugin)); | ||
1427 | 122 | } | ||
1428 | 123 | 0 | ||
1429 | === removed file 'plugins/folder-manager/Settings.vala' | |||
1430 | --- plugins/folder-manager/Settings.vala 2013-05-31 10:38:24 +0000 | |||
1431 | +++ plugins/folder-manager/Settings.vala 1970-01-01 00:00:00 +0000 | |||
1432 | @@ -1,36 +0,0 @@ | |||
1433 | 1 | // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- | ||
1434 | 2 | /*** | ||
1435 | 3 | BEGIN LICENSE | ||
1436 | 4 | |||
1437 | 5 | Copyright (C) 2013 Julien Spautz <spautz.julien@gmail.com> | ||
1438 | 6 | This program is free software: you can redistribute it and/or modify it | ||
1439 | 7 | under the terms of the GNU Lesser General Public License version 3, as published | ||
1440 | 8 | by the Free Software Foundation. | ||
1441 | 9 | |||
1442 | 10 | This program is distributed in the hope that it will be useful, but | ||
1443 | 11 | WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1444 | 12 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1445 | 13 | PURPOSE. See the GNU General Public License for more details. | ||
1446 | 14 | |||
1447 | 15 | You should have received a copy of the GNU General Public License along | ||
1448 | 16 | with this program. If not, see <http://www.gnu.org/licenses/> | ||
1449 | 17 | |||
1450 | 18 | END LICENSE | ||
1451 | 19 | ***/ | ||
1452 | 20 | |||
1453 | 21 | namespace Scratch.Plugins.FolderManager { | ||
1454 | 22 | |||
1455 | 23 | /** | ||
1456 | 24 | * Class for interacting with gsettings. | ||
1457 | 25 | */ | ||
1458 | 26 | internal class Settings : Granite.Services.Settings { | ||
1459 | 27 | |||
1460 | 28 | private const string SCHEMA = "org.pantheon.scratch.plugins.folder-manager"; | ||
1461 | 29 | |||
1462 | 30 | public string[] opened_folders { get; set; } | ||
1463 | 31 | |||
1464 | 32 | public Settings () { | ||
1465 | 33 | base (SCHEMA); | ||
1466 | 34 | } | ||
1467 | 35 | } | ||
1468 | 36 | } | ||
1469 | 37 | 0 | ||
1470 | === removed file 'plugins/folder-manager/folder-manager.plugin' | |||
1471 | --- plugins/folder-manager/folder-manager.plugin 2013-06-08 15:17:42 +0000 | |||
1472 | +++ plugins/folder-manager/folder-manager.plugin 1970-01-01 00:00:00 +0000 | |||
1473 | @@ -1,10 +0,0 @@ | |||
1474 | 1 | [Plugin] | ||
1475 | 2 | Module=folder-manager | ||
1476 | 3 | Loader=C | ||
1477 | 4 | IAge=2 | ||
1478 | 5 | Name=Folder Manager | ||
1479 | 6 | Description=Basic folder manager with file browsing | ||
1480 | 7 | Icon=folder-saved-search | ||
1481 | 8 | Authors=Julien Spautz <spautz.julien@gmail.com> | ||
1482 | 9 | Copyright=Copyright © 2013 Scratch Developers | ||
1483 | 10 | Website=http://launchpad.net/scratch | ||
1484 | 11 | 0 | ||
1485 | === modified file 'plugins/outline/OutlinePlugin.vala' | |||
1486 | --- plugins/outline/OutlinePlugin.vala 2016-01-14 19:33:06 +0000 | |||
1487 | +++ plugins/outline/OutlinePlugin.vala 2016-09-03 22:26:31 +0000 | |||
1488 | @@ -21,6 +21,7 @@ | |||
1489 | 21 | public const string NAME = _("Outline"); | 21 | public const string NAME = _("Outline"); |
1490 | 22 | public const string DESCRIPTION = _("Outline symbols in your current file in vala"); | 22 | public const string DESCRIPTION = _("Outline symbols in your current file in vala"); |
1491 | 23 | 23 | ||
1492 | 24 | |||
1493 | 24 | namespace Scratch.Plugins { | 25 | namespace Scratch.Plugins { |
1494 | 25 | public class OutlinePlugin : Peas.ExtensionBase, Peas.Activatable { | 26 | public class OutlinePlugin : Peas.ExtensionBase, Peas.Activatable { |
1495 | 26 | public Object object { owned get; construct; } | 27 | public Object object { owned get; construct; } |
1496 | @@ -113,7 +114,9 @@ | |||
1497 | 113 | 114 | ||
1498 | 114 | void add_container () { | 115 | void add_container () { |
1499 | 115 | if (notebook.page_num (container) == -1) { | 116 | if (notebook.page_num (container) == -1) { |
1501 | 116 | notebook.append_page (container, new Gtk.Label (_("Symbols"))); | 117 | var icon = new Gtk.Image.from_icon_name ("view-sort-ascending-symbolic", Gtk.IconSize.MENU); |
1502 | 118 | icon.tooltip_text = _("Outline"); | ||
1503 | 119 | notebook.append_page (container, icon); | ||
1504 | 117 | container.show_all (); | 120 | container.show_all (); |
1505 | 118 | } | 121 | } |
1506 | 119 | } | 122 | } |
1507 | 120 | 123 | ||
1508 | === modified file 'plugins/source-tree/SourceTreePlugin.vala' | |||
1509 | --- plugins/source-tree/SourceTreePlugin.vala 2015-12-01 11:41:37 +0000 | |||
1510 | +++ plugins/source-tree/SourceTreePlugin.vala 2016-09-03 22:26:31 +0000 | |||
1511 | @@ -194,7 +194,9 @@ | |||
1512 | 194 | view.welcome_hidden.connect (() => { | 194 | view.welcome_hidden.connect (() => { |
1513 | 195 | this.bookmark_tool_button.visible = true; | 195 | this.bookmark_tool_button.visible = true; |
1514 | 196 | this.bookmark_tool_button.no_show_all = false; | 196 | this.bookmark_tool_button.no_show_all = false; |
1516 | 197 | this.side_notebook.append_page (this.view, new Gtk.Label (_("Source Tree"))); | 197 | var icon = new Gtk.Image.from_icon_name ("view-list-symbolic", Gtk.IconSize.MENU); |
1517 | 198 | icon.tooltip_text = _("Source Tree"); | ||
1518 | 199 | this.side_notebook.append_page (this.view, icon); | ||
1519 | 198 | }); | 200 | }); |
1520 | 199 | }); | 201 | }); |
1521 | 200 | 202 | ||
1522 | 201 | 203 | ||
1523 | === modified file 'schemas/CMakeLists.txt' | |||
1524 | --- schemas/CMakeLists.txt 2015-09-10 00:54:45 +0000 | |||
1525 | +++ schemas/CMakeLists.txt 2016-09-03 22:26:31 +0000 | |||
1526 | @@ -1,6 +1,5 @@ | |||
1527 | 1 | include(GSettings) | 1 | include(GSettings) |
1528 | 2 | add_schema("org.pantheon.scratch.gschema.xml") | 2 | add_schema("org.pantheon.scratch.gschema.xml") |
1529 | 3 | add_schema("org.pantheon.scratch.plugins.folder-manager.gschema.xml") | ||
1530 | 4 | add_schema("org.pantheon.scratch.plugins.file-manager.gschema.xml") | 3 | add_schema("org.pantheon.scratch.plugins.file-manager.gschema.xml") |
1531 | 5 | add_schema("org.pantheon.scratch.plugins.terminal.gschema.xml") | 4 | add_schema("org.pantheon.scratch.plugins.terminal.gschema.xml") |
1532 | 6 | add_schema("org.pantheon.scratch.plugins.spell.gschema.xml") | 5 | add_schema("org.pantheon.scratch.plugins.spell.gschema.xml") |
1533 | 7 | 6 | ||
1534 | === modified file 'schemas/org.pantheon.scratch.plugins.file-manager.gschema.xml' | |||
1535 | --- schemas/org.pantheon.scratch.plugins.file-manager.gschema.xml 2013-07-16 15:56:38 +0000 | |||
1536 | +++ schemas/org.pantheon.scratch.plugins.file-manager.gschema.xml 2016-09-03 22:26:31 +0000 | |||
1537 | @@ -1,10 +1,10 @@ | |||
1538 | 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
1539 | 2 | <schemalist> | 2 | <schemalist> |
1540 | 3 | <schema path="/org/pantheon/scratch/plugins/file-manager/" id="org.pantheon.scratch.plugins.file-manager" gettext-domain="scratch"> | 3 | <schema path="/org/pantheon/scratch/plugins/file-manager/" id="org.pantheon.scratch.plugins.file-manager" gettext-domain="scratch"> |
1545 | 4 | <key name="opened-folder" type="s"> | 4 | <key name="opened-folders" type="as"> |
1546 | 5 | <default>''</default> | 5 | <default>[]</default> |
1547 | 6 | <summary>Opened folder.</summary> | 6 | <summary>Opened folders.</summary> |
1548 | 7 | <description>Opened folder that should be restored in startup.</description> | 7 | <description>Opened folders that should be restored in startup.</description> |
1549 | 8 | </key> | 8 | </key> |
1550 | 9 | </schema> | 9 | </schema> |
1551 | 10 | </schemalist> | 10 | </schemalist> |
1552 | 11 | 11 | ||
1553 | === removed file 'schemas/org.pantheon.scratch.plugins.folder-manager.gschema.xml' | |||
1554 | --- schemas/org.pantheon.scratch.plugins.folder-manager.gschema.xml 2013-05-31 10:38:24 +0000 | |||
1555 | +++ schemas/org.pantheon.scratch.plugins.folder-manager.gschema.xml 1970-01-01 00:00:00 +0000 | |||
1556 | @@ -1,10 +0,0 @@ | |||
1557 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
1558 | 2 | <schemalist> | ||
1559 | 3 | <schema path="/org/pantheon/scratch/plugins/folder-manager/" id="org.pantheon.scratch.plugins.folder-manager" gettext-domain="scratch"> | ||
1560 | 4 | <key name="opened-folders" type="as"> | ||
1561 | 5 | <default>[]</default> | ||
1562 | 6 | <summary>Opened folders.</summary> | ||
1563 | 7 | <description>Opened folders that should be restored in startup.</description> | ||
1564 | 8 | </key> | ||
1565 | 9 | </schema> | ||
1566 | 10 | </schemalist> |
This branch works as advertised, but, as discussed, we need to change the root item into a folder item too so you can use the context menu to add files to it, instead of using the plus sign at the bottom.
Also maybe after creating a new file, the sidebar entry needs to be opened in rename mode so that the user can type in the desired name.