mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:57:45 +00:00
Spreadsheet: Change paste action's enabled state on clipboard change
Previously, the paste action was always enabled and always assumed that anything was selected, which led to a crash by clicking the paste action right after the application startup. This patch will automatically enable/disable the paste action depending on whether a selection exists (it usually does, except on the app launch and after adding a new tab) and if the clipboard mime type is a text/ group. So no, you can't paste an image into the app anymore, even though this mostly froze the app before...
This commit is contained in:
parent
7ba2e5e3e7
commit
35934acbd3
2 changed files with 17 additions and 1 deletions
|
@ -245,6 +245,7 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe
|
|||
|
||||
m_cut_action->set_enabled(false);
|
||||
m_copy_action->set_enabled(false);
|
||||
m_paste_action->set_enabled(false);
|
||||
|
||||
m_tab_widget->on_change = [this](auto& selected_widget) {
|
||||
// for keyboard shortcuts and command palette
|
||||
|
@ -269,6 +270,12 @@ void SpreadsheetWidget::resize_event(GUI::ResizeEvent& event)
|
|||
m_inline_documentation_window->set_rect(m_cell_value_editor->screen_relative_rect().translated(0, m_cell_value_editor->height() + 7).inflated(6, 6));
|
||||
}
|
||||
|
||||
void SpreadsheetWidget::clipboard_content_did_change(String const& mime_type)
|
||||
{
|
||||
if (auto* sheet = current_worksheet_if_available())
|
||||
m_paste_action->set_enabled(!sheet->selected_cells().is_empty() && mime_type.starts_with("text/"));
|
||||
}
|
||||
|
||||
void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
|
||||
{
|
||||
for (auto& sheet : new_sheets) {
|
||||
|
@ -286,6 +293,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
|
|||
VERIFY(!selection.is_empty());
|
||||
m_cut_action->set_enabled(true);
|
||||
m_copy_action->set_enabled(true);
|
||||
m_paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type().starts_with("text/"));
|
||||
m_current_cell_label->set_enabled(true);
|
||||
m_cell_value_editor->set_enabled(true);
|
||||
|
||||
|
@ -353,6 +361,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
|
|||
|
||||
m_cut_action->set_enabled(false);
|
||||
m_copy_action->set_enabled(false);
|
||||
m_paste_action->set_enabled(false);
|
||||
|
||||
static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(nullptr);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue