Serenity Operating System
at master 62 lines 1.6 kB view raw
1/* 2 * Copyright (c) 2020-2022, the SerenityOS developers. 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <LibCodeComprehension/Types.h> 10#include <LibGUI/Forward.h> 11#include <LibGUI/Label.h> 12#include <LibGUI/TableView.h> 13#include <LibGUI/TextEditor.h> 14#include <LibGUI/Window.h> 15#include <LibIPC/Decoder.h> 16 17namespace GUI { 18 19class AutocompleteProvider { 20 AK_MAKE_NONCOPYABLE(AutocompleteProvider); 21 AK_MAKE_NONMOVABLE(AutocompleteProvider); 22 23public: 24 virtual ~AutocompleteProvider() = default; 25 26 virtual void provide_completions(Function<void(Vector<CodeComprehension::AutocompleteResultEntry>)>) = 0; 27 28 void attach(TextEditor& editor) 29 { 30 VERIFY(!m_editor); 31 m_editor = editor; 32 } 33 void detach() { m_editor.clear(); } 34 35protected: 36 AutocompleteProvider() = default; 37 38 WeakPtr<TextEditor> m_editor; 39}; 40 41class AutocompleteBox final { 42public: 43 explicit AutocompleteBox(TextEditor&); 44 ~AutocompleteBox() = default; 45 46 void update_suggestions(Vector<CodeComprehension::AutocompleteResultEntry>&& suggestions); 47 bool is_visible() const; 48 void show(Gfx::IntPoint suggestion_box_location); 49 void close(); 50 51 bool has_suggestions() { return m_suggestion_view->model()->row_count() > 0; } 52 void next_suggestion(); 53 void previous_suggestion(); 54 CodeComprehension::AutocompleteResultEntry::HideAutocompleteAfterApplying apply_suggestion(); 55 56private: 57 WeakPtr<TextEditor> m_editor; 58 RefPtr<GUI::Window> m_popup_window; 59 RefPtr<GUI::TableView> m_suggestion_view; 60 RefPtr<GUI::Label> m_no_suggestions_view; 61}; 62}