Exemplo n.º 1
0
        public void After_AddingHistory_ForwardHistoryIsDestroyed()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);
            nav.AddToHistory(4);
            nav.AddToHistory(5);

            nav.NavigateBackward();
            nav.NavigateBackward();
            nav.NavigateBackward();
            nav.NavigateBackward();

            // act

            nav.AddToHistory(9);

            var one = nav.NavigateBackward();
            var navBackAfterOne = nav.CanNavigateBackward;
            var nine = nav.NavigateForward();
            var navForwAfterNine = nav.CanNavigateForward;

            // assert

            Assert.IsFalse(navBackAfterOne);
            Assert.IsFalse(navForwAfterNine);
            Assert.AreEqual(1, one);
            Assert.AreEqual(9, nine);
        }
        public ChildFormNavigationController()
        {
            navigationHistory = CreateNavigationHistory();
            navigationStack = new SizeLimitedStack<ViewShortcut>(HistoryDepth);
            InitializeComponent();

            RegisterActions(components);
        }
        public void Go_back_from_end()
        {
            var sut = new NavigationHistory();
            sut.Extend("a");
            sut.Extend("b");
            sut.Extend("c");

            string item;
            Assert.IsTrue(sut.GoBack(out item));
            Assert.AreEqual("b", item);
            Assert.IsTrue(sut.GoBack(out item));
            Assert.AreEqual("a", item);
            Assert.IsFalse(sut.GoBack(out item));
        }
Exemplo n.º 4
0
        public void After_SingleHistoryItem_CannotNavigate()
        {
            // arrange

            var nav = new NavigationHistory <int>();

            // act

            nav.AddToHistory(42);

            // assert

            Assert.IsFalse(nav.CanNavigateBackward);
            Assert.IsFalse(nav.CanNavigateForward);
        }
Exemplo n.º 5
0
        public void After_MultipleHistoryItems_CanNavigateBackward()
        {
            // arrange

            var nav = new NavigationHistory <int>();

            // act

            nav.AddToHistory(1);
            nav.AddToHistory(2);

            // assert

            Assert.IsTrue(nav.CanNavigateBackward);
        }
Exemplo n.º 6
0
        public void While_AtHeadOfHistory_CannotNavigateForward()
        {
            // arrange

            var nav = new NavigationHistory <int>();

            // act

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            // assert

            Assert.IsFalse(nav.CanNavigateForward);
        }
        public void Go_forward_from_beginning()
        {
            var sut = new NavigationHistory();
            sut.Extend("a");
            sut.Extend("b");
            sut.Extend("c");

            string item;
            sut.GoBack(out item);
            sut.GoBack(out item);

            Assert.IsTrue(sut.GoForward(out item));
            Assert.AreEqual("b", item);
            Assert.IsTrue(sut.GoForward(out item));
            Assert.AreEqual("c", item);
        }
Exemplo n.º 8
0
        public void Go_back_from_end()
        {
            var sut = new NavigationHistory();

            sut.Extend("a");
            sut.Extend("b");
            sut.Extend("c");

            string item;

            Assert.IsTrue(sut.GoBack(out item));
            Assert.AreEqual("b", item);
            Assert.IsTrue(sut.GoBack(out item));
            Assert.AreEqual("a", item);
            Assert.IsFalse(sut.GoBack(out item));
        }
Exemplo n.º 9
0
        private async Task <NavigationResult> PeekPreviousRegion(INavigationParameters parameters)
        {
            var result = new NavigationResult();

            try
            {
                var currentRegion = PagesContainer[NavigationHistory.Pop()];

                var canNavigate = await PageUtilities.CanNavigateAsync(currentRegion, parameters);

                if (!canNavigate)
                {
                    result.Exception = new Exception(NavigationException.IConfirmNavigationReturnedFalse);
                    return(result);
                }

                if (NavigationHistory.Count == 0)
                {
                    //TODO: exit the application.
                    //_applicationProvider..Quit();
                    result.Success = true;
                    return(result);
                }

                var previousRegion = PagesContainer[NavigationHistory.Peek()];
                GetContentPresenter().Content = previousRegion;

                PageUtilities.OnNavigatedFrom(currentRegion, parameters);
                PageUtilities.OnNavigatedTo(previousRegion, parameters);

                if (CurrentRegionName.Contains('/'))
                {
                    PopRegion(currentRegion);
                }
                CurrentRegionName = NavigationHistory.Peek();

                result.Success = true;
                return(result);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                result.Exception = ex;
                return(result);
            }
        }
