protected override IScriptCommand executeInner(ParameterDic pm, ItemsControl ic, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            var        scp    = ControlUtils.GetScrollContentPresenter(ic);
            IChildInfo icInfo = UITools.FindVisualChild <Panel>(scp) as IChildInfo;

            if (icInfo == null)
            {
                return(ResultCommand.Error(new NotSupportedException()));
            }

            Rect          selectionBound = pm.GetValue <Rect>(SelectionBoundAdjustedKey);
            List <object> selectedList   = new List <object>();
            List <int>    selectedIdList = new List <int>();

            for (int i = 0; i < ic.Items.Count; i++)
            {
                if (icInfo.GetChildRect(i).IntersectsWith(selectionBound))
                {
                    selectedList.Add(ic.Items[i]);
                    selectedIdList.Add(i);
                }
            }

            pm.SetValue(SelectedListKey, selectedList);
            pm.SetValue(SelectedIdListKey, selectedIdList);
            logger.Debug(String.Format("Selected = {0}", selectedIdList.Count()));

            return(NextCommand);
        }
        public override IScriptCommand Execute(ParameterDic pm)
        {
            try
            {
                _command.Execute(pm.GetValue("{Parameter}"));
            }
            catch (Exception ex) { return(ResultCommand.Error(ex)); }

            return(ResultCommand.NoError);
        }
        public override IScriptCommand Execute(FileExplorer.ParameterDic pm)
        {
            IWindowManager wm = pm.GetValue <IWindowManager>(WindowManagerKey) ?? new WindowManager();

            WPF.MDI.MdiContainer container = pm.GetValue <WPF.MDI.MdiContainer>(MdiContainerKey);

            if (container == null)
            {
                return(ResultCommand.Error(new KeyNotFoundException("MdiContainerKey")));
            }

            IExplorerViewModel explorer = pm.GetValue <IExplorerViewModel>(ExplorerKey);

            if (explorer == null)
            {
                return(ResultCommand.Error(new KeyNotFoundException("ExplorerKey")));
            }

            var view = new ExplorerView();

            Caliburn.Micro.Bind.SetModel(view, explorer); //Set the ViewModel using this command.
            var mdiChild = new WPF.MDI.MdiChild
            {
                DataContext = explorer,
                ShowIcon    = true,
                Content     = view
            };

            mdiChild.SetBinding(WPF.MDI.MdiChild.TitleProperty, new Binding("DisplayName")
            {
                Mode = BindingMode.OneWay
            });
            mdiChild.SetBinding(WPF.MDI.MdiChild.IconProperty, new Binding("CurrentDirectory.Icon")
            {
                Mode = BindingMode.OneWay
            });
            mdiChild.SetBinding(WPF.MDI.MdiChild.WidthProperty, new Binding("Parameters.Width")
            {
                Mode = BindingMode.TwoWay
            });
            mdiChild.SetBinding(WPF.MDI.MdiChild.HeightProperty, new Binding("Parameters.Height")
            {
                Mode = BindingMode.TwoWay
            });
            mdiChild.SetBinding(WPF.MDI.MdiChild.PositionProperty, new Binding("Parameters.Position")
            {
                Mode = BindingMode.TwoWay
            });
            container.Children.Add(mdiChild);

            return(NextCommand);
        }
