mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:47:45 +00:00
SpaceAnalyzer: Rename widget variables to match code style
This commit is contained in:
parent
534039fdf5
commit
f7aead8086
1 changed files with 26 additions and 26 deletions
|
@ -28,14 +28,14 @@
|
||||||
|
|
||||||
static constexpr auto APP_NAME = "Space Analyzer"sv;
|
static constexpr auto APP_NAME = "Space Analyzer"sv;
|
||||||
|
|
||||||
static DeprecatedString get_absolute_path_to_selected_node(SpaceAnalyzer::TreeMapWidget const& treemapwidget, bool include_last_node = true)
|
static DeprecatedString get_absolute_path_to_selected_node(SpaceAnalyzer::TreeMapWidget const& tree_map_widget, bool include_last_node = true)
|
||||||
{
|
{
|
||||||
StringBuilder path_builder;
|
StringBuilder path_builder;
|
||||||
for (size_t k = 0; k < treemapwidget.path_size() - (include_last_node ? 0 : 1); k++) {
|
for (size_t k = 0; k < tree_map_widget.path_size() - (include_last_node ? 0 : 1); k++) {
|
||||||
if (k != 0) {
|
if (k != 0) {
|
||||||
path_builder.append('/');
|
path_builder.append('/');
|
||||||
}
|
}
|
||||||
TreeNode const* node = treemapwidget.path_node(k);
|
TreeNode const* node = tree_map_widget.path_node(k);
|
||||||
path_builder.append(node->name());
|
path_builder.append(node->name());
|
||||||
}
|
}
|
||||||
return path_builder.to_deprecated_string();
|
return path_builder.to_deprecated_string();
|
||||||
|
@ -53,18 +53,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
|
|
||||||
// Load widgets.
|
// Load widgets.
|
||||||
auto mainwidget = TRY(window->set_main_widget<GUI::Widget>());
|
auto main_widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||||
TRY(mainwidget->load_from_gml(space_analyzer_gml));
|
TRY(main_widget->load_from_gml(space_analyzer_gml));
|
||||||
auto& breadcrumbbar = *mainwidget->find_descendant_of_type_named<GUI::Breadcrumbbar>("breadcrumbbar");
|
auto& breadcrumbbar = *main_widget->find_descendant_of_type_named<GUI::Breadcrumbbar>("breadcrumbbar");
|
||||||
auto& treemapwidget = *mainwidget->find_descendant_of_type_named<SpaceAnalyzer::TreeMapWidget>("tree_map");
|
auto& tree_map_widget = *main_widget->find_descendant_of_type_named<SpaceAnalyzer::TreeMapWidget>("tree_map");
|
||||||
auto& statusbar = *mainwidget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
auto& statusbar = *main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
||||||
|
|
||||||
treemapwidget.set_focus(true);
|
tree_map_widget.set_focus(true);
|
||||||
|
|
||||||
auto file_menu = TRY(window->try_add_menu("&File"));
|
auto file_menu = TRY(window->try_add_menu("&File"));
|
||||||
TRY(file_menu->try_add_action(GUI::Action::create("&Analyze", { KeyCode::Key_F5 }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
|
TRY(file_menu->try_add_action(GUI::Action::create("&Analyze", { KeyCode::Key_F5 }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
|
||||||
// FIXME: Just modify the tree in memory instead of traversing the entire file system
|
// FIXME: Just modify the tree in memory instead of traversing the entire file system
|
||||||
if (auto result = treemapwidget.analyze(statusbar); result.is_error()) {
|
if (auto result = tree_map_widget.analyze(statusbar); result.is_error()) {
|
||||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error()));
|
GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error()));
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
|
@ -80,19 +80,19 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto open_icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"sv));
|
auto open_icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"sv));
|
||||||
// Configure the nodes context menu.
|
// Configure the nodes context menu.
|
||||||
auto open_folder_action = GUI::Action::create("Open Folder", { Mod_Ctrl, Key_O }, open_icon, [&](auto&) {
|
auto open_folder_action = GUI::Action::create("Open Folder", { Mod_Ctrl, Key_O }, open_icon, [&](auto&) {
|
||||||
Desktop::Launcher::open(URL::create_with_file_scheme(get_absolute_path_to_selected_node(treemapwidget)));
|
Desktop::Launcher::open(URL::create_with_file_scheme(get_absolute_path_to_selected_node(tree_map_widget)));
|
||||||
});
|
});
|
||||||
auto open_containing_folder_action = GUI::Action::create("Open Containing Folder", { Mod_Ctrl, Key_O }, open_icon, [&](auto&) {
|
auto open_containing_folder_action = GUI::Action::create("Open Containing Folder", { Mod_Ctrl, Key_O }, open_icon, [&](auto&) {
|
||||||
LexicalPath path { get_absolute_path_to_selected_node(treemapwidget) };
|
LexicalPath path { get_absolute_path_to_selected_node(tree_map_widget) };
|
||||||
Desktop::Launcher::open(URL::create_with_file_scheme(path.dirname(), path.basename()));
|
Desktop::Launcher::open(URL::create_with_file_scheme(path.dirname(), path.basename()));
|
||||||
});
|
});
|
||||||
|
|
||||||
auto copy_icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png"sv));
|
auto copy_icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png"sv));
|
||||||
auto copy_path_action = GUI::Action::create("Copy Path to Clipboard", { Mod_Ctrl, Key_C }, copy_icon, [&](auto&) {
|
auto copy_path_action = GUI::Action::create("Copy Path to Clipboard", { Mod_Ctrl, Key_C }, copy_icon, [&](auto&) {
|
||||||
GUI::Clipboard::the().set_plain_text(get_absolute_path_to_selected_node(treemapwidget));
|
GUI::Clipboard::the().set_plain_text(get_absolute_path_to_selected_node(tree_map_widget));
|
||||||
});
|
});
|
||||||
auto delete_action = GUI::CommonActions::make_delete_action([&](auto&) {
|
auto delete_action = GUI::CommonActions::make_delete_action([&](auto&) {
|
||||||
DeprecatedString selected_node_path = get_absolute_path_to_selected_node(treemapwidget);
|
DeprecatedString selected_node_path = get_absolute_path_to_selected_node(tree_map_widget);
|
||||||
bool try_again = true;
|
bool try_again = true;
|
||||||
while (try_again) {
|
while (try_again) {
|
||||||
try_again = false;
|
try_again = false;
|
||||||
|
@ -118,7 +118,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto result = treemapwidget.analyze(statusbar); result.is_error()) {
|
if (auto result = tree_map_widget.analyze(statusbar); result.is_error()) {
|
||||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error()));
|
GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -131,37 +131,37 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
// Configure event handlers.
|
// Configure event handlers.
|
||||||
breadcrumbbar.on_segment_click = [&](size_t index) {
|
breadcrumbbar.on_segment_click = [&](size_t index) {
|
||||||
VERIFY(index < treemapwidget.path_size());
|
VERIFY(index < tree_map_widget.path_size());
|
||||||
treemapwidget.set_viewpoint(index);
|
tree_map_widget.set_viewpoint(index);
|
||||||
};
|
};
|
||||||
treemapwidget.on_path_change = [&]() {
|
tree_map_widget.on_path_change = [&]() {
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
breadcrumbbar.clear_segments();
|
breadcrumbbar.clear_segments();
|
||||||
for (size_t k = 0; k < treemapwidget.path_size(); k++) {
|
for (size_t k = 0; k < tree_map_widget.path_size(); k++) {
|
||||||
if (k == 0) {
|
if (k == 0) {
|
||||||
if (treemapwidget.viewpoint() == 0)
|
if (tree_map_widget.viewpoint() == 0)
|
||||||
window->set_title("/ - SpaceAnalyzer");
|
window->set_title("/ - SpaceAnalyzer");
|
||||||
|
|
||||||
breadcrumbbar.append_segment("/", GUI::FileIconProvider::icon_for_path("/").bitmap_for_size(16), "/", "/");
|
breadcrumbbar.append_segment("/", GUI::FileIconProvider::icon_for_path("/").bitmap_for_size(16), "/", "/");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TreeNode* node = treemapwidget.path_node(k);
|
const TreeNode* node = tree_map_widget.path_node(k);
|
||||||
|
|
||||||
builder.append('/');
|
builder.append('/');
|
||||||
builder.append(node->name());
|
builder.append(node->name());
|
||||||
|
|
||||||
// Sneakily set the window title here, while the StringBuilder holds the right amount of the path.
|
// Sneakily set the window title here, while the StringBuilder holds the right amount of the path.
|
||||||
if (k == treemapwidget.viewpoint())
|
if (k == tree_map_widget.viewpoint())
|
||||||
window->set_title(DeprecatedString::formatted("{} - SpaceAnalyzer", builder.string_view()));
|
window->set_title(DeprecatedString::formatted("{} - SpaceAnalyzer", builder.string_view()));
|
||||||
|
|
||||||
breadcrumbbar.append_segment(node->name(), GUI::FileIconProvider::icon_for_path(builder.string_view()).bitmap_for_size(16), builder.string_view(), builder.string_view());
|
breadcrumbbar.append_segment(node->name(), GUI::FileIconProvider::icon_for_path(builder.string_view()).bitmap_for_size(16), builder.string_view(), builder.string_view());
|
||||||
}
|
}
|
||||||
breadcrumbbar.set_selected_segment(treemapwidget.viewpoint());
|
breadcrumbbar.set_selected_segment(tree_map_widget.viewpoint());
|
||||||
};
|
};
|
||||||
treemapwidget.on_context_menu_request = [&](const GUI::ContextMenuEvent& event) {
|
tree_map_widget.on_context_menu_request = [&](const GUI::ContextMenuEvent& event) {
|
||||||
DeprecatedString selected_node_path = get_absolute_path_to_selected_node(treemapwidget);
|
DeprecatedString selected_node_path = get_absolute_path_to_selected_node(tree_map_widget);
|
||||||
if (selected_node_path.is_empty())
|
if (selected_node_path.is_empty())
|
||||||
return;
|
return;
|
||||||
delete_action->set_enabled(Core::File::can_delete_or_move(selected_node_path));
|
delete_action->set_enabled(Core::File::can_delete_or_move(selected_node_path));
|
||||||
|
@ -176,7 +176,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
};
|
};
|
||||||
|
|
||||||
// At startup automatically do an analysis of root.
|
// At startup automatically do an analysis of root.
|
||||||
TRY(treemapwidget.analyze(statusbar));
|
TRY(tree_map_widget.analyze(statusbar));
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
return app->exec();
|
return app->exec();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue