mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 16:35:09 +00:00

Most of the models were just calling did_update anyway, which is pointless since it can be unified to the base Model class. Instead, code calling update() will now call invalidate(), which functions identically and is more obvious in what it does. Additionally, a default implementation is provided, which removes the need to add empty implementations of update() for each model subclass. Co-Authored-By: Ali Mohammad Pur <ali.mpfard@gmail.com>
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/NonnullPtrVector.h>
|
|
#include <AK/RefPtr.h>
|
|
#include <AK/WeakPtr.h>
|
|
#include <DevTools/HackStudio/ProjectTemplate.h>
|
|
#include <LibCore/FileWatcher.h>
|
|
#include <LibGUI/Model.h>
|
|
|
|
namespace HackStudio {
|
|
|
|
class ProjectTemplatesModel final : public GUI::Model {
|
|
public:
|
|
static NonnullRefPtr<ProjectTemplatesModel> create()
|
|
{
|
|
return adopt_ref(*new ProjectTemplatesModel());
|
|
}
|
|
|
|
enum Column {
|
|
Icon = 0,
|
|
Id,
|
|
Name,
|
|
__Count
|
|
};
|
|
|
|
virtual ~ProjectTemplatesModel() override;
|
|
|
|
RefPtr<ProjectTemplate> template_for_index(const GUI::ModelIndex& index);
|
|
|
|
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
|
|
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
|
|
virtual String column_name(int) const override;
|
|
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
|
|
|
void update();
|
|
void rescan_templates();
|
|
|
|
private:
|
|
explicit ProjectTemplatesModel();
|
|
|
|
NonnullRefPtrVector<ProjectTemplate> m_templates;
|
|
Vector<ProjectTemplate*> m_mapping;
|
|
|
|
RefPtr<Core::FileWatcher> m_file_watcher;
|
|
};
|
|
|
|
}
|