summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-19 21:37:25 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-19 21:37:25 +0200
commitf286eb7fcdf8fab0ff1f5859d1cf609b40e396c2 (patch)
treeaedc3eb4913f8e9fae9b2e4c2986526cb93258ec
parentdc696ba85c2bf359da389db521fd136c2e4e7ee2 (diff)
downloadserenity-f286eb7fcdf8fab0ff1f5859d1cf609b40e396c2.zip
FileManager: Show a special icon for the home directory
The home-directory icon now shows up in the FileManager title bar, and alongside the path in the location textbox. Very nice. :^)
-rw-r--r--Applications/FileManager/main.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp
index 474d7bf9db..7aba46befa 100644
--- a/Applications/FileManager/main.cpp
+++ b/Applications/FileManager/main.cpp
@@ -66,6 +66,18 @@
static int run_in_desktop_mode(RefPtr<Core::ConfigFile>, String initial_location);
static int run_in_windowed_mode(RefPtr<Core::ConfigFile>, String initial_location);
+static Gfx::Bitmap& folder_icon()
+{
+ static RefPtr<Gfx::Bitmap> icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-folder.png");
+ return *icon;
+}
+
+static Gfx::Bitmap& home_directory_icon()
+{
+ static RefPtr<Gfx::Bitmap> icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/home-directory.png");
+ return *icon;
+}
+
int main(int argc, char** argv)
{
if (pledge("stdio thread shared_buffer accept unix cpath rpath wpath fattr proc exec sigaction", nullptr) < 0) {
@@ -256,7 +268,6 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
auto& location_textbox = location_toolbar.add<GUI::TextBox>();
location_textbox.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
location_textbox.set_preferred_size(0, 22);
- location_textbox.set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-folder.png"));
auto& splitter = widget.add<GUI::HorizontalSplitter>();
auto& tree_view = splitter.add<GUI::TreeView>();
@@ -697,6 +708,15 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
main_toolbar.add_action(*view_as_columns_action);
directory_view.on_path_change = [&](const String& new_path) {
+ const Gfx::Bitmap* icon = nullptr;
+ if (new_path == Core::StandardPaths::home_directory())
+ icon = &home_directory_icon();
+ else
+ icon = &folder_icon();
+
+ window->set_icon(icon);
+ location_textbox.set_icon(icon);
+
window->set_title(String::format("%s - File Manager", new_path.characters()));
location_textbox.set_text(new_path);
auto new_index = directories_model->index(new_path, GUI::FileSystemModel::Column::Name);
@@ -916,8 +936,6 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
window->show();
- window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-folder.png"));
-
// Read direcory read mode from config.
auto dir_view_mode = config->read_entry("DirectoryView", "ViewMode", "Icon");