diff --git a/docs/changelog.txt b/docs/changelog.txt index 7b86f40..961e495 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,5 +1,7 @@ - Array brackets can now be omitted when there is only one element. - GUI elements can now be defined in root object. +- GUI labels became optional. +- "window_name" can now be default values of GUI labels. ver 0.7.2 - Added "optional" to ignore some options when a text box is empty. diff --git a/examples/all_keys/gui_definition.json b/examples/all_keys/gui_definition.json index adf1507..3869fe6 100644 --- a/examples/all_keys/gui_definition.json +++ b/examples/all_keys/gui_definition.json @@ -3,7 +3,7 @@ "minimum_required": "0.7.1", "gui": [ { - "label": "Components Minimal", + "window_name": "Components Minimal", "command": "echo file: %-% & echo folder: %-% & echo combo: %-% & echo radio: %-% & echo check: %-% & echo check_array: %-% & echo textbox: %-% & echo int: %-% & echo float: %-%", "components": [ { @@ -82,7 +82,7 @@ ] }, { - "label": "Components Optional", + "window_name": "Components Optional", "command": "echo file: %file% & echo folder: %folder% & echo combo: %combo% & echo radio: %radio% & echo check: %check% & echo check_array: %options% & echo textbox: %text% & echo int: %integer% & echo float: %double%", "components": [ { @@ -248,8 +248,8 @@ ] }, { - "label": "GUI Optional", - "window_name": "Window Title Here", + "window_name": "GUI Optional", + "label": "GUI Optional (this string is for a menu item)", "command_win": "echo home: %__HOME__% & echo cwd: %__CWD__% & echo percent: %% & echo sample message!", "command_linux": "echo home: %__HOME__%; echo cwd: %__CWD__%; echo percent: %%; echo sample message!", "command_mac": "echo home: %__HOME__%; echo cwd: %__CWD__%; echo percent: %%; echo sample message!", diff --git a/examples/comp_options/affix/README.md b/examples/comp_options/affix/README.md index 2d9151f..7fab4e3 100644 --- a/examples/comp_options/affix/README.md +++ b/examples/comp_options/affix/README.md @@ -7,7 +7,6 @@ ```json { "gui": { - "label": "Affix example", "command": "echo %-%", "components": [ { diff --git a/examples/comp_options/affix/gui_definition.json b/examples/comp_options/affix/gui_definition.json index a9131a0..10dd064 100644 --- a/examples/comp_options/affix/gui_definition.json +++ b/examples/comp_options/affix/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Affix example", "command": "echo %-%", "components": [ { diff --git a/examples/comp_options/button/README.md b/examples/comp_options/button/README.md index 2356728..3798c51 100644 --- a/examples/comp_options/button/README.md +++ b/examples/comp_options/button/README.md @@ -8,7 +8,6 @@ It allows you to rename the button associated with the picker component. ```json { "gui": { - "label": "Button", "window_name": "Button sample", "command": "echo %-% %-%", "components": [ diff --git a/examples/comp_options/button/gui_definition.json b/examples/comp_options/button/gui_definition.json index ba271a7..844f5df 100644 --- a/examples/comp_options/button/gui_definition.json +++ b/examples/comp_options/button/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Button", "window_name": "Button sample", "command": "echo %-% %-%", "components": [ diff --git a/examples/comp_options/default/gui_definition.json b/examples/comp_options/default/gui_definition.json index 3f43623..8641f3a 100644 --- a/examples/comp_options/default/gui_definition.json +++ b/examples/comp_options/default/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Sample GUI", "command": "echo file: %-% & echo options: %-%", "components": [ { diff --git a/examples/comp_options/id/README.md b/examples/comp_options/id/README.md index 673e6cf..57155d5 100644 --- a/examples/comp_options/id/README.md +++ b/examples/comp_options/id/README.md @@ -5,7 +5,6 @@ You can use the defined ids as variable names in commands. ```json { - "label": "IDs", "command": "echo x: %x% & echo y: %y% & echo x: %x%", "button": "Echo!", "components": [ @@ -29,7 +28,6 @@ When you put an undefined id in `%*%`, it'll use one of the components that have ```json { - "label": "Undefined IDs", "command": "echo x: %-% & echo y: %y% & echo z: %foo%", "button": "Echo!", "components": [ @@ -61,7 +59,6 @@ There are some predefined ids. ```json { - "label": "Reserved IDs", "command": "echo percent: %% & echo cwd: %__CWD__% & echo home: %__HOME__%", "button": "Echo!", "components": [] diff --git a/examples/comp_options/optional/README.md b/examples/comp_options/optional/README.md index ee0f519..799fad4 100644 --- a/examples/comp_options/optional/README.md +++ b/examples/comp_options/optional/README.md @@ -7,7 +7,6 @@ ```json { "gui": { - "label": "Optional component", "command": "echo %-%", "components": [ { diff --git a/examples/comp_options/optional/gui_definition.json b/examples/comp_options/optional/gui_definition.json index ad7e6ba..43328e4 100644 --- a/examples/comp_options/optional/gui_definition.json +++ b/examples/comp_options/optional/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Optional component", "command": "echo %-%", "components": [ { diff --git a/examples/comp_options/placeholder/README.md b/examples/comp_options/placeholder/README.md index 1af33a9..b00c23b 100644 --- a/examples/comp_options/placeholder/README.md +++ b/examples/comp_options/placeholder/README.md @@ -8,7 +8,6 @@ It displays a message when the text box is empty. ```json { "gui": { - "label": "Placeholder", "window_name": "Placeholder sample", "command": "echo %-% %-% %-%", "components": [ diff --git a/examples/comp_options/placeholder/gui_definition.json b/examples/comp_options/placeholder/gui_definition.json index 79f50e0..c76ec8d 100644 --- a/examples/comp_options/placeholder/gui_definition.json +++ b/examples/comp_options/placeholder/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Placeholder", "window_name": "Placeholder sample", "command": "echo %-% %-% %-%", "components": [ diff --git a/examples/comp_options/tooltip/gui_definition.json b/examples/comp_options/tooltip/gui_definition.json index 8309231..2543957 100644 --- a/examples/comp_options/tooltip/gui_definition.json +++ b/examples/comp_options/tooltip/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Sample GUI", "command": "echo file: %-% & echo folder: %-% & echo options: %-%", "components": [ { diff --git a/examples/components/check_boxes/gui_definition.json b/examples/components/check_boxes/gui_definition.json index 6bb59c0..960ffe6 100644 --- a/examples/components/check_boxes/gui_definition.json +++ b/examples/components/check_boxes/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Check Boxes", "command": "echo checkbox: %-% & echo options:%-%", "button": "Echo!", "components": [ diff --git a/examples/components/choices/gui_definition.json b/examples/components/choices/gui_definition.json index 6c8e958..adad90d 100644 --- a/examples/components/choices/gui_definition.json +++ b/examples/components/choices/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Component Sample", "command": "echo combo: %a% & echo radio: %b%", "button": "Echo!", "components": [ diff --git a/examples/components/num_pickers/gui_definition.json b/examples/components/num_pickers/gui_definition.json index b337ed2..9e397ff 100644 --- a/examples/components/num_pickers/gui_definition.json +++ b/examples/components/num_pickers/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Select numbers", "window_name": "Picker sample", "command": "echo int: %-% & echo float: %-%", "components": [ diff --git a/examples/components/other_components/gui_definition.json b/examples/components/other_components/gui_definition.json index 935c000..93592b7 100644 --- a/examples/components/other_components/gui_definition.json +++ b/examples/components/other_components/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Component Sample", "command": "echo textbox: %c%", "button": "Echo!", "components": [ diff --git a/examples/components/path_pickers/README.md b/examples/components/path_pickers/README.md index abf942b..7c66e2d 100644 --- a/examples/components/path_pickers/README.md +++ b/examples/components/path_pickers/README.md @@ -8,7 +8,6 @@ Of course, you can drop files on the pickers to specify the paths. ```json { "gui": { - "label": "Copy file", "window_name": "Picker sample", "command": "copy %foo% %bar%", "button": "copy", diff --git a/examples/components/path_pickers/gui_definition.json b/examples/components/path_pickers/gui_definition.json index 98942cd..1da2151 100644 --- a/examples/components/path_pickers/gui_definition.json +++ b/examples/components/path_pickers/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Copy file", "window_name": "Picker sample", "command": "copy %foo% %bar%", "button": "copy", diff --git a/examples/get_start/minimal/README.md b/examples/get_start/minimal/README.md index dea360f..3cdc852 100644 --- a/examples/get_start/minimal/README.md +++ b/examples/get_start/minimal/README.md @@ -10,7 +10,6 @@ It has only a button to echo `Hello!`. ```json { "gui": { - "label": "Minimal Sample", "command": "echo Hello!", "components": [] } @@ -19,6 +18,5 @@ It has only a button to echo `Hello!`. You can write a definition of your GUI in `"gui": {}`. -- `label` is the label for your definition. You can type anything you like here. - `command` is the command you want to execute when clicking the execution button. - `components` is an array of GUI components (e.g., file pickers). `[]` means no components. diff --git a/examples/get_start/minimal/gui_definition.json b/examples/get_start/minimal/gui_definition.json index 0be9217..3839166 100644 --- a/examples/get_start/minimal/gui_definition.json +++ b/examples/get_start/minimal/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Minimal Sample", "command": "echo Hello!", "components": [] } diff --git a/examples/get_start/put_component/README.md b/examples/get_start/put_component/README.md index 8f3a834..a7a52a1 100644 --- a/examples/get_start/put_component/README.md +++ b/examples/get_start/put_component/README.md @@ -7,7 +7,6 @@ You can put a text box in the GUI. ```json { "gui": { - "label": "Text Box Sample", "window_name": "Title here!", "command": "echo %-%", "button": "Hello!", diff --git a/examples/get_start/put_component/gui_definition.json b/examples/get_start/put_component/gui_definition.json index 9dce159..05a5478 100644 --- a/examples/get_start/put_component/gui_definition.json +++ b/examples/get_start/put_component/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Minimal Sample", "window_name": "Title here!", "command": "echo %-%", "button": "Hello!", diff --git a/examples/get_start/title_button/README.md b/examples/get_start/title_button/README.md index 7f2f94c..253a1a8 100644 --- a/examples/get_start/title_button/README.md +++ b/examples/get_start/title_button/README.md @@ -7,7 +7,6 @@ You can rename the window title and the execution button. ```json { "gui": { - "label": "Minimal Sample", "window_name": "Title here!", "command": "echo Hello!", "button": "Hello!", diff --git a/examples/get_start/title_button/gui_definition.json b/examples/get_start/title_button/gui_definition.json index c3fd011..3adb137 100644 --- a/examples/get_start/title_button/gui_definition.json +++ b/examples/get_start/title_button/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Minimal Sample", "window_name": "Title here!", "command": "echo Hello!", "button": "Hello!", diff --git a/examples/other_features/alternate_spellings/gui_definition.json b/examples/other_features/alternate_spellings/gui_definition.json index fc76d39..360bbdb 100644 --- a/examples/other_features/alternate_spellings/gui_definition.json +++ b/examples/other_features/alternate_spellings/gui_definition.json @@ -1,6 +1,5 @@ { "gui": { - "label": "Alternate Spellings", "command": "echo folder: %-% & echo combo: %-% & echo check_array: %-% & echo textbox: %-% & echo int: %-%", "title": "Alternate Spellings Sample", "component_array": [ diff --git a/examples/other_features/codepage/README.md b/examples/other_features/codepage/README.md index 5f4c640..75752d6 100644 --- a/examples/other_features/codepage/README.md +++ b/examples/other_features/codepage/README.md @@ -5,7 +5,7 @@ Tuw expects user's default locale for stdout on Windows. If you want to use UTF- ```json { "gui": { - "label": "Use UTF-8 outputs on Windows", + "window_name": "Use UTF-8 outputs on Windows", "command": "powershell -ExecutionPolicy Bypass -File \"utf.ps1\"", "codepage": "utf8", "components": [] diff --git a/examples/other_features/codepage/gui_definition.json b/examples/other_features/codepage/gui_definition.json index e39ca60..aa7e991 100644 --- a/examples/other_features/codepage/gui_definition.json +++ b/examples/other_features/codepage/gui_definition.json @@ -1,6 +1,6 @@ { "gui": { - "label": "Use UTF-8 outputs on Windows", + "window_name": "Use UTF-8 outputs on Windows", "command": "powershell -ExecutionPolicy Bypass -File \"utf.ps1\"", "codepage": "utf8", "components": [] diff --git a/examples/other_features/cross_platform/README.md b/examples/other_features/cross_platform/README.md index 2161819..03535c3 100644 --- a/examples/other_features/cross_platform/README.md +++ b/examples/other_features/cross_platform/README.md @@ -14,7 +14,6 @@ Tuw will use the platform-specific command instead of the default `command` valu ```json { - "label": "Platform Specific Commands", "command_win": "echo Windows!", "command_mac": "echo macOS!", "command_linux": "echo Linux!", @@ -35,7 +34,6 @@ Tuw will ignore the component if the current OS does not match the specified pla ```json { - "label": "Platform Specific Components", "command": "echo %os%", "show_last_line": true, "components": [ diff --git a/examples/other_features/error/README.md b/examples/other_features/error/README.md index 69a67ac..1dee348 100644 --- a/examples/other_features/error/README.md +++ b/examples/other_features/error/README.md @@ -8,13 +8,8 @@ When the executed command outputs something to `stderr`, Tuw will display an err ```json { - "gui": [ - { - "label": "Error Sample", - "command": "notcommand", - "components": [] - } - ] + "command": "notcommand", + "components": [] } ``` @@ -26,7 +21,6 @@ You can also customize the success code using the `exit_success` option. ```json { - "label": "check_exit_code Sample", "command": "echo exit code is zero.", "check_exit_code": true, "exit_success": 10, @@ -44,7 +38,6 @@ When `check_exit_code` is enabled, it can also show the last line in the error d ```json { - "label": "show_last_line Sample", "command": "echo Fake Error!", "show_last_line": true, "components": [] diff --git a/examples/other_features/help/gui_definition.json b/examples/other_features/help/gui_definition.json index fba10bc..a048db4 100644 --- a/examples/other_features/help/gui_definition.json +++ b/examples/other_features/help/gui_definition.json @@ -1,6 +1,6 @@ { "gui": { - "label": "Sample GUI", + "window_name": "Sample GUI", "command": "echo file: %-% & echo folder: %-% & echo checkbox: %-%", "components": [ { diff --git a/examples/other_features/multiple/README.md b/examples/other_features/multiple/README.md index 858f28a..6d16492 100644 --- a/examples/other_features/multiple/README.md +++ b/examples/other_features/multiple/README.md @@ -1,6 +1,37 @@ # Multiple Definitions `"gui"` can be an array of gui definitions. -Users can select one of the definitions from the `Menu` in the executable. +Users can select one of these definitions from the `Menu` in the executable. +You can also use `"label"` to modify strings that are displayed in the menu bar. +When `"label"` is not defined, `"window_name"` will be used as the GUI label. ![advanced](https://github.com/matyalatte/tuw/assets/69258547/956be42e-6931-4b71-ae3c-180103a93714) + +```json +{ + "gui": [ + { + "label": "Sample GUI", + "command": "echo file: %-%", + "button": "Echo!", + "components": [ + { + "type": "file", + "label": "Some file path" + } + ] + }, + { + "window_name": "Sample GUI2", + "command": "echo text_box: %-%", + "button": "Echo!", + "components": [ + { + "type": "text", + "label": "Some text" + } + ] + } + ] +} +``` diff --git a/examples/other_features/multiple/gui_definition.json b/examples/other_features/multiple/gui_definition.json index 89b12f8..a394a77 100644 --- a/examples/other_features/multiple/gui_definition.json +++ b/examples/other_features/multiple/gui_definition.json @@ -2,64 +2,23 @@ "gui": [ { "label": "Sample GUI", - "command": "echo file: %-% & echo folder: %-% & echo checkbox: %-%", + "command": "echo file: %-%", "button": "Echo!", "components": [ - { - "type": "static_text", - "label": "This is a sample GUI. Edit 'gui_definition.json' for your scripts." - }, { "type": "file", - "label": "Some file path", - "extension": "any files (*)|*", - "placeholder": "Drop a file here!" - }, - { - "type": "folder", - "label": "Some folder path" - }, - { - "type": "check", - "label": "checkbox", - "value": "true", - "default": true + "label": "Some file path" } ] }, { - "label": "Sample GUI2", - "command": "echo text_box: %-% & echo options:%-%", + "window_name": "Sample GUI2", + "command": "echo text_box: %-%", "button": "Echo!", "components": [ - { - "type": "static_text", - "label": "This is a sample GUI. Edit 'gui_definition.json' for your scripts." - }, { "type": "text", "label": "Some text" - }, - { - "type": "check_array", - "label": "options", - "items": [ - { - "label": "option1", - "value": "--opt1", - "default": true - }, - { - "label": "option2", - "value": "--opt2", - "default": false - }, - { - "label": "option3", - "value": "--opt3", - "default": false - } - ] } ] } diff --git a/examples/other_features/skip_dialog/README.md b/examples/other_features/skip_dialog/README.md index 6836bac..09f06f4 100644 --- a/examples/other_features/skip_dialog/README.md +++ b/examples/other_features/skip_dialog/README.md @@ -5,7 +5,7 @@ Tuw will refrain from showing the dialog regardless of how many times you push t ```json "gui": { - "label": "Skip dialog", + "window_name": "Skip dialog", "command": "echo No dialogues...", "show_success_dialog": false, "components": [] diff --git a/examples/other_features/skip_dialog/gui_definition.json b/examples/other_features/skip_dialog/gui_definition.json index 4e618c3..c5bc311 100644 --- a/examples/other_features/skip_dialog/gui_definition.json +++ b/examples/other_features/skip_dialog/gui_definition.json @@ -1,6 +1,6 @@ { "gui": { - "label": "Skip dialog", + "window_name": "Skip dialog", "command": "echo No dialogues...", "show_success_dialog": false, "components": [] diff --git a/examples/other_features/version_check/README.md b/examples/other_features/version_check/README.md index 06732b9..6a22320 100644 --- a/examples/other_features/version_check/README.md +++ b/examples/other_features/version_check/README.md @@ -14,7 +14,7 @@ There are two options for checking the tool version. "recommended": "2.1.0", "minimum_required": "2.0.0", "gui": { - "label": "You can't see this GUI.", + "window_name": "You can't see this GUI.", "command": "echo Hello!", "components": [] } diff --git a/examples/other_features/version_check/gui_definition.json b/examples/other_features/version_check/gui_definition.json index 04d452d..9881d08 100644 --- a/examples/other_features/version_check/gui_definition.json +++ b/examples/other_features/version_check/gui_definition.json @@ -2,7 +2,7 @@ "recommended": "2.1.0", "minimum_required": "2.0.0", "gui": { - "label": "You can't see this GUI.", + "window_name": "You can't see this GUI.", "command": "echo Hello!", "components": [] } diff --git a/examples/tips/comments/README.md b/examples/tips/comments/README.md index 8c1253c..5712554 100644 --- a/examples/tips/comments/README.md +++ b/examples/tips/comments/README.md @@ -9,7 +9,7 @@ Tuw supports the [JSON with Comments](https://code.visualstudio.com/docs/languag * Multi-line comment */ "gui": { - "label": "JSON with Comments", + "window_name": "JSON with Comments", "command": "echo Hello!", "components": [], // You can put a trailing comma after the last element. diff --git a/examples/tips/comments/gui_definition.jsonc b/examples/tips/comments/gui_definition.jsonc index cb84976..4bc0f0b 100644 --- a/examples/tips/comments/gui_definition.jsonc +++ b/examples/tips/comments/gui_definition.jsonc @@ -4,7 +4,7 @@ * Multi-line comment */ "gui": { - "label": "JSON with Comments", + "window_name": "JSON with Comments", "command": "echo Hello!", "components": [], // You can put a trailing comma after the last element. diff --git a/examples/tips/multi_lines/README.md b/examples/tips/multi_lines/README.md index 900e601..b6a673f 100644 --- a/examples/tips/multi_lines/README.md +++ b/examples/tips/multi_lines/README.md @@ -10,9 +10,9 @@ But you can see some examples for it. On windows, you can join the commands with ` && `. And some commands like `for` loop require parentheses `()`. -```json +```jsonc { - "label": "Search json in a folder (Windows)", + // Search json in a folder (Windows) "command": "@echo off && (for %%f in (\"%dir%\\*.json\") do (echo %%f)) && echo Done!", "button": "Echo!", "components": [ @@ -28,9 +28,9 @@ And some commands like `for` loop require parentheses `()`. On non-Windows platforms, you can join the commands with `;`. -```json +```jsonc { - "label": "Search json in a folder (Unix/Linux)", + // Search json in a folder (Unix/Linux) "command": "for f in %dir%/*.json; do echo \"${f}\"; done; echo Done!", "button": "Echo!", "components": [ diff --git a/examples/tips/unicode/README.md b/examples/tips/unicode/README.md index e8ade41..8b98c88 100644 --- a/examples/tips/unicode/README.md +++ b/examples/tips/unicode/README.md @@ -6,7 +6,7 @@ Tuw supports UTF-8 strings. ```json { - "label": "Unicode Sample", + "window_name": "Unicode Sample", "command": "echo file: %รหัส% & echo folder: %-% & echo checkbox: %-%", "button": "こんにちは!", "components": [ diff --git a/examples/tips/unicode/gui_definition.json b/examples/tips/unicode/gui_definition.json index 983fb14..3407071 100644 --- a/examples/tips/unicode/gui_definition.json +++ b/examples/tips/unicode/gui_definition.json @@ -1,6 +1,6 @@ { "gui": { - "label": "Unicode Sample", + "window_name": "Unicode Sample", "command": "echo file: %รหัส% & echo folder: %-% & echo checkbox: %-%", "button": "こんにちは!", "components": [ diff --git a/include/json_utils.h b/include/json_utils.h index 269bc2b..ae3c2dc 100644 --- a/include/json_utils.h +++ b/include/json_utils.h @@ -39,6 +39,7 @@ void GetDefaultDefinition(rapidjson::Document& definition); void CheckVersion(JsonResult& result, rapidjson::Document& definition); void CheckDefinition(JsonResult& result, rapidjson::Document& definition); void CheckSubDefinition(JsonResult& result, rapidjson::Value& sub_definition, + int index, rapidjson::Document::AllocatorType& alloc); void CheckHelpURLs(JsonResult& result, rapidjson::Document& definition); diff --git a/schema/schema.json b/schema/schema.json index db2b430..756b039 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -157,9 +157,6 @@ "components": { "$ref": "#/definitions/types/component_array" }, "component_array": { "$ref": "#/definitions/types/component_array" } }, - "required": [ - "label" - ], "allOf": [ { "if": { diff --git a/src/json_utils.cpp b/src/json_utils.cpp index e7037bf..466c6bd 100644 --- a/src/json_utils.cpp +++ b/src/json_utils.cpp @@ -230,7 +230,6 @@ namespace json_utils { // get default definition of gui void GetDefaultDefinition(rapidjson::Document& definition) { static const char* def_str = "{" - "\"label\":\"Default GUI\"," #ifdef _WIN32 "\"command\":\"dir\"," "\"button\":\"run 'dir'\"," @@ -446,14 +445,22 @@ namespace json_utils { // validate one of definitions (["gui"][i]) and store parsed info void CheckSubDefinition(JsonResult& result, rapidjson::Value& sub_definition, + int index, rapidjson::Document::AllocatorType& alloc) { - // check is_string - CheckJsonType(result, sub_definition, "label", JsonType::STRING); - CheckJsonType(result, sub_definition, "button", JsonType::STRING, "", OPTIONAL); CorrectKey(sub_definition, "window_title", "window_name", alloc); CorrectKey(sub_definition, "title", "window_name", alloc); CheckJsonType(result, sub_definition, "window_name", JsonType::STRING, "", OPTIONAL); + if (!sub_definition.HasMember("label")) { + std::string default_label = ConcatCStrings("GUI ", index); + const char* label = GetString(sub_definition, "window_name", default_label.c_str()); + rapidjson::Value n(label, alloc); + sub_definition.AddMember("label", n, alloc); + } + CheckJsonType(result, sub_definition, "label", JsonType::STRING); + + CheckJsonType(result, sub_definition, "button", JsonType::STRING, "", OPTIONAL); + CheckJsonType(result, sub_definition, "check_exit_code", JsonType::BOOLEAN, "", OPTIONAL); CheckJsonType(result, sub_definition, "exit_success", JsonType::INTEGER, "", OPTIONAL); CheckJsonType(result, sub_definition, "show_last_line", JsonType::BOOLEAN, "", OPTIONAL); @@ -699,9 +706,11 @@ namespace json_utils { result.msg = "The size of [\"gui\"] should NOT be zero."; } + int i = 0; for (rapidjson::Value& sub_d : definition["gui"].GetArray()) { if (!result.ok) return; - CheckSubDefinition(result, sub_d, alloc); + CheckSubDefinition(result, sub_d, i, alloc); + i++; } } diff --git a/src/main_frame.cpp b/src/main_frame.cpp index 1f7b775..59c73c1 100644 --- a/src/main_frame.cpp +++ b/src/main_frame.cpp @@ -313,8 +313,10 @@ static void OnClicked(uiButton *sender, void *data) { void MainFrame::UpdatePanel(unsigned definition_id) { m_definition_id = definition_id; rapidjson::Value& sub_definition = m_definition["gui"][m_definition_id]; - const char* label = sub_definition["label"].GetString(); - PrintFmt("[UpdatePanel] Label: %s\n", label); + if (m_definition["gui"].Size() > 1) { + const char* label = sub_definition["label"].GetString(); + PrintFmt("[UpdatePanel] Label: %s\n", label); + } const char* cmd_str = sub_definition["command_str"].GetString(); PrintFmt("[UpdatePanel] Command: %s\n", cmd_str); const char* window_name = json_utils::GetString(sub_definition, diff --git a/tests/json/relaxed.jsonc b/tests/json/relaxed.jsonc index c7a31f8..4e49a13 100644 --- a/tests/json/relaxed.jsonc +++ b/tests/json/relaxed.jsonc @@ -3,7 +3,6 @@ /* * Multi-line comments */ - "label": "test", "command": "echo hello", "components": [], "help": {