Skip to content

Commit

Permalink
v3.5.0: resolve issues #10, #11, #13
Browse files Browse the repository at this point in the history
ADDED
1. `Refresh` button for resetting the form with the JSON in the currently active buffer (resolves Issue #13).
2. __Tree view enhancements__ (resolves Issue #10):
	- Clicking on a tree node to expand it also changes the displayed node path and snaps the caret.
	- `Tab` can be used to switch between controls on the tree form.
	- Drop-down menu option for expanding/collapsing all subtrees when right-clicking on a tree node.
	- Query box is auto-selected when tree is opened.
	- `Ctrl+Enter` while query box is selected submits the query.
	- `Enter` while any button selected is equivalent to clicking it.
	- `Enter` while tree is selected toggles the selected node between expanded/collapsed.
	- `Escape` key takes focus from the tree back to the text editor (resolves Issue #11).

CHANGED
1. Minimizing the tree view closes it completely.
  • Loading branch information
molsonkiko committed Sep 24, 2022
1 parent 040cb9d commit 75a9118
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 21 deletions.
15 changes: 11 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@ This project has many features that were implemented in a [standalone app](https
- The tree view doesn't automatically reset when the user does an undo or redo action. You have to close and reopen the treeview for the changes to be reflected. This is annoying, but I can't seem to get my [Main.OnNotification](/JsonToolsNppPlugin/Main.cs) method to respond to undo and redo actions.
- Improve how well the caret tracks the node selected in the query tree, after a query that selects a subset of nodes. The iterables have their line number set to 0.

## [3.5.0] (unreleased) - 2022-MM-DD
## [3.5.0] - 2022-09-24

### Added

1. `Refresh` button for resetting the form with the JSON in the currently active buffer.
2. Clicking on a tree node to expand it also changes the displayed node path and snaps the caret.
3. Drop-down menu option for expanding/collapsing all subtrees when right-clicking on a tree node.
1. `Refresh` button for resetting the form with the JSON in the currently active buffer (resolves Issue #13).
2. __Tree view enhancements__ (resolves Issue #10):
- Clicking on a tree node to expand it also changes the displayed node path and snaps the caret.
- `Tab` can be used to switch between controls on the tree form.
- Drop-down menu option for expanding/collapsing all subtrees when right-clicking on a tree node.
- Query box is auto-selected when tree is opened.
- `Ctrl+Enter` while query box is selected submits the query.
- `Enter` while any button selected is equivalent to clicking it.
- `Enter` while tree is selected toggles the selected node between expanded/collapsed.
- `Escape` key takes focus from the tree back to the text editor (resolves Issue #11).

### Changed

Expand Down
7 changes: 7 additions & 0 deletions JsonToolsNppPlugin/Forms/JsonToCsvForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions JsonToolsNppPlugin/Forms/JsonToCsvForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ public JsonToCsvForm(JNode json)
StrategyBox.SelectedIndex = 0;
}

private void JsonToCsvForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
e.Handled = true;
Close();
}
else if (e.KeyCode == Keys.Enter)
{
if (sender is Button btn)
btn.PerformClick();
e.Handled = true;
}
}

private void GenerateCSVButton_Click(object sender, EventArgs e)
{
string keysep = new string(KeySepBox.Text[0], 1);
Expand Down
36 changes: 23 additions & 13 deletions JsonToolsNppPlugin/Forms/TreeViewer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 46 additions & 1 deletion JsonToolsNppPlugin/Forms/TreeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,55 @@ public TreeViewer(JNode json)
//this.Tree.BeforeExpand += new TreeViewCancelEventHandler(
// PopulateIfUnpopulatedHandler
//);
//QueryBox.Select();
// activate the query box so user can start typing immediately
}

// largely copied from NppManagedPluginDemo.cs in the original plugin pack
private void TreeViewer_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
// Ctrl+Enter in query box -> submit query
if (e.Control && QueryBox.Focused)
SubmitQueryButton.PerformClick();
else if (sender is Button btn)
{
// Enter has the same effect as clicking a selected button
btn.PerformClick();
}
else if (sender is TreeView)
{
// Enter in the TreeView toggles the selected node
TreeNode selected = Tree.SelectedNode;
if (selected == null || selected.Nodes.Count == 0)
return;
if (selected.IsExpanded)
selected.Collapse(true); // don't collapse the children as well
else selected.Expand();
}
}
// Escape -> go to editor
else if (e.KeyData == Keys.Escape)
{
Npp.editor.GrabFocus();
}
// Tab -> go through controls, Shift+Tab -> go through controls backward
else if (e.KeyCode == Keys.Tab)
{
Control next = GetNextControl((Control)sender, !e.Shift);
while ((next == null) || (!next.TabStop)) next = GetNextControl(next, !e.Shift);
next.Focus();
e.Handled = true;
}
}

private void QueryBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\t')
e.Handled = true;
}

public static void SetImageOfTreeNode(TreeNode root, JNode json)
{
switch (json.type)
Expand Down
2 changes: 1 addition & 1 deletion JsonToolsNppPlugin/Forms/TreeViewer.resx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADC
CgAAAk1TRnQBSQFMAgEBCAEAAagBAAGoAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CgAAAk1TRnQBSQFMAgEBCAEAAegBAAHoAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAATADAAEBAQABCAYAAQwYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down
7 changes: 5 additions & 2 deletions JsonToolsNppPlugin/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ public static void ShowTreeView(TreeViewer tree)
/// </summary>
static void OpenJsonTree(bool is_json_lines = false)
{
string cur_fname = Npp.notepad.GetCurrentFilePath();
//TreeViewer tv = null;
//if (IsWin32)
// treeViewers.TryGetValue(cur_fname, out tv);
Expand All @@ -414,6 +413,7 @@ static void OpenJsonTree(bool is_json_lines = false)
// if the tree view is open, hide the tree view and then dispose of it
HideTreeView(treeViewer);
treeViewer.Close();
treeViewer = null;
//if (IsWin32)
// treeViewers.Remove(cur_fname);
//else treeViewer = null;
Expand Down Expand Up @@ -459,7 +459,10 @@ static void OpenJsonTree(bool is_json_lines = false)
treeViewer.JsonTreePopulate(json);
//if (IsWin32)
// treeViewers[cur_fname] = tv;
treeViewer.Focus();
treeViewer.QueryBox.Focus();
// select QueryBox on startup
// note that this is only possible because we changed the access modifier
// of that control from private (the default) to internal.
}
#endregion
}
Expand Down
Binary file modified JsonToolsNppPlugin/Release_x64.zip
Binary file not shown.
Binary file modified JsonToolsNppPlugin/Release_x86.zip
Binary file not shown.
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ You can click on the nodes in that tree to see the children. When you select a n
__NOTES__
1. If you submit a RemesPath query that is anything other than the default `@`, the JSON tree may no longer send the caret to the correct line.
2. If you [edit your JSON](/docs/RemesPath.md#editing-with-assignment-expressions) with RemesPath queries and then undo your change with `Ctrl+Z` or similar, that will not undo the changes to the JSON. To re-sync the JSON with the document, you will have to close and then re-open the tree view.
3. Keyboard shortcuts:
- `Ctrl+Enter` in the query box submits the query.
- `Enter` while the tree is selected toggles the selected node between expanded/collapsed.
- Up and down arrow keys can also navigate the tree.
- `Escape` takes focus from the tree view back to the editor.

If a node has a `+` or `-` sign next to it, you can click on that button to expand the children of the node, as shown here.

Expand Down

0 comments on commit 75a9118

Please sign in to comment.