Пример #1
0
        public void AddNewTabForUrl(string url, bool focusOnNewTab, Action <TabItem> callback = null)
        {
            if (!string.IsNullOrWhiteSpace(url))
            {
                int _tabElements = TabItemCollection.Count;

                TabItem newTab = new TabItem(Model, resolver);
                newTab.SearchBar.Address = url;

                newTab.CloseButtonVisibility = Visibility.Visible;

                int count = TabItemCollection.Where(x => x.CloseButtonVisibility == Visibility.Visible).Count();

                if (count > 0)
                {
                    if (count >= MAX_TAB_COUNT)
                    {
                        var tab = TabItemCollection.LastOrDefault(x => x.CloseButtonVisibility == Visibility.Visible);
                        tab.SearchBar.Address = url;
                        tab.SearchBar.Navigate();
                    }
                    else
                    {
                        TabItemCollection.Insert(count, newTab);
                    }
                }
                else
                {
                    TabItemCollection.Insert(0, newTab);
                }

                if (focusOnNewTab)
                {
                    if (TabItemCollection.Count > 1)
                    {
                        bool isNewButtonVisible = TabItemCollection.Any(x => x.NewTabButtonVisibility);
                        if (isNewButtonVisible)
                        {
                            Model.SelectedIndex = TabItemCollection.Count - 2;
                        }
                        else
                        {
                            Model.SelectedIndex = TabItemCollection.Count - 1;
                        }
                    }
                    else
                    {
                        Model.SelectedIndex = 0;
                    }
                }

                if (callback != null)
                {
                    callback(newTab);
                }
            }

            ShowAddNewTabIfNeeded();
        }
Пример #2
0
        public void AddNewTabClick(object obj)
        {
            TabItem newTab = new TabItem(Model, resolver);

            newTab.SearchBar.Title = (string)System.Windows.Application.Current.FindResource(NewTabMessage);
            var startPage = this.Model.PBData.GetPrivateSetting(DefaultProperties.Settings_StartPageUrl);

            if (!string.IsNullOrWhiteSpace(startPage))
            {
                newTab.SearchBar.Address = startPage;
            }
            newTab.CloseButtonVisibility = Visibility.Visible;

            int count = TabItemCollection.Where(x => x.CloseButtonVisibility == Visibility.Visible).Count();

            if (count > 0)
            {
                if (!(TabItemCollection.Count > MAX_TAB_COUNT))
                {
                    TabItemCollection.Insert(count, newTab);
                }
            }
            else
            {
                TabItemCollection.Insert(0, newTab);
            }

            if (!(obj is TabItem))
            {
                Model.SelectedIndex = Model.TabItemCollection.Count - 2;
            }
            if (TabItemCollection.Count == 2)
            {
                Model.SelectedIndex = 0;
            }

            ShowAddNewTabIfNeeded();
        }