De-wxString HelpButton
This commit is contained in:
parent
8e36b69ef1
commit
f24a72d8fc
2 changed files with 41 additions and 41 deletions
|
@ -33,53 +33,54 @@
|
||||||
|
|
||||||
#include <libaegisub/exception.h>
|
#include <libaegisub/exception.h>
|
||||||
|
|
||||||
#include <boost/container/flat_map.hpp>
|
#include <algorithm>
|
||||||
|
|
||||||
|
static const char *pages[][2] = {
|
||||||
|
{"Attachment Manager", "Attachment_Manager"},
|
||||||
|
{"Automation Manager", "Automation/Manager"},
|
||||||
|
{"Colour Picker", "Colour_Picker"},
|
||||||
|
{"Dummy Video", "Video#dummyvideo"},
|
||||||
|
{"Export", "Exporting"},
|
||||||
|
{"Fonts Collector", "Fonts_Collector"},
|
||||||
|
{"Kanji Timer", "Kanji_Timer"},
|
||||||
|
{"Main", "Main_Page"},
|
||||||
|
{"Options", "Options"},
|
||||||
|
{"Paste Over", "Paste_Over"},
|
||||||
|
{"Properties", "Properties"},
|
||||||
|
{"Resample resolution", "Resolution_Resampler"},
|
||||||
|
{"Shift Times", "Shift_Times"},
|
||||||
|
{"Select Lines", "Select_Lines"},
|
||||||
|
{"Spell Checker", "Spell_Checker"},
|
||||||
|
{"Style Editor", "Styles"},
|
||||||
|
{"Styles Manager", "Styles"},
|
||||||
|
{"Styling Assistant", "Styling_Assistant"},
|
||||||
|
{"Timing Processor", "Timing_Post-Processor"},
|
||||||
|
{"Translation Assistant", "Translation_Assistant"},
|
||||||
|
{"Visual Typesetting", "Visual_Typesetting"},
|
||||||
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static boost::container::flat_map<wxString, wxString> pages;
|
const char *url(const char *page) {
|
||||||
|
auto it = std::lower_bound(std::begin(pages), std::end(pages), page, [](const char *pair[], const char *page) {
|
||||||
void init_static() {
|
return strcmp(pair[0], page) < 0;
|
||||||
if (pages.empty()) {
|
});
|
||||||
pages["Attachment Manager"] = "Attachment_Manager";
|
return it == std::end(pages) ? nullptr : (*it)[1];
|
||||||
pages["Automation Manager"] = "Automation/Manager";
|
|
||||||
pages["Colour Picker"] = "Colour_Picker";
|
|
||||||
pages["Dummy Video"] = "Video#dummyvideo";
|
|
||||||
pages["Export"] = "Exporting";
|
|
||||||
pages["Fonts Collector"] = "Fonts_Collector";
|
|
||||||
pages["Kanji Timer"] = "Kanji_Timer";
|
|
||||||
pages["Main"] = "Main_Page";
|
|
||||||
pages["Options"] = "Options";
|
|
||||||
pages["Paste Over"] = "Paste_Over";
|
|
||||||
pages["Properties"] = "Properties";
|
|
||||||
pages["Resample resolution"] = "Resolution_Resampler";
|
|
||||||
pages["Shift Times"] = "Shift_Times";
|
|
||||||
pages["Select Lines"] = "Select_Lines";
|
|
||||||
pages["Spell Checker"] = "Spell_Checker";
|
|
||||||
pages["Style Editor"] = "Styles";
|
|
||||||
pages["Styles Manager"] = "Styles";
|
|
||||||
pages["Styling Assistant"] = "Styling_Assistant";
|
|
||||||
pages["Timing Processor"] = "Timing_Post-Processor";
|
|
||||||
pages["Translation Assistant"] = "Translation_Assistant";
|
|
||||||
pages["Visual Typesetting"] = "Visual_Typesetting";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
HelpButton::HelpButton(wxWindow *parent, wxString const& page, wxPoint position, wxSize size)
|
HelpButton::HelpButton(wxWindow *parent, const char *page, wxPoint position, wxSize size)
|
||||||
: wxButton(parent, wxID_HELP, "", position, size)
|
: wxButton(parent, wxID_HELP, "", position, size)
|
||||||
{
|
{
|
||||||
Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { OpenPage(page); });
|
Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { OpenPage(page); });
|
||||||
init_static();
|
if (!url(page))
|
||||||
if (pages.find(page) == pages.end())
|
|
||||||
throw agi::InternalError("Invalid help page");
|
throw agi::InternalError("Invalid help page");
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpButton::OpenPage(wxString const& pageID) {
|
void HelpButton::OpenPage(const char *pageID) {
|
||||||
init_static();
|
auto page = url(pageID);
|
||||||
|
auto sep = strchr(page, '#');
|
||||||
wxString page = pages[pageID];
|
if (sep)
|
||||||
wxString section;
|
wxLaunchDefaultBrowser(fmt_wx("http://docs.aegisub.org/3.2/%.*s/%s", sep - page, page, sep));
|
||||||
page = page.BeforeFirst('#', §ion);
|
else
|
||||||
|
wxLaunchDefaultBrowser(fmt_wx("http://docs.aegisub.org/3.2/%s/", page));
|
||||||
wxLaunchDefaultBrowser(fmt_wx("http://docs.aegisub.org/3.2/%s/#%s", page, section));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
class HelpButton final : public wxButton {
|
class HelpButton final : public wxButton {
|
||||||
public:
|
public:
|
||||||
HelpButton(wxWindow *parent, wxString const& page="", wxPoint position=wxDefaultPosition, wxSize size=wxDefaultSize);
|
HelpButton(wxWindow *parent, const char *page, wxPoint position=wxDefaultPosition, wxSize size=wxDefaultSize);
|
||||||
|
static void OpenPage(const char *page);
|
||||||
static void OpenPage(wxString const& page);
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue