diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2012-08-14 06:42:42 -0400 |
|---|---|---|
| committer | Tarmac <> | 2012-08-14 06:42:42 -0400 |
| commit | 477a9ce0d85fb9277218b7d8dbb65b89703cc1d9 (patch) | |
| tree | 9149b92ae672e31241c7bb36620fd2a31e88549b | |
| parent | d7654460cd6a09a13be0b9f43ac7cc4690649d9c (diff) | |
| parent | 00695004aceb0c495545a0e06d5b5ba93fab0c4b (diff) | |
QuicklistMenuitem, BFBLauncherIcon: don't close the Dash when clicking on BFB quicklist items. Fixes: https://bugs.launchpad.net/bugs/1035641. Approved by Tim Penhey.
(bzr r2561)
| -rw-r--r-- | launcher/BFBLauncherIcon.cpp | 2 | ||||
| -rw-r--r-- | launcher/BamfLauncherIcon.cpp | 4 | ||||
| -rw-r--r-- | launcher/QuicklistMenuItem.cpp | 25 | ||||
| -rw-r--r-- | launcher/QuicklistMenuItem.h | 4 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | tests/test_bfb_launcher_icon.cpp | 54 | ||||
| -rw-r--r-- | tests/test_quicklist_menu_item.cpp | 72 |
7 files changed, 154 insertions, 8 deletions
diff --git a/launcher/BFBLauncherIcon.cpp b/launcher/BFBLauncherIcon.cpp index 394106cf1..bab32d7e8 100644 --- a/launcher/BFBLauncherIcon.cpp +++ b/launcher/BFBLauncherIcon.cpp @@ -118,6 +118,7 @@ std::list<DbusmenuMenuitem*> BFBLauncherIcon::GetMenus() dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Dash Home")); dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true); dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true); + dbusmenu_menuitem_property_set_bool(menu_item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY, true); g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, @@ -137,6 +138,7 @@ std::list<DbusmenuMenuitem*> BFBLauncherIcon::GetMenus() dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, lens->name); dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true); dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true); + dbusmenu_menuitem_property_set_bool(menu_item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY, true); g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, diff --git a/launcher/BamfLauncherIcon.cpp b/launcher/BamfLauncherIcon.cpp index c686ae122..32ab60eaa 100644 --- a/launcher/BamfLauncherIcon.cpp +++ b/launcher/BamfLauncherIcon.cpp @@ -976,7 +976,7 @@ std::list<DbusmenuMenuitem*> BamfLauncherIcon::GetMenus() if (dbusmenu_menuitem_property_get_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE)) { first_separator_needed = true; - dbusmenu_menuitem_property_set_bool(item, "unity-use-markup", FALSE); + dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::MARKUP_ENABLED_PROPERTY, FALSE); result.push_back(item); } @@ -1038,7 +1038,7 @@ std::list<DbusmenuMenuitem*> BamfLauncherIcon::GetMenus() DBUSMENU_MENUITEM_PROP_ENABLED, true); dbusmenu_menuitem_property_set_bool(item, - "unity-use-markup", + QuicklistMenuItem::MARKUP_ENABLED_PROPERTY, true); _gsignals.Add(new glib::Signal<void, DbusmenuMenuitem*, int>(item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, diff --git a/launcher/QuicklistMenuItem.cpp b/launcher/QuicklistMenuItem.cpp index 183549ece..00282baf9 100644 --- a/launcher/QuicklistMenuItem.cpp +++ b/launcher/QuicklistMenuItem.cpp @@ -28,6 +28,8 @@ namespace unity { +const char* QuicklistMenuItem::MARKUP_ENABLED_PROPERTY = "unity-use-markup"; +const char* QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY = "unity-overlay-item"; NUX_IMPLEMENT_OBJECT_TYPE(QuicklistMenuItem); @@ -127,12 +129,16 @@ std::string QuicklistMenuItem::GetText() const void QuicklistMenuItem::Activate() const { - if (!_menu_item) + if (!_menu_item || !GetSelectable()) return; dbusmenu_menuitem_handle_event(_menu_item, "clicked", nullptr, 0); - UBusManager manager; - manager.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST); + + if (!IsOverlayQuicklist()) + { + UBusManager manager; + manager.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST); + } } void QuicklistMenuItem::Select(bool select) @@ -333,7 +339,7 @@ void QuicklistMenuItem::EnableLabelMarkup(bool enabled) { if (IsMarkupEnabled() != enabled) { - dbusmenu_menuitem_property_set_bool(_menu_item, "unity-use-markup", enabled); + dbusmenu_menuitem_property_set_bool(_menu_item, MARKUP_ENABLED_PROPERTY, enabled); _text = ""; InitializeText(); @@ -345,10 +351,19 @@ bool QuicklistMenuItem::IsMarkupEnabled() const if (!_menu_item) return false; - gboolean markup = dbusmenu_menuitem_property_get_bool(_menu_item, "unity-use-markup"); + gboolean markup = dbusmenu_menuitem_property_get_bool(_menu_item, MARKUP_ENABLED_PROPERTY); return (markup != FALSE); } +bool QuicklistMenuItem::IsOverlayQuicklist() const +{ + if (!_menu_item) + return false; + + gboolean overlay = dbusmenu_menuitem_property_get_bool(_menu_item, OVERLAY_MENU_ITEM_PROPERTY); + return (overlay != FALSE); +} + unsigned QuicklistMenuItem::GetCairoSurfaceWidth() const { if (!_normalTexture[0]) diff --git a/launcher/QuicklistMenuItem.h b/launcher/QuicklistMenuItem.h index 3a25b8eb9..704bc5f51 100644 --- a/launcher/QuicklistMenuItem.h +++ b/launcher/QuicklistMenuItem.h @@ -61,6 +61,7 @@ public: void EnableLabelMarkup(bool enabled); bool IsMarkupEnabled() const; + bool IsOverlayQuicklist() const; void Activate() const; @@ -79,6 +80,9 @@ public: sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseClick; sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag; + static const char* MARKUP_ENABLED_PROPERTY; + static const char* OVERLAY_MENU_ITEM_PROPERTY; + protected: // Introspection std::string GetName() const; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9e43ed69f..26adb31cf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -200,6 +200,7 @@ if (GTEST_SRC_DIR AND add_executable(test-gtest test_main.cpp test_bamflaunchericon.cpp + test_bfb_launcher_icon.cpp test_dashview_impl.cpp test_edge_barrier_controller.cpp test_launcher.cpp diff --git a/tests/test_bfb_launcher_icon.cpp b/tests/test_bfb_launcher_icon.cpp new file mode 100644 index 000000000..858469d5e --- /dev/null +++ b/tests/test_bfb_launcher_icon.cpp @@ -0,0 +1,54 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with this program. If not, see + * <http://www.gnu.org/licenses/> + * + * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com> + */ + +#include <gmock/gmock.h> + +#include "BFBLauncherIcon.h" + +using namespace unity; +using namespace unity::launcher; + +namespace +{ + +class MockBFBLauncherIcon : public BFBLauncherIcon +{ +public: + MockBFBLauncherIcon() + : BFBLauncherIcon(LauncherHideMode::LAUNCHER_HIDE_NEVER) + {} + + std::list<DbusmenuMenuitem*> GetMenus() + { + return BFBLauncherIcon::GetMenus(); + } +}; + +TEST(TestBFBLauncherIcon, OverlayMenus) +{ + MockBFBLauncherIcon bfb; + + for (auto menu_item : bfb.GetMenus()) + { + bool overlay_item = dbusmenu_menuitem_property_get_bool(menu_item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY); + ASSERT_TRUE(overlay_item); + } +} + +} diff --git a/tests/test_quicklist_menu_item.cpp b/tests/test_quicklist_menu_item.cpp index 47289c3d8..dbba9d078 100644 --- a/tests/test_quicklist_menu_item.cpp +++ b/tests/test_quicklist_menu_item.cpp @@ -20,12 +20,16 @@ #include <gmock/gmock.h> #include <libdbusmenu-glib/client.h> +#include <UnityCore/GLibSignal.h> #include "QuicklistMenuItem.h" #include "QuicklistMenuItemCheckmark.h" #include "QuicklistMenuItemLabel.h" #include "QuicklistMenuItemRadio.h" #include "QuicklistMenuItemSeparator.h" +#include "unity-shared/UBusWrapper.h" +#include "unity-shared/UBusMessages.h" +#include "test_utils.h" using namespace unity; using namespace testing; @@ -64,7 +68,7 @@ TEST_F(TestQuicklistMenuItem, QuicklistMenuItemLabel) { dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "A Label"); dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true); - dbusmenu_menuitem_property_set_bool(item, "unity-use-markup", true); + dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::MARKUP_ENABLED_PROPERTY, true); nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item)); @@ -104,4 +108,70 @@ TEST_F(TestQuicklistMenuItem, QuicklistMenuItemSeparator) EXPECT_FALSE(qlitem->GetSelectable()); } +TEST_F(TestQuicklistMenuItem, OverlayMenuitem) +{ + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label"); + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true); + + nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item)); + + EXPECT_FALSE(qlitem->IsOverlayQuicklist()); + + dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY, true); + EXPECT_TRUE(qlitem->IsOverlayQuicklist()); +} + +TEST_F(TestQuicklistMenuItem, ItemActivate) +{ + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label"); + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true); + + nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item)); + + bool item_activated = false; + glib::Signal<void, DbusmenuMenuitem*, int> signal(item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + [&] (DbusmenuMenuitem* menu_item, int time) { + EXPECT_EQ(menu_item, item); + item_activated = true; + }); + + qlitem->Activate(); + EXPECT_TRUE(item_activated); +} + +TEST_F(TestQuicklistMenuItem, ItemActivateClosesDash) +{ + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label"); + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true); + + nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item)); + + bool closes_dash = false; + UBusManager manager; + manager.RegisterInterest(UBUS_PLACE_VIEW_CLOSE_REQUEST, [&] (GVariant*) { closes_dash = true; }); + + qlitem->Activate(); + Utils::WaitUntil(closes_dash); + + EXPECT_TRUE(closes_dash); +} + +TEST_F(TestQuicklistMenuItem, OverlayItemActivateDoesNotCloseDash) +{ + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label"); + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true); + dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY, true); + + nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item)); + + bool closes_dash = false; + UBusManager manager; + manager.RegisterInterest(UBUS_PLACE_VIEW_CLOSE_REQUEST, [&] (GVariant*) { closes_dash = true; }); + + qlitem->Activate(); + Utils::WaitForTimeoutMSec(100); + + EXPECT_FALSE(closes_dash); +} + } |
