Пример #1
0
        /// <summary>
        /// This method determines what template to use for tab's content.
        ///
        /// For example, if repo is not opened, it shows New Tab template, otherwise it shows the repository template.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="container"></param>
        /// <returns></returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            string templateName;

            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                templateName = "repoTabContentTemplate";
            }
            else if (item == CollectionView.NewItemPlaceholder)
            {
                templateName = "repoTabDashboardContentTemplate";
            }
            else
            {
                RepositoryViewModel repository = item as RepositoryViewModel;

                templateName = repository.NotOpened ? "repoTabDashboardContentTemplate" : "repoTabContentTemplate";
            }

            FrameworkElement element = container as FrameworkElement;
            var template             = element.TryFindResource(templateName) as DataTemplate;

            if (template != null)
            {
                return(template);
            }

            return(base.SelectTemplate(item, container));
        }
Пример #2
0
        /// <summary>
        /// Creates a new tab.
        /// </summary>
        /// <param name="action"></param>
        private void CreateTab(object action)
        {
            var tabControl          = UIHelper.FindChild <TabControl>(Application.Current.MainWindow, "RepositoryTabs");
            var mainWindowViewModel = (MainWindowViewModel)Application.Current.MainWindow.DataContext;

            var repository = new RepositoryViewModel
            {
                Name               = "Dashboard",
                NotOpened          = true,
                RepositoryFullPath = ""
            };

            mainWindowViewModel.RepositoryViewModels.Add(repository);

            tabControl.SelectedItem = repository;
        }
Пример #3
0
        /// <summary>
        /// Loads the initial configuration.
        /// </summary>
        public void Load()
        {
            var tabControl = UIHelper.FindChild <TabControl>(Application.Current.MainWindow, "RepositoryTabs");

            Config = Configuration.LoadConfiguration();

            // We need to temporarily disable notifications to avoid collection modification within a loop.
            RepositoryViewModels.DisableNotifications();

            // Fill the "RecentRepositories" collection and load them.
            foreach (var recent in Config.RecentRepositories)
            {
                var repo = new RepositoryViewModel {
                    Name = recent.Name, RepositoryFullPath = recent.RepositoryFullPath
                };

                RecentRepositories.Add(repo);

                // If this repository was opened previously, re-open it again.
                if (Config.OpenedRepositories.Any(r => r.RepositoryFullPath == recent.RepositoryFullPath))
                {
                    repo.Init();
                    RepositoryViewModels.Add(repo);
                }
            }

            RepositoryViewModels.EnableNotifications(true);

            // Create the dashboard tab if there are no tabs opened.
            if (tabControl.Items.Count == 1) // The "+" tab is counted as one.
            {
                CreateTab(new object());     // Create "Dashboard".
            }
            // Select the first tab.
            tabControl.SelectedIndex = 0;
        }
Пример #4
0
        /// <summary>
        /// Loads the initial configuration.
        /// </summary>
        public void Load()
        {
            var tabControl = UIHelper.FindChild<TabControl>(Application.Current.MainWindow, "RepositoryTabs");

            Config = Configuration.LoadConfiguration();

            // We need to temporarily disable notifications to avoid collection modification within a loop.
            RepositoryViewModels.DisableNotifications();

            // Fill the "RecentRepositories" collection and load them.
            foreach (var recent in Config.RecentRepositories)
            {
                var repo = new RepositoryViewModel { Name = recent.Name, RepositoryFullPath = recent.RepositoryFullPath };

                RecentRepositories.Add(repo);

                // If this repository was opened previously, re-open it again.
                if (Config.OpenedRepositories.Any(r => r.RepositoryFullPath == recent.RepositoryFullPath))
                {
                    repo.Init();
                    RepositoryViewModels.Add(repo);
                }
            }

            RepositoryViewModels.EnableNotifications(true);

            // Create the dashboard tab if there are no tabs opened.
            if (tabControl.Items.Count == 1) // The "+" tab is counted as one.
                CreateTab(new object()); // Create "Dashboard".

            // Select the first tab.
            tabControl.SelectedIndex = 0;
        }
Пример #5
0
        /// <summary>
        /// Creates a new tab.
        /// </summary>
        /// <param name="action"></param>
        private void CreateTab(object action)
        {
            var tabControl = UIHelper.FindChild<TabControl>(Application.Current.MainWindow, "RepositoryTabs");
            var mainWindowViewModel = (MainWindowViewModel) Application.Current.MainWindow.DataContext;

            var repository = new RepositoryViewModel
            {
                Name = "Dashboard",
                NotOpened = true,
                RepositoryFullPath = ""
            };

            mainWindowViewModel.RepositoryViewModels.Add(repository);

            tabControl.SelectedItem = repository;
        }