public void PickFiles() { ScriptRunner.RunScriptAsync( new ParameterDic() { { "WindowManager", _windowManager }, { "GlobalEvents", _events }, { "Header", "OpenFile(s)" }, { "StartupPath", OpenPath } }, IOScriptCommands.FileOpen(_profiles, RootModels.ToArray(), true, FileFilter, "{Selection}", UIScriptCommands.MessageBoxOK("{Header}", "{Selection[0]} Selected"), UIScriptCommands.MessageBoxOK("{Header}", "User Cancelled")) ); #region Obsoluted - 1 (Use WPFScriptCommands.OpenFileDialog() IScriptCommand) //ScriptRunner.RunScriptAsync( // new ParameterDic() { { "WindowManager", _windowManager } }, // WPFScriptCommands.OpenFileDialog(_windowManager, _events, RootModels.ToArray(), FileFilter, "demo.txt", // (fpvm) => WPFScriptCommands.MessageBox("Open", fpvm.FileName), ResultCommand.OK)); #endregion #region Obsoluted - 0 (Create FilePickerViewModel Manually) //var filePicker = new FilePickerViewModel(_events, _windowManager, FileFilter, FilePickerMode.Open, RootModels.ToArray()); //updateExplorerModel(initExplorerModel(filePicker)); //if (_windowManager.ShowDialog(filePicker).Value) //{ // MessageBox.Show(String.Join(",", filePicker.SelectedFiles.Select(em => em.FullPath))); //} #endregion }
private async Task <IEntryModel> showDirectoryPicker(IEntryModel[] rootModels) { IProfile[] profiles = rootModels.Select(rm => rm.Profile).Distinct().ToArray(); return(await ScriptRunner.RunScriptAsync <IEntryModel>( "{OutputDirectory}", new ParameterDic() { { "WindowManager", _windowManager }, { "GlobalEvents", _events }, { "Header", "DirectoryPick" } }, IOScriptCommands.DirectoryPick(profiles, rootModels, "{OutputDirectory}", null, UIScriptCommands.MessageBoxOKCancel("{Header}", "Add {OutputDIrectory}?", null, ScriptCommands.Assign("{OutputDirectory}", null))))); //var directoryPicker = new DirectoryPickerViewModel( // AppViewModel.getInitializer(_windowManager, _events, rootModels, // new BasicParamInitalizers(true, false, false, false), // new ColumnInitializers())); //if (_windowManager.ShowDialog(directoryPicker).Value) // return directoryPicker.SelectedDirectory; //return null; }
public void SaveFile() { ScriptRunner.RunScriptAsync( new ParameterDic() { { "WindowManager", _windowManager }, { "GlobalEvents", _events }, { "Header", "SaveFile" }, { "FileName", "OpenFile.txt" }, { "StartupPath", OpenPath } }, IOScriptCommands.FileSave(_profiles, RootModels.ToArray(), FileFilter, "{Selection}", UIScriptCommands.MessageBoxOK("{Header}", "{Selection[0]} Selected"), UIScriptCommands.MessageBoxOK("{Header}", "User Cancelled")) ); #region Obsolute - 2 (Use UIScriptCommands.FileSave) //ScriptRunner.RunScriptAsync( // new ParameterDic() // { // { "WindowManager", _windowManager }, // { "RootModels", RootModels.ToArray() }, // { "FilterStr", FileFilter }, // { "ProfileEx", _profileEx } // }, // UIScriptCommands.FileSave( // ScriptCommands.RunCommandsInQueue(null, // UIScriptCommands.ExplorerSetParameters(ExplorerParameterType.RootModels, "{RootModels}", // UIScriptCommands.ExplorerSetParameters(ExplorerParameterType.FilterStr, "{FilterStr}")) // ), // UIScriptCommands.ExplorerParseAndGoTo("{Explorer}", "{ProfileEx}", ""), // "{WindowsManager}", "{Events}", "{DialogResult}", "{SelectionPaths}", // ScriptCommands.IfTrue("{DialogResult}", // UIScriptCommands.MessageBoxOK("SaveFile", "{SelectionPaths}"), // UIScriptCommands.MessageBoxOK("SaveFile", "Cancelled")) // )); #endregion #region Obsolute - 1 (Use WPFScriptCommands.SaveFilePicker() IScriptCommand) //ScriptRunner.RunScriptAsync( // new ParameterDic() { { "WindowManager", _windowManager } }, // WPFScriptCommands.SaveFilePicker(_windowManager, null, RootModels.ToArray(), FileFilter, "demo.txt", // (fpvm) => WPFScriptCommands.MessageBox("Save", fpvm.FileName), ResultCommand.OK)); #endregion #region Obsolute - 0 (Create FilePickerViewModel manually) //var filePicker = new FilePickerViewModel(_events, _windowManager, FileFilter, FilePickerMode.Save, RootModels.ToArray()); //updateExplorerModel(initExplorerModel(filePicker)); //if (_windowManager.ShowDialog(filePicker).Value) //{ // MessageBox.Show(filePicker.FileName); //} #endregion }
public void OpenWindowUsingScriptCommand() { #region Obsoluted - Same as the code below. //IScriptCommand onModelCreated = // ScriptCommands.RunCommandsInSequence(null, // IOScriptCommands.ExplorerDefault(), // IOScriptCommands.ExplorerDefaultToolbarCommands(), // UIScriptCommands.ExplorerAssignScriptParameters("{Explorer}", // "{OnViewAttached},{OnModelCreated},{EnableDrag},{EnableDrop},{EnableMultiSelect}") // ); //ScriptRunner.RunScriptAsync(new ParameterDic() { // //Required // { "Profiles", _profiles }, // { "OnModelCreated", onModelCreated }, // { "OnViewAttached", UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot()}, // { "RootDirectories", RootModels.ToArray() }, // //Optional // { "StartupPath", OpenPath }, // { "Events", _events }, // { "WindowManager", _windowManager }, // { "EnableDrag", _enableDrag }, // { "EnableDrop", _enableDrop }, // { "EnableMultiSelect", _enableMultiSelect}, // }, UIScriptCommands.ExplorerShow()); #endregion //IOScriptCommands.ExplorerShow initialize {OnModelCreated} and {OnViewAttached} to IO based. //While UIScriptCommands.ExplorerShow have to specify explicitly. ScriptRunner.RunScriptAsync(new ParameterDic() { { "StartupPath", OpenPath }, { "GlobalEvents", _events }, { "WindowManager", _windowManager }, { "EnableDrag", _enableDrag }, { "EnableDrop", _enableDrop }, { "EnableContextMenu", _enableContextMenu }, { "EnableBookmark", _enableBookmark }, { "EnableMap", true }, { "EnableMultiSelect", _enableMultiSelect }, }, IOScriptCommands.ExplorerNewWindow(_profiles, RootModels.ToArray())); }
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); }
public override IScriptCommand GetTransferCommand(string sourceKey, string destinationDirKey, string destinationKey, bool removeOriginal, IScriptCommand nextCommand) { return(IOScriptCommands.SzsDiskTransfer(sourceKey, destinationDirKey, removeOriginal, nextCommand)); }
public void TabWindow() { ScriptRunner.RunScriptAsync(new ParameterDic() { { "StartupPath", OpenPath }, { "GlobalEvents", _events }, { "WindowManager", _windowManager }, { "EnableDrag", _enableDrag }, { "EnableDrop", _enableDrop }, { "EnableContextMenu", _enableContextMenu }, { "EnableBookmark", _enableBookmark }, { "EnableMultiSelect", _enableMultiSelect }, { "EnableTabsWhenOneTab", _showTabsWhenOneTab } }, IOScriptCommands.ExplorerNewTabWindow(_profiles, RootModels.ToArray(), "{TabbedExplorer}")); //var tabVM = new TabbedExplorerViewModel(_windowManager, _events); //tabVM.Initializer = new ScriptCommandInitializer() //{ // Events = _events, // WindowManager = _windowManager, // OnModelCreated = ScriptCommands.RunScriptCommand("{OnModelCreated}"), // OnViewAttached = ScriptCommands.RunScriptCommand("{OnViewAttached}"), // StartupParameters = new FileExplorer.ParameterDic() // { // {"TabbedExplorer", tabVM }, // {"Profiles", _profiles }, // {"RootDirectories", RootModels.ToArray() }, // {"OnModelCreated", IOInitializeHelpers.Explorer_Initialize_Default }, // {"OnViewAttached", UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot() }, // } //}; //_windowManager.ShowWindow(tabVM); //ScriptRunner.RunScriptAsync(new ParameterDic() { // { "StartupPath", OpenPath }, // { "GlobalEvents", _events }, // { "WindowManager", _windowManager }, // { "EnableDrag", _enableDrag }, // { "EnableDrop", _enableDrop }, // { "EnableMultiSelect", _enableMultiSelect}, // }, // IOScriptCommands.ExplorerShow(_profiles, RootModels.ToArray())); //var profiles = new IProfile[] { // _profileEx, _profileSkyDrive, _profileDropBox, _profileGoogleDrive //}; //var initializer = getInitializer(_windowManager, _events, RootModels.ToArray(), // ExplorerInitializers.Parameter(new FileListParameters() { ViewMode = "Icon", ItemSize = 100 }), // ExplorerInitializers.Parameter(new ExplorerParameters() { UIScale = 1.1f, FileListSize = "3*", NavigationSize = 45 }), // new BasicParamInitalizers(_expandRootDirectories, _enableMultiSelect, _enableDrag, _enableDrop), // new ColumnInitializers(), // new ScriptCommandsInitializers(_windowManager, _events, profiles), // new ToolbarCommandsInitializers(_windowManager)); //var initializer = //var tabVM = new TabbedExplorerViewModel(initializer); //var windowManager = new TabbedAppWindowManager(tabVM); //_windowManager.ShowWindow(tabVM); }
public AppViewModel() { LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Info, LogLevel.Fatal, new ConsoleTarget()); LogManagerFactory.DefaultConfiguration.IsEnabled = true; LogManagerFactory.DefaultLogManager.GetLogger <AppViewModel>().Log(LogLevel.Debug, "Test"); //AsyncUtils.RunSync(() => ScriptCommandTests.Test_DownloadFile()); // IScriptCommand diskTransferCommand = //ScriptCommands.ParsePath("{SourceFile}", "{Source}", //ScriptCommands.DiskParseOrCreateFolder("{DestinationDirectory}", "{Destination}", //IOScriptCommands.DiskTransfer("{Source}", "{Destination}", false, false))); //await ScriptRunner.RunScriptAsync(new ParameterDic() { // { "Profile", FileSystemInfoExProfile.CreateNew() }, // { "SourceFile", srcFile }, // { "DestinationFile", destFile } // }, copyCommand); //string tempDirectory = "C:\\Temp"; //string destDirectory = "C:\\Temp\\Destination1"; //string srcFile = System.IO.Path.Combine(tempDirectory, "file1.txt"); //string destFile = System.IO.Path.Combine(destDirectory, "file2.txt"); //AsyncUtils.RunSync(() => ScriptRunner.RunScriptAsync(new ParameterDic() { // { "Profile", FileExplorer.Models.FileSystemInfoExProfile.CreateNew() }, // { "SourceFile", srcFile }, // { "DestinationDirectory", destDirectory } //}, diskTransferCommand)); string tempDirectory = "C:\\Temp"; string destDirectory = "C:\\Temp\\Debug2"; string srcDirectory = "C:\\Temp\\aaaaabc"; IScriptCommand diskTransferCommand = CoreScriptCommands.ParsePath("{Profile}", srcDirectory, "{Source}", CoreScriptCommands.DiskParseOrCreateFolder("{Profile}", destDirectory, "{Destination}", IOScriptCommands.DiskTransfer("{Source}", "{Destination}", null, false, false))); AsyncUtils.RunSync(() => ScriptRunner.RunScriptAsync(new ParameterDic() { { "Profile", FileSystemInfoExProfile.CreateNew() } }, diskTransferCommand)); }
public virtual IScriptCommand GetTransferCommand(string sourceKey, string destinationDirKey, string destinationKey, bool removeOriginal, IScriptCommand nextCommand) { return(IOScriptCommands.DiskTransfer(sourceKey, destinationDirKey, destinationKey, removeOriginal, false, nextCommand)); }
public virtual IScriptCommand GetTransferCommand(IEntryModel srcModel, IEntryModel destDirModel, bool removeOriginal) { return(IOScriptCommands.DiskTransfer(srcModel, destDirModel, removeOriginal, false)); }
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; }