Save edited object/part's name to the object model
This commit is contained in:
parent
e1e4bf74ba
commit
416f220c36
@ -75,6 +75,8 @@ 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_EDITING_DONE, &ObjectList::OnEditingDone, this);
|
||||
|
||||
Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &ObjectList::ItemValueChanged, this);
|
||||
|
||||
Bind(wxCUSTOMEVT_LAST_VOLUME_IS_DELETED, [this](wxCommandEvent& e) { last_volume_is_deleted(e.GetInt()); });
|
||||
@ -290,6 +292,21 @@ void ObjectList::update_extruder_in_config(const wxDataViewItem& item)
|
||||
wxGetApp().plater()->update();
|
||||
}
|
||||
|
||||
void ObjectList::update_name_in_model(const wxDataViewItem& item)
|
||||
{
|
||||
const int obj_idx = m_objects_model->GetObjectIdByItem(item);
|
||||
if (obj_idx < 0) return;
|
||||
|
||||
if (m_objects_model->GetParent(item) == wxDataViewItem(0)) {
|
||||
(*m_objects)[obj_idx]->name = m_objects_model->GetName(item).ToStdString();
|
||||
return;
|
||||
}
|
||||
|
||||
const int volume_id = m_objects_model->GetVolumeIdByItem(item);
|
||||
if (volume_id < 0) return;
|
||||
(*m_objects)[obj_idx]->volumes[volume_id]->name = m_objects_model->GetName(item).ToStdString();
|
||||
}
|
||||
|
||||
void ObjectList::init_icons()
|
||||
{
|
||||
m_bmp_modifiermesh = wxBitmap(from_u8(var("lambda.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("plugin.png")), wxBITMAP_TYPE_PNG);
|
||||
@ -452,10 +469,10 @@ void ObjectList::OnDropPossible(wxDataViewEvent &event)
|
||||
wxDataViewItem item(event.GetItem());
|
||||
|
||||
// only allow drags for item or background, not containers
|
||||
if (item.IsOk() &&
|
||||
(m_objects_model->GetParent(item) == wxDataViewItem(0) ||
|
||||
if (!item.IsOk() ||
|
||||
m_objects_model->GetParent(item) == wxDataViewItem(0) ||
|
||||
m_objects_model->GetItemType(item) != itVolume ||
|
||||
m_dragged_data.obj_idx() != m_objects_model->GetObjectIdByItem(item)))
|
||||
m_dragged_data.obj_idx() != m_objects_model->GetObjectIdByItem(item))
|
||||
event.Veto();
|
||||
}
|
||||
|
||||
@ -463,9 +480,9 @@ void ObjectList::OnDrop(wxDataViewEvent &event)
|
||||
{
|
||||
wxDataViewItem item(event.GetItem());
|
||||
|
||||
if (item.IsOk() && ( m_objects_model->GetParent(item) == wxDataViewItem(0) ||
|
||||
m_objects_model->GetItemType(item) != itVolume) ||
|
||||
m_dragged_data.obj_idx() != m_objects_model->GetObjectIdByItem(item)) {
|
||||
if (!item.IsOk() || m_objects_model->GetParent(item) == wxDataViewItem(0) ||
|
||||
m_objects_model->GetItemType(item) != itVolume ||
|
||||
m_dragged_data.obj_idx() != m_objects_model->GetObjectIdByItem(item)) {
|
||||
event.Veto();
|
||||
m_dragged_data.clear();
|
||||
return;
|
||||
@ -1664,7 +1681,22 @@ void ObjectList::update_settings_items()
|
||||
|
||||
void ObjectList::ItemValueChanged(wxDataViewEvent &event)
|
||||
{
|
||||
update_extruder_in_config(event.GetItem());
|
||||
if (event.GetColumn() == 0)
|
||||
update_name_in_model(event.GetItem());
|
||||
else if (event.GetColumn() == 1)
|
||||
update_extruder_in_config(event.GetItem());
|
||||
}
|
||||
|
||||
void ObjectList::OnEditingDone(wxDataViewEvent &event)
|
||||
{
|
||||
if (event.GetColumn() != 0)
|
||||
return;
|
||||
|
||||
const auto renderer = dynamic_cast<PrusaBitmapTextRenderer*>(GetColumn(0)->GetRenderer());
|
||||
|
||||
if (renderer->WasCanceled())
|
||||
show_error(this, _(L("The supplied name is not valid;")) + "\n" +
|
||||
_(L("the following characters are not allowed:")) + " <>:/\\|?*\"");
|
||||
}
|
||||
|
||||
} //namespace GUI
|
||||
|
@ -128,6 +128,8 @@ public:
|
||||
void set_extruder_column_hidden(const bool hide) const;
|
||||
// update extruder in current config
|
||||
void update_extruder_in_config(const wxDataViewItem& item);
|
||||
// update changed name in the object model
|
||||
void update_name_in_model(const wxDataViewItem& item);
|
||||
void update_extruder_values_for_items(const int max_extruder);
|
||||
|
||||
void init_icons();
|
||||
@ -227,6 +229,7 @@ private:
|
||||
void OnDrop(wxDataViewEvent &event);
|
||||
|
||||
void ItemValueChanged(wxDataViewEvent &event);
|
||||
void OnEditingDone(wxDataViewEvent &event);
|
||||
};
|
||||
|
||||
|
||||
|
@ -1292,6 +1292,7 @@ wxWindow* PrusaBitmapTextRenderer::CreateEditorCtrl(wxWindow* parent, wxRect lab
|
||||
PrusaDataViewBitmapText data;
|
||||
data << value;
|
||||
m_bmp_from_editing_item = data.GetBitmap();
|
||||
m_was_unusable_symbol = false;
|
||||
|
||||
wxPoint position = labelRect.GetPosition();
|
||||
if (m_bmp_from_editing_item.IsOk()) {
|
||||
@ -1310,9 +1311,18 @@ wxWindow* PrusaBitmapTextRenderer::CreateEditorCtrl(wxWindow* parent, wxRect lab
|
||||
bool PrusaBitmapTextRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& value)
|
||||
{
|
||||
wxTextCtrl* text_editor = wxDynamicCast(ctrl, wxTextCtrl);
|
||||
if (!text_editor)
|
||||
if (!text_editor || text_editor->GetValue().IsEmpty())
|
||||
return false;
|
||||
|
||||
std::string chosen_name = Slic3r::normalize_utf8_nfc(text_editor->GetValue().ToUTF8());
|
||||
const char* unusable_symbols = "<>:/\\|?*\"";
|
||||
for (size_t i = 0; i < std::strlen(unusable_symbols); i++) {
|
||||
if (chosen_name.find_first_of(unusable_symbols[i]) != std::string::npos) {
|
||||
m_was_unusable_symbol = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
value << PrusaDataViewBitmapText(text_editor->GetValue(), m_bmp_from_editing_item);
|
||||
return true;
|
||||
}
|
||||
|
@ -538,10 +538,12 @@ public:
|
||||
const wxVariant& value) override;
|
||||
bool GetValueFromEditorCtrl( wxWindow* ctrl,
|
||||
wxVariant& value) override;
|
||||
bool WasCanceled() const { return m_was_unusable_symbol; }
|
||||
|
||||
private:
|
||||
PrusaDataViewBitmapText m_value;
|
||||
wxBitmap m_bmp_from_editing_item;
|
||||
bool m_was_unusable_symbol;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user