FileManager+LibGUI+html: Add an icon to represent HTML files

This also becomes the app icon for the little "html" program. :^)
This commit is contained in:
Andreas Kling 2019-09-29 21:00:41 +02:00
parent e38b454e11
commit 3900eebf15
Notes: sideshowbarker 2024-07-19 11:53:01 +09:00
6 changed files with 36 additions and 0 deletions

View file

@ -53,6 +53,16 @@ void DirectoryView::handle_activation(const GModelIndex& index)
return;
}
if (path.to_lowercase().ends_with(".html")) {
if (fork() == 0) {
int rc = execl("/bin/html", "/bin/html", path.characters(), nullptr);
if (rc < 0)
perror("exec");
ASSERT_NOT_REACHED();
}
return;
}
if (path.to_lowercase().ends_with(".wav")) {
if (fork() == 0) {
int rc = execl("/bin/SoundPlayer", "/bin/SoundPlayer", path.characters(), nullptr);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

View file

@ -34,6 +34,7 @@ GDirectoryModel::GDirectoryModel()
m_executable_icon = GIcon::default_icon("filetype-executable");
m_filetype_image_icon = GIcon::default_icon("filetype-image");
m_filetype_sound_icon = GIcon::default_icon("filetype-sound");
m_filetype_html_icon = GIcon::default_icon("filetype-html");
setpwent();
while (auto* passwd = getpwent())
@ -159,6 +160,8 @@ GIcon GDirectoryModel::icon_for(const Entry& entry) const
return m_executable_icon;
if (entry.name.to_lowercase().ends_with(".wav"))
return m_filetype_sound_icon;
if (entry.name.to_lowercase().ends_with(".html"))
return m_filetype_html_icon;
if (entry.name.to_lowercase().ends_with(".png")) {
if (!entry.thumbnail) {
if (!const_cast<GDirectoryModel*>(this)->fetch_thumbnail_for(entry))

View file

@ -78,6 +78,7 @@ private:
GIcon m_executable_icon;
GIcon m_filetype_image_icon;
GIcon m_filetype_sound_icon;
GIcon m_filetype_html_icon;
HashMap<uid_t, String> m_user_names;
HashMap<gid_t, String> m_group_names;

View file

@ -1,5 +1,9 @@
#include <LibCore/CFile.h>
#include <LibGUI/GAboutDialog.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GMenu.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GWindow.h>
#include <LibHTML/CSS/StyleResolver.h>
#include <LibHTML/DOM/Element.h>
@ -48,5 +52,23 @@ int main(int argc, char** argv)
window->set_main_widget(widget);
window->show();
auto menubar = make<GMenuBar>();
auto app_menu = make<GMenu>("HTML");
app_menu->add_action(GCommonActions::make_quit_action([&](auto&) {
app.quit();
}));
menubar->add_menu(move(app_menu));
auto help_menu = make<GMenu>("Help");
help_menu->add_action(GAction::create("About", [&](const GAction&) {
GAboutDialog::show("HTML", GraphicsBitmap::load_from_file("/res/icons/32x32/filetype-html.png"), window);
}));
menubar->add_menu(move(help_menu));
app.set_menubar(move(menubar));
window->set_icon(GraphicsBitmap::load_from_file("/res/icons/16x16/filetype-html.png"));
return app.exec();
}