diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index f45f908e3..f9d02d5a7 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -64,7 +64,6 @@ import com.fsck.k9.Preferences; import com.fsck.k9.R; import com.fsck.k9.activity.misc.ExtendedAsyncTask; import com.fsck.k9.activity.misc.NonConfigurationInstance; -import com.fsck.k9.activity.setup.AccountSettings; import com.fsck.k9.activity.setup.AccountSetupBasics; import com.fsck.k9.activity.setup.Prefs; import com.fsck.k9.activity.setup.WelcomeMessage; @@ -1788,7 +1787,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { LocalSearch search = null; if (account instanceof SearchAccount) { - search = ((SearchAccount) account).getRelatedSearch(); + search = ((SearchAccount) account).getRelatedSearch().clone(); search.setName(description); } else { search = new LocalSearch(description); diff --git a/src/com/fsck/k9/search/ConditionsTreeNode.java b/src/com/fsck/k9/search/ConditionsTreeNode.java index 430f31255..52bc6bb58 100644 --- a/src/com/fsck/k9/search/ConditionsTreeNode.java +++ b/src/com/fsck/k9/search/ConditionsTreeNode.java @@ -124,6 +124,35 @@ public class ConditionsTreeNode implements Parcelable { } + /* package */ ConditionsTreeNode cloneTree() { + if (mParent != null) { + throw new IllegalStateException("Can't call cloneTree() for a non-root node"); + } + + ConditionsTreeNode copy = new ConditionsTreeNode(mCondition.clone()); + + copy.mLeftMPTTMarker = mLeftMPTTMarker; + copy.mRightMPTTMarker = mRightMPTTMarker; + + copy.mLeft = (mLeft == null) ? null : mLeft.cloneNode(copy); + copy.mRight = (mRight == null) ? null : mRight.cloneNode(copy); + + return copy; + } + + private ConditionsTreeNode cloneNode(ConditionsTreeNode parent) { + ConditionsTreeNode copy = new ConditionsTreeNode(parent, mValue); + + copy.mCondition = mCondition.clone(); + copy.mLeftMPTTMarker = mLeftMPTTMarker; + copy.mRightMPTTMarker = mRightMPTTMarker; + + copy.mLeft = (mLeft == null) ? null : mLeft.cloneNode(copy); + copy.mRight = (mRight == null) ? null : mRight.cloneNode(copy); + + return copy; + } + /////////////////////////////////////////////////////////////// // Public modifiers /////////////////////////////////////////////////////////////// diff --git a/src/com/fsck/k9/search/LocalSearch.java b/src/com/fsck/k9/search/LocalSearch.java index c52dec469..a93ce187f 100644 --- a/src/com/fsck/k9/search/LocalSearch.java +++ b/src/com/fsck/k9/search/LocalSearch.java @@ -80,6 +80,15 @@ public class LocalSearch implements SearchSpecification { } } + @Override + public LocalSearch clone() { + ConditionsTreeNode conditions = (mConditions == null) ? null : mConditions.cloneTree(); + + LocalSearch copy = new LocalSearch(mName, conditions, null, mPredefined); + copy.mAccountUuids = new HashSet(mAccountUuids); + + return copy; + } /////////////////////////////////////////////////////////////// // Public manipulation methods diff --git a/src/com/fsck/k9/search/SearchSpecification.java b/src/com/fsck/k9/search/SearchSpecification.java index 8f22622c6..a953a5d4d 100644 --- a/src/com/fsck/k9/search/SearchSpecification.java +++ b/src/com/fsck/k9/search/SearchSpecification.java @@ -134,6 +134,11 @@ public interface SearchSpecification extends Parcelable { this.field = Searchfield.values()[in.readInt()]; } + @Override + public SearchCondition clone() { + return new SearchCondition(field, attribute, value); + } + public String toHumanString() { return field.toString() + attribute.toString(); }