mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
HackStudio: Sort ClassView entries
This commit is contained in:
parent
8388e822cb
commit
e5f84b53d8
1 changed files with 21 additions and 6 deletions
|
@ -27,7 +27,10 @@
|
|||
#include "ClassViewWidget.h"
|
||||
#include "HackStudio.h"
|
||||
#include "ProjectDeclarations.h"
|
||||
#include <AK/BinarySearch.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace HackStudio {
|
||||
|
||||
|
@ -127,6 +130,22 @@ ClassViewModel::ClassViewModel()
|
|||
});
|
||||
}
|
||||
|
||||
static ClassViewNode& add_child_node(NonnullOwnPtrVector<ClassViewNode>& children, NonnullOwnPtr<ClassViewNode>&& node_ptr, ClassViewNode* parent, const GUI::AutocompleteProvider::Declaration* declaration)
|
||||
{
|
||||
node_ptr->parent = parent;
|
||||
node_ptr->declaration = declaration;
|
||||
|
||||
size_t inserted_index = 0;
|
||||
ClassViewNode& node = *node_ptr;
|
||||
children.insert_before_matching(
|
||||
move(node_ptr), [&node](auto& other_node) {
|
||||
return strncmp(node.name.characters_without_null_termination(), other_node->name.characters_without_null_termination(), min(node.name.length(), other_node->name.length())) < 0;
|
||||
},
|
||||
0, &inserted_index);
|
||||
|
||||
return children.at(inserted_index);
|
||||
}
|
||||
|
||||
void ClassViewModel::add_declaration(const GUI::AutocompleteProvider::Declaration& decl)
|
||||
{
|
||||
ClassViewNode* parent = nullptr;
|
||||
|
@ -160,9 +179,7 @@ void ClassViewModel::add_declaration(const GUI::AutocompleteProvider::Declaratio
|
|||
continue;
|
||||
}
|
||||
|
||||
parent->children.append(make<ClassViewNode>(scope));
|
||||
parent->children.last().parent = parent;
|
||||
parent = &parent->children.last();
|
||||
parent = &add_child_node(parent->children, make<ClassViewNode>(scope), parent, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,9 +201,7 @@ void ClassViewModel::add_declaration(const GUI::AutocompleteProvider::Declaratio
|
|||
}
|
||||
}
|
||||
if (!already_exists) {
|
||||
children_of_parent->append(make<ClassViewNode>(decl.name));
|
||||
children_of_parent->last().declaration = &decl;
|
||||
children_of_parent->last().parent = parent;
|
||||
add_child_node(*children_of_parent, make<ClassViewNode>(decl.name), parent, &decl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue