Simplify HelpButton a little

Switch to flat_map for trivially less memory usage and just use a global
map rather than a heap-allocated map since it's not
(de)initialization-order sensitive.
This commit is contained in:
Thomas Goyne 2013-12-26 09:51:56 -08:00
parent 6ca0349fc8
commit 55ff9bfd50
3 changed files with 29 additions and 34 deletions

View file

@ -332,7 +332,6 @@ FrameMain::~FrameMain () {
delete_children(this, SubsGrid);
delete context->ass;
HelpButton::ClearPages();
delete context->audioController;
delete context->local_scripts;
}

View file

@ -41,61 +41,58 @@
#include <libaegisub/exception.h>
#include <libaegisub/path.h>
#include <boost/container/flat_map.hpp>
#include <boost/filesystem/path.hpp>
#include <functional>
#include <map>
#include <wx/filename.h>
static std::map<wxString,wxString> *pages = nullptr;
namespace {
static boost::container::flat_map<wxString, wxString> pages;
static void init_static() {
if (!pages) {
pages = new std::map<wxString, wxString>;
std::map<wxString, wxString> &page = *pages;
page["Attachment Manager"] = "Attachment_Manager";
page["Automation Manager"] = "Automation/Manager";
page["Colour Picker"] = "Colour_Picker";
page["Dummy Video"] = "Video#dummyvideo";
page["Export"] = "Exporting";
page["Fonts Collector"] = "Fonts_Collector";
page["Kanji Timer"] = "Kanji_Timer";
page["Main"] = "Main_Page";
page["Options"] = "Options";
page["Paste Over"] = "Paste_Over";
page["Properties"] = "Properties";
page["Resample resolution"] = "Resolution_Resampler";
page["Shift Times"] = "Shift_Times";
page["Select Lines"] = "Select_Lines";
page["Spell Checker"] = "Spell_Checker";
page["Style Editor"] = "Styles";
page["Styles Manager"] = "Styles";
page["Styling Assistant"] = "Styling_Assistant";
page["Timing Processor"] = "Timing_Post-Processor";
page["Translation Assistant"] = "Translation_Assistant";
page["Visual Typesetting"] = "Visual_Typesetting";
void init_static() {
if (pages.empty()) {
pages["Attachment Manager"] = "Attachment_Manager";
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)
: wxButton(parent, wxID_HELP, "", position, size)
{
Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, page));
init_static();
if (pages->find(page) == pages->end())
if (pages.find(page) == pages.end())
throw agi::InternalError("Invalid help page", nullptr);
}
void HelpButton::OpenPage(wxString const& pageID) {
init_static();
wxString page = (*pages)[pageID];
wxString page = pages[pageID];
wxString section;
page = page.BeforeFirst('#', &section);
wxLaunchDefaultBrowser(wxString::Format("http://docs.aegisub.org/3.1/%s/#%s", page, section));
}
void HelpButton::ClearPages() {
delete pages;
}

View file

@ -39,5 +39,4 @@ public:
HelpButton(wxWindow *parent, wxString const& page="", wxPoint position=wxDefaultPosition, wxSize size=wxDefaultSize);
static void OpenPage(wxString const& page);
static void ClearPages();
};