Skip to content

Commit

Permalink
Fix bug and improve UI.
Browse files Browse the repository at this point in the history
Refactor code.
  • Loading branch information
Alexander Chapchuk committed Feb 1, 2021
1 parent 9d1fc7e commit fac8bba
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 15 deletions.
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'org.bigtows'
version '2.1-b.3'
version '2.1-b.4'

sourceCompatibility = 11

Expand Down Expand Up @@ -41,17 +41,20 @@ jar {

patchPluginXml {
changeNotes """
<h1>Release: 2.1-b.3</h1><br>
<h1>Release: 2.1</h1><br>
<ul>
<li>
New feature: Shortcuts idea by <a href="/~https://github.com/BigTows/PinNote/issues/26">#26 By ash0080</a>
<ul>
New feature: Shortcuts and Drag and Drop mode idea by <a href="/~https://github.com/BigTows/PinNote/issues/26">#26 By ash0080</a>
<ul>Hey! PinNote now support new shortcuts:
<li>Create new target, default shortcut: ctrl/⌘ ⇧ T</li>
<li>Create new root task: Shift + enter</li>
<li>Delete current task: ctrl/⌘ ⇧ ⌫</li>
<li>Select previous task: ↑</li>
<li>Select next task: ↓</li>
</ul>
<ul>
Drag and drop mode here! Now you can reorder your tasks or move to another note
</ul>
</li>
</ul>
"""
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/org/bigtows/window/ui/notetree/NoteTree.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.bigtows.window.ui.notetree;

import com.intellij.ui.JBColor;
import com.intellij.ui.treeStructure.Tree;
import org.bigtows.window.ui.notetree.listener.NoteTreeChangeListener;
import org.bigtows.window.ui.notetree.listener.NoteTreeNeedRefreshModelListener;
Expand All @@ -10,6 +9,7 @@
import org.bigtows.window.ui.notetree.tree.entity.Task;
import org.bigtows.window.ui.notetree.tree.node.AbstractTaskTreeNode;
import org.bigtows.window.ui.notetree.tree.node.NoteTreeNode;
import org.bigtows.window.ui.notetree.tree.node.SubTaskTreeNode;
import org.bigtows.window.ui.notetree.tree.node.TaskTreeNode;
import org.bigtows.window.ui.notetree.tree.transfer.TreeTransferHandler;
import org.bigtows.window.ui.notetree.utils.ExpandTreeUtils;
Expand Down Expand Up @@ -191,11 +191,19 @@ public void needUpdateModel() {
}


/**
* Check has focused (mean editable right now task) task.
*
* @return {@code true} if exists else {@code false}
*/
public boolean hasFocusedTask() {
var path = tree.getEditingPath();
return path != null && path.getLastPathComponent() instanceof AbstractTaskTreeNode;
}

/**
* Remove focused (mean editable right now task) task.
*/
public void removeFocusedTask() {

var value = ((AbstractTaskTreeNode) tree.getEditingPath().getLastPathComponent());
Expand All @@ -205,6 +213,16 @@ public void removeFocusedTask() {
value.removeFromParent();
if (parent instanceof NoteTreeNode && parent.getChildCount() == 0) {
((NoteTreeNode) parent).add(new TaskTreeNode(Task.builder().build()));
} else if (parent instanceof TaskTreeNode && parent.getChildCount() > 0) {
var needCheck = true;
for (int i = 0; i < parent.getChildCount(); i++) {
var subTask = (SubTaskTreeNode) parent.getChildAt(i);
if (!subTask.getUserObject().getChecked()) {
needCheck = false;
break;
}
}
((TaskTreeNode) parent).getUserObject().setChecked(needCheck);
}
tree.updateUI();
processChangeEvent();
Expand All @@ -229,6 +247,8 @@ public void removeFocusedTask() {
* @param isEnable status of mode
*/
public void setDragEnable(boolean isEnable) {
tree.clearSelection();
tree.setEditable(!isEnable);
tree.setDragEnabled(isEnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private Thread initTimer() {
if (status == Status.EDITING) {
status = Status.NEED_PUBLISH;
} else if (status == Status.NEED_PUBLISH) {
System.out.println("Publish!!");
runnable.run();
status = Status.END;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ protected void exportDone(JComponent source, Transferable data, int action) {
if ((action & MOVE) == MOVE) {
JTree tree = (JTree) source;
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();

updateCheckedStatusForMovedNode(nodeToRemove, true);

model.removeNodeFromParent(nodeToRemove);

this.fillEmptyTaskAtEmptyTarget(tree);
Expand All @@ -103,26 +106,53 @@ protected void exportDone(JComponent source, Transferable data, int action) {
}
}

/**
* Update checked status for node
*
* @param movedAbstractTaskTreeNode moved node
* @param isDeletedNode is deleted node
*/
private void updateCheckedStatusForMovedNode(DefaultMutableTreeNode movedAbstractTaskTreeNode, boolean isDeletedNode) {
if (movedAbstractTaskTreeNode instanceof SubTaskTreeNode) {
var task = (TaskTreeNode) movedAbstractTaskTreeNode.getParent();
boolean needCheck = true;
if (task.getChildCount() == 0) {
return;
}
for (int i = 0; i < task.getChildCount(); i++) {
var subTask = (SubTaskTreeNode) task.getChildAt(i);

if (isDeletedNode) {
if (!subTask.equals(movedAbstractTaskTreeNode) && !subTask.getUserObject().getChecked()) {
needCheck = false;
break;
}
} else {
if (!subTask.getUserObject().getChecked()) {
needCheck = false;
break;
}
}

}
task.getUserObject().setChecked(needCheck);
}
}

/**
* Adding empty task for each empty target
*
* @param tree source
*/
private void fillEmptyTaskAtEmptyTarget(JTree tree) {
var root = (DefaultMutableTreeNode) tree.getModel().getRoot();
var hasNewTask = false;
for (int i = 0; i < root.getChildCount(); i++) {
var note = (DefaultMutableTreeNode) root.getChildAt(i);
if (note.getChildCount() == 0) {
hasNewTask = true;
note.add(new TaskTreeNode(Task.builder().build()));
}
}

if (hasNewTask) {
tree.updateUI();
}

}


Expand Down Expand Up @@ -172,6 +202,7 @@ public boolean importData(TransferHandler.TransferSupport support) {

for (AbstractTaskTreeNode node : nodes) {
model.insertNodeInto(node, parent, index++);
updateCheckedStatusForMovedNode(node, false);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ private BorderLayoutPanel createActionToolBar() {
group.addSeparator();
group.add(new ForceRefreshNoteAction(notebookTabbedPane));
group.addSeparator();
group.add(new OpenSettings(), Constraints.LAST);
group.add(new DragAndDropAction(notebookTabbedPane));
group.addSeparator();
group.add(new OpenSettings(), Constraints.LAST);
final ActionToolbar actionToolBar = ActionManager.getInstance().createActionToolbar("PinNoteToolbar", group, true);
var panel = JBUI.Panels.simplePanel(actionToolBar.getComponent());
panel.setBorder(new BottomBorder(JBUI.CurrentTheme.ToolWindow.borderColor()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@

import javax.swing.*;

public class DragAndDropAction extends AnAction implements Toggleable, DumbAware {

/**
* Action for switch drag and drop mode
*/
public final class DragAndDropAction extends AnAction implements Toggleable, DumbAware {

/**
* Tabbed pane
*/
private final JTabbedPane notebookTabbedPane;

/**
* Current status
*/
private boolean isEnable = false;

public DragAndDropAction(JTabbedPane notebookTabbedPane) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
text="Create New Target for Current Storage">
<keyboard-shortcut first-keystroke="control shift BACK_SPACE" keymap="$default"/>
</action>


<action id="org.bigtows.window.ui.pinnote.action.OpenSettings" class="org.bigtows.window.ui.pinnote.action.OpenSettings"
text="Open plugin settings">
</action>

</actions>
<depends>com.intellij.modules.lang</depends>
</idea-plugin>

0 comments on commit fac8bba

Please sign in to comment.