Пример #1
0
        public void ProgressDialog()
        {
            ScriptRunner.RunScript(
                WPFScriptCommands.ShowProgress(_windowManager, "Testing",
                                               WPFScriptCommands.ReportProgress(TransferProgress.From("C:\\Demo\\FileExplorer3.txt", "http://fileexplorer.codeplex.com/FileExplorer3.txt"),
                                                                                WPFScriptCommands.ReportProgress(TransferProgress.IncrementTotalEntries(100),
                                                                                                                 WPFScriptCommands.ReportProgress(TransferProgress.IncrementProcessedEntries(20),
                                                                                                                                                  WPFScriptCommands.ReportProgress(TransferProgress.UpdateCurrentProgress(50))))))
                );
            //_windowManager.ShowDialog(new ProgressDialogViewModel(new ParameterDic()
            //{

            //}));
        }
        public DragDropEffectsEx OnDropCompleted(IEnumerable <IEntryModel> entries, IDataObject da, IEntryModel destDir, DragDropEffectsEx allowedEffects)
        {
            string fileName = PathEx.GetFileName(destDir.FullPath);

            if (fileName == null)
            {
                fileName = destDir.FullPath;
            }

            if (entries.Count() == 0)
            {
                return(DragDropEffectsEx.None);
            }
            if (entries.Any(e => e.Equals(destDir) || e.Parent.Equals(destDir)))
            {
                return(DragDropEffectsEx.None);
            }



            //if (MessageBox.Show(
            //    String.Format("[OnDropCompleted] ({2}) {0} entries to {1}",
            //    entries.Count(), fileName, allowedEffects), "FileBasedDragDropHandler.OnDropCompleted", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                DragDropEffectsEx effect = allowedEffects.HasFlag(DragDropEffectsEx.Copy) ? DragDropEffectsEx.Copy :
                                           allowedEffects.HasFlag(DragDropEffectsEx.Move) ? DragDropEffectsEx.Move : DragDropEffectsEx.None;

                if (effect == DragDropEffectsEx.None)
                {
                    return(DragDropEffectsEx.None);
                }

                ScriptRunner.RunScriptAsync(
                    WPFScriptCommands.ShowProgress(effect.ToString(),
                                                   IOScriptCommands.DiskTransfer(entries.ToArray(), destDir, effect == DragDropEffectsEx.Move, true), true));
                return(effect);
            };
            return(DragDropEffectsEx.None);
        }
