ENH: [STUDIO-3893] edit plate name in object list

Change-Id: I2dd704c50f684bedac7958d4a133edbda5522382
This commit is contained in:
chunmao.guo 2023-08-08 09:06:20 +08:00 committed by Lane.Wei
parent 8e10ec039f
commit a549553960
2 changed files with 34 additions and 1 deletions

View file

@ -263,6 +263,7 @@ ObjectList::ObjectList(wxWindow* parent) :
Bind(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, &ObjectList::OnDropPossible, this);
Bind(wxEVT_DATAVIEW_ITEM_DROP, &ObjectList::OnDrop, this);
Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &ObjectList::OnStartEditing, this);
Bind(wxEVT_DATAVIEW_ITEM_EDITING_STARTED, &ObjectList::OnEditingStarted, this);
Bind(wxEVT_DATAVIEW_ITEM_EDITING_DONE, &ObjectList::OnEditingDone, this);
@ -366,7 +367,8 @@ void ObjectList::create_objects_ctrl()
// And Icon can be consisting of several bitmaps
BitmapTextRenderer* bmp_text_renderer = new BitmapTextRenderer();
bmp_text_renderer->set_can_create_editor_ctrl_function([this]() {
return m_objects_model->GetItemType(GetSelection()) & (itVolume | itObject);
auto type = m_objects_model->GetItemType(GetSelection());
return type & (itVolume | itObject | itPlate);
});
// BBS
@ -897,6 +899,20 @@ void ObjectList::update_filament_in_config(const wxDataViewItem& item)
void ObjectList::update_name_in_model(const wxDataViewItem& item) const
{
if (m_objects_model->GetItemType(item) & itPlate) {
std::string name = m_objects_model->GetName(item).ToUTF8().data();
int plate_idx = -1;
const ItemType type0 = m_objects_model->GetItemType(item, plate_idx);
if (plate_idx >= 0) {
auto plate = wxGetApp().plater()->get_partplate_list().get_plate(plate_idx);
if (plate->get_plate_name() != name) {
plate->set_plate_name(name);
m_objects_model->SetCurSelectedPlateFullName(plate_idx, name);
}
}
return;
}
const int obj_idx = m_objects_model->GetObjectIdByItem(item);
if (obj_idx < 0) return;
const int volume_id = m_objects_model->GetVolumeIdByItem(item);
@ -5482,6 +5498,22 @@ void ObjectList::ItemValueChanged(wxDataViewEvent &event)
}
}
void GUI::ObjectList::OnStartEditing(wxDataViewEvent &event)
{
auto col = event.GetColumn();
auto item = event.GetItem();
if (col == colName) {
ObjectDataViewModelNode* node = (ObjectDataViewModelNode*)item.GetID();
if (node->GetType() & itPlate) {
int plate_idx = node->GetPlateIdx();
if (plate_idx >= 0) {
auto plate = wxGetApp().plater()->get_partplate_list().get_plate(plate_idx);
m_objects_model->SetName(plate->get_plate_name(), GetSelection());
}
}
}
}
// Workaround for entering the column editing mode on Windows. Simulate keyboard enter when another column of the active line is selected.
// Here the last active column is forgotten, so when leaving the editing mode, the next mouse click will not enter the editing mode of the newly selected column.
void ObjectList::OnEditingStarted(wxDataViewEvent &event)