Beispiel #4
0
        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 static async Task Test_CopyFile()
        {
            string tempDirectory = "C:\\Temp";
            string srcFile       = System.IO.Path.Combine(tempDirectory, "File1.txt");
            string destFile      = System.IO.Path.Combine(tempDirectory, "File2.txt");
            string signature     = "Created by testCopyFile at " + DateTime.Now.ToString();

            Directory.CreateDirectory(tempDirectory);
            using (var sw = File.CreateText(srcFile))
                sw.WriteLine(signature);
            //File.Delete(destFile);

            IProfile fsiProfile = new FileSystemInfoExProfile(null, null);


            IScriptCommand copyCommand =
                CoreScriptCommands.ParsePath("{Profile}", "{SourceFile}", "{Source}",
                                             CoreScriptCommands.DiskParseOrCreateFile("{Profile}", "{DestinationFile}", "{Destination}",
                                                                                      CoreScriptCommands.DiskOpenStream("{Source}", "{SourceStream}", FileExplorer.Defines.FileAccess.Read,
                                                                                                                        CoreScriptCommands.DiskOpenStream("{Destination}", "{DestinationStream}", FileExplorer.Defines.FileAccess.Write,
                                                                                                                                                          CoreScriptCommands.CopyStream("{SourceStream}", "{DestinationStream}"))))
                                             , ResultCommand.Error(new FileNotFoundException(srcFile))
                                             );

            //copyCommand = ScriptCommands.CopyFile("SourceFile", "DestinationFile");
            copyCommand = serializeAndDeserializeCommand(copyCommand);
            await ScriptRunner.RunScriptAsync(new ParameterDic()
            {
                { "Profile", fsiProfile },
                { "SourceFile", srcFile },
                { "DestinationFile", destFile }
            }, copyCommand);


            string actual = null;

            using (var sr = File.OpenText(destFile))
            {
                actual = sr.ReadLine();
            }

            Assert.AreEqual(signature, actual);
        }
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            string fileName = _fileNameGenerator.Generate();

            while (fileName != null &&
                   await _profile.ParseAsync(_profile.Path.Combine(_parentPath, fileName)) != null)
            {
                fileName = _fileNameGenerator.Generate();
            }
            if (fileName == null)
            {
                return(ResultCommand.Error(new ArgumentException("Already exists.")));
            }

            string newEntryPath  = _profile.Path.Combine(_parentPath, fileName);
            var    createddModel = await _profile.DiskIO.CreateAsync(newEntryPath, _isFolder, pm.CancellationToken);

            return(new NotifyChangedCommand(_profile, newEntryPath, FileExplorer.Defines.ChangeType.Created,
                                            _thenFunc(createddModel)));
        }
Beispiel #7
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            FrameworkElement origSource = pm.GetValue <FrameworkElement>(SourceElementKey);

            Value = null;
            FrameworkElement ele = null;

            if (origSource != null)
            {
                switch (DataContextType)
                {
                case UIEventHub.DataContextType.Any:
                    Value = origSource.DataContext;
                    ele   = origSource;
                    break;

                case UIEventHub.DataContextType.SupportDrag:
                    Value = DataContextFinder.GetDataContext(origSource, out ele, DataContextFinder.SupportDrag);
                    break;

                case UIEventHub.DataContextType.SupportShellDrag:
                    Value = DataContextFinder.GetDataContext(origSource, out ele, DataContextFinder.SupportShellDrag);
                    break;

                case UIEventHub.DataContextType.SupportShellDrop:
                    Value = DataContextFinder.GetDataContext(origSource, out ele, DataContextFinder.SupportShellDrop);
                    break;

                case UIEventHub.DataContextType.SupportDrop:
                    Value = DataContextFinder.GetDataContext(origSource, out ele, DataContextFinder.SupportDrop);
                    break;

                default:
                    return(ResultCommand.Error(new NotSupportedException("DataContextType")));
                }
            }

            pm.SetValue(VariableKey, Value, SkipIfExists);
            pm.SetValue(DataContextElementKey, ele, SkipIfExists);
            return(NextCommand);
        }
        public override IScriptCommand Execute(ParameterDic pm)
        {
            FrameworkElement   ele      = pm.GetValue <FrameworkElement>(ElementKey);
            DependencyProperty property = pm.GetValue <DependencyProperty>(PropertyKey);

            if (ele == null)
            {
                return(ResultCommand.Error(new ArgumentException(ElementKey)));
            }
            if (property == null)
            {
                return(ResultCommand.Error(new ArgumentException(PropertyKey)));
            }

            object value = ele.GetValue(property);

            logger.Debug(String.Format("{0}'s {1} is equal to {2}", ele, property, value));
            pm.SetValue(DestinationKey, value);

            return(NextCommand);
        }
        //public void Save()
        //{
        //    string fullPath = FileList.CurrentDirectory.Profile.Path.Combine(FileList.CurrentDirectory.FullPath, FileName);
        //    var foundItem = FileList.ProcessedEntries.EntriesHelper.AllNonBindable.Select(evm => evm.EntryModel)
        //            .FirstOrDefault(em =>
        //            em.FullPath.Equals(fullPath, StringComparison.CurrentCultureIgnoreCase));
        //    if (foundItem != null)
        //    {
        //        string name = foundItem.Profile.Path.GetFileName(foundItem.FullPath);
        //        new IfOkCancel(_windowManager, () => "Overwrite", String.Format("Overwrite {0}?", name),
        //    }

        //}

        public async Task Save()
        {
            var pm = FileList.Commands.ParameterDicConverter.Convert(new ParameterDic());

            Profile = FileList.CurrentDirectory.Profile;

            //Update FileName in case user does not enter full path name.
            IScriptCommand updateFileName =
                new SimpleScriptCommand("updateFileName", pd =>
            {
                FileName = Profile.Path.Combine(FileList.CurrentDirectory.FullPath, FileName);
                return(ResultCommand.NoError);
            });

            //Update SelectedFiles property (if it's exists.")
            Func <IEntryModel, IScriptCommand> setSelectedFiles =
                m => new SimpleScriptCommand("SetSelectedFiles", pd =>
            {
                SelectedFiles = new[] { m }; FileName = m.FullPath; return(ResultCommand.NoError);
            });

            //Query whether to overwrite and if so, setSelectedFiles, otherwise throw a user cancel exception and no window close.
            Func <IEntryModel, IScriptCommand> queryOverwrite =
                m => new IfOkCancel(_windowManager,
                                    pd => "Overwrite",
                                    pd => "Overwrite " + Profile.Path.GetFileName(FileName),
                                    setSelectedFiles(m), ResultCommand.Error(new Exception("User cancel")) /* Cancel if user press cancel. */);

            await ScriptRunner.RunScriptAsync(pm,
                                              ScriptCommands.RunInSequence(
                                                  Script.FileList.Lookup(
                                                      m => m.FullPath.Equals(FileName) || m.Profile.Path.GetFileName(m.FullPath).Equals(FileName),
                                                      queryOverwrite,
                                                      FileList.CurrentDirectory.Profile.Parse(FileName, queryOverwrite,
                                                                                              updateFileName))),
                                              _tryCloseCommand
                                              );
        }
