Пример #1
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();
        }
Пример #2
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();
        }