public static ImageListViewItem FindItem(ImageListViewItemCollection imageListViewItemCollection, string fullFilename) { ImageListViewItem foundItem = null; foreach (ImageListViewItem item in imageListViewItemCollection) { if (FilesCutCopyPasteDrag.IsFilenameEqual(item.FileFullPath, fullFilename)) { foundItem = item; break; } } return(foundItem); }
/// <summary> /// Initializes a new instance of the ImageListView class. /// </summary> public ImageListView() { // Renderer parameters controlSuspended = false; rendererSuspendCount = 0; rendererNeedsPaint = true; mColors = ImageListViewColor.Default; Renderer = new ImageListViewRenderer(); // Property defaults AutoRotateThumbnails = true; AllowCheckBoxClick = true; AllowColumnClick = true; AllowColumnResize = true; AllowDrag = false; AllowDuplicateFileNames = false; AllowPaneResize = true; mBorderStyle = BorderStyle.Fixed3D; mCacheMode = CacheMode.OnDemand; mCacheLimitAsItemCount = 0; mCacheLimitAsMemory = 20 * 1024 * 1024; mColumns = new ImageListViewColumnHeaderCollection(this); resources = new ResourceManager("Manina.Windows.Forms.ImageListViewResources", typeof(ImageListView).Assembly); mDefaultImage = resources.GetObject("DefaultImage") as Image; mErrorImage = resources.GetObject("ErrorImage") as Image; mRatingImage = resources.GetObject("RatingImage") as Image; mEmptyRatingImage = resources.GetObject("EmptyRatingImage") as Image; GroupHeaderFont = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold); ColumnHeaderFont = new Font("Microsoft Sans Serif", 8.25f); mIntegralScroll = false; mItems = new ImageListViewItemCollection(this); MultiSelect = true; mPaneWidth = 240; mRetryOnError = true; mSelectedItems = new ImageListViewSelectedItemCollection(this); mCheckedItems = new ImageListViewCheckedItemCollection(this); mSortColumn = 0; mGroupColumn = 0; mSortOrder = SortOrder.None; mGroupOrder = SortOrder.None; SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.Selectable | ControlStyles.UserMouse, true); ScrollBars = true; ShellIconFallback = true; ShellIconFromFileContent = true; Size = new Size(120, 100); mShowCheckBoxes = false; mCheckBoxAlignment = ContentAlignment.BottomRight; mCheckBoxPadding = new Size(2, 2); mShowFileIcons = false; mIconAlignment = ContentAlignment.TopRight; mIconPadding = new Size(2, 2); Text = string.Empty; mThumbnailSize = new Size(96, 96); mUseEmbeddedThumbnails = UseEmbeddedThumbnails.Auto; mUseWIC = UseWIC.Auto; mView = View.Thumbnails; mViewOffset = new Point(0, 0); mShowScrollBars = true; // Child controls hScrollBar = new HScrollBar(); vScrollBar = new VScrollBar(); hScrollBar.Visible = false; vScrollBar.Visible = false; hScrollBar.Scroll += hScrollBar_Scroll; vScrollBar.Scroll += vScrollBar_Scroll; Controls.Add(hScrollBar); Controls.Add(vScrollBar); // Groups groups = new ImageListViewGroupCollection(this); showGroups = false; // Lazy refresh timer lazyRefreshTimer = new System.Timers.Timer(); lazyRefreshTimer.Interval = ImageListViewRenderer.LazyRefreshInterval; lazyRefreshTimer.Enabled = false; lazyRefreshTimer.Elapsed += lazyRefreshTimer_Tick; lazyRefreshCallback = new RefreshDelegateInternal(Refresh); // Helpers layoutManager = new ImageListViewLayoutManager(this); navigationManager = new ImageListViewNavigationManager(this); // Cache nabagers defaultAdaptor = new ImageListViewItemAdaptors.FileSystemAdaptor(); thumbnailCache = new ImageListViewCacheThumbnail(this); shellInfoCache = new ImageListViewCacheShellInfo(this); metadataCache = new ImageListViewCacheMetadata(this); disposed = false; }
public ImageListViewSelectedItemEnumerator(ImageListViewItemCollection collection) { owner = collection; current = -1; lastItem = Guid.Empty; }
/// <summary> /// Initializes a new instance of the ImageListView class. /// </summary> public ImageListView() { mColors = new ImageListViewColor(); SetRenderer(new ImageListViewRenderer()); AllowColumnClick = true; AllowColumnResize = true; AllowDrag = false; AllowDuplicateFileNames = false; AllowPaneResize = true; mBorderStyle = BorderStyle.Fixed3D; mCacheMode = CacheMode.OnDemand; mCacheLimitAsItemCount = 0; mCacheLimitAsMemory = 20 * 1024 * 1024; mColumns = new ImageListViewColumnHeaderCollection(this); ResourceManager manager = new ResourceManager("Manina.Windows.Forms.ImageListViewResources", Assembly.GetExecutingAssembly()); mDefaultImage = manager.GetObject("DefaultImage") as Image; mErrorImage = manager.GetObject("ErrorImage") as Image; HeaderFont = this.Font; mItems = new ImageListViewItemCollection(this); MultiSelect = true; mPaneWidth = 240; mRetryOnError = true; mSelectedItems = new ImageListViewSelectedItemCollection(this); mCheckedItems = new ImageListViewCheckedItemCollection(this); mSortColumn = ColumnType.Name; mSortOrder = SortOrder.None; SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.Selectable | ControlStyles.UserMouse, true); ScrollBars = true; mShowCheckBoxes = false; mCheckBoxAlignment = ContentAlignment.BottomRight; mCheckBoxPadding = new Size(2, 2); mShowFileIcons = false; mIconAlignment = ContentAlignment.TopRight; mIconPadding = new Size(2, 2); Text = string.Empty; mThumbnailSize = new Size(96, 96); mUseEmbeddedThumbnails = UseEmbeddedThumbnails.Auto; mView = View.Thumbnails; mViewOffset = new Point(0, 0); hScrollBar = new HScrollBar(); vScrollBar = new VScrollBar(); hScrollBar.Visible = false; vScrollBar.Visible = false; hScrollBar.Scroll += new ScrollEventHandler(hScrollBar_Scroll); vScrollBar.Scroll += new ScrollEventHandler(vScrollBar_Scroll); layoutManager = new ImageListViewLayoutManager(this); forceRefresh = false; navigationManager = new ImageListViewNavigationManager(this); cacheManager = new ImageListViewCacheManager(this); itemCacheManager = new ImageListViewItemCacheManager(this); disposed = false; }
/// <summary> /// Initializes a new instance of the ImageListView class. /// </summary> public ImageListView() { SetRenderer(new ImageListViewRenderer()); AllowColumnClick = true; AllowColumnResize = true; AllowDrag = false; AllowDuplicateFileNames = false; AllowPaneResize = true; BackColor = SystemColors.Window; mBorderStyle = BorderStyle.Fixed3D; mCacheMode = CacheMode.OnDemand; mCacheLimitAsItemCount = 0; mCacheLimitAsMemory = 20 * 1024 * 1024; mColumns = new ImageListViewColumnHeaderCollection(this); mDefaultImage = ImageListViewResources.image; mErrorImage = ImageListViewResources.exclamation; HeaderFont = this.Font; mItems = new ImageListViewItemCollection(this); mPaneWidth = 240; mRetryOnError = true; mSelectedItems = new ImageListViewSelectedItemCollection(this); mSortColumn = ColumnType.Name; mSortOrder = SortOrder.None; SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.Selectable | ControlStyles.UserMouse, true); Text = string.Empty; mThumbnailSize = new Size(96, 96); mUseEmbeddedThumbnails = UseEmbeddedThumbnails.Auto; mView = View.Thumbnails; mViewOffset = new Point(0, 0); hScrollBar = new HScrollBar(); vScrollBar = new VScrollBar(); hScrollBar.Visible = false; vScrollBar.Visible = false; hScrollBar.Scroll += new ScrollEventHandler(hScrollBar_Scroll); vScrollBar.Scroll += new ScrollEventHandler(vScrollBar_Scroll); layoutManager = new ImageListViewLayoutManager(this); forceRefresh = false; navigationManager = new ImageListViewNavigationManager(this); cacheManager = new ImageListViewCacheManager(this); itemCacheManager = new ImageListViewItemCacheManager(this); disposed = false; }
private void SelectedGroupByMatch(ImageListView imageListView, bool checkFileCreated, bool checkMediaTaken, bool checkAllDates, int maxDayRange, bool checkLocationName, bool checkLocationCity, bool checkLocationDistrict, bool checkLocationCountry, bool checkAllLocations) { try { ImageListViewHandler.SuspendLayout(imageListView1); ImageListViewHandler.Enable(imageListView, false); TreeViewFolderBrowserHandler.Enabled(treeViewFolderBrowser1, false); GlobalData.DoNotTrigger_ImageListView_SelectionChanged = true; #region Do the work using (new WaitCursor()) { ImageListViewItemCollection imageListViewItems = imageListView.Items; List <GroupMacth> groupMacthSourceList = new List <GroupMacth>(); #region Init foreach (ImageListViewItem imageListViewItem in imageListView.SelectedItems) { Metadata metadata = databaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(new FileEntryBroker(imageListViewItem.FileFullPath, imageListViewItem.DateModified, MetadataBrokerType.ExifTool)); GroupMacth groupMacthSource = new GroupMacth(); groupMacthSource.IsMetadataNull = (metadata == null); groupMacthSource.FileDate = imageListViewItem.Date; groupMacthSource.MediaTaken = metadata?.MediaDateTaken; groupMacthSource.LocationName = metadata?.LocationName; groupMacthSource.LocationCity = metadata?.LocationCity; groupMacthSource.LocationDistrict = metadata?.LocationState; groupMacthSource.LocationCountry = metadata?.LocationCountry; groupMacthSourceList.Add(groupMacthSource); } #endregion imageListView.ClearSelection(); #region Find and Select foreach (ImageListViewItem imageListViewItem in imageListView.Items) { Metadata metadata = databaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(new FileEntryBroker(imageListViewItem.FileFullPath, imageListViewItem.DateModified, MetadataBrokerType.ExifTool)); GroupMacth groupMacthCheckWith = new GroupMacth(); groupMacthCheckWith.IsMetadataNull = (metadata == null); groupMacthCheckWith.FileDate = imageListViewItem.Date; groupMacthCheckWith.MediaTaken = metadata?.MediaDateTaken; groupMacthCheckWith.LocationName = metadata?.LocationName; groupMacthCheckWith.LocationCity = metadata?.LocationCity; groupMacthCheckWith.LocationDistrict = metadata?.LocationState; groupMacthCheckWith.LocationCountry = metadata?.LocationCountry; bool isItemsEqual = false; foreach (GroupMacth groupMacthSource in groupMacthSourceList) { isItemsEqual = GroupMacth.IsMatch(groupMacthSource, groupMacthCheckWith, checkFileCreated, checkMediaTaken, checkAllDates, maxDayRange, checkLocationName, checkLocationCity, checkLocationDistrict, checkLocationCountry, checkAllLocations); if (isItemsEqual) { break; } } if (isItemsEqual) { imageListViewItem.Selected = true; } else { imageListViewItem.Selected = false; } } #endregion } #endregion } catch (Exception ex) { Logger.Error(ex); KryptonMessageBox.Show("Unexpected error occur.\r\nException message:" + ex.Message + "\r\n", "Unexpected error occur", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } finally { GlobalData.DoNotTrigger_ImageListView_SelectionChanged = false; TreeViewFolderBrowserHandler.Enabled(treeViewFolderBrowser1, true); ImageListViewHandler.Enable(imageListView, true); ImageListViewHandler.ResumeLayout(imageListView1); imageListView.Focus(); ImageListView_SelectionChanged_Action_ImageListView_DataGridView(false); } }
/// <summary> /// /// </summary> /// <param name="imageListView"></param> /// <param name="direction">-1 = backwards, 0 both directions (when direction not slected), 1 forward</param> /// <returns></returns> private int SelectedGroupFindBaseItemIndex(ImageListView imageListView, int direction) { using (new WaitCursor()) { ImageListViewItemCollection imageListViewItems = imageListView.Items; int selectedCount = imageListView.SelectedItems.Count; int baseItemIndex; if (direction == 0) { baseItemIndex = lastGroupBaseIndex; //-1 is unknown } else { if (selectedCount == 0) { if (direction == 1) { baseItemIndex = 0; } else { baseItemIndex = imageListViewItems.Count - 1; } } else { bool isSelecedFound = false; bool isBaseItemFound = false; if (direction == 1) { baseItemIndex = 0; } else { baseItemIndex = imageListViewItems.Count - 1; } while (!isBaseItemFound && baseItemIndex > -1 && baseItemIndex < imageListViewItems.Count) { ImageListViewItem imageListViewItem = imageListViewItems[baseItemIndex]; if (!isSelecedFound && imageListViewItem.Selected) { isSelecedFound = true; if (selectedCount == 1 && lastGroupBaseIndex != baseItemIndex) { isBaseItemFound = true; } } if (isSelecedFound && !imageListViewItem.Selected) { isBaseItemFound = true; } if (!isBaseItemFound) { baseItemIndex += direction; } } } } if (baseItemIndex > imageListViewItems.Count - 1) { baseItemIndex = 0; } if (baseItemIndex < 0) { baseItemIndex = imageListViewItems.Count - 1; } lastGroupBaseIndex = baseItemIndex; return(baseItemIndex); } }
private void SelectedGroupBySelections(ImageListView imageListView, int baseItemIndex, int direction, int maxSelectCount, bool checkFileCreated, bool checkMediaTaken, bool checkAllDates, int maxDayRange, bool checkLocationName, bool checkLocationCity, bool checkLocationDistrict, bool checkLocationCountry, bool checkAllLocations) { try { ImageListViewHandler.SuspendLayout(imageListView1); ImageListViewHandler.Enable(imageListView, false); TreeViewFolderBrowserHandler.Enabled(treeViewFolderBrowser1, false); GlobalData.DoNotTrigger_ImageListView_SelectionChanged = true; #region Do the work using (new WaitCursor()) { ImageListViewItemCollection imageListViewItems = imageListView.Items; if (baseItemIndex < imageListViewItems.Count && direction != 0) { #region Init Variables GroupMacth groupMacthSource = new GroupMacth(); ImageListViewItem imageListViewItem = imageListViewItems[baseItemIndex]; Metadata metadata = databaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(new FileEntryBroker(imageListViewItem.FileFullPath, imageListViewItem.DateModified, MetadataBrokerType.ExifTool)); groupMacthSource.IsMetadataNull = (metadata == null); groupMacthSource.FileDate = imageListViewItem.Date; groupMacthSource.MediaTaken = metadata?.MediaDateTaken; groupMacthSource.LocationName = metadata?.LocationName; groupMacthSource.LocationCity = metadata?.LocationCity; groupMacthSource.LocationDistrict = metadata?.LocationState; groupMacthSource.LocationCountry = metadata?.LocationCountry; #endregion imageListView.ClearSelection(); #region Find and Select int selectedCount = 0; int itemIndex = baseItemIndex; while (itemIndex > -1 && itemIndex < imageListViewItems.Count && selectedCount < maxSelectCount) { imageListViewItem = imageListViewItems[itemIndex]; metadata = databaseAndCacheMetadataExiftool.ReadMetadataFromCacheOnly(new FileEntryBroker(imageListViewItem.FileFullPath, imageListViewItem.DateModified, MetadataBrokerType.ExifTool)); GroupMacth groupMacthCheckWith = new GroupMacth(); groupMacthCheckWith.IsMetadataNull = (metadata == null); groupMacthCheckWith.FileDate = imageListViewItem.Date; groupMacthCheckWith.MediaTaken = metadata?.MediaDateTaken; groupMacthCheckWith.LocationName = metadata?.LocationName; groupMacthCheckWith.LocationCity = metadata?.LocationCity; groupMacthCheckWith.LocationDistrict = metadata?.LocationState; groupMacthCheckWith.LocationCountry = metadata?.LocationCountry; bool isItemsEqual = GroupMacth.IsMatch(groupMacthSource, groupMacthCheckWith, checkFileCreated, checkMediaTaken, checkAllDates, maxDayRange, checkLocationName, checkLocationCity, checkLocationDistrict, checkLocationCountry, checkAllLocations); if (isItemsEqual) { selectedCount++; imageListViewItem.Selected = true; } else { imageListViewItem.Selected = false; } itemIndex += direction; } #endregion imageListView.EnsureVisible(itemIndex - direction); imageListView.EnsureVisible(baseItemIndex); } lastGroupBaseIndex = baseItemIndex; } #endregion } catch (Exception ex) { Logger.Error(ex); KryptonMessageBox.Show("Unexpected error occur.\r\nException message:" + ex.Message + "\r\n", "Unexpected error occur", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } finally { GlobalData.DoNotTrigger_ImageListView_SelectionChanged = false; TreeViewFolderBrowserHandler.Enabled(treeViewFolderBrowser1, true); ImageListViewHandler.Enable(imageListView, true); ImageListViewHandler.ResumeLayout(imageListView1); imageListView.Focus(); ImageListView_SelectionChanged_Action_ImageListView_DataGridView(false); } }