+void
+FontsDialog::selection_changed ()
+{
+ setup_sensitivity ();
+}
+
+void
+FontsDialog::setup_sensitivity ()
+{
+ int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ _edit->Enable (item != -1);
+}
+
+void
+FontsDialog::edit_clicked ()
+{
+ shared_ptr<Content> content = _content.lock ();
+ shared_ptr<TextContent> caption = _caption.lock ();
+ if (!content || !caption) {
+ return;
+ }
+
+ int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ string const id = wx_to_std (_fonts->GetItemText (item, 0));
+ shared_ptr<Font> font;
+ BOOST_FOREACH (shared_ptr<Font> i, caption->fonts()) {
+ if (i->id() == id) {
+ font = i;
+ }
+ }
+
+ if (!font) {
+ return;
+ }
+
+ /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
+ non-Latin filenames or paths.
+ */
+ wxString default_dir = "";
+#ifdef DCPOMATIC_LINUX
+ if (boost::filesystem::exists ("/usr/share/fonts/truetype")) {
+ default_dir = "/usr/share/fonts/truetype";
+ } else {
+ default_dir = "/usr/share/fonts";
+ }
+#endif
+#ifdef DCPOMATIC_OSX
+ default_dir = "/System/Library/Fonts";
+#endif
+
+ wxFileDialog* d = new wxFileDialog (this, _("Choose a font file"), default_dir, wxT(""), wxT("*.ttf;*.otf"), wxFD_CHANGE_DIR);
+ int const r = d->ShowModal ();
+
+ if (r != wxID_OK) {
+ d->Destroy ();
+ return;
+ }
+
+ font->set_file (wx_to_std(d->GetPath()));
+ d->Destroy ();
+
+ setup ();
+}