Beispiel #10
0
        protected override IScriptCommand executeInner(ParameterDic pm, UIElement ic,
                                                       RoutedEventArgs eventArgs, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            if (Keyboard.Modifiers != ModifierKeys.None)
            {
                return(ResultCommand.NoError);
            }

            logger.Debug(String.Format("Capture {0}", _mode));
            switch (_mode)
            {
            case CaptureMouseMode.UIElement:
                Mouse.Capture(ic, CaptureMode.Element);
                break;

            case CaptureMouseMode.ScrollContentPresenter:
                if (ic is ItemsControl)
                {
                    var scp = ControlUtils.GetScrollContentPresenter(ic as ItemsControl);
                    if (scp == null)
                    {
                        return(ResultCommand.NoError);
                    }

                    Mouse.Capture(scp, CaptureMode.SubTree);
                }
                break;

            case CaptureMouseMode.Release:
                Mouse.Capture(null);
                break;

            default:
                return(ResultCommand.Error(new NotSupportedException("CaptureMouseMode")));
            }
            return(NextCommand);
        }
        public async Task Open()
        {
            List <IEntryModel> selectedFiles = new List <IEntryModel>();

            Profile = FileList.CurrentDirectory.Profile;
            Func <IEntryModel, IScriptCommand> addToSelectedFiles =
                m => new SimpleScriptCommand("AddToSelectedFiles", pd => { selectedFiles.Add(m); return(ResultCommand.NoError); });
            var pm = FileList.Commands.ParameterDicConverter.Convert(new ParameterDic());
            await ScriptRunner.RunScriptAsync(pm,
                                              ScriptCommands.RunInSequence(
                                                  ScriptCommands.ForEach(
                                                      FileName.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
                                                      f => Script.FileList.Lookup(
                                                          m => m.FullPath.Equals(f) || m.Profile.Path.GetFileName(m.FullPath).Equals(f),
                                                          addToSelectedFiles,
                                                          FileList.CurrentDirectory.Profile.Parse(f, addToSelectedFiles,
                                                                                                  ResultCommand.Error(new System.IO.FileNotFoundException(f + " is not found.")))))),
                                              new SimpleScriptCommand("AssignSelectedFiles", pd => { SelectedFiles = selectedFiles.ToArray(); return(ResultCommand.NoError); }),
                                              _tryCloseCommand
                                              );
        }
        protected override Script.IScriptCommand executeInner(ParameterDic pm, ItemsControl sender,
                                                              RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            var scp = ControlUtils.GetScrollContentPresenter(sender);

            if (scp != null)
            {
                AdornerLayer adornerLayer = ControlUtils.GetAdornerLayer(sender);

                switch (AdornerMode)
                {
                case UIEventHub.AdornerMode.Attach:
                    if (adornerLayer == null)
                    {
                        return(ResultCommand.Error(new Exception("Adorner layer not found.")));
                    }
                    if (UIEventHubProperties.GetSelectionAdorner(scp) == null)
                    {
                        Window parentWindow = UITools.FindAncestor <Window>(sender);

                        Point scpPos = scp.TranslatePoint(new Point(0, 0), sender);

                        //Create and register adorner.
                        SelectionAdorner adorner = new SelectionAdorner(scp)
                        {
                            //AdjustVector = new Vector(-scpPos.X, -scpPos.Y)
                        };
                        pm.SetValue(SelectionAdornerKey, adorner);
                        UIEventHubProperties.SetSelectionAdorner(scp, adorner);
                        UIEventHubProperties.SetLastScrollContentPresenter(sender, scp);     //For used when detach.

                        adornerLayer.Add(adorner);
                    }
                    break;

                case UIEventHub.AdornerMode.Detach:

                    var lastScp     = UIEventHubProperties.GetLastScrollContentPresenter(sender); //For used when detach.
                    var lastAdorner = UIEventHubProperties.GetSelectionAdorner(scp);
                    if (lastAdorner != null)
                    {
                        adornerLayer.Remove(lastAdorner);
                    }

                    UIEventHubProperties.SetLastScrollContentPresenter(sender, null);
                    UIEventHubProperties.SetSelectionAdorner(scp, null);
                    pm.SetValue <Object>(SelectionAdornerKey, null);
                    break;

                case UIEventHub.AdornerMode.Update:
                    var updateAdorner = pm.GetValue <SelectionAdorner>(SelectionAdornerKey) ??
                                        UIEventHubProperties.GetSelectionAdorner(scp);

                    if (updateAdorner == null)
                    {
                        return(ResultCommand.Error(new Exception("Adorner not found.")));
                    }

                    updateAdorner.IsSelecting = UIEventHubProperties.GetIsSelecting(sender);
                    Point startAdjusted = pm.GetValue <Point>("{StartPosition}");
                    Point current       = pm.GetValue <Point>(CurrentPositionKey);
                    updateAdorner.SetValue(SelectionAdorner.StartPositionProperty, startAdjusted);
                    updateAdorner.SetValue(SelectionAdorner.EndPositionProperty, current);
                    break;
                }
            }
            return(NextCommand);
        }
