Skip to content

Commit

Permalink
v3.4.0: node/line path getters, gui enhancements
Browse files Browse the repository at this point in the history
ADDED
1. Menu command for getting path to first node in current line.
2. Right-clicking on tree nodes lets you get the current node's
    value, key/index in parent iterable, or path.
3. key_style option in settings for customizing how the path is
    formatted (e.g., dot syntax for JavaScript vs.
    obligatory square brackets and quotes for Python)
4. Automatic resizing of the query box and the tree view when
    the docking box is resized.
5. A text box containing the path to the currently selected
    tree node (in the default key style) and a button for
    copying it to the clipboard.

CHANGED
1. Settings now persist between sessions.
    They are saved to an ini file in the Notepad++ config directory.
  • Loading branch information
molsonkiko committed Sep 22, 2022
1 parent bb18ee6 commit 02e9abe
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 224 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@ This project has many features that were implemented in a [standalone app](https
- fails when key contains singlequotes and doublequotes
- Fix bug with the range() function where if the first or second argument is a uminus'd function of the CurJson there's an error because the uminus somehow maybe turned the int into a float(???). Error is raised on line 1706 of RemesPath.cs. E.g., `range(-len(@))` and `range(0, -len(@))`) will throw errors.
- Sometimes recursive queries may cause an infinite loop, or something else that leads to Notepad++ crashing. Recursive queries are almost always fine, and I only saw this bug once. Not sure why yet.
- 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.

## [3.4.0] (unreleased) - 2022-MM-DD
## [3.4.0] - 2022-09-22

### Added

