mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-26 04:35:41 +03:00
Everywhere: "indexes" => "indices"
I've wasted a silly amount of time in the past fretting over which of these words to use. Let's just choose one and use it everywhere. :^)
This commit is contained in:
parent
7ae7170d61
commit
3d4afe7614
Notes:
sideshowbarker
2024-07-18 18:53:37 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3d4afe7614b
@ -39,10 +39,10 @@ struct TypeWrapper {
|
||||
using Type = T;
|
||||
};
|
||||
|
||||
template<typename List, typename F, unsigned... Indexes>
|
||||
constexpr void for_each_type_impl(F&& f, IndexSequence<Indexes...>)
|
||||
template<typename List, typename F, unsigned... Indices>
|
||||
constexpr void for_each_type_impl(F&& f, IndexSequence<Indices...>)
|
||||
{
|
||||
(forward<F>(f)(TypeWrapper<typename List::template Type<Indexes>> {}), ...);
|
||||
(forward<F>(f)(TypeWrapper<typename List::template Type<Indices>> {}), ...);
|
||||
}
|
||||
|
||||
template<typename List, typename F>
|
||||
@ -51,10 +51,10 @@ constexpr void for_each_type(F&& f)
|
||||
for_each_type_impl<List>(forward<F>(f), MakeIndexSequence<List::size> {});
|
||||
}
|
||||
|
||||
template<typename ListA, typename ListB, typename F, unsigned... Indexes>
|
||||
constexpr void for_each_type_zipped_impl(F&& f, IndexSequence<Indexes...>)
|
||||
template<typename ListA, typename ListB, typename F, unsigned... Indices>
|
||||
constexpr void for_each_type_zipped_impl(F&& f, IndexSequence<Indices...>)
|
||||
{
|
||||
(forward<F>(f)(TypeWrapper<typename ListA::template Type<Indexes>> {}, TypeWrapper<typename ListB::template Type<Indexes>> {}), ...);
|
||||
(forward<F>(f)(TypeWrapper<typename ListA::template Type<Indices>> {}, TypeWrapper<typename ListB::template Type<Indices>> {}), ...);
|
||||
}
|
||||
|
||||
template<typename ListA, typename ListB, typename F>
|
||||
|
@ -208,32 +208,32 @@ Ext2FS::BlockListShape Ext2FS::compute_block_list_shape(unsigned blocks) const
|
||||
return shape;
|
||||
}
|
||||
|
||||
KResult Ext2FSInode::write_indirect_block(BlockBasedFS::BlockIndex block, Span<BlockBasedFS::BlockIndex> blocks_indexes)
|
||||
KResult Ext2FSInode::write_indirect_block(BlockBasedFS::BlockIndex block, Span<BlockBasedFS::BlockIndex> blocks_indices)
|
||||
{
|
||||
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
|
||||
VERIFY(blocks_indexes.size() <= entries_per_block);
|
||||
VERIFY(blocks_indices.size() <= entries_per_block);
|
||||
|
||||
auto block_contents = ByteBuffer::create_uninitialized(fs().block_size());
|
||||
OutputMemoryStream stream { block_contents };
|
||||
auto buffer = UserOrKernelBuffer::for_kernel_buffer(stream.data());
|
||||
|
||||
VERIFY(blocks_indexes.size() <= EXT2_ADDR_PER_BLOCK(&fs().super_block()));
|
||||
for (unsigned i = 0; i < blocks_indexes.size(); ++i)
|
||||
stream << static_cast<u32>(blocks_indexes[i].value());
|
||||
VERIFY(blocks_indices.size() <= EXT2_ADDR_PER_BLOCK(&fs().super_block()));
|
||||
for (unsigned i = 0; i < blocks_indices.size(); ++i)
|
||||
stream << static_cast<u32>(blocks_indices[i].value());
|
||||
stream.fill_to_end(0);
|
||||
|
||||
return fs().write_block(block, buffer, stream.size());
|
||||
}
|
||||
|
||||
KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFS::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFS::BlockIndex> blocks_indexes, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
|
||||
KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFS::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFS::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
|
||||
{
|
||||
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
|
||||
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
|
||||
const auto old_indirect_blocks_length = divide_rounded_up(old_blocks_length, entries_per_block);
|
||||
const auto new_indirect_blocks_length = divide_rounded_up(blocks_indexes.size(), entries_per_block);
|
||||
VERIFY(blocks_indexes.size() > 0);
|
||||
VERIFY(blocks_indexes.size() > old_blocks_length);
|
||||
VERIFY(blocks_indexes.size() <= entries_per_doubly_indirect_block);
|
||||
const auto new_indirect_blocks_length = divide_rounded_up(blocks_indices.size(), entries_per_block);
|
||||
VERIFY(blocks_indices.size() > 0);
|
||||
VERIFY(blocks_indices.size() > old_blocks_length);
|
||||
VERIFY(blocks_indices.size() <= entries_per_doubly_indirect_block);
|
||||
|
||||
auto block_contents = ByteBuffer::create_uninitialized(fs().block_size());
|
||||
auto* block_as_pointers = (unsigned*)block_contents.data();
|
||||
@ -259,7 +259,7 @@ KResult Ext2FSInode::grow_doubly_indirect_block(BlockBasedFS::BlockIndex block,
|
||||
// Write out the indirect blocks.
|
||||
for (unsigned i = old_blocks_length / entries_per_block; i < new_indirect_blocks_length; i++) {
|
||||
const auto offset_block = i * entries_per_block;
|
||||
if (auto result = write_indirect_block(block_as_pointers[i], blocks_indexes.slice(offset_block, min(blocks_indexes.size() - offset_block, entries_per_block))); result.is_error())
|
||||
if (auto result = write_indirect_block(block_as_pointers[i], blocks_indices.slice(offset_block, min(blocks_indices.size() - offset_block, entries_per_block))); result.is_error())
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -302,16 +302,16 @@ KResult Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFS::BlockIndex block
|
||||
return KSuccess;
|
||||
}
|
||||
|
||||
KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFS::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFS::BlockIndex> blocks_indexes, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
|
||||
KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFS::BlockIndex block, size_t old_blocks_length, Span<BlockBasedFS::BlockIndex> blocks_indices, Vector<Ext2FS::BlockIndex>& new_meta_blocks, unsigned& meta_blocks)
|
||||
{
|
||||
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
|
||||
const auto entries_per_doubly_indirect_block = entries_per_block * entries_per_block;
|
||||
const auto entries_per_triply_indirect_block = entries_per_block * entries_per_block;
|
||||
const auto old_doubly_indirect_blocks_length = divide_rounded_up(old_blocks_length, entries_per_doubly_indirect_block);
|
||||
const auto new_doubly_indirect_blocks_length = divide_rounded_up(blocks_indexes.size(), entries_per_doubly_indirect_block);
|
||||
VERIFY(blocks_indexes.size() > 0);
|
||||
VERIFY(blocks_indexes.size() > old_blocks_length);
|
||||
VERIFY(blocks_indexes.size() <= entries_per_triply_indirect_block);
|
||||
const auto new_doubly_indirect_blocks_length = divide_rounded_up(blocks_indices.size(), entries_per_doubly_indirect_block);
|
||||
VERIFY(blocks_indices.size() > 0);
|
||||
VERIFY(blocks_indices.size() > old_blocks_length);
|
||||
VERIFY(blocks_indices.size() <= entries_per_triply_indirect_block);
|
||||
|
||||
auto block_contents = ByteBuffer::create_uninitialized(fs().block_size());
|
||||
auto* block_as_pointers = (unsigned*)block_contents.data();
|
||||
@ -338,8 +338,8 @@ KResult Ext2FSInode::grow_triply_indirect_block(BlockBasedFS::BlockIndex block,
|
||||
for (unsigned i = old_blocks_length / entries_per_doubly_indirect_block; i < new_doubly_indirect_blocks_length; i++) {
|
||||
const auto processed_blocks = i * entries_per_doubly_indirect_block;
|
||||
const auto old_doubly_indirect_blocks_length = min(old_blocks_length > processed_blocks ? old_blocks_length - processed_blocks : 0, entries_per_doubly_indirect_block);
|
||||
const auto new_doubly_indirect_blocks_length = min(blocks_indexes.size() > processed_blocks ? blocks_indexes.size() - processed_blocks : 0, entries_per_doubly_indirect_block);
|
||||
if (auto result = grow_doubly_indirect_block(block_as_pointers[i], old_doubly_indirect_blocks_length, blocks_indexes.slice(processed_blocks, new_doubly_indirect_blocks_length), new_meta_blocks, meta_blocks); result.is_error())
|
||||
const auto new_doubly_indirect_blocks_length = min(blocks_indices.size() > processed_blocks ? blocks_indices.size() - processed_blocks : 0, entries_per_doubly_indirect_block);
|
||||
if (auto result = grow_doubly_indirect_block(block_as_pointers[i], old_doubly_indirect_blocks_length, blocks_indices.slice(processed_blocks, new_doubly_indirect_blocks_length), new_meta_blocks, meta_blocks); result.is_error())
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -161,15 +161,15 @@ public:
|
||||
Vector<u8> to_vector() const
|
||||
{
|
||||
// FIXME: Add a sync mechanism!
|
||||
Vector<u8> indexes;
|
||||
Vector<u8> indices;
|
||||
u32 bitfield = m_bitfield & m_bit_mask;
|
||||
for (size_t index = 0; index < 32; index++) {
|
||||
if (bitfield & 1) {
|
||||
indexes.append(index);
|
||||
indices.append(index);
|
||||
}
|
||||
bitfield >>= 1;
|
||||
}
|
||||
return indexes;
|
||||
return indices;
|
||||
}
|
||||
|
||||
u32 bit_mask() const { return m_bit_mask; };
|
||||
|
@ -343,7 +343,7 @@ DirectoryView::~DirectoryView()
|
||||
|
||||
void DirectoryView::model_did_update(unsigned flags)
|
||||
{
|
||||
if (flags & GUI::Model::UpdateFlag::InvalidateAllIndexes) {
|
||||
if (flags & GUI::Model::UpdateFlag::InvalidateAllIndices) {
|
||||
for_each_view_implementation([](auto& view) {
|
||||
view.selection().clear();
|
||||
});
|
||||
|
@ -152,7 +152,7 @@ void SheetModel::set_data(const GUI::ModelIndex& index, const GUI::Variant& valu
|
||||
void SheetModel::update()
|
||||
{
|
||||
m_sheet->update();
|
||||
did_update(UpdateFlag::DontInvalidateIndexes);
|
||||
did_update(UpdateFlag::DontInvalidateIndices);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||
|
||||
m_table_view->on_selection_change = [&] {
|
||||
m_sheet->selected_cells().clear();
|
||||
for (auto& index : m_table_view->selection().indexes()) {
|
||||
for (auto& index : m_table_view->selection().indices()) {
|
||||
Position position { (size_t)index.column(), (size_t)index.row() };
|
||||
m_sheet->selected_cells().set(position);
|
||||
}
|
||||
@ -201,7 +201,7 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||
|
||||
Vector<Position> selected_positions;
|
||||
selected_positions.ensure_capacity(m_table_view->selection().size());
|
||||
for (auto& selection : m_table_view->selection().indexes())
|
||||
for (auto& selection : m_table_view->selection().indices())
|
||||
selected_positions.empend((size_t)selection.column(), (size_t)selection.row());
|
||||
|
||||
if (on_selection_changed) {
|
||||
@ -222,7 +222,7 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||
m_cell_range_context_menu = GUI::Menu::construct();
|
||||
m_cell_range_context_menu->add_action(GUI::Action::create("Type and Formatting...", [this](auto&) {
|
||||
Vector<Position> positions;
|
||||
for (auto& index : m_table_view->selection().indexes()) {
|
||||
for (auto& index : m_table_view->selection().indices()) {
|
||||
Position position { (size_t)index.column(), (size_t)index.row() };
|
||||
positions.append(move(position));
|
||||
}
|
||||
@ -295,7 +295,7 @@ void SpreadsheetView::show_event(GUI::ShowEvent&)
|
||||
if (on_selection_changed && !m_table_view->selection().is_empty()) {
|
||||
Vector<Position> selected_positions;
|
||||
selected_positions.ensure_capacity(m_table_view->selection().size());
|
||||
for (auto& selection : m_table_view->selection().indexes())
|
||||
for (auto& selection : m_table_view->selection().indices())
|
||||
selected_positions.empend((size_t)selection.column(), (size_t)selection.row());
|
||||
|
||||
on_selection_changed(move(selected_positions));
|
||||
|
@ -416,7 +416,7 @@ void ProcessModel::update()
|
||||
if (on_state_update)
|
||||
on_state_update(all_processes->size(), m_threads.size());
|
||||
|
||||
// FIXME: This is a rather hackish way of invalidating indexes.
|
||||
// It would be good if GUI::Model had a way to orchestrate removal/insertion while preserving indexes.
|
||||
did_update(previous_tid_count == m_tids.size() ? GUI::Model::UpdateFlag::DontInvalidateIndexes : GUI::Model::UpdateFlag::InvalidateAllIndexes);
|
||||
// FIXME: This is a rather hackish way of invalidating indices.
|
||||
// It would be good if GUI::Model had a way to orchestrate removal/insertion while preserving indices.
|
||||
did_update(previous_tid_count == m_tids.size() ? GUI::Model::UpdateFlag::DontInvalidateIndices : GUI::Model::UpdateFlag::InvalidateAllIndices);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
|
||||
virtual void update() override
|
||||
{
|
||||
did_update(GUI::Model::DontInvalidateIndexes);
|
||||
did_update(GUI::Model::DontInvalidateIndices);
|
||||
}
|
||||
|
||||
virtual void model_did_update([[maybe_unused]] unsigned flags) override
|
||||
|
@ -67,5 +67,5 @@ GUI::Variant IndividualSampleModel::data(const GUI::ModelIndex& index, GUI::Mode
|
||||
|
||||
void IndividualSampleModel::update()
|
||||
{
|
||||
did_update(Model::InvalidateAllIndexes);
|
||||
did_update(Model::InvalidateAllIndices);
|
||||
}
|
||||
|
@ -127,5 +127,5 @@ GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
|
||||
|
||||
void ProfileModel::update()
|
||||
{
|
||||
did_update(Model::InvalidateAllIndexes);
|
||||
did_update(Model::InvalidateAllIndices);
|
||||
}
|
||||
|
@ -89,5 +89,5 @@ GUI::Variant SamplesModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
|
||||
|
||||
void SamplesModel::update()
|
||||
{
|
||||
did_update(Model::InvalidateAllIndexes);
|
||||
did_update(Model::InvalidateAllIndices);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ typedef uint32_t Elf64_Half;
|
||||
typedef uint16_t Elf64_Quarter;
|
||||
|
||||
/*
|
||||
* e_ident[] identification indexes
|
||||
* e_ident[] identification indices
|
||||
* See http://www.sco.com/developers/gabi/latest/ch4.eheader.html
|
||||
*/
|
||||
#define EI_MAG0 0 /* file ID */
|
||||
@ -241,15 +241,15 @@ typedef struct {
|
||||
Elf64_Xword sh_entsize; /* table entry size */
|
||||
} Elf64_Shdr;
|
||||
|
||||
/* Special Section Indexes */
|
||||
/* Special Section Indices */
|
||||
#define SHN_UNDEF 0 /* undefined */
|
||||
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
|
||||
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indices */
|
||||
#define SHN_LOPROC 0xff00 /* reserved range for processor */
|
||||
#define SHN_HIPROC 0xff1f /* specific section indexes */
|
||||
#define SHN_HIPROC 0xff1f /* specific section indices */
|
||||
#define SHN_ABS 0xfff1 /* absolute value */
|
||||
#define SHN_COMMON 0xfff2 /* common symbol */
|
||||
#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere. */
|
||||
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
|
||||
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indices */
|
||||
|
||||
/* sh_type */
|
||||
#define SHT_NULL 0 /* inactive */
|
||||
@ -269,7 +269,7 @@ typedef struct {
|
||||
#define SHT_FINI_ARRAY 15 /* pointers to termination functions */
|
||||
#define SHT_PREINIT_ARRAY 16 /* ptrs to funcs called before init */
|
||||
#define SHT_GROUP 17 /* defines a section group */
|
||||
#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX). */
|
||||
#define SHT_SYMTAB_SHNDX 18 /* Section indices (see SHN_XINDEX). */
|
||||
#define SHT_LOOS 0x60000000 /* reserved range for OS specific */
|
||||
#define SHT_SUNW_dof 0x6ffffff4 /* used by dtrace */
|
||||
#define SHT_GNU_LIBLIST 0x6ffffff7 /* libraries to be prelinked */
|
||||
@ -282,7 +282,7 @@ typedef struct {
|
||||
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define SHT_HIPROC 0x7fffffff /* specific section header types */
|
||||
#define SHT_LOUSER 0x80000000 /* reserved range for application */
|
||||
#define SHT_HIUSER 0xffffffff /* specific indexes */
|
||||
#define SHT_HIUSER 0xffffffff /* specific indices */
|
||||
|
||||
#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table section */
|
||||
|
||||
|
@ -578,7 +578,7 @@ FLATTEN void UnsignedBigInteger::shift_left_without_allocation(
|
||||
* Complexity: O(N^2) where N is the number of words in the larger number
|
||||
* Multiplication method:
|
||||
* An integer is equal to the sum of the powers of two
|
||||
* according to the indexes of its 'on' bits.
|
||||
* according to the indices of its 'on' bits.
|
||||
* So to multiple x*y, we go over each '1' bit in x (say the i'th bit),
|
||||
* and add y<<i to the result.
|
||||
*/
|
||||
|
@ -43,13 +43,13 @@ void AbstractView::set_model(RefPtr<Model> model)
|
||||
m_model = move(model);
|
||||
if (m_model)
|
||||
m_model->register_view({}, *this);
|
||||
model_did_update(GUI::Model::InvalidateAllIndexes);
|
||||
model_did_update(GUI::Model::InvalidateAllIndices);
|
||||
scroll_to_top();
|
||||
}
|
||||
|
||||
void AbstractView::model_did_update(unsigned int flags)
|
||||
{
|
||||
if (!model() || (flags & GUI::Model::InvalidateAllIndexes)) {
|
||||
if (!model() || (flags & GUI::Model::InvalidateAllIndices)) {
|
||||
stop_editing();
|
||||
m_edit_index = {};
|
||||
m_hovered_index = {};
|
||||
@ -630,9 +630,9 @@ void AbstractView::do_search(String&& searching)
|
||||
return;
|
||||
}
|
||||
|
||||
auto found_indexes = model()->matches(searching, Model::MatchesFlag::FirstMatchOnly | Model::MatchesFlag::MatchAtStart | Model::MatchesFlag::CaseInsensitive, model()->parent_index(cursor_index()));
|
||||
if (!found_indexes.is_empty() && found_indexes[0].is_valid()) {
|
||||
auto& index = found_indexes[0];
|
||||
auto found_indices = model()->matches(searching, Model::MatchesFlag::FirstMatchOnly | Model::MatchesFlag::MatchAtStart | Model::MatchesFlag::CaseInsensitive, model()->parent_index(cursor_index()));
|
||||
if (!found_indices.is_empty() && found_indices[0].is_valid()) {
|
||||
auto& index = found_indices[0];
|
||||
m_highlighted_search_index = index;
|
||||
m_searching = move(searching);
|
||||
set_selection(index);
|
||||
|
@ -629,17 +629,17 @@ Vector<ModelIndex, 1> FileSystemModel::matches(const StringView& searching, unsi
|
||||
{
|
||||
Node& node = const_cast<Node&>(this->node(index));
|
||||
node.reify_if_needed();
|
||||
Vector<ModelIndex, 1> found_indexes;
|
||||
Vector<ModelIndex, 1> found_indices;
|
||||
for (auto& child : node.children) {
|
||||
if (string_matches(child.name, searching, flags)) {
|
||||
const_cast<Node&>(child).reify_if_needed();
|
||||
found_indexes.append(child.index(Column::Name));
|
||||
found_indices.append(child.index(Column::Name));
|
||||
if (flags & FirstMatchOnly)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found_indexes;
|
||||
return found_indices;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -106,10 +106,10 @@ bool FilteringProxyModel::is_searchable() const
|
||||
|
||||
Vector<ModelIndex, 1> FilteringProxyModel::matches(const StringView& searching, unsigned flags, const ModelIndex& index)
|
||||
{
|
||||
auto found_indexes = m_model.matches(searching, flags, index);
|
||||
for (size_t i = 0; i < found_indexes.size(); i++)
|
||||
found_indexes[i] = map(found_indexes[i]);
|
||||
return found_indexes;
|
||||
auto found_indices = m_model.matches(searching, flags, index);
|
||||
for (size_t i = 0; i < found_indices.size(); i++)
|
||||
found_indices[i] = map(found_indices[i]);
|
||||
return found_indices;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ auto IconView::item_data_from_content_position(const Gfx::IntPoint& content_posi
|
||||
void IconView::model_did_update(unsigned flags)
|
||||
{
|
||||
AbstractView::model_did_update(flags);
|
||||
if (!model() || (flags & GUI::Model::InvalidateAllIndexes)) {
|
||||
if (!model() || (flags & GUI::Model::InvalidateAllIndices)) {
|
||||
m_item_data_cache.clear();
|
||||
AbstractView::clear_selection();
|
||||
m_selected_count_cache = 0;
|
||||
|
@ -37,8 +37,8 @@ public:
|
||||
class Model : public RefCounted<Model> {
|
||||
public:
|
||||
enum UpdateFlag {
|
||||
DontInvalidateIndexes = 0,
|
||||
InvalidateAllIndexes = 1 << 0,
|
||||
DontInvalidateIndices = 0,
|
||||
InvalidateAllIndices = 1 << 0,
|
||||
};
|
||||
|
||||
enum MatchesFlag {
|
||||
@ -88,7 +88,7 @@ protected:
|
||||
Model();
|
||||
|
||||
void for_each_view(Function<void(AbstractView&)>);
|
||||
void did_update(unsigned flags = UpdateFlag::InvalidateAllIndexes);
|
||||
void did_update(unsigned flags = UpdateFlag::InvalidateAllIndices);
|
||||
|
||||
static bool string_matches(const StringView& str, const StringView& needle, unsigned flags)
|
||||
{
|
||||
|
@ -14,13 +14,13 @@ namespace GUI {
|
||||
void ModelSelection::remove_matching(Function<bool(const ModelIndex&)> filter)
|
||||
{
|
||||
Vector<ModelIndex> to_remove;
|
||||
for (auto& index : m_indexes) {
|
||||
for (auto& index : m_indices) {
|
||||
if (filter(index))
|
||||
to_remove.append(index);
|
||||
}
|
||||
if (!to_remove.is_empty()) {
|
||||
for (auto& index : to_remove)
|
||||
m_indexes.remove(index);
|
||||
m_indices.remove(index);
|
||||
notify_selection_changed();
|
||||
}
|
||||
}
|
||||
@ -28,19 +28,19 @@ void ModelSelection::remove_matching(Function<bool(const ModelIndex&)> filter)
|
||||
void ModelSelection::set(const ModelIndex& index)
|
||||
{
|
||||
VERIFY(index.is_valid());
|
||||
if (m_indexes.size() == 1 && m_indexes.contains(index))
|
||||
if (m_indices.size() == 1 && m_indices.contains(index))
|
||||
return;
|
||||
m_indexes.clear();
|
||||
m_indexes.set(index);
|
||||
m_indices.clear();
|
||||
m_indices.set(index);
|
||||
notify_selection_changed();
|
||||
}
|
||||
|
||||
void ModelSelection::add(const ModelIndex& index)
|
||||
{
|
||||
VERIFY(index.is_valid());
|
||||
if (m_indexes.contains(index))
|
||||
if (m_indices.contains(index))
|
||||
return;
|
||||
m_indexes.set(index);
|
||||
m_indices.set(index);
|
||||
notify_selection_changed();
|
||||
}
|
||||
|
||||
@ -59,28 +59,28 @@ void ModelSelection::add_all(const Vector<ModelIndex>& indices)
|
||||
void ModelSelection::toggle(const ModelIndex& index)
|
||||
{
|
||||
VERIFY(index.is_valid());
|
||||
if (m_indexes.contains(index))
|
||||
m_indexes.remove(index);
|
||||
if (m_indices.contains(index))
|
||||
m_indices.remove(index);
|
||||
else
|
||||
m_indexes.set(index);
|
||||
m_indices.set(index);
|
||||
notify_selection_changed();
|
||||
}
|
||||
|
||||
bool ModelSelection::remove(const ModelIndex& index)
|
||||
{
|
||||
VERIFY(index.is_valid());
|
||||
if (!m_indexes.contains(index))
|
||||
if (!m_indices.contains(index))
|
||||
return false;
|
||||
m_indexes.remove(index);
|
||||
m_indices.remove(index);
|
||||
notify_selection_changed();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ModelSelection::clear()
|
||||
{
|
||||
if (m_indexes.is_empty())
|
||||
if (m_indices.is_empty())
|
||||
return;
|
||||
m_indexes.clear();
|
||||
m_indices.clear();
|
||||
notify_selection_changed();
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,12 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
int size() const { return m_indexes.size(); }
|
||||
bool is_empty() const { return m_indexes.is_empty(); }
|
||||
bool contains(const ModelIndex& index) const { return m_indexes.contains(index); }
|
||||
int size() const { return m_indices.size(); }
|
||||
bool is_empty() const { return m_indices.is_empty(); }
|
||||
bool contains(const ModelIndex& index) const { return m_indices.contains(index); }
|
||||
bool contains_row(int row) const
|
||||
{
|
||||
for (auto& index : m_indexes) {
|
||||
for (auto& index : m_indices) {
|
||||
if (index.row() == row)
|
||||
return true;
|
||||
}
|
||||
@ -47,33 +47,33 @@ public:
|
||||
template<typename Callback>
|
||||
void for_each_index(Callback callback)
|
||||
{
|
||||
for (auto& index : indexes())
|
||||
for (auto& index : indices())
|
||||
callback(index);
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_index(Callback callback) const
|
||||
{
|
||||
for (auto& index : indexes())
|
||||
for (auto& index : indices())
|
||||
callback(index);
|
||||
}
|
||||
|
||||
Vector<ModelIndex> indexes() const
|
||||
Vector<ModelIndex> indices() const
|
||||
{
|
||||
Vector<ModelIndex> selected_indexes;
|
||||
Vector<ModelIndex> selected_indices;
|
||||
|
||||
for (auto& index : m_indexes)
|
||||
selected_indexes.append(index);
|
||||
for (auto& index : m_indices)
|
||||
selected_indices.append(index);
|
||||
|
||||
return selected_indexes;
|
||||
return selected_indices;
|
||||
}
|
||||
|
||||
// FIXME: This doesn't guarantee that what you get is the lowest or "first" index selected..
|
||||
ModelIndex first() const
|
||||
{
|
||||
if (m_indexes.is_empty())
|
||||
if (m_indices.is_empty())
|
||||
return {};
|
||||
return *m_indexes.begin();
|
||||
return *m_indices.begin();
|
||||
}
|
||||
|
||||
void remove_matching(Function<bool(const ModelIndex&)>);
|
||||
@ -94,7 +94,7 @@ private:
|
||||
void notify_selection_changed();
|
||||
|
||||
AbstractView& m_view;
|
||||
HashTable<ModelIndex> m_indexes;
|
||||
HashTable<ModelIndex> m_indices;
|
||||
bool m_disable_notify { false };
|
||||
bool m_notify_pending { false };
|
||||
};
|
||||
|
@ -24,7 +24,7 @@ SortingProxyModel::~SortingProxyModel()
|
||||
|
||||
void SortingProxyModel::invalidate(unsigned int flags)
|
||||
{
|
||||
if (flags == UpdateFlag::DontInvalidateIndexes) {
|
||||
if (flags == UpdateFlag::DontInvalidateIndices) {
|
||||
sort(m_last_key_column, m_last_sort_order);
|
||||
} else {
|
||||
m_mappings.clear();
|
||||
@ -201,20 +201,20 @@ void SortingProxyModel::sort_mapping(Mapping& mapping, int column, SortOrder sor
|
||||
|
||||
// Update the view's selection.
|
||||
view.selection().change_from_model({}, [&](ModelSelection& selection) {
|
||||
Vector<ModelIndex> selected_indexes_in_source;
|
||||
Vector<ModelIndex> stale_indexes_in_selection;
|
||||
Vector<ModelIndex> selected_indices_in_source;
|
||||
Vector<ModelIndex> stale_indices_in_selection;
|
||||
selection.for_each_index([&](const ModelIndex& index) {
|
||||
if (index.parent() == mapping.source_parent) {
|
||||
stale_indexes_in_selection.append(index);
|
||||
selected_indexes_in_source.append(source().index(old_source_rows[index.row()], index.column(), mapping.source_parent));
|
||||
stale_indices_in_selection.append(index);
|
||||
selected_indices_in_source.append(source().index(old_source_rows[index.row()], index.column(), mapping.source_parent));
|
||||
}
|
||||
});
|
||||
|
||||
for (auto& index : stale_indexes_in_selection) {
|
||||
for (auto& index : stale_indices_in_selection) {
|
||||
selection.remove(index);
|
||||
}
|
||||
|
||||
for (auto& index : selected_indexes_in_source) {
|
||||
for (auto& index : selected_indices_in_source) {
|
||||
for (size_t i = 0; i < mapping.source_rows.size(); ++i) {
|
||||
if (mapping.source_rows[i] == index.row()) {
|
||||
auto new_source_index = this->index(i, index.column(), mapping.source_parent);
|
||||
@ -237,7 +237,7 @@ void SortingProxyModel::sort(int column, SortOrder sort_order)
|
||||
m_last_key_column = column;
|
||||
m_last_sort_order = sort_order;
|
||||
|
||||
did_update(UpdateFlag::DontInvalidateIndexes);
|
||||
did_update(UpdateFlag::DontInvalidateIndices);
|
||||
}
|
||||
|
||||
SortingProxyModel::InternalMapIterator SortingProxyModel::build_mapping(const ModelIndex& source_parent)
|
||||
@ -287,10 +287,10 @@ bool SortingProxyModel::is_searchable() const
|
||||
|
||||
Vector<ModelIndex, 1> SortingProxyModel::matches(const StringView& searching, unsigned flags, const ModelIndex& proxy_index)
|
||||
{
|
||||
auto found_indexes = source().matches(searching, flags, map_to_source(proxy_index));
|
||||
for (size_t i = 0; i < found_indexes.size(); i++)
|
||||
found_indexes[i] = map_to_proxy(found_indexes[i]);
|
||||
return found_indexes;
|
||||
auto found_indices = source().matches(searching, flags, map_to_source(proxy_index));
|
||||
for (size_t i = 0; i < found_indices.size(); i++)
|
||||
found_indices[i] = map_to_proxy(found_indices[i]);
|
||||
return found_indices;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
private:
|
||||
explicit SortingProxyModel(NonnullRefPtr<Model> source);
|
||||
|
||||
// NOTE: The internal_data() of indexes points to the corresponding Mapping object for that index.
|
||||
// NOTE: The internal_data() of indices points to the corresponding Mapping object for that index.
|
||||
struct Mapping {
|
||||
Vector<int> source_rows;
|
||||
Vector<int> proxy_rows;
|
||||
@ -63,7 +63,7 @@ private:
|
||||
Model& source() { return *m_source; }
|
||||
const Model& source() const { return *m_source; }
|
||||
|
||||
void invalidate(unsigned flags = Model::UpdateFlag::DontInvalidateIndexes);
|
||||
void invalidate(unsigned flags = Model::UpdateFlag::DontInvalidateIndices);
|
||||
InternalMapIterator build_mapping(const ModelIndex& proxy_index);
|
||||
|
||||
NonnullRefPtr<Model> m_source;
|
||||
|
@ -430,10 +430,10 @@ NEVER_INLINE FLATTEN static bool unfilter(PNGLoadingContext& context)
|
||||
auto pixels_per_byte = 8 / context.bit_depth;
|
||||
auto mask = (1 << context.bit_depth) - 1;
|
||||
for (int y = 0; y < context.height; ++y) {
|
||||
auto* palette_indexes = context.scanlines[y].data.data();
|
||||
auto* palette_indices = context.scanlines[y].data.data();
|
||||
for (int i = 0; i < context.width; ++i) {
|
||||
auto bit_offset = (8 - context.bit_depth) - (context.bit_depth * (i % pixels_per_byte));
|
||||
auto palette_index = (palette_indexes[i / pixels_per_byte] >> bit_offset) & mask;
|
||||
auto palette_index = (palette_indices[i / pixels_per_byte] >> bit_offset) & mask;
|
||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||
if ((size_t)palette_index >= context.palette_data.size())
|
||||
return false;
|
||||
|
@ -79,21 +79,21 @@ describe("normal behavior", () => {
|
||||
}, 100);
|
||||
expect(result).toBe(121);
|
||||
|
||||
var indexes = [];
|
||||
var indices = [];
|
||||
result = ["foo", 1, true].reduce((a, v, i) => {
|
||||
indexes.push(i);
|
||||
indices.push(i);
|
||||
});
|
||||
expect(result).toBeUndefined();
|
||||
expect(indexes.length).toBe(2);
|
||||
expect(indexes[0]).toBe(1);
|
||||
expect(indexes[1]).toBe(2);
|
||||
expect(indices.length).toBe(2);
|
||||
expect(indices[0]).toBe(1);
|
||||
expect(indices[1]).toBe(2);
|
||||
|
||||
indexes = [];
|
||||
indices = [];
|
||||
result = ["foo", 1, true].reduce((a, v, i) => {
|
||||
indexes.push(i);
|
||||
indices.push(i);
|
||||
}, "foo");
|
||||
expect(result).toBeUndefined();
|
||||
expect(indexes).toEqual([0, 1, 2]);
|
||||
expect(indices).toEqual([0, 1, 2]);
|
||||
|
||||
var mutable = { prop: 0 };
|
||||
result = ["foo", 1, true].reduce((a, v) => {
|
||||
|
@ -84,21 +84,21 @@ describe("normal behavior", () => {
|
||||
}, 100);
|
||||
expect(result).toBe("100123456");
|
||||
|
||||
var indexes = [];
|
||||
var indices = [];
|
||||
result = ["foo", 1, true].reduceRight((a, v, i) => {
|
||||
indexes.push(i);
|
||||
indices.push(i);
|
||||
});
|
||||
expect(result).toBeUndefined();
|
||||
expect(indexes.length).toBe(2);
|
||||
expect(indexes[0]).toBe(1);
|
||||
expect(indexes[1]).toBe(0);
|
||||
expect(indices.length).toBe(2);
|
||||
expect(indices[0]).toBe(1);
|
||||
expect(indices[1]).toBe(0);
|
||||
|
||||
indexes = [];
|
||||
indices = [];
|
||||
result = ["foo", 1, true].reduceRight((a, v, i) => {
|
||||
indexes.push(i);
|
||||
indices.push(i);
|
||||
}, "foo");
|
||||
expect(result).toBeUndefined();
|
||||
expect(indexes).toEqual([2, 1, 0]);
|
||||
expect(indices).toEqual([2, 1, 0]);
|
||||
|
||||
var mutable = { prop: 0 };
|
||||
result = ["foo", 1, true].reduceRight((a, v) => {
|
||||
|
@ -618,15 +618,15 @@ void Menu::set_visible(bool visible)
|
||||
void Menu::add_item(NonnullOwnPtr<MenuItem> item)
|
||||
{
|
||||
if (auto alt_shortcut = find_ampersand_shortcut_character(item->text())) {
|
||||
m_alt_shortcut_character_to_item_indexes.ensure(tolower(alt_shortcut)).append(m_items.size());
|
||||
m_alt_shortcut_character_to_item_indices.ensure(tolower(alt_shortcut)).append(m_items.size());
|
||||
}
|
||||
m_items.append(move(item));
|
||||
}
|
||||
|
||||
const Vector<size_t>* Menu::items_with_alt_shortcut(u32 alt_shortcut) const
|
||||
{
|
||||
auto it = m_alt_shortcut_character_to_item_indexes.find(tolower(alt_shortcut));
|
||||
if (it == m_alt_shortcut_character_to_item_indexes.end())
|
||||
auto it = m_alt_shortcut_character_to_item_indices.find(tolower(alt_shortcut));
|
||||
if (it == m_alt_shortcut_character_to_item_indices.end())
|
||||
return nullptr;
|
||||
return &it->value;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ private:
|
||||
int m_scroll_offset { 0 };
|
||||
int m_max_scroll_offset { 0 };
|
||||
|
||||
HashMap<u32, Vector<size_t>> m_alt_shortcut_character_to_item_indexes;
|
||||
HashMap<u32, Vector<size_t>> m_alt_shortcut_character_to_item_indices;
|
||||
};
|
||||
|
||||
u32 find_ampersand_shortcut_character(const StringView&);
|
||||
|
@ -70,11 +70,11 @@ void MenuManager::event(Core::Event& event)
|
||||
&& ((key_event.key() >= Key_A && key_event.key() <= Key_Z)
|
||||
|| (key_event.key() >= Key_0 && key_event.key() <= Key_9))) {
|
||||
|
||||
if (auto* shortcut_item_indexes = m_current_menu->items_with_alt_shortcut(key_event.code_point())) {
|
||||
VERIFY(!shortcut_item_indexes->is_empty());
|
||||
if (auto* shortcut_item_indices = m_current_menu->items_with_alt_shortcut(key_event.code_point())) {
|
||||
VERIFY(!shortcut_item_indices->is_empty());
|
||||
// FIXME: If there are multiple items with the same Alt shortcut, we should cycle through them
|
||||
// with each keypress instead of activating immediately.
|
||||
auto index = shortcut_item_indexes->at(0);
|
||||
auto index = shortcut_item_indices->at(0);
|
||||
auto& item = m_current_menu->item(index);
|
||||
m_current_menu->set_hovered_index(index);
|
||||
if (item.is_submenu())
|
||||
|
@ -37,10 +37,10 @@ static void print_usage_and_exit(int ret)
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
static void add_if_not_exists(Vector<Index>& indexes, Index data)
|
||||
static void add_if_not_exists(Vector<Index>& indices, Index data)
|
||||
{
|
||||
bool append_to_vector = true;
|
||||
for (auto& index : indexes) {
|
||||
for (auto& index : indices) {
|
||||
if (index.intersects(data)) {
|
||||
if (index.m_type == Index::Type::RangedIndex) {
|
||||
index.m_from = min(index.m_from, data.m_from);
|
||||
@ -51,11 +51,11 @@ static void add_if_not_exists(Vector<Index>& indexes, Index data)
|
||||
}
|
||||
|
||||
if (append_to_vector) {
|
||||
indexes.append(data);
|
||||
indices.append(data);
|
||||
}
|
||||
}
|
||||
|
||||
static void expand_list(Vector<String>& tokens, Vector<Index>& indexes)
|
||||
static void expand_list(Vector<String>& tokens, Vector<Index>& indices)
|
||||
{
|
||||
for (auto& token : tokens) {
|
||||
if (token.length() == 0) {
|
||||
@ -81,7 +81,7 @@ static void expand_list(Vector<String>& tokens, Vector<Index>& indexes)
|
||||
}
|
||||
|
||||
Index tmp = { 1, index.value(), Index::Type::RangedIndex };
|
||||
add_if_not_exists(indexes, tmp);
|
||||
add_if_not_exists(indices, tmp);
|
||||
} else if (token[token.length() - 1] == '-') {
|
||||
auto index = token.substring(0, token.length() - 1).to_int();
|
||||
if (!index.has_value()) {
|
||||
@ -94,7 +94,7 @@ static void expand_list(Vector<String>& tokens, Vector<Index>& indexes)
|
||||
print_usage_and_exit(1);
|
||||
}
|
||||
Index tmp = { index.value(), -1, Index::Type::SliceIndex };
|
||||
add_if_not_exists(indexes, tmp);
|
||||
add_if_not_exists(indices, tmp);
|
||||
} else {
|
||||
auto range = token.split('-');
|
||||
if (range.size() == 2) {
|
||||
@ -119,7 +119,7 @@ static void expand_list(Vector<String>& tokens, Vector<Index>& indexes)
|
||||
}
|
||||
|
||||
Index tmp = { index1.value(), index2.value(), Index::Type::RangedIndex };
|
||||
add_if_not_exists(indexes, tmp);
|
||||
add_if_not_exists(indices, tmp);
|
||||
} else if (range.size() == 1) {
|
||||
auto index = range[0].to_int();
|
||||
if (!index.has_value()) {
|
||||
@ -133,7 +133,7 @@ static void expand_list(Vector<String>& tokens, Vector<Index>& indexes)
|
||||
}
|
||||
|
||||
Index tmp = { index.value(), index.value(), Index::Type::SingleIndex };
|
||||
add_if_not_exists(indexes, tmp);
|
||||
add_if_not_exists(indices, tmp);
|
||||
} else {
|
||||
fprintf(stderr, "cut: invalid byte or character range\n");
|
||||
print_usage_and_exit(1);
|
||||
|
Loading…
Reference in New Issue
Block a user