Beispiel #13
0
        protected override IScriptCommand executeInner(ParameterDic pm, Control sender,
                                                       RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            if (!pm.HasValue <ParameterDic>("{DragDrop}"))
            {
                ScriptCommands.AssignGlobalParameterDic("{DragDrop}", false).Execute(pm);
            }
            if (!pm.HasValue <Point>(CurrentPositionAdjustedKey))
            {
                HubScriptCommands.ObtainPointerPosition().Execute(pm);
            }

            logger.Debug(State.ToString());
            switch (State)
            {
            case DragDropLiteState.StartLite:
            case DragDropLiteState.StartCanvas:
                string mode = State == DragDropLiteState.StartLite ? "Lite" : "Canvas";
                if (dragStart(pm, input, mode))
                {
                    foreach (var item in
                             pm.GetValue <IEnumerable <IDraggable> >(DragDropDraggingItemsKey)
                             .Where(i => (State == DragDropLiteState.StartLite) || i is IPositionAware))
                    {
                        item.IsDragging = true;
                    }
                    return(NextCommand);
                }
                else
                {
                    return(FailCommand);
                }

            case DragDropLiteState.EndLite:
            case DragDropLiteState.EndCanvas:
            case DragDropLiteState.CancelCanvas:
                //foreach (var item in pm.GetValue<IEnumerable<IDraggable>>(DragDropDraggingItemsKey))
                //    item.IsDragging = true;

                if (pm.HasValue <Point>(DragDropStartPositionKey))
                {
                    Point  currentPosition = pm.GetValue <Point>(CurrentPositionAdjustedKey);
                    Point  startPosition   = pm.GetValue <Point>(DragDropStartPositionKey);
                    Vector movePt          = currentPosition - startPosition;

                    var items = pm.GetValue <IEnumerable <IDraggable> >(DragDropDraggingItemsKey);
                    foreach (var item in items)
                    {
                        item.IsDragging = false;
                    }

                    if (State == DragDropLiteState.EndCanvas)
                    {
                        foreach (var posAwareItem in items.Cast <IPositionAware>())
                        {
                            posAwareItem.OffsetPosition(movePt);
                        }
                    }
                }

                dragEnd(pm);
                return(NextCommand);

            default: return(ResultCommand.Error(new NotSupportedException(State.ToString())));
            }
        }
        protected override Script.IScriptCommand executeInner(ParameterDic pm, ItemsControl ic,
                                                              RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            var scp = ControlUtils.GetScrollContentPresenter(ic);

            if (scp != null)
            {
                AdornerLayer adornerLayer = ControlUtils.GetAdornerLayer(ic);

                switch (AdornerMode)
                {
                case UIEventHub.AdornerMode.Attach:
                    if (adornerLayer == null)
                    {
                        return(ResultCommand.Error(new Exception("Adorner layer not found.")));
                    }
                    if (UIEventHubProperties.GetSelectedItemsAdorner(scp) == null)
                    {
                        //Create and register adorner.
                        SelectedItemsAdorner adorner = new SelectedItemsAdorner(scp);
                        pm.SetValue(SelectedItemsAdornerKey, adorner);
                        UIEventHubProperties.SetSelectedItemsAdorner(scp, adorner);
                        UIEventHubProperties.SetLastScrollContentPresenter(ic, scp);     //For used when detach.

                        adornerLayer.Add(adorner);
                    }
                    break;

                case UIEventHub.AdornerMode.Detach:

                    var lastScp     = UIEventHubProperties.GetLastScrollContentPresenter(ic); //For used when detach.
                    var lastAdorner = UIEventHubProperties.GetSelectedItemsAdorner(scp);
                    if (lastAdorner != null)
                    {
                        adornerLayer.Remove(lastAdorner);
                    }

                    UIEventHubProperties.SetLastScrollContentPresenter(ic, null);
                    UIEventHubProperties.SetSelectedItemsAdorner(scp, null);
                    pm.SetValue <Object>(SelectedItemsAdornerKey, null);
                    break;

                case UIEventHub.AdornerMode.Update:
                    var updateAdorner = pm.GetValue <SelectedItemsAdorner>(SelectedItemsAdornerKey) ??
                                        UIEventHubProperties.GetSelectedItemsAdorner(scp);

                    if (updateAdorner == null)
                    {
                        return(ResultCommand.Error(new Exception("Adorner not found.")));
                    }

                    Point current = pm.GetValue <Point>(CurrentPositionAdjustedKey);

                    if (updateAdorner.CurrentPosition.X == -1 && updateAdorner.CurrentPosition.Y == -1)
                    {
                        //If the adorner is not initialized.
                        updateAdorner.SetValue(SelectedItemsAdorner.CurrentPositionProperty, current);
                        updateAdorner.SetValue(SelectedItemsAdorner.ItemsProperty, ic.ItemsSource);
                    }
                    else
                    {
                        updateAdorner.SetValue(SelectedItemsAdorner.CurrentPositionProperty, current);
                    }
                    break;
                }
            }
            return(NextCommand);
        }