1. [Menu command](/docs/README.md#path-to-current-line) for getting path to first node in current line.
2. Right-clicking on tree nodes lets you get the current node's value, key/index in parent iterable, or path.
3. `key_style` option in settings for customizing how the path is formatted (e.g., dot syntax for JavaScript vs. obligatory square brackets and quotes for Python)
3. [key_style](/docs/README.md#key-style) option in settings for customizing how the path is formatted (e.g., dot syntax for JavaScript vs. obligatory square brackets and quotes for Python)
4. Automatic resizing of the query box and the tree view when the docking box is resized.
5. A text box containing the path to the currently selected tree node (in the default key style) and a [button for copying it to the clipboard](/docs/README.md#get-info-about-tree-nodes).

### Changed

1. Settings now persist between sessions. They are saved to an ini file in the Notepad++ config directory.

## [3.3.0] - 2022-09-21

Expand Down
40 changes: 38 additions & 2 deletions JsonToolsNppPlugin/Forms/TreeViewer.Designer.cs

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

11 changes: 11 additions & 0 deletions JsonToolsNppPlugin/Forms/TreeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ private void Tree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
TreeNode node = e.Node;
string path = node.FullPath;
Npp.editor.GotoLine(pathsToJNodes[path].line_num);
CurrentPathBox.Text = PathToTreeNode(node, Main.settings.key_style);
// might also want to make it so that the selected line is scrolled to the top
if (e.Button == MouseButtons.Right)
{
Expand Down Expand Up @@ -628,6 +629,16 @@ public string KeyOfTreeNode(TreeNode node, KeyStyle style)
return JNode.FormatKey(node.Name, style);
}

private void CurrentPathButton_Click(object sender, EventArgs e)
{
Npp.TryCopyToClipboard(CurrentPathBox.Text);
CurrentPathButton.Text = "Copied!";
CurrentPathButton.Update();
System.Threading.Thread.Sleep(200);
CurrentPathButton.Text = "Current path";
CurrentPathButton.Update();
}

// not creating schemas at present because schemas produced may be invalid
//private void SchemaButton_Click(object sender, EventArgs e)
//{
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
CgAAAk1TRnQBSQFMAgEBCAEAAUgBAAFIAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CgAAAk1TRnQBSQFMAgEBCAEAAVgBAAFYAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAATADAAEBAQABCAYAAQwYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down
1 change: 1 addition & 0 deletions JsonToolsNppPlugin/JsonToolsNppPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Compile Include="PluginInfrastructure\Preference_h.cs" />
<Compile Include="PluginInfrastructure\ScintillaGateway.cs" />
<Compile Include="PluginInfrastructure\Scintilla_iface.cs" />
<Compile Include="PluginInfrastructure\SettingsBase.cs" />
<Compile Include="PluginInfrastructure\UnmanagedExports.cs" />
<Compile Include="PluginInfrastructure\Win32.cs" />
<Compile Include="PluginInfrastructure\resource_h.cs" />
Expand Down
54 changes: 19 additions & 35 deletions JsonToolsNppPlugin/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ class Main
{
#region " Fields "
internal const string PluginName = "JsonTools";
static string iniFilePath = null;
static string sectionName = "Format JSON";
static string keyName = "LoadJson";
static bool shouldLoadJson = false;
//static string sessionFilePath = @"C:\text.session";
// json tools related things
public static Settings settings = new Settings();
public static JsonParser jsonParser = new JsonParser(settings.allow_datetimes,
Expand Down Expand Up @@ -60,28 +55,6 @@ class Main
static internal void CommandMenuInit()
{
// Initialization of your plugin commands
// You should fill your plugins commands here

//
// Firstly we get the parameters from your plugin config file (if any)
//

// get path of plugin configuration
StringBuilder sbIniFilePath = new StringBuilder(Win32.MAX_PATH);
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, sbIniFilePath);
iniFilePath = sbIniFilePath.ToString();

// if config path doesn't exist, we create it
if (!Directory.Exists(iniFilePath))
{
Directory.CreateDirectory(iniFilePath);
}

// make your plugin config file full file path name
iniFilePath = Path.Combine(iniFilePath, PluginName + ".ini");

// get the parameter value from plugin config
//shouldLoadJson = Win32.GetPrivateProfileInt(sectionName, keyName, 0, iniFilePath) != 0;

// with function :
// SetCommand(int index, // zero based number to indicate the order of command
Expand Down Expand Up @@ -146,13 +119,28 @@ public static void OnNotification(ScNotification notification)
//{
// Main.LoadJson();
//}

//// when closing a file
// when closing a file
if (code == (uint)NppMsg.NPPN_FILEBEFORECLOSE)
{
fname_jsons.Remove(Npp.GetCurrentPath());
return;
}

// after an undo (Ctrl + Z) or redo (Ctrl + Y) action
//if (code == (uint)SciMsg.SCI_UNDO
// || code == (uint)SciMsg.SCI_REDO)
//{
// string fname = Npp.GetCurrentPath();
// if (!fname_jsons.ContainsKey(fname))
// return; // ignore files with no JSON yet
// // reparse the file
// string ext = Npp.FileExtension(fname);
// JNode json = TryParseJson(ext == "jsonl");
// treeViewer.json = json;
// // if the tree view is open, refresh it
// if (treeViewer != null)
// treeViewer.JsonTreePopulate(json);
// return;
//}
//if (code > int.MaxValue) // windows messages
//{
// int wm = -(int)code;
Expand All @@ -170,7 +158,6 @@ public static void OnNotification(ScNotification notification)

static internal void PluginCleanUp()
{
Win32.WritePrivateProfileString(sectionName, keyName, shouldLoadJson ? "1" : "0", iniFilePath);
if (treeViewer != null)
treeViewer.Close();
}
Expand Down Expand Up @@ -333,10 +320,7 @@ static void OpenSettings()
jsonParser.allow_datetimes = settings.allow_datetimes;
jsonParser.allow_javascript_comments = settings.allow_javascript_comments;
jsonParser.allow_singlequoted_str = settings.allow_singlequoted_str;
if (settings.linting)
{
jsonParser.lint = new List<JsonLint>();
}
jsonParser.lint = settings.linting ? new List<JsonLint>() : null;
}

private static void PathToCurrentLine()
Expand Down
Loading

0 comments on commit 02e9abe

Please sign in to comment.