From 5f4f42b4d9e05f9dba5b8a86b68b360310b64942 Mon Sep 17 00:00:00 2001 From: mpolosak <42770518+mpolosak@users.noreply.github.com> Date: Fri, 17 Apr 2020 16:05:24 +0200 Subject: [PATCH 1/5] Add 'label' varible to FileLauncherInfo struct --- src/panel/widgets/launchers.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/panel/widgets/launchers.cpp b/src/panel/widgets/launchers.cpp index cd11fb15..72bfb8a2 100644 --- a/src/panel/widgets/launchers.cpp +++ b/src/panel/widgets/launchers.cpp @@ -62,11 +62,16 @@ struct FileLauncherInfo : public LauncherInfo { std::string command; std::string icon; + std::string label; - bool load(std::string name, std::string icon) + bool load(std::string command, std::string icon, std::string label = "") { - command = name; + this->command = command; this->icon = icon; + if(label == "") + this->label = command; + else + this->label = label; return load_icon_pixbuf_safe(icon, 24).get() != nullptr; } @@ -78,7 +83,7 @@ struct FileLauncherInfo : public LauncherInfo std::string get_text() { - return command; + return label; } void execute() From 878ac3c99dfca24f5e68cae0c9b1b02ec8719a33 Mon Sep 17 00:00:00 2001 From: mpolosak <42770518+mpolosak@users.noreply.github.com> Date: Fri, 17 Apr 2020 16:38:13 +0200 Subject: [PATCH 2/5] Add label argument to WfLauncherButton::initialize() & pass it to f1->load() --- src/panel/widgets/launchers.cpp | 6 +++--- src/panel/widgets/launchers.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/panel/widgets/launchers.cpp b/src/panel/widgets/launchers.cpp index 72bfb8a2..972c3d62 100644 --- a/src/panel/widgets/launchers.cpp +++ b/src/panel/widgets/launchers.cpp @@ -64,7 +64,7 @@ struct FileLauncherInfo : public LauncherInfo std::string icon; std::string label; - bool load(std::string command, std::string icon, std::string label = "") + bool load(std::string command, std::string icon, std::string label) { this->command = command; this->icon = icon; @@ -109,7 +109,7 @@ void WfLauncherButton::set_size(int size) on_scale_update(); } -bool WfLauncherButton::initialize(std::string name, std::string icon) +bool WfLauncherButton::initialize(std::string name, std::string icon, std::string label) { launcher_name = name; base_size = WfOption {"panel/launcher_size"} / LAUNCHERS_ICON_SCALE; @@ -125,7 +125,7 @@ bool WfLauncherButton::initialize(std::string name, std::string icon) } else { auto fl = new FileLauncherInfo(); - if (!fl->load(name, icon)) + if (!fl->load(name, icon, label)) { std::cerr << "Failed to load icon " << icon << std::endl; return false; diff --git a/src/panel/widgets/launchers.hpp b/src/panel/widgets/launchers.hpp index 90ed023d..f4363a8b 100644 --- a/src/panel/widgets/launchers.hpp +++ b/src/panel/widgets/launchers.hpp @@ -49,7 +49,7 @@ struct WfLauncherButton WfLauncherButton& operator = (const WfLauncherButton&) = delete; ~WfLauncherButton(); - bool initialize(std::string name, std::string icon = "none"); + bool initialize(std::string name, std::string icon = "none", std::string label = ""); bool on_click(GdkEventButton *ev); bool on_enter(GdkEventCrossing *ev); From c73970e4b0cd435f17f70fb6f8d481934378fd74 Mon Sep 17 00:00:00 2001 From: mpolosak <42770518+mpolosak@users.noreply.github.com> Date: Fri, 17 Apr 2020 17:01:48 +0200 Subject: [PATCH 3/5] Get label value from config --- src/panel/widgets/launchers.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/panel/widgets/launchers.cpp b/src/panel/widgets/launchers.cpp index 972c3d62..00cdecb7 100644 --- a/src/panel/widgets/launchers.cpp +++ b/src/panel/widgets/launchers.cpp @@ -253,13 +253,14 @@ launcher_container WayfireLaunchers::get_launchers_from_config() const std::string desktop_prefix = "launcher_"; const std::string file_icon_prefix = "launcher_icon_"; const std::string file_cmd_prefix = "launcher_cmd_"; + const std::string file_label_prefix = "launcher_label_"; launcher_container launchers; auto try_push_launcher = [&launchers] ( - const std::string cmd, const std::string icon) + const std::string cmd, const std::string icon, const std::string label = "") { auto launcher = new WfLauncherButton(); - if (launcher->initialize(cmd, icon)) { + if (launcher->initialize(cmd, icon, label)) { launchers.push_back(std::unique_ptr(launcher)); } else { delete launcher; @@ -277,17 +278,25 @@ launcher_container WayfireLaunchers::get_launchers_from_config() auto icon_option = section->get_option_or(file_icon_prefix + launcher_name); if (icon_option) { - /* bingo, found command + icon */ - try_push_launcher(opt->get_value_str(), - icon_option->get_value_str()); + /* bingo, found command + icon + * now look for the corresponding label */ + auto label_option = section->get_option_or(file_label_prefix + launcher_name); + if(label_option) + { + /* found label */ + try_push_launcher(opt->get_value_str(), icon_option->get_value_str(), label_option->get_value_str()); + } else { + try_push_launcher(opt->get_value_str(), icon_option->get_value_str()); + } } } /* an entry is a deskop-file entry if the it has the desktop prefix - * but not the file_icon or file_cmd prefix */ + * but not the file_icon, file_cmd or file_label prefix */ if (begins_with(opt->get_name(), desktop_prefix) && !begins_with(opt->get_name(), file_icon_prefix) && - !begins_with(opt->get_name(), file_cmd_prefix)) + !begins_with(opt->get_name(), file_cmd_prefix) && + !begins_with(opt->get_name(), file_label_prefix)) { try_push_launcher(opt->get_value_str(), "none"); } From 70a831a65aaeda36faf2cca2e82b97553caa1e2f Mon Sep 17 00:00:00 2001 From: mpolosak <42770518+mpolosak@users.noreply.github.com> Date: Sun, 3 May 2020 12:45:52 +0200 Subject: [PATCH 4/5] Add braces for better readability --- src/panel/widgets/launchers.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/panel/widgets/launchers.cpp b/src/panel/widgets/launchers.cpp index 00cdecb7..0b5cdb1c 100644 --- a/src/panel/widgets/launchers.cpp +++ b/src/panel/widgets/launchers.cpp @@ -69,10 +69,11 @@ struct FileLauncherInfo : public LauncherInfo this->command = command; this->icon = icon; if(label == "") + { this->label = command; - else + } else { this->label = label; - + } return load_icon_pixbuf_safe(icon, 24).get() != nullptr; } From f3272c5280571dfbf89953ef34c5781d571658db Mon Sep 17 00:00:00 2001 From: mpolosak <42770518+mpolosak@users.noreply.github.com> Date: Sun, 3 May 2020 12:53:39 +0200 Subject: [PATCH 5/5] Brake to long line --- src/panel/widgets/launchers.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/panel/widgets/launchers.cpp b/src/panel/widgets/launchers.cpp index 0b5cdb1c..16d47e7f 100644 --- a/src/panel/widgets/launchers.cpp +++ b/src/panel/widgets/launchers.cpp @@ -285,7 +285,8 @@ launcher_container WayfireLaunchers::get_launchers_from_config() if(label_option) { /* found label */ - try_push_launcher(opt->get_value_str(), icon_option->get_value_str(), label_option->get_value_str()); + try_push_launcher(opt->get_value_str(), icon_option->get_value_str(), + label_option->get_value_str()); } else { try_push_launcher(opt->get_value_str(), icon_option->get_value_str()); }