Skip to content

Commit

Permalink
Rename tree views when moved to a new file
Browse files Browse the repository at this point in the history
This also fixes an old bug where if you opened a tree view in oldFile,
    then refreshed it with JSON from newFile, then tried to open a new tree view for oldFile,
    it would instead close the tree view for newFile.
  • Loading branch information
molsonkiko committed Oct 18, 2024
1 parent 1ac1e73 commit 57239da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

1. When a file is renamed, the name of a [tree view](/docs/README.md#json-tools-overview) associated with that file also changes to match the new name.
1. When a file is renamed, the name of a [tree view](/docs/README.md#json-tools-overview) associated with that file also changes to match the new name. This also happens when a treeview is refreshed with JSON from a different file.
2. Add [`rand_schema` RemesPath function](/docs/RemesPath.md#non-vectorized-functions) to generate random JSON from schema.

### Changed
Expand All @@ -78,6 +78,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
9. Fix annoying but harmless bug where, if the user had two views open and [ran a plugin command on one or more selections](/docs/README.md#working-with-selections) in the second view, the indicator that JsonTools uses to remember selections (which is supposed to be hidden at all times) would cause the selections to be underlined.
10. Address [issue 80](https://github.com/molsonkiko/JsonToolsNppPlugin/issues/80); now [error form](/docs/README.md#error-form-and-status-bar) will be cleared of errors when the JSON parser does not log any syntax errors.
11. Make it so that JSON Lines documents are correctly formatted as JSON Lines after sorting by the [sort form](/docs/README.md#sort-form).
12. Make it so that refreshing a tree view originally associated with `oldFile` with JSON from `newFile` will correctly cause the tree view to be associated with `newFile`. Previously, the tree view stayed associated with `oldFile`, so attempting to open a new tree view for `oldFile` would instead close the tree view now associated with `newFile`, because the command to open a tree view for a file closes that file's tree view if it already has an open one.

## [8.1.0] - 2024-08-23

Expand Down
22 changes: 21 additions & 1 deletion JsonToolsNppPlugin/Forms/TreeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ private void RefreshButton_Click(object sender, EventArgs e)
(_, JNode newJson, _, DocumentType _) = Main.TryParseJson(GetDocumentTypeFromComboBox());
if (newJson == null)
return;
fname = curFname;
TransferToNewFile(curFname);
json = newJson;
queryResult = json;
JsonTreePopulate(json);
Expand Down Expand Up @@ -1461,6 +1461,7 @@ private void DocumentTypeComboBox_SelectedIndexChanged(object sender, EventArgs
if (oldDocumentType == newDocumentType)
return;
(_, JNode newJson, _, _) = Main.TryParseJson(newDocumentType);
TransferToNewFile(Npp.notepad.GetCurrentFilePath());
JsonTreePopulate(newJson);
}

Expand All @@ -1477,6 +1478,25 @@ public void Rename(string newFname, bool isFilename)
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DMMUPDATEDISPINFO, 0, Handle);
}

/// <summary>
/// Rename this tree view to newFname,<br></br>
/// set the <c>tv</c> attribute of the <see cref="JsonFileInfo"/> for newFname to this,<br></br>
/// and clear the <c>tv</c> attribute for the JsonFileInfo of this tree's previous fname
/// </summary>
/// <param name="newFname"></param>
private void TransferToNewFile(string newFname)
{
string oldFname = fname;
if (oldFname != newFname && (Main.grepperForm is null || Main.grepperForm.tv is null || this != Main.grepperForm.tv))
{
Rename(newFname, true);
if (Main.TryGetInfoForFile(newFname, out JsonFileInfo info))
info.tv = this;
if (Main.TryGetInfoForFile(oldFname, out JsonFileInfo oldInfo))
oldInfo.tv = null;
}
}

/// <summary>
/// sets this.ptrTitleBuf to a pointer to an unmanaged Unicode char array containing the title of this TreeViewer's docking form.<br></br>
/// If isFilename, inserts the title (after stripping the directory name away from the beginning of title) into the normal format string for the TreeViewer title
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("8.1.0.11")]
[assembly: AssemblyFileVersion("8.1.0.11")]
[assembly: AssemblyVersion("8.1.0.12")]
[assembly: AssemblyFileVersion("8.1.0.12")]

0 comments on commit 57239da

Please sign in to comment.