Merge lp:~lukas-vacek/unity/bamficon_windowlist-raring into lp:unity
- bamficon_windowlist-raring
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Marco Trevisan (Treviño) |
Approved revision: | no longer in the source branch. |
Merged at revision: | 3143 |
Proposed branch: | lp:~lukas-vacek/unity/bamficon_windowlist-raring |
Merge into: | lp:unity |
Diff against target: |
308 lines (+191/-1) 7 files modified
launcher/ApplicationLauncherIcon.cpp (+59/-0) launcher/ApplicationLauncherIcon.h (+2/-0) launcher/QuicklistMenuItem.cpp (+24/-1) launcher/QuicklistMenuItem.h (+3/-0) tests/mock-application.h (+1/-0) tests/test_application_launcher_icon.cpp (+82/-0) tests/test_quicklist_menu_item.cpp (+20/-0) |
To merge this branch: | bzr merge lp:~lukas-vacek/unity/bamficon_windowlist-raring |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
John Lea (community) | design | Approve | |
Marco Trevisan (Treviño) | Approve | ||
PS Jenkins bot | continuous-integration | Pending | |
Review via email: mp+145676@code.launchpad.net |
Commit message
ApplicationLaun
(LP: #1107866)
Description of the change
Show a list of windows in a Launcher icon's Quicklist. (LP: #1107866)
Michael Terry (mterry) wrote : | # |
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
10 + WindowManager& wm = WindowManager:
11 + // delete all menu items for windows
…
29 + char menu_item_
30 + sprintf(
…
44 + _menu_items[
Please, don't add these items to _menu_items. Use instead another container (such as
std::vector<
22 + for ( auto w: Windows() ) {
Use for (auto const& w : Windows())
At that point call it into GetMenus() putting the items you computed into the result list.
36 + _gsignals.Add(
37 + new glib::Signal<void, DbusmenuMenuitem*, int>(menu_item,
You can use the utility Add function to save some space:
_gsignals.Add<void, DbusmenuMenuitem*, int>(menu_item, DBUSMENU_
39 + [w,&wm] (DbusmenuMenuit
Just pass w, while generate the WM inside the lambda body (even if that pointer won't change, it's safer not to pass by reference inside a lambda that is going to be executed when the local variable is dead). Also it's not needed to specify the "-> void" return type. g++ will guess it for you.
45 + std::string winName( ( wm.GetWindowName( w->window_id() ) ) );
46 + dbusmenu_
47 + DBUSMENU_
Only use:
dbusmenu_
51 + if (windows_added) {
52 + // add seperator
…
65 + }
Do this into GetMenus.
Also, long quicklist items should be cut. I'll provide I way to do it as I need it also on another branch, please ping me on IRC in case you'd need help.
Fix the style to match the one we use in unity (2 spaces indentation, brackets on next line)
Need tests.
John Lea (johnlea) wrote : | # |
Also the maximum string length of each Window title should be limited to 45 characters including spaces. Anything more than 45 characters should be chopped at 43 characters and have "..." applied to the end e.g.
"bamficon_
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
> Also the maximum string length of each Window title should be limited to 45
> characters including spaces. Anything more than 45 characters should be
> chopped at 43 characters and have "..." applied to the end e.g.
>
> "bamficon_
Yes, I agree with this (as I wrote above).
The fix for that is needed also by bug #893652 and will be provided by lp:~3v1n0/unity/quicklist-max-label-width.
Just set the QuicklistMenuIt
John Lea (johnlea) wrote : | # |
Update to my comment above:
- The max width should be 300px
- The window title should be ellipsized at the end
- This entry should only be displayed if there are 2 or more windows. If the application only has 1 or 0 windows open nothing should be displayed.
The format of the option should be:
=======
[application specific quicklist options area]
--------------
[application name]
--------------
Windows:
[window title 1]
[window title 2]
[window title 3]
--------------
Most recent files:
file one.odt
file two.odt
file three.odt
file four.odt
file five.odt
--------------
Keep in launcher
Quit
=======
thanks!
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
36 + // delete all menu items for windows
37 + _menu_items_
Please do this on EnsureMenuItems
17 + _gsignals.Add<void, DbusmenuMenuitem*, int>(menu_item, DBUSMENU_
18 + [w] (DbusmenuMenuit
This is ok, but since using [w] means copying the the WindowPtr, I'd prefer if you instead do:
Window xid = w->window_id();
_gsignals.Add<void, DbusmenuMenuitem*, int>(menu_item, DBUSMENU_
...
wm.Raise(xid);
}
22 + } );
Remove this padding, please (use also for the lambda two spaces for indenting).
24 + dbusmenu_
That property is an integer, you should do instead:
dbusmenu_
Where MAXIMUM_
40 + // add windows menu items
41 + if (_menu_
Mh, I'd prefer to iterate one more time than allocating some extra memory here, so just use if (Windows().size() > 1), and move EnsureMenuItems
Thanks ;)
Lukas Vacek (lukas-vacek) wrote : | # |
Thanks for your fast reply. I will fix that and push the changes tonight.
> 24 + dbusmenu_
> QuicklistMenuIt
>
> That property is an integer, you should do instead:
>
> dbusmenu_
> QuicklistMenuIt
>
> Where MAXIMUM_
> unnamed namespace that we have at the top of the ApplicationLaun
> file ;).
>
I am not sure about this one - to me it seems the property is const char* and it won't compile if I set it to an integer. I am not sure how to fix my code here.
Andrea Azzarone (azzar1) wrote : | # |
> Thanks for your fast reply. I will fix that and push the changes tonight.
>
> > 24 + dbusmenu_
> > QuicklistMenuIt
> >
> > That property is an integer, you should do instead:
> >
> > dbusmenu_
> > QuicklistMenuIt
> >
> > Where MAXIMUM_
> > unnamed namespace that we have at the top of the ApplicationLaun
> > file ;).
> >
>
> I am not sure about this one - to me it seems the property is const char* and
> it won't compile if I set it to an integer. I am not sure how to fix my code
> here.
Keep in mind you need to use dbusmenu_
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Ah, also... It would be needed an unit-test or AP test. If you need some guidance, ping me on IRC.
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
I think it's now ready to go in trunk... We have tests and correctly cut long entries!
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
New screenshot for design re-review: http://
John Lea (johnlea) wrote : | # |
Looks good to me now, thanks!
Preview Diff
1 | === modified file 'launcher/ApplicationLauncherIcon.cpp' | |||
2 | --- launcher/ApplicationLauncherIcon.cpp 2013-02-05 02:14:32 +0000 | |||
3 | +++ launcher/ApplicationLauncherIcon.cpp 2013-02-08 15:07:28 +0000 | |||
4 | @@ -51,6 +51,7 @@ | |||
5 | 51 | const std::string ICON_REMOVE_TIMEOUT = "bamf-icon-remove"; | 51 | const std::string ICON_REMOVE_TIMEOUT = "bamf-icon-remove"; |
6 | 52 | //const std::string ICON_DND_OVER_TIMEOUT = "bamf-icon-dnd-over"; | 52 | //const std::string ICON_DND_OVER_TIMEOUT = "bamf-icon-dnd-over"; |
7 | 53 | const std::string DEFAULT_ICON = "application-default-icon"; | 53 | const std::string DEFAULT_ICON = "application-default-icon"; |
8 | 54 | const int MAXIMUM_QUICKLIST_WIDTH = 300; | ||
9 | 54 | } | 55 | } |
10 | 55 | 56 | ||
11 | 56 | NUX_IMPLEMENT_OBJECT_TYPE(ApplicationLauncherIcon); | 57 | NUX_IMPLEMENT_OBJECT_TYPE(ApplicationLauncherIcon); |
12 | @@ -692,6 +693,42 @@ | |||
13 | 692 | EmitNeedsRedraw(); | 693 | EmitNeedsRedraw(); |
14 | 693 | } | 694 | } |
15 | 694 | 695 | ||
16 | 696 | void ApplicationLauncherIcon::EnsureMenuItemsWindowsReady() | ||
17 | 697 | { | ||
18 | 698 | // delete all menu items for windows | ||
19 | 699 | _menu_items_windows.clear(); | ||
20 | 700 | |||
21 | 701 | auto const& windows = Windows(); | ||
22 | 702 | |||
23 | 703 | // We only add quicklist menu-items for windows if we have more than one window | ||
24 | 704 | if (windows.size() < 2) | ||
25 | 705 | return; | ||
26 | 706 | |||
27 | 707 | // add menu items for all open windows | ||
28 | 708 | for (auto const& w : windows) | ||
29 | 709 | { | ||
30 | 710 | if (w->title().empty()) | ||
31 | 711 | continue; | ||
32 | 712 | |||
33 | 713 | glib::Object<DbusmenuMenuitem> menu_item(dbusmenu_menuitem_new()); | ||
34 | 714 | dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, w->title().c_str()); | ||
35 | 715 | dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true); | ||
36 | 716 | dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true); | ||
37 | 717 | dbusmenu_menuitem_property_set_bool(menu_item, QuicklistMenuItem::MARKUP_ACCEL_DISABLED_PROPERTY, true); | ||
38 | 718 | dbusmenu_menuitem_property_set_int(menu_item, QuicklistMenuItem::MAXIMUM_LABEL_WIDTH_PROPERTY, MAXIMUM_QUICKLIST_WIDTH); | ||
39 | 719 | |||
40 | 720 | Window xid = w->window_id(); | ||
41 | 721 | _gsignals.Add<void, DbusmenuMenuitem*, int>(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, | ||
42 | 722 | [xid] (DbusmenuMenuitem*, int) { | ||
43 | 723 | WindowManager& wm = WindowManager::Default(); | ||
44 | 724 | wm.Activate(xid); | ||
45 | 725 | wm.Raise(xid); | ||
46 | 726 | }); | ||
47 | 727 | |||
48 | 728 | _menu_items_windows.push_back(menu_item); | ||
49 | 729 | } | ||
50 | 730 | } | ||
51 | 731 | |||
52 | 695 | void ApplicationLauncherIcon::UpdateMenus() | 732 | void ApplicationLauncherIcon::UpdateMenus() |
53 | 696 | { | 733 | { |
54 | 697 | // add dynamic quicklist | 734 | // add dynamic quicklist |
55 | @@ -926,6 +963,28 @@ | |||
56 | 926 | } | 963 | } |
57 | 927 | result.push_back(item); | 964 | result.push_back(item); |
58 | 928 | 965 | ||
59 | 966 | EnsureMenuItemsWindowsReady(); | ||
60 | 967 | |||
61 | 968 | if (!_menu_items_windows.empty()) | ||
62 | 969 | { | ||
63 | 970 | for (auto const& it : _menu_items_windows) | ||
64 | 971 | result.push_back(it); | ||
65 | 972 | |||
66 | 973 | auto third_sep = _menu_items_extra.find("ThirdSeparator"); | ||
67 | 974 | if (third_sep != _menu_items_extra.end()) | ||
68 | 975 | { | ||
69 | 976 | item = third_sep->second; | ||
70 | 977 | } | ||
71 | 978 | else | ||
72 | 979 | { | ||
73 | 980 | item = dbusmenu_menuitem_new(); | ||
74 | 981 | dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); | ||
75 | 982 | _menu_items_extra["ThirdSeparator"] = glib::Object<DbusmenuMenuitem>(item); | ||
76 | 983 | } | ||
77 | 984 | |||
78 | 985 | result.push_back(item); | ||
79 | 986 | } | ||
80 | 987 | |||
81 | 929 | EnsureMenuItemsReady(); | 988 | EnsureMenuItemsReady(); |
82 | 930 | 989 | ||
83 | 931 | for (auto it : _menu_items) | 990 | for (auto it : _menu_items) |
84 | 932 | 991 | ||
85 | === modified file 'launcher/ApplicationLauncherIcon.h' | |||
86 | --- launcher/ApplicationLauncherIcon.h 2013-02-05 02:14:32 +0000 | |||
87 | +++ launcher/ApplicationLauncherIcon.h 2013-02-08 15:07:28 +0000 | |||
88 | @@ -108,6 +108,7 @@ | |||
89 | 108 | }; | 108 | }; |
90 | 109 | 109 | ||
91 | 110 | void EnsureWindowState(); | 110 | void EnsureWindowState(); |
92 | 111 | void EnsureMenuItemsWindowsReady(); | ||
93 | 111 | void EnsureMenuItemsReady(); | 112 | void EnsureMenuItemsReady(); |
94 | 112 | void UpdateBackgroundColor(); | 113 | void UpdateBackgroundColor(); |
95 | 113 | void UpdateMenus(); | 114 | void UpdateMenus(); |
96 | @@ -130,6 +131,7 @@ | |||
97 | 130 | std::map<std::string, glib::Object<DbusmenuClient>> _menu_clients; | 131 | std::map<std::string, glib::Object<DbusmenuClient>> _menu_clients; |
98 | 131 | std::map<std::string, glib::Object<DbusmenuMenuitem>> _menu_items; | 132 | std::map<std::string, glib::Object<DbusmenuMenuitem>> _menu_items; |
99 | 132 | std::map<std::string, glib::Object<DbusmenuMenuitem>> _menu_items_extra; | 133 | std::map<std::string, glib::Object<DbusmenuMenuitem>> _menu_items_extra; |
100 | 134 | std::vector<glib::Object<DbusmenuMenuitem>> _menu_items_windows; | ||
101 | 133 | glib::Object<IndicatorDesktopShortcuts> _desktop_shortcuts; | 135 | glib::Object<IndicatorDesktopShortcuts> _desktop_shortcuts; |
102 | 134 | glib::Object<DbusmenuMenuitem> _menu_desktop_shortcuts; | 136 | glib::Object<DbusmenuMenuitem> _menu_desktop_shortcuts; |
103 | 135 | glib::Object<GFileMonitor> _desktop_file_monitor; | 137 | glib::Object<GFileMonitor> _desktop_file_monitor; |
104 | 136 | 138 | ||
105 | === modified file 'launcher/QuicklistMenuItem.cpp' | |||
106 | --- launcher/QuicklistMenuItem.cpp 2013-01-31 14:54:19 +0000 | |||
107 | +++ launcher/QuicklistMenuItem.cpp 2013-02-08 15:07:28 +0000 | |||
108 | @@ -29,6 +29,7 @@ | |||
109 | 29 | namespace unity | 29 | namespace unity |
110 | 30 | { | 30 | { |
111 | 31 | const char* QuicklistMenuItem::MARKUP_ENABLED_PROPERTY = "unity-use-markup"; | 31 | const char* QuicklistMenuItem::MARKUP_ENABLED_PROPERTY = "unity-use-markup"; |
112 | 32 | const char* QuicklistMenuItem::MARKUP_ACCEL_DISABLED_PROPERTY = "unity-disable-accel"; | ||
113 | 32 | const char* QuicklistMenuItem::MAXIMUM_LABEL_WIDTH_PROPERTY = "unity-max-label-width"; | 33 | const char* QuicklistMenuItem::MAXIMUM_LABEL_WIDTH_PROPERTY = "unity-max-label-width"; |
114 | 33 | const char* QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY = "unity-overlay-item"; | 34 | const char* QuicklistMenuItem::OVERLAY_MENU_ITEM_PROPERTY = "unity-overlay-item"; |
115 | 34 | 35 | ||
116 | @@ -280,7 +281,11 @@ | |||
117 | 280 | std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free); | 281 | std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free); |
118 | 281 | pango_layout_set_font_description(layout, desc.get()); | 282 | pango_layout_set_font_description(layout, desc.get()); |
119 | 282 | pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); | 283 | pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); |
121 | 283 | pango_layout_set_markup_with_accel(layout, _text.c_str(), -1, '_', nullptr); | 284 | |
122 | 285 | if (IsMarkupAccelEnabled()) | ||
123 | 286 | pango_layout_set_markup_with_accel(layout, _text.c_str(), -1, '_', nullptr); | ||
124 | 287 | else | ||
125 | 288 | pango_layout_set_markup(layout, _text.c_str(), -1); | ||
126 | 284 | 289 | ||
127 | 285 | if (GetMaxLabelWidth() > 0) | 290 | if (GetMaxLabelWidth() > 0) |
128 | 286 | { | 291 | { |
129 | @@ -360,6 +365,24 @@ | |||
130 | 360 | return (markup != FALSE); | 365 | return (markup != FALSE); |
131 | 361 | } | 366 | } |
132 | 362 | 367 | ||
133 | 368 | void QuicklistMenuItem::EnableLabelMarkupAccel(bool enabled) | ||
134 | 369 | { | ||
135 | 370 | if (IsMarkupAccelEnabled() != enabled) | ||
136 | 371 | { | ||
137 | 372 | dbusmenu_menuitem_property_set_bool(_menu_item, MARKUP_ACCEL_DISABLED_PROPERTY, enabled ? FALSE : TRUE); | ||
138 | 373 | InitializeText(); | ||
139 | 374 | } | ||
140 | 375 | } | ||
141 | 376 | |||
142 | 377 | bool QuicklistMenuItem::IsMarkupAccelEnabled() const | ||
143 | 378 | { | ||
144 | 379 | if (!_menu_item) | ||
145 | 380 | return false; | ||
146 | 381 | |||
147 | 382 | gboolean disabled = dbusmenu_menuitem_property_get_bool(_menu_item, MARKUP_ACCEL_DISABLED_PROPERTY); | ||
148 | 383 | return (disabled == FALSE); | ||
149 | 384 | } | ||
150 | 385 | |||
151 | 363 | void QuicklistMenuItem::SetMaxLabelWidth(int max_width) | 386 | void QuicklistMenuItem::SetMaxLabelWidth(int max_width) |
152 | 364 | { | 387 | { |
153 | 365 | if (GetMaxLabelWidth() != max_width) | 388 | if (GetMaxLabelWidth() != max_width) |
154 | 366 | 389 | ||
155 | === modified file 'launcher/QuicklistMenuItem.h' | |||
156 | --- launcher/QuicklistMenuItem.h 2013-01-31 13:41:35 +0000 | |||
157 | +++ launcher/QuicklistMenuItem.h 2013-02-08 15:07:28 +0000 | |||
158 | @@ -61,6 +61,8 @@ | |||
159 | 61 | 61 | ||
160 | 62 | void EnableLabelMarkup(bool enabled); | 62 | void EnableLabelMarkup(bool enabled); |
161 | 63 | bool IsMarkupEnabled() const; | 63 | bool IsMarkupEnabled() const; |
162 | 64 | void EnableLabelMarkupAccel(bool enabled); | ||
163 | 65 | bool IsMarkupAccelEnabled() const; | ||
164 | 64 | 66 | ||
165 | 65 | void SetMaxLabelWidth(int max_width); | 67 | void SetMaxLabelWidth(int max_width); |
166 | 66 | int GetMaxLabelWidth() const; | 68 | int GetMaxLabelWidth() const; |
167 | @@ -85,6 +87,7 @@ | |||
168 | 85 | sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag; | 87 | sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag; |
169 | 86 | 88 | ||
170 | 87 | static const char* MARKUP_ENABLED_PROPERTY; | 89 | static const char* MARKUP_ENABLED_PROPERTY; |
171 | 90 | static const char* MARKUP_ACCEL_DISABLED_PROPERTY; | ||
172 | 88 | static const char* MAXIMUM_LABEL_WIDTH_PROPERTY; | 91 | static const char* MAXIMUM_LABEL_WIDTH_PROPERTY; |
173 | 89 | static const char* OVERLAY_MENU_ITEM_PROPERTY; | 92 | static const char* OVERLAY_MENU_ITEM_PROPERTY; |
174 | 90 | 93 | ||
175 | 91 | 94 | ||
176 | === modified file 'tests/mock-application.h' | |||
177 | --- tests/mock-application.h 2013-02-05 02:10:45 +0000 | |||
178 | +++ tests/mock-application.h 2013-02-08 15:07:28 +0000 | |||
179 | @@ -30,6 +30,7 @@ | |||
180 | 30 | MockApplicationWindow(Window xid) | 30 | MockApplicationWindow(Window xid) |
181 | 31 | : xid_(xid) | 31 | : xid_(xid) |
182 | 32 | , monitor_(0) | 32 | , monitor_(0) |
183 | 33 | , title_("MockApplicationWindow "+std::to_string(xid_)) | ||
184 | 33 | , type_("window") | 34 | , type_("window") |
185 | 34 | , visible_(true) | 35 | , visible_(true) |
186 | 35 | , active_(false) | 36 | , active_(false) |
187 | 36 | 37 | ||
188 | === modified file 'tests/test_application_launcher_icon.cpp' | |||
189 | --- tests/test_application_launcher_icon.cpp 2013-02-05 02:14:46 +0000 | |||
190 | +++ tests/test_application_launcher_icon.cpp 2013-02-08 15:07:28 +0000 | |||
191 | @@ -180,4 +180,86 @@ | |||
192 | 180 | EXPECT_TRUE(mock_icon->IsActive()); | 180 | EXPECT_TRUE(mock_icon->IsActive()); |
193 | 181 | } | 181 | } |
194 | 182 | 182 | ||
195 | 183 | TEST_F(TestApplicationLauncherIcon, NoWindowListMenusWithOneWindow) | ||
196 | 184 | { | ||
197 | 185 | auto win = std::make_shared<MockApplicationWindow>(g_random_int()); | ||
198 | 186 | mock_app->window_list_ = { win }; | ||
199 | 187 | |||
200 | 188 | auto const& menus = mock_icon->Menus(); | ||
201 | 189 | auto menu_it = std::find_if(menus.begin(), menus.end(), [win] (glib::Object<DbusmenuMenuitem> it) { | ||
202 | 190 | auto* label = dbusmenu_menuitem_property_get(it, DBUSMENU_MENUITEM_PROP_LABEL); | ||
203 | 191 | return (label && std::string(label) == win->title()); | ||
204 | 192 | }); | ||
205 | 193 | |||
206 | 194 | EXPECT_EQ(menu_it, menus.end()); | ||
207 | 195 | } | ||
208 | 196 | |||
209 | 197 | TEST_F(TestApplicationLauncherIcon, WindowListMenusWithTwoWindows) | ||
210 | 198 | { | ||
211 | 199 | auto win1 = std::make_shared<MockApplicationWindow>(1); | ||
212 | 200 | auto wm_win1 = std::make_shared<StandaloneWindow>(win1->window_id()); | ||
213 | 201 | auto win2 = std::make_shared<MockApplicationWindow>(2); | ||
214 | 202 | auto wm_win2 = std::make_shared<StandaloneWindow>(win2->window_id()); | ||
215 | 203 | |||
216 | 204 | mock_app->window_list_ = { win1, win2 }; | ||
217 | 205 | WM->AddStandaloneWindow(wm_win1); | ||
218 | 206 | WM->AddStandaloneWindow(wm_win2); | ||
219 | 207 | ASSERT_TRUE(wm_win2->active()); | ||
220 | 208 | |||
221 | 209 | auto const& menus = mock_icon->Menus(); | ||
222 | 210 | |||
223 | 211 | auto menu1_it = std::find_if(menus.begin(), menus.end(), [win1] (glib::Object<DbusmenuMenuitem> it) { | ||
224 | 212 | auto* label = dbusmenu_menuitem_property_get(it, DBUSMENU_MENUITEM_PROP_LABEL); | ||
225 | 213 | return (label && std::string(label) == win1->title()); | ||
226 | 214 | }); | ||
227 | 215 | |||
228 | 216 | ASSERT_NE(menu1_it, menus.end()); | ||
229 | 217 | EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(*menu1_it, DBUSMENU_MENUITEM_PROP_ENABLED)); | ||
230 | 218 | EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(*menu1_it, DBUSMENU_MENUITEM_PROP_VISIBLE)); | ||
231 | 219 | EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(*menu1_it, QuicklistMenuItem::MARKUP_ACCEL_DISABLED_PROPERTY)); | ||
232 | 220 | EXPECT_EQ(dbusmenu_menuitem_property_get_int(*menu1_it, QuicklistMenuItem::MAXIMUM_LABEL_WIDTH_PROPERTY), 300); | ||
233 | 221 | |||
234 | 222 | auto menu2_it = std::find_if(menus.begin(), menus.end(), [win2] (glib::Object<DbusmenuMenuitem> it) { | ||
235 | 223 | auto* label = dbusmenu_menuitem_property_get(it, DBUSMENU_MENUITEM_PROP_LABEL); | ||
236 | 224 | return (label && std::string(label) == win2->title()); | ||
237 | 225 | }); | ||
238 | 226 | |||
239 | 227 | ASSERT_NE(menu2_it, menus.end()); | ||
240 | 228 | EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(*menu2_it, DBUSMENU_MENUITEM_PROP_ENABLED)); | ||
241 | 229 | EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(*menu2_it, DBUSMENU_MENUITEM_PROP_VISIBLE)); | ||
242 | 230 | EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(*menu2_it, QuicklistMenuItem::MARKUP_ACCEL_DISABLED_PROPERTY)); | ||
243 | 231 | EXPECT_EQ(dbusmenu_menuitem_property_get_int(*menu2_it, QuicklistMenuItem::MAXIMUM_LABEL_WIDTH_PROPERTY), 300); | ||
244 | 232 | |||
245 | 233 | bool activated = false; | ||
246 | 234 | wm_win1->active.changed.connect([&activated] (bool a) { activated = a; }); | ||
247 | 235 | g_signal_emit_by_name(*menu1_it, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, 0); | ||
248 | 236 | |||
249 | 237 | EXPECT_TRUE(wm_win1->active()); | ||
250 | 238 | EXPECT_TRUE(activated); | ||
251 | 239 | |||
252 | 240 | activated = false; | ||
253 | 241 | wm_win2->active.changed.connect([&activated] (bool a) { activated = a; }); | ||
254 | 242 | g_signal_emit_by_name(*menu2_it, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, 0); | ||
255 | 243 | |||
256 | 244 | EXPECT_TRUE(wm_win2->active()); | ||
257 | 245 | EXPECT_TRUE(activated); | ||
258 | 246 | } | ||
259 | 247 | |||
260 | 248 | TEST_F(TestApplicationLauncherIcon, WindowListMenusWithEmptyTitles) | ||
261 | 249 | { | ||
262 | 250 | auto win1 = std::make_shared<MockApplicationWindow>(1); | ||
263 | 251 | auto win2 = std::make_shared<MockApplicationWindow>(2); | ||
264 | 252 | win1->title_.clear(); | ||
265 | 253 | |||
266 | 254 | mock_app->window_list_ = { win1, win2 }; | ||
267 | 255 | auto const& menus = mock_icon->Menus(); | ||
268 | 256 | |||
269 | 257 | auto menu1_it = std::find_if(menus.begin(), menus.end(), [win1] (glib::Object<DbusmenuMenuitem> it) { | ||
270 | 258 | auto* label = dbusmenu_menuitem_property_get(it, DBUSMENU_MENUITEM_PROP_LABEL); | ||
271 | 259 | return (label && std::string(label) == win1->title()); | ||
272 | 260 | }); | ||
273 | 261 | |||
274 | 262 | ASSERT_EQ(menu1_it, menus.end()); | ||
275 | 263 | } | ||
276 | 264 | |||
277 | 183 | } | 265 | } |
278 | 184 | 266 | ||
279 | === modified file 'tests/test_quicklist_menu_item.cpp' | |||
280 | --- tests/test_quicklist_menu_item.cpp 2013-01-31 13:43:13 +0000 | |||
281 | +++ tests/test_quicklist_menu_item.cpp 2013-02-08 15:07:28 +0000 | |||
282 | @@ -139,6 +139,26 @@ | |||
283 | 139 | EXPECT_EQ(dbusmenu_menuitem_property_get_int(item, QuicklistMenuItem::MAXIMUM_LABEL_WIDTH_PROPERTY), max_width); | 139 | EXPECT_EQ(dbusmenu_menuitem_property_get_int(item, QuicklistMenuItem::MAXIMUM_LABEL_WIDTH_PROPERTY), max_width); |
284 | 140 | } | 140 | } |
285 | 141 | 141 | ||
286 | 142 | TEST_F(TestQuicklistMenuItem, MarkupAccelEnabled) | ||
287 | 143 | { | ||
288 | 144 | dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label"); | ||
289 | 145 | dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, true); | ||
290 | 146 | |||
291 | 147 | nux::ObjectPtr<QuicklistMenuItemLabel> qlitem(new QuicklistMenuItemLabel(item)); | ||
292 | 148 | EXPECT_TRUE(qlitem->IsMarkupAccelEnabled()); | ||
293 | 149 | |||
294 | 150 | dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::MARKUP_ACCEL_DISABLED_PROPERTY, true); | ||
295 | 151 | EXPECT_FALSE(qlitem->IsMarkupAccelEnabled()); | ||
296 | 152 | |||
297 | 153 | qlitem->EnableLabelMarkupAccel(true); | ||
298 | 154 | EXPECT_TRUE(qlitem->IsMarkupAccelEnabled()); | ||
299 | 155 | EXPECT_FALSE(dbusmenu_menuitem_property_get_bool(item, QuicklistMenuItem::MARKUP_ACCEL_DISABLED_PROPERTY)); | ||
300 | 156 | |||
301 | 157 | qlitem->EnableLabelMarkupAccel(false); | ||
302 | 158 | EXPECT_FALSE(qlitem->IsMarkupAccelEnabled()); | ||
303 | 159 | EXPECT_TRUE(dbusmenu_menuitem_property_get_bool(item, QuicklistMenuItem::MARKUP_ACCEL_DISABLED_PROPERTY)); | ||
304 | 160 | } | ||
305 | 161 | |||
306 | 142 | TEST_F(TestQuicklistMenuItem, ItemActivate) | 162 | TEST_F(TestQuicklistMenuItem, ItemActivate) |
307 | 143 | { | 163 | { |
308 | 144 | dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label"); | 164 | dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Label"); |
Seems like it could use a test.