if (!Global.mimicEvernoteInterface) {
for (int i=0; i<selections.size(); i++) {
currentSelection = selections.get(i);
- selectedNotebookGUIDs.add(currentSelection.text(2));
+ if (!currentSelection.text(2).equals("STACK"))
+ selectedNotebookGUIDs.add(currentSelection.text(2));
+ else {
+ String stackName = currentSelection.text(0);
+ for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
+ Notebook book = listManager.getNotebookIndex().get(j);
+ if (book.getStack()!=null && book.getStack().equalsIgnoreCase(stackName))
+ selectedNotebookGUIDs.add(book.getGuid());
+ }
+ }
}
previousSelectedNotebook = "";
} else {
String guid = "";
- if (selections.size() > 0)
+ String stackName = "";
+ if (selections.size() > 0) {
guid = (selections.get(0).text(2));
- if (!guid.equals("")) {
+ stackName = selections.get(0).text(0);
+ }
+ if (!guid.equals("") && !guid.equals("STACK")) {
selectedNotebookGUIDs.add(guid);
menuBar.notebookIconAction.setEnabled(true);
}
else {
menuBar.notebookIconAction.setEnabled(false);
+ for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
+ Notebook book = listManager.getNotebookIndex().get(j);
+ if (book.getStack() != null && book.getStack().equalsIgnoreCase(stackName))
+ selectedNotebookGUIDs.add(book.getGuid());
+ }
}
}
listManager.setSelectedNotebooks(selectedNotebookGUIDs);
import com.trolltech.qt.gui.QMenu;\r
import com.trolltech.qt.gui.QTreeWidget;\r
import com.trolltech.qt.gui.QTreeWidgetItem;\r
+import com.trolltech.qt.gui.QTreeWidgetItem.ChildIndicatorPolicy;\r
\r
import cx.fbn.nevernote.Global;\r
import cx.fbn.nevernote.filters.NotebookCounter;\r
private QAction iconAction;\r
public NoteSignal noteSignal;\r
private HashMap<String, QIcon> icons;\r
+ private final HashMap<String, QTreeWidgetItem> stacks;\r
// private final QTreeWidgetItem previousMouseOver;\r
// private boolean previousMouseOverWasSelected;\r
\r
\r
public NotebookTreeWidget() {\r
noteSignal = new NoteSignal();\r
- setProperty("hideTree", true);\r
+// setProperty("hideTree", true);\r
List<String> labels = new ArrayList<String>();\r
labels.add("Notebooks");\r
labels.add("");\r
} else\r
setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection);\r
\r
+ stacks = new HashMap<String, QTreeWidgetItem>();\r
// int width = Global.getColumnWidth("notebookTreeName");\r
// if (width>0)\r
// setColumnWidth(0, width);\r
for (int i=0; i<books.size(); i++) {\r
book = books.get(i);\r
child = new QTreeWidgetItem();\r
+ child.setChildIndicatorPolicy(ChildIndicatorPolicy.DontShowIndicatorWhenChildless);\r
child.setText(0, book.getName());\r
if (icons != null && !icons.containsKey(book.getGuid())) {\r
QIcon icon = findDefaultIcon(book.getGuid(), book.getName(), localBooks, book.isPublished());\r
}\r
child.setTextAlignment(1, ra.value());\r
child.setText(2, book.getGuid());\r
- addTopLevelItem(child);\r
+ if (book.getStack() == null || book.getStack().equalsIgnoreCase(""))\r
+ addTopLevelItem(child); \r
+ else {\r
+ String stackName = book.getStack();\r
+ QTreeWidgetItem parent;\r
+ if (!stacks.containsKey(stackName)) {\r
+ String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
+ QIcon stackIcon = new QIcon(iconPath+"books2.png");\r
+ parent = new QTreeWidgetItem();\r
+ stacks.put(stackName, parent);\r
+ parent.setText(0, stackName);\r
+ parent.setIcon(0, stackIcon);\r
+ parent.setText(2, "STACK");\r
+ parent.setTextAlignment(1, ra.value());\r
+ addTopLevelItem(parent);\r
+ } else\r
+ parent = stacks.get(stackName);\r
+ parent.addChild(child);\r
+ \r
+ }\r
}\r
\r
sortItems(0, SortOrder.AscendingOrder); \r
child = new QTreeWidgetItem();\r
child.setIcon(0, greenIcon);\r
child.setText(0, "All Notebooks");\r
-// child.setText(1, "0");\r
child.setText(2, "");\r
child.setTextAlignment(1, ra.value());\r
insertTopLevelItem(0,child);\r
resizeColumnToContents(0);\r
resizeColumnToContents(1);\r
}\r
+\r
// update the display with the current number of notes\r
public void updateCounts(List<Notebook> books, List<NotebookCounter> counts) {\r
QTreeWidgetItem root = invisibleRootItem();\r
QTreeWidgetItem child;\r
+ HashMap<String, Integer> stackCounts = new HashMap<String, Integer>();\r
\r
QBrush blue = new QBrush();\r
QBrush black = new QBrush();\r
blue.setColor(QColor.black);\r
int total=0;\r
\r
-// for (int i=0; i<counts.size(); i++) {\r
-// total=total+counts.get(i).getCount();\r
-// }\r
\r
int size = books.size();\r
if (Global.mimicEvernoteInterface)\r
size++;\r
\r
for (int i=0; i<size; i++) {\r
- child = root.child(i); \r
- if (child != null) {\r
- String guid = child.text(2);\r
- child.setText(1,"0");\r
- child.setForeground(0, black);\r
- child.setForeground(1, black);\r
- for (int j=0; j<counts.size(); j++) {\r
- if (counts.get(j).getGuid().equals(guid)) {\r
- child.setText(1, new Integer(counts.get(j).getCount()).toString());\r
- total = total+counts.get(j).getCount();\r
- if (counts.get(j).getCount() > 0) {\r
- child.setForeground(0, blue);\r
- child.setForeground(1, blue);\r
- }\r
- }\r
-// if (guid.equals("") && Global.mimicEvernoteInterface) {\r
-// child.setText(1, new Integer(total).toString());\r
-// }\r
+ child = root.child(i);\r
+ if (child != null && child.childCount() > 0) {\r
+ int count = child.childCount();\r
+ QTreeWidgetItem parent = child;\r
+ int localTotal = 0;\r
+ for (int j=0; j<count; j++) {\r
+ child = parent.child(j);\r
+ int childCount = updateCounts(child, books, counts, blue, black);\r
+ total = total+childCount;\r
+ localTotal = localTotal+childCount;\r
}\r
- }\r
+ parent.setText(1, new Integer(localTotal).toString());\r
+ } else\r
+ total = total+updateCounts(child, books, counts, blue, black);\r
}\r
\r
for (int i=0; i<size; i++) {\r
}\r
}\r
}\r
+ \r
+ private int updateCounts(QTreeWidgetItem child, List<Notebook> books, List<NotebookCounter> counts, QBrush blue, QBrush black) {\r
+ int total=0;\r
+ if (child != null) {\r
+ String guid = child.text(2);\r
+ child.setText(1,"0");\r
+ child.setForeground(0, black);\r
+ child.setForeground(1, black);\r
+ for (int j=0; j<counts.size(); j++) {\r
+ if (counts.get(j).getGuid().equals(guid)) {\r
+ child.setText(1, new Integer(counts.get(j).getCount()).toString());\r
+ total = counts.get(j).getCount();\r
+ if (counts.get(j).getCount() > 0) {\r
+ child.setForeground(0, blue);\r
+ child.setForeground(1, blue);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return total;\r
+ }\r
+ \r
// Return a list of the notebook guids, ordered by the current display order.\r
public List<String> getNotebookGuids() {\r
List<String> names = new ArrayList<String>();\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
check = query.prepare("Insert Into Notebook (guid, sequence, name, defaultNotebook, "\r
+"serviceCreated, serviceUpdated, published, " \r
- + "isDirty, autoEncrypt," \r
+ + "isDirty, autoEncrypt, stack" \r
+ "local, archived) Values("\r
+":guid, :sequence, :name, :defaultNotebook, "\r
+":serviceCreated, :serviceUpdated, :published, "\r
+":isDirty, :autoEncrypt, "\r
- +":local, false)");\r
+ +":local, false, :stack)");\r
query.bindValue(":guid", tempNotebook.getGuid());\r
query.bindValue(":sequence", tempNotebook.getUpdateSequenceNum());\r
query.bindValue(":name", tempNotebook.getName());\r
query.bindValue(":isDirty", false);\r
query.bindValue(":autoEncrypt", false);\r
query.bindValue(":local", local);\r
+ query.bindValue(":stack", tempNotebook.getStack());\r
\r
check = query.exec();\r
if (!check) {\r
check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
"serviceCreated, "+\r
"serviceUpdated, "+\r
- "published, defaultNotebook from Notebook order by name");\r
+ "published, defaultNotebook, stack from Notebook order by name");\r
if (!check)\r
logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
while (query.next()) {\r
}\r
tempNotebook.setPublished(new Boolean(query.valueString(6)));\r
tempNotebook.setDefaultNotebook(new Boolean(query.valueString(7)));\r
+ tempNotebook.setStack(query.valueString(8));\r
index.add(tempNotebook); \r
} \r
return index;\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
\r
check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
- "serviceCreated, serviceUpdated, published from Notebook where local=true order by name");\r
+ "serviceCreated, serviceUpdated, published, stack from Notebook where local=true order by name");\r
if (!check)\r
logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
while (query.next()) {\r
} catch (ParseException e) {\r
e.printStackTrace();\r
}\r
+ tempNotebook.setStack(query.valueString(7));\r
index.add(tempNotebook); \r
} \r
return index;\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
\r
check = query.exec("Select guid, sequence, name, defaultNotebook, " +\r
- "serviceCreated, serviceUpdated, published from Notebook where archived=true order by name");\r
+ "serviceCreated, serviceUpdated, published, stack from Notebook where archived=true order by name");\r
if (!check)\r
logger.log(logger.EXTREME, "Notebook SQL retrieve has failed.");\r
while (query.next()) {\r
e.printStackTrace();\r
}\r
tempNotebook.setPublished(new Boolean(query.valueString(6)));\r
+ tempNotebook.setStack(query.valueString(7));\r
index.add(tempNotebook); \r
} \r
return index;\r