From e248c98eb8cb3b0521ed3316cb2e1c71a721b1f9 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Thu, 11 Feb 2021 19:25:01 -0600 Subject: [PATCH] DNSSettingsView: Disable list buttons when nothing selected Change-Id: I2ff2ab1b3e29b1a8b217506ae620926f0f51787f Reviewed-on: https://review.haiku-os.org/c/haiku/+/3742 Reviewed-by: Adrien Destugues --- .../dnsclient/DNSSettingsView.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/add-ons/network_settings/dnsclient/DNSSettingsView.cpp b/src/add-ons/network_settings/dnsclient/DNSSettingsView.cpp index b6294652ea..559754b52e 100644 --- a/src/add-ons/network_settings/dnsclient/DNSSettingsView.cpp +++ b/src/add-ons/network_settings/dnsclient/DNSSettingsView.cpp @@ -34,6 +34,7 @@ static const int32 kMsgAddServer = 'adds'; static const int32 kMsgDeleteServer = 'dels'; +static const int32 kMsgSelectServer = 'sels'; static const int32 kMsgMoveUp = 'mvup'; static const int32 kMsgMoveDown = 'mvdn'; static const int32 kMsgApply = 'aply'; @@ -54,6 +55,7 @@ DNSSettingsView::DNSSettingsView(BNetworkSettingsItem* item) titleView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); fServerListView = new BListView("nameservers"); + fServerListView->SetSelectionMessage(new BMessage(kMsgSelectServer)); const char* serverLabel = B_TRANSLATE("Server:"); fTextControl = new IPAddressControl(AF_UNSPEC, serverLabel, "server"); fTextControl->SetExplicitMinSize(BSize(fTextControl->StringWidth("5") * 16 @@ -63,12 +65,15 @@ DNSSettingsView::DNSSettingsView(BNetworkSettingsItem* item) fAddButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); fUpButton = new BButton(B_TRANSLATE("Move up"), new BMessage(kMsgMoveUp)); fUpButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + fUpButton->SetEnabled(false); fDownButton = new BButton(B_TRANSLATE("Move down"), new BMessage(kMsgMoveDown)); fDownButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + fDownButton->SetEnabled(false); fRemoveButton = new BButton(B_TRANSLATE("Remove"), new BMessage(kMsgDeleteServer)); fRemoveButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + fRemoveButton->SetEnabled(false); fDomain = new BTextControl(B_TRANSLATE("Domain:"), "", NULL); fApplyButton = new BButton(B_TRANSLATE("Apply"), new BMessage(kMsgApply)); @@ -143,6 +148,8 @@ DNSSettingsView::AttachedToWindow() fUpButton->SetTarget(this); fDownButton->SetTarget(this); + fServerListView->SetTarget(this); + fTextControl->SetTarget(this); fApplyButton->SetTarget(this); @@ -178,6 +185,17 @@ DNSSettingsView::MessageReceived(BMessage* message) fServerListView->SwapItems(index, index + 1); break; } + case kMsgSelectServer: + { + bool enabled = false; + if (fServerListView->CurrentSelection() > -1) + enabled = true; + + fUpButton->SetEnabled(enabled); + fDownButton->SetEnabled(enabled); + fRemoveButton->SetEnabled(enabled); + break; + } case kMsgApply: if (_SaveDNSConfiguration() == B_OK) fItem->NotifySettingsUpdated();