Skip to content

Commit 57a15b8

Browse files
authored
Merge pull request #8 from matyalatte/dev
v0.2.2 update
2 parents a03073a + 489bd59 commit 57a15b8

25 files changed

+322
-98
lines changed

.github/workflows/test.yml

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: test
22

33
on:
4-
push:
5-
tags:
6-
- "v*"
74
workflow_dispatch:
85

96
env:

batch_files/build_exe.bat

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
@echo off
22

3-
REM Builds SimpleCommandRunner with cmake.
3+
REM Builds SimpleCommandRunner with CMake and Visual Studio.
44
REM SimpleCommandRunner.exe will be generated in Simple-Command-Runner/%BUILD_TYPE%/Release
55

6-
REM You need Visual Studio to use this batch file.
7-
REM Run it with "x64 Ntive Tools Command Prompt for VS 2022". Or fail to build.
8-
96
set /p WX_VERSION=< %~dp0\..\WX_VERSION.txt
107
set VS_VERSION=Visual Studio 17 2022
118

batch_files/build_wxWidgets.bat

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
@echo off
22

3-
REM Builds wxWidgets with cmake.
4-
REM You need Visual Studio to use this batch file.
5-
REM Run it with "x64 Ntive Tools Command Prompt for VS 2022". Or fail to build.
3+
REM Builds wxWidgets with CMake and Visual Studio.
64

75
set /p WX_VERSION=< %~dp0\..\WX_VERSION.txt
86
set VS_VERSION=Visual Studio 17 2022

batch_files/download_wxWidgets.bat

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@echo off
2+
23
REM Downloads wxWidget.
34
REM Run it as admin. Or fail to install.
45

