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