diff --git a/AccountListItem.h b/AccountListItem.h index 022c95372f0549539556cfd6463c07dc4981d032..b8a46da8b0a8e6ebe5beb368e9a43c0c32ed40fe 100644 --- a/AccountListItem.h +++ b/AccountListItem.h @@ -37,20 +37,21 @@ public: property bool _isSelected { void set(bool value) { isSelected_ = value; - NotifyPropertyChanged("_isSelected"); + if (!_disconnected) + NotifyPropertyChanged("_isSelected"); } bool get() { return isSelected_; } } property bool _editionMode; + property bool _disconnected; protected: void NotifyPropertyChanged(String^ propertyName); private: bool isSelected_; - }; } } diff --git a/AccountListItemsViewModel.cpp b/AccountListItemsViewModel.cpp index ce72035f9603dcb01b81cddba50b650cd712573d..c32609633f33fec82d7e8bf26e397c54e7332fdb 100644 --- a/AccountListItemsViewModel.cpp +++ b/AccountListItemsViewModel.cpp @@ -60,3 +60,14 @@ RingClientUWP::ViewModel::AccountListItemsViewModel::findItem(String^ accountId) return nullptr; } + +void RingClientUWP::ViewModel::AccountListItemsViewModel::removeItem(AccountListItem ^ item) +{ + unsigned int index; + itemsList_->IndexOf(item, &index); + + item->_disconnected = true; // avoid disconected exception. + + itemsList_->RemoveAt(index); + +} diff --git a/AccountListItemsViewModel.h b/AccountListItemsViewModel.h index 0674557b7ee4368d6ff228825089e5179a6de125..b39eca86548d3f0018396a7a4e2d594408f5be6d 100644 --- a/AccountListItemsViewModel.h +++ b/AccountListItemsViewModel.h @@ -43,6 +43,7 @@ internal: /* functions */ AccountListItem^ findItem(String^ accountId); + void removeItem(AccountListItem^ item); /* properties */ property Vector<AccountListItem^>^ itemsList diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index 7a9029b6cb96976f3b220df541be5c79c0932780..b8f55fade46e4693db5102fba30475fa28f7c0f3 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -727,6 +727,8 @@ void RingClientUWP::Views::SmartPanel::_editAccountMenuButton__Click(Platform::O auto account = AccountListItemsViewModel::instance->_selectedItem->_account; _aliasTextBoxEditionMenu_->Text = account->name_; _accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; + _deleteAccountBtnEditionMenu_->IsChecked = false; + _deleteAccountBtnEditionMenu_->IsEnabled = (AccountListItemsViewModel::instance->itemsList->Size > 1)? true : false; } @@ -739,19 +741,19 @@ void RingClientUWP::Views::SmartPanel::_acceptAccountModification__Click(Platfor // mettre ca en visibility du bouton delete auto accountsListSize = dynamic_cast<Vector<AccountListItem^>^>(_accountsList_->ItemsSource)->Size; + /* if the delete button is toggled, just delete the account */ if (_deleteAccountBtnEditionMenu_->IsChecked && accountsListSize > 1) { - RingD::instance->deleteAccount(accountId); + AccountListItem^ item; + for each (item in AccountListItemsViewModel::instance->itemsList) + if (item->_account->accountID_ == accountId) + break; - /* rebuild a new list of accounts without the one to delete */ - auto newAccountList = ref new Vector<AccountListItem^>(); - for each (AccountListItem^ item in AccountListItemsViewModel::instance->itemsList) { - if (item->_account->accountID_ != accountId) - newAccountList->Append(item); - } + if (item) + AccountListItemsViewModel::instance->removeItem(item); - _accountsList_->ItemsSource = newAccountList; + RingD::instance->deleteAccount(accountId); - } else { + } else { /* otherwise edit the account */ account->name_ = _aliasTextBoxEditionMenu_->Text; account->_upnpState = _upnpState_->IsOn; @@ -774,4 +776,4 @@ void RingClientUWP::Views::SmartPanel::_cancelAccountModification__Click(Platfor void RingClientUWP::Views::SmartPanel::OnaccountUpdated(RingClientUWP::Account ^account) { updatePageContent(); -} +} \ No newline at end of file