OSDN Git Service

Added option to add tag as a child of a selected tag.
authorRandy Baumgarte <randy@fbn.cx>
Sun, 20 Mar 2011 17:28:47 +0000 (13:28 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Sun, 3 Apr 2011 18:02:48 +0000 (14:02 -0400)
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/dialog/TagEdit.java

index 4ccdfa9..8ac26d2 100644 (file)
@@ -1944,6 +1944,14 @@ public class NeverNote extends QMainWindow{
                logger.log(logger.HIGH, "Inside NeverNote.addTag");
                TagEdit edit = new TagEdit();
                edit.setTagList(listManager.getTagIndex());
+
+               List<QTreeWidgetItem> selections = tagTree.selectedItems();
+               QTreeWidgetItem currentSelection = null;
+               if (selections.size() > 0) {
+                       currentSelection = selections.get(0);
+                       edit.setParentTag(currentSelection.text(0));
+               }
+
                edit.exec();
        
                if (!edit.okPressed())
@@ -1957,6 +1965,11 @@ public class NeverNote extends QMainWindow{
                newTag.setUpdateSequenceNum(0);
                newTag.setGuid(randint);
                newTag.setName(edit.getTag());
+               if (edit.getParentTag().isChecked()) {
+                       newTag.setParentGuid(currentSelection.text(2));
+                       newTag.setParentGuidIsSet(true);
+                       currentSelection.setExpanded(true);
+               }
                conn.getTagTable().addTag(newTag, true);
                listManager.getTagIndex().add(newTag);
                reloadTagTree(true);
index 7a43821..72c4ff7 100644 (file)
@@ -22,6 +22,7 @@ package cx.fbn.nevernote.dialog;
 import java.util.List;
 
 import com.evernote.edam.type.Tag;
+import com.trolltech.qt.gui.QCheckBox;
 import com.trolltech.qt.gui.QDialog;
 import com.trolltech.qt.gui.QGridLayout;
 import com.trolltech.qt.gui.QIcon;
@@ -33,6 +34,7 @@ public class TagEdit extends QDialog {
        private boolean         okPressed;
        private final QLineEdit tag;
        QPushButton ok;
+       private final QCheckBox useParentTag;
        List<Tag>               currentTags;
        private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
        
@@ -48,8 +50,14 @@ public class TagEdit extends QDialog {
                tag = new QLineEdit();
                textGrid.addWidget(new QLabel(tr("Tag Name")), 1,1);
                textGrid.addWidget(tag, 1, 2);
+               
                textGrid.setContentsMargins(10, 10,-10, -10);
                grid.addLayout(textGrid,1,1);
+
+               useParentTag = new QCheckBox();
+               useParentTag.setVisible(false);
+               useParentTag.setChecked(false);
+               grid.addWidget(useParentTag,2,1);
                
                QGridLayout buttonGrid = new QGridLayout();
                ok = new QPushButton(tr("OK"));
@@ -60,7 +68,7 @@ public class TagEdit extends QDialog {
                tag.textChanged.connect(this, "textChanged()");
                buttonGrid.addWidget(ok, 3, 1);
                buttonGrid.addWidget(cancel, 3,2);
-               grid.addLayout(buttonGrid,2,1);
+               grid.addLayout(buttonGrid,3,1);
        }
        
        // The OK button was pressed
@@ -86,6 +94,16 @@ public class TagEdit extends QDialog {
        public void setTag(String name) {
                tag.setText(name);
        }
+
+       // Set the tag name
+       public void setParentTag(String name) {
+               useParentTag.setText(tr("Create as child of \"") +name +"\"");
+               useParentTag.setVisible(true);
+               useParentTag.setChecked(true);
+       }
+       public QCheckBox getParentTag() {
+               return useParentTag;
+       }
        
        // Check if the OK button was pressed
        public boolean okPressed() {