OSDN Git Service

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