mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 18:24:45 -05:00
KeyboardSettings: Reuse generic GUI::ItemListModel
This change removes the manually created model class in order to use a generic GUI::ItemListModel. Besides from code reusability, it also makes the list searchable as you type.
This commit is contained in:
parent
4bad2bf100
commit
d04c8d478f
Notes:
sideshowbarker
2024-07-19 17:16:31 +09:00
Author: https://github.com/krkk Commit: https://github.com/SerenityOS/serenity/commit/d04c8d478f4 Pull-request: https://github.com/SerenityOS/serenity/pull/9576 Reviewed-by: https://github.com/alimpfard
2 changed files with 2 additions and 51 deletions
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/Model.h>
|
||||
|
||||
class CharacterMapFileListModel final : public GUI::Model {
|
||||
public:
|
||||
static NonnullRefPtr<CharacterMapFileListModel> create(Vector<String>& filenames)
|
||||
{
|
||||
return adopt_ref(*new CharacterMapFileListModel(filenames));
|
||||
}
|
||||
|
||||
virtual ~CharacterMapFileListModel() override { }
|
||||
|
||||
virtual int row_count(const GUI::ModelIndex&) const override
|
||||
{
|
||||
return m_filenames.size();
|
||||
}
|
||||
|
||||
virtual int column_count(const GUI::ModelIndex&) const override
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override
|
||||
{
|
||||
VERIFY(index.is_valid());
|
||||
VERIFY(index.column() == 0);
|
||||
|
||||
if (role == GUI::ModelRole::Display)
|
||||
return m_filenames.at(index.row());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
explicit CharacterMapFileListModel(Vector<String>& filenames)
|
||||
: m_filenames(filenames)
|
||||
{
|
||||
}
|
||||
|
||||
Vector<String>& m_filenames;
|
||||
};
|
|
@ -4,7 +4,6 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "CharacterMapFileListModel.h"
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
|
@ -16,6 +15,7 @@
|
|||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/CheckBox.h>
|
||||
#include <LibGUI/ComboBox.h>
|
||||
#include <LibGUI/ItemListModel.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/Menubar.h>
|
||||
|
@ -122,7 +122,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto& character_map_file_combo = character_map_file_selection_container.add<GUI::ComboBox>();
|
||||
character_map_file_combo.set_only_allow_values_from_model(true);
|
||||
character_map_file_combo.set_model(*CharacterMapFileListModel::create(character_map_files));
|
||||
character_map_file_combo.set_model(*GUI::ItemListModel<String>::create(character_map_files));
|
||||
character_map_file_combo.set_selected_index(initial_keymap_index);
|
||||
|
||||
auto& num_lock_checkbox = root_widget.add<GUI::CheckBox>("Enable Num Lock on login");
|
||||
|
|
Loading…
Add table
Reference in a new issue