X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fcontent_panel.cc;h=d9400e34c504ee64081945539ba641a8422f04fb;hb=a4a7cd938aa4f23f23240ed732844e5ad61683c0;hp=df6308bea548929f1ba50a9dd0ffe366c00693f3;hpb=deb61d087799d18cce97b1f0f99fe036d2214a42;p=dcpomatic.git diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index df6308bea..d9400e34c 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -90,22 +90,26 @@ public: bool OnSashPositionChange(int new_position) override { /* Try to stop the top bit of the splitter getting so small that buttons disappear */ - return new_position > 220; + auto const ok = new_position > 220; + if (ok) { + Config::instance()->set_main_content_divider_sash_position(new_position); + } + return ok; } void first_shown(wxWindow* top, wxWindow* bottom) { int const sn = wxDisplay::GetFromWindow(this); + /* Fallback for when GetFromWindow fails for reasons that aren't clear */ + int pos = -600; if (sn >= 0) { wxRect const screen = wxDisplay(sn).GetClientArea(); /* This is a hack to try and make the content notebook a sensible size; large on big displays but small enough on small displays to leave space for the content area. */ - SplitHorizontally(top, bottom, screen.height > 800 ? -600 : -_top_panel_minimum_size); - } else { - /* Fallback for when GetFromWindow fails for reasons that aren't clear */ - SplitHorizontally(top, bottom, -600); + pos = screen.height > 800 ? -600 : -_top_panel_minimum_size; } + SplitHorizontally(top, bottom, Config::instance()->main_content_divider_sash_position().get_value_or(pos)); _first_shown = true; } @@ -117,7 +121,7 @@ private: /* The window is now fairly big but the top panel is small; this happens when the DCP-o-matic window * is shrunk and then made larger again. Try to set a sensible top panel size in this case (#1839). */ - SetSashPosition(_top_panel_minimum_size); + SetSashPosition(Config::instance()->main_content_divider_sash_position().get_value_or(_top_panel_minimum_size)); } ev.Skip (); @@ -175,6 +179,47 @@ private: }; +/** A wxListCtrl that can middle-ellipsize its text */ +class ContentListCtrl : public wxListCtrl +{ +public: + ContentListCtrl(wxWindow* parent) + : wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxSize(320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_VIRTUAL) + { + _red.SetTextColour(*wxRED); + } + + struct Item + { + wxString text; + bool error; + }; + + void set(vector const& items) + { + _items = items; + SetItemCount(items.size()); + } + + wxString OnGetItemText(long item, long) const override + { + DCPOMATIC_ASSERT(item >= 0 && item < static_cast(_items.size())); + wxClientDC dc(const_cast(static_cast(this))); + return wxControl::Ellipsize(_items[item].text, dc, wxELLIPSIZE_MIDDLE, GetSize().GetWidth()); + } + + wxListItemAttr* OnGetItemAttr(long item) const override + { + DCPOMATIC_ASSERT(item >= 0 && item < static_cast(_items.size())); + return _items[item].error ? const_cast(&_red) : nullptr; + } + +private: + std::vector _items; + wxListItemAttr _red; +}; + + ContentPanel::ContentPanel(wxNotebook* n, shared_ptr film, FilmViewer& viewer) : _parent (n) , _film (film) @@ -191,12 +236,12 @@ ContentPanel::ContentPanel(wxNotebook* n, shared_ptr film, FilmViewer& vie { auto s = new wxBoxSizer (wxHORIZONTAL); - _content = new wxListCtrl (_top_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER); + _content = new ContentListCtrl(_top_panel); _content->DragAcceptFiles (true); s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6); _content->InsertColumn (0, wxT("")); - _content->SetColumnWidth (0, 512); + _content->SetColumnWidth(0, 2048); auto b = new wxBoxSizer (wxVERTICAL); @@ -857,7 +902,7 @@ ContentPanel::setup () selected_content = reinterpret_cast (item.GetData ()); } - _content->DeleteAllItems (); + vector items; for (auto i: content) { int const t = _content->GetItemCount (); @@ -881,21 +926,15 @@ ContentPanel::setup () s = _("NEEDS OV: ") + s; } - wxListItem item; - item.SetId (t); - item.SetText (s); - item.SetData (i.get ()); - _content->InsertItem (item); + items.push_back({s, !valid || needs_kdm || needs_assets}); if (i.get() == selected_content) { set_selected_state(t, true); } - - if (!valid || needs_kdm || needs_assets) { - _content->SetItemTextColour (t, *wxRED); - } } + _content->set(items); + if (!selected_content && !content.empty ()) { /* Select the item of content if none was selected before */ set_selected_state(0, true);