source: libi4uc/i4ucdocumentpagepresenter.vala @ 8136fe29ea470e63713d323bab546b243fe7ccd7

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

Add 'new', 'save' and 'save as' document actions

  • Property mode set to 100644
Line 
1/* i4ucdocumentpagepresenter.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
22public class I4uc.DocumentPagePresenter : GLib.Object
23{
24        private DocumentPageViewIface _view;
25        private Document _document = new Document ();
26       
27        public DocumentPageViewIface view { get { return _view; } }
28        public bool is_new { set; get; }
29       
30        public bool can_save
31        {
32                get
33                {
34                        if (_is_new)
35                                return true;
36                        return _document.can_write;
37                }
38        }
39       
40        public signal void selected ();
41        public signal void remove_document ();
42       
43        public DocumentPagePresenter (DocumentPageViewIface view)
44        {
45                _view = view;
46               
47                //connect view signals
48                _view.selected.connect (on_selected);
49                _view.content_changed.connect (on_content_changed);
50        }
51       
52        public void save ()
53        {
54                if (_is_new)
55                        save_as ();
56                else if (_view.tab_mark)
57                {
58                        _document.save_contents (_view.content);
59                        _view.tab_mark = false;
60                }
61        }
62       
63        public void save_as ()
64        {
65                string document_uri;
66                var response = _view.show_save_dialog ("", out document_uri);
67                if (response == Gtk.ResponseType.OK)
68                {
69                        try
70                        {
71                                _document.save_contents (_view.content, document_uri);
72                                _view.title = document_uri;
73                                _is_new = false;
74                                _view.tab_title = _document.display_name;
75                                _view.tab_tooltip = "<b>%s</b> %s".printf (_("Name:"), _document.parse_name);
76                                _view.tab_image = Gtk.STOCK_FILE;
77                                _view.tab_mark = false;
78                        }
79                        catch (GLib.Error e)
80                        {
81                                _view.show_error_message (e.message);
82                        }
83                }
84        }
85       
86        private void on_selected ()
87        {
88                this.selected ();
89        }
90       
91        private void on_content_changed ()
92        {
93                _view.tab_mark = true;
94        }
95}
Note: See TracBrowser for help on using the repository browser.