public List <SortTerm> GetSortsParsed() { if (Sorts != null) { var value = new List <SortTerm>(); foreach (var sort in Regex.Split(Sorts, EscapedCommaPattern)) { if (string.IsNullOrWhiteSpace(sort)) { continue; } var sortTerm = new SortTerm() { Sort = sort }; if (value.All(s => s.Name != sortTerm.Name)) { value.Add(sortTerm); } } return(value); } return(null); }
public CustomSort(FileDatabase database) { this.InitializeComponent(); this.database = database; this.SortTerm1 = new SortTerm(); this.SortTerm2 = new SortTerm(); }
private void PopulateSecondaryUIElements() { // Populate the Secondary combo box with choices // By default, we select "None' unless its over-ridden this.SecondaryComboBox.Items.Clear(); // Add a 'None' entry, as sorting on a second term is optional this.SecondaryComboBox.Items.Add(Constant.SortTermValues.NoneDisplayLabel); this.SecondaryComboBox.SelectedIndex = 0; SortTerm sortTermDB = this.database.ImageSet.GetSortTerm(1); // Get the 2nd sort term from the database foreach (SortTerm sortTerm in this.sortTermList) { // If the current sort term is the one already selected in the primary combo box, skip it // as it doesn't make sense to sort again on the same term if (sortTerm.DisplayLabel == (string)this.PrimaryComboBox.SelectedItem) { continue; } this.SecondaryComboBox.Items.Add(sortTerm.DisplayLabel); // If the current SecondarySort sort term matches the current item, then set it as selected. // Note that we check both terms for it, as File would be the 2nd term vs. the 1st term if (sortTermDB.DataLabel == sortTerm.DataLabel) { this.SecondaryComboBox.SelectedIndex = this.SecondaryComboBox.Items.Count - 1; } } // Set the radio buttons to the default values this.SecondaryAscending.IsChecked = sortTermDB.IsAscending == Constant.BooleanValue.True; this.SecondaryDescending.IsChecked = sortTermDB.IsAscending == Constant.BooleanValue.False; }
// Handle the standard menu sorting items private async void MenuItemSort_Click(object sender, RoutedEventArgs e) { // While this should never happen, don't do anything if we don's have any data if (this.DataHandler == null || this.DataHandler.FileDatabase == null) { return; } MenuItem mi = (MenuItem)sender; SortTerm sortTerm1 = new SortTerm(); SortTerm sortTerm2 = new SortTerm(); switch (mi.Name) { case "MenuItemSortByRelativPathDateTime": // The default sortTerm1.DataLabel = Constant.DatabaseColumn.RelativePath; sortTerm1.DisplayLabel = Constant.DatabaseColumn.RelativePath; sortTerm1.ControlType = Constant.DatabaseColumn.RelativePath; sortTerm1.IsAscending = Constant.BooleanValue.True; sortTerm2.DataLabel = Constant.DatabaseColumn.DateTime; sortTerm2.DisplayLabel = Constant.DatabaseColumn.DateTime; sortTerm2.ControlType = Constant.DatabaseColumn.DateTime; sortTerm2.IsAscending = Constant.BooleanValue.True; break; case "MenuItemSortByDateTime": sortTerm1.DataLabel = Constant.DatabaseColumn.DateTime; sortTerm1.DisplayLabel = Constant.DatabaseColumn.DateTime; sortTerm1.ControlType = Constant.DatabaseColumn.DateTime; sortTerm1.IsAscending = Constant.BooleanValue.True; break; case "MenuItemSortByFileName": sortTerm1.DataLabel = Constant.DatabaseColumn.File; sortTerm1.DisplayLabel = Constant.DatabaseColumn.File; sortTerm1.ControlType = Constant.DatabaseColumn.File; sortTerm1.IsAscending = Constant.BooleanValue.True; break; case "MenuItemSortById": sortTerm1.DataLabel = Constant.DatabaseColumn.ID; sortTerm1.DisplayLabel = Constant.DatabaseColumn.ID; sortTerm1.ControlType = Constant.DatabaseColumn.ID; sortTerm1.IsAscending = Constant.BooleanValue.True; break; default: break; } // Record the sort terms in the image set this.DataHandler.FileDatabase.ImageSet.SetSortTerm(sortTerm1, sortTerm2); // Do the sort, showing feedback in the status bar and by checking the appropriate menu item await this.DoSortAndShowSortFeedbackAsync(true).ConfigureAwait(true); }
// Show feedback in the UI based on the sort selection // Record the current sort state // Note: invoked by the above menu functions AND the OnFolderLoadingComplete method // SAULXXX WE MAY WANT TO MOVE THIS ELSEWHERE private void ShowSortFeedback(bool updateMenuChecks) { // Get the two sort terms SortTerm[] sortTerm = new SortTerm[2]; for (int i = 0; i <= 1; i++) { sortTerm[i] = this.DataHandler.FileDatabase.ImageSet.GetSortTerm(i); } // If instructed to do so, Reset menu item checkboxes based on the current sort terms. if (updateMenuChecks == false) { return; } this.MenuItemSortByRelativPathDateTime.IsChecked = false; this.MenuItemSortByDateTime.IsChecked = false; this.MenuItemSortByFileName.IsChecked = false; this.MenuItemSortById.IsChecked = false; this.MenuItemSortCustom.IsChecked = false; // Determine which selection best fits the sort terms (e.g., a custom selection on just ID will be ID rather than Custom) if (sortTerm[0].DataLabel == Constant.DatabaseColumn.DateTime && sortTerm[0].IsAscending == Constant.BooleanValue.True && string.IsNullOrEmpty(sortTerm[1].DataLabel)) { this.MenuItemSortByDateTime.IsChecked = true; } else if (sortTerm[0].DataLabel == Constant.DatabaseColumn.RelativePath && sortTerm[0].IsAscending == Constant.BooleanValue.True && sortTerm[1].DataLabel == Constant.DatabaseColumn.DateTime && sortTerm[1].IsAscending == Constant.BooleanValue.True) { this.MenuItemSortByRelativPathDateTime.IsChecked = true; } else if (sortTerm[0].DataLabel == Constant.DatabaseColumn.ID && sortTerm[0].IsAscending == Constant.BooleanValue.True && string.IsNullOrEmpty(sortTerm[1].DataLabel)) { this.MenuItemSortById.IsChecked = true; } else if (sortTerm[0].DataLabel == Constant.DatabaseColumn.File && sortTerm[0].IsAscending == Constant.BooleanValue.True && string.IsNullOrEmpty(sortTerm[1].DataLabel)) { this.MenuItemSortByFileName.IsChecked = true; } else { this.MenuItemSortCustom.IsChecked = true; } // Provide feedback in the status bar of what sort terms are being used this.StatusBar.SetSort(sortTerm[0].DataLabel, sortTerm[0].IsAscending == Constant.BooleanValue.True, sortTerm[1].DataLabel, sortTerm[1].IsAscending == Constant.BooleanValue.True); }
private async void MenuItemEditDuplicateRecord_Click(object sender, RoutedEventArgs e) { // Check: ideally the sort terms will be RelativePath x DateTime, as otherwise the duplicates may not be in sorted order. // The various flags determine whether we show only a problem message, a duplicate info message, or both. SortTerm sortTermDB1 = this.DataHandler.FileDatabase.ImageSet.GetSortTerm(0); // Get the 1st sort term from the database SortTerm sortTermDB2 = this.DataHandler.FileDatabase.ImageSet.GetSortTerm(1); // Get the 2nd sort term from the database bool sortTermsOKForDuplicateOrdering = (sortTermDB1.DataLabel == Constant.DatabaseColumn.RelativePath && sortTermDB2.DataLabel == Constant.DatabaseColumn.DateTime) || (sortTermDB1.DataLabel == Constant.DatabaseColumn.DateTime && String.IsNullOrWhiteSpace(sortTermDB2.DataLabel)); if (this.State.SuppressHowDuplicatesWork == false || sortTermsOKForDuplicateOrdering == false) { if (Dialogs.MenuEditHowDuplicatesWorkDialog(this, sortTermsOKForDuplicateOrdering, this.State.SuppressHowDuplicatesWork) == false) { return; } } await this.DuplicateCurrentRecord(); }
// Populate the two combo boxes with potential sort terms // We use the custom selection to get the field we need, but note that: // - we add a None entry to the secondary combo box, allowing the user to clear the selection private void PopulatePrimaryUIElements() { // Populate the Primary combo box with choices // By default, we select sort by ID unless its over-ridden this.PrimaryComboBox.SelectedIndex = 0; SortTerm sortTermDB = this.database.ImageSet.GetSortTerm(0); // Get the 1st sort term from the database foreach (SortTerm sortTerm in this.sortTermList) { this.PrimaryComboBox.Items.Add(sortTerm.DisplayLabel); // If the current PrimarySort sort term matches the current item, then set it as selected // if (sortTerm.DataLabel == database.ImageSet.GetSortTerm(0) || sortTerm.DataLabel == database.ImageSet.GetSortTerm(1 if (sortTerm.DataLabel == sortTermDB.DataLabel) { this.PrimaryComboBox.SelectedIndex = this.PrimaryComboBox.Items.Count - 1; } } // Set the radio buttons to the default values this.PrimaryAscending.IsChecked = sortTermDB.IsAscending == Constant.BooleanValue.True; this.PrimaryDescending.IsChecked = sortTermDB.IsAscending == Constant.BooleanValue.False; }
private async void MenuItemEditPopulateFieldWithEpisodeData_Click(object sender, RoutedEventArgs e) { // Check: needs at least one file in the current selection, if (this.DataHandler?.FileDatabase?.CountAllCurrentlySelectedFiles == 0 || this.DataHandler.FileDatabase.ImageSet == null) { Dialogs.MenuOptionsCantPopulateDataFieldWithEpisodeAsNoFilesDialog(this); return; } // Check: needs at least one Note field that could be populated bool noteControlOk = false; foreach (ControlRow control in this.DataHandler.FileDatabase.Controls) { if (control.Type == Constant.Control.Note) { noteControlOk = true; } } if (!noteControlOk) { Dialogs.MenuOptionsCantPopulateDataFieldWithEpisodeAsNoNoteFields(this); return; } // Check: search term, can only be none or relativePath bool searchTermsOk = true; List <SearchTerm> searchTerms = this.DataHandler.FileDatabase.CustomSelection?.SearchTerms; if (searchTerms == null) { searchTermsOk = false; } else { foreach (SearchTerm searchTerm in searchTerms) { if (searchTerm.UseForSearching && searchTerm.DataLabel != Constant.DatabaseColumn.RelativePath) { searchTermsOk = false; } } } // Check: if the sort terms must be RelativePath x DateTime, or DateTime all ascending SortTerm sortTermDB1 = this.DataHandler.FileDatabase.ImageSet.GetSortTerm(0); // Get the 1st sort term from the database SortTerm sortTermDB2 = this.DataHandler.FileDatabase.ImageSet.GetSortTerm(1); // Get the 2nd sort term from the database bool sortTermsOk = (sortTermDB1.DataLabel == Constant.DatabaseColumn.RelativePath && Constant.BooleanValue.True == sortTermDB1.IsAscending && sortTermDB2.DataLabel == Constant.DatabaseColumn.DateTime && Constant.BooleanValue.True == sortTermDB1.IsAscending) || (sortTermDB1.DataLabel == Constant.DatabaseColumn.DateTime && Constant.BooleanValue.True == sortTermDB1.IsAscending && String.IsNullOrWhiteSpace(sortTermDB2.DataLabel)); if (!noteControlOk || !searchTermsOk || !sortTermsOk) { if (false == Dialogs.MenuOptionsCantPopulateDataFieldWithEpisodeAsSortIsWrong(this, searchTermsOk, sortTermsOk)) { return; } } // Warn the user that they are currently in a selection displaying only a subset of files, and make sure they want to continue. if (Dialogs.MaybePromptToApplyOperationOnSelectionDialog(this, this.DataHandler.FileDatabase, this.State.SuppressSelectedPopulateFieldFromMetadataPrompt, "'Populate a data field with episodedata...'", (bool optOut) => { this.State.SuppressSelectedPopulateFieldFromMetadataPrompt = optOut; })) { PopulateFieldWithEpisodeData populateField = new PopulateFieldWithEpisodeData(this, this.DataHandler.FileDatabase); { if (this.ShowDialogAndCheckIfChangesWereMade(populateField)) { await this.FilesSelectAndShowAsync().ConfigureAwait(true); } ; } } }
} // End Constructor public void AddSort <TKey>(System.Func <T, TKey> sorter, SortDirection direction) // where TKey: System.IComparable // where TKey: struct, System.IComparable { this.m_sorts.Add(SortTerm <T> .Create <TKey>(sorter, direction)); }