ManageSymbolSpecificationsDialogViewModel.cs 3.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
    internal class ManageSymbolSpecificationsDialogViewModel : AbstractNotifyPropertyChanged, IManageNamingStylesInfoDialogViewModel
    {
        private readonly INotificationService _notificationService;

        public ObservableCollection<INamingStylesInfoDialogViewModel> Items { get; set; }
        public string LanguageName { get; private set; }

        public string DialogTitle => "Manage Specifications";

        public ManageSymbolSpecificationsDialogViewModel(
            ObservableCollection<SymbolSpecification> specifications, 
            List<NamingStyleOptionPageViewModel.NamingRuleViewModel> namingRules, 
            string languageName,
            INotificationService notificationService)
        {
            LanguageName = languageName;
            _notificationService = notificationService;

            Items = new ObservableCollection<INamingStylesInfoDialogViewModel>(specifications.Select(specification => new SymbolSpecificationViewModel(
                languageName,
                specification,
                !namingRules.Any(rule => rule.SelectedSpecification?.ID == specification.ID),
                notificationService)));
        }

        internal void AddSymbolSpecification(INamingStylesInfoDialogViewModel symbolSpecification)
        {
            
        }

        internal void RemoveSymbolSpecification(INamingStylesInfoDialogViewModel symbolSpecification)
        {
            Items.Remove(symbolSpecification);
        }

        public void AddItem()
        {
            var viewModel = new SymbolSpecificationViewModel(LanguageName, canBeDeleted: true, notificationService: _notificationService);
            var dialog = new SymbolSpecificationDialog(viewModel);
            if (dialog.ShowDialog().Value == true)
            {
                Items.Add(viewModel);
            }
        }

        public void RemoveItem(INamingStylesInfoDialogViewModel item)
        {
            Items.Remove(item);
        }

        public void EditItem(INamingStylesInfoDialogViewModel item)
        {
            var symbolSpecificationViewModel = (SymbolSpecificationViewModel)item;

            var symbolSpecification = ((SymbolSpecificationViewModel)item).GetSymbolSpecification();
            var viewModel = new SymbolSpecificationViewModel(LanguageName, symbolSpecification, symbolSpecificationViewModel.CanBeDeleted, _notificationService);
            var dialog = new SymbolSpecificationDialog(viewModel);
            if (dialog.ShowDialog().Value == true)
            {
                symbolSpecificationViewModel.ItemName = viewModel.ItemName;
                symbolSpecificationViewModel.AccessibilityList = viewModel.AccessibilityList;
                symbolSpecificationViewModel.ModifierList = viewModel.ModifierList;
                symbolSpecificationViewModel.SymbolKindList = viewModel.SymbolKindList;
            }
        }
    }
}