DNSSettingsView: Disable list buttons when nothing selected

Change-Id: I2ff2ab1b3e29b1a8b217506ae620926f0f51787f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3742
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Jaidyn Ann 2021-02-11 19:25:01 -06:00 committed by Adrien Destugues
parent 91b9cbbbb0
commit e248c98eb8

View File

@ -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();