private void ShowImage(string imageName) { if (string.IsNullOrEmpty(imageName)) { this.tbkImage.Visibility = Visibility.Collapsed; this.imgMain.Visibility = Visibility.Collapsed; this.imgMain.Tag = null; this.btnAddImage.Visibility = Visibility.Visible; this.btnAddImage.IsEnabled = true; this.btnUpdateImage.Visibility = Visibility.Collapsed; } else { this.tbkImage.Visibility = Visibility.Visible; this.imgMain.Visibility = Visibility.Visible; this.imgMain.Tag = imageName; this.btnAddImage.Visibility = Visibility.Collapsed; this.btnUpdateImage.Visibility = Visibility.Visible; this.btnUpdateImage.IsEnabled = false; ShortcutImageHelper.UseImage(imageName, (imgSrc) => { this.imgMain.Source = imgSrc; this.btnUpdateImage.IsEnabled = true; }); } }
private string SelectImageFile(string parnFnOld = null) { string imageName = null; try { imageName = OpenFileDialogEx.GetOpenFileName("选择图片", "图片文件|*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff", null); if (!string.IsNullOrEmpty(imageName)) { if (FileEx.IsFileLengthMoreKB(imageName, 1024)) { throw new Exception("图片大小不能超过1MB"); } BitmapImage bitmapImage; if (!BitmapImageEx.TryCreateFromFile(imageName, out bitmapImage)) { throw new Exception("无法解析图片,请选择正常的图片"); } imageName = ShortcutImageHelper.AddNewImage(imageName, parnFnOld); } } catch (Exception ex) { Log.Exception(ex); MsgBox.ShowErrTip(ex.Message, null); } return(imageName); }
private static void SetOrSendShortcut(this ShortcutEntity shortcut, ChatDesk desk, bool isSend, bool focusEditor) { if (shortcut == null) { return; } if (string.IsNullOrEmpty(shortcut.ImageName)) { if (isSend) { desk.Editor.SendPlainText(shortcut.Text); desk.Editor.FocusEditor(true); } else { desk.Editor.SetPlainText(shortcut.Text, true, focusEditor); } } else { ShortcutImageHelper.UseImage(shortcut.ImageName, image => { if (isSend) { desk.Editor.SendPlainTextAndImage(shortcut.Text, image); desk.Editor.FocusEditor(true); } else { desk.Editor.SetPlainTextAndImage(shortcut.Text, image, focusEditor); } }); } }
private void imgMain_MouseDown(object sender, MouseButtonEventArgs e) { if (this.imgMain.Tag != null && e.ChangedButton == MouseButton.Left && e.ClickCount == 2) { e.Handled = true; Process.Start(ShortcutImageHelper.GetFullPath(this.imgMain.Tag as string)); } }
private TreeNode CreateShortcut(ShortcutEntity fromShortcut, string dbAccount) { var shortcut = EntityHelper.Create <ShortcutEntity>(dbAccount); shortcut.Text = fromShortcut.Text; shortcut.ImageName = ShortcutImageHelper.AddNewImage(fromShortcut.ImageName); shortcut.Code = fromShortcut.Code; return(shortcut); }
private void CopyImageIntoCache() { var imgDir = this.GetImgDir(); if (!string.IsNullOrEmpty(imgDir)) { var files = Directory.GetFiles(imgDir); foreach (var fn in files.xSafeForEach()) { ShortcutImageHelper.CopyImageIntoCache(fn); } } }
private void btnDeleteImage_Click(object sender, RoutedEventArgs e) { MsgBox.ShowNotTipAgain("确定要删除图片?", "操作确认", "WndShortcutEditor_DeleteImage", (b1, okClicked) => { if (!b1 || okClicked) { string text = this.imgMain.Tag as string; if (!string.IsNullOrEmpty(text)) { ShortcutImageHelper.DeleteImage(text); } this.ShowImage(null); } }); }
private void DeleteShortcutImageIfHas(ShortcutEntity se) { try { if (se != null && !string.IsNullOrEmpty(se.ImageName)) { ShortcutImageHelper.DeleteImage(se.ImageName); } } catch (Exception e) { Log.Exception(e); } }
private void Delete() { CtlTreeView ctv = this.GetShowingTreeview(null); if (this.CanEdit(ctv)) { var tn = ctv.Delete(); if (tn != null) { this.LoadDatas(ctv, null); if (!ctv.IsCatalogType(tn)) { var shortcut = tn as ShortcutEntity; if (shortcut != null && !string.IsNullOrEmpty(shortcut.ImageName)) { ShortcutImageHelper.DeleteImage(shortcut.ImageName); } } } } }