Prefetch the list of fonts for the style editor dialog
On my machine (with ~5000 fonts installed), enumerating the installed fonts was about 75% of the total construction time of the style editor dialog.
This commit is contained in:
parent
55379d506a
commit
a75b7f6ca8
4 changed files with 16 additions and 10 deletions
|
@ -58,7 +58,6 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include <wx/bmpbuttn.h>
|
||||
#include <wx/fontenum.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/stattext.h>
|
||||
|
@ -140,7 +139,7 @@ static wxTextCtrl *num_text_ctrl(wxWindow *parent, double value, bool allow_nega
|
|||
return new wxTextCtrl(parent, -1, "", wxDefaultPosition, size, 0, NumValidator(value, allow_negative));
|
||||
}
|
||||
|
||||
DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store, std::string const& new_name)
|
||||
DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store, std::string const& new_name, wxArrayString const& font_list)
|
||||
: wxDialog (parent, -1, _("Style Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||
, c(c)
|
||||
, is_new(false)
|
||||
|
@ -164,8 +163,6 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
|
|||
// Prepare control values
|
||||
wxString EncodingValue = std::to_wstring(style->encoding);
|
||||
wxString alignValues[9] = { "7", "8", "9", "4", "5", "6", "1", "2", "3" };
|
||||
wxArrayString fontList = wxFontEnumerator::GetFacenames();
|
||||
fontList.Sort();
|
||||
|
||||
// Encoding options
|
||||
wxArrayString encodingStrings;
|
||||
|
@ -236,7 +233,7 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
|
|||
Alignment->SetSelection(AlignToControl(style->alignment));
|
||||
// Fill font face list box
|
||||
FontName->Freeze();
|
||||
FontName->Append(fontList);
|
||||
FontName->Append(font_list);
|
||||
FontName->SetValue(to_wx(style->font));
|
||||
FontName->Thaw();
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ class DialogStyleEditor : public wxDialog {
|
|||
void OnSetColor(wxThreadEvent& evt);
|
||||
|
||||
public:
|
||||
DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store = 0, std::string const& new_name = "");
|
||||
DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store, std::string const& new_name, wxArrayString const& font_list);
|
||||
~DialogStyleEditor();
|
||||
|
||||
std::string GetStyleName() const;
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
|
||||
#include <wx/bmpbuttn.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/fontenum.h>
|
||||
#include <wx/intl.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/sizer.h>
|
||||
|
@ -159,6 +160,11 @@ DialogStyleManager::DialogStyleManager(agi::Context *context)
|
|||
, c(context)
|
||||
, commit_connection(c->ass->AddCommitListener(&DialogStyleManager::LoadCurrentStyles, this))
|
||||
, active_line_connection(c->selectionController->AddActiveLineListener(&DialogStyleManager::OnActiveLineChanged, this))
|
||||
, font_list(std::async(std::launch::async, []() -> wxArrayString {
|
||||
wxArrayString fontList = wxFontEnumerator::GetFacenames();
|
||||
fontList.Sort();
|
||||
return fontList;
|
||||
}))
|
||||
{
|
||||
using std::bind;
|
||||
SetIcon(GETICON(style_toolbutton_16));
|
||||
|
@ -486,7 +492,7 @@ void DialogStyleManager::PasteToStorage() {
|
|||
}
|
||||
|
||||
void DialogStyleManager::ShowStorageEditor(AssStyle *style, std::string const& new_name) {
|
||||
DialogStyleEditor editor(this, style, c, &Store, new_name);
|
||||
DialogStyleEditor editor(this, style, c, &Store, new_name, font_list.get());
|
||||
if (editor.ShowModal()) {
|
||||
UpdateStorage();
|
||||
StorageList->SetStringSelection(to_wx(editor.GetStyleName()));
|
||||
|
@ -495,7 +501,7 @@ void DialogStyleManager::ShowStorageEditor(AssStyle *style, std::string const& n
|
|||
}
|
||||
|
||||
void DialogStyleManager::OnStorageNew() {
|
||||
ShowStorageEditor(0);
|
||||
ShowStorageEditor(nullptr);
|
||||
}
|
||||
|
||||
void DialogStyleManager::OnStorageEdit() {
|
||||
|
@ -524,7 +530,7 @@ void DialogStyleManager::OnStorageDelete() {
|
|||
}
|
||||
|
||||
void DialogStyleManager::ShowCurrentEditor(AssStyle *style, std::string const& new_name) {
|
||||
DialogStyleEditor editor(this, style, c, 0, new_name);
|
||||
DialogStyleEditor editor(this, style, c, nullptr, new_name, font_list.get());
|
||||
if (editor.ShowModal()) {
|
||||
CurrentList->DeselectAll();
|
||||
CurrentList->SetStringSelection(to_wx(editor.GetStyleName()));
|
||||
|
@ -533,7 +539,7 @@ void DialogStyleManager::ShowCurrentEditor(AssStyle *style, std::string const& n
|
|||
}
|
||||
|
||||
void DialogStyleManager::OnCurrentNew() {
|
||||
ShowCurrentEditor(0);
|
||||
ShowCurrentEditor(nullptr);
|
||||
}
|
||||
|
||||
void DialogStyleManager::OnCurrentEdit() {
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
/// @ingroup style_editor
|
||||
///
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
@ -58,6 +59,8 @@ class DialogStyleManager : public wxDialog {
|
|||
agi::signal::Connection commit_connection;
|
||||
agi::signal::Connection active_line_connection;
|
||||
|
||||
std::shared_future<wxArrayString> font_list;
|
||||
|
||||
/// Styles in the current subtitle file
|
||||
std::vector<AssStyle*> styleMap;
|
||||
|
||||
|
|
Loading…
Reference in a new issue