private void ChooseIcon_Click(object sender, RoutedEventArgs e) { OpenFileDialog fd = new OpenFileDialog(); fd.Multiselect = false; fd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); fd.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png, *.ico) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png; *.ico"; if (fd.ShowDialog() == true) { var fileInfo = new FileInfo(fd.FileName); if (fileInfo.Length > 200 * 1024) { DialogUtil.showError(parent, "The image size should no more than 200KB"); } else { var img = new BitmapImage(new Uri(fd.FileName)); if (img.PixelHeight > 128 || img.PixelWidth > 128) { DialogUtil.showError(parent, "The image width and height should mo more than 128 pixel"); } else { QCommand.Img = img; } } } }
private void InitHotKey() { try { rawHotKey = RawHotKey.Parse(mainWindowHotKey.Value); hotKey = new HotKey(rawHotKey.Key, rawHotKey.HotKeyModifiers); } catch (Exception e) { Trace.TraceError(e.Message); DialogUtil.showError(owningWindow, e.Message); } }
private void SafeSave(SettingItem settingItem) { try { SettingItemUtils.SaveSettingItem(settingItem); } catch (Exception r) { Trace.TraceError(r.Message); Trace.TraceError(r.StackTrace); DialogUtil.showError(owningWindow, r.InnerException.Message); } }
private async void Save_Click(object sender, RoutedEventArgs e) { var error = HasError(); if (error != null) { DialogUtil.showError(this.parent, error); } else { doSave(); quickCommands.CollectionChanged -= QuickCommands_CollectionChanged; await parent.HideMetroDialogAsync(this); } }
private void Save_Click(object sender, RoutedEventArgs e) { if (QCommand.Error != null) { DialogUtil.showError(this.parent, QCommand.Error); } else { try { var dbContext = QuickCommandContext.Instance; QuickCommand qc = dbContext.QuickCommands.SingleOrDefault(b => b.UUID == QCommand.UUID); if (qc != null) { qc.Alias = QCommand.Alias; qc.Path = QCommand.Path; qc.Command = QCommand.Command; qc.WorkDirectory = QCommand.WorkDirectory; qc.CustomIcon = QCommand.CustomIcon; dbContext.SaveChanges(); } else { dbContext.QuickCommands.Add(QCommand); dbContext.SaveChanges(); if (AddedNewQuickCommand != null) { AddedNewQuickCommand(QCommand); } } parent.HideMetroDialogAsync(this); } catch (Exception ee) { Trace.TraceError(ee.Message); Trace.TraceError(ee.StackTrace); DialogUtil.showError(parent, ee.Message); } } }