Skip to content

Commit a03073a

Browse files
authored
Merge pull request #7 from matyalatte/dev
v0.2.1
2 parents f0d2ba1 + 6224b10 commit a03073a

19 files changed

+346
-295
lines changed

changelog.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
ver0.2.1
2+
- Introduced wxBoxSizer to align components automatically.
3+
- Added "default" option to all components.
4+
- Fixed a bug that non-ascii characters won't be shown up as "empty_message." (Windows)
5+
- Fixed a bug that LogFrame can't catch non-ascii characters from std::cout. (Linux)
6+
- Fixed an error when executing non-ascii commands. (Unix)
7+
- Fixed an error when saving non-ascii characters for text box.
8+
19
ver0.2.0
210
- Made "button" key optional
311
- Fixed a bug that text boxes can't handle their input values properly.

docs/Build-With-Unix.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ The steps are as follows.
2525

2626
1. Open the Terminal.
2727
2. Move to `./Simple-Command-Runner/shell_scripts`
28-
3. Type `bush build_exe.sh`.
28+
3. Type `bash build_exe.sh`.
2929
4. An executable file `SimpleCommandRunner` will be generated in `./Simple-Command-Runner/Release`.
3030

3131
## Debug build
3232

3333
If you want a debug build, you need to use `Debug` as an argument for shell scripts.
34-
So, you should type `bash build_wxWidgets.sh Debug` and `bush build_exe.sh Debug` on the terminal.
34+
So, you should type `bash build_wxWidgets.sh Debug` and `bash build_exe.sh Debug` on the terminal.
3535

3636
## Test
3737

docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Simple-Command-Runner ver 0.2.0
1+
# Simple-Command-Runner ver 0.2.1
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)

examples/6_all_keys/gui_definition.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,39 @@
4949
"label": "PNG or JPG",
5050
"extension": "png or jpg (*.png;*.jpg)|*.png;*.jpg",
5151
"empty_message": "Drop a file here!",
52+
"default": "test.txt",
5253
"add_quotes": true
5354
},
5455
{
5556
"type": "folder",
56-
"label": "Some folder path",
57+
"label": "Folder path",
5758
"empty_message": "Drop a folder here!",
59+
"default": "testdir",
5860
"add_quotes": true
5961
},
6062
{
6163
"type": "check",
62-
"label": "checkbox",
64+
"label": "Checkbox",
6365
"value": "flag!",
6466
"default": true
6567
},
6668
{
6769
"type": "choice",
68-
"label": "combo box",
70+
"label": "Combo box",
6971
"items": ["item1", "item2", "item3"],
7072
"values": ["value1", "value2", "value3"],
7173
"default": 2
7274
},
7375
{
7476
"type": "check_array",
75-
"label": "options",
77+
"label": "Options",
7678
"items": ["item1", "item2", "item3", "item4"],
7779
"values": ["falg1", "falg2", "falg3", "flag4"],
7880
"default": [false, false, true, false]
7981
},
8082
{
8183
"type": "text_box",
82-
"label": "text box",
84+
"label": "Text box",
8385
"empty_message": "type here!",
8486
"default": "remove this text!"
8587
}

include/component.h

+18-23
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,18 @@
88
#include "json_utils.h"
99
#include "custom_wx_obj.h"
1010

