private void FindDuplicate() { Bitmap icon; if ((listView.SelectedItem is FileElement) && IsImage((listView.SelectedItem as Element).Name)) { MemoryStream ms = new MemoryStream(); (listView.SelectedItem as FileElement).SaveTo(ms); ms.Position = 0; Bitmap tmp = new Bitmap(ms); icon = ImgConverter.ResizeImage(tmp, thumbnailSize); tmp?.Dispose(); ms.Dispose(); } else { icon = (listView.SelectedItem as Element).Icon; } DirElement dir = (listView.Tag as DirElement) != null ? (listView.Tag as DirElement) : xdb; Finder f = new Finder(dir, icon, ShowList); icon = null; f.Owner = this; f.Show(); }
private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.V)) { if (Clipboard.ContainsImage()) { Bitmap tmp = ImgConverter.BitmapFromSource(Clipboard.GetImage()); SetThumbnail(ImgConverter.ResizeImage(tmp, MainWindow.thumbnailSize)); tmp?.Dispose(); } } }
private void Window_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if ((files.Length > 0) && (MainWindow.IsImage(files[0]))) { Bitmap tmp = new Bitmap(files[0]); SetThumbnail(ImgConverter.ResizeImage(tmp, MainWindow.thumbnailSize)); tmp?.Dispose(); } } }
private void InsertImageFromClipboard(bool Refresh) { if ((!editable) || (!System.Windows.Clipboard.ContainsImage())) { return; } Element newFile = null; ushort maxTries = 3; do { try { Bitmap tmp = ImgConverter.BitmapFromSource(System.Windows.Clipboard.GetImage()); using (MemoryStream stream = new MemoryStream()) { //tmp1 через який баг в GDI, не хоче працювати з tmp Bitmap tmp1 = new Bitmap(tmp); tmp1.Save(stream, ImageFormat.Jpeg); tmp1?.Dispose(); Bitmap icon = ImgConverter.ResizeImage(tmp, thumbnailSize); string FileName = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + ".jpg"; if (isCompareImage) { var duplicates = GetDuplicates(FileName, icon); if (duplicates.Count > 0) { ShowDuplicateFilesList(duplicates, FileName, icon); icon?.Dispose(); tmp?.Dispose(); return; } } stream.Position = 0; try { newFile = (listView.Tag as DirElement)?.AddFile(stream, FileName, false, icon); } catch (Exception e) { Refresh = false; System.Windows.MessageBox.Show(e.Message); } icon?.Dispose(); maxTries = 0; } tmp?.Dispose(); } catch (ExternalException ex) { maxTries--; } } while (maxTries > 0); if (Refresh && newFile != null) { ShowFiles(listView.Tag as Element, newFile); } if (clipboardClean_CheckBox.IsChecked == true) { System.Windows.Clipboard.Clear(); } }
private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if ((Keyboard.Modifiers == ModifierKeys.None) && (((e.Key >= Key.D0) && (e.Key <= Key.Z)) || ((e.Key >= Key.NumPad0) && (e.Key <= Key.NumPad9)))) { if (search_text_box.Visibility == Visibility.Hidden) { search_text_box.Clear(); } search_text_box.Visibility = Visibility.Visible; search_text_box.Focus(); } if (e.Key == Key.F5) { ShowFiles(listView.Tag as DirElement); } if (search_text_box.Visibility == Visibility.Hidden) { if (e.Key == Key.Back) { if (LastParent != null) { var el = listView.Tag as Element; ShowFiles(LastParent.Parent == null ? LastParent : LastParent.Parent, el); } } if (e.Key == Key.Escape) { search_text_box.Visibility = Visibility.Hidden; ShowFiles(LastParent); } } if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S)) { SaveSelectedAs(); return; } if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.X)) { CutSelected(); return; } if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.V)) { Insert_Click(null, null); return; } if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.F)) { DirElement dir = (listView.Tag as DirElement) != null ? (listView.Tag as DirElement) : xdb; Finder f = new Finder(dir, ShowList); f.Owner = this; f.Show(); return; } if (e.Key == Key.D && (Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Alt)) == (ModifierKeys.Control | ModifierKeys.Alt)) { Bitmap icon; if ((listView.SelectedItem is FileElement) && IsImage((listView.SelectedItem as Element).Name)) { MemoryStream ms = new MemoryStream(); (listView.SelectedItem as FileElement).SaveTo(ms); ms.Position = 0; Bitmap tmp = new Bitmap(ms); icon = ImgConverter.ResizeImage(tmp, thumbnailSize); tmp?.Dispose(); ms.Dispose(); } else { icon = (listView.SelectedItem as Element).Icon; } ShowList(xdb.FindAllByIcon(icon, 0)); return; } if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.D)) { CreateNewDir(); return; } }