private void AddRepoMenuItem_Click(object?sender, EventArgs e)
 {
     using FavoriteRepoCreatorDialog dialog = new FavoriteRepoCreatorDialog();
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         AddFavorite(dialog.ToFavoriteRepo());
     }
 }
Esempio n. 2
0
        private void EditFavoriteContextMenuItem_Click(object?sender, EventArgs e)
        {
            if (_favoriteRepos is null)
            {
                LOG.Error($"{nameof( EditFavoriteContextMenuItem_Click )} - Favorite repos is null");
                return;
            }

            if (sender is not ToolStripMenuItem contextMenuItem ||
                contextMenuItem.Owner.Tag is not Favorite favorite)
            {
                return;
            }

            Favorite?newFavorite = null;

            if (favorite is FavoriteFolder folder)
            {
                using FavoriteFolderCreatorDialog dialog = FavoriteFolderCreatorDialog.FromFavoriteFolder(folder);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    newFavorite = dialog.ToFavoriteFolder();
                }
            }
            else if (favorite is FavoriteRepo repo)
            {
                using FavoriteRepoCreatorDialog dialog = FavoriteRepoCreatorDialog.FromFavoriteRepo(repo);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    newFavorite = dialog.ToFavoriteRepo();
                }
            }
            else if (favorite is FavoriteReposDirectory directory)
            {
                using FavoriteReposDirectoryCreatorDialog dialog = FavoriteReposDirectoryCreatorDialog.FromFavoriteReposDirectory(directory);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    newFavorite = dialog.ToFavoriteReposDirectory();
                }
            }
            else
            {
                LOG.Error($"{nameof( EditFavoriteContextMenuItem_Click )} - Unknown favorite type: {favorite}");
            }

            if (newFavorite != null)
            {
                if (!_favoriteRepos.Replace(favorite, newFavorite))
                {
                    LOG.Error($"{nameof( EditFavoriteContextMenuItem_Click )} - Failed to replace old favorite: {favorite} - {newFavorite}");
                    return;
                }

                Settings.Default.FavoriteRepos = _favoriteRepos !;
                Settings.Default.Save();
            }
        }
        private void EditFavoriteMenuItem_Click(object?sender, EventArgs e)
        {
            if (_selectedFavoriteItem == null)
            {
                LOG.Error($"{nameof( EditFavoriteMenuItem_Click )} - Selected favorite is null");
                return;
            }

            Favorite?newFavorite = null;

            if (_selectedFavoriteItem is FavoriteFolder folder)
            {
                using FavoriteFolderCreatorDialog dialog = FavoriteFolderCreatorDialog.FromFavoriteFolder(folder);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    newFavorite = dialog.ToFavoriteFolder();
                }
            }
            else if (_selectedFavoriteItem is FavoriteRepo repo)
            {
                using FavoriteRepoCreatorDialog dialog = FavoriteRepoCreatorDialog.FromFavoriteRepo(repo);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    newFavorite = dialog.ToFavoriteRepo();
                }
            }
            else if (_selectedFavoriteItem is FavoriteReposDirectory directory)
            {
                using FavoriteReposDirectoryCreatorDialog dialog = FavoriteReposDirectoryCreatorDialog.FromFavoriteReposDirectory(directory);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    newFavorite = dialog.ToFavoriteReposDirectory();
                }
            }
            else
            {
                LOG.Error($"{nameof( EditFavoriteMenuItem_Click )} - Unknown favorite type: {_selectedFavoriteItem}");
            }

            if (newFavorite != null)
            {
                if (!Favorites.Replace(_selectedFavoriteItem, newFavorite))
                {
                    LOG.Error($"{nameof( EditFavoriteMenuItem_Click )} - Failed to replace old favorite: {_selectedFavoriteItem} - {newFavorite}");
                    return;
                }

                UpdateFavoritesTree(newFavorite);
            }
        }
        private void AddFavoriteRepo(String path)
        {
            if (_favoriteRepos is null)
            {
                LOG.Error($"{nameof( AddFavoriteRepo )} - {nameof( _favoriteRepos )} has not been initialized");
                return;
            }

            if (!Git.IsInRepo(path))
            {
                LOG.Error($"{nameof( AddFavoriteRepo )} - Failed to add favorite repo: {path}");
                return;
            }

            using FavoriteRepoCreatorDialog dialog = FavoriteRepoCreatorDialog.FromRepo(path);
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                _favoriteRepos.Children.Add(dialog.ToFavoriteRepo());

                Settings.Default.FavoriteRepos = _favoriteRepos;
                Settings.Default.Save();
            }
        }