diff options
author | Federico Guerinoni <guerinoni.federico@gmail.com> | 2021-05-22 14:14:49 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-23 19:00:11 +0100 |
commit | 935c7b2f4b1299aceec32e7e5123f2f014cc6710 (patch) | |
tree | d54a997b05ad5fa55ecba2cb71d382d37ea6ee93 /Userland | |
parent | 26a7356e90a1717b7259510e13af906c7bb09c43 (diff) | |
download | serenity-935c7b2f4b1299aceec32e7e5123f2f014cc6710.zip |
HackStudio: Add TODO entries widget
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/DevTools/HackStudio/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/HackStudioWidget.cpp | 6 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/HackStudioWidget.h | 2 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/ToDoEntriesWidget.cpp | 96 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/ToDoEntriesWidget.h | 29 |
5 files changed, 134 insertions, 0 deletions
diff --git a/Userland/DevTools/HackStudio/CMakeLists.txt b/Userland/DevTools/HackStudio/CMakeLists.txt index 5d27af90ef..a4e8040c19 100644 --- a/Userland/DevTools/HackStudio/CMakeLists.txt +++ b/Userland/DevTools/HackStudio/CMakeLists.txt @@ -44,6 +44,7 @@ set(SOURCES ProjectTemplate.cpp TerminalWrapper.cpp ToDoEntries.cpp + ToDoEntriesWidget.cpp main.cpp ) diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index e4df70c9f1..3d6a35143a 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -22,6 +22,7 @@ #include "Project.h" #include "ProjectDeclarations.h" #include "TerminalWrapper.h" +#include "ToDoEntries.h" #include <AK/LexicalPath.h> #include <AK/StringBuilder.h> #include <Kernel/API/InodeWatcherEvent.h> @@ -867,6 +868,7 @@ void HackStudioWidget::create_action_tab(GUI::Widget& parent) }; m_find_in_files_widget = m_action_tab_widget->add_tab<FindInFilesWidget>("Find in files"); + m_todo_entries_widget = m_action_tab_widget->add_tab<ToDoEntriesWidget>("TODO"); m_terminal_wrapper = m_action_tab_widget->add_tab<TerminalWrapper>("Build", false); m_debug_info_widget = m_action_tab_widget->add_tab<DebugInfoWidget>("Debug"); m_disassembly_widget = m_action_tab_widget->add_tab<DisassemblyWidget>("Disassembly"); @@ -875,6 +877,10 @@ void HackStudioWidget::create_action_tab(GUI::Widget& parent) m_diff_viewer->set_content(original_content, diff); set_edit_mode(EditMode::Diff); }); + + ToDoEntries::the().on_update = [this]() { + m_todo_entries_widget->refresh(); + }; } void HackStudioWidget::create_project_tab(GUI::Widget& parent) diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h index 37f11fa227..86e56596f0 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.h +++ b/Userland/DevTools/HackStudio/HackStudioWidget.h @@ -19,6 +19,7 @@ #include "Project.h" #include "ProjectFile.h" #include "TerminalWrapper.h" +#include "ToDoEntriesWidget.h" #include <LibGUI/ActionGroup.h> #include <LibGUI/Scrollbar.h> #include <LibGUI/Splitter.h> @@ -143,6 +144,7 @@ private: RefPtr<TerminalWrapper> m_terminal_wrapper; RefPtr<Locator> m_locator; RefPtr<FindInFilesWidget> m_find_in_files_widget; + RefPtr<ToDoEntriesWidget> m_todo_entries_widget; RefPtr<DebugInfoWidget> m_debug_info_widget; RefPtr<DisassemblyWidget> m_disassembly_widget; RefPtr<Threading::Thread> m_debugger_thread; diff --git a/Userland/DevTools/HackStudio/ToDoEntriesWidget.cpp b/Userland/DevTools/HackStudio/ToDoEntriesWidget.cpp new file mode 100644 index 0000000000..ff7a3f119f --- /dev/null +++ b/Userland/DevTools/HackStudio/ToDoEntriesWidget.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2021, Federico Guerinoni <guerinoni.federico@gmail.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "ToDoEntriesWidget.h" +#include "HackStudio.h" +#include "Project.h" +#include "ToDoEntries.h" +#include <AK/StringBuilder.h> +#include <LibGUI/BoxLayout.h> +#include <LibGUI/Button.h> +#include <LibGUI/TableView.h> +#include <LibGUI/TextBox.h> +#include <LibGfx/FontDatabase.h> + +namespace HackStudio { + +class ToDoEntriesModel final : public GUI::Model { +public: + enum Column { + Filename, + Text, + __Count + }; + + explicit ToDoEntriesModel(const Vector<ToDoEntryPair>&& matches) + : m_matches(move(matches)) + { + } + + virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_matches.size(); } + virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; } + + virtual String column_name(int column) const override + { + switch (column) { + case Column::Filename: + return "Filename"; + case Column::Text: + return "Text"; + default: + VERIFY_NOT_REACHED(); + } + } + + virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override + { + if (role == GUI::ModelRole::TextAlignment) + return Gfx::TextAlignment::CenterLeft; + if (role == GUI::ModelRole::Font) { + if (index.column() == Column::Text) + return Gfx::FontDatabase::default_fixed_width_font(); + return {}; + } + if (role == GUI::ModelRole::Display) { + auto& match = m_matches.at(index.row()); + switch (index.column()) { + case Column::Filename: + return match.filename; + case Column::Text: + return match.comment; + } + } + return {}; + } + + virtual void update() override { } + virtual GUI::ModelIndex index(int row, int column = 0, const GUI::ModelIndex& = GUI::ModelIndex()) const override + { + if (row < 0 || row >= (int)m_matches.size()) + return {}; + if (column < 0 || column >= Column::__Count) + return {}; + return create_index(row, column, &m_matches.at(row)); + } + +private: + Vector<ToDoEntryPair> m_matches; +}; + +void ToDoEntriesWidget::refresh() +{ + const auto& entries = ToDoEntries::the().get_entries(); + auto results_model = adopt_ref(*new ToDoEntriesModel(move(entries))); + m_result_view->set_model(results_model); +} + +ToDoEntriesWidget::ToDoEntriesWidget() +{ + set_layout<GUI::VerticalBoxLayout>(); + m_result_view = add<GUI::TableView>(); +} + +} diff --git a/Userland/DevTools/HackStudio/ToDoEntriesWidget.h b/Userland/DevTools/HackStudio/ToDoEntriesWidget.h new file mode 100644 index 0000000000..ca252fd924 --- /dev/null +++ b/Userland/DevTools/HackStudio/ToDoEntriesWidget.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021, Federico Guerinoni <guerinoni.federico@gmail.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibGUI/Button.h> +#include <LibGUI/TableView.h> +#include <LibGUI/TextBox.h> +#include <LibGUI/Widget.h> + +namespace HackStudio { + +class ToDoEntriesWidget final : public GUI::Widget { + C_OBJECT(ToDoEntriesWidget) +public: + virtual ~ToDoEntriesWidget() override { } + + void refresh(); + +private: + explicit ToDoEntriesWidget(); + + RefPtr<GUI::TableView> m_result_view; +}; + +} |