mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 20:22:13 +00:00
TextEditor: Enable/disable undo & redo buttons based on availability (#740)
This commit is contained in:
parent
3e84ea9a53
commit
503fe37eaa
2 changed files with 10 additions and 2 deletions
|
@ -48,6 +48,8 @@ void GTextEditor::create_actions()
|
||||||
{
|
{
|
||||||
m_undo_action = GCommonActions::make_undo_action([&](auto&) { undo(); }, this);
|
m_undo_action = GCommonActions::make_undo_action([&](auto&) { undo(); }, this);
|
||||||
m_redo_action = GCommonActions::make_redo_action([&](auto&) { redo(); }, this);
|
m_redo_action = GCommonActions::make_redo_action([&](auto&) { redo(); }, this);
|
||||||
|
m_undo_action->set_enabled(false);
|
||||||
|
m_redo_action->set_enabled(false);
|
||||||
m_cut_action = GCommonActions::make_cut_action([&](auto&) { cut(); }, this);
|
m_cut_action = GCommonActions::make_cut_action([&](auto&) { cut(); }, this);
|
||||||
m_copy_action = GCommonActions::make_copy_action([&](auto&) { copy(); }, this);
|
m_copy_action = GCommonActions::make_copy_action([&](auto&) { copy(); }, this);
|
||||||
m_paste_action = GCommonActions::make_paste_action([&](auto&) { paste(); }, this);
|
m_paste_action = GCommonActions::make_paste_action([&](auto&) { paste(); }, this);
|
||||||
|
@ -469,7 +471,7 @@ void GTextEditor::select_all()
|
||||||
|
|
||||||
void GTextEditor::undo()
|
void GTextEditor::undo()
|
||||||
{
|
{
|
||||||
if (m_undo_stack_index >= m_undo_stack.size() || m_undo_stack.is_empty())
|
if (!can_undo())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& undo_container = m_undo_stack[m_undo_stack_index];
|
auto& undo_container = m_undo_stack[m_undo_stack_index];
|
||||||
|
@ -488,11 +490,12 @@ void GTextEditor::undo()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_undo_stack_index++;
|
m_undo_stack_index++;
|
||||||
|
did_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::redo()
|
void GTextEditor::redo()
|
||||||
{
|
{
|
||||||
if (m_undo_stack_index <= 0 || m_undo_stack.is_empty())
|
if (!can_redo())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& undo_container = m_undo_stack[m_undo_stack_index - 1];
|
auto& undo_container = m_undo_stack[m_undo_stack_index - 1];
|
||||||
|
@ -504,6 +507,7 @@ void GTextEditor::redo()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_undo_stack_index--;
|
m_undo_stack_index--;
|
||||||
|
did_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::get_selection_line_boundaries(int& first_line, int& last_line)
|
void GTextEditor::get_selection_line_boundaries(int& first_line, int& last_line)
|
||||||
|
@ -1293,6 +1297,8 @@ void GTextEditor::did_change()
|
||||||
ASSERT(!is_readonly());
|
ASSERT(!is_readonly());
|
||||||
update_content_size();
|
update_content_size();
|
||||||
recompute_all_visual_lines();
|
recompute_all_visual_lines();
|
||||||
|
m_undo_action->set_enabled(can_undo());
|
||||||
|
m_redo_action->set_enabled(can_redo());
|
||||||
if (!m_has_pending_change_notification) {
|
if (!m_has_pending_change_notification) {
|
||||||
m_has_pending_change_notification = true;
|
m_has_pending_change_notification = true;
|
||||||
deferred_invoke([this](auto&) {
|
deferred_invoke([this](auto&) {
|
||||||
|
|
|
@ -69,6 +69,8 @@ public:
|
||||||
bool has_selection() const { return m_selection.is_valid(); }
|
bool has_selection() const { return m_selection.is_valid(); }
|
||||||
String selected_text() const;
|
String selected_text() const;
|
||||||
void set_selection(const GTextRange&);
|
void set_selection(const GTextRange&);
|
||||||
|
bool can_undo() const { return m_undo_stack_index < m_undo_stack.size() && !m_undo_stack.is_empty(); }
|
||||||
|
bool can_redo() const { return m_undo_stack_index > 0 && m_undo_stack[m_undo_stack_index - 1].m_undo_vector.size() > 0 && !m_undo_stack.is_empty(); }
|
||||||
|
|
||||||
String text() const;
|
String text() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue