OSDN Git Service

Correct problem parsing notes where carriage returns did not separate some XML lines...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / SavedSearchTreeWidget.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.ArrayList;\r
23 import java.util.List;\r
24 \r
25 import com.evernote.edam.type.SavedSearch;\r
26 import com.trolltech.qt.core.Qt.SortOrder;\r
27 import com.trolltech.qt.gui.QAbstractItemView;\r
28 import com.trolltech.qt.gui.QAction;\r
29 import com.trolltech.qt.gui.QContextMenuEvent;\r
30 import com.trolltech.qt.gui.QIcon;\r
31 import com.trolltech.qt.gui.QMenu;\r
32 import com.trolltech.qt.gui.QTreeWidget;\r
33 import com.trolltech.qt.gui.QTreeWidgetItem;\r
34 \r
35 public class SavedSearchTreeWidget extends QTreeWidget {\r
36         private QAction editAction;\r
37         private QAction deleteAction;\r
38         private QAction addAction;\r
39         \r
40         \r
41         public SavedSearchTreeWidget() {\r
42 //              setAcceptDrops(true);\r
43 //              setDragEnabled(true);\r
44                 setAcceptDrops(false);\r
45                 setDragEnabled(false);\r
46 //              setDragDropMode(QAbstractItemView.DragDropMode.DragDrop);\r
47         setHeaderLabel(tr("Saved Searches"));\r
48         setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
49         }\r
50         \r
51         public void setEditAction(QAction e) {\r
52                 editAction = e;\r
53         }\r
54         public void setDeleteAction(QAction d) {\r
55                 deleteAction = d;\r
56         }\r
57         public void setAddAction(QAction a) {\r
58                 addAction = a;\r
59         }\r
60         \r
61         public void load(List<SavedSearch> tempList) {\r
62         SavedSearch search;\r
63         List<QTreeWidgetItem> index = new ArrayList<QTreeWidgetItem>();\r
64                 \r
65         //Clear out the tree & reload\r
66         clear();\r
67         String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
68                 QIcon icon = new QIcon(iconPath+"search.png");\r
69         \r
70                 for (int i=0; i<tempList.size(); i++) {\r
71                         search = tempList.get(i);\r
72                         QTreeWidgetItem child = new QTreeWidgetItem();\r
73                         child.setText(0, search.getName());\r
74                         child.setIcon(0,icon);\r
75                         child.setText(1, search.getGuid());\r
76                         index.add(child);\r
77                         addTopLevelItem(child);\r
78                 } \r
79         sortItems(0, SortOrder.AscendingOrder);\r
80         }\r
81 \r
82         \r
83         public boolean selectGuid(String guid) {\r
84                 QTreeWidgetItem root = invisibleRootItem();\r
85                 QTreeWidgetItem child;\r
86 \r
87                 for (int i=0; i<root.childCount(); i++) {\r
88                         child = root.child(i);\r
89                         if (child.text(1).equals(guid)) {\r
90                                 child.setSelected(true);\r
91                                 return true;\r
92                         }\r
93                 }\r
94                 return false;\r
95         }\r
96         \r
97         \r
98         @Override\r
99         public void contextMenuEvent(QContextMenuEvent event) {\r
100                 QMenu menu = new QMenu(this);\r
101                 menu.addAction(addAction);\r
102                 menu.addAction(editAction);\r
103                 menu.addAction(deleteAction);\r
104                 menu.exec(event.globalPos());\r
105         }\r
106         \r
107         \r
108         public void selectSavedSearch(QTreeWidgetItem item) {\r
109                 QTreeWidgetItem root = invisibleRootItem();\r
110                 QTreeWidgetItem child;\r
111                 \r
112                 for (int i=0; i<root.childCount(); i++) {\r
113                         child = root.child(i); \r
114                         if (child.text(1).equals(item.text(1))) {\r
115                                 child.setSelected(true);\r
116                                 return;\r
117                         }\r
118                 }\r
119         }\r
120 }\r