public static void Add(this ViewModel viewModel, Shortcut shortcut, bool msg = true) { if (msg && viewModel.Settings.Shortcuts.Any(x => x.ProcessFile.Path == shortcut.ProcessFile.Path)) if ( Popup.Show( "A shortcut with this path already exists.\n\nAre you sure you want to add this shortcut?", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes) == MessageBoxResult.No) return; viewModel.Settings.Shortcuts.Add(shortcut); }
public ShortcutProperties(Shortcut shortcut = null) { InitializeComponent(); Title = shortcut == null ? "New Shortcut" : "Edit Shortcut"; if (shortcut == null) NewShortcut = new Shortcut(); else NewShortcut = (Shortcut) shortcut.Clone(); DataContext = NewShortcut; }
public static void Execute(this ViewModel viewModel, Shortcut shortcut, bool hide = true) { if (viewModel.Settings.HideOnExecute && hide && viewModel.Settings.OpenMode != OpenMode.AlwaysOpen) { viewModel.View?.HideUi(); } try { ProcessHelper.Launch(shortcut.ProcessFile); } catch (Win32Exception) { if (Popup.Show( $"This file does not exist.\n\nDo you want to remove \"{GetName(shortcut)}\"?", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes) == MessageBoxResult.No) { return; } viewModel.Remove(shortcut); } }
public static void Add(this ViewModel viewModel, Shortcut shortcut, bool msg = true, int position = -1) { if (msg && viewModel.Settings.Shortcuts.Any(x => x.ProcessFile.Path == shortcut.ProcessFile.Path)) { if ( Popup.Show( $"\"{shortcut.ProcessFile.Path}\" has already been added.\n\nDo you want to add it again?", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes) == MessageBoxResult.No) { return; } } if (position > -1 && position < viewModel.Settings.Shortcuts.Count) { viewModel.Settings.Shortcuts.Insert(position, shortcut); } else { viewModel.Settings.Shortcuts.Add(shortcut); } }
public static string GetFriendlyNameWithData(this Shortcut shortcut) { var dataList = new List <string>(); if (!string.IsNullOrWhiteSpace(shortcut.ProcessFile.Path)) { dataList.Add(shortcut.ProcessFile.Path); } if (!string.IsNullOrWhiteSpace(shortcut.ProcessFile.Arguments)) { dataList.Add(shortcut.ProcessFile.Arguments); } var dataStr = string.Join(", ", dataList); if (!string.IsNullOrWhiteSpace(dataStr)) { dataStr = $" ({dataStr})"; } return($"{shortcut.Name}{dataStr}"); }
private void ShortcutExecuteExecute(Shortcut shortcut) { ShortcutFocusExecute(shortcut); this.Execute(SelectedShortcut, !Keyboard.Modifiers.HasFlag(Settings.KeepOpenWithModifierKey)); }
public void ReloadShortcutHotKey(Shortcut shortcut) { HotkeyStore.RegisterHotkey(shortcut.Hotkey, delegate { this.Execute(shortcut); }); }
public static Shortcut MoveUp(this ViewModel viewModel, Shortcut shortcut, bool toEnd = false) => toEnd?viewModel.Settings.Shortcuts.MoveToTop(shortcut) : viewModel.Settings.Shortcuts.MoveUp(shortcut);
public static string GetName(Shortcut shortcut) => string.IsNullOrWhiteSpace(shortcut.Name) ? shortcut.ProcessFile.Path : shortcut.Name;
private static ImageSource GetShortcutIcon(Shortcut shortcut) { try { if (!string.IsNullOrWhiteSpace(shortcut.IconPath) && File.Exists(shortcut.IconPath)) { var bmi = new BitmapImage(); bmi.BeginInit(); bmi.CacheOption = BitmapCacheOption.OnLoad; bmi.UriSource = new Uri(shortcut.IconPath, UriKind.Absolute); bmi.EndInit(); return bmi; } if (File.Exists(shortcut.ProcessFile.Path) || Directory.Exists(shortcut.ProcessFile.Path)) return IconHelper.GetPathIcon(shortcut.ProcessFile.Path); if (shortcut.SpecialType == "Help") return SystemIcons.Information.ToImageSource(); if (LinkHelper.IsHyperlink(shortcut.ProcessFile.Path)) return IconHelper.Extract("shell32.dll", 13, true).ToImageSource(); } catch { // ignored } return SystemIcons.Error.ToImageSource(); }
public static string GetName(Shortcut shortcut) => string.IsNullOrWhiteSpace(shortcut.Name) ? shortcut.ProcessFile.Path : shortcut.Name;
private void btnCancel_Click(object sender, RoutedEventArgs e) { NewShortcut = null; DialogResult = true; }
public static void OpenProperties(this ViewModel viewModel, Shortcut shortcut) { var dialog = new ShortcutProperties(shortcut); dialog.ShowDialog(); if (dialog.NewShortcut == null) return; viewModel.Settings.Shortcuts[viewModel.Settings.Shortcuts.IndexOf(shortcut)] = dialog.NewShortcut; viewModel.ReloadShortcutHotKey(dialog.NewShortcut); }
public static void Execute(this ViewModel viewModel, Shortcut shortcut, bool hide = true) { if (viewModel.Settings.HideOnExecute && hide && viewModel.Settings.OpenMode != OpenMode.AlwaysOpen) viewModel.View?.HideUi(); if (File.Exists(shortcut.ProcessFile.Path) || Directory.Exists(shortcut.ProcessFile.Path) || LinkHelper.IsHyperlink(shortcut.ProcessFile.Path)) { ProcessHelper.Launch(shortcut.ProcessFile); } else { if (Popup.Show( $"This file does not exist. Do you want to remove \"{GetName(shortcut)}\"?", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) == MessageBoxResult.No) return; viewModel.Remove(shortcut); } }
private void btnCancel_Click(object sender, RoutedEventArgs e) { NewShortcut = null; DialogResult = true; }
public static void OpenFolder(this Shortcut shortcut) { ProcessHelper.OpenFolder(shortcut.ProcessFile.Path); }
private void ShortcutFocusExecute(Shortcut shortcut) { SelectedShortcut = shortcut; }
public void ReloadShortcutHotKey(Shortcut shortcut) { HotkeyStore.RegisterHotkey(shortcut.Hotkey, delegate { this.Execute(shortcut); }); }
public static void Remove(this ViewModel viewModel, Shortcut shortcut, bool msg = false) { if (msg && Popup.Show($"Are you sure you want to remove \"{GetName(shortcut)}\"?", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) == MessageBoxResult.No) return; viewModel.Settings.Shortcuts.Remove(shortcut); if (shortcut.Hotkey.Key != Key.None) HotkeyStore.RemoveHotkey(shortcut.Hotkey.Guid); }
public static Shortcut MoveDown(this ViewModel viewModel, Shortcut shortcut, bool toEnd = false) => toEnd ? viewModel.Settings.Shortcuts.MoveToBottom(shortcut) : viewModel.Settings.Shortcuts.MoveDown(shortcut);
private void ShortcutExecuteExecute(Shortcut shortcut) { ShortcutFocusExecute(shortcut); this.Execute(SelectedShortcut, !Keyboard.Modifiers.HasFlag(Settings.KeepOpenWithModifierKey)); }
public static Shortcut MoveUp(this ViewModel viewModel, Shortcut shortcut, bool toEnd = false) => toEnd ? viewModel.Settings.Shortcuts.MoveToTop(shortcut) : viewModel.Settings.Shortcuts.MoveUp(shortcut);
private void ShortcutFocusExecute(Shortcut shortcut) { SelectedShortcut = shortcut; }
public static Shortcut MoveDown(this ViewModel viewModel, Shortcut shortcut, bool toEnd = false) => toEnd ? viewModel.Settings.Shortcuts.MoveToBottom(shortcut) : viewModel.Settings.Shortcuts.MoveDown(shortcut);