private void OnReorder() { isReordering = true; ConditionGroups.ForEachSafe(grp => { if (!grp.IsExclude) { if (ConditionGroups.Before(grp).Any(cg => cg.IsExclude)) { ConditionGroups.Remove(grp); int count = ConditionGroups.Count(cg => !cg.IsExclude); ConditionGroups.Insert(count, grp); } } else // grp.IsExclude { if (ConditionGroups.After(grp).Any(cg => !cg.IsExclude)) { ConditionGroups.Remove(grp); ConditionGroups.Add(grp); } } }); ConditionGroups.ForEach(cg => cg.ReorderCommand.Execute()); isReordering = false; }
private void OnCreateConditionGroup() { FilterConditionGroupViewModel cg = new FilterConditionGroupViewModel(this); cg.CreateConditionCommand.Execute(); ConditionGroups.Add(cg); }
public void LoadFromString(string data) { isLoading = true; ConditionGroups.Clear(); IEnumerable <string> lines = data.Split('\n').Select(s => s.Trim('\r')); List <string> lineBuffer = new List <string>(); bool lineBufferIsExclude = false; bool lineBufferIsEnabled = true; bool haveName = false; foreach (string line in lines) { if (!haveName) { // The first line contains the "quick filter" flag and filter name string[] chunks = line.Split(new char[] { ',' }, 2); if (chunks[0] == "qf") { QuickModifiedTime = DateTime.UtcNow.AddYears(-1); } DisplayName = chunks[1]; haveName = true; } else { string[] chunks = line.Split(new char[] { ',' }, 3); if (chunks[0] == "or" || chunks[0] == "and not") { // New condition group starts if (lineBuffer.Count > 0) { // Create condition group from buffer of previous lines FilterConditionGroupViewModel grp = new FilterConditionGroupViewModel(this); grp.LoadFromString(lineBuffer); grp.IsExclude = lineBufferIsExclude; grp.IsEnabled = lineBufferIsEnabled; ConditionGroups.Add(grp); lineBuffer.Clear(); } // Remember type for the upcoming condition group lineBufferIsExclude = chunks[0] == "and not"; lineBufferIsEnabled = chunks[1] == "on"; } // Save line to buffer lineBuffer.Add(line); } } // Create last condition group from buffer of previous lines FilterConditionGroupViewModel grp2 = new FilterConditionGroupViewModel(this); grp2.LoadFromString(lineBuffer); grp2.IsExclude = lineBufferIsExclude; grp2.IsEnabled = lineBufferIsEnabled; ConditionGroups.Add(grp2); isLoading = false; }