11-
#ifdef _WIN32
12-
#include <codecvt> // char code converter for Windows system
13-
#endif
14-
1511
// Base class for GUI components (file picker, combo box, etc.)
1612
class Component {
1713
protected:
1814
void* m_widget;
1915

2016
private:
21-
int m_height;
2217
bool m_has_string;
2318
bool m_add_quotes;
2419
std::string m_label;
2520

2621
public:
27-
Component(nlohmann::json j, int height, bool has_string);
22+
Component(nlohmann::json j, bool has_string);
2823
~Component() {}
2924
virtual wxString GetRawString() { return "";}
3025
wxString GetString();
@@ -33,12 +28,9 @@ class Component {
3328
virtual void SetConfig(nlohmann::json config) {}
3429
virtual nlohmann::json GetConfig();
3530

36-
void SetHeight(int h);
37-
int GetHeight();
38-
3931
bool HasString();
4032

41-
static Component* PutComponent(wxPanel* panel, nlohmann::json j, int y);
33+
static Component* PutComponent(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j);
4234
};
4335

4436
// containers for Choice and CheckArray
@@ -60,29 +52,33 @@ std::wstring UTF8ToWString(const std::string& str);
6052

6153
class StaticText : public Component {
6254
public:
63-
StaticText(wxPanel* panel, nlohmann::json j, int y);
55+
StaticText(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j);
6456
};
6557

66-
class FilePicker : public Component {
58+
class StringComponentBase : public Component {
6759
public:
68-
wxString GetRawString() override;
69-
FilePicker(wxPanel* panel, nlohmann::json j, int y);
60+
StringComponentBase(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j);
7061
nlohmann::json GetConfig() override;
62+
};
63+
64+
class FilePicker : public StringComponentBase {
65+
public:
66+
wxString GetRawString() override;
67+
FilePicker(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j);
7168
void SetConfig(nlohmann::json config) override;
7269
};
7370

74-
class DirPicker : public Component {
71+
class DirPicker : public StringComponentBase {
7572
public:
7673
wxString GetRawString() override;
77-
DirPicker(wxPanel* panel, nlohmann::json j, int y);
78-
nlohmann::json GetConfig() override;
74+
DirPicker(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j);
7975
void SetConfig(nlohmann::json config) override;
8076
};
8177

8278
class Choice : public Component, MultipleValuesContainer {
8379
public:
8480
wxString GetRawString() override;
85-
Choice(wxPanel* panel, nlohmann::json j, int y);
81+
Choice(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j);
8682
nlohmann::json GetConfig() override;
8783
void SetConfig(nlohmann::json config) override;
8884
};
@@ -92,23 +88,22 @@ class CheckBox : public Component {
9288
std::string m_value;
9389
public:
9490
wxString GetRawString() override;
95-
CheckBox(wxPanel* panel, nlohmann::json j, int y);
91+
CheckBox(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j);
9692
nlohmann::json GetConfig() override;
9793
void SetConfig(nlohmann::json config) override;
9894
};
9995

10096
class CheckArray : public Component, MultipleValuesContainer {
10197
public:
10298
wxString GetRawString() override;
103-
CheckArray(wxPanel* panel, nlohmann::json j, int y);
99+
CheckArray(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j);
104100
nlohmann::json GetConfig() override;
105101
void SetConfig(nlohmann::json config) override;
106102
};
107103

108-
class TextBox : public Component {
104+
class TextBox : public StringComponentBase {
109105
public:
110106
wxString GetRawString() override;
111-
TextBox(wxPanel* panel, nlohmann::json j, int y);
112-
nlohmann::json GetConfig() override;
107+
TextBox(wxWindow* panel, wxBoxSizer* sizer, nlohmann::json j);
113108
void SetConfig(nlohmann::json config) override;
114109
};

include/custom_wx_obj.h

+11-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class CustomTextCtrl : public wxTextCtrl {
2222
long style = 0,
2323
const wxValidator& validator = wxDefaultValidator,
2424
const wxString& name = wxTextCtrlNameStr);
25-
virtual ~CustomTextCtrl() {}
2625

2726
void OnSetFocusEmptyMessage(wxFocusEvent& event);
2827
void OnKillFocusEmptyMessage(wxFocusEvent& event);
@@ -41,9 +40,14 @@ class DropFilePath : public wxFileDropTarget{
4140
CustomTextCtrl* m_text_ctrl;
4241

4342
public:
44-
DropFilePath(T* frame, CustomTextCtrl* text_ctrl);
45-
~DropFilePath();
46-
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) wxOVERRIDE;
43+
DropFilePath(T* frame, CustomTextCtrl* text_ctrl): wxFileDropTarget() {
44+
m_frame = frame;
45+
m_text_ctrl = text_ctrl;
46+
}
47+
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames){
48+
m_text_ctrl->UpdateText(filenames[0]);
49+
return 1;
50+
}
4751
};
4852

4953
// Customized wxFileDirPickerCtrlBase
@@ -53,8 +57,9 @@ class CustomPickerBase : public wxFileDirPickerCtrlBase {
5357
CustomTextCtrl* m_custom_text_ctrl;
5458

5559
public:
56-
CustomPickerBase();
57-
virtual ~CustomPickerBase() {}
60+
CustomPickerBase() : wxFileDirPickerCtrlBase() {
61+
m_custom_text_ctrl = nullptr;
62+
}
5863

5964
// Customized wxPickerBase::CreateBase
6065
bool CustomCreatePickerBase(wxWindow* parent,
@@ -98,7 +103,6 @@ class CustomFilePicker : public CustomPickerBase {
98103
long style = wxFLP_DEFAULT_STYLE,
99104
const wxValidator& validator = wxDefaultValidator,
100105
const wxString& name = wxFilePickerCtrlNameStr);
101-
virtual ~CustomFilePicker() {}
102106

103107
wxString GetTextCtrlValue() const wxOVERRIDE;
104108
wxString GetFullPath() wxOVERRIDE;
@@ -153,7 +157,6 @@ class CustomDirPicker : public CustomPickerBase {
153157
long style = wxFLP_DEFAULT_STYLE,
154158
const wxValidator& validator = wxDefaultValidator,
155159
const wxString& name = wxFilePickerCtrlNameStr);
156-
virtual ~CustomDirPicker() {}
157160

158161
wxString GetTextCtrlValue() const wxOVERRIDE;
159162
wxString GetFullPath() wxOVERRIDE;

include/exec.h

+38-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,42 @@
55
#include "wx/wx.h"
66
#include "wx/process.h"
77

8+
#ifdef __linux__
9+
// A text window to show outputs.
10+
// wxStreamToTextRedirector won't work because it can't handle utf-8 characters.
11+
class LogFrame : public wxFrame {
12+
private:
13+
wxTextCtrl* m_log_box;
14+
wxStreamToTextRedirector* m_log_redirector;
15+
16+
public:
17+
explicit LogFrame(wxString exepath);
18+
void OnClose(wxCloseEvent& event);
19+
LogFrame& operator <<(std::string& str) {
20+
m_log_box->AppendText(wxString::FromUTF8(str));
21+
return *this;
22+
}
23+
LogFrame& operator <<(wxString& str) {
24+
m_log_box->AppendText(str);
25+
return *this;
26+
}
27+
LogFrame& operator <<(const char* str) {
28+
m_log_box->AppendText(wxString::FromUTF8(str));
29+
return *this;
30+
}
31+
typedef std::basic_ostream<char, std::char_traits<char> > CoutType;
32+
typedef CoutType& (*StandardEndLine)(CoutType&);
33+
LogFrame& operator <<(StandardEndLine endl) {
34+
*this << "\n";
35+
return *this;
36+
}
37+
};
38+
#endif
39+
40+
841
// run command and return error messages
9-
std::array<std::string, 2> Exec(const char* cmd);
42+
#ifdef __linux__
43+
std::array<std::string, 2> Exec(LogFrame& ostream, wxString& cmd);
44+
#else
45+
std::array<std::string, 2> Exec(std::ostream& ostream, wxString& cmd);
46+
#endif

include/main_frame.h

+10-16
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,42 @@
1212
#include <wx/stdpaths.h>
1313
#endif
1414

15-
#ifdef __linux__
16-
class LogFrame : public wxFrame {
17-
private:
18-
wxTextCtrl* m_log_box;
19-
wxStreamToTextRedirector* m_log_redirector;
20-
public:
21-
explicit LogFrame(wxString exepath);
22-
virtual ~LogFrame() {}
23-
void OnClose(wxCloseEvent& event);
24-
};
25-
#endif
26-
2715
// Main window
2816
class MainFrame : public wxFrame {
2917
private:
3018
nlohmann::json m_definition;
3119
nlohmann::json m_sub_definition;
3220
nlohmann::json m_config;
21+
3322
#ifdef __linux__
23+
// Linux needs a window to show outputs
3424
LogFrame* m_log_frame;
25+
LogFrame* m_ostream;
26+
#else
27+
std::ostream* m_ostream;
3528
#endif
29+
3630
#ifndef _WIN32
31+
// Unix systems need to get current dir to read json files.
3732
wxString m_exe_path;
3833
void CalcExePath();
3934
#endif
35+
4036
std::vector<Component*> m_components;
41-
wxPanel* m_main_panel;
37+
wxPanel* m_panel;
4238
wxButton* m_run_button;
4339

4440
void CreateFrame();
4541
void CheckDefinition();
46-
int UpdatePanel(wxPanel* panel);
42+
void UpdatePanel();
4743
void UpdateConfig();
48-
void Align(int y);
4944
void ShowErrorDialog(wxString msg);
5045
void ShowSuccessDialog(wxString msg);
5146
void JsonLoadFailed(std::string msg);
5247

5348
public:
5449
MainFrame();
5550
explicit MainFrame(nlohmann::json definition, nlohmann::json config = nlohmann::json({}));
56-
virtual ~MainFrame() {}
5751

5852
void OnClose(wxCloseEvent& event);
5953
void OpenURL(wxCommandEvent& event);

0 commit comments

Comments
 (0)