public void AddOption(ApplicationOption option) { var index = -1; if (!string.IsNullOrWhiteSpace(option.Label)) { foreach (var item in Options) { if (String.Compare(option.Label, item.Label, StringComparison.Ordinal) < 0) { index = Options.IndexOf(item); break; } } } if (index != -1) { Options.Insert(index, option); } else { Options.Add(option); } OnPropertyChanged(nameof(HasOneOption)); }
public void AddOption(string group, string optionLabel, Action action, string description = null) { var option = new ApplicationOption(optionLabel, action, description); if (group == "Help") { AddToCollection(option, Helps); } else if (group == "Setting") { AddToCollection(option, Settings); } else { if (!Options.Any(o => o.Label == group)) { AddToCollection(new MenuGroupViewModel(group, ApplicationController), Options); } var groupMenu = Options.First(o => o.Label == group); groupMenu.AddOption(option); } OnPropertyChanged("HasSettings"); OnPropertyChanged("HasHelp"); }
private void AddToCollection(ApplicationOption option, ObservableCollection <ApplicationOption> options) { var forceLastLabel = "About"; if (option.Label == forceLastLabel) { options.Add(option); } else { var index = -1; if (!option.Label.IsNullOrWhiteSpace()) { foreach (var item in options) { if (item.Label == forceLastLabel || String.Compare(option.Label, item.Label, StringComparison.Ordinal) < 0) { index = options.IndexOf(item); break; } } } if (index != -1) { options.Insert(index, option); } else { options.Add(option); } } }
private void AddToSettingsCollection(string optionLabel, Action action, string description) { var option = new ApplicationOption(optionLabel, () => { OpenSettings = false; action(); }, description); var forceLastLabel = "About"; if (option.Label == forceLastLabel) { Settings.Add(option); } else { var index = -1; if (!option.Label.IsNullOrWhiteSpace()) { foreach (var item in Settings) { if (item.Label == forceLastLabel || String.Compare(option.Label, item.Label, StringComparison.Ordinal) < 0) { index = Settings.IndexOf(item); break; } } } if (index != -1) { Settings.Insert(index, option); } else { Settings.Add(option); } } }
private void AddToSettingsCollection(string optionLabel, Action action, string description, int order) { var option = new ApplicationOption(optionLabel, () => { OpenSettings = false; action(); }, description, order: order); var index = -1; if (!option.Label.IsNullOrWhiteSpace()) { foreach (var item in Settings) { if (order < item.Order || (order == item.Order && String.Compare(option.Label, item.Label, StringComparison.Ordinal) < 0)) { index = Settings.IndexOf(item); break; } } } if (index != -1) { Settings.Insert(index, option); } else { Settings.Add(option); } }
public void AddOption(string optionLabel, Action action, string description) { var option = new ApplicationOption(optionLabel, () => { OpenChildButtons = false; action(); }, description); AddOption(option); }