| 1 |
/* DocumentManager.vala |
| 2 |
* |
| 3 |
* Copyright 2023 Diego Iván <[email protected]> |
| 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 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 19 |
*/ |
| 20 |
|
| 21 |
public sealed class PaperClip.Services.DocumentManager : Object { |
| 22 |
public bool changed { get; private set; default = false; } |
| 23 |
private Document _document; |
| 24 |
public Document document { |
| 25 |
get { |
| 26 |
return _document; |
| 27 |
} |
| 28 |
set { |
| 29 |
disconnect_document (); |
| 30 |
|
| 31 |
_document = value; |
| 32 |
changed = false; |
| 33 |
|
| 34 |
document.notify.connect (on_doc_changed); |
| 35 |
document.keywords.items_changed.connect (on_doc_changed); |
| 36 |
document.keyword_changed.connect (on_doc_changed); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
public async void save (string? uri = null) { |
| 41 |
yield document.save (uri ?? document.original_file.get_uri ()); |
| 42 |
changed = false; |
| 43 |
} |
| 44 |
|
| 45 |
private void disconnect_document () { |
| 46 |
if (document == null) { |
| 47 |
return; |
| 48 |
} |
| 49 |
document.notify.disconnect (on_doc_changed); |
| 50 |
document.keywords.items_changed.disconnect (on_doc_changed); |
| 51 |
document.keyword_changed.disconnect (on_doc_changed); |
| 52 |
} |
| 53 |
|
| 54 |
private void on_doc_changed () { |
| 55 |
changed = true; |
| 56 |
} |
| 57 |
} |