OSDN Git Service

Fix bug where the external editor would force a close of the main window when the...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / ExternalBrowse.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.gui;\r
21 \r
22 import java.util.List;\r
23 \r
24 import com.trolltech.qt.core.Qt.WidgetAttribute;\r
25 import com.trolltech.qt.gui.QCloseEvent;\r
26 import com.trolltech.qt.gui.QMdiSubWindow;\r
27 \r
28 import cx.fbn.nevernote.Global;\r
29 import cx.fbn.nevernote.sql.DatabaseConnection;\r
30 \r
31 public class ExternalBrowse extends QMdiSubWindow {\r
32         private final DatabaseConnection  conn;\r
33         private final BrowserWindow     browser;\r
34         public Signal4<String, String, Boolean, BrowserWindow> contentsChanged;\r
35         public Signal1<String>  windowClosing;\r
36         boolean noteDirty;\r
37         \r
38         // Constructor\r
39         public ExternalBrowse(DatabaseConnection c) {\r
40                 setAttribute(WidgetAttribute.WA_QuitOnClose, false);\r
41                 setWindowTitle(tr("NeverNote"));\r
42                 conn = c;\r
43                 contentsChanged = new Signal4<String, String, Boolean, BrowserWindow>();\r
44                 windowClosing = new Signal1<String>();\r
45                 browser = new BrowserWindow(conn);\r
46                 setWidget(browser);\r
47                 noteDirty = false;\r
48                 browser.titleLabel.textChanged.connect(this, "titleChanged(String)");\r
49                 browser.getBrowser().page().contentsChanged.connect(this, "contentChanged()");\r
50         }\r
51         \r
52         private void contentChanged() {\r
53                 noteDirty = true;\r
54                 contentsChanged.emit(getBrowserWindow().getNote().getGuid(), getBrowserWindow().getContent(), false, getBrowserWindow());\r
55         }\r
56 \r
57         \r
58         @Override\r
59         public void closeEvent(QCloseEvent event) {\r
60                 if (noteDirty) \r
61                         contentsChanged.emit(getBrowserWindow().getNote().getGuid(), getBrowserWindow().getContent(), true, getBrowserWindow());\r
62                 windowClosing.emit(getBrowserWindow().getNote().getGuid());\r
63         }\r
64         \r
65     public BrowserWindow getBrowserWindow() {\r
66         return browser;\r
67     }\r
68     \r
69     private void titleChanged(String value) {\r
70         setWindowTitle(tr("NeverNote - ") +value);\r
71     }\r
72     \r
73         private void updateTitle(String guid, String title) {\r
74                 if (guid.equals(getBrowserWindow().getNote().getGuid())) {\r
75                         getBrowserWindow().loadingData(true);\r
76                         getBrowserWindow().setTitle(title);\r
77                         getBrowserWindow().getNote().setTitle(title);\r
78                         getBrowserWindow().loadingData(false);\r
79                 }\r
80         }\r
81         private void updateNotebook(String guid, String notebook) {\r
82                 if (guid.equals(getBrowserWindow().getNote().getGuid())) {\r
83                         getBrowserWindow().loadingData(true);\r
84                         getBrowserWindow().setNotebook(notebook);\r
85                         getBrowserWindow().loadingData(false);\r
86                 }\r
87         }\r
88         \r
89         private void updateTags(String guid, List<String> tags) {\r
90                 if (guid.equals(getBrowserWindow().getNote().getGuid())) {\r
91                         StringBuffer tagLine = new StringBuffer(100);\r
92                         for (int i=0; i<tags.size(); i++) {\r
93                                 if (i>0)\r
94                                         tagLine.append(Global.tagDelimeter+" ");\r
95                                 tagLine.append(tags.get(i));\r
96                                 \r
97                         }\r
98                         getBrowserWindow().loadingData(true);\r
99                         getBrowserWindow().getTagLine().setText(tagLine.toString());\r
100                         getBrowserWindow().loadingData(false);\r
101                 }\r
102         }\r
103 \r
104 }\r