SQLStudio: Reset status bar and menu actions when closing a tab

This commit is contained in:
Jose Flores 2022-08-14 18:35:24 -05:00 committed by Linus Groh
parent abc150085f
commit 355911c44e
Notes: sideshowbarker 2024-07-17 07:51:17 +09:00

View file

@ -183,6 +183,7 @@ MainWidget::MainWidget()
if (close_attempt.release_value()) {
m_tab_widget->remove_tab(widget);
update_title();
on_editor_change();
}
};
@ -351,14 +352,18 @@ void MainWidget::update_title()
void MainWidget::on_editor_change()
{
auto editor = dynamic_cast<ScriptEditor*>(m_tab_widget->active_widget());
if (editor) {
update_statusbar(editor);
update_editor_actions(editor);
}
update_statusbar(editor);
update_editor_actions(editor);
}
void MainWidget::update_statusbar(ScriptEditor* editor)
{
if (!editor) {
m_statusbar->set_text(1, "");
m_statusbar->set_text(2, "");
return;
}
if (editor->has_selection()) {
auto character_count = editor->selected_text().length();
auto word_count = editor->number_of_selected_words();
@ -374,6 +379,15 @@ void MainWidget::update_statusbar(ScriptEditor* editor)
void MainWidget::update_editor_actions(ScriptEditor* editor)
{
if (!editor) {
m_copy_action->set_enabled(false);
m_cut_action->set_enabled(false);
m_paste_action->set_enabled(false);
m_undo_action->set_enabled(false);
m_redo_action->set_enabled(false);
return;
}
m_copy_action->set_enabled(editor->copy_action().is_enabled());
m_cut_action->set_enabled(editor->cut_action().is_enabled());
m_paste_action->set_enabled(editor->paste_action().is_enabled());