2020-09-20 14:56:02 -03:00
|
|
|
/*
|
2022-02-26 14:50:04 -03:00
|
|
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
2020-09-20 14:56:02 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-20 14:56:02 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-05-14 11:09:24 -03:00
|
|
|
#include <LibCodeComprehension/Types.h>
|
2020-12-30 07:25:06 -03:00
|
|
|
#include <LibGUI/Forward.h>
|
2021-10-28 01:13:49 -03:00
|
|
|
#include <LibGUI/Label.h>
|
2021-10-28 02:46:05 -03:00
|
|
|
#include <LibGUI/TableView.h>
|
2020-12-30 07:25:06 -03:00
|
|
|
#include <LibGUI/TextEditor.h>
|
|
|
|
|
#include <LibGUI/Window.h>
|
2021-02-27 04:31:05 -03:00
|
|
|
#include <LibIPC/Decoder.h>
|
2020-09-20 14:56:02 -03:00
|
|
|
|
2020-12-30 07:25:06 -03:00
|
|
|
namespace GUI {
|
2020-09-20 14:56:02 -03:00
|
|
|
|
2020-12-30 07:25:06 -03:00
|
|
|
class AutocompleteProvider {
|
|
|
|
|
AK_MAKE_NONCOPYABLE(AutocompleteProvider);
|
|
|
|
|
AK_MAKE_NONMOVABLE(AutocompleteProvider);
|
2020-10-03 10:00:16 -03:00
|
|
|
|
2020-09-20 14:56:02 -03:00
|
|
|
public:
|
2022-02-26 14:50:04 -03:00
|
|
|
virtual ~AutocompleteProvider() = default;
|
2020-09-20 14:56:02 -03:00
|
|
|
|
2022-05-14 11:09:24 -03:00
|
|
|
virtual void provide_completions(Function<void(Vector<CodeComprehension::AutocompleteResultEntry>)>) = 0;
|
2022-02-05 15:31:33 -03:00
|
|
|
|
2020-12-30 07:25:06 -03:00
|
|
|
void attach(TextEditor& editor)
|
|
|
|
|
{
|
2021-02-23 16:42:32 -03:00
|
|
|
VERIFY(!m_editor);
|
2020-12-30 07:25:06 -03:00
|
|
|
m_editor = editor;
|
|
|
|
|
}
|
|
|
|
|
void detach() { m_editor.clear(); }
|
|
|
|
|
|
|
|
|
|
protected:
|
2022-02-26 14:50:04 -03:00
|
|
|
AutocompleteProvider() = default;
|
2020-12-30 07:25:06 -03:00
|
|
|
|
|
|
|
|
WeakPtr<TextEditor> m_editor;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class AutocompleteBox final {
|
|
|
|
|
public:
|
|
|
|
|
explicit AutocompleteBox(TextEditor&);
|
2022-02-26 14:50:04 -03:00
|
|
|
~AutocompleteBox() = default;
|
2020-12-30 07:25:06 -03:00
|
|
|
|
2022-05-14 11:09:24 -03:00
|
|
|
void update_suggestions(Vector<CodeComprehension::AutocompleteResultEntry>&& suggestions);
|
2020-12-30 07:25:06 -03:00
|
|
|
bool is_visible() const;
|
2021-03-27 12:27:08 -03:00
|
|
|
void show(Gfx::IntPoint suggestion_box_location);
|
2020-09-20 14:56:02 -03:00
|
|
|
void close();
|
|
|
|
|
|
2021-10-28 02:46:45 -03:00
|
|
|
bool has_suggestions() { return m_suggestion_view->model()->row_count() > 0; }
|
2020-09-20 14:56:02 -03:00
|
|
|
void next_suggestion();
|
|
|
|
|
void previous_suggestion();
|
2022-05-14 11:09:24 -03:00
|
|
|
CodeComprehension::AutocompleteResultEntry::HideAutocompleteAfterApplying apply_suggestion();
|
2020-09-20 14:56:02 -03:00
|
|
|
|
|
|
|
|
private:
|
2020-12-30 07:25:06 -03:00
|
|
|
WeakPtr<TextEditor> m_editor;
|
2020-09-20 14:56:02 -03:00
|
|
|
RefPtr<GUI::Window> m_popup_window;
|
|
|
|
|
RefPtr<GUI::TableView> m_suggestion_view;
|
2021-10-28 01:13:49 -03:00
|
|
|
RefPtr<GUI::Label> m_no_suggestions_view;
|
2020-09-20 14:56:02 -03:00
|
|
|
};
|
|
|
|
|
}
|