瀏覽代碼

Hackstudio: Use `GUI::TextEditor' actions for cut/copy/paste buttons

This fixes a bug where hackstudio's language server will crash upon
clicking the 'cut' button when no text is selected.  This was because
the actions were not disabled on empty selection.

We now disable the actions depending on if there is empty selection
inside current tab. We update the cut/copy/paste buttons' actions when
changing tabs.
Aayush 2 年之前
父節點
當前提交
bc1293925a
共有 2 個文件被更改,包括 17 次插入3 次删除
  1. 11 3
      Userland/DevTools/HackStudio/HackStudioWidget.cpp
  2. 6 0
      Userland/DevTools/HackStudio/HackStudioWidget.h

+ 11 - 3
Userland/DevTools/HackStudio/HackStudioWidget.cpp

@@ -1171,6 +1171,7 @@ void HackStudioWidget::set_current_editor_wrapper(RefPtr<EditorWrapper> editor_w
     update_window_title();
     update_window_title();
     update_current_editor_title();
     update_current_editor_title();
     update_tree_view();
     update_tree_view();
+    update_toolbar_actions();
     set_current_editor_tab_widget(static_cast<GUI::TabWidget*>(m_current_editor_wrapper->parent()));
     set_current_editor_tab_widget(static_cast<GUI::TabWidget*>(m_current_editor_wrapper->parent()));
     m_current_editor_tab_widget->set_active_widget(editor_wrapper);
     m_current_editor_tab_widget->set_active_widget(editor_wrapper);
     update_statusbar();
     update_statusbar();
@@ -1263,9 +1264,9 @@ void HackStudioWidget::create_toolbar(GUI::Widget& parent)
     toolbar.add_action(*m_delete_action);
     toolbar.add_action(*m_delete_action);
     toolbar.add_separator();
     toolbar.add_separator();
 
 
-    toolbar.add_action(GUI::CommonActions::make_cut_action([this](auto&) { current_editor().cut_action().activate(); }, m_editors_splitter));
-    toolbar.add_action(GUI::CommonActions::make_copy_action([this](auto&) { current_editor().copy_action().activate(); }, m_editors_splitter));
-    toolbar.add_action(GUI::CommonActions::make_paste_action([this](auto&) { current_editor().paste_action().activate(); }, m_editors_splitter));
+    m_cut_button = toolbar.add_action(current_editor().cut_action());
+    m_copy_button = toolbar.add_action(current_editor().copy_action());
+    m_paste_button = toolbar.add_action(current_editor().paste_action());
     toolbar.add_separator();
     toolbar.add_separator();
     toolbar.add_action(GUI::CommonActions::make_undo_action([this](auto&) { current_editor().undo_action().activate(); }, m_editors_splitter));
     toolbar.add_action(GUI::CommonActions::make_undo_action([this](auto&) { current_editor().undo_action().activate(); }, m_editors_splitter));
     toolbar.add_action(GUI::CommonActions::make_redo_action([this](auto&) { current_editor().redo_action().activate(); }, m_editors_splitter));
     toolbar.add_action(GUI::CommonActions::make_redo_action([this](auto&) { current_editor().redo_action().activate(); }, m_editors_splitter));
@@ -1653,6 +1654,13 @@ void HackStudioWidget::update_tree_view()
     }
     }
 }
 }
 
 
+void HackStudioWidget::update_toolbar_actions()
+{
+    m_copy_button->set_action(current_editor().copy_action());
+    m_paste_button->set_action(current_editor().paste_action());
+    m_cut_button->set_action(current_editor().cut_action());
+}
+
 void HackStudioWidget::update_window_title()
 void HackStudioWidget::update_window_title()
 {
 {
     window()->set_title(DeprecatedString::formatted("{} - {} - Hack Studio", m_current_editor_wrapper->filename_title(), m_project->name()));
     window()->set_title(DeprecatedString::formatted("{} - {} - Hack Studio", m_current_editor_wrapper->filename_title(), m_project->name()));

+ 6 - 0
Userland/DevTools/HackStudio/HackStudioWidget.h

@@ -16,6 +16,7 @@
 #include "GMLPreviewWidget.h"
 #include "GMLPreviewWidget.h"
 #include "Git/DiffViewer.h"
 #include "Git/DiffViewer.h"
 #include "Git/GitWidget.h"
 #include "Git/GitWidget.h"
+#include "LibGUI/Button.h"
 #include "Locator.h"
 #include "Locator.h"
 #include "Project.h"
 #include "Project.h"
 #include "ProjectBuilder.h"
 #include "ProjectBuilder.h"
@@ -163,6 +164,7 @@ private:
 
 
     void update_gml_preview();
     void update_gml_preview();
     void update_tree_view();
     void update_tree_view();
+    void update_toolbar_actions();
     void on_cursor_change();
     void on_cursor_change();
     void file_renamed(DeprecatedString const& old_name, DeprecatedString const& new_name);
     void file_renamed(DeprecatedString const& old_name, DeprecatedString const& new_name);
 
 
@@ -257,6 +259,10 @@ private:
     RefPtr<GUI::Action> m_wrap_anywhere_action;
     RefPtr<GUI::Action> m_wrap_anywhere_action;
     RefPtr<GUI::Action> m_wrap_at_words_action;
     RefPtr<GUI::Action> m_wrap_at_words_action;
 
 
+    RefPtr<GUI::Button> m_cut_button;
+    RefPtr<GUI::Button> m_paste_button;
+    RefPtr<GUI::Button> m_copy_button;
+
     Mode m_mode { Mode::Code };
     Mode m_mode { Mode::Code };
     OwnPtr<Coredump::Inspector> m_coredump_inspector;
     OwnPtr<Coredump::Inspector> m_coredump_inspector;
     OwnPtr<ProjectBuilder> m_project_builder;
     OwnPtr<ProjectBuilder> m_project_builder;