mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-22 06:04:01 -06:00
Extended "Delete" functions
This commit is contained in:
parent
db7c58009c
commit
5c4c912132
3 changed files with 48 additions and 12 deletions
|
@ -920,6 +920,13 @@ wxBoxSizer* content_edit_object_buttons(wxWindow* win)
|
||||||
wxString name = "Part";
|
wxString name = "Part";
|
||||||
m_objects_model->AddChild(item, name);
|
m_objects_model->AddChild(item, name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
btn_delete->Bind(wxEVT_BUTTON, [](wxEvent&)
|
||||||
|
{
|
||||||
|
auto item = m_objects_ctrl->GetSelection();
|
||||||
|
if (!item) return;
|
||||||
|
m_objects_model->Delete(item);
|
||||||
|
});
|
||||||
//***
|
//***
|
||||||
|
|
||||||
btn_move_up->SetMinSize(wxSize(20, -1));
|
btn_move_up->SetMinSize(wxSize(20, -1));
|
||||||
|
@ -1036,7 +1043,12 @@ void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer)
|
||||||
auto add_btn = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
|
auto add_btn = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
|
||||||
if (wxMSW) add_btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
if (wxMSW) add_btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||||
add_btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("add.png")), wxBITMAP_TYPE_PNG));
|
add_btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("add.png")), wxBITMAP_TYPE_PNG));
|
||||||
sizer->Add(add_btn, 0, wxALIGN_LEFT | wxLEFT, 20);
|
sizer->Add(add_btn, 0, wxALIGN_LEFT | wxLEFT | wxTOP, 20);
|
||||||
|
|
||||||
|
auto del_btn = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
|
||||||
|
if (wxMSW) del_btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||||
|
del_btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("brick_delete.png")), wxBITMAP_TYPE_PNG));
|
||||||
|
sizer->Add(del_btn, 0, wxALIGN_LEFT | wxLEFT, 20);
|
||||||
|
|
||||||
// *** Objects List ***
|
// *** Objects List ***
|
||||||
auto collpane = add_prusa_collapsible_pane(parent, sizer, "Objects List:", content_objects_list);
|
auto collpane = add_prusa_collapsible_pane(parent, sizer, "Objects List:", content_objects_list);
|
||||||
|
@ -1064,6 +1076,15 @@ void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer)
|
||||||
m_objects_model->Add(name);
|
m_objects_model->Add(name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
del_btn->Bind(wxEVT_BUTTON, [](wxEvent& )
|
||||||
|
{
|
||||||
|
auto item = m_objects_ctrl->GetSelection();
|
||||||
|
if (!item) return;
|
||||||
|
m_objects_model->Delete(item);
|
||||||
|
if (m_objects_model->IsEmpty())
|
||||||
|
m_collpane_settings->show_it(false);
|
||||||
|
});
|
||||||
|
|
||||||
// More experiments with UI
|
// More experiments with UI
|
||||||
// auto listctrl = new wxDataViewListCtrl(main_page, wxID_ANY, wxDefaultPosition, wxSize(-1, 100));
|
// auto listctrl = new wxDataViewListCtrl(main_page, wxID_ANY, wxDefaultPosition, wxSize(-1, 100));
|
||||||
// listctrl->AppendToggleColumn("Toggle");
|
// listctrl->AppendToggleColumn("Toggle");
|
||||||
|
|
|
@ -367,6 +367,15 @@ void MyObjectTreeModel::AddChild(const wxDataViewItem &parent_item, wxString &na
|
||||||
MyObjectTreeModelNode *root = (MyObjectTreeModelNode*)parent_item.GetID();
|
MyObjectTreeModelNode *root = (MyObjectTreeModelNode*)parent_item.GetID();
|
||||||
if (!root) return;
|
if (!root) return;
|
||||||
|
|
||||||
|
if (root->GetChildren().Count() == 0)
|
||||||
|
{
|
||||||
|
auto node = new MyObjectTreeModelNode(root, root->m_name);
|
||||||
|
root->Append(node);
|
||||||
|
// notify control
|
||||||
|
wxDataViewItem child((void*)node);
|
||||||
|
ItemAdded(parent_item, child);
|
||||||
|
}
|
||||||
|
|
||||||
auto node = new MyObjectTreeModelNode(root, name);
|
auto node = new MyObjectTreeModelNode(root, name);
|
||||||
root->Append(node);
|
root->Append(node);
|
||||||
// notify control
|
// notify control
|
||||||
|
@ -380,22 +389,27 @@ void MyObjectTreeModel::Delete(const wxDataViewItem &item)
|
||||||
if (!node) // happens if item.IsOk()==false
|
if (!node) // happens if item.IsOk()==false
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxDataViewItem parent(node->GetParent());
|
auto node_parent = node->GetParent();
|
||||||
if (!parent.IsOk())
|
wxDataViewItem parent(node_parent);
|
||||||
{
|
|
||||||
// wxASSERT(node == m_root);
|
|
||||||
// don't make the control completely empty:
|
|
||||||
//wxLogError("Cannot remove the root item!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// first remove the node from the parent's array of children;
|
// first remove the node from the parent's array of children;
|
||||||
// NOTE: MyObjectTreeModelNodePtrArray is only an array of _pointers_
|
// NOTE: MyObjectTreeModelNodePtrArray is only an array of _pointers_
|
||||||
// thus removing the node from it doesn't result in freeing it
|
// thus removing the node from it doesn't result in freeing it
|
||||||
node->GetParent()->GetChildren().Remove(node);
|
if (node_parent)
|
||||||
|
node_parent->GetChildren().Remove(node);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto it = m_objects.find(node);
|
||||||
|
if (it != m_objects.end())
|
||||||
|
m_objects.erase(it);
|
||||||
|
}
|
||||||
// free the node
|
// free the node
|
||||||
delete node;
|
delete node;
|
||||||
|
|
||||||
|
// set m_containet to FALSE if parent has no child
|
||||||
|
if (node_parent && node_parent->GetChildCount() == 0)
|
||||||
|
node_parent->m_container = false;
|
||||||
|
|
||||||
// notify control
|
// notify control
|
||||||
ItemDeleted(parent, item);
|
ItemDeleted(parent, item);
|
||||||
}
|
}
|
||||||
|
@ -498,7 +512,7 @@ wxDataViewItem MyObjectTreeModel::GetParent(const wxDataViewItem &item) const
|
||||||
|
|
||||||
bool MyObjectTreeModel::IsContainer(const wxDataViewItem &item) const
|
bool MyObjectTreeModel::IsContainer(const wxDataViewItem &item) const
|
||||||
{
|
{
|
||||||
// the invisble root node can have children
|
// the invisible root node can have children
|
||||||
if (!item.IsOk())
|
if (!item.IsOk())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -195,7 +195,7 @@ public:
|
||||||
m_container = true;
|
m_container = true;
|
||||||
m_children.Add(child);
|
m_children.Add(child);
|
||||||
}
|
}
|
||||||
unsigned int GetChildCount() const
|
size_t GetChildCount() const
|
||||||
{
|
{
|
||||||
return m_children.GetCount();
|
return m_children.GetCount();
|
||||||
}
|
}
|
||||||
|
@ -219,6 +219,7 @@ public:
|
||||||
void Add(wxString &name);
|
void Add(wxString &name);
|
||||||
void AddChild(const wxDataViewItem &parent_item, wxString &name);
|
void AddChild(const wxDataViewItem &parent_item, wxString &name);
|
||||||
void Delete(const wxDataViewItem &item);
|
void Delete(const wxDataViewItem &item);
|
||||||
|
bool IsEmpty() { return m_objects.empty(); }
|
||||||
|
|
||||||
// helper method for wxLog
|
// helper method for wxLog
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue