1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Diagnostics;
10
using ICSharpCode.Core;
11
using ICSharpCode.SharpDevelop.Gui;
12
using ICSharpCode.SharpDevelop.Project.Dialogs;
13
using Microsoft.Win32;
15
namespace ICSharpCode.SharpDevelop.Project.Commands
17
public class ViewProjectOptions : AbstractMenuCommand
19
public override void Run()
21
ShowProjectOptions(ProjectService.CurrentProject);
24
public static void ShowProjectOptions(IProject project)
26
if (project == null) {
29
foreach (IViewContent viewContent in WorkbenchSingleton.Workbench.ViewContentCollection) {
30
ProjectOptionsView projectOptions = viewContent as ProjectOptionsView;
31
if (projectOptions != null && projectOptions.Project == project) {
32
projectOptions.WorkbenchWindow.SelectWindow();
37
AddInTreeNode projectOptionsNode = AddInTree.GetTreeNode("/SharpDevelop/BackendBindings/ProjectOptions/" + project.Language);
38
ProjectOptionsView projectOptions = new ProjectOptionsView(projectOptionsNode, project);
39
WorkbenchSingleton.Workbench.ShowView(projectOptions);
40
} catch (TreePathNotFoundException) {
41
MessageService.ShowError("${res:Dialog.ProjectOptions.NoPanelsInstalledForProject}");
46
public class GenerateProjectDocumentation : AbstractMenuCommand
48
static string[] registryKeys = new string[] {
49
@"HKEY_CLASSES_ROOT\Sandcastle Help File Builder Project\shell\open\command",
50
@"HKEY_CLASSES_ROOT\SandcastleBuilder.shfbproj\shell\open\command"
53
static string FindSHFB()
55
string envVar = Environment.GetEnvironmentVariable("SHFBROOT");
56
if (!string.IsNullOrEmpty(envVar)) {
57
return Path.Combine(envVar, "SandcastleBuilderGUI.exe");
59
foreach (string registryKey in registryKeys) {
60
string fileName = FindSHFB(registryKey);
61
if (fileName != null) {
68
static string FindSHFB(string registryKey)
70
string command = Registry.GetValue(registryKey, null, string.Empty) as string;
71
return ExtractExecutableFromCommand(command);
74
static string ExtractExecutableFromCommand(string command)
76
if (string.IsNullOrEmpty(command))
78
command = command.Trim();
79
if (string.IsNullOrEmpty(command))
81
if (command[0] == '"') {
83
int pos = command.IndexOf('"', 1);
86
return command.Substring(1, pos - 1);
89
int pos = command.IndexOf(' ');
93
return command.Substring(0, pos);
97
public override void Run()
99
CompilableProject project = ProjectService.CurrentProject as CompilableProject;
100
if (project == null) {
103
string sandcastleHelpFileBuilderPath = FindSHFB();
104
if (sandcastleHelpFileBuilderPath == null || !File.Exists(sandcastleHelpFileBuilderPath)) {
105
using (ToolNotFoundDialog dlg = new ToolNotFoundDialog(
106
StringParser.Parse("${res:ProjectComponent.ContextMenu.GenerateDocumentation.SHFBNotFound}"),
107
"http://www.codeplex.com/SHFB/", null))
109
dlg.ShowDialog(WorkbenchSingleton.MainWin32Window);
114
string assembly = project.OutputAssemblyFullPath;
115
string xmlDocFile = project.DocumentationFileFullPath;
116
if (xmlDocFile == null) {
117
MessageService.ShowMessage("${res:ProjectComponent.ContextMenu.GenerateDocumentation.NeedToEditBuildOptions}");
120
if (!File.Exists(assembly)) {
121
MessageService.ShowMessage("${res:ProjectComponent.ContextMenu.GenerateDocumentation.ProjectNeedsToBeCompiled}");
124
if (!File.Exists(xmlDocFile)) {
125
MessageService.ShowMessage("${res:ProjectComponent.ContextMenu.GenerateDocumentation.ProjectNeedsToBeCompiled2}");
128
string sandcastleHelpFileBuilderProjectFile = Path.ChangeExtension(project.FileName, ".shfbproj");
129
if (!File.Exists(sandcastleHelpFileBuilderProjectFile)) {
130
using (XmlTextWriter w = new XmlTextWriter(sandcastleHelpFileBuilderProjectFile, Encoding.UTF8)) {
131
w.Formatting = Formatting.Indented;
132
const string ns = "http://schemas.microsoft.com/developer/msbuild/2003";
133
w.WriteStartElement("Project", ns);
134
w.WriteAttributeString("DefaultTargets", "Build");
135
w.WriteAttributeString("ToolsVersion", "3.5");
137
w.WriteStartElement("PropertyGroup", ns);
138
w.WriteComment("The configuration and platform will be used to determine which\n" +
139
"assemblies to include from solution and project documentation\n" +
141
w.WriteStartElement("Configuration", ns);
142
w.WriteAttributeString("Condition", " '$(Configuration)' == '' ");
143
w.WriteValue("Debug");
144
w.WriteEndElement(); // </Configuration>
146
w.WriteStartElement("Platform", ns);
147
w.WriteAttributeString("Condition", " '$(Platform)' == '' ");
148
w.WriteValue("AnyCPU");
149
w.WriteEndElement(); // </AnyCPU>
151
w.WriteElementString("SchemaVersion", ns, "2.0");
152
w.WriteElementString("ProjectGuid", ns, Guid.NewGuid().ToString("B"));
153
w.WriteElementString("SHFBSchemaVersion", ns, "1.8.0.3");
155
w.WriteElementString("AssemblyName", ns, "Documentation");
156
w.WriteElementString("RootNamespace", ns, "Documentation");
157
w.WriteElementString("Name", ns, "Documentation");
159
w.WriteElementString("OutputPath", ns, @".\Help\");
160
w.WriteElementString("HtmlHelpName", ns, "Documentation");
162
w.WriteStartElement("DocumentationSources", ns);
163
w.WriteStartElement("DocumentationSource", "");
164
w.WriteAttributeString("sourceFile", FileUtility.GetRelativePath(Path.GetDirectoryName(sandcastleHelpFileBuilderProjectFile), project.FileName));
165
w.WriteEndElement(); // </DocumentationSource>
166
w.WriteEndElement(); // </DocumentationSources>
168
w.WriteEndElement(); // </PropertyGrup>
170
w.WriteComment("There are no properties for these groups. AnyCPU needs to appear in\n" +
171
"order for Visual Studio to perform the build. The others are optional\n" +
172
"common platform types that may appear.");
173
string[] confPlatList = {
174
"Debug|AnyCPU", "Release|AnyCPU", "Debug|x86", "Release|x86", "Debug|x64", "Release|x64", "Debug|Win32", "Release|Win32"
176
foreach (string confPlat in confPlatList) {
177
w.WriteStartElement("PropertyGroup", ns);
178
w.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == '" + confPlat + "' ");
179
w.WriteEndElement(); // </PropertyGrup>
182
w.WriteComment("Import the SHFB build targets");
183
w.WriteStartElement("Import", ns);
184
w.WriteAttributeString("Project", @"$(SHFBROOT)\SandcastleHelpFileBuilder.targets");
185
w.WriteEndElement(); // </Import>
187
w.WriteEndElement(); // </Project>
191
ProcessStartInfo psi = new ProcessStartInfo(sandcastleHelpFileBuilderPath, '"' + sandcastleHelpFileBuilderProjectFile + '"');
192
psi.WorkingDirectory = Path.GetDirectoryName(sandcastleHelpFileBuilderPath);
193
psi.UseShellExecute = false;
199
/// Opens the projects output folder in an explorer window.
201
public class OpenProjectFolder : AbstractMenuCommand
203
public override void Run()
205
IProject project = ProjectService.CurrentProject;
206
if (project == null) {
210
OpenFolder.OpenFolderInExplorer(project.Directory);
215
/// Opens the projects output folder in an explorer window.
217
public class OpenProjectOutputFolder : AbstractMenuCommand
219
public override void Run()
221
CompilableProject project = ProjectService.CurrentProject as CompilableProject;
222
if (project == null) {
226
// Explorer does not handle relative paths as a command line argument properly
227
string outputFolder = project.OutputFullPath;
228
if (!Directory.Exists(outputFolder)) {
229
Directory.CreateDirectory(outputFolder);
232
OpenFolder.OpenFolderInExplorer(outputFolder);