Merge lp:~unity-team/unity/unity.fix-741657 into lp:unity

Proposed by Mirco Müller
Status: Merged
Approved by: Jason Smith
Approved revision: no longer in the source branch.
Merged at revision: 1077
Proposed branch: lp:~unity-team/unity/unity.fix-741657
Merge into: lp:unity
Diff against target: 86 lines (+42/-1)
2 files modified
src/QuicklistView.cpp (+39/-0)
src/QuicklistView.h (+3/-1)
To merge this branch: bzr merge lp:~unity-team/unity/unity.fix-741657
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Review via email: mp+55517@code.launchpad.net

Description of the change

Skip over separator items in Quicklists, if walking them with keyboard-navigation. Fixes LP: #741657

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

On Thu, 31 Mar 2011 00:27:20 you wrote:
> Mirco Müller has proposed merging lp:~unity-team/unity/unity.fix-741657
> into lp:unity.
>
> Requested reviews:
> Unity Team (unity-team)
> Related bugs:
> Bug #741657 in unity: "quicklist key-nav needs to ignore separator items"
> https://bugs.launchpad.net/unity/+bug/741657
>
> For more details, see:
> https://code.launchpad.net/~unity-team/unity/unity.fix-741657/+merge/55517
>
> Skip over separator items in Quicklists, if walking them with
> keyboard-navigation. Fixes LP: #741657

How about adding a method like like:

bool menu_item_is_seperator(int index) const
{
  DbusmenuMenuitem* item = GetNthItems(index)->_menuItem;
  const gchar* label = dbusmenu_menuitem_property_get(
      item, DBUSMENU_MENUITEM_PROP_LABEL);
  return label != 0;
}

Then you can use it in the up and down code:

     case NUX_VK_UP:
       if (_current_item_index > 0)
       {
         GetNthItems (_current_item_index)->_prelight = false;
         --_current_item_index;
         while (menu_item_is_seperator(_current_item_index)
         {
           --_current_item_index;
         }
         GetNthItems (_current_item_index)->_prelight = true;
         QueueDraw ();
       }

This makes the code in the case a little easier to understand.

Revision history for this message
Mirco Müller (macslow) wrote :

Made code more readable.

Revision history for this message
Jason Smith (jassmith) wrote :

Does this handle the case where the last or first item is a separator?

review: Needs Information
Revision history for this message
Tim Penhey (thumper) wrote :

On Fri, 01 Apr 2011 08:41:06 you wrote:
> Review: Needs Information
> Does this handle the case where the last or first item is a separator?

Not very well in the original form.

Revision history for this message
Mirco Müller (macslow) wrote :

I does... now :)

Revision history for this message
Mirco Müller (macslow) wrote :

Doh... need to remerge with trunk.

Revision history for this message
Mirco Müller (macslow) wrote :

Ok, everything is in order again.

Revision history for this message
Jason Smith (jassmith) wrote :

Looks better now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/QuicklistView.cpp'
2--- src/QuicklistView.cpp 2011-03-30 14:58:44 +0000
3+++ src/QuicklistView.cpp 2011-04-01 13:48:06 +0000
4@@ -123,6 +123,29 @@
5 {
6 }
7
8+bool
9+QuicklistView::IsMenuItemSeperator (int index)
10+{
11+ DbusmenuMenuitem* item = NULL;
12+ const gchar* label = NULL;
13+ bool result = false;
14+
15+ if (index < 0)
16+ return false;
17+
18+ item = GetNthItems (index)->_menuItem;
19+ if (!item)
20+ return false;
21+
22+ label = dbusmenu_menuitem_property_get (item, DBUSMENU_MENUITEM_PROP_LABEL);
23+ if (!label)
24+ result = true;
25+ else
26+ result = false;
27+
28+ return result;
29+}
30+
31 void
32 QuicklistView::RecvKeyPressed (unsigned int key_sym,
33 unsigned long key_code,
34@@ -133,10 +156,18 @@
35 // up (highlight previous menu-item)
36 case NUX_VK_UP:
37 case NUX_KP_UP:
38+ // protect against edge-case of first item being a separator
39+ if (_current_item_index == 1 && IsMenuItemSeperator (0))
40+ break;
41+
42 if (_current_item_index > 0)
43 {
44 GetNthItems (_current_item_index)->_prelight = false;
45 _current_item_index--;
46+
47+ while (IsMenuItemSeperator (_current_item_index))
48+ _current_item_index--;
49+
50 GetNthItems (_current_item_index)->_prelight = true;
51 QueueDraw ();
52 }
53@@ -145,10 +176,18 @@
54 // down (highlight next menu-item)
55 case NUX_VK_DOWN:
56 case NUX_KP_DOWN:
57+ // protect against edge-case of last item being a separator
58+ if (_current_item_index == (GetNumItems () - 1) && IsMenuItemSeperator (GetNumItems ()))
59+ break;
60+
61 if (_current_item_index < GetNumItems () - 1)
62 {
63 GetNthItems (_current_item_index)->_prelight = false;
64 _current_item_index++;
65+
66+ while (IsMenuItemSeperator (_current_item_index))
67+ _current_item_index++;
68+
69 GetNthItems (_current_item_index)->_prelight = true;
70 QueueDraw ();
71 }
72
73=== modified file 'src/QuicklistView.h'
74--- src/QuicklistView.h 2011-02-27 08:18:45 +0000
75+++ src/QuicklistView.h 2011-04-01 13:48:06 +0000
76@@ -139,7 +139,9 @@
77
78 //! Check the mouse up event sent by an item. Detect the item where the mous is and emit the appropriate signal.
79 void CheckAndEmitItemSignal (int x, int y);
80-
81+
82+ bool IsMenuItemSeperator (int index);
83+
84 //nux::CairoGraphics* _cairo_graphics;
85 int _anchorX;
86 int _anchorY;