This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH setup 4/4] Use a pop-up menu to directly select chooser view filter


Rather that cycling through views, popup a menu to choose the view when the
view button is clicked

Future work:

Hopefully this does reduce the average number of clicks needed, but
popping-up on mouse button down, rather than mouse button click is perhaps
what we really want here, but seems to be rather hard to achieve in a
propsheet.
---
 PickView.cc |  16 ++++-----
 PickView.h  |   2 +-
 choose.cc   | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 choose.h    |   1 +
 res.rc      |  22 +++++++++++--
 resource.h  |  10 ++++++
 6 files changed, 141 insertions(+), 18 deletions(-)

diff --git a/PickView.cc b/PickView.cc
index 25d43a2..3702b92 100644
--- a/PickView.cc
+++ b/PickView.cc
@@ -141,16 +141,6 @@ PickView::note_width (PickView::Header *hdrs, HDC dc,
 }
 
 void
-PickView::cycleViewMode ()
-{
-  PickView::views _value = (PickView::views)((int)view_mode + 1);
-  if (_value > PickView::views::Category)
-    _value = PickView::views::PackageFull;
-
-  setViewMode (_value);
-}
-
-void
 PickView::setViewMode (views mode)
 {
   view_mode = mode;
@@ -227,6 +217,12 @@ PickView::setViewMode (views mode)
   InvalidateRect (GetHWND(), &r, TRUE);
 }
 
