Skip to content

Commit

Permalink
Improve translation code, translation files
Browse files Browse the repository at this point in the history
Also rename `Choose schemas to automatically validate filename patterns` to `Validate files with JSON schema if name matches pattern`
    because it had become clear that people systematically misunderstood
    what that command was supposed to do.
  • Loading branch information
molsonkiko committed Jul 4, 2024
1 parent 56f453b commit 3a9be8a
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 62 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2. In the `grepper form`, pressing `Enter` inside the `Previously viewed directories...` box causes the current text of the box to be searched, assuming that it is a valid directory.
3. [Translation](/README.md#translating-jsontools-to-another-language) of settings in the [Settings form](/docs/README.md#customizing-settings).

### Changed

1. Rename `Choose schemas to automatically validate filename patterns` to [`Validate files with JSON schema if name matches pattern`](/docs/README.md#automatic-validation-of-json-against-json-schema), in the hopes that the new name will be less confusing.

### Fixed

1. If there would be an `OutOfMemoryException` due to running out of memory while formatting JSON (a likely occurrence when using the `grepper form`), that error is caught and reported with a message box, rather than potentially causing Notepad++ to crash.
Expand Down
2 changes: 1 addition & 1 deletion JsonToolsNppPlugin/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static internal void CommandMenuInit()
PluginBase.SetCommand(10, Translator.GetTranslatedMenuItem("&Settings"), OpenSettings, new ShortcutKey(true, true, true, Keys.S));
PluginBase.SetCommand(11, "---", null);
PluginBase.SetCommand(12, Translator.GetTranslatedMenuItem("&Validate JSON against JSON schema"), () => ValidateJson());
PluginBase.SetCommand(13, Translator.GetTranslatedMenuItem("Choose schemas to automatically validate &filename patterns"), MapSchemasToFnamePatterns);
PluginBase.SetCommand(13, Translator.GetTranslatedMenuItem("Validate &files with JSON schema if name matches pattern"), MapSchemasToFnamePatterns);
PluginBase.SetCommand(14, Translator.GetTranslatedMenuItem("Generate sc&hema from JSON"), GenerateJsonSchema);
PluginBase.SetCommand(15, Translator.GetTranslatedMenuItem("Generate &random JSON from schema"), GenerateRandomJson);
PluginBase.SetCommand(16, "---", null);
Expand Down
18 changes: 15 additions & 3 deletions JsonToolsNppPlugin/PluginInfrastructure/SettingsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public void ShowDialog(bool debug = false)

var dialog = new Form
{
Name = "SettingsForm",
Text = "Settings - JsonTools plug-in",
ClientSize = new Size(DEFAULT_WIDTH, DEFAULT_HEIGHT),
MinimumSize = new Size(250, 250),
Expand All @@ -232,7 +233,7 @@ public void ShowDialog(bool debug = false)
Text = "&Cancel",
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
Size = new Size(75, 23),
Location = new Point(DEFAULT_WIDTH - 115, DEFAULT_HEIGHT - 36),
Location = new Point(DEFAULT_WIDTH - 135, DEFAULT_HEIGHT - 36),
UseVisualStyleBackColor = true
},
new Button
Expand All @@ -241,7 +242,7 @@ public void ShowDialog(bool debug = false)
Text = "&Reset",
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
Size = new Size(75, 23),
Location = new Point(DEFAULT_WIDTH - 212, DEFAULT_HEIGHT - 36),
Location = new Point(DEFAULT_WIDTH - 232, DEFAULT_HEIGHT - 36),
UseVisualStyleBackColor = true
},
new Button
Expand All @@ -250,7 +251,7 @@ public void ShowDialog(bool debug = false)
Text = "&Ok",
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
Size = new Size(75, 23),
Location = new Point(DEFAULT_WIDTH - 310, DEFAULT_HEIGHT - 36),
Location = new Point(DEFAULT_WIDTH - 330, DEFAULT_HEIGHT - 36),
UseVisualStyleBackColor = true
},
new PropertyGrid
Expand All @@ -265,6 +266,7 @@ public void ShowDialog(bool debug = false)
},
}
};
Translator.TranslateForm(dialog);

dialog.Controls["Cancel"].Click += (a, b) => dialog.Close();
dialog.Controls["Ok"].Click += (a, b) =>
Expand Down Expand Up @@ -296,6 +298,16 @@ public void ShowDialog(bool debug = false)
SaveToIniFile();
dialog.Close();
};
// close dialog on pressing Escape (this doesn't work if a grid cell is selected, but it does work if a button is selected)
KeyEventHandler keyDownHandler = (a, b) =>
{
if (b.KeyCode == Keys.Escape)
dialog.Close();
};
dialog.KeyDown += keyDownHandler;
foreach (Control ctrl in dialog.Controls)
ctrl.KeyDown += keyDownHandler;
// translate the descriptions of the settings
var grid = dialog.Controls["Grid"];
if (Translator.HasTranslations
&& grid.Controls.Count >= 1 && grid.Controls[0] is Control commentPane
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.0.0.3")]
[assembly: AssemblyFileVersion("8.0.0.3")]
[assembly: AssemblyVersion("8.0.0.4")]
[assembly: AssemblyFileVersion("8.0.0.4")]
15 changes: 6 additions & 9 deletions JsonToolsNppPlugin/Utils/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,18 @@ private static void TranslateControl(Control ctrl, Dictionary<string, JNode> con
}
int maxRight = 0;
foreach (Control child in ctrl.Controls)
{
maxRight = child.Right > maxRight ? child.Right : maxRight;
// unanchor everything from the right, so resizing the form doesn't move those controls
child.Anchor &= (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left);
}
// Temporarily turn off the normal layout logic,
// because this would cause controls to move right when the form is resized
// (yes, even if they're not anchored right. No, that doesn't make sense)
ctrl.SuspendLayout();
if (maxRight > ctrl.Width)
{
int padding = ctrl is Form ? 25 : 5;
ctrl.Width = maxRight + padding;
}
foreach ((Control child, _, bool wasAnchoredRight) in childrenByLeft)
{
if (wasAnchoredRight)
child.Anchor |= AnchorStyles.Right;
}
// Resume layout logic, ignoring the pending requests to move controls right due to resizing of form
ctrl.ResumeLayout(false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ This JSON schema generator only produces schemas with the following keywords:

As of version [4.11.0](/CHANGELOG.md#4110---2023-03-15), you can set up this plugin to *automatically validate* JSON files with certain filenames whenever you open them. (*starting in version [4.11.2](/CHANGELOG.md#4112---2023-03-21), auto-validation also occurs when files are saved or renamed*)

Let's try out this feature! We can use the plugin command `Choose schemas to automatically validate filename patterns`, which will open up a file that looks like this.
Let's try out this feature! We can use the plugin command `Choose schemas to automatically validate filename patterns` (renamed in [v8.1](/CHANGELOG.md#810---unreleased-yyyy-mm-dd) to `Validate files with JSON schema if name matches pattern`), which will open up a file that looks like this.

![schemas to filename patterns file new](/docs/schemasToFnamePatterns%20with%20no%20fname%20patterns.PNG)

Expand Down
Loading

0 comments on commit 3a9be8a

Please sign in to comment.