From e52deb92490e653dc5ef550c612d91bd8995c05e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 27 Sep 2007 17:57:48 +0000 Subject: [PATCH] Support embedding the .manifest in the .exe. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2697 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../src/Service/Help2RegistryWalker.cs | 27 ++-- .../Project/ICSharpCode.SharpDevelop.csproj | 1 + .../Resources/DefaultManifest.manifest | 21 +++ .../ProjectOptions/ApplicationSettings.xfrm | 143 ++++++++++-------- .../ProjectOptions/ApplicationSettings.cs | 137 +++++++++++++++-- .../ProjectOptions/ReferencePaths.cs | 2 +- .../Base/Project/Src/Project/BuildEngine.cs | 1 + .../Bookmarks/ClassMemberBookmark.cs | 2 +- 8 files changed, 239 insertions(+), 95 deletions(-) create mode 100644 src/Main/Base/Project/Resources/DefaultManifest.manifest diff --git a/src/AddIns/Misc/HtmlHelp2/Project/src/Service/Help2RegistryWalker.cs b/src/AddIns/Misc/HtmlHelp2/Project/src/Service/Help2RegistryWalker.cs index 33276f1195..3a3e8cb96a 100644 --- a/src/AddIns/Misc/HtmlHelp2/Project/src/Service/Help2RegistryWalker.cs +++ b/src/AddIns/Misc/HtmlHelp2/Project/src/Service/Help2RegistryWalker.cs @@ -143,25 +143,24 @@ namespace HtmlHelp2.Environment { registryWalker = new HxRegistryWalkerClass(); help2Namespaces = registryWalker.get_RegisteredNamespaceList(""); + + if (registryWalker == null || help2Namespaces == null || help2Namespaces.Count == 0 || string.IsNullOrEmpty(matchingName)) + { + return string.Empty; + } + foreach (IHxRegNamespace currentNamespace in help2Namespaces) + { + if (NativeMethods.PathMatchSpec(currentNamespace.Name, matchingName)) + { + return currentNamespace.Name; + } + } + return help2Namespaces.ItemAt(1).Name; } catch (System.Runtime.InteropServices.COMException) - { - help2Namespaces = null; - registryWalker = null; - } - - if (registryWalker == null || help2Namespaces == null || help2Namespaces.Count == 0 || string.IsNullOrEmpty(matchingName)) { return string.Empty; } - foreach (IHxRegNamespace currentNamespace in help2Namespaces) - { - if (NativeMethods.PathMatchSpec(currentNamespace.Name, matchingName)) - { - return currentNamespace.Name; - } - } - return help2Namespaces.ItemAt(1).Name; } } diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index a693af6c4d..4fbeb4971a 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -690,6 +690,7 @@ + diff --git a/src/Main/Base/Project/Resources/DefaultManifest.manifest b/src/Main/Base/Project/Resources/DefaultManifest.manifest new file mode 100644 index 0000000000..bfc2928d47 --- /dev/null +++ b/src/Main/Base/Project/Resources/DefaultManifest.manifest @@ -0,0 +1,21 @@ + + + + + + + + + + + diff --git a/src/Main/Base/Project/Resources/ProjectOptions/ApplicationSettings.xfrm b/src/Main/Base/Project/Resources/ProjectOptions/ApplicationSettings.xfrm index eb53c9f942..7c83116619 100644 --- a/src/Main/Base/Project/Resources/ProjectOptions/ApplicationSettings.xfrm +++ b/src/Main/Base/Project/Resources/ProjectOptions/ApplicationSettings.xfrm @@ -1,186 +1,197 @@ - + + + + + + + + + + + + + + + - + - + - + - - - + + + + - - - - + + - + + - - + - + - + - + - + - - + + + - - + - + + - + - - + - + + - + - - + - + + - - - + + - - - + + + + - - - - + + - + - - - - + + + + - + - - + + - - + - + + - - + + - + - - + - + + - - + + - - + - + + - - + - + \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.cs index 260f8706a0..14f53744b0 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.cs @@ -19,19 +19,20 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels { public class ApplicationSettings : AbstractProjectOptionPanel { + ComboBox applicationManifestComboBox; + public override void LoadPanelContents() { SetupFromXmlResource("ProjectOptions.ApplicationSettings.xfrm"); InitializeHelper(); - ConnectBrowseButton("applicationIconBrowseButton", "applicationIconComboBox", + ConnectBrowseButton("applicationIconBrowseButton", "applicationIconTextBox", "${res:SharpDevelop.FileFilter.Icons}|*.ico|${res:SharpDevelop.FileFilter.AllFiles}|*.*", TextBoxEditMode.EditEvaluatedProperty); - // TODO: Suitable file filter. - ConnectBrowseButton("win32ResourceFileBrowseButton", "win32ResourceFileComboBox", - "${res:SharpDevelop.FileFilter.AllFiles}|*.*", + ConnectBrowseButton("win32ResourceFileBrowseButton", "win32ResourceFileTextBox", + "Win32 Resource files|*.res|${res:SharpDevelop.FileFilter.AllFiles}|*.*", TextBoxEditMode.EditEvaluatedProperty); ConfigurationGuiBinding b; @@ -45,7 +46,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels b = helper.BindEnum("outputTypeComboBox", "OutputType"); locationButton = b.CreateLocationButton("outputTypeComboBox"); - Get("outputType").SelectedIndexChanged += new EventHandler(RefreshOutputNameTextBox); + Get("outputType").SelectedIndexChanged += RefreshOutputNameTextBox; + Get("outputType").SelectedIndexChanged += RefreshStartupObjectEnabled; b = helper.BindString("startupObjectComboBox", "StartupObject", TextBoxEditMode.EditEvaluatedProperty); b.RegisterLocationButton(locationButton); @@ -53,12 +55,27 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels Get("startupObject").Items.Add(c.FullyQualifiedName); } - b = helper.BindString("applicationIconComboBox", "ApplicationIcon", TextBoxEditMode.EditEvaluatedProperty); - Get("applicationIcon").TextChanged += new EventHandler(ApplicationIconComboBoxTextChanged); - b.CreateLocationButton("applicationIconComboBox"); + b = helper.BindString("applicationIconTextBox", "ApplicationIcon", TextBoxEditMode.EditEvaluatedProperty); + Get("applicationIcon").TextChanged += new EventHandler(ApplicationIconTextBoxTextChanged); + b.CreateLocationButton("applicationIconTextBox"); + + b = helper.BindString("win32ResourceFileTextBox", "Win32Resource", TextBoxEditMode.EditEvaluatedProperty); + b.CreateLocationButton("win32ResourceFileTextBox"); + + applicationManifestComboBox = Get("applicationManifest"); + applicationManifestComboBox.Items.Add("Embed default manifest"); + applicationManifestComboBox.Items.Add("Do not embed manifest"); + foreach (string fileName in Directory.GetFiles(project.Directory, "*.manifest")) { + applicationManifestComboBox.Items.Add(Path.GetFileName(fileName)); + } + applicationManifestComboBox.Items.Add(StringParser.Parse("<${res:Global.CreateButtonText}...>")); + applicationManifestComboBox.Items.Add(StringParser.Parse("<${res:Global.BrowseText}...>")); + applicationManifestComboBox.SelectedIndexChanged += ApplicationManifestComboBox_SelectedIndexChanged; - b = helper.BindString("win32ResourceFileComboBox", "Win32Resource", TextBoxEditMode.EditEvaluatedProperty); - b.CreateLocationButton("win32ResourceFileComboBox"); + b = new ManifestBinding(applicationManifestComboBox); + helper.AddBinding("ApplicationManifest", b); + b.CreateLocationButton(applicationManifestComboBox); + applicationManifestComboBox.TextChanged += delegate { helper.IsDirty = true; }; Get("projectFolder").Text = project.Directory; Get("projectFile").Text = Path.GetFileName(project.FileName); @@ -66,11 +83,99 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels // maybe make this writable again? Needs special care when saving! Get("projectFile").ReadOnly = true; + RefreshStartupObjectEnabled(null, EventArgs.Empty); RefreshOutputNameTextBox(null, EventArgs.Empty); helper.AddConfigurationSelector(this); } + void ApplicationManifestComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + if (applicationManifestComboBox.SelectedIndex == applicationManifestComboBox.Items.Count - 2) { + BeginInvoke(new MethodInvoker(CreateManifest)); + } else if (applicationManifestComboBox.SelectedIndex == applicationManifestComboBox.Items.Count - 1) { + BeginInvoke(new MethodInvoker(BrowseForManifest)); + } + } + + void BrowseForManifest() + { + applicationManifestComboBox.SelectedIndex = -1; + BrowseForFile(applicationManifestComboBox, "Manifest files|*.manifest|${res:SharpDevelop.FileFilter.AllFiles}|*.*", TextBoxEditMode.EditEvaluatedProperty); + } + + void CreateManifest() + { + string manifestFile = Path.Combine(project.Directory, "app.manifest"); + if (!File.Exists(manifestFile)) { + string defaultManifest; + using (Stream stream = typeof(ApplicationSettings).Assembly.GetManifestResourceStream("Resources.DefaultManifest.manifest")) { + if (stream == null) + throw new ResourceNotFoundException("DefaultManifest.manifest"); + using (StreamReader r = new StreamReader(stream)) { + defaultManifest = r.ReadToEnd(); + } + } + defaultManifest = defaultManifest.Replace("\t", DefaultEditor.Gui.Editor.SharpDevelopTextEditorProperties.Instance.IndentationString); + File.WriteAllText(manifestFile, defaultManifest, System.Text.Encoding.UTF8); + FileService.FireFileCreated(manifestFile); + } + + if (!project.IsFileInProject(manifestFile)) { + FileProjectItem newItem = new FileProjectItem(project, ItemType.None); + newItem.Include = "app.manifest"; + ProjectService.AddProjectItem(project, newItem); + ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView(); + } + + FileService.OpenFile(manifestFile); + + applicationManifestComboBox.Text = "app.manifest"; + } + + sealed class ManifestBinding : ConfigurationGuiBinding + { + ComboBox applicationManifestComboBox; + + public ManifestBinding(ComboBox applicationManifestComboBox) + { + this.applicationManifestComboBox = applicationManifestComboBox; + } + + public override void Load() + { + string manifestFileName = Get(""); + if (string.IsNullOrEmpty(manifestFileName)) { + if (Helper.GetProperty("NoWin32Manifest", false, true)) { + // no manifest + applicationManifestComboBox.SelectedIndex = 1; + } else { + // default manifest + applicationManifestComboBox.SelectedIndex = 0; + } + } else { + applicationManifestComboBox.Text = manifestFileName; + } + } + + public override bool Save() + { + if (applicationManifestComboBox.SelectedIndex == 0) { + // Embed default manifest + Set(""); + Helper.SetProperty("NoWin32Manifest", "", true, this.Location); + } else if (applicationManifestComboBox.SelectedIndex == 1) { + // No manifest + Set(""); + Helper.SetProperty("NoWin32Manifest", true, true, this.Location); + } else { + Set(applicationManifestComboBox.Text); + Helper.SetProperty("NoWin32Manifest", "", true, this.Location); + } + return true; + } + } + public static IList GetPossibleStartupObjects(IProject project) { List results = new List(); @@ -87,16 +192,22 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels return results; } + void RefreshStartupObjectEnabled(object sender, EventArgs e) + { + bool isLibrary = OutputType.Library == (OutputType)Get("outputType").SelectedIndex; + ControlDictionary["startupObjectComboBox"].Enabled = !isLibrary; + } + void RefreshOutputNameTextBox(object sender, EventArgs e) { Get("outputName").Text = Get("assemblyName").Text + CompilableProject.GetExtension((OutputType)Get("outputType").SelectedIndex); } - void ApplicationIconComboBoxTextChanged(object sender, EventArgs e) + void ApplicationIconTextBoxTextChanged(object sender, EventArgs e) { - if(FileUtility.IsValidPath(Get("applicationIcon").Text)) + if(FileUtility.IsValidPath(Get("applicationIcon").Text)) { - string applicationIcon = Path.Combine(baseDirectory, Get("applicationIcon").Text); + string applicationIcon = Path.Combine(baseDirectory, Get("applicationIcon").Text); if (File.Exists(applicationIcon)) { try { Get("applicationIcon").Image = Image.FromFile(applicationIcon); diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.cs index 7b28b615b7..75c16e580f 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.cs @@ -31,7 +31,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels helper.AddConfigurationSelector(this); } - public class SemicolonSeparatedStringListBinding : ConfigurationGuiBinding + sealed class SemicolonSeparatedStringListBinding : ConfigurationGuiBinding { StringListEditor editor; diff --git a/src/Main/Base/Project/Src/Project/BuildEngine.cs b/src/Main/Base/Project/Src/Project/BuildEngine.cs index 61e2e1a34d..3ede76a367 100644 --- a/src/Main/Base/Project/Src/Project/BuildEngine.cs +++ b/src/Main/Base/Project/Src/Project/BuildEngine.cs @@ -30,6 +30,7 @@ namespace ICSharpCode.SharpDevelop.Project results.Result = BuildResultCode.MSBuildAlreadyRunning; options.Callback(results); } else { + guiBuildRunning = true; Gui.WorkbenchSingleton.Workbench.GetPad(typeof(Gui.CompilerMessageView)).BringPadToFront(); StartBuild(project, options, new MessageViewSink(TaskService.BuildMessageViewCategory)); } diff --git a/src/Main/Base/Project/Src/TextEditor/Bookmarks/ClassMemberBookmark.cs b/src/Main/Base/Project/Src/TextEditor/Bookmarks/ClassMemberBookmark.cs index 5a8db7a0b0..a6f92a39ae 100644 --- a/src/Main/Base/Project/Src/TextEditor/Bookmarks/ClassMemberBookmark.cs +++ b/src/Main/Base/Project/Src/TextEditor/Bookmarks/ClassMemberBookmark.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.SharpDevelop.Bookmarks } public ClassMemberBookmark(IDocument document, IMember member) - : base(document, member.Region.BeginLine - 1) + : base(document, Math.Min(document.TotalNumberOfLines - 1, member.Region.BeginLine - 1)) { this.member = member; }