+PickView::views
+PickView::getViewMode ()
+{
+  return view_mode;
+}
+
 const char *
 PickView::mode_caption ()
 {
diff --git a/PickView.h b/PickView.h
index c07249b..332383a 100644
--- a/PickView.h
+++ b/PickView.h
@@ -44,8 +44,8 @@ public:
   class Header;
   int num_columns;
   void defaultTrust (trusts trust);
-  void cycleViewMode ();
   void setViewMode (views mode);
+  views getViewMode ();
   void DrawIcon (HDC hdc, int x, int y, HANDLE hIcon);
   void paint (HWND hwnd);
   LRESULT CALLBACK list_click (HWND hwnd, BOOL dblclk, int x, int y, UINT hitCode);
diff --git a/choose.cc b/choose.cc
index 3c7f4f8..180c788 100644
--- a/choose.cc
+++ b/choose.cc
@@ -385,6 +385,10 @@ ChooserPage::changeTrust(trusts aTrust)
 bool
 ChooserPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
 {
+#if DEBUG
+  Log (LOG_BABBLE) << "OnMesageCmd " << id << " " << hwndctl << " " << code << endLog;
+#endif
+
   if (code == EN_CHANGE && id == IDC_CHOOSE_SEARCH_EDIT)
     {
       SetTimer(GetHWND (), timer_id, SEARCH_TIMER_DELAY, (TIMERPROC) NULL);
@@ -423,11 +427,7 @@ ChooserPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
       break;
 
     case IDC_CHOOSE_VIEW:
-      chooser->cycleViewMode ();
-      if (!SetDlgItemText
-        (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ()))
-      Log (LOG_BABBLE) << "Failed to set View button caption " <<
-           GetLastError () << endLog;
+      selectView();
       break;
 
     case IDC_CHOOSE_HIDE:
@@ -442,6 +442,104 @@ ChooserPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
   return true;
 }
 
+static void
+setMenuItemState (HMENU hMenu, UINT item, UINT state)
+{
+  MENUITEMINFO mii;
+  memset(&mii, 0, sizeof(MENUITEMINFO));
+  mii.cbSize = sizeof(MENUITEMINFO);
+  mii.fMask = MIIM_STATE;
+  mii.fState = state;
+  SetMenuItemInfo (hMenu, item, FALSE, &mii);
+}
+
+void
+ChooserPage::selectView (void)
+{
+  HMENU hMenu = LoadMenu (GetModuleHandle (NULL), MAKEINTRESOURCE (IDM_CHOOSE_VIEW));
+  hMenu = GetSubMenu (hMenu, 0);
+
+  // mark the current view mode as selected
+  int item = 0;
+  PickView::views view_mode = chooser->getViewMode ();
+
+  switch (view_mode)
+    {
+    case PickView::views::PackageFull:
+      item = IDM_VIEW_FULL;
+      break;
+    case PickView::views::PackagePending:
+      item = IDM_VIEW_PENDING;
+      break;
+    case PickView::views::PackageKeeps:
+      item = IDM_VIEW_UPTODATE;
+      break;
+    case PickView::views::PackageSkips:
+      item = IDM_VIEW_NOT_INSTALLED;
+      break;
+    case PickView::views::PackageUserPicked:
+      item = IDM_VIEW_PICKED;
+      break;
+    case PickView::views::Category:
+      item = IDM_VIEW_CATEGORY;
+      break;
+    case PickView::views::Unknown:
+      item = 0;
+    }
+
+  if (item)
+    setMenuItemState (hMenu, item, MFS_CHECKED);
+
+  // place the menu over the 'view' button
+  HWND hButton = ::GetDlgItem (GetHWND (), IDC_CHOOSE_VIEW);
+  RECT rect;
+  ::GetWindowRect (hButton, &rect);
+
+  item = TrackPopupMenu (hMenu,
+                         TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_NOANIMATION,
+                         rect.left, rect.top,
+                         0, GetHWND (), NULL);
+
+  DestroyMenu (hMenu);
+
+#if DEBUG
+  Log (LOG_BABBLE) << "TrackPopupMenu returned " << item << endLog;
+#endif
+
+  // menu cancelled without making a selection
+  if (item == 0)
+    return;
+
+  // switch to the selected view
+  switch (item)
+    {
+    case IDM_VIEW_FULL:
+      view_mode = PickView::views::PackageFull;
+      break;
+    case IDM_VIEW_PENDING:
+      view_mode = PickView::views::PackagePending;
+      break;
+    case IDM_VIEW_UPTODATE:
+      view_mode = PickView::views::PackageKeeps;
+      break;
+    case IDM_VIEW_NOT_INSTALLED:
+      view_mode = PickView::views::PackageSkips;
+      break;
+    case IDM_VIEW_PICKED:
+      view_mode = PickView::views::PackageUserPicked;
+      break;
+    case IDM_VIEW_CATEGORY:
+      view_mode = PickView::views::Category;
+      break;
+    }
+
+  chooser->setViewMode (view_mode);
+  if (!SetDlgItemText
+      (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ()))
+    Log (LOG_BABBLE) << "Failed to set View button caption " <<
+      GetLastError () << endLog;
+}
+
 INT_PTR CALLBACK
 ChooserPage::OnMouseWheel (UINT message, WPARAM wParam, LPARAM lParam)
 {
diff --git a/choose.h b/choose.h
index 46f0f35..8832f5e 100644
--- a/choose.h
+++ b/choose.h
@@ -59,6 +59,7 @@ private:
   void logResults();
   void setPrompt(char const *aPrompt);
   void PlaceDialog (bool);
+  void selectView (void);
 
   PickView *chooser;
   static HWND ins_dialog;
diff --git a/res.rc b/res.rc
index 2fae133..10ec375 100644
--- a/res.rc
+++ b/res.rc
@@ -536,8 +536,8 @@ BEGIN
        "considered the most stable. (RECOMMENDED)"
     IDS_TRUSTEXP_TOOLTIP    "Globally select the most recent version, even if "
        "that version is considered Experimental or for test use by the maintainer."
-    IDS_VIEWBUTTON_TOOLTIP  "Cycles the package view.  This determines "
-       "which packages are shown in the chooser below.\r\n"
+    IDS_VIEWBUTTON_TOOLTIP  "Select the package view.  This determines "
+       "which packages are shown below.\r\n"
        "\r\n"
        "Category: Group by package category.  Click on '+' to expand.\r\n"
        "\r\n"
@@ -574,3 +574,21 @@ BEGIN
     IDS_ELEVATED       "Hand installation over to elevated child process."
     IDS_INSTALLEDB_VERSION "Unknown INSTALLED.DB version"
 END
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Menu
+//
+
+IDM_CHOOSE_VIEW MENUEX
+BEGIN
+    POPUP "ViewMenu"
+    BEGIN
+        MENUITEM "&Full",          IDM_VIEW_FULL,          MFT_STRING | MFT_RADIOCHECK
+        MENUITEM "&Pending",       IDM_VIEW_PENDING,       MFT_STRING | MFT_RADIOCHECK
+        MENUITEM "&Up To Date",    IDM_VIEW_UPTODATE,      MFT_STRING | MFT_RADIOCHECK
+        MENUITEM "&Not Installed", IDM_VIEW_NOT_INSTALLED, MFT_STRING | MFT_RADIOCHECK
+        MENUITEM "P&icked",        IDM_VIEW_PICKED,        MFT_STRING | MFT_RADIOCHECK
+        MENUITEM "&Category",      IDM_VIEW_CATEGORY,      MFT_STRING | MFT_RADIOCHECK
+    END
+END
diff --git a/resource.h b/resource.h
index 68e8023..e2312ac 100644
--- a/resource.h
+++ b/resource.h
@@ -175,3 +175,13 @@
 #define IDC_FILE_INUSE_EDIT               590
 #define IDC_FILE_INUSE_MSG                591
 #define IDC_FILE_INUSE_HELP               592
+
+// Menus
+
+#define IDM_CHOOSE_VIEW                   900
+#define IDM_VIEW_FULL                     901
+#define IDM_VIEW_PENDING                  902
+#define IDM_VIEW_UPTODATE                 903
+#define IDM_VIEW_NOT_INSTALLED            904
+#define IDM_VIEW_PICKED                   905
+#define IDM_VIEW_CATEGORY                 906
-- 
2.8.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]