Ejemplo n.º 1
0
        public InstallDialog(InstallDialogViewModel viewModel)
        {
            InitializeComponent();
            DataContext = viewModel;

            Loaded += OnLoaded;
        }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            Icon  = BitmapFrame.Create(new Uri("pack://application:,,,/LibraryInstaller.Vsix;component/Resources/dialog-icon.png", UriKind.RelativeOrAbsolute));
            Title = Vsix.Name;

            cbName.Focus();

            ViewModel = new InstallDialogViewModel(Dispatcher, CloseDialog);
        }
Ejemplo n.º 3
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            Icon  = WpfUtil.GetIconForImageMoniker(KnownMonikers.JSWebScript, 16, 16);
            Title = Vsix.Name;

            ViewModel = new InstallDialogViewModel(Dispatcher, _configFileName, _deps, _folder, CloseDialog);

            FocusManager.SetFocusedElement(cbName, cbName);
        }
Ejemplo n.º 4
0
        private void TargetLocation_Loaded(object sender, RoutedEventArgs e)
        {
            InstallDialogViewModel viewModel = ((InstallDialog)Window.GetWindow(this)).ViewModel;

            _libraryNameChange = viewModel.LibraryNameChange;
            _libraryNameChange.PropertyChanged += this.LibraryNameChanged;

            Window window = Window.GetWindow(TargetLocationSearchTextBox);

            // Simple hack to make the popup dock to the textbox, so that the popup will be repositioned whenever
            // the dialog is dragged or resized.
            // In the below section, we will bump up the HorizontalOffset property of the popup whenever the dialog window
            // location is changed or window is resized so that the popup gets repositioned.
            if (window != null)
            {
                window.LocationChanged += RepositionPopup;
                window.SizeChanged     += RepositionPopup;
            }
        }
        public void GetLibraryTextToBeInserted_BasicProperties()
        {
            var installState = new LibraryInstallationState
            {
                ProviderId = "cdnjs",
                Name       = "jquery",
                Version    = "3.3.1",
            };

            string resultString = InstallDialogViewModel.GetLibraryTextToBeInserted(installState, _manifest);

            var expectedObj = new
            {
                provider = "cdnjs",
                library  = "[email protected]",
            };
            string expected = JsonConvert.SerializeObject(expectedObj, _jsonSettings);

            Assert.AreEqual(expected, resultString);
        }
Ejemplo n.º 6
0
        private async Task ExecuteAsync(object sender, EventArgs e)
        {
            Telemetry.TrackUserTask("Execute-InstallLibraryCommand");

            ProjectItem item = await VsHelpers.GetSelectedItemAsync().ConfigureAwait(false);

            Project project = await VsHelpers.GetProjectOfSelectedItemAsync().ConfigureAwait(false);

            if (project != null)
            {
                string rootFolder = await project.GetRootFolderAsync().ConfigureAwait(false);

                string        configFilePath = Path.Combine(rootFolder, Constants.ConfigFileName);
                IDependencies dependencies   = _dependenciesFactory.FromConfigFile(configFilePath);

                Manifest manifest = await GetManifestAsync(configFilePath, dependencies).ConfigureAwait(false);

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                // If the manifest contains errors, we will not invoke the "Add Client-Side libraries" dialog
                // Instead we will display a message box indicating the syntax errors in manifest file.
                if (manifest == null)
                {
                    IVsUIShell shell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;
                    int        result;

                    shell.ShowMessageBox(dwCompRole: 0,
                                         rclsidComp: Guid.Empty,
                                         pszTitle: null,
                                         pszText: PredefinedErrors.ManifestMalformed().Message,
                                         pszHelpFile: null,
                                         dwHelpContextID: 0,
                                         msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                         msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                         msgicon: OLEMSGICON.OLEMSGICON_WARNING,
                                         fSysAlert: 0,
                                         pnResult: out result);

                    return;
                }

                string target = string.Empty;

                // Install command was invoked from a folder.
                // So the initial target location should be name of the folder from which
                // the command was invoked.
                if (item != null)
                {
                    target = item.FileNames[1];
                }
                else
                {
                    // Install command was invoked from project scope.
                    // If wwwroot exists, initial target location should be - wwwroot/lib.
                    // Else, target location should be - lib
                    if (Directory.Exists(Path.Combine(rootFolder, "wwwroot")))
                    {
                        target = Path.Combine(rootFolder, "wwwroot", "lib") + Path.DirectorySeparatorChar;
                    }
                    else
                    {
                        target = Path.Combine(rootFolder, "lib") + Path.DirectorySeparatorChar;
                    }
                }

                string initialTargetLocation = CalculateSuggestedInstallPath(target, rootFolder);


                var selectedProviderBinding = new SelectedProviderBinding();
                var libraryIdViewModel      = new LibraryIdViewModel(new ProviderCatalogSearchService(() => selectedProviderBinding.SelectedProvider),
                                                                     string.Empty);

                var libraryNameBinding      = new LibraryNameBinding();
                var targetLocationViewModel = new TargetLocationViewModel(initialTargetLocation,
                                                                          libraryNameBinding,
                                                                          new LocationSearchService(dependencies.GetHostInteractions()));

                var dialogViewModel = new InstallDialogViewModel(
                    _libraryCommandService,
                    configFilePath,
                    dependencies,
                    libraryIdViewModel,
                    targetLocationViewModel,
                    selectedProviderBinding,
                    libraryNameBinding,
                    target,
                    project);

                var dialog = new UI.InstallDialog(dialogViewModel);
                dialog.ShowModal();

                Telemetry.TrackUserTask("Open-InstallDialog");
            }
        }
Ejemplo n.º 7
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            ViewModel = new InstallDialogViewModel(Dispatcher, _libraryCommandService, _configFileName, _deps, _fullPath, CloseDialog, _project);

            FocusManager.SetFocusedElement(LibrarySearchBox, LibrarySearchBox);
        }