OSDN Git Service

Added the ability to merge tags and corrected some shortcuts.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / TagMerge.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.dialog;\r
21 \r
22 import java.util.List;\r
23 \r
24 import com.evernote.edam.type.Tag;\r
25 import com.trolltech.qt.gui.QComboBox;\r
26 import com.trolltech.qt.gui.QDialog;\r
27 import com.trolltech.qt.gui.QHBoxLayout;\r
28 import com.trolltech.qt.gui.QIcon;\r
29 import com.trolltech.qt.gui.QLabel;\r
30 import com.trolltech.qt.gui.QPushButton;\r
31 import com.trolltech.qt.gui.QSpacerItem;\r
32 import com.trolltech.qt.gui.QVBoxLayout;\r
33 \r
34 public class TagMerge extends QDialog {\r
35         private final QComboBox                 newTag;\r
36         private final QPushButton               okButton;\r
37         private final QPushButton               cancelButton;\r
38         private boolean                                 okClicked;\r
39         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
40         \r
41         public TagMerge(List<Tag> tags) {\r
42                 setWindowIcon(new QIcon(iconPath+"tag.png"));\r
43                 okClicked = false;\r
44                 \r
45                 okButton = new QPushButton();\r
46                 okButton.setText(tr("OK"));\r
47                 okButton.pressed.connect(this, "onClicked()");\r
48                 \r
49                 cancelButton = new QPushButton();\r
50                 cancelButton.setText(tr("Cancel"));\r
51                 cancelButton.pressed.connect(this, "onCancel()");\r
52         \r
53                 \r
54                 QVBoxLayout middleLayout = new QVBoxLayout();\r
55                 middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
56                 middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
57 \r
58                 QVBoxLayout closeLayout = new QVBoxLayout();\r
59                 closeLayout.addWidget(new QLabel(tr("Merge Into")));\r
60                 newTag = new QComboBox();\r
61                 closeLayout.addWidget(newTag);\r
62                 \r
63                 QHBoxLayout buttonLayout = new QHBoxLayout();\r
64                 buttonLayout.addStretch(1);\r
65                 buttonLayout.addWidget(okButton);\r
66                 buttonLayout.addWidget(cancelButton);\r
67                 setWindowTitle(tr("Open/Close Notebooks"));\r
68                 \r
69                 QHBoxLayout upperLayout = new QHBoxLayout();\r
70                 upperLayout.addLayout(middleLayout);\r
71                 upperLayout.addLayout(closeLayout);\r
72                 \r
73                 QVBoxLayout mainLayout = new QVBoxLayout();\r
74                 mainLayout.addLayout(upperLayout);\r
75                 //mainLayout.addStretch(1);\r
76                 mainLayout.addSpacing(1);\r
77                 mainLayout.addLayout(buttonLayout);\r
78                 setLayout(mainLayout);\r
79                 \r
80                 for (int i=0; i<tags.size(); i++) {\r
81                         newTag.addItem(tags.get(i).getName(), tags.get(i).getGuid());\r
82                 }\r
83                 setWindowTitle(tr("Merge Tags"));\r
84         }\r
85         \r
86         @SuppressWarnings("unused")\r
87         private void onClicked() {\r
88                 okClicked = true;\r
89                 close();\r
90         }\r
91         \r
92         @SuppressWarnings("unused")\r
93         private void onCancel() {\r
94                 okClicked = false;\r
95                 close();\r
96         }\r
97         \r
98         public boolean okClicked() {\r
99                 return okClicked;\r
100         }\r
101         \r
102         public String getNewTagGuid() {\r
103                 int position = newTag.currentIndex();\r
104                 return newTag.itemData(position).toString();\r
105         }\r
106 }\r