1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-14 17:14:07 +01:00

Move code for Label track menu items

This commit is contained in:
Paul Licameli
2015-07-31 18:53:23 -04:00
committed by Paul Licameli
parent 516d812f3a
commit 01d5d30b7e
3 changed files with 110 additions and 112 deletions

View File

@@ -13,6 +13,14 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../HitTestResult.h"
#include "../../../LabelTrack.h"
#include "../../../widgets/PopupMenuTable.h"
#include "../../../Prefs.h"
#include "../../../RefreshCode.h"
#include "../../../ShuttleGui.h"
#include "../../../widgets/wxPanelWrapper.h"
#include <wx/dialog.h>
#include <wx/fontenum.h>
#include <wx/listbox.h>
#include <wx/spinctrl.h>
LabelTrackControls::LabelTrackControls()
{
@@ -54,6 +62,8 @@ public:
}
TrackControls::InitMenuData *mpData;
void OnSetFont(wxCommandEvent &);
};
LabelTrackMenuTable &LabelTrackMenuTable::Instance()
@@ -62,9 +72,108 @@ LabelTrackMenuTable &LabelTrackMenuTable::Instance()
return instance;
}
enum
{
OnSetFontID = 30000,
};
BEGIN_POPUP_MENU(LabelTrackMenuTable)
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM(OnSetFontID, _("&Font..."), OnSetFont)
END_POPUP_MENU()
void LabelTrackMenuTable::OnSetFont(wxCommandEvent &)
{
// Small helper class to enumerate all fonts in the system
// We use this because the default implementation of
// wxFontEnumerator::GetFacenames() has changed between wx2.6 and 2.8
class FontEnumerator : public wxFontEnumerator
{
public:
explicit FontEnumerator(wxArrayString* fontNames) :
mFontNames(fontNames) {}
bool OnFacename(const wxString& font) override
{
mFontNames->Add(font);
return true;
}
private:
wxArrayString* mFontNames;
};
wxArrayString facenames;
FontEnumerator fontEnumerator(&facenames);
fontEnumerator.EnumerateFacenames(wxFONTENCODING_SYSTEM, false);
wxString facename = gPrefs->Read(wxT("/GUI/LabelFontFacename"), wxT(""));
// Correct for empty facename, or bad preference file:
// get the name of a really existing font, to highlight by default
// in the list box
facename = LabelTrack::GetFont(facename).GetFaceName();
long fontsize = gPrefs->Read(wxT("/GUI/LabelFontSize"),
LabelTrack::DefaultFontSize);
/* i18n-hint: (noun) This is the font for the label track.*/
wxDialogWrapper dlg(mpData->pParent, wxID_ANY, wxString(_("Label Track Font")));
dlg.SetName(dlg.GetTitle());
ShuttleGui S(&dlg, eIsCreating);
wxListBox *lb;
wxSpinCtrl *sc;
S.StartVerticalLay(true);
{
S.StartMultiColumn(2, wxEXPAND);
{
S.SetStretchyRow(0);
S.SetStretchyCol(1);
/* i18n-hint: (noun) The name of the typeface*/
S.AddPrompt(_("Face name"));
lb = safenew wxListBox(&dlg, wxID_ANY,
wxDefaultPosition,
wxDefaultSize,
facenames,
wxLB_SINGLE);
lb->SetName(_("Face name"));
lb->SetSelection(facenames.Index(facename));
S.AddWindow(lb, wxALIGN_LEFT | wxEXPAND | wxALL);
/* i18n-hint: (noun) The size of the typeface*/
S.AddPrompt(_("Face size"));
sc = safenew wxSpinCtrl(&dlg, wxID_ANY,
wxString::Format(wxT("%ld"), fontsize),
wxDefaultPosition,
wxDefaultSize,
wxSP_ARROW_KEYS,
8, 48, fontsize);
sc->SetName(_("Face size"));
S.AddWindow(sc, wxALIGN_LEFT | wxALL);
}
S.EndMultiColumn();
S.AddStandardButtons();
}
S.EndVerticalLay();
dlg.Layout();
dlg.Fit();
dlg.CenterOnParent();
if (dlg.ShowModal() == wxID_CANCEL)
return;
gPrefs->Write(wxT("/GUI/LabelFontFacename"), lb->GetStringSelection());
gPrefs->Write(wxT("/GUI/LabelFontSize"), sc->GetValue());
gPrefs->Flush();
LabelTrack::ResetFont();
mpData->result = RefreshCode::RefreshAll;
}
PopupMenuTable *LabelTrackControls::GetMenuExtension(Track *)
{
return &LabelTrackMenuTable::Instance();