Beispiel #1
0
        /// <inheritdoc/>
        public override void DoAcceptFiles(AcceptFilesEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            // that source
            if (!(args.Explorer is ItemExplorer))
            {
                if (args.UI)
                {
                    A.Message(Res.UnknownFileSource);
                }
                args.Result = JobResult.Ignore;
                return;
            }

            // this target
            if (!My.ProviderInfoEx.IsNavigation(Provider))
            {
                //! Actually e.g. functions can be copied, see UICopyHere
                if (args.UI)
                {
                    A.Message(Res.NotSupportedByProvider);
                }
                args.Result = JobResult.Ignore;
                return;
            }

            // call
            using (var ps = A.Psf.NewPowerShell())
            {
                if (args.Move)
                {
                    ps.AddCommand("Move-Item").AddParameter(Prm.Force);
                }
                else
                {
                    ps.AddCommand("Copy-Item").AddParameter(Prm.Recurse);
                }

                ps
                .AddParameter("Destination", this.Location)
                .AddParameter(Prm.Confirm)
                .AddParameter(Prm.ErrorAction, ActionPreference.Continue);

                ps.Invoke(args.FilesData);

                // errors
                if (ps.Streams.Error.Count > 0)
                {
                    args.Result = JobResult.Incomplete;
                    if (args.UI)
                    {
                        A.ShowError(ps);
                    }
                }
            }
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override void AcceptFiles(AcceptFilesEventArgs args)
        {
            if (args == null) return;

            // that source
            var that = args.Explorer as PropertyExplorer;
            if (that == null)
            {
                if (args.UI) A.Message(Res.UnknownFileSource);
                args.Result = JobResult.Ignore;
                return;
            }

            // names
            List<string> names = A.FileNameList(args.Files);

            //! gotchas in {Copy|Move}-ItemProperty:
            //! *) -Name takes a single string only? (help: yes (copy), no (move) - odd!)
            //! *) Names can't be pipelined (help says they can)
            //! so, use provider directly (no confirmation)
            string source = Kit.EscapeWildcard(that.ItemPath);
            string target = Kit.EscapeWildcard(this.ItemPath);
            if (args.Move)
            {
                foreach (string name in names)
                    A.Psf.Engine.InvokeProvider.Property.Move(source, name, target, name);
            }
            else
            {
                foreach (string name in names)
                    A.Psf.Engine.InvokeProvider.Property.Copy(source, name, target, name);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Calls <see cref="FarNet.Explorer.AcceptFiles"/> and <see cref="OnThisFileChanged"/>.
        /// </summary>
        /// <param name="args">.</param>
        public virtual void UIAcceptFiles(AcceptFilesEventArgs args)
        {
            if (args == null) return;

            Explorer.AcceptFiles(args);

            if (args.Result != JobResult.Ignore)
                OnThisFileChanged(args);
        }
Beispiel #4
0
        public override void UIAcceptFiles(AcceptFilesEventArgs args)
        {
            if (!ensurePathExist())
            {
                return;
            }

            base.UIAcceptFiles(args);
        }
Beispiel #5
0
        /// <inheritdoc/>
        public override void DoAcceptFiles(AcceptFilesEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            AddObjects(args.FilesData);
        }
Beispiel #6
0
 /// <include file='doc.xml' path='doc/ScriptFork/*'/>
 /// <param name="args">.</param>
 public sealed override void AcceptFiles(AcceptFilesEventArgs args)
 {
     if (AsAcceptFiles == null)
     {
         DoAcceptFiles(args);
     }
     else
     {
         A.InvokeScriptReturnAsIs(AsAcceptFiles, this, args);
     }
 }
Beispiel #7
0
        /// <inheritdoc/>
        public override void AcceptFiles(AcceptFilesEventArgs args)
        {
            if (args == null) return;

            foreach (var file in args.Files)
            {
                var xfile = file as SuperFile;
                if (xfile == null)
                    Cache.Add(new SuperFile(args.Explorer, file));
                else
                    Cache.Add(xfile);
            }
        }
        public override void AcceptFiles(AcceptFilesEventArgs args)
        {
            if (args.Explorer as FarPodExplorerBase == null)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            FarPodOperationService s = get(args, (FarPodExplorerBase)args.Explorer);

            OperationResult or = s.DirectCopyOrMoveToDevice(args.Files, this, args.Move);

            args.Result = processResult(or, args.Mode.HasFlag(ExplorerModes.Silent), args.FilesToStay);
        }
Beispiel #9
0
        /// <inheritdoc/>
        public override void DoAcceptFiles(AcceptFilesEventArgs args)
        {
            if (args == null) return;

            // that source
            var that = args.Explorer as ItemExplorer;
            if (that == null)
            {
                if (args.UI) A.Message(Res.UnknownFileSource);
                args.Result = JobResult.Ignore;
                return;
            }

            // this target
            if (!My.ProviderInfoEx.IsNavigation(Provider))
            {
                //! Actually e.g. functions can be copied, see UICopyHere
                if (args.UI) A.Message(Res.NotSupportedByProvider);
                args.Result = JobResult.Ignore;
                return;
            }

            // call
            using (var ps = A.Psf.NewPowerShell())
            {
                if (args.Move)
                    ps.AddCommand("Move-Item").AddParameter(Prm.Force);
                else
                    ps.AddCommand("Copy-Item").AddParameter(Prm.Recurse);

                ps
                    .AddParameter("Destination", this.Location)
                    .AddParameter(Prm.Confirm)
                    .AddParameter(Prm.ErrorAction, ActionPreference.Continue);

                ps.Invoke(args.FilesData);

                // errors
                if (ps.Streams.Error.Count > 0)
                {
                    args.Result = JobResult.Incomplete;
                    if (args.UI)
                        A.ShowError(ps);
                }
            }
        }
Beispiel #10
0
        /// <inheritdoc/>
        public override void AcceptFiles(AcceptFilesEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            // that source
            var that = args.Explorer as PropertyExplorer;

            if (that == null)
            {
                if (args.UI)
                {
                    A.Message(Res.UnknownFileSource);
                }
                args.Result = JobResult.Ignore;
                return;
            }

            // names
            List <string> names = A.FileNameList(args.Files);

            //! gotchas in {Copy|Move}-ItemProperty:
            //! *) -Name takes a single string only? (help: yes (copy), no (move) - odd!)
            //! *) Names can't be pipelined (help says they can)
            //! so, use provider directly (no confirmation)
            string source = Kit.EscapeWildcard(that.ItemPath);
            string target = Kit.EscapeWildcard(this.ItemPath);

            if (args.Move)
            {
                foreach (string name in names)
                {
                    A.Psf.Engine.InvokeProvider.Property.Move(source, name, target, name);
                }
            }
            else
            {
                foreach (string name in names)
                {
                    A.Psf.Engine.InvokeProvider.Property.Copy(source, name, target, name);
                }
            }
        }
Beispiel #11
0
        /// <inheritdoc/>
        public override void AcceptFiles(AcceptFilesEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            foreach (var file in args.Files)
            {
                if (file is SuperFile xfile)
                {
                    Cache.Add(xfile);
                }
                else
                {
                    Cache.Add(new SuperFile(args.Explorer, file));
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Copy/move action.
        /// </summary>
        /// <param name="move">Tells to move files.</param>
        /// <remarks>
        /// The source and target panel are module panels.
        /// The target panel explorer accepts the selected files.
        /// </remarks>
        public virtual void UICopyMove(bool move)
        {
            // target
            var that = TargetPanel;

            // commit
            if (that == null)
            {
                // can?
                if (!Explorer.CanExportFiles)
                    return;

                // target?
                var native = Far.Api.Panel2;
                if (native.IsPlugin || native.Kind != PanelKind.File)
                    return;

                // args
                var argsExport = new ExportFilesEventArgs(ExplorerModes.None, SelectedFiles, move, native.CurrentDirectory);
                if (argsExport.Files.Count == 0)
                    return;

                // call
                UIExportFiles(argsExport);
                if (argsExport.Result == JobResult.Ignore)
                    return;

                // show
                native.Update(true);
                native.Redraw();

                // complete
                UICopyMoveComplete(argsExport);
                return;
            }

            // can?
            if (!that.Explorer.CanAcceptFiles)
                return;

            // args
            var argsAccept = new AcceptFilesEventArgs(ExplorerModes.None, this.SelectedFiles, move, this.Explorer);
            if (argsAccept.Files.Count == 0)
                return;

            // call
            that.UIAcceptFiles(argsAccept);
            if (argsAccept.Result == JobResult.Ignore)
                return;

            // the target may have new files, update, keep selection
            that.Post(argsAccept);
            that.Update(true);
            that.Redraw();

            // complete
            UICopyMoveComplete(argsAccept);
        }
Beispiel #13
0
        /// <inheritdoc/>
        public override void DoAcceptFiles(AcceptFilesEventArgs args)
        {
            if (args == null) return;

            AddObjects(args.FilesData);
        }
Beispiel #14
0
        ///
        internal void CommitFiles(SuperPanel source, Panel target, IList<FarFile> files, bool move)
        {
            var dicTypeId = GroupFiles(files, ExplorerFunctions.None);

            bool SelectionExists = source.SelectionExists;
            var xfilesToStay = new List<FarFile>();
            bool toUnselect = false;
            bool toUpdate = false;
            foreach (var xTypeId in dicTypeId)
            {
                Log.Source.TraceInformation("AcceptFiles TypeId='{0}'", xTypeId.Key);
                object codata = null;
                foreach (var kv in xTypeId.Value)
                {
                    // explorer and its files
                    var explorer = kv.Key;
                    var xfiles = kv.Value;
                    var filesToAccept = new List<FarFile>(xfiles.Count);
                    foreach (var file in xfiles)
                        filesToAccept.Add(file.File);

                    // accept, mind co-data
                    Log.Source.TraceInformation("AcceptFiles Count='{0}' Location='{1}'", filesToAccept.Count, explorer.Location);
                    var argsAccept = new AcceptFilesEventArgs(ExplorerModes.None, filesToAccept, move, explorer);
                    argsAccept.Data = codata;
                    target.UIAcceptFiles(argsAccept);
                    codata = argsAccept.Data;

                    // info
                    bool isIncomplete = argsAccept.Result == JobResult.Incomplete;
                    bool isAllToStay = isIncomplete && argsAccept.FilesToStay.Count == 0;

                    // Copy: do not update the source, files are the same
                    if (!move)
                    {
                        // keep it as it is
                        if (isAllToStay || !SelectionExists)
                        {
                            if (isAllToStay && SelectionExists)
                                foreach(var file in xfiles)
                                    xfilesToStay.Add(file);
                            continue;
                        }

                        // drop selection
                        toUnselect = true;

                        // recover
                        if (isIncomplete)
                            xfilesToStay.AddRange(SuperFile.SuperFilesOfExplorerFiles(xfiles, argsAccept.FilesToStay, explorer.FileComparer));

                        continue;
                    }

                    // Move: no need to delete or all to stay or cannot delete
                    if (!argsAccept.ToDeleteFiles || isAllToStay || !explorer.CanDeleteFiles)
                    {
                        // the source may have some files deleted, update
                        toUpdate = true;

                        // recover selection
                        if (isIncomplete)
                            xfilesToStay.AddRange(SuperFile.SuperFilesOfExplorerFiles(
                                xfiles, isAllToStay ? argsAccept.Files : argsAccept.FilesToStay, explorer.FileComparer));

                        continue;
                    }

                    // Move: delete is requested, delete the source files

                    // exclude this files to stay from to be deleted
                    if (isIncomplete)
                    {
                        foreach (SuperFile xfile in SuperFile.SuperFilesOfExplorerFiles(xfiles, argsAccept.FilesToStay, explorer.FileComparer))
                        {
                            xfiles.Remove(xfile);
                            xfilesToStay.Add(xfile);
                        }
                    }

                    // call delete on remaining files
                    object codata2 = null;
                    var result = DeleteFilesOfExplorer(explorer, xfiles, xfilesToStay, ExplorerModes.Silent, false, ref codata2);
                    if (result == JobResult.Done || result == JobResult.Incomplete)
                        toUpdate = true;
                }
            }

            // update the target panel
            target.Update(true);
            target.Redraw();

            // update/recover the source

            if (toUpdate)
                source.Update(false);
            else if (toUnselect)
                source.UnselectAll();

            if (xfilesToStay.Count > 0)
                source.SelectFiles(xfilesToStay, null);

            source.Redraw();
        }
Beispiel #15
0
 /// <summary>
 /// Accepts module files from another explorer, normally from another module panel.
 /// </summary>
 /// <param name="args">.</param>
 /// <remarks>
 /// Read carefully all about <see cref="AcceptFilesEventArgs"/> and all its members.
 /// <para>
 /// The source explorer can be any explorer of any module panel, not even from this module.
 /// The method should check the source type or type ID and ignore unknown or not supported.
 /// </para>
 /// </remarks>
 public virtual void AcceptFiles(AcceptFilesEventArgs args)
 {
     if (args != null) args.Result = JobResult.Ignore;
 }
Beispiel #16
0
        ///
        internal void CommitFiles(SuperPanel source, Panel target, IList <FarFile> files, bool move)
        {
            var dicTypeId = GroupFiles(files, ExplorerFunctions.None);

            bool SelectionExists = source.SelectionExists;
            var  xfilesToStay    = new List <FarFile>();
            bool toUnselect      = false;
            bool toUpdate        = false;

            foreach (var xTypeId in dicTypeId)
            {
                Log.Source.TraceInformation("AcceptFiles TypeId='{0}'", xTypeId.Key);
                object codata = null;
                foreach (var kv in xTypeId.Value)
                {
                    // explorer and its files
                    var explorer      = kv.Key;
                    var xfiles        = kv.Value;
                    var filesToAccept = new List <FarFile>(xfiles.Count);
                    foreach (var file in xfiles)
                    {
                        filesToAccept.Add(file.File);
                    }

                    // accept, mind co-data
                    Log.Source.TraceInformation("AcceptFiles Count='{0}' Location='{1}'", filesToAccept.Count, explorer.Location);
                    var argsAccept = new AcceptFilesEventArgs(ExplorerModes.None, filesToAccept, move, explorer)
                    {
                        Data = codata
                    };
                    target.UIAcceptFiles(argsAccept);
                    codata = argsAccept.Data;

                    // info
                    bool isIncomplete = argsAccept.Result == JobResult.Incomplete;
                    bool isAllToStay  = isIncomplete && argsAccept.FilesToStay.Count == 0;

                    // Copy: do not update the source, files are the same
                    if (!move)
                    {
                        // keep it as it is
                        if (isAllToStay || !SelectionExists)
                        {
                            if (isAllToStay && SelectionExists)
                            {
                                foreach (var file in xfiles)
                                {
                                    xfilesToStay.Add(file);
                                }
                            }
                            continue;
                        }

                        // drop selection
                        toUnselect = true;

                        // recover
                        if (isIncomplete)
                        {
                            xfilesToStay.AddRange(SuperFile.SuperFilesOfExplorerFiles(xfiles, argsAccept.FilesToStay, explorer.FileComparer));
                        }

                        continue;
                    }

                    // Move: no need to delete or all to stay or cannot delete
                    if (!argsAccept.ToDeleteFiles || isAllToStay || !explorer.CanDeleteFiles)
                    {
                        // the source may have some files deleted, update
                        toUpdate = true;

                        // recover selection
                        if (isIncomplete)
                        {
                            xfilesToStay.AddRange(SuperFile.SuperFilesOfExplorerFiles(
                                                      xfiles, isAllToStay ? argsAccept.Files : argsAccept.FilesToStay, explorer.FileComparer));
                        }

                        continue;
                    }

                    // Move: delete is requested, delete the source files

                    // exclude this files to stay from to be deleted
                    if (isIncomplete)
                    {
                        foreach (SuperFile xfile in SuperFile.SuperFilesOfExplorerFiles(xfiles, argsAccept.FilesToStay, explorer.FileComparer))
                        {
                            xfiles.Remove(xfile);
                            xfilesToStay.Add(xfile);
                        }
                    }

                    // call delete on remaining files
                    object codata2 = null;
                    var    result  = DeleteFilesOfExplorer(explorer, xfiles, xfilesToStay, ExplorerModes.Silent, false, ref codata2);
                    if (result == JobResult.Done || result == JobResult.Incomplete)
                    {
                        toUpdate = true;
                    }
                }
            }

            // update the target panel
            target.Update(true);
            target.Redraw();

            // update/recover the source

            if (toUpdate)
            {
                source.Update(false);
            }
            else if (toUnselect)
            {
                source.UnselectAll();
            }

            if (xfilesToStay.Count > 0)
            {
                source.SelectFiles(xfilesToStay, null);
            }

            source.Redraw();
        }
Beispiel #17
0
 /// <include file='doc.xml' path='doc/ScriptFork/*'/>
 /// <param name="args">.</param>
 public override sealed void AcceptFiles(AcceptFilesEventArgs args)
 {
     if (AsAcceptFiles == null)
         DoAcceptFiles(args);
     else
         A.InvokeScriptReturnAsIs(AsAcceptFiles, this, args);
 }
Beispiel #18
0
 /// <summary>
 /// <see cref="Explorer.AcceptFiles"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void DoAcceptFiles(AcceptFilesEventArgs args)
 {
     base.AcceptFiles(args);
 }
Beispiel #19
0
 /// <summary>
 /// <see cref="Explorer.AcceptFiles"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void DoAcceptFiles(AcceptFilesEventArgs args)
 {
     base.AcceptFiles(args);
 }