Skip to content

Commit c196142

Browse files
authored
Added shortcuts by issues #26
# 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: ↓
2 parents cec9694 + 4d18bb1 commit c196142

27 files changed

Lines changed: 1057 additions & 234 deletions

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ Features
1414
* Sync notes between many instance IDE.
1515
* The opportunity to share notes on target.
1616
* Support for SubTasks.
17+
* Shortcuts
18+
* Create a new target, default shortcut: ctrl/⌘ ⇧ T
19+
* Create a new root task: Shift + enter
20+
* Delete current task: ctrl/⌘ ⇧ ⌫
21+
* Select previous task: ↑
22+
* Select next task: ↓
1723

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

2026
## Demo.
2127
### General view
22-
![Demo](https://pinnote.bigtows.org/example/demo_new.gif)
28+
![Demo](https://pinnote.bigtows.org/example/review-new.gif)
2329
### Setup.
2430
![Demo](https://pinnote.bigtows.org/example/demo_setup.gif)
2531
### Sync demo (GUI from old version).

build.gradle

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'org.bigtows'
7-
version '2.0.2.2'
7+
version '2.1'
88

99
sourceCompatibility = 11
1010

@@ -41,12 +41,24 @@ jar {
4141

4242
patchPluginXml {
4343
changeNotes """
44-
<h1>Release: 2.0.2.2</h1><br>
44+
<h1>Release: 2.1</h1><br>
4545
<ul>
46-
<li>Fix bug from report <a href="https://github.com/BigTows/PinNote/issues/27">#27 By yanchick</a></li>
46+
<li>
47+
New feature: Shortcuts and Drag and Drop mode idea by <a href="https://github.com/BigTows/PinNote/issues/26">#26 By ash0080</a>
48+
<ul>Hey! PinNote now support new shortcuts:
49+
<li>Create a new target, default shortcut: ctrl/⌘ ⇧ T</li>
50+
<li>Create a new root task: Shift + enter</li>
51+
<li>Delete current task: ctrl/⌘ ⇧ ⌫</li>
52+
<li>Select previous task: ↑</li>
53+
<li>Select next task: ↓</li>
54+
</ul>
55+
<ul>
56+
Drag and drop mode here! Now you can reorder your tasks or move to another note
57+
</ul>
58+
</li>
4759
</ul>
4860
"""
4961
//https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html?search=build
5062
sinceBuild "193.2252"
51-
untilBuild "203.*"
63+
untilBuild "213.*"
5264
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip

src/main/java/org/bigtows/utils/PinNoteIcon.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,35 @@ public class PinNoteIcon {
1717
* Icon used in notification's
1818
*/
1919
public static final Icon NOTIFICATION_PIN_NOTE = PinNoteIcon.getSvgIconFromResource(
20-
"/icons/toolWindowRight_dark.svg", 1.2f
20+
"icons/toolWindowRight_dark.svg", 1.2f
2121
).orElse(AllIcons.Ide.FatalError);
2222

2323
/**
2424
* Icon for evernote in tab context
2525
*/
2626
public static final Icon TAB_EVERNOTE_ICON = PinNoteIcon.getSvgIconFromResource(
27-
"/icons/evernote.svg", 0.5f
27+
"icons/evernote.svg", 0.5f
2828
).orElse(AllIcons.Ide.FatalError);
2929

3030
/**
3131
* Icon for local storage in tab context
3232
*/
3333
public static final Icon TAB_LOCAL_NOTE_ICON = PinNoteIcon.getSvgIconFromResource(
34-
"/icons/file.svg", 0.7f
34+
"icons/file.svg", 0.7f
3535
).orElse(AllIcons.Ide.FatalError);
3636

3737
/**
3838
* Icon for evernote in settings menu
3939
*/
4040
public static final Icon SETTINGS_EVERNOTE_ICON = PinNoteIcon.getSvgIconFromResource(
41-
"/icons/evernote.svg", 1.2f
41+
"icons/evernote.svg", 1.2f
4242
).orElse(AllIcons.Ide.FatalError);
4343

4444
/**
4545
* Icon for evernote in settings menu
4646
*/
4747
public static final Icon SETTINGS_LOCAL_NOTE_ICON = PinNoteIcon.getSvgIconFromResource(
48-
"/icons/file.svg", 1.5f
48+
"icons/file.svg", 1.5f
4949
).orElse(AllIcons.Ide.FatalError);
5050

5151
/**
@@ -66,6 +66,7 @@ public static Optional<Icon> getSvgIconFromResource(String resource, float scale
6666
)
6767
);
6868
} catch (Throwable e) {
69+
e.printStackTrace();
6970
return Optional.empty();
7071
}
7172
}

src/main/java/org/bigtows/window/ui/notetree/NoteTree.java

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import com.intellij.ui.treeStructure.Tree;
44
import org.bigtows.window.ui.notetree.listener.NoteTreeChangeListener;
55
import org.bigtows.window.ui.notetree.listener.NoteTreeNeedRefreshModelListener;
6-
import org.bigtows.window.ui.notetree.tree.editor.PinNoteTreeCellEditor;
6+
import org.bigtows.window.ui.notetree.tree.PinNoteTreeCellEditor;
7+
import org.bigtows.window.ui.notetree.tree.PinNoteTreeCellRender;
78
import org.bigtows.window.ui.notetree.tree.entity.Note;
89
import org.bigtows.window.ui.notetree.tree.entity.Task;
10+
import org.bigtows.window.ui.notetree.tree.node.AbstractTaskTreeNode;
911
import org.bigtows.window.ui.notetree.tree.node.NoteTreeNode;
12+
import org.bigtows.window.ui.notetree.tree.node.SubTaskTreeNode;
1013
import org.bigtows.window.ui.notetree.tree.node.TaskTreeNode;
11-
import org.bigtows.window.ui.notetree.tree.render.PinNoteTreeCellRender;
14+
import org.bigtows.window.ui.notetree.tree.transfer.TreeTransferHandler;
1215
import org.bigtows.window.ui.notetree.utils.ExpandTreeUtils;
1316

1417
import javax.swing.*;
@@ -34,6 +37,11 @@ public NoteTree(List<MutableTreeNode> data) {
3437
tree.setCellRenderer(new PinNoteTreeCellRender(this::processChangeEvent));
3538
tree.setEditable(true);
3639
tree.setRootVisible(false);
40+
tree.setSelectionModel(new DefaultTreeSelectionModel());
41+
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
42+
tree.setDragEnabled(false);
43+
tree.setDropMode(DropMode.ON_OR_INSERT);
44+
tree.setTransferHandler(new TreeTransferHandler(this::processChangeEvent));
3745
setLayout(new BorderLayout());
3846
add(tree, BorderLayout.CENTER);
3947
}
@@ -129,6 +137,9 @@ public void addNewNote(String name) {
129137
SwingUtilities.invokeLater(() -> {
130138
ExpandTreeUtils.expandLeaf(tree, listOfLeaf);
131139
tree.updateUI();
140+
var treePath = new TreePath(((AbstractTaskTreeNode) noteTreeNode.getChildAt(0)).getPath());
141+
tree.expandPath(treePath);
142+
tree.startEditingAtPath(treePath);
132143
});
133144
}
134145

@@ -170,13 +181,86 @@ public void removeSelectedElement() {
170181
new TaskTreeNode(Task.builder().build())
171182
);
172183
}
173-
this.processChangeEvent();
174-
tree.updateUI();
175184
}
185+
if (selectedPath instanceof SubTaskTreeNode && tree.getSelectionPath() != null) {
186+
var parent = tree.getSelectionPath().getParentPath().getLastPathComponent();
187+
this.recalculateCheckStatus((TreeNode) parent);
188+
}
189+
this.processChangeEvent();
190+
tree.updateUI();
176191
}
177192

178-
public void needUpdateModel() {
193+
/**
194+
* Notify about need update model
195+
*/
196+
public void notifyUpdateModel() {
179197
this.needUpdateModelListeners.forEach(NoteTreeNeedRefreshModelListener::refresh);
180198
}
181199

200+
201+
/**
202+
* Check has focused (mean editable right now task) task.
203+
*
204+
* @return {@code true} if exists else {@code false}
205+
*/
206+
public boolean hasFocusedTask() {
207+
var path = tree.getEditingPath();
208+
return path != null && path.getLastPathComponent() instanceof AbstractTaskTreeNode;
209+
}
210+
211+
/**
212+
* Remove focused (mean editable right now task) task.
213+
*/
214+
public void removeFocusedTask() {
215+
216+
var value = ((AbstractTaskTreeNode) tree.getEditingPath().getLastPathComponent());
217+
218+
var parent = value.getParent();
219+
int indexValue = parent.getIndex(value);
220+
value.removeFromParent();
221+
if (parent instanceof NoteTreeNode && parent.getChildCount() == 0) {
222+
((NoteTreeNode) parent).add(new TaskTreeNode(Task.builder().build()));
223+
}
224+
this.recalculateCheckStatus(parent);
225+
tree.updateUI();
226+
processChangeEvent();
227+
228+
229+
//Set cursor at nearby position
230+
TreePath cursorPath;
231+
if (parent instanceof TaskTreeNode && parent.getChildCount() == 0) {
232+
cursorPath = new TreePath(((TaskTreeNode) parent).getPath());
233+
} else {
234+
cursorPath = new TreePath(((AbstractTaskTreeNode) parent.getChildAt(
235+
parent.getChildCount() - 1 < indexValue ? indexValue - 1 : indexValue
236+
)).getPath());
237+
}
238+
239+
SwingUtilities.invokeLater(() -> tree.startEditingAtPath(cursorPath));
240+
}
241+
242+
private void recalculateCheckStatus(TreeNode parent) {
243+
if (parent instanceof TaskTreeNode && parent.getChildCount() > 0) {
244+
var needCheck = true;
245+
for (int i = 0; i < parent.getChildCount(); i++) {
246+
var subTask = (SubTaskTreeNode) parent.getChildAt(i);
247+
if (!subTask.getUserObject().getChecked()) {
248+
needCheck = false;
249+
break;
250+
}
251+
}
252+
((TaskTreeNode) parent).getUserObject().setChecked(needCheck);
253+
}
254+
}
255+
256+
/**
257+
* Enable or disable drag and drop mode
258+
*
259+
* @param isEnable status of mode
260+
*/
261+
public void setDragEnable(boolean isEnable) {
262+
tree.clearSelection();
263+
tree.setEditable(!isEnable);
264+
tree.setDragEnabled(isEnable);
265+
}
182266
}

src/main/java/org/bigtows/window/ui/notetree/factory/EditorTimer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ private Thread initTimer() {
2323
while (true) {
2424
try {
2525
Thread.sleep(5000);
26-
} catch (InterruptedException e) {
26+
} catch (InterruptedException ignored) {
2727
}
2828
if (status == Status.EDITING) {
2929
status = Status.NEED_PUBLISH;
3030
} else if (status == Status.NEED_PUBLISH) {
31-
System.out.println("Publish!!");
3231
runnable.run();
3332
status = Status.END;
3433
}

0 commit comments

Comments
 (0)