| 1 | /* i4ucprojectsview.vala |
|---|
| 2 | * |
|---|
| 3 | * Copyright (C) 2010 Matias De la Puente |
|---|
| 4 | * |
|---|
| 5 | * This program is free software: you can redistribute it and/or modify |
|---|
| 6 | * it under the terms of the GNU General Public License as published by |
|---|
| 7 | * the Free Software Foundation, either version 3 of the License, or |
|---|
| 8 | * (at your option) any later version. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | * GNU General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | * |
|---|
| 18 | * Author: |
|---|
| 19 | * Matias De la Puente <mfpuente.ar@gmail.com> |
|---|
| 20 | */ |
|---|
| 21 | using Gtk; |
|---|
| 22 | using Gee; |
|---|
| 23 | |
|---|
| 24 | public class I4uc.ProjectsView : GLib.Object, ProjectsViewIface |
|---|
| 25 | { |
|---|
| 26 | private UIManager _ui_manager; |
|---|
| 27 | private ActionGroup _action_group; |
|---|
| 28 | private SidePanel _side_panel; |
|---|
| 29 | private ProjectsSidePageView _projects_side_page_view = new ProjectsSidePageView (); |
|---|
| 30 | private Action _close_action; |
|---|
| 31 | |
|---|
| 32 | public ProjectsSidePageViewIface projects_side_page_view { get { return _projects_side_page_view; } } |
|---|
| 33 | |
|---|
| 34 | public bool close_sensitive |
|---|
| 35 | { |
|---|
| 36 | set { _close_action.sensitive = value; } |
|---|
| 37 | get { return _close_action.sensitive; } |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | public ProjectsView (UIManager ui_manager, SidePanel side_panel) |
|---|
| 41 | { |
|---|
| 42 | _ui_manager = ui_manager; |
|---|
| 43 | _side_panel = side_panel; |
|---|
| 44 | |
|---|
| 45 | _action_group = new ActionGroup ("I4ucProjectsActions"); |
|---|
| 46 | _action_group.add_actions (_action_entries, this); |
|---|
| 47 | |
|---|
| 48 | _ui_manager.insert_action_group (_action_group, -1); |
|---|
| 49 | _ui_manager.add_ui_from_string (_UI, -1); |
|---|
| 50 | |
|---|
| 51 | _close_action = _action_group.get_action ("CloseProjectAction"); |
|---|
| 52 | |
|---|
| 53 | _side_panel.add_page (_projects_side_page_view); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | public void show_error_message (string error_message) |
|---|
| 57 | { |
|---|
| 58 | var message = new MessageDialog (null, DialogFlags.MODAL, MessageType.ERROR, ButtonsType.NONE, error_message); |
|---|
| 59 | message.add_button (STOCK_OK, ResponseType.OK); |
|---|
| 60 | message.set_default_response (ResponseType.OK); |
|---|
| 61 | message.run (); |
|---|
| 62 | message.destroy (); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | public int show_new_dialog (out string project_uri, out string project_name, out Gee.List<string> authors) |
|---|
| 66 | { |
|---|
| 67 | var dialog = new NewProjectDialog (); |
|---|
| 68 | var response = dialog.run (); |
|---|
| 69 | |
|---|
| 70 | project_uri = dialog.uri; |
|---|
| 71 | project_name = dialog.name; |
|---|
| 72 | authors = dialog.authors; |
|---|
| 73 | |
|---|
| 74 | dialog.destroy (); |
|---|
| 75 | return response; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | public void show_open_dialog (ref string folder_uri, out Gee.List<string> projects) |
|---|
| 79 | { |
|---|
| 80 | var dialog = new FileChooserDialog (_("Open project"), null, FileChooserAction.OPEN); |
|---|
| 81 | dialog.select_multiple = true; |
|---|
| 82 | dialog.set_current_folder_uri (folder_uri); |
|---|
| 83 | dialog.add_button (STOCK_CANCEL, ResponseType.CANCEL); |
|---|
| 84 | dialog.add_button (STOCK_OPEN, ResponseType.OK); |
|---|
| 85 | dialog.set_default_response (ResponseType.OK); |
|---|
| 86 | var filter = new FileFilter (); |
|---|
| 87 | filter.set_name (_("i4uc projects")); |
|---|
| 88 | filter.add_pattern ("*.i4uc"); |
|---|
| 89 | dialog.add_filter (filter); |
|---|
| 90 | |
|---|
| 91 | var uris = new ArrayList<string> (); |
|---|
| 92 | if (dialog.run () == ResponseType.OK) |
|---|
| 93 | { |
|---|
| 94 | folder_uri = dialog.get_current_folder_uri (); |
|---|
| 95 | foreach (var uri in dialog.get_uris ()) |
|---|
| 96 | uris.add (uri); |
|---|
| 97 | } |
|---|
| 98 | projects = uris.read_only_view; |
|---|
| 99 | dialog.destroy (); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | private void on_new () |
|---|
| 103 | { |
|---|
| 104 | this.new_clicked (); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | private void on_open () |
|---|
| 108 | { |
|---|
| 109 | this.open_clicked (); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | private void on_close () |
|---|
| 113 | { |
|---|
| 114 | this.close_clicked (); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | private const ActionEntry[] _action_entries = |
|---|
| 118 | { |
|---|
| 119 | { "ProjectsMenuAction", null, N_("_Projects") }, |
|---|
| 120 | { "NewProjectAction", STOCK_NEW, null, null, N_("Create a new project"), on_new }, |
|---|
| 121 | { "OpenProjectAction", STOCK_OPEN, null, null, N_("Open a project"), on_open }, |
|---|
| 122 | { "CloseProjectAction", STOCK_CLOSE, null, null, N_("Close current project"), on_close } |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | private const string _UI = """ |
|---|
| 126 | <ui> |
|---|
| 127 | <menubar name="MainMenu"> |
|---|
| 128 | <placeholder name="MenuBarOps"> |
|---|
| 129 | <menu name="ProjectsMenu" action="ProjectsMenuAction"> |
|---|
| 130 | <menuitem action="NewProjectAction"/> |
|---|
| 131 | <menuitem action="OpenProjectAction"/> |
|---|
| 132 | <separator/> |
|---|
| 133 | <menuitem action="CloseProjectAction"/> |
|---|
| 134 | </menu> |
|---|
| 135 | </placeholder> |
|---|
| 136 | </menubar> |
|---|
| 137 | </ui>"""; |
|---|
| 138 | } |
|---|