Esempio n. 1
0
        /// <summary>
        /// Starts search and when it is done opens the panel with results.
        /// </summary>
        /// <param name="sourcePanel">The result panel to open.</param>
        public void Invoke(Panel sourcePanel)
        {
            if (sourcePanel == null)
            {
                throw new ArgumentNullException("sourcePanel");
            }

            // panel with the file store
            var panel = new SuperPanel();

            // invoke
            IsCompleted = false;
            try
            {
                panel.Explorer.AddFiles(InvokeWithProgress());
            }
            finally
            {
                IsCompleted = true;
            }

            // complete panel
            panel.Escaping += OnPanelEscaping;
            panel.Title     = string.Format(null, Res.SearchTitle,
                                            FoundFileCount, ProcessedDirectoryCount, Stopping ? Res.StateStopped : Res.StateCompleted);

            // open panel, even empty
            panel.OpenChild(sourcePanel);
        }
Esempio n. 2
0
        /// <summary>
        /// Starts search in the background and opens the panel for results immediately.
        /// </summary>
        /// <param name="sourcePanel">The result panel to open.</param>
        public void InvokeAsync(Panel sourcePanel)
        {
            if (sourcePanel == null)
            {
                throw new ArgumentNullException("sourcePanel");
            }

            var panel = new SuperPanel();

            panel.Title = Res.Searching;

            // open panel (try)
            panel.OpenChild(sourcePanel);

            // start search
            (new Thread(InvokeAsyncWorker)).Start();

            // subscribe
            panel.Escaping += OnPanelEscaping;
            panel.Closed   += OnPanelClosed;
            panel.Idled    += OnPanelIdled;
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        /// <summary>
        /// Starts search in the background and opens the panel for results immediately.
        /// </summary>
        /// <param name="sourcePanel">The result panel to open.</param>
        public void InvokeAsync(Panel sourcePanel)
        {
            if (sourcePanel == null) throw new ArgumentNullException("sourcePanel");

            var panel = new SuperPanel();
            panel.Title = Res.Searching;

            // open panel (try)
            panel.OpenChild(sourcePanel);

            // start search
            (new Thread(InvokeAsyncWorker)).Start();

            // subscribe
            panel.Escaping += OnPanelEscaping;
            panel.Closed += OnPanelClosed;
            panel.Idled += OnPanelIdled;
        }
Esempio n. 5
0
        /// <summary>
        /// Starts search and when it is done opens the panel with results.
        /// </summary>
        /// <param name="sourcePanel">The result panel to open.</param>
        public void Invoke(Panel sourcePanel)
        {
            if (sourcePanel == null) throw new ArgumentNullException("sourcePanel");

            // panel with the file store
            var panel = new SuperPanel();

            // invoke
            IsCompleted = false;
            try
            {
                panel.Explorer.AddFiles(InvokeWithProgress());
            }
            finally
            {
                IsCompleted = true;
            }

            // complete panel
            panel.Escaping += OnPanelEscaping;
            panel.Title = string.Format(null, Res.SearchTitle,
                FoundFileCount, ProcessedDirectoryCount, Stopping ? Res.StateStopped : Res.StateCompleted);

            // open panel, even empty
            panel.OpenChild(sourcePanel);
        }
Esempio n. 6
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();
        }