protected override IScriptCommand executeInner(ParameterDic pm, UIElement sender, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs) { Point position = input.Position; //Console.WriteLine(input.IsDragging.ToString() + position.ToString()); switch (PositionRelativeTo) { case PositionRelativeToType.Sender: position = input.PositionRelativeTo(sender); break; case PositionRelativeToType.Scp: var scp = ControlUtils.GetScrollContentPresenter(sender is Control ? (Control)sender : UITools.FindAncestor <Control>(sender)); position = input.PositionRelativeTo(scp); break; case PositionRelativeToType.Panel: var parentPanel = UITools.FindAncestor <Panel>(sender); position = input.PositionRelativeTo(parentPanel); break; case PositionRelativeToType.Window: var parentWindow = Window.GetWindow(sender); position = input.PositionRelativeTo(parentWindow); break; } //Console.WriteLine(position); return(ScriptCommands.Assign(DestinationKey, position, SkipIfExists, NextCommand)); }
/// <summary> /// Update DragAdorner's Text to Move xyz.txt to Dest, syntax = /// [queryDropResult.supported/PreferredEffects] ([draggables.length] Items/draggables[0].DisplayName) to [isd.DisplayName] /// </summary> public static IScriptCommand UpdateAdornerText(string adornerVariable = "{DragDrop.Adorner}", string dragMethodVariable = "{DragDrop.DragMethod}", string draggablesVariable = "{DragDrop.Draggables}", string queryDropResultVariable = "{DragDrop.QueryDropResult}", string ISupportDropVariable = "{ISupportDrop}", IScriptCommand nextCommand = null) { string adornerTextVariable = ParameterDic.CombineVariable(adornerVariable, ".Text", false); string queryDropSupportedEffectsVariable = ParameterDic.CombineVariable(queryDropResultVariable, ".SupportedEffects", false); string queryDropPreferredEffectVariable = ParameterDic.CombineVariable(queryDropResultVariable, ".PreferredEffect", false); string draggablesLengthVariable = ParameterDic.CombineVariable(draggablesVariable, ".Count()", false); string draggablesFirstLabelVariable = ParameterDic.CombineVariable(draggablesVariable, ".First().DisplayName", false); string iSupportDropLabelVariable = ParameterDic.CombineVariable(ISupportDropVariable, ".DropTargetLabel", false); string iSupportDropDisplayNameVariable = ParameterDic.CombineVariable(ISupportDropVariable, ".DisplayName", false); return (ScriptCommands.RunSequence(nextCommand, ScriptCommands.IfEquals(draggablesLengthVariable, 1, ScriptCommands.FormatText("{ItemLabel}", draggablesFirstLabelVariable), ScriptCommands.FormatText("{ItemLabel}", draggablesLengthVariable + " items")), ScriptCommands.IfEquals(dragMethodVariable, DragMethod.Menu, ScriptCommands.Assign("{MethodLabel}", queryDropSupportedEffectsVariable), ScriptCommands.Assign("{MethodLabel}", queryDropPreferredEffectVariable)), ScriptCommands.IfEquals(queryDropResultVariable, QueryDropEffects.None, ScriptCommands.FormatText(adornerTextVariable, "{ItemLabel}"), ScriptCommands.IfAssigned(iSupportDropLabelVariable, ScriptCommands.FormatText(adornerTextVariable, iSupportDropLabelVariable), ScriptCommands.SetProperty(adornerTextVariable, iSupportDropDisplayNameVariable) )) )); }
public void Test_RunScript_Return_Result() { int var1 = ScriptRunner.RunScript <int>("{var1}", null, ScriptCommands.Assign("{var1}", 1)); Assert.AreEqual(1, var1); }
public static IScriptCommand SetDependencyProperty(string elementVariable, DependencyProperty property, string valueVariable, IScriptCommand nextCommand = null) { string propertyVariable = ParameterDic.CombineVariable(elementVariable, "Property"); return(ScriptCommands.Assign(propertyVariable, property, false, SetDependencyProperty(elementVariable, propertyVariable, valueVariable, nextCommand))); }
public static IScriptCommand GetDependencyProperty(string elementVariable, DependencyProperty property, string destinationVariable, IScriptCommand nextCommand) { string propertyVariable = ParameterDic.CombineVariable(elementVariable, "Property"); return(ScriptCommands.Assign(propertyVariable, property, false, GetDependencyProperty(elementVariable, propertyVariable, destinationVariable, nextCommand))); }
public static IScriptCommand IfMouseGesture(MouseGesture gesture, IScriptCommand nextCommand = null, IScriptCommand otherwiseCommand = null) { string MouseGestureVariable = "{IfMouseGesture-Gesture}"; return (ScriptCommands.Assign(MouseGestureVariable, gesture, false, HubScriptCommands.IfMouseGesture(MouseGestureVariable, nextCommand, otherwiseCommand))); }
public IExplorerViewModel OpenTab(IEntryModel model = null) { var initializer = _initializer.Clone(); if (initializer is ExplorerInitializer) { ExplorerInitializer eInit = initializer as ExplorerInitializer; if (model != null) { eInit.Initializers.Add(ExplorerInitializers.StartupDirectory(model)); } } else if (initializer is ScriptCommandInitializer) { ScriptCommandInitializer sInit = initializer as ScriptCommandInitializer; sInit.OnViewAttached = (model != null) ? ScriptCommands.Assign("{StartupPath}", model.FullPath, false, UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot()) : UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot(); sInit.OnModelCreated = ScriptCommands.Assign("{TabbedExplorer}", this, false, UIScriptCommands.ExplorerAssignScriptParameters("{Explorer}", "{TabbedExplorer}", sInit.OnModelCreated)); } ExplorerViewModel expvm = new ExplorerViewModel(_windowManager, _events) { Initializer = initializer }; //expvm.Commands.ParameterDicConverter.AddAdditionalParameters(new ParameterDic() // { // {"TabbedExplorer", this } // }); expvm.DropHelper = new TabDropHelper <IExplorerViewModel>(expvm, this); //expvm.FileList.Commands.CommandDictionary.CloseTab = // UIScriptCommands.TabExplorerCloseTab("{TabbedExplorer}", "{Explorer}"); ////ScriptCommands.ReassignToParameter("{Explorer}", TabbedExplorer.CloseTab(this)); expvm.FileList.Commands.CommandDictionary.OpenTab = ScriptCommands.Assign("{TabbedExplorer}", this, false, FileList.AssignSelectionToParameter( UIScriptCommands.TabExplorerNewTab("{TabbedExplorer}", "{Parameter}", null))); expvm.DirectoryTree.Commands.CommandDictionary.OpenTab = ScriptCommands.Assign("{TabbedExplorer}", this, false, DirectoryTree.AssignSelectionToParameter( UIScriptCommands.TabExplorerNewTab("{TabbedExplorer}", "{Parameter}", null))); ActivateItem(expvm); checkTabs(); return(expvm); }
public void Test_ExecuteFunc() { IParameterDic pm = new ParameterDic(); Assert.IsTrue(runCommand( ScriptCommands.Assign("{utcNow}", DateTime.UtcNow, ScriptCommands.ExecuteFunc("{utcNow}", "AddDays", new object[] { 10 }, "{utcNow10}")), pm)); Assert.AreNotEqual(pm.Get("{utcNow.Day}"), pm.Get("{utcNow10.Day}")); }
protected override Script.IScriptCommand onEvent(RoutedEvent eventId) { switch (eventId.Name) { case "MouseMove": case "TouchMove": return (ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, ScriptCommands.IfTrue("{CanvasResize.IsResizing}", HubScriptCommands.AssignCursorPosition(PositionRelativeToType.Panel, "{CanvasResize.CurrentPosition}", false, HubScriptCommands.UpdateResizeItemAdorner("{CanvasResize.ResizeItemAdorner}", "{CanvasResize.ResizeMode}", "{CanvasResize.StartPosition}", "{CanvasResize.CurrentPosition}"))))); //case "MouseDrag": //case "TouchDrag": case "PreviewTouchDown": case "PreviewMouseDown": return (ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, HubScriptCommands.SetRoutedEventHandled( ScriptCommands.Assign("{CanvasResize.IsResizing}", true, false, HubScriptCommands.AssignCursorPosition(PositionRelativeToType.Panel, "{CanvasResize.StartPosition}", false, //Assign Source's Name (e.g. N, NW) to CanvasResize.ResizeMode. ScriptCommands.Assign("{CanvasResize.ResizeMode}", "{EventArgs.Source.Name}", false, HubScriptCommands.CaptureMouse(CaptureMouseMode.UIElement))))))); case "PreviewTouchUp": case "PreviewMouseUp": return (ScriptCommands.Assign("{CanvasResize.ResizeItemAdorner.OffsetX}", 0, false, ScriptCommands.Assign("{CanvasResize.ResizeItemAdorner.OffsetY}", 0, false, ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, ScriptCommands.Assign("{CanvasResize.IsResizing}", false, false, HubScriptCommands.SetRoutedEventHandled( HubScriptCommands.CaptureMouse(CaptureMouseMode.Release, ScriptCommands.Subtract("{CanvasResize.CurrentPosition.X}", "{CanvasResize.StartPosition.X}", "{DiffX}", ScriptCommands.Subtract("{CanvasResize.CurrentPosition.Y}", "{CanvasResize.StartPosition.Y}", "{DiffY}", ScriptCommands.Switch <string>("{CanvasResize.ResizeMode}", new Dictionary <string, IScriptCommand>() { { "N", resizeNorthCommand }, { "NE", ScriptCommands.RunSequence(resizeNorthCommand, resizeEastCommand) }, { "E", resizeEastCommand }, { "SE", ScriptCommands.RunSequence(resizeSouthCommand, resizeEastCommand) }, { "S", resizeSouthCommand }, { "SW", ScriptCommands.RunSequence(resizeSouthCommand, resizeWestCommand) }, { "W", resizeWestCommand }, { "NW", ScriptCommands.RunSequence(resizeNorthCommand, resizeWestCommand) }, }, ScriptCommands.PrintConsole("Not supported : {CanvasResize.ResizeMode}, {DiffX},{DiffY}"))))))))))); } return(base.onEvent(eventId)); }
public void Test_SubString() { IParameterDic pm = new ParameterDic(); string str = "onceuponatime"; Assert.IsTrue(runCommand( ScriptCommands.Assign("{str}", str, ScriptCommands.Substring("{str}", 4, "{outputStr}", ScriptCommands.Substring("{str}", 4, 4, "{outputStr2}"))), pm)); Assert.AreEqual("uponatime", pm.Get("{outputStr}")); Assert.AreEqual("upon", pm.Get("{outputStr2}")); }
public void Test_GetArrayItem() { IParameterDic pm = new ParameterDic(); int[] array = new[] { 1, 3, 5 }; Assert.IsTrue(runCommand( ScriptCommands.Assign("{array}", array, ScriptCommands.GetArrayItem("{array}", 1, "{item1}", ScriptCommands.Reassign("{array[1]}", null, "{item2}"))), pm)); Assert.AreEqual(3, pm.Get("{item1}")); Assert.AreEqual(3, pm.Get("{item2}")); }
public void Test_GetProperty() { IParameterDic pm = new ParameterDic(); Assert.IsTrue(runCommand( ScriptCommands.Assign("{utcNow}", DateTime.UtcNow, ScriptCommands.GetProperty("{utcNow}", "Ticks", "{ticks1}", ScriptCommands.Reassign("{utcNow.Ticks}", null, "{ticks2}"))), pm)); Assert.AreNotEqual(0, pm.Get("{ticks1}")); Assert.AreEqual(pm.Get <long>("{ticks1}"), pm.Get <long>("{ticks2}")); }
public void Test_ParameterDic_Not_Altered() { IParameterDic pm = new ParameterDic(); pm.Set("{var1}", 1); ScriptRunner.RunScript(pm, false, //Not Cloned ScriptCommands.Assign("{var1}", 2)); Assert.AreEqual(2, pm.Get <int>("{var1}", -1)); pm.Set("{var1}", 1); ScriptRunner.RunScript(pm, true, //Cloned ScriptCommands.Assign("{var1}", 2)); Assert.AreEqual(1, pm.Get <int>("{var1}", -1)); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); var vm = DataContext as AddBookmarksViewModel; var rootDir = new IEntryModel[] { vm.Profile.RootModel }; expFolderPicker.ViewModel.Initializer = new ScriptCommandInitializer() { OnModelCreated = UIScriptCommands.ExplorerDefault(), OnViewAttached = ScriptCommands.Assign("{StartupDir}", vm.CurrentBookmarkDirectory, false, ScriptCommands.Assign("{StartupPath}", "{StartupDir.FullPath}", false, UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot())), RootModels = rootDir, StartupParameters = new ParameterDic() { { "Profiles", vm.Profile }, { "RootDirectories", rootDir }, //{ "StartupPath", vm.CurrentBookmarkDirectory.FullPath }, //{ "StartupPath", _selectedPath }, //{ "FilterString", _filterStr }, { "ViewMode", "List" }, { "ItemSize", 16 }, { "EnableDrag", true }, { "EnableDrop", true }, { "EnableMap", false }, { "FileListNewWindowCommand", NullScriptCommand.Instance }, //Disable NewWindow Command. { "EnableMultiSelect", true }, { "ShowToolbar", false }, { "ShowGridHeader", false } } }; expFolderPicker.ViewModel.FileList.PropertyChanged += (o, e) => { if (e.PropertyName == "CurrentDirectory") { vm.CurrentBookmarkDirectory = expFolderPicker.ViewModel.FileList.CurrentDirectory; } }; vm.PropertyChanged += (o, e) => { if (e.PropertyName == "CurrentBookmarkDirectory") { expFolderPicker.ViewModel.FileList.CurrentDirectory = vm.CurrentBookmarkDirectory; } }; }
public void Test_SetProperty() { IParameterDic pm = new ParameterDic(); testClass obj = new testClass() { val1 = 1, val2 = 2 }; Assert.IsTrue(runCommand( ScriptCommands.Assign("{obj}", obj, ScriptCommands.SetProperty("{obj}", "val1", "{obj.val2}", ScriptCommands.Assign("{obj.val2}", 1))), pm)); Assert.AreEqual(2, pm.Get <int>("{obj.val1}")); Assert.AreEqual(1, pm.Get <int>("{obj.val2}")); }
public void Test_ForEach() { int[] array = new int[] { 1, 3, 5 }; IParameterDic pm = new ParameterDic(); int sum; bool success = runCommand( ScriptCommands.Assign("{array}", array, ScriptCommands.ForEach("{array}", "{i}", ScriptCommands.Add("{i}", "{sum}", "{sum}"))), pm); Assert.IsTrue(success); sum = pm.Get <int>("{sum}"); Assert.AreEqual(9, sum); }
public static IScriptCommand ExplorerNewMdiWindow(WPF.MDI.MdiContainer container, IProfile[] profiles, IEntryModel[] rootDirectories, string explorerVariable = "{Explorer}", IScriptCommand nextCommand = null) { return(ScriptCommands.Assign(new Dictionary <string, object>() { { "{MdiContainer}", container }, { "{Profiles}", profiles }, { "{RootDirectories}", rootDirectories }, { "{OnModelCreated}", ScriptCommands.RunSequence(null, TestAppCommands.MdiExplorer_Initialize_Default, UIScriptCommands.ExplorerAssignScriptParameters("{Explorer}", "{MdiContainer},{RootDirectories}")) }, { "{OnViewAttached}", UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot() } }, false, TestAppCommands.ExplorerNewMdiWindow("{MdiContainer}", "{WindowManager}", "{GlobalEvents}", "{Explorer}", nextCommand))); }
/// <summary> /// Assign destination to DragMethod.Menu if Mouse action is right click, otherwise DragMethod.Normal. /// </summary> /// <returns></returns> public static IScriptCommand AssignDragMethod(string variable, IScriptCommand nextCommand = null) { return (ScriptCommands.RunSequence(nextCommand, HubScriptCommands.IfMouseGesture(new MouseGesture() { MouseAction = MouseAction.RightClick }, ScriptCommands.Assign(variable, DragMethod.Menu), HubScriptCommands.IfTouchGesture(new TouchGesture() { TouchAction = UITouchGesture.Drag }, ScriptCommands.Assign(variable, DragMethod.Menu), ScriptCommands.Assign(variable, DragMethod.Normal)) ))); }
public void Test_Script_Assign() { IParameterDic pm = new ParameterDic(); int var1; bool resultValue; bool success = runCommand(ScriptCommands.Assign("{var1}", 1, ScriptCommands.IfEquals("{var1}", 1, ScriptCommands.Assign("{resultValue}", true), ScriptCommands.Assign("{resultValue}", false))), pm); Assert.IsTrue(success); var1 = pm.Get("{var1}", -1); resultValue = pm.Get("{resultValue}", false); Assert.AreEqual(var1, 1); Assert.IsTrue(resultValue); }
public override IScriptCommand Execute(ParameterDic pm) { AdornerLayer value = null; FrameworkElement sender = pm.GetValue <FrameworkElement>(SenderKey); if (sender == null) { return(ResultCommand.Error(new KeyNotFoundException(SenderKey))); } switch (AssignAdornerType) { case AdornerType.Named: Window parentWindow = Window.GetWindow(sender); AdornerDecorator decorator = UITools.FindVisualChildByName <AdornerDecorator>(parentWindow, "PART_DragDropAdorner"); value = AdornerLayer.GetAdornerLayer(sender); break; case AdornerType.ItemsControl: value = AdornerLayer.GetAdornerLayer(sender); break; case AdornerType.SelectedItem: if (!(sender is ItemsControl)) { return(ResultCommand.Error(new ArgumentException(SenderKey))); } ItemsControl ic = sender as ItemsControl; foreach (var item in ic.ItemsSource) { if (item is ISelectable && (item as ISelectable).IsSelected) { UIElement selectedItem = ic.ItemContainerGenerator.ContainerFromItem(item) as UIElement; value = UITools.FindVisualChild <AdornerLayer>(selectedItem); } } break; } if (value != null) { return(ScriptCommands.Assign(DestinationKey, value, SkipIfExists, NextCommand)); } return(FailCommand); }
public void Test_FormatText() { string fmtString = "{day}-{month}-{year}"; int day = 5; int month = 12; int year = 2015; string outputStr; IParameterDic pm = new ParameterDic(); bool success = runCommand( ScriptCommands.Assign("{day}", day, ScriptCommands.Assign("{month}", month, ScriptCommands.Assign("{year}", year, ScriptCommands.FormatText("{output}", fmtString)))), pm); Assert.IsTrue(success); outputStr = pm.Get <string>("{output}"); Assert.AreEqual("5-12-2015", outputStr); }
public void Test_FilterArray() { int[] array = new int[] { 1, 3, 5 }; IParameterDic pm = new ParameterDic(); int[] outputArray; int arraySize; bool success = runCommand( ScriptCommands.Assign("{array}", array, ScriptCommands.FilterArray("{array}", null, ComparsionOperator.GreaterThan, 2, "{outputArray}", ScriptCommands.PrintDebug("{outputArray.Length}"))), pm); Assert.IsTrue(success); outputArray = pm.Get <int[]>("{outputArray}"); arraySize = outputArray.Length; Assert.IsNotNull(outputArray); Assert.AreEqual(2, arraySize); }
protected override IScriptCommand executeInner(ParameterDic pm, ItemsControl ic, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs) { Point currentRelPos = pm.GetValue <Point>(CurrentRelativePositionKey); if (currentRelPos.X == 0 && currentRelPos.Y == 0) { logger.Warn("CurrentRelativePosition not set."); } FrameworkElement eleUnderMouse = UITools.GetItemUnderMouse(ic, currentRelPos); if (eleUnderMouse != null) { return(ScriptCommands.Assign(VariableKey, eleUnderMouse.DataContext, SkipIfExists, NextCommand)); } else { return(ScriptCommands.Assign(VariableKey, null, SkipIfExists, NextCommand)); }; }
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 static IScriptCommand OffsetPositionValue(string positionVariable = "{Position}", Point offset = default(Point), string destinationVariable = "{Position}", IScriptCommand nextCommand = null) { return(ScriptCommands.Assign("{OffsetPositionValue}", offset, false, OffsetPosition(positionVariable, "{OffsetPositionValue}", destinationVariable))); }
protected override FileExplorer.Script.IScriptCommand onEvent(RoutedEvent eventId) { if (EnableDrag) { switch (eventId.Name) { case "PreviewMouseDown": return(_cmdDic.PreviewMouseDown ?? (_cmdDic.PreviewMouseDown = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //Set Default value for CanDrag first. ScriptCommands.Assign("{DragDrop.CanDrag}", false, false, //Find a DataContext that implement SupportDrag, and if assigned HubScriptCommands.IfHasDataContext("{EventArgs.OriginalSource}", DataContextType.SupportShellDrag, //and item under mouse (ISelectable) IsSelected. DragDropScriptCommands.IfItemUnderMouseIsSelected( //Notify MouseDrag can drag. ScriptCommands.Assign("{DragDrop.CanDrag}", true, false, //Prevent MultiSelect from starting. HubScriptCommands.SetRoutedEventHandled()) )))))); case "MouseDrag": return(_cmdDic.MouseDrag ?? (_cmdDic.MouseDrag = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If not handled. HubScriptCommands.IfNotRoutedEventHandled( //IfCanDrag (assigned from PreviewMouseDown) ScriptCommands.IfTrue("{DragDrop.CanDrag}", //Reset CanDrag ScriptCommands.Assign("{DragDrop.CanDrag}", false, false, //Mark handled, prevent MultiSelect from processing. HubScriptCommands.SetRoutedEventHandled( //If changed IsDraggingProperty, Find DataContext that support ISupportDrag to {ISupportDrag} variable. HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportShellDrag, "{DragDrop.SupportDrag}", null, false, //Determine DragMethod and call QueryDrag(). DragDropScriptCommands.StartShellDrag("{DragDrop.SupportDrag}") )))))))); case "PreviewMouseUp": return(_cmdDic.PreviewMouseUp ?? (_cmdDic.PreviewMouseUp = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //HubScriptCommands.SetDependencyPropertyValue("{Sender}", AttachedProperties.IsDraggingProperty, false, ScriptCommands.IfEquals(QueryDrag.DragMethodKey, DragMethod.Menu, ResultCommand.NoError, //This is defined in drop, detach if there's an adorner. DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}"))))); case "MouseMove": return(_cmdDic.MouseMove ?? (_cmdDic.MouseMove = HubScriptCommands.IfDependencyProperty("{Sender}", UIEventHubProperties.IsDraggingProperty, ComparsionOperator.Equals, true, HubScriptCommands.SetRoutedEventHandled()))); } } if (EnableDrop) { switch (eventId.Name) { case "DragEnter": return(_cmdDic.DragEnter ?? (_cmdDic.DragEnter = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //Find DataContext that support IShellDrop HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportShellDrop, "{ISupportDrop}", "{ElementSupportDrop}", false, //And if there's one, ScriptCommands.IfAssigned("{ISupportDrop}", HubScriptCommands.QueryShellDragInfo("{ISupportDrop}", "{DataObj}", "{DragDrop.Draggables}", "{DragDrop.QueryDropResult}", false, //Otherwise, ScriptCommands.Assign(new Dictionary <string, object>() { { "{DragDrop.SupportDrop}", "{ISupportDrop}" }, //Store SupportDrop property to global for future use. { "{DragDrop.ElementSupportDrop}", "{ElementSupportDrop}" }, //Store SupportDrop element to global for future use. { "{ISupportDrop.IsDraggingOver}", true }, //Set DataContext.IsDraggingOver to true. { "{EventArgs.Handled}", true } //Mark RoutedEvent handled. }, false, //Attach DragAdorner and update it. DragDropScriptCommands.AttachAdorner( "{DragDrop.AdornerLayer}", "{DragDrop.Adorner}", "{ISupportDrop}", "{DragDrop.DragMethod}", "{DragDrop.Draggables}"))), DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}")))))); case "GiveFeedback": return(_cmdDic.GiveFeedback ?? (_cmdDic.GiveFeedback = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If QueryDropResult returns none, set cursor to not droppable. ScriptCommands.IfEquals("{DragDrop.QueryDropResult}", QueryDropEffects.None, HubScriptCommands.SetCustomCursor(Cursors.No))))); case "DragOver": return(_cmdDic.DragOver ?? (_cmdDic.DragOver = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, DragDropScriptCommands.UpdateAdornerPointerPosition("{DragDrop.Adorner}")))); case "DragLeave": return(_cmdDic.DragLeave ?? (_cmdDic.DragLeave = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, ScriptCommands.SetPropertyValue("{DragDrop.SupportDrop}", "IsDraggingOver", false, //Detach adorner if DragLeave current element. ScriptCommands.IfAssigned("{DragDrop.SupportDrop}", DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}")))))); case "Drop": IScriptCommand detachAdornerAndResetDragDrop = ScriptCommands.SetPropertyValue("{DragDrop.SupportDrop}", "IsDraggingOver", false, DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}", ScriptCommands.Reset(null, "{DragDrop.Adorner}", "{DragDrop.AdornerLayer}", "{DragDrop.SupportDrop}", "{DragDrop.Draggables}"))); return(_cmdDic.Drop ?? (_cmdDic.Drop = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //Find DataContext that support ISupportShellDrop HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportShellDrop, "{ISupportDrop}", "{ElementSupportDrop}", false, //If ISupportDrop found. ScriptCommands.IfAssigned("{ISupportDrop}", ////Obtain DataObject from event and Call ISupportDrop.QueryDrop() to get IDraggables[] and QueryDropResult. HubScriptCommands.SetRoutedEventHandled( HubScriptCommands.QueryShellDragInfo("{ISupportDrop}", "{DataObj}", "{DragDrop.Draggables}", "{DragDrop.QueryDropResult}", false, //If QueryShellDragInfo Success, if DragMethod... ScriptCommands.IfEquals(QueryDrag.DragMethodKey, DragMethod.Menu, //Backup because ISupportDrag parameter is reset after this command is completed. ScriptCommands.Assign("{DragDrop.SupportDragBackup}", "{DragDrop.SupportDrag}", false, //is Menu, then Show Menu. HubScriptCommands.ShowDragAdornerContextMenu("{DragDrop.Adorner}", "{DragDrop.QueryDropResult.SupportedEffects}", "{DragDrop.QueryDropResult.PreferredEffect}", "{ResultEffect}", //After menu closed... ScriptCommands.IfEquals("{ResultEffect}", DragDropEffectsEx.None, //If User choose None (click on empty area), detach and reset. detachAdornerAndResetDragDrop, //Otherwise, call ISupportDrop.Drop() HubScriptCommands.QueryDrop("{DragDrop.SupportDragBackup}", "{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", "{ResultEffect}", "{DragDrop.DropResult}", false, //And detach adorner. detachAdornerAndResetDragDrop)))), //If DragMethod is not Menu, Drop immediately. HubScriptCommands.QueryDrop("{DragDrop.SupportDrag}", "{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", "{DragDrop.QueryDropResult.PreferredEffect}", "{DragDrop.DropResult}", false, detachAdornerAndResetDragDrop)), //If QueryDropEffects is None, drag failed, detach adorner. detachAdornerAndResetDragDrop))))))); } } return(base.onEvent(eventId)); }
protected override Script.IScriptCommand onEvent(RoutedEvent eventId) { switch (eventId.Name) { //case "MouseDrag": //case "TouchDrag": // return ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, // ScriptCommands.IfAssigned("{CanvasResize.ResizeItemAdorner}", // HubScriptCommands.DettachResizeItemAdorner("{CanvasResize.AdornerLayer}","{CanvasResize.ResizeItemAdorner}"))); //case "MouseDrag": //case "TouchDrag": // return HubScriptCommands.DettachResizeItemAdorner("{ResizeItemAdorner}"); case "PreviewTouchUp": case "PreviewMouseUp": return(ScriptCommands.FilterArray("{Sender.Items}", "IsSelected", ComparsionOperator.Equals, true, "{SelectedItems}", ScriptCommands.AssignGlobalParameterDic("{CanvasResize}", false, HubScriptCommands.DettachResizeItemAdorner("{CanvasResize.AdornerLayer}", "{CanvasResize.ResizeItemAdorner}", ScriptCommands.IfArrayLength(ComparsionOperator.Equals, "{SelectedItems}", 1, ScriptCommands.Assign("{CanvasResize.ResizeItem}", "{SelectedItems[0]}", false, HubScriptCommands.AssignAdornerLayer(AdornerType.SelectedItem, "{CanvasResize.AdornerLayer}", false, HubScriptCommands.AttachResizeItemAdorner("{CanvasResize.AdornerLayer}", "{CanvasResize.ResizeItemAdorner}"))) ))))); } return(base.onEvent(eventId)); }
public static IScriptCommand StartShellDrag(string iShellDragVariable = "{DragDrop.SupportDrag}", IScriptCommand nextCommand = null) { return //If CanDrag (ItemUnderMouse is selected), Check and set IsDraggingProperty to true. (ScriptCommands.SetPropertyValue(iShellDragVariable, (ISupportDrag d) => d.IsDraggingFrom, true, HubScriptCommands.AssignDragMethod(QueryDrag.DragMethodKey, //Initialize shell based drag drop HubScriptCommands.QueryDrag(iShellDragVariable, "{DragResult}", //Reset IsDragging property. ScriptCommands.SetPropertyValue(iShellDragVariable, (ISupportDrag d) => d.IsDraggingFrom, false, //Reset IShellDrag variable. ScriptCommands.Assign(iShellDragVariable, null, false, nextCommand)))))); }
protected override IScriptCommand onEvent(RoutedEvent eventId) { if (eventId.Name.Contains("Mouse") && !EnableMouse) { return(base.onEvent(eventId)); } if (eventId.Name.Contains("Touch") && !EnableTouch) { return(base.onEvent(eventId)); } IScriptCommand detachAdornerAndResetDragDrop = ScriptCommands.SetPropertyValue(DragDropLiteCommand.DragDropDropTargetKey, "IsDraggingOver", false, DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}", DragDropScriptCommands.EndLiteDrag("{DragDrop.SupportDrag}"))); if (EnableDrag) { switch (eventId.Name) { case "KeyDown": return(ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", HubScriptCommands.IfKeyGesture(new KeyGesture(Key.Escape), detachAdornerAndResetDragDrop))); case "PreviewMouseDown": case "PreviewTouchDown": return(_cmdDic.PreviewMouseDown ?? (_cmdDic.PreviewMouseDown = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //Set Default value for CanDrag first. ScriptCommands.Assign("{DragDrop.CanDrag}", false, false, //Find a DataContext that implement SupportDrag, and if assigned HubScriptCommands.IfHasDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrag, //and item under mouse (ISelectable) IsSelected. DragDropScriptCommands.IfItemUnderMouseIsSelected( //Notify MouseDrag can drag. ScriptCommands.Assign("{DragDrop.CanDrag}", true, false, //Prevent MultiSelect from starting. HubScriptCommands.SetRoutedEventHandled()) )))))); case "TouchDrag": case "MouseDrag": return(_cmdDic.MouseDrag ?? (_cmdDic.MouseDrag = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If not handled. HubScriptCommands.IfNotRoutedEventHandled( //IfCanDrag (assigned from PreviewMouseDown) ScriptCommands.IfTrue("{DragDrop.CanDrag}", //Reset CanDrag ScriptCommands.Assign("{DragDrop.CanDrag}", false, false, //Mark handled, prevent MultiSelect from processing. HubScriptCommands.SetRoutedEventHandled( //If changed IsDraggingProperty, Find DataContext that support ISupportDrag to {ISupportDrag} variable. HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrag, "{DragDrop.SupportDrag}", null, false, //Determine DragMethod and call QueryDrag(). DragDropScriptCommands.StartLiteDrag("{DragDrop.SupportDrag}") )))))))); } } if (EnableDrop) { switch (eventId.Name) { case "QueryCursor": return(_cmdDic.GiveFeedback ?? (_cmdDic.GiveFeedback = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If QueryDropResult returns none, set cursor to not droppable. ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", HubScriptCommands.QueryDropEffects("{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", DragDropLiteCommand.DragDropEffectsKey, "{DragDrop.QueryDropResult}", false, ScriptCommands.IfEquals("{DragDrop.QueryDropResult}", QueryDropEffects.None, HubScriptCommands.SetCustomCursor(Cursors.No), HubScriptCommands.SetCustomCursor(Cursors.Arrow))))))); case "TouchMove": case "MouseMove": return(_cmdDic.MouseMove ?? (_cmdDic.MouseMove = HubScriptCommands.ThrottleTouchDrag(5, ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, //If not handled. HubScriptCommands.IfNotRoutedEventHandled( ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrop, "{ISupportDrop}", "{ElementSupportDrop}", false, //And if there's one, //If Moved to different support drop. ScriptCommands.IfEquals("{ISupportDrop}", DragDropLiteCommand.DragDropDropTargetKey, DragDropScriptCommands.UpdateAdornerPointerPosition("{DragDrop.Adorner}"), HubScriptCommands.QueryDropEffects("{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", DragDropLiteCommand.DragDropEffectsKey, "{DragDrop.QueryDropResult}", false, ScriptCommands.SetPropertyValue(DragDropLiteCommand.DragDropDropTargetKey, (ISupportDrop p) => p.IsDraggingOver, false, ScriptCommands.Assign(new Dictionary <string, object>() { { DragDropLiteCommand.DragDropDropTargetKey, "{ISupportDrop}" }, //Store SupportDrop property to global for future use. { "{DragDrop.ElementSupportDrop}", "{ElementSupportDrop}" }, //Store SupportDrop element to global for future use. { "{EventArgs.Handled}", true } //Mark RoutedEvent handled. }, false, //ScriptCommands.IfNotEquals("{DragDrop.QueryDropResult}", QueryDropEffects.None, //Attach DragAdorner and update it. ScriptCommands.SetPropertyValue(DragDropLiteCommand.DragDropDropTargetKey, (ISupportDrop p) => p.IsDraggingOver, true, DragDropScriptCommands.AttachAdorner( "{DragDrop.AdornerLayer}", "{DragDrop.Adorner}", "{ISupportDrop}", "{DragDrop.DragMethod}", "{DragDrop.Draggables}")) /*DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}")*/))))))))))); case "TouchUp": case "PreviewMouseUp": return(_cmdDic.MouseUp ?? (_cmdDic.MouseUp = ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", //Find DataContext that support ISupportDrop HubScriptCommands.AssignDataContext("{EventArgs.OriginalSource}", DataContextType.SupportDrop, "{ISupportDrop}", "{ElementSupportDrop}", false, //If ISupportDrop found. ScriptCommands.IfAssigned("{ISupportDrop}", ////Obtain DataObject from event and Call ISupportDrop.QueryDrop() to get IDraggables[] and QueryDropResult. HubScriptCommands.QueryDropEffects("{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", DragDropLiteCommand.DragDropEffectsKey, "{DragDrop.QueryDropResult}", false, //If QueryShellDragInfo Success, if DragMethod... ScriptCommands.IfEquals(QueryDrag.DragMethodKey, DragMethod.Menu, HubScriptCommands.SetRoutedEventHandled( HubScriptCommands.ShowDragAdornerContextMenu("{DragDrop.Adorner}", "{DragDrop.QueryDropResult.SupportedEffects}", "{DragDrop.QueryDropResult.PreferredEffect}", "{ResultEffect}", //After menu closed... ScriptCommands.IfEquals("{ResultEffect}", DragDropEffectsEx.None, //If User choose None (click on empty area), detach and reset. detachAdornerAndResetDragDrop, //Otherwise, call ISupportDrop.Drop() HubScriptCommands.QueryDrop("{DragDrop.SupportDrag}", "{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", "{ResultEffect}", "{DragDrop.DropResult}", false, //And detach adorner. detachAdornerAndResetDragDrop)))), //If DragMethod is not Menu, Drop immediately. HubScriptCommands.QueryDrop("{DragDrop.SupportDrag}", "{ISupportDrop}", "{DragDrop.Draggables}", "{DataObj}", "{DragDrop.QueryDropResult.PreferredEffect}", "{DragDrop.DropResult}", false, detachAdornerAndResetDragDrop))), //If QueryDropEffects is None, drag failed, detach adorner. detachAdornerAndResetDragDrop)))))); } } switch (eventId.Name) { case "PreviewKeyDown": return (ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", HubScriptCommands.IfKeyGesture(new KeyGesture(Key.Escape), detachAdornerAndResetDragDrop)))); case "PreviewMouseUp": return (ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false, ScriptCommands.IfEquals(DragDropLiteCommand.DragDropModeKey, "Lite", DragDropScriptCommands.DetachAdorner("{DragDrop.AdornerLayer}", "{DragDrop.Adorner}")))); } return(base.onEvent(eventId)); }
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; }