diff --git a/FunctionImp.cpp b/FunctionImp.cpp index 6acf678..46d609f 100644 --- a/FunctionImp.cpp +++ b/FunctionImp.cpp @@ -3,3 +3,11 @@ // #include "FunctionImp.h" + +CFunctionImp::CFunctionImp() += default; + +bool CFunctionImp::gen(const wxString& out_dir, const wxArrayString& dirs) +{ + return true; +} diff --git a/FunctionImp.h b/FunctionImp.h index 42d004a..b863cd1 100644 --- a/FunctionImp.h +++ b/FunctionImp.h @@ -4,5 +4,15 @@ #ifndef FUNCTIONIMP_H #define FUNCTIONIMP_H +#include + +class CFunctionImp +{ +public: + CFunctionImp(); + +public: + bool gen(const wxString& out_dir, const wxArrayString& dirs); +}; #endif //FUNCTIONIMP_H diff --git a/MainFrame.cpp b/MainFrame.cpp index 5b09dc7..f26fba2 100644 --- a/MainFrame.cpp +++ b/MainFrame.cpp @@ -12,4 +12,5 @@ CMainFrame::CMainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title void CMainFrame::InitFrame() { panel_ = new CMainPanel(this); + SetSize(wxSize(600, 800)); } \ No newline at end of file diff --git a/MainPanel.cpp b/MainPanel.cpp index b7a5f9d..f5283d1 100644 --- a/MainPanel.cpp +++ b/MainPanel.cpp @@ -3,25 +3,128 @@ CMainPanel::CMainPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxPanel(parent, id, pos, size, style, name) { + top_sizer_ = new wxBoxSizer(wxVERTICAL); + handle_ = new CFunctionImp(); InitPanel(); } void CMainPanel::InitPanel() { - ui_box_sizer_ = new wxStaticBoxSizer(wxVERTICAL, this, wxT("一、基本信息")); + // 创建 wxStaticBoxSizer,并设置标题 + base_box_sizer_ = new wxStaticBoxSizer(wxVERTICAL, this, wxT("一、基本信息")); + // 创建水平 sizer 来放置控件 sizer_select_ = new wxBoxSizer(wxHORIZONTAL); - label_select_ = new wxStaticText(ui_box_sizer_->GetStaticBox(), wxID_ANY, wxT("要打包的二进制文件")); - text_select_ctrl_ = new wxTextCtrl(ui_box_sizer_->GetStaticBox(), wxID_ANY); - text_select_ctrl_->SetMinSize(wxSize(300, -1)); - btn_select_ = new wxButton(ui_box_sizer_->GetStaticBox(), wxID_ANY, wxT("选择")); - btn_select_->Bind(wxEVT_BUTTON, &CMainPanel::selectBinaryFile, this); - sizer_select_->Add(label_select_, 0, wxALL | wxALIGN_CENTER_VERTICAL, 3); - sizer_select_->Add(text_select_ctrl_, 1, wxALL, 3); - sizer_select_->Add(btn_select_, 0, wxALL | wxALIGN_LEFT, 3); - ui_box_sizer_->Add(sizer_select_, 0, wxALL | wxEXPAND, 3); - SetSizer(ui_box_sizer_); + // 创建控件,并将其父级设置为正确的窗口(即 `this`,代表主窗口或面板) + label_select_ = new wxStaticText(this, wxID_ANY, wxT("要打包的二进制文件:")); + text_select_ctrl_ = new wxTextCtrl(this, wxID_ANY); + text_select_ctrl_->SetMinSize(wxSize(300, -1)); + + btn_select_ = new wxButton(this, wxID_ANY, wxT("选择文件")); + btn_select_->Bind(wxEVT_BUTTON, &CMainPanel::selectBinaryFile, this); + + // 将控件添加到水平 sizer 中 + sizer_select_->Add(text_select_ctrl_, 1, wxALL | wxEXPAND, g_Border); + sizer_select_->Add(btn_select_, 0, wxALL | wxALIGN_LEFT, g_Border); + + // 将水平 sizer 添加到带标题的 sizer 中, wxALIGN_CENTER_VERTICAL 仅水平可用 + base_box_sizer_->Add(label_select_, 0, wxALL, g_Border); + base_box_sizer_->Add(sizer_select_, 0, wxALL | wxEXPAND, g_Border); + + sizer_output_ = new wxBoxSizer(wxHORIZONTAL); + btn_output_ = new wxButton(this, wxID_ANY, wxT("选择目录")); + text_output_ctrl_ = new wxTextCtrl(this, wxID_ANY); + label_output_ = new wxStaticText(this, wxID_ANY, wxT("输出目录:")); + base_box_sizer_->Add(label_output_, 0, wxALL, g_Border); + + sizer_output_->Add(text_output_ctrl_, 1, wxALL, g_Border); + sizer_output_->Add(btn_output_, 0, wxALL, g_Border); + base_box_sizer_->Add(sizer_output_, 0, wxALL | wxEXPAND, g_Border); + + env_box_sizer_ = new wxStaticBoxSizer(wxVERTICAL, this, wxT("二、搜索库范围")); + env_list_ = new wxListBox(this, wxID_ANY); + + env_oper_sizer_ = new wxBoxSizer(wxHORIZONTAL); + btn_add_env_ = new wxButton(this, wxID_ANY, wxT("添加")); + btn_del_env_ = new wxButton(this, wxID_ANY, wxT("删除")); + btn_add_env_->Bind(wxEVT_BUTTON, &CMainPanel::addEnv, this); + btn_del_env_->Bind(wxEVT_BUTTON, &CMainPanel::delEnv, this); + + env_oper_sizer_->Add(btn_add_env_, 0, wxALL | wxALIGN_LEFT, g_Border); + env_oper_sizer_->Add(btn_del_env_, 0, wxALL | wxALIGN_LEFT, g_Border); + + env_box_sizer_->Add(env_oper_sizer_, 0, wxALL, g_Border); + env_box_sizer_->Add(env_list_, 1, wxALL | wxEXPAND, g_Border); + + top_sizer_->Add(base_box_sizer_, 1, wxALL | wxEXPAND, g_Border); + top_sizer_->Add(env_box_sizer_, 1, wxALL | wxEXPAND, g_Border); + + oper_sizer_ = new wxBoxSizer(wxHORIZONTAL); + btn_gen_ = new wxButton(this, wxID_ANY, wxT("生成")); + btn_exit_ = new wxButton(this, wxID_ANY, wxT("退出")); + btn_gen_->Bind(wxEVT_BUTTON, &CMainPanel::genResult, this); + btn_exit_->Bind(wxEVT_BUTTON, [&](wxCommandEvent& event) { GetParent()->Close(); }); + oper_sizer_->Add(btn_gen_, 0, wxALL, g_Border); + oper_sizer_->Add(btn_exit_, 0, wxALL, g_Border); + + // 排列的时候在 sizer 里面排列 + top_sizer_->Add(oper_sizer_, 0, wxALIGN_RIGHT | wxALL, g_Border); + + // 设置主窗口的 sizer + SetSizer(top_sizer_); +} + +void CMainPanel::genResult(wxCommandEvent& event) +{ + wxArrayString arrayStrings; + // 获取 wxListBox 中的所有项 + unsigned int count = env_list_->GetCount(); + for (unsigned int i = 0; i < count; ++i) { + wxString item = env_list_->GetString(i); + arrayStrings.Add(item); + } + wxString out_dir = text_output_ctrl_->GetValue(); + if (handle_->gen(out_dir, arrayStrings)) { + // 显示消息框 + wxMessageBox(wxT("成功"), // 消息内容 + wxT("成功"), // 标题 + wxOK | wxICON_INFORMATION, // 按钮和图标 + this // 父窗口 + ); + return; + } + wxMessageBox(wxT("失败"), // 消息内容 + wxT("失败"), // 标题 + wxOK | wxICON_INFORMATION, // 按钮和图标 + this // 父窗口 + ); +} + +void CMainPanel::delEnv(wxCommandEvent& event) +{ + int selection = env_list_->GetSelection(); + if (selection != wxNOT_FOUND) { + // 删除选中的项 + env_list_->Delete(selection); + } +} + +void CMainPanel::addEnv(wxCommandEvent& event) +{ + wxDirDialog dirDialog(this, wxT("Select Directory"), wxEmptyString, wxDD_DIR_MUST_EXIST); + + if (dirDialog.ShowModal() == wxID_CANCEL) return; // 用户取消选择 + + wxString selectedDir = dirDialog.GetPath(); + + // 检查列表中是否已经存在此目录 + for (unsigned int i = 0; i < env_list_->GetCount(); ++i) { + if (env_list_->GetString(i) == selectedDir) return; // 目录已存在,不再添加 + } + + // 添加目录到列表 + env_list_->Append(selectedDir); } void CMainPanel::selectBinaryFile(wxCommandEvent& event) diff --git a/MainPanel.h b/MainPanel.h index daa2c71..55faaf8 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -2,21 +2,39 @@ #define MAIN_PANEL #include +#include "FunctionImp.h" constexpr int g_Width = 700; constexpr int g_Heigh = 450; +constexpr int g_Border = 3; class CMainPanel : public wxPanel { -protected: - wxStaticBox* ui_basic_box_{}; - wxStaticBox* ui_second_box_{}; - wxStaticBoxSizer* ui_box_sizer_{}; - wxStaticText* label_select_{}; - wxBoxSizer* sizer_select_{}; - wxTextCtrl* text_select_ctrl_{}; - wxButton* btn_select_{}; +private: + CFunctionImp* handle_{}; +protected: + wxBoxSizer* top_sizer_{}; + wxStaticBoxSizer* base_box_sizer_{}; + wxStaticBoxSizer* env_box_sizer_{}; + wxStaticText* label_select_{}; + wxStaticText* label_output_{}; + + wxBoxSizer* sizer_select_{}; + wxBoxSizer* sizer_output_{}; + wxTextCtrl* text_select_ctrl_{}; + wxTextCtrl* text_output_ctrl_{}; + wxButton* btn_select_{}; + wxButton* btn_output_{}; + + wxBoxSizer* env_oper_sizer_{}; + wxButton* btn_add_env_{}; + wxButton* btn_del_env_{}; + + wxListBox* env_list_{}; + wxBoxSizer* oper_sizer_{}; + wxButton* btn_gen_{}; + wxButton* btn_exit_{}; public: explicit CMainPanel(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(g_Width, g_Heigh), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString); @@ -26,6 +44,9 @@ public: private: void selectBinaryFile(wxCommandEvent& event); + void addEnv(wxCommandEvent& event); + void delEnv(wxCommandEvent& event); + void genResult(wxCommandEvent& event); }; #endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index 9101de1..7ff3b8c 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,7 @@ class CLinuxPack : public wxApp public: bool OnInit() override { - auto* frame = new CMainFrame(wxT("Linux二进制打包")); + auto* frame = new CMainFrame(wxT("Linux二进制工具")); frame->Show(true); return true; }