| 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 _side_page_view = new ProjectsSidePageView (); |
|---|
| 30 | private Action _add_file_action; |
|---|
| 31 | private Action _remove_file_from_project_action; |
|---|
| 32 | private Action _remove_file_from_profile_action; |
|---|
| 33 | private Action _add_profile_action; |
|---|
| 34 | private Action _close_action; |
|---|
| 35 | |
|---|
| 36 | public ProjectsSidePageViewIface side_page_view { get { return _side_page_view; } } |
|---|
| 37 | |
|---|
| 38 | public bool add_file_sensitive |
|---|
| 39 | { |
|---|
| 40 | set { _add_file_action.sensitive = value; } |
|---|
| 41 | get { return _add_file_action.sensitive; } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | public bool remove_file_from_project_sensitive |
|---|
| 45 | { |
|---|
| 46 | set { _remove_file_from_project_action.sensitive = value; } |
|---|
| 47 | get { return _remove_file_from_project_action.sensitive; } |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public bool remove_file_from_profile_sensitive |
|---|
| 51 | { |
|---|
| 52 | set { _remove_file_from_profile_action.sensitive = value; } |
|---|
| 53 | get { return _remove_file_from_profile_action.sensitive; } |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | public bool add_profile_sensitive |
|---|
| 57 | { |
|---|
| 58 | set { _add_profile_action.sensitive = value; } |
|---|
| 59 | get { return _add_profile_action.sensitive; } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | public bool close_sensitive |
|---|
| 63 | { |
|---|
| 64 | set { _close_action.sensitive = value; } |
|---|
| 65 | get { return _close_action.sensitive; } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | public ProjectsView (UIManager ui_manager, SidePanel side_panel) |
|---|
| 69 | { |
|---|
| 70 | _ui_manager = ui_manager; |
|---|
| 71 | _side_panel = side_panel; |
|---|
| 72 | |
|---|
| 73 | _action_group = new ActionGroup ("I4ucProjectsActions"); |
|---|
| 74 | _action_group.add_actions (_action_entries, this); |
|---|
| 75 | |
|---|
| 76 | _ui_manager.insert_action_group (_action_group, -1); |
|---|
| 77 | _ui_manager.add_ui_from_string (_UI, -1); |
|---|
| 78 | |
|---|
| 79 | _add_file_action = _action_group.get_action ("AddFileProjectAction"); |
|---|
| 80 | _remove_file_from_project_action = _action_group.get_action ("RemoveFileFromProjectProjectAction"); |
|---|
| 81 | _remove_file_from_profile_action = _action_group.get_action ("RemoveFileFromProfileProjectAction"); |
|---|
| 82 | _add_profile_action = _action_group.get_action ("AddProfileProjectAction"); |
|---|
| 83 | _close_action = _action_group.get_action ("CloseProjectAction"); |
|---|
| 84 | |
|---|
| 85 | _side_panel.add_page (_side_page_view); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | public void show_error_message (string error_message) |
|---|
| 89 | { |
|---|
| 90 | var message = new MessageDialog (null, DialogFlags.MODAL, MessageType.ERROR, ButtonsType.NONE, error_message); |
|---|
| 91 | message.add_button (STOCK_OK, ResponseType.OK); |
|---|
| 92 | message.set_default_response (ResponseType.OK); |
|---|
| 93 | message.run (); |
|---|
| 94 | message.destroy (); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | public int show_yes_no_message (string message, bool cancel) |
|---|
| 98 | { |
|---|
| 99 | var dialog = new MessageDialog (null, DialogFlags.MODAL, MessageType.WARNING, ButtonsType.NONE, message); |
|---|
| 100 | if (cancel) |
|---|
| 101 | dialog.add_button (STOCK_CANCEL, ResponseType.CANCEL); |
|---|
| 102 | dialog.add_button (STOCK_NO, ResponseType.NO); |
|---|
| 103 | dialog.add_button (STOCK_YES, ResponseType.YES); |
|---|
| 104 | dialog.set_default_response (ResponseType.YES); |
|---|
| 105 | var response = dialog.run (); |
|---|
| 106 | dialog.destroy (); |
|---|
| 107 | return response; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | public int show_new_dialog (out string project_uri, out string project_name, out Gee.List<string> authors) |
|---|
| 111 | { |
|---|
| 112 | var dialog = new NewProjectDialog (); |
|---|
| 113 | var response = dialog.run (); |
|---|
| 114 | |
|---|
| 115 | project_uri = dialog.project_uri; |
|---|
| 116 | project_name = dialog.project_name; |
|---|
| 117 | authors = dialog.project_authors; |
|---|
| 118 | |
|---|
| 119 | dialog.destroy (); |
|---|
| 120 | return response; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | public void show_open_dialog (ref string folder_uri, out Gee.List<string> projects) |
|---|
| 124 | { |
|---|
| 125 | var dialog = new FileChooserDialog (_("Open project"), null, FileChooserAction.OPEN); |
|---|
| 126 | dialog.select_multiple = true; |
|---|
| 127 | dialog.set_current_folder_uri (folder_uri); |
|---|
| 128 | dialog.add_button (STOCK_CANCEL, ResponseType.CANCEL); |
|---|
| 129 | dialog.add_button (STOCK_OPEN, ResponseType.OK); |
|---|
| 130 | dialog.set_default_response (ResponseType.OK); |
|---|
| 131 | var filter = new FileFilter (); |
|---|
| 132 | filter.set_name (_("i4uc projects")); |
|---|
| 133 | filter.add_pattern ("*.i4uc"); |
|---|
| 134 | dialog.add_filter (filter); |
|---|
| 135 | |
|---|
| 136 | var uris = new ArrayList<string> (); |
|---|
| 137 | if (dialog.run () == ResponseType.OK) |
|---|
| 138 | { |
|---|
| 139 | folder_uri = dialog.get_current_folder_uri (); |
|---|
| 140 | foreach (var uri in dialog.get_uris ()) |
|---|
| 141 | uris.add (uri); |
|---|
| 142 | } |
|---|
| 143 | projects = uris.read_only_view; |
|---|
| 144 | dialog.destroy (); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | public AddFileDialogViewIface create_add_file_dialog_view () |
|---|
| 148 | { |
|---|
| 149 | return new AddFileDialogView (); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | public AddProfileDialogViewIface create_add_profile_dialog_view () |
|---|
| 153 | { |
|---|
| 154 | return new AddProfileDialogView (); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | private void on_new () |
|---|
| 158 | { |
|---|
| 159 | this.new_clicked (); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | private void on_open () |
|---|
| 163 | { |
|---|
| 164 | this.open_clicked (); |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | private void on_add_file () |
|---|
| 168 | { |
|---|
| 169 | this.add_file_clicked (); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | private void on_remove_file_from_project () |
|---|
| 173 | { |
|---|
| 174 | this.remove_file_from_project_clicked (); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | private void on_remove_file_from_profile () |
|---|
| 178 | { |
|---|
| 179 | this.remove_file_from_profile_clicked (); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | private void on_add_profile () |
|---|
| 183 | { |
|---|
| 184 | this.add_profile_clicked (); |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | private void on_close () |
|---|
| 188 | { |
|---|
| 189 | this.close_clicked (); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | private const ActionEntry[] _action_entries = |
|---|
| 193 | { |
|---|
| 194 | { "ProjectsMenuAction", null, N_("_Projects") }, |
|---|
| 195 | { "NewProjectAction", STOCK_NEW, null, null, N_("Create a new project"), on_new }, |
|---|
| 196 | { "OpenProjectAction", STOCK_OPEN, null, null, N_("Open a project"), on_open }, |
|---|
| 197 | { "AddFileProjectAction", STOCK_ADD, N_("Add file"), null, N_("Add a file to current project"), on_add_file }, |
|---|
| 198 | { "RemoveFileFromProjectProjectAction", STOCK_REMOVE, N_("Remove file from project"), null, N_("Remove a file from current project"), on_remove_file_from_project }, |
|---|
| 199 | { "RemoveFileFromProfileProjectAction", STOCK_REMOVE, N_("Remove file from profile"), null, N_("Remove a file from current profile"), on_remove_file_from_profile }, |
|---|
| 200 | { "AddProfileProjectAction", STOCK_ADD, N_("Add profile"), null, N_("Add a profile to current project"), on_add_profile }, |
|---|
| 201 | { "CloseProjectAction", STOCK_CLOSE, null, null, N_("Close current project"), on_close } |
|---|
| 202 | }; |
|---|
| 203 | |
|---|
| 204 | private const string _UI = """ |
|---|
| 205 | <ui> |
|---|
| 206 | <menubar name="MainMenu"> |
|---|
| 207 | <placeholder name="MenuBarOps"> |
|---|
| 208 | <menu name="ProjectsMenu" action="ProjectsMenuAction"> |
|---|
| 209 | <menuitem action="NewProjectAction"/> |
|---|
| 210 | <menuitem action="OpenProjectAction"/> |
|---|
| 211 | <separator/> |
|---|
| 212 | <menuitem action="AddFileProjectAction"/> |
|---|
| 213 | <menuitem action="RemoveFileFromProjectProjectAction"/> |
|---|
| 214 | <menuitem action="RemoveFileFromProfileProjectAction"/> |
|---|
| 215 | <separator/> |
|---|
| 216 | <menuitem action="AddProfileProjectAction"/> |
|---|
| 217 | <separator/> |
|---|
| 218 | <menuitem action="CloseProjectAction"/> |
|---|
| 219 | </menu> |
|---|
| 220 | </placeholder> |
|---|
| 221 | </menubar> |
|---|
| 222 | </ui>"""; |
|---|
| 223 | } |
|---|