From 648acfbd6ec753b9b9b81ff176d314849cbbe5f5 Mon Sep 17 00:00:00 2001
From: Emmanuel Lepage Vallee <elv1313@gmail.com>
Date: Tue, 22 Dec 2015 10:16:25 -0500
Subject: [PATCH] accountmodel: Correctly cancel changes

There was a few missing peices to correctly undo the changes
when canceling the AccountModel

Tuleap: #212
Change-Id: Icb296a424ad30017b8b6ba5cc49a2d3dc834394f
---
 src/accountmodel.cpp | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/accountmodel.cpp b/src/accountmodel.cpp
index 64f85c27..76fc9a85 100644
--- a/src/accountmodel.cpp
+++ b/src/accountmodel.cpp
@@ -547,11 +547,27 @@ void AccountModel::registerAllAccounts()
 ///Cancel all modifications
 void AccountModel::cancel() {
    foreach (Account* a, d_ptr->m_lAccounts) {
-      if (a->editState() == Account::EditState::MODIFIED_COMPLETE
-       || a->editState() == Account::EditState::MODIFIED_INCOMPLETE
-       || a->editState() == Account::EditState::OUTDATED
-      )
-         a->performAction(Account::EditAction::CANCEL);
+      // Account::EditState::NEW is only for new and unmodified accounts
+      if (a->isNew())
+         remove(a);
+      else {
+         switch(a->editState()) {
+            case Account::EditState::NEW                :
+               remove(a);
+            case Account::EditState::MODIFIED_INCOMPLETE:
+            case Account::EditState::MODIFIED_COMPLETE  :
+               a << Account::EditAction::CANCEL;
+               break;
+            case Account::EditState::OUTDATED           :
+               a << Account::EditAction::RELOAD;
+               break;
+            case Account::EditState::READY              :
+            case Account::EditState::REMOVED            :
+            case Account::EditState::EDITING            :
+            case Account::EditState::COUNT__            :
+               break;
+         }
+      }
    }
    d_ptr->m_lDeletedAccounts.clear();
 }
-- 
GitLab