public void SetupCommands(DirectoryTree dtree, DirectoryTreeViewModel rootModel)
        {

            #region RefreshCommand
            RefreshCommand = new SimpleRoutedCommand(NavigationCommands.Refresh)
            {
                CanExecuteDelegate = x => true,
                ExecuteDelegate = x => rootModel.SelectedDirectoryModel.Refresh()
            };
            #endregion

            #region RenamdCommand
            RenameCommand = new SimpleRoutedCommand(ApplicationCommands.SaveAs)
            {
                CanExecuteDelegate = x =>
                {
                    return rootModel.SelectedDirectoryModel != null &&
                        rootModel.SelectedDirectoryModel.EmbeddedModel.IsEditable;
                },
                ExecuteDelegate = x =>
                {
                    if (dtree._lastSelectedContainer != null)
                    {
                        DirectoryTree.SetIsEditing(dtree._lastSelectedContainer, true);
                    }
                }
            };
            #endregion RenamdCommand            
        }
 public static void Register(Type hostType, SimpleRoutedCommand simpleRoutedCommand)
 {
     CommandManager.RegisterClassCommandBinding(hostType, simpleRoutedCommand.CommandBinding);
 }
 //http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!255.entry?wa=wsignin1.0
 public static void Register(Type hostType, SimpleRoutedCommand simpleRoutedCommand, InputGesture inputGesture)
 {
     CommandManager.RegisterClassCommandBinding(hostType, simpleRoutedCommand.CommandBinding);
     CommandManager.RegisterClassInputBinding(hostType, new InputBinding(simpleRoutedCommand, inputGesture));
     simpleRoutedCommand._routedCommand.InputGestures.Add(inputGesture);
 }
        public void SetupCommands(FileList flist, FileListViewModel rootModel)
        {
            #region IndividualItemCommand - Open, Rename
            OpenCommand = new SimpleRoutedCommand(ApplicationCommands.Open)
            {
                CanExecuteDelegate = x =>
                {
                    return rootModel.CurrentDirectoryModel != null && rootModel.CurrentDirectoryModel.SelectedCount == 1;
                },
                ExecuteDelegate = x =>
                {
                    rootModel.CurrentDirectoryModel.SelectedViewModels[0].Expand(rootModel,
                        rootModel.CurrentDirectoryModel.SelectedViewModels[0].EmbeddedModel);
                }
            };

            RenameCommand = new SimpleRoutedCommand(ApplicationCommands.SaveAs)
            {
                CanExecuteDelegate = x =>
                {
                    return rootModel.CurrentDirectoryModel != null && rootModel.CurrentDirectoryModel.SelectedCount == 1;
                },
                ExecuteDelegate = x =>
                {
                    rootModel.CurrentDirectoryModel.IsEditing = !rootModel.CurrentDirectoryModel.IsEditing;
                }
            };

            #endregion

            #region NewFolderCommand
            NewFolderCommand = new SimpleRoutedCommand(FileListCommands.NewFolder)
            {
                CanExecuteDelegate = x =>
                {
                    if ((rootModel.CurrentDirectoryModel.EmbeddedDirectoryModel.EmbeddedDirectoryEntry.Attributes & FileAttributes.ReadOnly) != 0)
                        return false;

                    if (x == null)
                        return true;

                    if (x is string)
                    {
                        string type = (string)x;
                        switch (type.ToLower())
                        {
                            case "zip":
                            case "7z": return true;
                        }
                    }

                    return false;
                },
                ExecuteDelegate = x =>
                {
                    string type = x as string;
                    if (x != null) type = type.ToLower();
                    rootModel.CurrentDirectoryModel.NewFolder();
                }
            };
            #endregion

            #region SelectAllCommand
            SelectAllCommand = new SimpleRoutedCommand(ApplicationCommands.SelectAll)
            {
                CanExecuteDelegate = x =>
                {
                    return rootModel.CurrentDirectoryModel != null && rootModel.CurrentDirectoryModel.HasSubEntries;
                },
                ExecuteDelegate = x =>
                {
                    if (rootModel.CurrentDirectoryModel.SelectedCount == rootModel.CurrentDirectoryModel.SubEntriesInternal.Count)
                        rootModel.CurrentDirectoryModel.UnselectAll();
                    else rootModel.CurrentDirectoryModel.SelectAll();
                }

            };
            #endregion

            #region RefreshCommand
            RefreshCommand = new SimpleRoutedCommand(NavigationCommands.Refresh)
            {
                CanExecuteDelegate = x => true,
                ExecuteDelegate = x => rootModel.CurrentDirectoryModel.Refresh()
            };
            #endregion

            #region FindCommand

            FindCommand = new SimpleRoutedCommand(ApplicationCommands.Find)
            {
                CanExecuteDelegate = x =>
                {
                    return rootModel.CurrentDirectoryModel != null && !rootModel.CurrentDirectoryModel.IsEditing;
                },
                ExecuteDelegate = x =>
                {
                    flist.LookupAdorner.UpdateVisibilty(true);
                    FocusManager.SetFocusedElement(flist, flist.LookupAdorner);
                }
            };

            #endregion
        }
        protected void SetupCommands(Func<ExModel[]> getSelectionFunc,
            Func<DirectoryModel> getCurrentFunc, Func<System.Drawing.Point> getMousePositionFunc)
        {
            #region OpenCommand and ContextMenuCommand
            OpenCommand = new SimpleRoutedCommand(ApplicationCommands.Open)
            {
                CanExecuteDelegate = x => { return getCurrentFunc() != null; },
                ExecuteDelegate = x => { Process.Start(getCurrentFunc().EmbeddedDirectoryEntry.FullName); }
            };

            ContextMenuCommand = new SimpleRoutedCommand(ApplicationCommands.ContextMenu)
            {
                CanExecuteDelegate = x =>
                {
                    return getSelectionFunc() != null && getSelectionFunc().Length > 0;
                },
                ExecuteDelegate = x =>
                {
                    ContextMenuWrapper _cmw = new ContextMenuWrapper();

                    _cmw.OnBeforeInvokeCommand += (InvokeCommandEventHandler)delegate(object sender, InvokeCommandEventArgs args)
                    {
                        if (args.Command == "open")
                            args.ContinueInvoke = false;
                        if (args.Command == "openas" && args.SelectedItems != null
                            && args.SelectedItems.Length == 1)
                            args.ContinueInvoke = false;
                    };
                    var selectedItems = (from model in getSelectionFunc() select model.EmbeddedEntry).ToArray();

                    System.Drawing.Point pt = getMousePositionFunc();
                    string command = _cmw.Popup(selectedItems, pt);
                    switch (command)
                    {
                        case "open": OpenCommand.Execute(null); break;
                        case "openas": OpenCommand.Execute(null); break;
                        case "rename": RenameCommand.Execute(null); break;
                        case "refresh": RefreshCommand.Execute(null); break;
                    }
                }
            };
            #endregion

            #region Delete, Copy and Paste
            DeleteCommand = new SimpleRoutedCommand(ApplicationCommands.Delete)
            {
                CanExecuteDelegate = x =>
                {
                    if (getSelectionFunc() != null && getSelectionFunc().Length > 0) ;
                    {
                        var selectedItems = (from model in getSelectionFunc() select model.EmbeddedEntry).ToArray();
                        foreach (FileSystemInfoEx item in selectedItems)
                        {
                            if ((item.Attributes & FileAttributes.ReadOnly) != 0)
                                return false;
                        }
                        return true;
                    }
                    //return false;
                },
                ExecuteDelegate = x =>
                {
                    var selectedItems = (from model in getSelectionFunc() select model.EmbeddedEntry).ToArray();
                    int itemCount = selectedItems.Length;
                    if (System.Windows.Forms.MessageBox.Show(String.Format("Are you sure want to permanently remove these {0} item{1}?",
                        itemCount, itemCount > 1 ? "s" : ""), "Delete", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                        foreach (FileSystemInfoEx item in selectedItems)
                            item.Delete();
                }
            };

            CopyCommand = new SimpleRoutedCommand(ApplicationCommands.Copy)
            {
                CanExecuteDelegate = x =>
                {
                    return getSelectionFunc() != null && getSelectionFunc().Length > 0;
                },
                ExecuteDelegate = x =>
                {
                    var selectedItems = (from model in getSelectionFunc() select model.EmbeddedEntry).ToArray();


                    StringCollection fileList = new StringCollection();

                    foreach (FileSystemInfoEx item in selectedItems)
                        fileList.Add(item.FullName);

                    Clipboard.Clear();
                    Clipboard.SetFileDropList(fileList);
                }
            };


            PasteCommand = new SimpleRoutedCommand(ApplicationCommands.Paste)
            {
                CanExecuteDelegate = x =>
                {
                    return
                        getCurrentFunc() != null &&
                        ((getCurrentFunc().EmbeddedDirectoryEntry.Attributes & FileAttributes.ReadOnly) != 0) &&
                        Clipboard.ContainsFileDropList();
                },
                ExecuteDelegate = x =>
                {
                    DirectoryInfoEx parentDir = getCurrentFunc().EmbeddedDirectoryEntry;
                    List<FileSystemInfoEx> entryList = new List<FileSystemInfoEx>();
                    foreach (string path in Clipboard.GetFileDropList())
                        IOTools.Copy(path, PathEx.Combine(parentDir.FullName, PathEx.GetFileName(path)));                        
                }
            };
            #endregion

            #region PropertiesCommand
            PropertiesCommand = new SimpleRoutedCommand(ApplicationCommands.Properties)
            {
                CanExecuteDelegate = x =>
                {
                    return getSelectionFunc() != null && getSelectionFunc().Length > 0;
                },
                ExecuteDelegate = x =>
                {
                    System.Windows.Point position = Mouse.GetPosition(null);
                    var selectedItems = (from model in getSelectionFunc() select model.EmbeddedEntry).ToArray();

                    ContextMenuHelper.InvokeCommand(getSelectionFunc()[0].EmbeddedEntry.Parent,
                        selectedItems, "properties", new System.Drawing.Point((int)position.X, (int)position.Y));
                }
            };
            #endregion
        }
 public static void Register(Type hostType, SimpleRoutedCommand simpleRoutedCommand)
 {
     CommandManager.RegisterClassCommandBinding(hostType, simpleRoutedCommand.CommandBinding);
 }
 //http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!255.entry?wa=wsignin1.0
 public static void Register(Type hostType, SimpleRoutedCommand simpleRoutedCommand, InputGesture inputGesture)
 {
     CommandManager.RegisterClassCommandBinding(hostType, simpleRoutedCommand.CommandBinding);
     CommandManager.RegisterClassInputBinding(hostType, new InputBinding(simpleRoutedCommand, inputGesture));
     simpleRoutedCommand._routedCommand.InputGestures.Add(inputGesture);
 }