예제 #1
0
        public MainViewModelBase(IServiceProvider serviceProvider, ITelemetryProvider telemetryProvider, ICommandProvider commands, IApplicationSettings settings, NuGetViewModel nugetViewModel)
        {
            _serviceProvider   = serviceProvider;
            _telemetryProvider = telemetryProvider;
            _commands          = commands;

            settings.LoadFrom(Path.Combine(GetDefaultDocumentPath(), ConfigFileName));
            Settings = settings;

            _telemetryProvider.Initialize(_currentVersion.ToString(), settings);
            _telemetryProvider.LastErrorChanged += () =>
            {
                OnPropertyChanged(nameof(LastError));
                OnPropertyChanged(nameof(HasError));
            };

            NuGet = nugetViewModel;
            NuGetConfiguration = new NuGetConfiguration(NuGet.GlobalPackageFolder, NuGetPathVariableName);

            NewDocumentCommand          = commands.Create(CreateNewDocument);
            OpenFileCommand             = commands.CreateAsync(OpenFile);
            CloseCurrentDocumentCommand = commands.CreateAsync(CloseCurrentDocument);
            ClearErrorCommand           = commands.Create(() => _telemetryProvider.ClearLastError());
            ReportProblemCommand        = commands.Create(ReportProblem);
            EditUserDocumentPathCommand = commands.Create(EditUserDocumentPath);
            ToggleOptimizationCommand   = commands.Create(() => settings.OptimizeCompilation = !settings.OptimizeCompilation);

            _editorFontSize = Settings.EditorFontSize;

            DocumentRoot = CreateDocumentRoot();

            OpenDocuments = new ObservableCollection <OpenDocumentViewModel>();
            OpenDocuments.CollectionChanged += (sender, args) => OnPropertyChanged(nameof(HasNoOpenDocuments));
        }
예제 #2
0
        public ICommand GetActionCommand(object action)
        {
            if (action is CodeAction codeAction)
            {
                return((ICommand)_commandProvider.CreateAsync(() => ExecuteCodeAction(codeAction)));
            }
            var codeFix = action as CodeFix;

            if (codeFix == null || codeFix.Action.HasCodeActions())
            {
                return(null);
            }
            return((ICommand)_commandProvider.CreateAsync(() => ExecuteCodeAction(codeFix.Action)));
        }
예제 #3
0
        public MainViewModel(IServiceLocator serviceLocator, ITelemetryProvider telemetryProvider, ICommandProvider commands, NuGetViewModel nugetViewModel)
        {
            _serviceLocator    = serviceLocator;
            _telemetryProvider = telemetryProvider;
            _telemetryProvider.Initialize(_currentVersion.ToString());
            _telemetryProvider.LastErrorChanged += () => OnPropertyChanged(nameof(LastError));

            NuGet = nugetViewModel;
            NuGetConfiguration = new NuGetConfiguration(NuGet.GlobalPackageFolder, NuGetPathVariableName);
            RoslynHost         = new RoslynHost(NuGetConfiguration, new[]
            {
                // TODO: xplat
                Assembly.Load("RoslynPad.Roslyn.Windows"),
                Assembly.Load("RoslynPad.Editor.Windows")
            });

            NewDocumentCommand          = commands.Create(CreateNewDocument);
            CloseCurrentDocumentCommand = commands.CreateAsync(CloseCurrentDocument);
            ClearErrorCommand           = commands.Create(() => _telemetryProvider.ClearLastError());
            ReportProblemCommand        = commands.Create(ReportProblem);
            EditUserDocumentPathCommand = commands.Create(EditUserDocumentPath);

            _editorFontSize = Properties.Settings.Default.EditorFontSize;

            DocumentRoot = CreateDocumentRoot();

            OpenDocuments = new ObservableCollection <OpenDocumentViewModel>();
            OpenDocuments.CollectionChanged += (sender, args) => OnPropertyChanged(nameof(HasNoOpenDocuments));
        }
예제 #4
0
        public NuGetDocumentViewModel(NuGetViewModel nuGetViewModel, ICommandProvider commands)
        {
            _nuGetViewModel = nuGetViewModel;

            InstallPackageCommand = commands.CreateAsync <PackageData>(InstallPackage);

            IsEnabled = true;
        }
예제 #5
0
        public OpenDocumentViewModel(IServiceLocator serviceLocator, MainViewModel mainViewModel, ICommandProvider commands)
        {
            _serviceLocator = serviceLocator;
            MainViewModel   = mainViewModel;
            CommandProvider = commands;
            NuGet           = serviceLocator.GetInstance <NuGetDocumentViewModel>();
            _dispatcher     = Dispatcher.CurrentDispatcher;

            var roslynHost = mainViewModel.RoslynHost;

            Platform       = Platform.X86;
            _executionHost = new ExecutionHost(GetHostExeName(), _workingDirectory,
                                               roslynHost.DefaultReferences.OfType <PortableExecutableReference>().Select(x => x.FilePath),
                                               roslynHost.DefaultImports, mainViewModel.NuGetConfiguration);

            SaveCommand               = commands.CreateAsync(() => Save(promptSave: false));
            RunCommand                = commands.CreateAsync(Run, () => !IsRunning);
            CompileAndSaveCommand     = commands.CreateAsync(CompileAndSave);
            RestartHostCommand        = commands.CreateAsync(RestartHost);
            FormatDocumentCommand     = commands.CreateAsync(FormatDocument);
            CommentSelectionCommand   = commands.CreateAsync(() => CommentUncommentSelection(CommentAction.Comment));
            UncommentSelectionCommand = commands.CreateAsync(() => CommentUncommentSelection(CommentAction.Uncomment));
            RenameSymbolCommand       = commands.CreateAsync(RenameSymbol);
        }