forked from mia/Aegisub
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:
parent
6ca0349fc8
commit
55ff9bfd50
3 changed files with 29 additions and 34 deletions
|
@ -332,7 +332,6 @@ FrameMain::~FrameMain () {
|
||||||
delete_children(this, SubsGrid);
|
delete_children(this, SubsGrid);
|
||||||
|
|
||||||
delete context->ass;
|
delete context->ass;
|
||||||
HelpButton::ClearPages();
|
|
||||||
delete context->audioController;
|
delete context->audioController;
|
||||||
delete context->local_scripts;
|
delete context->local_scripts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,61 +41,58 @@
|
||||||
#include <libaegisub/exception.h>
|
#include <libaegisub/exception.h>
|
||||||
#include <libaegisub/path.h>
|
#include <libaegisub/path.h>
|
||||||
|
|
||||||
|
#include <boost/container/flat_map.hpp>
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
|
||||||
static std::map<wxString,wxString> *pages = nullptr;
|
namespace {
|
||||||
|
static boost::container::flat_map<wxString, wxString> pages;
|
||||||
|
|
||||||
static void init_static() {
|
void init_static() {
|
||||||
if (!pages) {
|
if (pages.empty()) {
|
||||||
pages = new std::map<wxString, wxString>;
|
pages["Attachment Manager"] = "Attachment_Manager";
|
||||||
std::map<wxString, wxString> &page = *pages;
|
pages["Automation Manager"] = "Automation/Manager";
|
||||||
page["Attachment Manager"] = "Attachment_Manager";
|
pages["Colour Picker"] = "Colour_Picker";
|
||||||
page["Automation Manager"] = "Automation/Manager";
|
pages["Dummy Video"] = "Video#dummyvideo";
|
||||||
page["Colour Picker"] = "Colour_Picker";
|
pages["Export"] = "Exporting";
|
||||||
page["Dummy Video"] = "Video#dummyvideo";
|
pages["Fonts Collector"] = "Fonts_Collector";
|
||||||
page["Export"] = "Exporting";
|
pages["Kanji Timer"] = "Kanji_Timer";
|
||||||
page["Fonts Collector"] = "Fonts_Collector";
|
pages["Main"] = "Main_Page";
|
||||||
page["Kanji Timer"] = "Kanji_Timer";
|
pages["Options"] = "Options";
|
||||||
page["Main"] = "Main_Page";
|
pages["Paste Over"] = "Paste_Over";
|
||||||
page["Options"] = "Options";
|
pages["Properties"] = "Properties";
|
||||||
page["Paste Over"] = "Paste_Over";
|
pages["Resample resolution"] = "Resolution_Resampler";
|
||||||
page["Properties"] = "Properties";
|
pages["Shift Times"] = "Shift_Times";
|
||||||
page["Resample resolution"] = "Resolution_Resampler";
|
pages["Select Lines"] = "Select_Lines";
|
||||||
page["Shift Times"] = "Shift_Times";
|
pages["Spell Checker"] = "Spell_Checker";
|
||||||
page["Select Lines"] = "Select_Lines";
|
pages["Style Editor"] = "Styles";
|
||||||
page["Spell Checker"] = "Spell_Checker";
|
pages["Styles Manager"] = "Styles";
|
||||||
page["Style Editor"] = "Styles";
|
pages["Styling Assistant"] = "Styling_Assistant";
|
||||||
page["Styles Manager"] = "Styles";
|
pages["Timing Processor"] = "Timing_Post-Processor";
|
||||||
page["Styling Assistant"] = "Styling_Assistant";
|
pages["Translation Assistant"] = "Translation_Assistant";
|
||||||
page["Timing Processor"] = "Timing_Post-Processor";
|
pages["Visual Typesetting"] = "Visual_Typesetting";
|
||||||
page["Translation Assistant"] = "Translation_Assistant";
|
|
||||||
page["Visual Typesetting"] = "Visual_Typesetting";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HelpButton::HelpButton(wxWindow *parent, wxString const& page, wxPoint position, wxSize size)
|
HelpButton::HelpButton(wxWindow *parent, wxString const& page, wxPoint position, wxSize size)
|
||||||
: wxButton(parent, wxID_HELP, "", position, size)
|
: wxButton(parent, wxID_HELP, "", position, size)
|
||||||
{
|
{
|
||||||
Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, page));
|
Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, page));
|
||||||
init_static();
|
init_static();
|
||||||
if (pages->find(page) == pages->end())
|
if (pages.find(page) == pages.end())
|
||||||
throw agi::InternalError("Invalid help page", nullptr);
|
throw agi::InternalError("Invalid help page", nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpButton::OpenPage(wxString const& pageID) {
|
void HelpButton::OpenPage(wxString const& pageID) {
|
||||||
init_static();
|
init_static();
|
||||||
|
|
||||||
wxString page = (*pages)[pageID];
|
wxString page = pages[pageID];
|
||||||
wxString section;
|
wxString section;
|
||||||
page = page.BeforeFirst('#', §ion);
|
page = page.BeforeFirst('#', §ion);
|
||||||
|
|
||||||
wxLaunchDefaultBrowser(wxString::Format("http://docs.aegisub.org/3.1/%s/#%s", page, section));
|
wxLaunchDefaultBrowser(wxString::Format("http://docs.aegisub.org/3.1/%s/#%s", page, section));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpButton::ClearPages() {
|
|
||||||
delete pages;
|
|
||||||
}
|
|
||||||
|
|
|
@ -39,5 +39,4 @@ public:
|
||||||
HelpButton(wxWindow *parent, wxString const& page="", wxPoint position=wxDefaultPosition, wxSize size=wxDefaultSize);
|
HelpButton(wxWindow *parent, wxString const& page="", wxPoint position=wxDefaultPosition, wxSize size=wxDefaultSize);
|
||||||
|
|
||||||
static void OpenPage(wxString const& page);
|
static void OpenPage(wxString const& page);
|
||||||
static void ClearPages();
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue