Close undo/redo windows when an item in the list is selected

This commit is contained in:
enricoturri1966 2020-03-23 16:00:56 +01:00
parent b8c4369c4f
commit c480041487
2 changed files with 25 additions and 6 deletions

View file

@ -4201,8 +4201,10 @@ static bool string_getter(const bool is_undo, int idx, const char** out_text)
return wxGetApp().plater()->undo_redo_string_getter(is_undo, idx, out_text); return wxGetApp().plater()->undo_redo_string_getter(is_undo, idx, out_text);
} }
void GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) const bool GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) const
{ {
bool action_taken = false;
ImGuiWrapper* imgui = wxGetApp().imgui(); ImGuiWrapper* imgui = wxGetApp().imgui();
const float x = pos_x * (float)get_camera().get_zoom() + 0.5f * (float)get_canvas_size().get_width(); const float x = pos_x * (float)get_camera().get_zoom() + 0.5f * (float)get_canvas_size().get_width();
@ -4223,11 +4225,16 @@ void GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) const
m_imgui_undo_redo_hovered_pos = -1; m_imgui_undo_redo_hovered_pos = -1;
if (selected >= 0) if (selected >= 0)
{
is_undo ? wxGetApp().plater()->undo_to(selected) : wxGetApp().plater()->redo_to(selected); is_undo ? wxGetApp().plater()->undo_to(selected) : wxGetApp().plater()->redo_to(selected);
action_taken = true;
}
imgui->text(wxString::Format(is_undo ? _L_PLURAL("Undo %1$d Action", "Undo %1$d Actions", hovered + 1) : _L_PLURAL("Redo %1$d Action", "Redo %1$d Actions", hovered + 1), hovered + 1)); imgui->text(wxString::Format(is_undo ? _L_PLURAL("Undo %1$d Action", "Undo %1$d Actions", hovered + 1) : _L_PLURAL("Redo %1$d Action", "Redo %1$d Actions", hovered + 1), hovered + 1));
imgui->end(); imgui->end();
return action_taken;
} }
#if ENABLE_THUMBNAIL_GENERATOR #if ENABLE_THUMBNAIL_GENERATOR
@ -4784,12 +4791,18 @@ bool GLCanvas3D::_init_undoredo_toolbar()
item.name = "undo"; item.name = "undo";
item.icon_filename = "undo_toolbar.svg"; item.icon_filename = "undo_toolbar.svg";
item.tooltip = _utf8(L("Undo")) + " [" + GUI::shortkey_ctrl_prefix() + "Z]\n" + _utf8(L("Click right mouse button to open History")); item.tooltip = _utf8(L("Undo")) + " [" + GUI::shortkey_ctrl_prefix() + "Z]\n" + _utf8(L("Click right mouse button to open/close History"));
item.sprite_id = 0; item.sprite_id = 0;
item.left.action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_UNDO)); }; item.left.action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_UNDO)); };
item.right.toggable = true; item.right.toggable = true;
item.right.action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; }; item.right.action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; };
item.right.render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(true, 0.5f * (left + right)); }; item.right.render_callback = [this](float left, float right, float, float) {
if (m_canvas != nullptr)
{
if (_render_undo_redo_stack(true, 0.5f * (left + right)))
_deactivate_undo_redo_toolbar_items();
}
};
item.enabling_callback = [this]()->bool { item.enabling_callback = [this]()->bool {
bool can_undo = wxGetApp().plater()->can_undo(); bool can_undo = wxGetApp().plater()->can_undo();
int id = m_undoredo_toolbar.get_item_id("undo"); int id = m_undoredo_toolbar.get_item_id("undo");
@ -4817,11 +4830,17 @@ bool GLCanvas3D::_init_undoredo_toolbar()
item.name = "redo"; item.name = "redo";
item.icon_filename = "redo_toolbar.svg"; item.icon_filename = "redo_toolbar.svg";
item.tooltip = _utf8(L("Redo")) + " [" + GUI::shortkey_ctrl_prefix() + "Y]\n" + _utf8(L("Click right mouse button to open History")); item.tooltip = _utf8(L("Redo")) + " [" + GUI::shortkey_ctrl_prefix() + "Y]\n" + _utf8(L("Click right mouse button to open/close History"));
item.sprite_id = 1; item.sprite_id = 1;
item.left.action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_REDO)); }; item.left.action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_REDO)); };
item.right.action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; }; item.right.action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; };
item.right.render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(false, 0.5f * (left + right)); }; item.right.render_callback = [this](float left, float right, float, float) {
if (m_canvas != nullptr)
{
if (_render_undo_redo_stack(false, 0.5f * (left + right)))
_deactivate_undo_redo_toolbar_items();
}
};
item.enabling_callback = [this]()->bool { item.enabling_callback = [this]()->bool {
bool can_redo = wxGetApp().plater()->can_redo(); bool can_redo = wxGetApp().plater()->can_redo();
int id = m_undoredo_toolbar.get_item_id("redo"); int id = m_undoredo_toolbar.get_item_id("redo");

View file

@ -743,7 +743,7 @@ private:
#endif // ENABLE_SHOW_CAMERA_TARGET #endif // ENABLE_SHOW_CAMERA_TARGET
void _render_sla_slices() const; void _render_sla_slices() const;
void _render_selection_sidebar_hints() const; void _render_selection_sidebar_hints() const;
void _render_undo_redo_stack(const bool is_undo, float pos_x) const; bool _render_undo_redo_stack(const bool is_undo, float pos_x) const;
#if ENABLE_THUMBNAIL_GENERATOR #if ENABLE_THUMBNAIL_GENERATOR
void _render_thumbnail_internal(ThumbnailData& thumbnail_data, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const; void _render_thumbnail_internal(ThumbnailData& thumbnail_data, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const;
// render thumbnail using an off-screen framebuffer // render thumbnail using an off-screen framebuffer