예제 #1
0
 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;
         });
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
 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);
             }
         });
     }
 }
예제 #4
0
 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));
     }
 }
예제 #5
0
        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);
        }
예제 #6
0
        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);
                }
            }
        }
예제 #7
0
 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);
         }
     });
 }
예제 #8
0
 private void DeleteShortcutImageIfHas(ShortcutEntity se)
 {
     try
     {
         if (se != null && !string.IsNullOrEmpty(se.ImageName))
         {
             ShortcutImageHelper.DeleteImage(se.ImageName);
         }
     }
     catch (Exception e)
     {
         Log.Exception(e);
     }
 }
예제 #9
0
        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);
                        }
                    }
                }
            }
        }