Exemplo n.º 10
0
        public void GotoPage(int key)
        {
            CurrentPage?.OnNavigatedFrom(false);

            WizardPageViewModel nextPage;

            if (Pages.TryGetValue(key, out nextPage))
            {
                NavigationHistory.Push(CurrentPageKey);
                CurrentPage    = nextPage;
                CurrentPageKey = key;

                CurrentPage?.OnNavigatedTo(true);
            }

            // TODO: Handle this
        }
Exemplo n.º 11
0
        public void Go_forward_from_beginning()
        {
            var sut = new NavigationHistory();

            sut.Extend("a");
            sut.Extend("b");
            sut.Extend("c");

            string item;

            sut.GoBack(out item);
            sut.GoBack(out item);

            Assert.IsTrue(sut.GoForward(out item));
            Assert.AreEqual("b", item);
            Assert.IsTrue(sut.GoForward(out item));
            Assert.AreEqual("c", item);
        }
Exemplo n.º 12
0
        public void After_NavigatingBackward_CanNavigateForward()
        {
            // arrange

            var nav = new NavigationHistory <int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            // act

            nav.NavigateBackward();

            // assert

            Assert.IsTrue(nav.CanNavigateForward);
        }
Exemplo n.º 13
0
        public void AddingToHistory_InvokesChangeEvent()
        {
            // arrange

            var nav = new NavigationHistory<int>();
            var eventCount = 0;

            nav.OnHistoryChange += () =>
            {
                eventCount++;
            };

            // act

            nav.AddToHistory(1);

            // assert

            Assert.AreEqual(1, eventCount);
        }
Exemplo n.º 14
0
        public MainForm()
        {
            InitializeComponent();

            allObjectsTreeView.ImageList         = IconImages.ImageList;
            relationshipsListView.SmallImageList = IconImages.ImageList;

            allObjectsTreeViewRadioButton.Checked = true;

            m_treeViewNavHistory             = new NavigationHistory(allObjectsTreeView, 64);
            m_recentProjects                 = new RecentlyOpenedList("projects", 8, recentFoldersToolStripMenuItem);
            m_recentProjects.OnItemSelected += OnRecentPathSelected;

            ObjectDatabase.Added   += OnObjectAdded;
            ObjectDatabase.Removed += OnObjectRemoved;
            ObjectDatabase.Cleared += OnDatabaseCleared;

            m_updateLoopThread = new Thread(UpdateLoop);
            m_updateLoopThread.Start();
        }
Exemplo n.º 15
0
        public async void Back()
        {
            if (_navigationHistory.Count == 1)
            {
                return;
            }

            _navigationHistory.Pop();
            NavigationHistory.RemoveAt(0);
            if (_navigationHistory.Count == 1)
            {
                try
                {
                    await _jiraApi.Session.Logout();
                }
                catch (IncompleteJiraConfiguration)
                { }
            }
            await SetPage();
        }
Exemplo n.º 16
0
        private async void BackToPage(NavigationHistoryEntry entry)
        {
            if (entry.Page.Title.Contains("Log out"))
            {
                await _jiraApi.Session.Logout();
            }

            if (_navigationHistory.Peek() == entry.Page)
            {
                return;
            }

            while (_navigationHistory.Peek() != entry.Page)
            {
                _navigationHistory.Pop();
                NavigationHistory.RemoveAt(0);
            }

            await SetPage();
        }
Exemplo n.º 17
0
        public void BackwardsNavigation_DuringReadOnlyMode_ProducesDefaultValue()
        {
            // arrange

            var nav = new NavigationHistory <int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            nav.IsReadOnly = true;

            // act

            var zero = nav.NavigateBackward();

            // assert

            Assert.AreEqual(default(int), zero);
        }
Exemplo n.º 18
0
        public void AddingToHistory_InvokesChangeEvent()
        {
            // arrange

            var nav        = new NavigationHistory <int>();
            var eventCount = 0;

            nav.OnHistoryChange += () =>
            {
                eventCount++;
            };

            // act

            nav.AddToHistory(1);

            // assert

            Assert.AreEqual(1, eventCount);
        }
