/// <summary> /// /// </summary> /// <param name="item"></param> private void AddLibraryItem(LibraryListItem item) { if (this.status != null) { this.status.Progress = (int)(100.0 * (this.listView.Items.Count + 1.0) / this.Library.Count); } this.listView.Items.Add(item); if (this.listView.Items.Count == this.Library.Count) { this.listView.Items[0].Selected = true; } }
private void listView_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { var item = listView.GetItemAt(e.X, e.Y) as LibraryListItem; if (item == null) { this.tipListView.Active = false; } else if (item != lastLibListItem) { this.tipListView.Active = true; this.tipListView.SetToolTip(this.listView, "Name: " + Path.GetFileName(item.Item.Path) + "\n" + "Type: " + Path.GetExtension(item.Item.Path).Substring(1).ToUpperInvariant() + "\n" + "Dimensions: " + item.Size.Width + " x " + item.Size.Height + "\n" + "Size: " + (item.FileSize / 1024) + " KB"); } lastLibListItem = item; }
/// <summary> /// /// </summary> private void LoadImages() { LibraryItem[] items = this.library.GetImageItems(true); //AUTO Arrange Removes almost all flickering while adding on first pass!! //this.listView.AutoArrange = false; // Stage 1: Fast loading with generic icon foreach (LibraryItem libraryItem in items) { LibraryListItem libraryListItem = new LibraryListItem(libraryItem); this.Invoke(this.delegateAddLibraryItem, new Object[] { libraryListItem }); Application.DoEvents(); libraryListItem.ImageIndex = GetGenericImage(Path.GetExtension(libraryListItem.Item.Path)); if (eventThreadStop.WaitOne(0, true)) { eventThreadFinish.Set(); return; } } this.listView.AutoArrange = true; // Stage 2: Slower Thumbnail Generation foreach (LibraryListItem libraryListItem in this.listView.Items) { this.GenerateThumbnail(libraryListItem); if (eventThreadStop.WaitOne(0, true)) { eventThreadFinish.Set(); return; } } try { this.Invoke(this.delegateThreadFinished, null); } catch { Console.Out.WriteLine("TODO: Invoke fails if application is closed and not cancelled on time"); } }
private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { switch (this.toolBar.Buttons.IndexOf(e.Button)) { case 0: rotateSelection(RotateFlipType.Rotate270FlipNone); break; case 1: rotateSelection(RotateFlipType.Rotate90FlipNone); break; case 2: OnOpenImage(new ImageOpenEventArgs(this.listView.SelectedItems[0] as LibraryListItem)); break; case 4: LibraryListItem item = this.listView.SelectedItems[0] as LibraryListItem; if (item != null) { WallpaperDialog dialog = new WallpaperDialog(item.Item); dialog.ShowDialog(this); } break; case 5: string[] files = new string[this.listView.SelectedIndices.Count]; for (int i = 0; i < files.Length; i++) { files[i] = ((LibraryListItem)this.listView.SelectedItems[i]).Item.Path; } NativeMethods.PrintFiles(files); break; default: break; } }
private void listView_AfterLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e) { if (e.Label == null || e.Label.Length == 0) { e.CancelEdit = true; MessageBox.Show(this, "Picture name can't be empty", Program.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { LibraryListItem item = (LibraryListItem)this.listView.Items[e.Item]; string name = Path.Combine(Path.GetDirectoryName(item.Item.Path), e.Label + Path.GetExtension(item.Item.Path)); try { File.Move(item.Item.Path, name); item.Item.Name = item.Text = e.Label; } catch (Exception ex) { MessageBox.Show(this, "Failed to rename '" + Path.GetFileName(item.Item.Path) + "'\n\nSystem Error:\n" + ex.StackTrace, Program.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public ImageOpenEventArgs(LibraryListItem item) { this.Item = item; }
public void GenerateThumbnail(LibraryListItem item) { double ratio = 0.0; Image image = null; Stream stream = null; Size largeSize = this.previewImageList.ImageSize; Bitmap thumbnail = new Bitmap(largeSize.Width, largeSize.Height); try { stream = new FileStream(item.Item.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); image = Image.FromStream(stream); //Save some data item.Size = image.Size; item.FileSize = stream.Length; //Draw Thumbnail if (image.Width <= largeSize.Width && image.Height <= largeSize.Height) { ratio = 1.0; } else { ratio = Math.Min(((double)largeSize.Width) / image.Width, ((double)largeSize.Height) / image.Height); } Rectangle rec = new Rectangle(0, 0, (int)(image.Width * ratio), (int)(image.Height * ratio)); Graphics gfx = Graphics.FromImage(thumbnail); gfx.Clear(SystemColors.Window); gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; gfx.InterpolationMode = InterpolationMode.High; gfx.DrawImage(image, (largeSize.Width - rec.Width) / 2, (largeSize.Height - rec.Height) / 2, rec.Width, rec.Height); } catch (Exception e) { Console.Out.WriteLine("There was an error while trying to open image '" + item.Text + "'.\n\nError Reason:\n" + e.Message + "\n" + e.StackTrace); thumbnail.Dispose(); thumbnail = null; } finally { if (image != null) { image.Dispose(); } if (stream != null) { stream.Close(); } } if (thumbnail == null) { item.ImageIndex = GetCouldNotLoadImage(); } else if (item.ImageIndex >= ImageListThumbnailStartIndex) { int index = item.ImageIndex; this.previewImageList.Images[index] = thumbnail; } else { item.ImageIndex = this.previewImageList.Images.Add(thumbnail, Color.Transparent); } }