/// <summary>
        /// A control has send an event that it has (been) browsing to a new location.
        /// Lets sync this with all other controls.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Control_BrowseEvent(object sender,
                                         FileSystemModels.Browse.BrowsingEventArgs e)
        {
            if (e.IsBrowsing == false && e.Result == BrowseResult.Complete)
            {
                var request = new BrowseRequest(e.Location);
                FinalBrowseResult browseResult = null;

                if (FolderTextPath != sender)
                {
                    // Navigate Folder ComboBox to this folder
                    browseResult = FolderTextPath.NavigateTo(request);

                    if (browseResult.Result != BrowseResult.Complete)
                    {
                        return;
                    }
                }

                if (FolderItemsView != sender)
                {
                    // Navigate Folder/File ListView to this folder
                    browseResult = FolderItemsView.NavigateTo(request);

                    if (browseResult.Result != BrowseResult.Complete)
                    {
                        return;
                    }
                }

                if (browseResult != null) // There should be at least one succesfull browse
                {                         // to change selection and log history
                    if (browseResult.Result == BrowseResult.Complete)
                    {
                        // Log location into history of recent locations
                        SelectedFolder = request.NewLocation.Path;
                        NaviHistory.Forward(request.NewLocation);
                    }
                }
            }
            else
            {
                if (e.IsBrowsing == true)
                {
                    if (FolderTextPath != sender)
                    {
                        // Navigate Folder ComboBox to this folder
                        FolderTextPath.SetExternalBrowsingState(true);
                    }

                    if (FolderItemsView != sender)
                    {
                        // Navigate Folder/File ListView to this folder
                        FolderItemsView.SetExternalBrowsingState(true);
                    }
                }
            }
        }
        /// <summary>
        /// One of the controls has changed its location in the filesystem.
        /// This method is invoked to synchronize this change with all other controls.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FolderTextPath_BrowseEvent(object sender,
                                                FileSystemModels.Browse.BrowsingEventArgs e)
        {
            var location = e.Location;

            SelectedFolder = location.Path;

            if (e.IsBrowsing == false && e.Result == BrowseResult.Complete)
            {
                NavigateToFolder(location);
            }
            else
            {
                if (e.IsBrowsing == true)
                {
                    // The sender has messaged: "I am chnaging location..."
                    // So, we set this property to tell the others:
                    // 1) Don't change your location now (eg.: Disable UI)
                    // 2) We'll be back to tell you the location when we know it
                    if (TreeBrowser != sender)
                    {
                        TreeBrowser.SetExternalBrowsingState(true);
                    }

                    if (FolderTextPath != sender)
                    {
                        FolderTextPath.SetExternalBrowsingState(true);
                    }

                    if (FolderItemsView != sender)
                    {
                        FolderItemsView.SetExternalBrowsingState(true);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// One of the controls has changed its location in the filesystem.
        /// This method is invoked to synchronize this change with all other controls.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FolderTextPath_BrowseEvent(object sender,
                                                FileSystemModels.Browse.BrowsingEventArgs e)
        {
            var location = e.Location;

            SelectedFolder = location.Path;

            if (e.IsBrowsing == false && e.Result == BrowseResult.Complete)
            {
                // XXX Todo Keep task reference, support cancel, and remove on end?
                try
                {
                    var timeout    = TimeSpan.FromSeconds(5);
                    var actualTask = new Task(() =>
                    {
                        var request = new BrowseRequest(location, _CancelTokenSourc.Token);

                        var t = Task.Factory.StartNew(() => NavigateToFolderAsync(request, sender),
                                                      request.CancelTok,
                                                      TaskCreationOptions.LongRunning,
                                                      _OneTaskScheduler);

                        if (t.Wait(timeout) == true)
                        {
                            return;
                        }

                        _CancelTokenSourc.Cancel();     // Task timed out so lets abort it
                        return;                         // Signal timeout here...
                    });

                    actualTask.Start();
                    actualTask.Wait();
                }
                catch (System.AggregateException ex)
                {
                    Logger.Error(ex);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            }
            else
            {
                if (e.IsBrowsing == true)
                {
                    // The sender has messaged: "I am changing location..."
                    // So, we set this property to tell the others:
                    // 1) Don't change your location now (eg.: Disable UI)
                    // 2) We'll be back to tell you the location when we know it
                    if (TreeBrowser != sender)
                    {
                        TreeBrowser.SetExternalBrowsingState(true);
                    }

                    if (FolderTextPath != sender)
                    {
                        FolderTextPath.SetExternalBrowsingState(true);
                    }

                    if (FolderItemsView != sender)
                    {
                        FolderItemsView.SetExternalBrowsingState(true);
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Master controler interface method to navigate all views
        /// to the folder indicated in <paramref name="folder"/>
        /// - updates all related viewmodels.
        /// </summary>
        /// <param name="request"></param>
        private async Task <FinalBrowseResult> NavigateToFolderAsync(BrowseRequest request,
                                                                     object sender)
        {
            // Make sure the task always processes the last input but is not started twice
            await _SlowStuffSemaphore.WaitAsync();

            try
            {
                var newPath = request.NewLocation;
                var cancel  = request.CancelTok;

                if (cancel != null)
                {
                    cancel.ThrowIfCancellationRequested();
                }

                TreeBrowser.SetExternalBrowsingState(true);
                FolderItemsView.SetExternalBrowsingState(true);
                FolderTextPath.SetExternalBrowsingState(true);

                FinalBrowseResult browseResult = null;

                // Navigate TreeView to this file system location
                if (TreeBrowser != sender)
                {
                    browseResult = await TreeBrowser.NavigateToAsync(request);

                    if (cancel != null)
                    {
                        cancel.ThrowIfCancellationRequested();
                    }

                    if (browseResult.Result != BrowseResult.Complete)
                    {
                        return(FinalBrowseResult.FromRequest(request, BrowseResult.InComplete));
                    }
                }

                // Navigate Folder ComboBox to this folder
                if (FolderTextPath != sender)
                {
                    browseResult = await FolderTextPath.NavigateToAsync(request);

                    if (cancel != null)
                    {
                        cancel.ThrowIfCancellationRequested();
                    }

                    if (browseResult.Result != BrowseResult.Complete)
                    {
                        return(FinalBrowseResult.FromRequest(request, BrowseResult.InComplete));
                    }
                }

                if (cancel != null)
                {
                    cancel.ThrowIfCancellationRequested();
                }

                // Navigate Folder/File ListView to this folder
                if (FolderItemsView != sender)
                {
                    browseResult = await FolderItemsView.NavigateToAsync(request);

                    if (cancel != null)
                    {
                        cancel.ThrowIfCancellationRequested();
                    }

                    if (browseResult.Result != BrowseResult.Complete)
                    {
                        return(FinalBrowseResult.FromRequest(request, BrowseResult.InComplete));
                    }
                }

                if (browseResult != null)
                {
                    if (browseResult.Result == BrowseResult.Complete)
                    {
                        SelectedFolder = newPath.Path;

                        // Log location into history of recent locations
                        NaviHistory.Forward(newPath);
                    }
                }

                return(browseResult);
            }
            catch (Exception exp)
            {
                var result = FinalBrowseResult.FromRequest(request, BrowseResult.InComplete);
                result.UnexpectedError = exp;
                return(result);
            }
            finally
            {
                TreeBrowser.SetExternalBrowsingState(true);
                FolderItemsView.SetExternalBrowsingState(false);
                FolderTextPath.SetExternalBrowsingState(false);

                _SlowStuffSemaphore.Release();
            }
        }