Exemplo n.º 19
0
        public void NavigatingBackward_ProducesCorrectItem()
        {
            // arrange

            var nav = new NavigationHistory <int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            // act

            var two = nav.NavigateBackward();
            var one = nav.NavigateBackward();

            // assert

            Assert.AreEqual(2, two);
            Assert.AreEqual(1, one);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Initializes the current page.
        /// </summary>
        protected override void InitializePage()
        {
            base.InitializePage();

            if (Request.Url == null)
            {
                return;
            }

            var currentUrl = Request.Url.AbsoluteUri;

            if (string.IsNullOrWhiteSpace(ViewBag.Title))
            {
                return;
            }

            if (!NavigationHistory.Any() || !NavigationHistory.Last().Equals(currentUrl))
            {
                AddToHistory(ViewBag.Title, Request.Url);
            }
        }
Exemplo n.º 21
0
        public void After_AddingHistory_CannotNavigateForward()
        {
            // arrange

            var nav = new NavigationHistory <int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            nav.NavigateBackward();
            nav.NavigateBackward();

            // act

            nav.AddToHistory(9);

            // assert

            Assert.IsFalse(nav.CanNavigateForward);
        }
Exemplo n.º 22
0
        public void After_AddingHistory_CannotNavigateForward()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            nav.NavigateBackward();
            nav.NavigateBackward();

            // act

            nav.AddToHistory(9);

            // assert

            Assert.IsFalse(nav.CanNavigateForward);
        }
Exemplo n.º 23
0
        public void ReadOnlyMode_BlocksAddingToHistory()
        {
            // arrange

            var nav = new NavigationHistory <int>();

            nav.IsReadOnly = true;

            // act

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            nav.IsReadOnly = false;

            // assert

            Assert.IsFalse(nav.CanNavigateBackward);
            Assert.IsFalse(nav.CanNavigateForward);
        }
Exemplo n.º 24
0
        public NavigationService(
            Frame frame,
            IPageDefinitionRegistry pageDefinitions,
            IViewModelFactory viewModelFactory,
            IScheduler dispatcherScheduler,
            IScheduler backgroundScheduler)
        {
            if (frame == null)
            {
                throw new ArgumentNullException("frame");
            }
            if (pageDefinitions == null)
            {
                throw new ArgumentNullException("pageDefinitions");
            }
            if (viewModelFactory == null)
            {
                throw new ArgumentNullException("viewModelFactory");
            }
            if (dispatcherScheduler == null)
            {
                throw new ArgumentNullException("dispatcherScheduler");
            }
            if (backgroundScheduler == null)
            {
                throw new ArgumentNullException("backgroundScheduler");
            }
            _frame               = frame;
            _pageDefinitions     = pageDefinitions;
            _viewModelFactory    = viewModelFactory;
            _dispatcherScheduler = dispatcherScheduler;
            _backgroundScheduler = backgroundScheduler;
            _navigatingSubject   = new Subject <INavigationRequest>();
            _navigatedSubject    = new Subject <INavigationRequest>();
            _semaphore           = new SemaphoreSlim(1);
            History              = _history = new NavigationHistory(RemoveHistoryEntry, ClearHistory);

            _frame.Navigated += _frame_Navigated;
            //_frame.BackKeyPress += _frame_BackKeyPress;
        }
        public void Extend_after_going_back()
        {
            var sut = new NavigationHistory();
            sut.Extend("a");
            sut.Extend("b");
            sut.Extend("c");

            string item;
            sut.GoBack(out item); // b

            sut.Extend("x");
            sut.Extend("y");

            Assert.IsTrue(sut.GoBack(out item));
            Assert.AreEqual("x", item);
            Assert.IsTrue(sut.GoBack(out item));
            Assert.AreEqual("b", item);

            Assert.IsTrue(sut.GoForward(out item));
            Assert.AreEqual("x", item);
            Assert.IsTrue(sut.GoForward(out item));
            Assert.AreEqual("y", item);
        }
Exemplo n.º 26
0
        public void Initially_CannotNavigate()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            // act

            // assert

            Assert.IsFalse(nav.CanNavigateBackward);
            Assert.IsFalse(nav.CanNavigateForward);
        }
Exemplo n.º 27
0
        public void NavigatingForward_InvokesChangeEvent()
        {
            // arrange

            var nav = new NavigationHistory<int>();
            var eventCount = 0;

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            nav.NavigateBackward();
            nav.NavigateBackward();

            nav.OnHistoryChange += () =>
            {
                eventCount++;
            };

            // act

            nav.NavigateForward();

            // assert

            Assert.AreEqual(1, eventCount);
        }
Exemplo n.º 28
0
 protected void OnCurrentFolderUpdate()
 {
     this.ExecuteCommand(typeof(NavigateCommand));
     NavigationHistory.SetCurrent(CurrentFolder);
     RaisePropertyChanged(nameof(SelectedLocationItem));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Initializes Navigator instance
 /// </summary>
 /// <param name="controllerProvider">Instance of the IControllerProvider</param>
 public Navigator(IControllerProvider controllerProvider)
 {
     this.controllerProvider = controllerProvider;
     this.history            = new NavigationHistory();
 }
Exemplo n.º 30
0
        public void After_NavigatingBackward_CanNavigateForward()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            // act

            nav.NavigateBackward();

            // assert

            Assert.IsTrue(nav.CanNavigateForward);
        }
