source: libi4uc/i4ucprojectssidepagepresenter.vala @ acc9147bf954331ae9f2f16fc044ae08936bd679

Revision acc9147bf954331ae9f2f16fc044ae08936bd679, 3.1 KB checked in by Matias De la Puente <mfpuente.ar@…>, 3 years ago (diff)

Projects: Open the file when is activated from the projects panel

  • Property mode set to 100644
Line 
1/* i4ucprojectssidepagepresenter.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 */
21using Gee;
22
23public class I4uc.ProjectsSidePagePresenter : GLib.Object
24{
25        private ProjectsSidePageViewIface _view;
26        private DocumentsPresenter _documents_presenter;
27        private ArrayList<Project> _projects = new ArrayList<Project> ();
28
29        public Project current_project
30        {
31                set { _view.current_project = value.uri; }
32                owned get { return get_project_from_uri (_view.current_project); }
33        }
34
35        public Gee.List<Project> projects { owned get { return _projects.read_only_view; } }
36
37        public ProjectsSidePagePresenter (ProjectsSidePageViewIface view, DocumentsPresenter documents_presenter)
38        {
39                _view = view;
40                _documents_presenter = documents_presenter;
41
42                //Configure view
43                _view.tab_title = _("Projects");
44
45                //Connect view signals
46                _view.project_changed.connect (on_project_changed);
47                _view.file_activated.connect (on_file_activated);
48        }
49
50        public void add_project (Project project)
51        {
52                if (!(project in _projects))
53                {
54                        _view.add_project (project.uri, project.name);
55                        _projects.add (project);
56                }
57                _view.current_project = project.uri;
58        }
59
60        public void remove_project (Project project)
61        {
62                if (!(project in _projects))
63                        return;
64                _projects.remove (project);
65                _view.remove_project (project.uri);
66                if (_projects.size > 0)
67                        _view.current_project = _projects[0].uri;
68        }
69
70        public void remove_all_projects ()
71        {
72                for (int i = _projects.size-1; i >= 0; i--)
73                {
74                        var project = _projects[i];
75                        _projects.remove (project);
76                        _view.remove_project (project.uri);
77                }
78        }
79
80        private void on_project_changed ()
81        {
82                _view.clear_files_list ();
83                _view.clear_profiles_list ();
84
85                var current_project = get_project_from_uri (_view.current_project);
86                if (current_project == null)
87                        return;
88
89                //Load files list
90                foreach (var file in current_project.files)
91                        _view.add_file (file);
92
93                //Load profiles list
94                foreach (var profile in current_project.profiles.values)
95                {
96                        _view.add_profile (profile.name);
97                        foreach (var file in profile.files)
98                                _view.add_profile_file (profile.name, file);
99                }
100        }
101
102        private void on_file_activated ()
103        {
104                var document_uri = this.current_project.get_file_uri (_view.current_file);
105                _documents_presenter.open_document (document_uri);
106        }
107
108        private Project? get_project_from_uri (string? project_uri)
109        {
110                foreach (var project in _projects)
111                        if (project.uri == project_uri)
112                                return project;
113                return null;
114        }
115}
Note: See TracBrowser for help on using the repository browser.