diff --git a/radiant/uimanager/colourscheme/ColourSchemeEditor.cpp b/radiant/uimanager/colourscheme/ColourSchemeEditor.cpp index 01880ea519..dac1238b51 100644 --- a/radiant/uimanager/colourscheme/ColourSchemeEditor.cpp +++ b/radiant/uimanager/colourscheme/ColourSchemeEditor.cpp @@ -15,7 +15,7 @@ #include #include -namespace ui +namespace ui { namespace @@ -24,8 +24,7 @@ namespace } ColourSchemeEditor::ColourSchemeEditor() : - DialogBase(_(EDITOR_WINDOW_TITLE)), - _listStore(new wxutil::TreeModel(_columns, true)) + DialogBase(_(EDITOR_WINDOW_TITLE)) { SetSizer(new wxBoxSizer(wxVERTICAL)); @@ -45,97 +44,96 @@ ColourSchemeEditor::ColourSchemeEditor() : void ColourSchemeEditor::populateTree() { - GlobalColourSchemeManager().foreachScheme([&](const std::string& name, colours::IColourScheme&) - { - wxutil::TreeModel::Row row = _listStore->AddItem(); - - row[_columns.name] = name; - - row.SendItemAdded(); - }); + GlobalColourSchemeManager().foreachScheme( + [&](const std::string& name, colours::IColourScheme&) + { + wxVector row; + row.push_back(wxVariant(name)); + _schemeList->AppendItem(row); + } + ); } void ColourSchemeEditor::constructWindow() { - wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL); - GetSizer()->Add(hbox, 1, wxEXPAND | wxALL, 12); - GetSizer()->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL), 0, - wxALIGN_RIGHT | wxLEFT | wxBOTTOM | wxRIGHT, 12); + GetSizer()->Add(hbox, 1, wxEXPAND | wxALL, 12); + GetSizer()->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL), 0, + wxALIGN_RIGHT | wxLEFT | wxBOTTOM | wxRIGHT, 12); - // Create the treeview and the buttons - wxBoxSizer* treeViewVbox = new wxBoxSizer(wxVERTICAL); - hbox->Add(treeViewVbox, 0, wxEXPAND | wxRIGHT, 6); + // Create the scheme list and the buttons + wxBoxSizer* treeViewVbox = new wxBoxSizer(wxVERTICAL); + hbox->Add(treeViewVbox, 0, wxEXPAND | wxRIGHT, 6); - _treeView = wxutil::TreeView::CreateWithModel(this, _listStore.get(), wxDV_NO_HEADER); - _treeView->SetMinClientSize(wxSize(200, -1)); - treeViewVbox->Add(_treeView, 1, wxEXPAND | wxBOTTOM, 6); + _schemeList = new wxDataViewListCtrl(this, wxID_ANY, wxDefaultPosition, + wxDefaultSize, wxDV_NO_HEADER); + _schemeList->SetMinClientSize(wxSize(200, -1)); + treeViewVbox->Add(_schemeList, 1, wxEXPAND | wxBOTTOM, 6); - // Create a new column and set its parameters - _treeView->AppendTextColumn(_("Colour"), _columns.name.getColumnIndex(), - wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); + // Create a text column to show the scheme name + _schemeList->AppendTextColumn( + _("Colour scheme"), wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, + wxALIGN_LEFT, wxDATAVIEW_COL_SORTABLE + ); - // Connect the signal AFTER selecting the active scheme - _treeView->Connect(wxEVT_DATAVIEW_SELECTION_CHANGED, - wxDataViewEventHandler(ColourSchemeEditor::callbackSelChanged), NULL, this); + // Connect the signal AFTER selecting the active scheme + _schemeList->Connect(wxEVT_DATAVIEW_SELECTION_CHANGED, + wxDataViewEventHandler(ColourSchemeEditor::callbackSelChanged), NULL, this); - // Treeview buttons - wxBoxSizer* buttonBox = new wxBoxSizer(wxHORIZONTAL); - treeViewVbox->Add(buttonBox, 0, wxEXPAND, 6); + // Treeview buttons + wxBoxSizer* buttonBox = new wxBoxSizer(wxHORIZONTAL); + treeViewVbox->Add(buttonBox, 0, wxEXPAND, 6); - _deleteButton = new wxButton(this, wxID_DELETE, _("Delete")); - wxButton* copyButton = new wxButton(this, wxID_COPY, _("Copy")); + _deleteButton = new wxButton(this, wxID_DELETE, _("Delete")); + wxButton* copyButton = new wxButton(this, wxID_COPY, _("Copy")); - buttonBox->Add(copyButton, 1, wxEXPAND | wxRIGHT, 6); - buttonBox->Add(_deleteButton, 1, wxEXPAND); + buttonBox->Add(copyButton, 1, wxEXPAND | wxRIGHT, 6); + buttonBox->Add(_deleteButton, 1, wxEXPAND); - copyButton->Connect(wxEVT_BUTTON, wxCommandEventHandler(ColourSchemeEditor::callbackCopy), NULL, this); - _deleteButton->Connect(wxEVT_BUTTON, wxCommandEventHandler(ColourSchemeEditor::callbackDelete), NULL, this); + copyButton->Connect(wxEVT_BUTTON, wxCommandEventHandler(ColourSchemeEditor::callbackCopy), NULL, this); + _deleteButton->Connect(wxEVT_BUTTON, wxCommandEventHandler(ColourSchemeEditor::callbackDelete), NULL, this); - // The Box containing the Colour, pack it into the right half of the hbox - _colourFrame = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxDOUBLE_BORDER); - hbox->Add(_colourFrame, 1, wxEXPAND); + // The Box containing the Colour, pack it into the right half of the hbox + _colourFrame = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxDOUBLE_BORDER); + hbox->Add(_colourFrame, 1, wxEXPAND); } void ColourSchemeEditor::selectActiveScheme() { - wxDataViewItem found = _listStore->FindString( - GlobalColourSchemeManager().getActiveScheme().getName(), _columns.name); - - _treeView->Select(found); + // Find a row matching the active colour scheme name + wxString name = GlobalColourSchemeManager().getActiveScheme().getName(); + unsigned r = 0; + for ( ; r < _schemeList->GetItemCount(); ++r) + { + wxString rowName = _schemeList->GetTextValue(r, 0); + if (rowName == name) + break; + } + + _schemeList->SelectRow(r); selectionChanged(); } void ColourSchemeEditor::deleteSchemeFromList() { - wxDataViewItem item = _treeView->GetSelection(); - - if (item.IsOk()) - { - _listStore->RemoveItem(item); - } + // Delete the selected row + int row = _schemeList->GetSelectedRow(); + if (row != wxNOT_FOUND) + _schemeList->DeleteItem(row); // Select the first scheme - wxDataViewItemArray children; - - if (_listStore->GetChildren(_listStore->GetRoot(), children) > 0) - { - _treeView->Select(*children.begin()); - selectionChanged(); - } + if (_schemeList->GetItemCount() > 0) + _schemeList->SelectRow(0); } std::string ColourSchemeEditor::getSelectedScheme() { - wxDataViewItem item = _treeView->GetSelection(); - - if (item.IsOk()) - { - wxutil::TreeModel::Row row(item, *_listStore); - return row[_columns.name]; - } - - return ""; + int row = _schemeList->GetSelectedRow(); + if (row != wxNOT_FOUND) + return _schemeList->GetTextValue(row, 0).ToStdString(); + else + return ""; } wxSizer* ColourSchemeEditor::constructColourSelector(colours::IColourItem& colour, const std::string& name) @@ -160,7 +158,7 @@ wxSizer* ColourSchemeEditor::constructColourSelector(colours::IColourItem& colou { callbackColorChanged(ev, colour); }); - + // Create the description label wxStaticText* label = new wxStaticText(_colourFrame, wxID_ANY, description); @@ -281,9 +279,9 @@ void ColourSchemeEditor::copyScheme() GlobalColourSchemeManager().setActive(newName); // Add the new list item to the ListStore - wxutil::TreeModel::Row row = _listStore->AddItem(); - row[_columns.name] = newName; - row.SendItemAdded(); + wxVector rowData; + rowData.push_back(wxVariant(newName)); + _schemeList->AppendItem(rowData); // Highlight the copied scheme selectActiveScheme(); @@ -306,7 +304,7 @@ void ColourSchemeEditor::callbackColorChanged(wxColourPickerEvent& ev, colours:: // Update the colourItem class item.getColour().set( - static_cast(colour.Red()) / 255.0, + static_cast(colour.Red()) / 255.0, static_cast(colour.Green()) / 255.0, static_cast(colour.Blue()) / 255.0); @@ -323,7 +321,7 @@ void ColourSchemeEditor::callbackSelChanged(wxDataViewEvent& ev) int ColourSchemeEditor::ShowModal() { int returnCode = DialogBase::ShowModal(); - + if (returnCode == wxID_OK) { GlobalColourSchemeManager().setActive(getSelectedScheme()); diff --git a/radiant/uimanager/colourscheme/ColourSchemeEditor.h b/radiant/uimanager/colourscheme/ColourSchemeEditor.h index 31869c110c..8d10d43eba 100644 --- a/radiant/uimanager/colourscheme/ColourSchemeEditor.h +++ b/radiant/uimanager/colourscheme/ColourSchemeEditor.h @@ -22,22 +22,8 @@ namespace ui class ColourSchemeEditor : public wxutil::DialogBase { - // The treeview and its selection pointer - wxutil::TreeView* _treeView; - - struct Columns : - public wxutil::TreeModel::ColumnRecord - { - Columns() : - name(add(wxutil::TreeModel::Column::String)) - {} - - wxutil::TreeModel::Column name; - }; - - // The list store containing the list of ColourSchemes - Columns _columns; - wxutil::TreeModel::Ptr _listStore; + // The list of available colour schemes + wxDataViewListCtrl* _schemeList = nullptr; // The vbox containing the colour buttons and its frame wxPanel* _colourFrame;