private void PasteItemsFromClipboard() { var pastedItemsJson = Clipboard.GetDataObject()?.GetData(CmdArgsPackage.ClipboardCmdItemFormat) as string; if (pastedItemsJson != null) { var pastedItems = JsonConvert.DeserializeObject <CmdArgClipboardItem[]>(pastedItemsJson); foreach (var item in pastedItems) { CurrentArgumentList.AddNewItem(item.Command, item.Enabled); } } else if (Clipboard.ContainsText()) { var pastedItems = Clipboard.GetText().Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); foreach (var s in pastedItems) { CurrentArgumentList.AddNewItem(s); } } }
public ToolWindowViewModel() { solutionArguments = new Dictionary <string, ListViewModel>(); AddEntryCommand = new RelayCommand( () => { CurrentArgumentList.AddNewItem(command: "", enabled: true); }, canExecute: _ => { return(StartupProject != null); }); RemoveEntriesCommand = new RelayCommand( () => { RemoveSelectedItems(); }, canExecute: _ => { return(StartupProject != null && CurrentArgumentList.SelectedItems != null && CurrentArgumentList.SelectedItems.Count != 0); }); MoveEntriesUpCommand = new RelayCommand( () => { CurrentArgumentList.MoveEntriesUp(CurrentArgumentList.SelectedItems.Cast <CmdArgItem>()); }, canExecute: _ => { return(this.StartupProject != null && CurrentArgumentList.SelectedItems != null && CurrentArgumentList.SelectedItems.Count != 0); }); MoveEntriesDownCommand = new RelayCommand( () => { CurrentArgumentList.MoveEntriesDown(CurrentArgumentList.SelectedItems.Cast <CmdArgItem>()); }, canExecute: _ => { return(this.StartupProject != null && CurrentArgumentList.SelectedItems != null && CurrentArgumentList.SelectedItems.Count != 0); }); CopyCommandlineCommand = new RelayCommand( () => { IEnumerable <string> enabledEntries; enabledEntries = this.EnabledItemsForCurrentProject().Select(e => e.Command); string prjCmdArgs = string.Join(" ", enabledEntries); Clipboard.SetText(prjCmdArgs); }, canExecute: _ => { return(this.StartupProject != null); // && CurrentArgumentList.SelectedItems != null && CurrentArgumentList.SelectedItems.Count != 0; }); ToggleItemEnabledCommand = new RelayCommand <CmdArgItem>( (item) => { CurrentArgumentList.ToogleEnabledForItem(item, Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)); }, canExecute: _ => { return(this.StartupProject != null); }); CopySelectedItemsCommand = new RelayCommand(CopySelectedItemsToClipboard, canExecute: _ => CurrentArgumentList.SelectedItems.Count != 0); PasteItemsCommand = new RelayCommand(PasteItemsFromClipboard, canExecute: _ => StartupProject != null); CutItemsCommand = new RelayCommand(CutItemsToClipboard, canExecute: _ => CurrentArgumentList.SelectedItems.Count != 0); }