Пример #3
0
        public static void InitializeScriptCommands(IExplorerViewModel explorerModel,
                                                    IWindowManager windowManager, IEventAggregator events, params IProfile[] profiles)
        {
            var initilizer = AppViewModel.getInitializer(windowManager, events, explorerModel.RootModels.ToArray(),
                                                         new ColumnInitializers(),
                                                         new ScriptCommandsInitializers(windowManager, events),
                                                         new ToolbarCommandsInitializers(windowManager));


            explorerModel.FileList.Commands.Commands.Open =
                FileList.IfSelection(evm => evm.Count() == 1,
                                     FileList.IfSelection(evm => evm[0].EntryModel.IsDirectory,
                                                          FileList.OpenSelectedDirectory,        //Selected directory
                                                          FileList.AssignSelectionToParameter(
                                                              new OpenWithScriptCommand(null))), //Selected non-directory
                                     ResultCommand.NoError                                       //Selected more than one item, ignore.
                                     );


            explorerModel.FileList.Commands.Commands.NewFolder =
                FileList.Do(flvm => WPFScriptCommands.CreatePath(
                                flvm.CurrentDirectory, "NewFolder", true, true,
                                //FileList.Do(flvm => CoreScriptCommands.DiskCreateFolder(
                                //        flvm.CurrentDirectory, "NewFolder", "{DestinationFolder}", NameGenerationMode.Rename,
                                m => FileList.Refresh(FileList.Select(fm => fm.Equals(m), ResultCommand.OK), true)));

            explorerModel.FileList.Commands.Commands.Delete =
                FileList.IfSelection(evm => evm.Count() >= 1,
                                     WPFScriptCommands.IfOkCancel(windowManager, pd => "Delete",
                                                                  pd => String.Format("Delete {0} items?", (pd["FileList"] as IFileListViewModel).Selection.SelectedItems.Count),
                                                                  WPFScriptCommands.ShowProgress(windowManager, "Delete",
                                                                                                 ScriptCommands.RunInSequence(
                                                                                                     FileList.AssignSelectionToParameter(
                                                                                                         IOScriptCommands.DeleteFromParameter),
                                                                                                     new HideProgress())),
                                                                  ResultCommand.NoError),
                                     NullScriptCommand.Instance);


            explorerModel.FileList.Commands.Commands.Copy =
                FileList.IfSelection(evm => evm.Count() >= 1,
                                     WPFScriptCommands.IfOkCancel(windowManager, pd => "Copy",
                                                                  pd => String.Format("Copy {0} items?", (pd["FileList"] as IFileListViewModel).Selection.SelectedItems.Count),
                                                                  ScriptCommands.RunInSequence(FileList.AssignSelectionToParameter(ClipboardCommands.Copy)),
                                                                  ResultCommand.NoError),
                                     NullScriptCommand.Instance);

            explorerModel.FileList.Commands.Commands.Cut =
                FileList.IfSelection(evm => evm.Count() >= 1,
                                     WPFScriptCommands.IfOkCancel(windowManager, pd => "Cut",
                                                                  pd => String.Format("Cut {0} items?", (pd["FileList"] as IFileListViewModel).Selection.SelectedItems.Count),
                                                                  ScriptCommands.RunInSequence(FileList.AssignSelectionToParameter(ClipboardCommands.Cut)),
                                                                  ResultCommand.NoError),
                                     NullScriptCommand.Instance);

            explorerModel.DirectoryTree.Commands.Commands.Delete =
                WPFScriptCommands.IfOkCancel(windowManager, pd => "Delete",
                                             pd => String.Format("Delete {0}?", ((pd["DirectoryTree"] as IDirectoryTreeViewModel).Selection.RootSelector.SelectedValue.Label)),
                                             WPFScriptCommands.ShowProgress(windowManager, "Delete",
                                                                            ScriptCommands.RunInSequence(
                                                                                DirectoryTree.AssignSelectionToParameter(
                                                                                    IOScriptCommands.DeleteFromParameter),
                                                                                new HideProgress())),
                                             ResultCommand.NoError);


            //explorerModel.DirectoryTree.Commands.Commands.Map =
            //    UIScriptCommands.ExplorerShow

            if (profiles.Length > 0)
            {
                explorerModel.DirectoryTree.Commands.CommandDictionary.Map =
                    Explorer.PickDirectory(initilizer, profiles,
                                           dir => Explorer.BroadcastRootChanged(RootChangedEvent.Created(dir)), ResultCommand.NoError);
            }



            //explorerModel.Commands.ScriptCommands.Transfer =
            //    TransferCommand =
            //    new TransferCommand((effect, source, destDir) =>
            //        source.Profile is IDiskProfile ?
            //            IOScriptCommands.Transfer(source, destDir, effect == DragDropEffects.Move)
            //            : ResultCommand.Error(new NotSupportedException())
            //        , _windowManager);
        }
        public override void NotifySelectionChanged(IEntryModel[] appliedModels)
        {
            List <ICommandModel> subItemList = new List <ICommandModel>();

            if (appliedModels.Count() == 1)
            {
                GoogleDriveItemModel model = appliedModels[0] as GoogleDriveItemModel;
                if (model != null && model.Metadata != null && model.Metadata.ExportLinks != null)
                {
                    foreach (var mimeType in model.Metadata.ExportLinks.Keys)
                    {
                        string url = model.Metadata.ExportLinks[mimeType];

                        string ext   = null;
                        var    match = Regex.Match(url, "[&]exportFormat=(?<ext>[\\w]*)$", RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            ext = "." + match.Groups["ext"].Value;
                        }
                        else
                        {
                            ext = ShellUtils.MIMEType2Extension(mimeType);
                        }

                        string filter      = String.Format("{0} ({1})|*{1}", mimeType, ext);
                        string defaultName = System.IO.Path.ChangeExtension(appliedModels[0].Name, ext);

                        if (ext != null)
                        {
                            subItemList.Add(
                                new CommandModel(
                                    //SaveFile --> ParseOrCreatePath -> ShowProgress -> Download -> HideProgress
                                    //         --> OK (If cancel)
                                    WPFScriptCommands.SaveFilePicker(WindowManager, Events,
                                                                     _rootModelFunc(), filter, defaultName,
                                                                     (fi) => WPFScriptCommands.ParseOrCreatePath(fi.Profile as IDiskProfile,
                                                                                                                 fi.FileName, false,
                                                                                                                 (m) => WPFScriptCommands.ShowProgress(WindowManager, "Saving",
                                                                                                                                                       WPFScriptCommands.Download(url, m,
                                                                                                                                                                                  (appliedModels[0].Profile as GoogleDriveProfile)
                                                                                                                                                                                  .HttpClientFunc(),
                                                                                                                                                                                  new HideProgress()))),
                                                                     ResultCommand.OK)
                                    )
                            {
                                Header          = String.Format("{0} ({1})", mimeType, ext),
                                IsEnabled       = true,
                                IsVisibleOnMenu = true
                            });
                        }
                    }
                }
            }

            SubCommands    = subItemList;
            this.IsEnabled = subItemList.Count() > 0;
        }