changelog.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
ver 0.2.2
2+
- Added "id" option to all components.
3+
(It'll be used as a variable name for the command and gui_config.json)
4+
- Improved json validatior
5+
16
ver0.2.1
27
- Introduced wxBoxSizer to align components automatically.
38
- Added "default" option to all components.
File renamed without changes.

docs/Build-With-Windows.md docs/Build-on-Windows.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- CMake
77
- Batch files in [`./Simple-Command-Runner/batch_files`](../batch_files)
88

9+
If you won't use Visual Studio 2022, you could need to edit cmake commands in batch files.
10+
911
## 1. Build wxWidgets
1012

1113
wxWidgets is a GUI framework.

docs/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Simple-Command-Runner ver 0.2.1
1+
# Simple-Command-Runner ver 0.2.2
22

33
![build](https://github.com/matyalatte/Simple-Command-Runner/actions/workflows/build_all.yml/badge.svg)
44
![test](https://github.com/matyalatte/Simple-Command-Runner/actions/workflows/test.yml/badge.svg)
@@ -71,14 +71,14 @@ See here for the details.
7171
### Windows
7272

7373
There is a document for Windows users.
74-
[Building Workflow for Windows](./Build-With-Windows.md)
74+
[Building Workflow for Windows](./Build-on-Windows.md)
7575

7676
It only supports Visual Studio 2022, but you can see [the batch files](../batch_files/) to find a way to build it with your environment.
7777

7878
### Mac and Ubuntu
7979

8080
There is a document for Mac and Ubuntu users.
81-
[Building Workflow for Ubuntu and MacOS](./Build-With-Unix.md)
81+
[Building Workflow for Ubuntu and MacOS](./Build-on-Unix.md)
8282

8383
And you can see [the shell scripts](../shell_scripts/) to understand the workflow.
8484

examples/6_id/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# ID
2+
3+
`id` is an optional key for components.
4+
Its value will be used as a veriable name in commands.
5+
6+
Here is an example.
7+
8+
```json
9+
{
10+
"label": "Sample GUI",
11+
"command": "echo y: %something% & echo x: %x% & echo z: %bruh% & echo x: %x%",
12+
"button": "Echo!",
13+
"components": [
14+
{
15+
"type": "static_text",
16+
"label": "Sample GUI for \"id\" option."
17+
},
18+
{
19+
"type": "text",
20+
"label": "Value of x",
21+
"id": "x"
22+
},
23+
{
24+
"type": "text",
25+
"label": "Value of y"
26+
},
27+
{
28+
"type": "text",
29+
"label": "Value of z"
30+
}
31+
]
32+
}
33+
```
34+
35+
In this case, the value of x will be injected into both of `%x%` parts.
36+
Because `x` is an ID for the first text box.
37+
The value of y will be injected into `%something%`.
38+
Because `something` is not any ID for components and the second text box is the first component that have no ID.
39+
The value of z will be injected into `%bruh%`.
40+
Because the last text box is the second component that have no ID.

examples/6_id/gui_definition.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"gui": [
3+
{
4+
"label": "Sample GUI",
5+
"command": "echo x: %x% & echo y: %y% & echo z: %z%",
6+
"button": "Echo!",
7+
"components": [
8+
{
9+
"type": "static_text",
10+
"label": "Sample GUI for \"id\" option."
11+
},
12+
{
13+
"type": "text",
14+
"label": "Value of z",
15+
"id": "z"
16+
},
17+
{
18+
"type": "text",
19+
"label": "Value of y",
20+
"id": "y"
21+
},
22+
{
23+
"type": "text",
24+
"label": "Value of x",
25+
"id": "x"
26+
}
27+
]
28+
},
29+
{
30+
"label": "Sample GUI2",
31+
"command": "echo y: %something% & echo x: %x% & echo x: %x%",
32+
"button": "Echo!",
33+
"components": [
34+
{
35+
"type": "static_text",
36+
"label": "Sample GUI for \"id\" option."
37+
},
38+
{
39+
"type": "text",
40+
"label": "Value of x",
41+
"id": "x"
42+
},
43+
{
44+
"type": "text",
45+
"label": "Value of y"
46+
}
47+
]
48+
}
49+
]
50+
}
File renamed without changes.

examples/6_all_keys/gui_definition.json examples/7_all_keys/gui_definition.json

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
{
4848
"type": "file",
4949
"label": "PNG or JPG",
50+
"id": "file",
5051
"extension": "png or jpg (*.png;*.jpg)|*.png;*.jpg",
5152
"empty_message": "Drop a file here!",
5253
"default": "test.txt",
@@ -55,33 +56,38 @@
5556
{
5657
"type": "folder",
5758
"label": "Folder path",
59+
"id": "folder",
5860
"empty_message": "Drop a folder here!",
5961
"default": "testdir",
6062
"add_quotes": true
6163
},
6264
{
6365
"type": "check",
6466
"label": "Checkbox",
67+
"id": "check",
6568
"value": "flag!",
6669
"default": true
6770
},
6871
{
6972
"type": "choice",
7073
"label": "Combo box",
74+
"id": "choice",
7175
"items": ["item1", "item2", "item3"],
7276
"values": ["value1", "value2", "value3"],
7377
"default": 2
7478
},
7579
{
7680
"type": "check_array",
7781
"label": "Options",
82+
"id": "options",
7883
"items": ["item1", "item2", "item3", "item4"],
7984
"values": ["falg1", "falg2", "falg3", "flag4"],
8085
"default": [false, false, true, false]
8186
},
8287
{
8388
"type": "text_box",
8489
"label": "Text box",
90+
"id": "text",
8591
"empty_message": "type here!",
8692
"default": "remove this text!"
8793
}

include/component.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212
class Component {
1313
protected:
1414
void* m_widget;
15+
wxString m_label;
1516

1617
private:
1718
bool m_has_string;
1819
bool m_add_quotes;
19-
std::string m_label;
20+
std::string m_id;
2021

2122
public:
2223
Component(nlohmann::json j, bool has_string);
2324
~Component() {}
2425
virtual wxString GetRawString() { return "";}
2526
wxString GetString();
26-
std::string GetLabel();
27+
std::string const GetID();
2728

2829
virtual void SetConfig(nlohmann::json config) {}
2930
virtual nlohmann::json GetConfig();

include/main_frame.h

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class MainFrame : public wxFrame {
5353
void OpenURL(wxCommandEvent& event);
5454
void UpdateFrame(wxCommandEvent& event);
5555
void ClickButton(wxCommandEvent& event);
56+
wxString GetCommand();
5657
std::array<std::string, 2> RunCommand();
5758
nlohmann::json GetDefinition();
5859
void SaveConfig();

shell_scripts/build_exe.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
#Builds an executable file with cmake.
3-
#SimpleCommandRunner will be generated in ../build
2+
# Builds an executable file with cmake.
3+
# SimpleCommandRunner will be generated in ../build
44

55
if [ "$1" = "Debug" ];
66
then build_type="Debug";

shell_scripts/build_wxWidgets.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
2-
#Builds and installs wxWidgets with cmake.
2+
# Builds and installs wxWidgets with cmake.
33

4-
#you need build-essential and libgtk-3-dev for linux
5-
#sudo apt -y install build-essential libgtk-3-dev
4+
# you need build-essential and libgtk-3-dev for linux
5+
# sudo apt -y install build-essential libgtk-3-dev
66

77
wx_version="$(cat $(dirname "$0")/../WX_VERSION.txt)"
88

shell_scripts/download_wxWidgets.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
#Downloads wxWidgets.
2+
# Downloads wxWidgets.
33

44
wx_version="$(cat $(dirname "$0")/../WX_VERSION.txt)"
55

shell_scripts/test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
#Builds an executable file with cmake.
3-
#SimpleCommandRunner will be generated in ../build
2+
# Builds an executable file with cmake.
3+
# SimpleCommandRunner will be generated in ../build
44

55
if [ "$1" = "Debug" ];
66
then build_type="Debug";

src/component.cpp

+17-21
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
Component::Component(nlohmann::json j, bool has_string) {
55
m_widget = nullptr;
66
m_has_string = has_string;
7-
m_label = j["label"];
7+
m_label = wxString::FromUTF8(j["label"]);
8+
m_id = j.value("id", "");
9+
if (m_id == "") {
10+
if (m_label.Length() > 128) {
11+
m_id = m_label.Left(128).ToUTF8();
12+
} else {
13+
m_id = m_label;
14+
}
15+
}
816
m_add_quotes = j.value("add_quotes", false);
917
}
1018

@@ -20,8 +28,8 @@ nlohmann::json Component::GetConfig() {
2028
return {};
2129
}
2230

23-
std::string Component::GetLabel() {
24-
return m_label;
31+
std::string const Component::GetID() {
32+
return m_id;
2533
}
2634

2735
bool Component::HasString() {
@@ -58,18 +66,13 @@ const int DEFAULT_SIZER_FLAG = wxFIXED_MINSIZE | wxALIGN_LEFT | wxBOTTOM;
5866
// Static Text
5967
StaticText::StaticText(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j)
6068
: Component(j, NOT_STRING) {
61-
sizer->Add(
62-
new wxStaticText(panel, wxID_ANY,
63-
wxString::FromUTF8(j["label"])),
64-
0, DEFAULT_SIZER_FLAG , 13);
69+
sizer->Add(new wxStaticText(panel, wxID_ANY, m_label), 0, DEFAULT_SIZER_FLAG , 13);
6570
}
6671

6772
// Base Class for strings
6873
StringComponentBase::StringComponentBase(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j)
6974
: Component(j, HAS_STRING) {
70-
sizer->Add(
71-
new wxStaticText(panel, wxID_ANY, wxString::FromUTF8(j["label"])),
72-
0, DEFAULT_SIZER_FLAG, 3);
75+
sizer->Add(new wxStaticText(panel, wxID_ANY, m_label), 0, DEFAULT_SIZER_FLAG, 3);
7376
}
7477

7578
nlohmann::json StringComponentBase::GetConfig() {
@@ -146,10 +149,7 @@ Choice::Choice(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j)
146149
std::for_each(items.begin(), items.end(), [&](std::string i) {
147150
wxitems.Add(wxString::FromUTF8(i));
148151
});
149-
sizer->Add(
150-
new wxStaticText(panel, wxID_ANY,
151-
wxString::FromUTF8(j["label"])),
152-
0, DEFAULT_SIZER_FLAG, 3);
152+
sizer->Add(new wxStaticText(panel, wxID_ANY, m_label), 0, DEFAULT_SIZER_FLAG, 3);
153153
wxChoice* choice = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxitems);
154154
sizer->Add(choice, 0, DEFAULT_SIZER_FLAG, 13);
155155
if (j.contains("default") && j["items"].size() > j["default"]) {
@@ -193,10 +193,9 @@ void SetDefaultForCheckBox(wxCheckBox* check, nlohmann::json j) {
193193
// CheckBox
194194
CheckBox::CheckBox(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j)
195195
: Component(j, HAS_STRING) {
196-
wxCheckBox* check = new wxCheckBox(panel, wxID_ANY,
197-
wxString::FromUTF8(j["label"]));
196+
wxCheckBox* check = new wxCheckBox(panel, wxID_ANY, m_label);
198197
sizer->Add(check, 0, DEFAULT_SIZER_FLAG, 13);
199-
m_value = j.value("value", j["label"]);
198+
m_value = j.value("value", m_label.ToUTF8());
200199
if (j.contains("default")) {
201200
SetDefaultForCheckBox(check, j["default"]);
202201
}
@@ -225,10 +224,7 @@ nlohmann::json CheckBox::GetConfig() {
225224
// CheckArray
226225
CheckArray::CheckArray(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j)
227226
: Component(j, HAS_STRING) {
228-
sizer->Add(
229-
new wxStaticText(panel, wxID_ANY,
230-
wxString::FromUTF8(j["label"])),
231-
0, DEFAULT_SIZER_FLAG, 3);
227+
sizer->Add(new wxStaticText(panel, wxID_ANY, m_label), 0, DEFAULT_SIZER_FLAG, 3);
232228
std::vector<wxCheckBox*>* checks = new std::vector<wxCheckBox*>();
233229
for (int i = 0; i < j["items"].size(); i++) {
234230
wxCheckBox* check = new wxCheckBox(panel, wxID_ANY,

0 commit comments

Comments
 (0)