Beispiel #1
0
        /// <summary>
        /// Provide UI to add a JAR reference.
        /// </summary>
        private void AddJarReference()
        {
            // Get the current project
            var project = (IVsHierarchy)GetCurrentProject();

            using (var dialog = new AddJarReferenceDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var jarPath    = dialog.JarPath;
                    var libName    = dialog.LibraryName;
                    var importCode = dialog.ImportCode;

                    var item = BuildProject.AddItem("JarReference", jarPath).Single();
                    if (!string.IsNullOrEmpty(libName))
                    {
                        item.SetMetadataValue("LibraryName", libName);
                    }
                    if (importCode)
                    {
                        item.SetMetadataValue("ImportCode", "yes");
                    }

                    // Save project
                    BuildProject.Save();

                    // Unload the project - also saves the modifications
                    ErrorHandler.ThrowOnFailure(solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, project, 0));

                    // Reload project
                    dte.ExecuteCommand("Project.ReloadProject", "");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add jar reference
        /// </summary>
        public override void Run()
        {
            var node    = Owner as AbstractProjectBrowserTreeNode;
            var project = (node != null) ? node.Project : ProjectService.CurrentProject;

            if (project == null)
            {
                return;
            }
            LoggingService.Info("Show add jar reference dialog for " + project.FileName);
            using (var dialog = new AddJarReferenceDialog()) {
                if (dialog.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainWin32Window) == DialogResult.OK)
                {
                    var jarPath    = dialog.JarPath;
                    var libName    = dialog.LibraryName;
                    var importCode = dialog.ImportCode;

                    var item = new JarReferenceProjectItem(project, jarPath);
                    if (!string.IsNullOrEmpty(libName))
                    {
                        item.SetMetadata("LibraryName", libName);
                    }
                    if (importCode)
                    {
                        item.SetMetadata("ImportCode", "yes");
                    }
                    ProjectService.AddProjectItem(project, item);

                    project.Save();

                    ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView();
                }
            }
        }