Skip to content

Commit

Permalink
Added shortcuts by issues #26
Browse files Browse the repository at this point in the history
# Release: 2.1

*   New feature: Shortcuts and Drag and Drop mode idea by [#26 By ash0080](#26)

    *   Create a new target, default shortcut: ctrl/⌘ ⇧ T
    *   Create a new root task: Shift + enter
    *   Delete current task: ctrl/⌘ ⇧ ⌫
    *   Select previous task: ↑
    *   Select next task: ↓
  • Loading branch information
BigTows authored Feb 22, 2021
2 parents cec9694 + 4d18bb1 commit c196142
Show file tree
Hide file tree
Showing 27 changed files with 1,057 additions and 234 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ Features
* Sync notes between many instance IDE.
* The opportunity to share notes on target.
* Support for SubTasks.
* Shortcuts
* Create a new target, default shortcut: ctrl/⌘ ⇧ T
* Create a new root task: Shift + enter
* Delete current task: ctrl/⌘ ⇧ ⌫
* Select previous task: ↑
* Select next task: ↓

## [Guide](https://github.com/BigTows/PinNote/wiki/Instruction)

## Demo.
### General view
![Demo](https://pinnote.bigtows.org/example/demo_new.gif)
![Demo](https://pinnote.bigtows.org/example/review-new.gif)
### Setup.
![Demo](https://pinnote.bigtows.org/example/demo_setup.gif)
### Sync demo (GUI from old version).
Expand Down
20 changes: 16 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.0.2.2'
version '2.1'

sourceCompatibility = 11

Expand Down Expand Up @@ -41,12 +41,24 @@ jar {

patchPluginXml {
changeNotes """
<h1>Release: 2.0.2.2</h1><br>
<h1>Release: 2.1</h1><br>
<ul>
<li>Fix bug from report <a href="https://github.com/BigTows/PinNote/issues/27">#27 By yanchick</a></li>
<li>
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 a new target, default shortcut: ctrl/⌘ ⇧ T</li>
<li>Create a 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>
"""
//https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html?search=build
sinceBuild "193.2252"
untilBuild "203.*"
untilBuild "213.*"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
11 changes: 6 additions & 5 deletions src/main/java/org/bigtows/utils/PinNoteIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@ public class PinNoteIcon {
* Icon used in notification's
*/
public static final Icon NOTIFICATION_PIN_NOTE = PinNoteIcon.getSvgIconFromResource(
"/icons/toolWindowRight_dark.svg", 1.2f
"icons/toolWindowRight_dark.svg", 1.2f
).orElse(AllIcons.Ide.FatalError);

/**
* Icon for evernote in tab context
*/
public static final Icon TAB_EVERNOTE_ICON = PinNoteIcon.getSvgIconFromResource(
"/icons/evernote.svg", 0.5f
"icons/evernote.svg", 0.5f
).orElse(AllIcons.Ide.FatalError);

/**
* Icon for local storage in tab context
*/
public static final Icon TAB_LOCAL_NOTE_ICON = PinNoteIcon.getSvgIconFromResource(
"/icons/file.svg", 0.7f
"icons/file.svg", 0.7f
).orElse(AllIcons.Ide.FatalError);

/**
* Icon for evernote in settings menu
*/
public static final Icon SETTINGS_EVERNOTE_ICON = PinNoteIcon.getSvgIconFromResource(
"/icons/evernote.svg", 1.2f
"icons/evernote.svg", 1.2f
).orElse(AllIcons.Ide.FatalError);

/**
* Icon for evernote in settings menu
*/
public static final Icon SETTINGS_LOCAL_NOTE_ICON = PinNoteIcon.getSvgIconFromResource(
"/icons/file.svg", 1.5f
"icons/file.svg", 1.5f
).orElse(AllIcons.Ide.FatalError);

/**
Expand All @@ -66,6 +66,7 @@ public static Optional<Icon> getSvgIconFromResource(String resource, float scale
)
);
} catch (Throwable e) {
e.printStackTrace();
return Optional.empty();
}
}
Expand Down
94 changes: 89 additions & 5 deletions src/main/java/org/bigtows/window/ui/notetree/NoteTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import com.intellij.ui.treeStructure.Tree;
import org.bigtows.window.ui.notetree.listener.NoteTreeChangeListener;
import org.bigtows.window.ui.notetree.listener.NoteTreeNeedRefreshModelListener;
import org.bigtows.window.ui.notetree.tree.editor.PinNoteTreeCellEditor;
import org.bigtows.window.ui.notetree.tree.PinNoteTreeCellEditor;
import org.bigtows.window.ui.notetree.tree.PinNoteTreeCellRender;
import org.bigtows.window.ui.notetree.tree.entity.Note;
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.render.PinNoteTreeCellRender;
import org.bigtows.window.ui.notetree.tree.transfer.TreeTransferHandler;
import org.bigtows.window.ui.notetree.utils.ExpandTreeUtils;

import javax.swing.*;
Expand All @@ -34,6 +37,11 @@ public NoteTree(List<MutableTreeNode> data) {
tree.setCellRenderer(new PinNoteTreeCellRender(this::processChangeEvent));
tree.setEditable(true);
tree.setRootVisible(false);
tree.setSelectionModel(new DefaultTreeSelectionModel());
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setDragEnabled(false);
tree.setDropMode(DropMode.ON_OR_INSERT);
tree.setTransferHandler(new TreeTransferHandler(this::processChangeEvent));
setLayout(new BorderLayout());
add(tree, BorderLayout.CENTER);
}
Expand Down Expand Up @@ -129,6 +137,9 @@ public void addNewNote(String name) {
SwingUtilities.invokeLater(() -> {
ExpandTreeUtils.expandLeaf(tree, listOfLeaf);
tree.updateUI();
var treePath = new TreePath(((AbstractTaskTreeNode) noteTreeNode.getChildAt(0)).getPath());
tree.expandPath(treePath);
tree.startEditingAtPath(treePath);
});
}

Expand Down Expand Up @@ -170,13 +181,86 @@ public void removeSelectedElement() {
new TaskTreeNode(Task.builder().build())
);
}
this.processChangeEvent();
tree.updateUI();
}
if (selectedPath instanceof SubTaskTreeNode && tree.getSelectionPath() != null) {
var parent = tree.getSelectionPath().getParentPath().getLastPathComponent();
this.recalculateCheckStatus((TreeNode) parent);
}
this.processChangeEvent();
tree.updateUI();
}

public void needUpdateModel() {
/**
* Notify about need update model
*/
public void notifyUpdateModel() {
this.needUpdateModelListeners.forEach(NoteTreeNeedRefreshModelListener::refresh);
}


/**
* 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());

var parent = value.getParent();
int indexValue = parent.getIndex(value);
value.removeFromParent();
if (parent instanceof NoteTreeNode && parent.getChildCount() == 0) {
((NoteTreeNode) parent).add(new TaskTreeNode(Task.builder().build()));
}
this.recalculateCheckStatus(parent);
tree.updateUI();
processChangeEvent();


//Set cursor at nearby position
TreePath cursorPath;
if (parent instanceof TaskTreeNode && parent.getChildCount() == 0) {
cursorPath = new TreePath(((TaskTreeNode) parent).getPath());
} else {
cursorPath = new TreePath(((AbstractTaskTreeNode) parent.getChildAt(
parent.getChildCount() - 1 < indexValue ? indexValue - 1 : indexValue
)).getPath());
}

SwingUtilities.invokeLater(() -> tree.startEditingAtPath(cursorPath));
}

private void recalculateCheckStatus(TreeNode parent) {
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);
}
}

/**
* Enable or disable drag and drop mode
*
* @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 @@ -23,12 +23,11 @@ private Thread initTimer() {
while (true) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
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
Loading

0 comments on commit c196142

Please sign in to comment.