Ver código fonte

HackStudio: Remove FindWidget

HackStudio editors now have built-in incremental search
thankyouverycool 2 anos atrás
pai
commit
ed196fc265

+ 0 - 3
Userland/DevTools/HackStudio/CMakeLists.txt

@@ -10,7 +10,6 @@ add_subdirectory(LanguageClients)
 
 compile_gml(Dialogs/NewProjectDialog.gml Dialogs/NewProjectDialogGML.h new_project_dialog_gml)
 compile_gml(Dialogs/Git/GitCommitDialog.gml Dialogs/Git/GitCommitDialogGML.h git_commit_dialog_gml)
-compile_gml(FindWidget.gml FindWidgetGML.h find_widget_gml)
 
 set(SOURCES
     CodeDocument.cpp
@@ -28,7 +27,6 @@ set(SOURCES
     Editor.cpp
     EditorWrapper.cpp
     FindInFilesWidget.cpp
-    FindWidget.cpp
     Git/DiffViewer.cpp
     Git/GitFilesModel.cpp
     Git/GitFilesView.cpp
@@ -54,7 +52,6 @@ set(SOURCES
 set(GENERATED_SOURCES
     Dialogs/Git/GitCommitDialogGML.h
     Dialogs/NewProjectDialogGML.h
-    FindWidgetGML.h
 )
 
 serenity_app(HackStudio ICON app-hack-studio)

+ 0 - 9
Userland/DevTools/HackStudio/EditorWrapper.cpp

@@ -25,7 +25,6 @@ EditorWrapper::EditorWrapper()
 
     // FIXME: Propagate errors instead of giving up
     m_editor = MUST(Editor::try_create());
-    m_find_widget = add<FindWidget>(*m_editor);
 
     add_child(*m_editor);
     m_editor->set_ruler_visible(true);
@@ -126,12 +125,4 @@ void EditorWrapper::set_debug_mode(bool enabled)
     m_editor->set_debug_mode(enabled);
 }
 
-void EditorWrapper::search_action()
-{
-    if (m_find_widget->visible())
-        m_find_widget->hide();
-    else
-        m_find_widget->show();
-}
-
 }

+ 0 - 5
Userland/DevTools/HackStudio/EditorWrapper.h

@@ -8,7 +8,6 @@
 #pragma once
 
 #include "Debugger/BreakpointCallback.h"
-#include "FindWidget.h"
 #include "Git/GitRepo.h"
 #include "LanguageClient.h"
 #include <AK/Function.h>
@@ -53,9 +52,6 @@ public:
     Function<void()> on_change;
     Function<void(EditorWrapper&)> on_tab_close_request;
 
-    void search_action();
-    FindWidget const& find_widget() const { return *m_find_widget; }
-
 private:
     static constexpr auto untitled_label = "(Untitled)"sv;
 
@@ -66,7 +62,6 @@ private:
     String m_filename;
     String m_filename_title;
     RefPtr<Editor> m_editor;
-    RefPtr<FindWidget> m_find_widget;
 
     Optional<String> m_project_root;
     RefPtr<GitRepo> m_git_repo;

+ 0 - 87
Userland/DevTools/HackStudio/FindWidget.cpp

@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2022, Itamar S. <itamar8910@gmail.com>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include "FindWidget.h"
-#include "Editor.h"
-#include <AK/QuickSort.h>
-#include <DevTools/HackStudio/FindWidgetGML.h>
-#include <LibGUI/BoxLayout.h>
-#include <LibGfx/Palette.h>
-
-namespace HackStudio {
-
-FindWidget::FindWidget(NonnullRefPtr<Editor> editor)
-    : m_editor(move(editor))
-{
-    load_from_gml(find_widget_gml);
-    set_fixed_height(widget_height);
-    m_input_field = find_descendant_of_type_named<GUI::TextBox>("input_field");
-    m_index_label = find_descendant_of_type_named<GUI::Label>("index_label");
-    m_next = find_descendant_of_type_named<GUI::Button>("next");
-    m_previous = find_descendant_of_type_named<GUI::Button>("previous");
-
-    VERIFY(m_input_field);
-    VERIFY(m_next);
-    VERIFY(m_previous);
-
-    m_next->on_click = [this](auto) {
-        find_next(GUI::TextEditor::SearchDirection::Forward);
-    };
-    m_previous->on_click = [this](auto) {
-        find_next(GUI::TextEditor::SearchDirection::Backward);
-    };
-
-    m_input_field->on_change = [this]() {
-        m_editor->reset_search_results();
-        find_next(GUI::TextEditor::SearchDirection::Forward);
-    };
-
-    m_input_field->on_return_pressed = [this]() {
-        find_next(GUI::TextEditor::SearchDirection::Forward);
-    };
-
-    m_input_field->on_escape_pressed = [this]() {
-        hide();
-    };
-}
-
-void FindWidget::show()
-{
-    set_visible(true);
-    set_focus(true);
-    m_input_field->set_focus(true);
-    // Adjust scroll value to smooth the appearance of the FindWidget.
-    m_editor->vertical_scrollbar().set_value(m_editor->vertical_scrollbar().value() + widget_height, GUI::AllowCallback::Yes, GUI::Scrollbar::DoClamp::No);
-    m_visible = !m_visible;
-}
-
-void FindWidget::hide()
-{
-    set_visible(false);
-    set_focus(false);
-    m_visible = !m_visible;
-    m_editor->vertical_scrollbar().set_value(m_editor->vertical_scrollbar().value() - widget_height, GUI::AllowCallback::Yes, GUI::Scrollbar::DoClamp::No);
-    m_editor->set_focus(true);
-    m_editor->reset_search_results();
-}
-
-void FindWidget::find_next(GUI::TextEditor::SearchDirection direction)
-{
-    auto needle = m_input_field->text();
-    if (needle.is_empty()) {
-        m_editor->reset_search_results();
-        m_index_label->set_text(String::empty());
-        return;
-    }
-    auto result = m_editor->find_text(needle, direction, GUI::TextDocument::SearchShouldWrap::Yes, false, false);
-
-    if (result.is_valid())
-        m_index_label->set_text(String::formatted("{}/{}", m_editor->search_result_index().value_or(0) + 1, m_editor->search_results().size()));
-    else
-        m_index_label->set_text(String::empty());
-}
-
-}

+ 0 - 32
Userland/DevTools/HackStudio/FindWidget.gml

@@ -1,32 +0,0 @@
-@GUI::Widget {
-    name: "find_widget"
-    fill_with_background_color: true
-    shrink_to_fit: true
-    visible: false
-    layout: @GUI::HorizontalBoxLayout {
-        margins: [0, 0]
-    }
-
-    @GUI::TextBox {
-        name: "input_field"
-        max_width: 250
-    }
-
-    @GUI::Label {
-        name: "index_label"
-        max_width: 30
-        text: ""
-    }
-
-    @GUI::Button {
-        name: "next"
-        icon: "/res/icons/16x16/go-down.png"
-        max_width: 15
-    }
-
-    @GUI::Button {
-        name: "previous"
-        icon: "/res/icons/16x16/go-up.png"
-        max_width: 15
-    }
-}

+ 0 - 44
Userland/DevTools/HackStudio/FindWidget.h

@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2022, Itamar S. <itamar8910@gmail.com>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include "Editor.h"
-#include <LibGUI/Button.h>
-#include <LibGUI/TextBox.h>
-#include <LibGUI/Widget.h>
-#include <LibGUI/Window.h>
-
-namespace HackStudio {
-
-class Editor;
-class EditorWrapper;
-
-class FindWidget final : public GUI::Widget {
-    C_OBJECT(FindWidget)
-public:
-    ~FindWidget() = default;
-
-    void show();
-    void hide();
-    bool visible() const { return m_visible; }
-
-private:
-    FindWidget(NonnullRefPtr<Editor>);
-
-    void find_next(GUI::TextEditor::SearchDirection);
-
-    static constexpr auto widget_height = 25;
-
-    NonnullRefPtr<Editor> m_editor;
-    RefPtr<GUI::TextBox> m_input_field;
-    RefPtr<GUI::Label> m_index_label;
-    RefPtr<GUI::Button> m_next;
-    RefPtr<GUI::Button> m_previous;
-    bool m_visible { false };
-};
-
-}

+ 0 - 5
Userland/DevTools/HackStudio/HackStudioWidget.cpp

@@ -1509,11 +1509,6 @@ void HackStudioWidget::create_view_menu(GUI::Window& window)
     view_menu.add_action(*m_locations_history_back_action);
     view_menu.add_action(*m_locations_history_forward_action);
 
-    auto search_action = GUI::Action::create("&Search", { Mod_Ctrl, Key_F }, [this](auto&) {
-        current_editor_wrapper().search_action();
-    });
-    view_menu.add_action(search_action);
-
     view_menu.add_separator();
 
     view_menu.add_action(GUI::CommonActions::make_fullscreen_action([&](auto&) {