Exemplo n.º 31
0
        public void After_MultipleHistoryItems_CanNavigateBackward()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            // act

            nav.AddToHistory(1);
            nav.AddToHistory(2);

            // assert

            Assert.IsTrue(nav.CanNavigateBackward);
        }
Exemplo n.º 32
0
        public void ReadOnlyMode_BlocksForwardNavigation()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            nav.NavigateBackward();
            nav.NavigateBackward();

            nav.IsReadOnly = true;

            // act

            nav.NavigateForward();
            nav.NavigateForward();
            nav.NavigateForward();

            var canStillNavigate = nav.CanNavigateForward;

            nav.IsReadOnly = false;

            var two = nav.NavigateForward();

            // assert

            Assert.True(canStillNavigate);
            Assert.AreEqual(2, two);
        }
Exemplo n.º 33
0
        public void NavigatingForward_WhenUnable_ThrowsException()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            // act

            nav.NavigateForward();

            // assert

            Assert.Fail();
        }
Exemplo n.º 34
0
 // ======================================================================
 // ----------------------------------------------------------------------
 public void SaveNavigationState()
 {
     NavigationHistory.Save(Storage);
 }
Exemplo n.º 35
0
        private async Task <NavigationResult> PushRegion(string path, INavigationParameters parameters)
        {
            var result = new NavigationResult();

            try
            {
                View currentRegion = null;
                parameters = GetParams(path, parameters);

                if (PagesContainer.Count > 0)
                {
                    currentRegion = PagesContainer.Last().Value;
                    var canNavigate = await PageUtilities.CanNavigateAsync(currentRegion, parameters);

                    if (!canNavigate)
                    {
                        result.Exception = new Exception(NavigationException.IConfirmNavigationReturnedFalse);
                        return(result);
                    }
                }

                View nextRegion = null;
                if (path.Contains('/'))
                {
                    foreach (var splitPath in path.Split(new[] { '/' },
                                                         StringSplitOptions.RemoveEmptyEntries))
                    {
                        if (PagesContainer.Keys.Contains(splitPath))
                        {
                            continue;
                        }
                        nextRegion = _containerProvider.ResolveRegion(splitPath);
                        PagesContainer.Add(splitPath, nextRegion);
                    }
                }
                else if (PagesContainer.Keys.Contains(path))
                {
                    nextRegion = PagesContainer[path];
                }
                else
                {
                    nextRegion = _containerProvider.ResolveRegion(path);
                    PagesContainer.Add(path, nextRegion);
                }

                GetContentPresenter().Content = nextRegion;

                await PageUtilities.OnInitializedAsync(currentRegion, parameters);

                PageUtilities.OnNavigatedFrom(currentRegion, parameters);
                PageUtilities.OnNavigatedTo(nextRegion, parameters);

                CurrentRegionName = path;
                NavigationHistory.Push(CurrentRegionName);

                result.Success = true;
                return(result);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                result.Exception = ex;
                return(result);
            }
        }
Exemplo n.º 36
0
        public void ReadOnlyMode_BlocksAddingToHistory()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            nav.IsReadOnly = true;

            // act

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            nav.IsReadOnly = false;

            // assert

            Assert.IsFalse(nav.CanNavigateBackward);
            Assert.IsFalse(nav.CanNavigateForward);
        }
Exemplo n.º 37
0
        public void ForwardsNavigation_DuringReadOnlyMode_ProducesDefaultValue()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            nav.NavigateBackward();
            nav.NavigateBackward();

            nav.IsReadOnly = true;

            // act

            var zero = nav.NavigateForward();

            // assert

            Assert.AreEqual(default(int), zero);
        }
Exemplo n.º 38
0
        public void After_SingleHistoryItem_CannotNavigate()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            // act

            nav.AddToHistory(42);

            // assert

            Assert.IsFalse(nav.CanNavigateBackward);
            Assert.IsFalse(nav.CanNavigateForward);
        }
Exemplo n.º 39
0
        public void NavigatingForward_ProducesCorrectItem()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            nav.NavigateBackward();
            nav.NavigateBackward();

            // act

            var two = nav.NavigateForward();
            var three = nav.NavigateForward();

            // assert

            Assert.AreEqual(2, two);
            Assert.AreEqual(3, three);
        }
Exemplo n.º 40
0
 public void Clear()
 {
     NavigationHistory.Clear();
     NavigationPosition = -1;
 }
