private void cbMaintTag_SelectionChanged(object sender, SelectionChangedEventArgs e) { var changedTag = e.AddedItems[0] as TagModel; if (changedTag != null) { ScreenModels.Clear(); if (changedTag.Name == "Everything") { AllScreenModels.ForEach(a => ScreenModels.Add(a)); } else { foreach (var item in AllScreenModels.Where(a => a.SelectedTag.Name == changedTag.Name)) { ScreenModels.Add(item); } } } }
public MainWindow(int displayCondition, string startupPath) { InitializeComponent(); this.DataContext = this; userCtrlFullScreenImg.DataContext = ImageFull; Stopwatch sw = new Stopwatch(); sw.Start(); var allPng = Directory.GetFiles(startupPath, "*.png", SearchOption.AllDirectories); var pngFromScreensDir = allPng.Where(a => Directory.GetParent(a).Name == "Screeny").ToList(); if (pngFromScreensDir == null && !pngFromScreensDir.Any()) { MessageBox.Show("Brak screenów!"); Close(); } var screensDetails = pngFromScreensDir.Select(a => new ScreenModel(a, 1920 * Scale, 1080 * Scale)) .Where(c => FilterScreens(c.CreationDate, displayCondition)) .OrderBy(b => b.CreationDate) //.Take(20) .Reverse() .ToList(); foreach (var item in screensDetails) { item.SetBitmap(); } var grouped = screensDetails.GroupBy(a => a.Directory).ToList(); foreach (var item in grouped) { foreach (var internalItem in item) { ScreenModels.Add(internalItem); AllScreenModels.Add(internalItem); FullPathToScreenDict.Add(internalItem.Name, internalItem); } } sw.Stop(); TimerDragging.Tick += (sender, e) => { if (IsDragging) { mySv.ScrollToVerticalOffset(mySv.VerticalOffset + ScrollFactor); } }; TimerDragging.Interval = TimeSpan.FromMilliseconds(10); ICollectionView view = CollectionViewSource.GetDefaultView(ScreenModels); view.GroupDescriptions.Add(new PropertyGroupDescription("FormatCreationDate")); mainListbox.ItemsSource = view; ScreenModel.SetFullScreen = (source) => { ImageFull.ImgName = BitmapFromUri(new Uri(source)); ShowFullImage(); userCtrlFullScreenImg.btnNext.Focus(); }; ScreenModel.MessageBoxShow = (text) => { return(MessageBox.Show(text, "Warning", MessageBoxButton.YesNo)); }; ScreenModel.RemoveImageFromCollection = (image) => { ScreenModels.Remove(image); image.ButtonImage.Freeze(); ImageFull.ImgName?.Freeze(); File.Delete(image.Name); }; Dictionary <string, string> TagNameToBrushKeyDict = new Dictionary <string, string> { { "FL Studio", "FlStudioGradientKey" }, { "Xamarin", "XamarinGradientKey" }, { "ASP", "AspGradientKey" }, { "Empty", "EmptyGradientKey" }, { "Everything", "EverythingGradientKey" }, { "Inne", "InneGradientKey" }, }; ScreenModel.GetBrushForTagFunc = (key) => { var brushKey = TagNameToBrushKeyDict[key]; var brush = (Brush)this.FindResource(brushKey); return(brush); }; ScreenModel.SerializeSelectedTag = (fullPath, tagName) => { if (TagStatesDict.ContainsKey(fullPath)) { TagStatesDict[fullPath] = tagName; } else { TagStatesDict.Add(fullPath, tagName); } SerializeTagsState(TagStatesDict); }; FullScreenImageControl.PreviousScreen = () => { if (mainListbox.SelectedIndex == 0) { return; } mainListbox.SelectedIndex--; var selectedItem = mainListbox.SelectedItem as ScreenModel; ImageFull.ImgName = selectedItem.ButtonImage; }; FullScreenImageControl.NextScreen = () => { if (mainListbox.SelectedIndex == ScreenModels.Count - 1) { return; } mainListbox.SelectedIndex++; var selectedItem = mainListbox.SelectedItem as ScreenModel; ImageFull.ImgName = selectedItem.ButtonImage; }; FullScreenImageControl.RemoveScreen = () => { var selectedItem = mainListbox.SelectedItem as ScreenModel; if (selectedItem != null) { var res = MessageBox.Show("Czy na pewno chcesz usunąć screena?", "Warning", MessageBoxButton.YesNo); if (res == MessageBoxResult.No) { return; } int removedIdx = mainListbox.SelectedIndex; ScreenModel.RemoveImageFromCollection(selectedItem); mainListbox.SelectedIndex = removedIdx; var selectedItemNext = mainListbox.SelectedItem as ScreenModel; ImageFull.ImgName = selectedItemNext.ButtonImage; } }; FullScreenImageControl.GoBack = () => { HideFullImage(); var listBoxItem = (ListBoxItem)mainListbox .ItemContainerGenerator .ContainerFromItem(mainListbox.SelectedItem); listBoxItem.Focus(); }; foreach (var item in ScreenModels) { item.InitializeTags(); } TagStatesDict = DeserializeTagsState() ?? new Dictionary <string, string>(); foreach (var item in TagStatesDict) { if (!FullPathToScreenDict.ContainsKey(item.Key)) { continue; } FullPathToScreenDict[item.Key].InitializeSelectedTag(FullPathToScreenDict[item.Key].Tags.First(a => a.Name == item.Value)); } TagsMain.Add(new TagModel() { Name = "Everything", BackgroundBrush = (Brush)this.FindResource("EverythingGradientKey") }); TagsMain.Add(new TagModel() { Name = "FL Studio", BackgroundBrush = (Brush)this.FindResource("FlStudioGradientKey") }); TagsMain.Add(new TagModel() { Name = "Xamarin", BackgroundBrush = (Brush)this.FindResource("XamarinGradientKey") }); TagsMain.Add(new TagModel() { Name = "ASP", BackgroundBrush = (Brush)this.FindResource("AspGradientKey") }); TagsMain.Add(new TagModel() { Name = "Inne", BackgroundBrush = (Brush)this.FindResource("InneGradientKey") }); TagsMain.Add(new TagModel() { Name = "Empty", BackgroundBrush = (Brush)this.FindResource("EmptyGradientKey") }); }