[PATCH setup 4/4] Use a drop-down list to directly select chooser view filter
Jon Turney
jon.turney@dronecode.org.uk
Mon Aug 29 10:04:00 GMT 2016
Rather than a button for cycling through views, use a drop-down list to
choose the view
Remove not very useful PickView::views::Unknown enum value so that enum can
start from 0, so it can be used directly as a drop-down list index.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
---
PickView.cc | 28 +++++++++++-----------------
PickView.h | 7 +++----
choose.cc | 52 ++++++++++++++++++++++++++++++++++------------------
choose.h | 1 +
res.rc | 20 ++++++++++----------
5 files changed, 59 insertions(+), 49 deletions(-)
diff --git a/PickView.cc b/PickView.cc
index 25d43a2..fc6f8c2 100644
--- a/PickView.cc
+++ b/PickView.cc
@@ -81,11 +81,9 @@ DoInsertItem (HWND hwndHeader, int iInsertAfter, int nWidth, LPSTR lpsz)
int
PickView::set_header_column_order (views vm)
{
- if (vm == views::Unknown)
- return -1;
- else if (vm == views::PackageFull || vm == views::PackagePending
- || vm == views::PackageKeeps || vm == views::PackageSkips
- || vm == views::PackageUserPicked)
+ if (vm == views::PackageFull || vm == views::PackagePending
+ || vm == views::PackageKeeps || vm == views::PackageSkips
+ || vm == views::PackageUserPicked)
{
headers = pkg_headers;
current_col = 0;
@@ -141,16 +139,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,10 +215,16 @@ PickView::setViewMode (views mode)
InvalidateRect (GetHWND(), &r, TRUE);
}
+PickView::views
+PickView::getViewMode ()
+{
+ return view_mode;
+}
+
const char *
-PickView::mode_caption ()
+PickView::mode_caption (views mode)
{
- switch (view_mode)
+ switch (mode)
{
case views::PackageFull:
return "Full";
diff --git a/PickView.h b/PickView.h
index c07249b..298f844 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);
@@ -57,7 +57,7 @@ public:
PickView (Category & cat);
void init(views _mode);
~PickView();
- const char *mode_caption ();
+ static const char *mode_caption (views mode);
void setObsolete (bool doit);
void insert_pkg (packagemeta &);
void insert_category (Category *, bool);
@@ -98,8 +98,7 @@ public:
enum class views
{
- Unknown,
- PackageFull,
+ PackageFull = 0,
PackagePending,
PackageKeeps,
PackageSkips,
diff --git a/choose.cc b/choose.cc
index 3c7f4f8..687addf 100644
--- a/choose.cc
+++ b/choose.cc
@@ -153,9 +153,7 @@ ChooserPage::createListview ()
chooser->Show(SW_SHOW);
chooser->setViewMode (UpgradeAlsoOption || hasManualSelections ?
PickView::views::PackagePending : PickView::views::Category);
- if (!SetDlgItemText (GetHWND (), IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ()))
- Log (LOG_BABBLE) << "Failed to set View button caption %ld" <<
- GetLastError () << endLog;
+ SendMessage (GetDlgItem (IDC_CHOOSE_VIEW), CB_SETCURSEL, (WPARAM)chooser->getViewMode(), 0);
/* FIXME: do we need to init the desired fields ? */
static int ta[] = { IDC_CHOOSE_KEEP, IDC_CHOOSE_CURR, IDC_CHOOSE_EXP, 0 };
@@ -241,6 +239,16 @@ ChooserPage::OnInit ()
{
CheckDlgButton (GetHWND (), IDC_CHOOSE_HIDE, BST_CHECKED);
+ /* Populate view dropdown list with choices */
+ HWND viewlist = GetDlgItem (IDC_CHOOSE_VIEW);
+ SendMessage (viewlist, CB_RESETCONTENT, 0, 0);
+ for (int view = (int)PickView::views::PackageFull;
+ view <= (int)PickView::views::Category;
+ view++)
+ {
+ SendMessage(viewlist, CB_ADDSTRING, 0, (LPARAM)PickView::mode_caption((PickView::views)view));
+ }
+
SetBusy ();
if (source == IDC_SOURCE_DOWNLOAD || source == IDC_SOURCE_LOCALDIR)
packagemeta::ScanDownloadedFiles (MirrorOption);
@@ -385,17 +393,17 @@ 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);
return true;
}
- else if (code != BN_CLICKED && code != EN_CHANGE)
- {
- // Not a click notification, we don't care.
- return false;
- }
-
+ else if (code == BN_CLICKED)
+ {
switch (id)
{
case IDC_CHOOSE_CLEAR_SEARCH:
@@ -422,14 +430,6 @@ ChooserPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
changeTrust (TRUST_TEST);
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;
- break;
-
case IDC_CHOOSE_HIDE:
chooser->setObsolete (!IsButtonChecked (id));
break;
@@ -437,9 +437,25 @@ ChooserPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
// Wasn't recognized or handled.
return false;
}
-
// Was handled since we never got to default above.
return true;
+ }
+ else if (code == CBN_SELCHANGE)
+ {
+ if (id == IDC_CHOOSE_VIEW)
+ {
+ // switch to the selected view
+ LRESULT view_mode = SendMessage (GetDlgItem (IDC_CHOOSE_VIEW),
+ CB_GETCURSEL, 0, 0);
+ if (view_mode != CB_ERR)
+ chooser->setViewMode ((PickView::views)view_mode);
+
+ return true;
+ }
+ }
+
+ // We don't care.
+ return false;
}
INT_PTR CALLBACK
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..3ddf751 100644
--- a/res.rc
+++ b/res.rc
@@ -318,10 +318,10 @@ END
// Left-aligned controls.
#define SETUP_VIEW_X (7)
-#define SETUP_VIEW_W (26)
-#define SETUP_VIEWCAP_X (SETUP_VIEW_X + SETUP_VIEW_W +5)
-#define SETUP_VIEWCAP_W (40)
-#define SETUP_SEARCH_X (SETUP_VIEWCAP_X + SETUP_VIEWCAP_W + 80)
+#define SETUP_VIEW_W (20)
+#define SETUP_VIEWLIST_X (SETUP_VIEW_X + SETUP_VIEW_W + 2)
+#define SETUP_VIEWLIST_W (60)
+#define SETUP_SEARCH_X (SETUP_VIEWLIST_X + SETUP_VIEWLIST_W + 2)
#define SETUP_SEARCH_W (32)
#define SETUP_SEARCHTEXT_X (SETUP_SEARCH_X + SETUP_SEARCH_W + 2)
#define SETUP_SEARCHTEXT_W (60)
@@ -334,10 +334,10 @@ STYLE DS_MODALFRAME | DS_3DLOOK | WS_CHILD | WS_VISIBLE | WS_CAPTION |
CAPTION "Cygwin Setup - Select Packages"
FONT 8, "MS Shell Dlg"
BEGIN
- PUSHBUTTON "&View", IDC_CHOOSE_VIEW, SETUP_VIEW_X, 30, SETUP_VIEW_W,
- 14, WS_EX_RIGHT
- LTEXT "", IDC_CHOOSE_VIEWCAPTION, SETUP_VIEWCAP_X, 33,
- SETUP_VIEWCAP_W, 10
+ LTEXT "View:", IDC_CHOOSE_VIEWCAPTION, SETUP_VIEW_X, 33,
+ SETUP_VIEW_W, 10
+ COMBOBOX IDC_CHOOSE_VIEW, SETUP_VIEWLIST_X, 30, SETUP_VIEWLIST_W, 84,
+ CBS_DROPDOWNLIST
RTEXT "&Search", IDC_STATIC, SETUP_SEARCH_X, 33, SETUP_SEARCH_W,
10, SS_CENTERIMAGE, WS_EX_RIGHT
EDITTEXT IDC_CHOOSE_SEARCH_EDIT, SETUP_SEARCHTEXT_X, 30,
@@ -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"
--
2.8.3
More information about the Cygwin-apps
mailing list