95 lines
3.4 KiB
C++

#include "mainframe.h"
#include <wx/grid.h>
constexpr int g_Border = 2;
MainFrame::MainFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600))
{
match_func_ = std::make_shared<MatchFunc>();
}
MainFrame::~MainFrame()
{
}
bool MainFrame::Init()
{
auto* panel = new wxPanel(this, wxID_ANY);
auto* mainSizer = new wxBoxSizer(wxVERTICAL);
auto* sizerA = new wxBoxSizer(wxHORIZONTAL);
auto* staticTextA = new wxStaticText(panel, wxID_ANY, wxT("工程目录:"));
proj_root_ = new wxTextCtrl(panel, wxID_ANY, wxT(""));
auto* buttonA = new wxButton(panel, wxID_ANY, wxT("..."));
buttonA->Bind(wxEVT_BUTTON, &MainFrame::OnSelectDir, this, buttonA->GetId());
sizerA->Add(staticTextA, 0, wxALL | wxALIGN_CENTER_VERTICAL, g_Border);
sizerA->Add(proj_root_, 1, wxALL, g_Border);
sizerA->Add(buttonA, 0, wxALL, g_Border);
auto* sizerHelp = new wxBoxSizer(wxHORIZONTAL);
auto* sizerB = new wxBoxSizer(wxHORIZONTAL);
auto* helpText = new wxStaticText(panel, wxID_ANY, wxT("简要说明:筛选框多个内容以|分隔。"));
sizerHelp->Add(helpText, 1, wxALL, g_Border);
auto* staticTextB = new wxStaticText(panel, wxID_ANY, wxT("筛选后缀:"));
auto* staticTextC = new wxStaticText(panel, wxID_ANY, wxT("筛选函数:"));
auto* combox = new wxChoice(panel, wxID_ANY);
combox->Append(wxT("printf"));
combox->Append(wxT("format"));
combox->SetSelection(0);
auto* textCtrlC = new wxTextCtrl(panel, wxID_ANY, wxT("cxx|cpp|h|hpp|cc|c"));
sizerB->Add(staticTextB, 0, wxALL | wxALIGN_CENTER_VERTICAL, g_Border);
sizerB->Add(textCtrlC, 1, wxALL | wxEXPAND, g_Border);
sizerB->Add(staticTextC, 0, wxALL | wxALIGN_CENTER_VERTICAL, g_Border);
sizerB->Add(combox, 0, wxALL, g_Border);
auto* sizerC = new wxBoxSizer(wxHORIZONTAL);
// 表格控件
auto* tableCtrl = new wxGrid(panel, wxID_ANY);
tableCtrl->CreateGrid(1, 2);
tableCtrl->SetColLabelValue(0, wxT("文件名"));
tableCtrl->SetColLabelValue(1, wxT("行号"));
sizerC->Add(tableCtrl, 1, wxALL, g_Border);
auto* sizerD = new wxBoxSizer(wxHORIZONTAL);
auto* btnStart = new wxButton(panel, wxID_ANY, wxT("开始"));
auto* btnRecheck = new wxButton(panel, wxID_ANY, wxT("重查"));
auto* btnSimpleIntro = new wxButton(panel, wxID_ANY, wxT("工具简介"));
auto* btnExit = new wxButton(panel, wxID_ANY, wxT("退出"));
sizerD->Add(btnStart, 0, wxALL, g_Border);
sizerD->Add(btnRecheck, 0, wxALL, g_Border);
sizerD->Add(btnSimpleIntro, 0, wxALL, g_Border);
sizerD->Add(btnExit, 0, wxALL, g_Border);
mainSizer->Add(sizerA, 0, wxEXPAND | wxALL, g_Border);
mainSizer->Add(sizerHelp, 0, wxEXPAND | wxALL, g_Border);
mainSizer->Add(sizerB, 0, wxEXPAND | wxALL, g_Border);
mainSizer->Add(sizerC, 1, wxEXPAND | wxALL, g_Border);
mainSizer->Add(sizerD, 0, wxEXPAND | wxALL, g_Border);
panel->SetSizer(mainSizer);
return true;
}
void MainFrame::OnSelectDir(wxCommandEvent& event)
{
wxDirDialog dialog(this, wxT("选择工程根目录"));
if (dialog.ShowModal() == wxID_OK) {
proj_root_->SetValue(dialog.GetPath());
}
}
void MainFrame::Start(wxCommandEvent& event)
{
auto dir = proj_root_->GetValue();
if (dir.Trim().IsEmpty()) {
wxMessageBox(wxT("请选择工程根目录!"), wxT("提示"), wxOK | wxICON_INFORMATION);
return;
}
}