Пример #5
0
        public override void NotifySelectionChanged(IEntryModel[] appliedModels)
        {
            List <ICommandModel> subCommands = new List <ICommandModel>();

            if (appliedModels.Length >= 1 &&
                !(appliedModels.Any(em => em.FullPath.StartsWith("::"))))
            {
                #region Decompress - When selected archive.
                if (appliedModels.All(em => em is ISzsItemModel))
                {
                    bool isRoot = appliedModels.All(em => em is SzsRootModel);
                    Func <IEntryModel, IScriptCommand, IScriptCommand> transferCommandFunc =
                        (destModel, thenCommand) =>
                        isRoot?
                        IOScriptCommands.DiskTransferChild(appliedModels, destModel, false, true, thenCommand) :
                            IOScriptCommands.DiskTransfer(appliedModels, destModel, false, true, thenCommand);


                    //Extract to ...
                    subCommands.Add(new CommandModel(
                                        WPFScriptCommands.ShowDirectoryPicker(_initializer, null,
                                                                              dm =>
                                                                              WPFScriptCommands.ShowProgress("Extract", transferCommandFunc(dm, WPFScriptCommands.HideProgress())),
                                                                              ResultCommand.NoError))
                    {
                        Header = "Extract to ...", IsEnabled = true, IsVisibleOnMenu = true
                    });

                    if (isRoot)
                    {
                        SzsRootModel firstRoot = appliedModels[0] as SzsRootModel;

                        IPathHelper path = firstRoot.Profile.Path;
                        Header = path.GetExtension(firstRoot.Name).TrimStart('.').FirstCharToUppercase();
                        string parentPath = path.GetDirectoryName(firstRoot.FullPath);

                        //Extract Here
                        subCommands.Add(new CommandModel(
                                            WPFScriptCommands.ShowProgress("Extract",
                                                                           transferCommandFunc(firstRoot.Parent, WPFScriptCommands.HideProgress())))
                        {
                            Header = "Extract Here", IsEnabled = true, IsVisibleOnMenu = true
                        });


                        if (appliedModels.Length == 1)
                        {
                            //Extract to \\ArchiveName
                            subCommands.Add(new CommandModel(
                                                WPFScriptCommands.ParseOrCreatePath(firstRoot.Parent.Profile as IDiskProfile,
                                                                                    path.Combine(parentPath, path.RemoveExtension(appliedModels[0].Name)), true,
                                                                                    destFolder => transferCommandFunc(destFolder, WPFScriptCommands.HideProgress())))
                            {
                                Header          = "Extract to \\" + path.RemoveExtension(appliedModels[0].Name),
                                IsEnabled       = true,
                                IsVisibleOnMenu = true
                            });
                        }
                        else
                        {
                            subCommands.Add(new CommandModel(
                                                WPFScriptCommands.ShowProgress("Extract",
                                                                               ScriptCommands.ForEach(appliedModels, am =>
                                                                                                      WPFScriptCommands.ParseOrCreatePath(firstRoot.Parent.Profile as IDiskProfile,
                                                                                                                                          path.Combine(parentPath, path.RemoveExtension(am.Name)), true,
                                                                                                                                          destFolder => transferCommandFunc(destFolder, WPFScriptCommands.HideProgress())))))
                            {
                                Header = "Extract to {ArchiveName}\\", IsEnabled = true, IsVisibleOnMenu = true
                            });
                        }
                    }
                }

                //if (appliedModels.All(em => em is SzsRootModel))
                //{
                //    SzsRootModel firstRoot = appliedModels[0] as SzsRootModel;

                //    IPathHelper path = firstRoot.Profile.Path;
                //    Header = path.GetExtension(firstRoot.Name).TrimStart('.').FirstCharToUppercase();
                //    string parentPath = path.GetDirectoryName(firstRoot.FullPath);


                //    //Extract to ...
                //    subCommands.Add(new CommandModel(
                //        ScriptCommands.ShowDirectoryPicker(_initializer, null,
                //        dm =>
                //         ScriptCommands.ShowProgress("Extract",
                //         ScriptCommands.ForEach(appliedModels, am =>
                //                     IOScriptCommands.TransferChild(am, dm, null, false),
                //              ScriptCommands.HideProgress())),
                //              ResultCommand.NoError)) { Header = "Extract to ...", IsEnabled = true, IsVisibleOnMenu = true });

                //    //Extract Here
                //    subCommands.Add(new CommandModel(
                //           ScriptCommands.ShowProgress("Extract",
                //           ScriptCommands.ForEach(appliedModels, am =>
                //                       IOScriptCommands.TransferChild(am, firstRoot.Parent, null, false),
                //                ScriptCommands.HideProgress()))) { Header = "Extract Here", IsEnabled = true, IsVisibleOnMenu = true });


                //    if (appliedModels.Length == 1)
                //    {
                //        //Extract to \\ArchiveName
                //        subCommands.Add(new CommandModel(
                //            ScriptCommands.ParseOrCreatePath(firstRoot.Parent.Profile as IDiskProfile,
                //            path.Combine(parentPath, path.RemoveExtension(appliedModels[0].Name)), true,
                //            destFolder =>
                //                ScriptCommands.ShowProgress("Extract",
                //                    IOScriptCommands.TransferChild(appliedModels[0], destFolder, null, false,
                //                      ScriptCommands.HideProgress()))))
                //                      {
                //                          Header = "Extract to \\" + path.RemoveExtension(appliedModels[0].Name),
                //                          IsEnabled = true,
                //                          IsVisibleOnMenu = true
                //                      });
                //    }
                //    else
                //        subCommands.Add(new CommandModel(
                //                ScriptCommands.ShowProgress("Extract",
                //                ScriptCommands.ForEach(appliedModels, am =>
                //                     ScriptCommands.ParseOrCreatePath(firstRoot.Parent.Profile as IDiskProfile,
                //                        path.Combine(parentPath, path.RemoveExtension(am.Name)), true,
                //                        destFolder =>
                //                            IOScriptCommands.TransferChild(am, destFolder, null, false)),
                //                     ScriptCommands.HideProgress()))) { Header = "Extract to {ArchiveName}\\", IsEnabled = true, IsVisibleOnMenu = true });

                //}
                #endregion


                #region Compress

                if (!appliedModels.Any(em => em is SzsChildModel) && !(appliedModels.Length == 1 && appliedModels[0] is SzsRootModel))
                {
                    Header = "Compress";
                    IEntryModel  firstEntry   = appliedModels[0];
                    IDiskProfile firstProfile = firstEntry.Profile as IDiskProfile;

                    if (firstProfile != null && !firstEntry.FullPath.StartsWith("::{") &&
                        firstEntry.Parent != null)
                    {
                        IPathHelper path = firstEntry.Profile.Path;
                        //Header = path.GetExtension(firstEntry.Name).TrimStart('.').FirstCharToUppercase();
                        string parentPath = path.GetDirectoryName(firstEntry.FullPath);

                        //e.g. C:\temp\abc.txt => C:\temp\temp.zip
                        string parentArchiveName = path.ChangeExtension(firstEntry.Parent.Name, ".zip");
                        string parentArchivePath = path.Combine(firstEntry.Parent.FullPath, parentArchiveName);

                        string firstArchiveName = path.ChangeExtension(firstEntry.Name, ".zip");
                        string firstArchivePath = path.Combine(firstEntry.Parent.FullPath, firstArchiveName);

                        subCommands.Add(new CommandModel(
                                            ScriptCommands.Assign(new Dictionary <string, object>()
                        {
                            { "{Profile}", firstEntry.Parent.Profile },
                            { "{Header}", "Compress" },
                            { "{CompressFiles}", appliedModels },
                            { "{StartupPath}", firstEntry.Parent.FullPath },
                            { "{FileName}", firstArchiveName }
                        }, false,
                                                                  IOScriptCommands.FileSave("Zip archives (.zip)|*.zip|7z archives (.7z)|*.7z", "{ArchivePath}",
                                                                                            WPFScriptCommands.ShowProgress("Compress",
                                                                                                                           IOScriptCommands.DiskParseOrCreateArchive("{Profile}", "{ArchivePath}", "{Archive}",
                                                                                                                                                                     IOScriptCommands.SzsDiskTransfer("{CompressFiles}", "{Archive}", false))),
                                                                                            UIScriptCommands.MessageBoxOK("Compress", "Compress is canceled."))))

                        {
                            Header          = "Compress to ...",
                            IsEnabled       = true,
                            IsVisibleOnMenu = true
                        });

                        Action <string, string> addCompressToPath = (destName, destPath) =>
                        {
                            subCommands.Add(new CommandModel(
                                                WPFScriptCommands.ShowProgress("Compress",
                                                                               IOScriptCommands.ParseOrCreateArchive(firstProfile, destPath,
                                                                                                                     pm => IOScriptCommands.DiskTransfer(appliedModels, pm, false, true,
                                                                                                                                                         null))))
                            {
                                Header          = "Compress to " + destName,
                                IsEnabled       = true,
                                IsVisibleOnMenu = true
                            });
                        };

                        addCompressToPath(firstArchiveName, firstArchivePath);
                        addCompressToPath(parentArchiveName, parentArchivePath);
                    }
                }
                #endregion
            }

            SubCommands     = subCommands;
            IsVisibleOnMenu = SubCommands.Count() > 0;
        }