示例#1
0
        private async void SaveSearch_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(NewSearch.Species))
            {
                return;
            }

            try
            {
                NewSearch.Order = ListSearches.Where(sc => sc.Group == NewSearch.Group).Max(sc => sc.Order) + 100;
            }
            catch (InvalidOperationException) // no entries for .Max - ignore
            { }

            IsLoading = true;
            try
            {
                StatusText = $"Loading {NewSearch.Species}...";
                await arkReaderWild.EnsureSpeciesIsLoaded(NewSearch.Species);

                StatusText = $"Ready";
            }
            finally
            {
                IsLoading = false;
            }

            ListSearches.Add(NewSearch);
            NewSearch             = null;
            NewSearchActive       = false;
            CreateSearchAvailable = true;

            MarkSearchesChanged();
        }
示例#2
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            var sourceItem = (SearchCriteria)dropInfo.Data;
            var targetItem = (SearchCriteria)dropInfo.TargetItem;

            var ii = dropInfo.InsertIndex;
            var ip = dropInfo.InsertPosition;

            // Change source item's group
            sourceItem.Group = targetItem.Group;

            // Try to figure out the other item to insert between, or pick a boundary
            var options = ListSearches
                          .Where(sc => sc != sourceItem)
                          .Where(sc => sc.Group == targetItem.Group)
                          .OrderBy(sc => sc.Order)
                          .ToArray();

            // Make no changes if it was dropped on itself
            if (options.Length == 0)
            {
                return;
            }

            var above = options.Where(sc => sc.Order < targetItem.Order).OrderByDescending(sc => sc.Order).FirstOrDefault();
            var below = options.Where(sc => sc.Order > targetItem.Order).OrderBy(sc => sc.Order).FirstOrDefault();

            var aboveOrder = (above == null) ? options.Min(sc => sc.Order) - 1 : above.Order;
            var belowOrder = (below == null) ? options.Max(sc => sc.Order) + 1 : below.Order;

            // Update the order to be mid-way between either above or below, based on drag insert position
            sourceItem.Order = (targetItem.Order + (ip.HasFlag(RelativeInsertPosition.AfterTargetItem) ? belowOrder : aboveOrder)) / 2;

            // Renumber the results
            var orderedSearches = ListSearches
                                  .OrderBy(sc => sc.Group)
                                  .ThenBy(sc => sc.Order)
                                  .ToArray();

            for (var i = 0; i < orderedSearches.Length; i++)
            {
                orderedSearches[i].Order = i;
            }

            // Force binding update
            CollectionViewSource.GetDefaultView(searchesList.ItemsSource).Refresh();

            // Save list
            MarkSearchesChanged();
        }
示例#3
0
        private void SaveSearch_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(NewSearch.Species))
            {
                return;
            }

            try
            {
                NewSearch.Order = ListSearches.Where(sc => sc.Group == NewSearch.Group).Max(sc => sc.Order) + 100;
            }
            catch (InvalidOperationException) // no entries for .Max - ignore
            { }

            ListSearches.Add(NewSearch);
            NewSearch             = null;
            NewSearchActive       = false;
            CreateSearchAvailable = true;

            MarkSearchesChanged();
        }
示例#4
0
        private void SaveSearch_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(NewSearch.Species))
            {
                return;
            }

            List <String>  NewSearchList = new List <String>(AllSpecies.Where(species => species.Contains(NewSearch.Species)));
            SearchCriteria tempSearch;
            int            order = 100;

            //If we lose our selection default back to Shopping List
            try
            {
                Properties.Settings.Default.LastGroup = groupsCombo.Text;
            }
            catch
            {
                Properties.Settings.Default.LastGroup = "Shopping List";
            }
            //Set and save property
            Properties.Settings.Default.GroupSearch = NewSearch.GroupSearch;
            Properties.Settings.Default.Save();

            if (NewSearchList.Count == 0 && !NewSearch.GroupSearch) // No matches
            {                                                       //Trigger default values so the user knows we did search to match
                NewSearch             = null;
                tempSearch            = null;
                NewSearchActive       = false;
                CreateSearchAvailable = true;
                return;
            }
            ObservableCollection <SearchCriteria> tempListSearch = new ObservableCollection <SearchCriteria>(ListSearches.Where(sc => sc.Group == (String)groupsCombo.SelectedValue));

            if (tempListSearch.Count > 0)
            {
                order = (int)ListSearches.Where(sc => sc.Group == NewSearch.Group).Max(sc => sc.Order) + 100;
            }
            //Check for group based search
            if (NewSearch.GroupSearch)
            {
                tempSearch             = new SearchCriteria(NewSearch);
                tempSearch.Species     = NewSearch.Species;
                tempSearch.Order       = order; //Sort order
                tempSearch.GroupSearch = NewSearch.GroupSearch;
                ListSearches.Add(tempSearch);
            }
            else
            {
                try
                {
                    foreach (String newDino in NewSearchList)
                    {
                        if (tempListSearch.Count == 0 || tempListSearch.Where(dino => dino.Species == newDino).Count() == 0)
                        {
                            tempSearch             = new SearchCriteria(NewSearch);
                            tempSearch.Species     = newDino;
                            tempSearch.Order       = order;
                            tempSearch.GroupSearch = NewSearch.GroupSearch;
                            ListSearches.Add(tempSearch);
                            order += 100;
                        }
                    }
                }
                catch (InvalidOperationException) // no entries for .Max - ignore
                { }
            }


            NewSearch             = null;
            tempSearch            = null;
            NewSearchActive       = false;
            CreateSearchAvailable = true;

            MarkSearchesChanged();
        }