Exemplo n.º 41
0
 public async void NavigateTo(INavigationPage page)
 {
     _navigationHistory.Push(page);
     NavigationHistory.Insert(0, new NavigationHistoryEntry(page));
     await SetPage();
 }
Exemplo n.º 42
0
 protected void OnCurrentFolderUpdate()
 {
     this.ExecuteCommand(typeof(NavigateCommand));
     NavigationHistory.SetCurrent(CurrentFolder);
     SelectedLocationItem = Locations.FirstOrDefault(x => CurrentFolder.Path.Contains(x.Path));
 }
Exemplo n.º 43
0
        public void While_AtHeadOfHistory_CannotNavigateForward()
        {
            // arrange

            var nav = new NavigationHistory<int>();

            // act

            nav.AddToHistory(1);
            nav.AddToHistory(2);
            nav.AddToHistory(3);

            // assert

            Assert.IsFalse(nav.CanNavigateForward);
        }
Exemplo n.º 44
0
        public Main(string[] cmdlineArgs, GUIUser user, bool showConsole)
        {
            log.Info("Starting the GUI");
            commandLineArgs = cmdlineArgs;
            currentUser = user;

            user.displayMessage = AddStatusMessage;
            user.displayError = ErrorDialog;

            controlFactory = new ControlFactory();
            Instance = this;
            mainModList = new MainModList(source => UpdateFilters(this), TooManyModsProvide, user);

            navHistory = new NavigationHistory<GUIMod>();
            navHistory.IsReadOnly = true; // read-only until the UI is started.
                                            // we switch out of it at the end of OnLoad()
                                            // when we call NavInit()

            InitializeComponent();

            // We need to initialize error dialog first to display errors
            errorDialog = controlFactory.CreateControl<ErrorDialog>();

            // We want to check our current instance is null first, as it may
            // have already been set by a command-line option.
            Manager = new KSPManager(user);
            if (CurrentInstance == null && manager.GetPreferredInstance() == null)
            {
                Hide();

                var result = new ChooseKSPInstance().ShowDialog();
                if (result == DialogResult.Cancel || result == DialogResult.Abort)
                {
                    Application.Exit();
                    return;
                }
            }

            configuration = Configuration.LoadOrCreateConfiguration
                (
                    Path.Combine(CurrentInstance.GameDir(), "CKAN/GUIConfig.xml"),
                    Repo.default_ckan_repo.ToString()
                );

            // Check if there is any other instances already running.
            // This is not entirely necessary, but we can show a nicer error message this way.
            try
            {
                #pragma warning disable 219
                var lockedReg = RegistryManager.Instance(CurrentInstance).registry;
                #pragma warning restore 219
            }
            catch (RegistryInUseKraken kraken)
            {
                errorDialog.ShowErrorDialog(kraken.ToString());

                return;
            }

            FilterToolButton.MouseHover += (sender, args) => FilterToolButton.ShowDropDown();
            launchKSPToolStripMenuItem.MouseHover += (sender, args) => launchKSPToolStripMenuItem.ShowDropDown();
            ApplyToolButton.MouseHover += (sender, args) => ApplyToolButton.ShowDropDown();

            ModList.CurrentCellDirtyStateChanged += ModList_CurrentCellDirtyStateChanged;
            ModList.CellValueChanged += ModList_CellValueChanged;

            tabController = new TabController(MainTabControl);
            tabController.ShowTab("ManageModsTabPage");

            RecreateDialogs();

            if (!showConsole)
            {
                Util.HideConsoleWindow();
            }

            // Disable the modinfo controls until a mod has been choosen.
            ModInfoTabControl.SelectedModule = null;

            // WinForms on Mac OS X has a nasty bug where the UI thread hogs the CPU,
            // making our download speeds really slow unless you move the mouse while
            // downloading. Yielding periodically addresses that.
            // https://bugzilla.novell.com/show_bug.cgi?id=663433
            if (Platform.IsMac)
            {
                var timer = new Timer { Interval = 2 };
                timer.Tick += (sender, e) => {
                    Thread.Yield();
                };
                timer.Start();
            }

            Application.Run(this);

            var registry = RegistryManager.Instance(Manager.CurrentInstance);
            if (registry != null)
            {
                registry.Dispose();
            }
        }
Exemplo n.º 45
0
        //TODO: Why you use this Public constructors in case of the Singleton

        /// <summary>
        /// Initializes Navigator instance
        /// </summary>
        public Navigator()
        {
            this.controllerProvider = new DefaultControllerProvider();
            this.history            = new NavigationHistory();
        }