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 <algorithm>
|
||||||
|
|
||||||
#include <wx/bmpbuttn.h>
|
#include <wx/bmpbuttn.h>
|
||||||
#include <wx/fontenum.h>
|
|
||||||
#include <wx/msgdlg.h>
|
#include <wx/msgdlg.h>
|
||||||
#include <wx/sizer.h>
|
#include <wx/sizer.h>
|
||||||
#include <wx/stattext.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));
|
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)
|
: wxDialog (parent, -1, _("Style Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||||
, c(c)
|
, c(c)
|
||||||
, is_new(false)
|
, is_new(false)
|
||||||
|
@ -164,8 +163,6 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
|
||||||
// Prepare control values
|
// Prepare control values
|
||||||
wxString EncodingValue = std::to_wstring(style->encoding);
|
wxString EncodingValue = std::to_wstring(style->encoding);
|
||||||
wxString alignValues[9] = { "7", "8", "9", "4", "5", "6", "1", "2", "3" };
|
wxString alignValues[9] = { "7", "8", "9", "4", "5", "6", "1", "2", "3" };
|
||||||
wxArrayString fontList = wxFontEnumerator::GetFacenames();
|
|
||||||
fontList.Sort();
|
|
||||||
|
|
||||||
// Encoding options
|
// Encoding options
|
||||||
wxArrayString encodingStrings;
|
wxArrayString encodingStrings;
|
||||||
|
@ -236,7 +233,7 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
|
||||||
Alignment->SetSelection(AlignToControl(style->alignment));
|
Alignment->SetSelection(AlignToControl(style->alignment));
|
||||||
// Fill font face list box
|
// Fill font face list box
|
||||||
FontName->Freeze();
|
FontName->Freeze();
|
||||||
FontName->Append(fontList);
|
FontName->Append(font_list);
|
||||||
FontName->SetValue(to_wx(style->font));
|
FontName->SetValue(to_wx(style->font));
|
||||||
FontName->Thaw();
|
FontName->Thaw();
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ class DialogStyleEditor : public wxDialog {
|
||||||
void OnSetColor(wxThreadEvent& evt);
|
void OnSetColor(wxThreadEvent& evt);
|
||||||
|
|
||||||
public:
|
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();
|
~DialogStyleEditor();
|
||||||
|
|
||||||
std::string GetStyleName() const;
|
std::string GetStyleName() const;
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
|
|
||||||
#include <wx/bmpbuttn.h>
|
#include <wx/bmpbuttn.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
#include <wx/fontenum.h>
|
||||||
#include <wx/intl.h>
|
#include <wx/intl.h>
|
||||||
#include <wx/msgdlg.h>
|
#include <wx/msgdlg.h>
|
||||||
#include <wx/sizer.h>
|
#include <wx/sizer.h>
|
||||||
|
@ -159,6 +160,11 @@ DialogStyleManager::DialogStyleManager(agi::Context *context)
|
||||||
, c(context)
|
, c(context)
|
||||||
, commit_connection(c->ass->AddCommitListener(&DialogStyleManager::LoadCurrentStyles, this))
|
, commit_connection(c->ass->AddCommitListener(&DialogStyleManager::LoadCurrentStyles, this))
|
||||||
, active_line_connection(c->selectionController->AddActiveLineListener(&DialogStyleManager::OnActiveLineChanged, 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;
|
using std::bind;
|
||||||
SetIcon(GETICON(style_toolbutton_16));
|
SetIcon(GETICON(style_toolbutton_16));
|
||||||
|
@ -486,7 +492,7 @@ void DialogStyleManager::PasteToStorage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogStyleManager::ShowStorageEditor(AssStyle *style, std::string const& new_name) {
|
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()) {
|
if (editor.ShowModal()) {
|
||||||
UpdateStorage();
|
UpdateStorage();
|
||||||
StorageList->SetStringSelection(to_wx(editor.GetStyleName()));
|
StorageList->SetStringSelection(to_wx(editor.GetStyleName()));
|
||||||
|
@ -495,7 +501,7 @@ void DialogStyleManager::ShowStorageEditor(AssStyle *style, std::string const& n
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogStyleManager::OnStorageNew() {
|
void DialogStyleManager::OnStorageNew() {
|
||||||
ShowStorageEditor(0);
|
ShowStorageEditor(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogStyleManager::OnStorageEdit() {
|
void DialogStyleManager::OnStorageEdit() {
|
||||||
|
@ -524,7 +530,7 @@ void DialogStyleManager::OnStorageDelete() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogStyleManager::ShowCurrentEditor(AssStyle *style, std::string const& new_name) {
|
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()) {
|
if (editor.ShowModal()) {
|
||||||
CurrentList->DeselectAll();
|
CurrentList->DeselectAll();
|
||||||
CurrentList->SetStringSelection(to_wx(editor.GetStyleName()));
|
CurrentList->SetStringSelection(to_wx(editor.GetStyleName()));
|
||||||
|
@ -533,7 +539,7 @@ void DialogStyleManager::ShowCurrentEditor(AssStyle *style, std::string const& n
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogStyleManager::OnCurrentNew() {
|
void DialogStyleManager::OnCurrentNew() {
|
||||||
ShowCurrentEditor(0);
|
ShowCurrentEditor(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogStyleManager::OnCurrentEdit() {
|
void DialogStyleManager::OnCurrentEdit() {
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
/// @ingroup style_editor
|
/// @ingroup style_editor
|
||||||
///
|
///
|
||||||
|
|
||||||
|
#include <future>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -58,6 +59,8 @@ class DialogStyleManager : public wxDialog {
|
||||||
agi::signal::Connection commit_connection;
|
agi::signal::Connection commit_connection;
|
||||||
agi::signal::Connection active_line_connection;
|
agi::signal::Connection active_line_connection;
|
||||||
|
|
||||||
|
std::shared_future<wxArrayString> font_list;
|
||||||
|
|
||||||
/// Styles in the current subtitle file
|
/// Styles in the current subtitle file
|
||||||
std::vector<AssStyle*> styleMap;
|
std::vector<AssStyle*> styleMap;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue