Time prefs: Enable add button if server name valid

* Add button is disabled initially (as the server name is blank)
* Use B_FAILURE_COLOR when server name is invalid instead of hardcoding red
* Some code refactoring
* Some style fixes
This commit is contained in:
John Scipione
2014-03-31 18:57:46 -04:00
parent 62b45ce190
commit 8fbf8d56f6
2 changed files with 12 additions and 14 deletions
+11 -13
View File
@@ -295,21 +295,18 @@ NetworkTimeView::MessageReceived(BMessage* message)
case kMsgServerEdited: case kMsgServerEdited:
{ {
rgb_color defaultColor = ui_color(B_CONTROL_TEXT_COLOR); rgb_color defaultColor = ui_color(B_CONTROL_TEXT_COLOR);
rgb_color red = {255, 0, 0}; rgb_color invalid = ui_color(B_FAILURE_COLOR);
int32 length = fServerTextControl->TextView()->TextLength(); bool isValidServerName
= _IsValidServerName(fServerTextControl->Text());
if (_IsValidServerName(fServerTextControl->TextView()->Text())) { fServerTextControl->TextView()->SetFontAndColor(0,
fServerTextControl->TextView()->SetFontAndColor(0, length, NULL, fServerTextControl->TextView()->TextLength(), NULL, 0,
0, &defaultColor); isValidServerName ? &defaultColor : &invalid);
} else { fAddButton->SetEnabled(isValidServerName);
fServerTextControl->TextView()->SetFontAndColor(0, length, NULL,
0, &red);
}
break; break;
} }
case kMsgAddServer: case kMsgAddServer:
if (!_IsValidServerName(fServerTextControl->TextView()->Text())) if (!_IsValidServerName(fServerTextControl->Text()))
break; break;
fSettings.AddServer(fServerTextControl->Text()); fSettings.AddServer(fServerTextControl->Text());
@@ -418,6 +415,7 @@ NetworkTimeView::AttachedToWindow()
fServerTextControl->SetTarget(this); fServerTextControl->SetTarget(this);
fServerListView->SetTarget(this); fServerListView->SetTarget(this);
fAddButton->SetTarget(this); fAddButton->SetTarget(this);
fAddButton->SetEnabled(false);
fRemoveButton->SetTarget(this); fRemoveButton->SetTarget(this);
fResetButton->SetTarget(this); fResetButton->SetTarget(this);
fTryAllServersCheckBox->SetTarget(this); fTryAllServersCheckBox->SetTarget(this);
@@ -521,9 +519,9 @@ NetworkTimeView::_DoneSynchronizing()
bool bool
NetworkTimeView::_IsValidServerName(const char * serverName) NetworkTimeView::_IsValidServerName(const char* serverName)
{ {
if (serverName[0] == '\0') if (serverName == NULL || *serverName == '\0')
return false; return false;
for (int32 i = 0; serverName[i] != '\0'; i++) { for (int32 i = 0; serverName[i] != '\0'; i++) {
+1 -1
View File
@@ -93,7 +93,7 @@ private:
void _InitView(); void _InitView();
void _UpdateServerList(); void _UpdateServerList();
void _DoneSynchronizing(); void _DoneSynchronizing();
bool _IsValidServerName(const char * serverName); bool _IsValidServerName(const char* serverName);
Settings fSettings; Settings fSettings;