/* * Copyright (c) 2020-2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace GUI { class AutocompleteProvider { AK_MAKE_NONCOPYABLE(AutocompleteProvider); AK_MAKE_NONMOVABLE(AutocompleteProvider); public: virtual ~AutocompleteProvider() = default; virtual void provide_completions(Function)>) = 0; void attach(TextEditor& editor) { VERIFY(!m_editor); m_editor = editor; } void detach() { m_editor.clear(); } protected: AutocompleteProvider() = default; WeakPtr m_editor; }; class AutocompleteBox final { public: explicit AutocompleteBox(TextEditor&); ~AutocompleteBox() = default; void update_suggestions(Vector&& suggestions); bool is_visible() const; void show(Gfx::IntPoint suggestion_box_location); void close(); bool has_suggestions() { return m_suggestion_view->model()->row_count() > 0; } void next_suggestion(); void previous_suggestion(); CodeComprehension::AutocompleteResultEntry::HideAutocompleteAfterApplying apply_suggestion(); private: WeakPtr m_editor; RefPtr m_popup_window; RefPtr m_suggestion_view; RefPtr m_no_suggestions_view; }; }