Browse Source

Cppbinding build events project options.

Application icon selection in the application options tab.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4440 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Tomasz Tretkowski 17 years ago
parent
commit
1a024d1b97
  1. 6
      src/AddIns/BackendBindings/CppBinding/CppBinding/CppBinding.addin
  2. 2
      src/AddIns/BackendBindings/CppBinding/CppBinding/CppBinding.csproj
  3. 90
      src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.cs
  4. 33
      src/AddIns/BackendBindings/CppBinding/CppBinding/Project/BuildEventOptions.cs
  5. 3
      src/AddIns/BackendBindings/CppBinding/CppBinding/Project/CppProject.cs
  6. 3
      src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ObservedBinding.cs
  7. 159
      src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ResourceScript.cs
  8. 5
      src/AddIns/BackendBindings/CppBinding/CppBinding/Templates/ConsoleProject.xpt
  9. 2
      src/Main/Base/Project/Src/Project/Solution/Solution.cs

6
src/AddIns/BackendBindings/CppBinding/CppBinding/CppBinding.addin

@ -22,15 +22,15 @@ @@ -22,15 +22,15 @@
<OptionPanel id = "Linker"
label = "${res:ICSharpCode.CppBinding.ProjectOptions.Linker}"
class = "ICSharpCode.CppBinding.Project.LinkerOptions" />
<OptionPanel id = "BuildEvents"
label = "${res:Dialog.ProjectOptions.BuildEvents}"
class = "ICSharpCode.CppBinding.Project.BuildEventOptions"/>
<!--<OptionPanel id = "ReferencePaths"
label = "${res:Dialog.ProjectOptions.ReferencePaths}"
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.ReferencePaths"/>
<OptionPanel id = "Signing"
label = "${res:Dialog.ProjectOptions.Signing}"
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.Signing"/>
<OptionPanel id = "BuildEvents"
label = "${res:Dialog.ProjectOptions.BuildEvents}"
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.BuildEvents"/>
<OptionPanel id = "DebugOptions"
label = "${res:Dialog.ProjectOptions.DebugOptions}"
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.DebugOptions"/>/-->

2
src/AddIns/BackendBindings/CppBinding/CppBinding/CppBinding.csproj

@ -67,6 +67,7 @@ @@ -67,6 +67,7 @@
<Compile Include="Project\ApplicationOptions.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Project\BuildEventOptions.cs" />
<Compile Include="Project\LinkerOptions.cs">
<SubType>UserControl</SubType>
</Compile>
@ -77,6 +78,7 @@ @@ -77,6 +78,7 @@
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Project\ProjectConfigurationProjectItem.cs" />
<Compile Include="Project\ResourceScript.cs" />
<Compile Include="Project\SpecifyCliRuntimeLibraryCommand.cs" />
<Compile Include="Project\CppProject.cs" />
<Compile Include="Project\StringListEditorDialog.cs">

90
src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ApplicationOptions.cs

@ -7,10 +7,14 @@ @@ -7,10 +7,14 @@
* Do zmiany tego szablonu użyj Narzędzia | Opcje | Kodowanie | Edycja Nagłówków Standardowych.
*/
using System;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.Core;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.CppBinding.Project
{
/// <summary>
@ -29,6 +33,13 @@ namespace ICSharpCode.CppBinding.Project @@ -29,6 +33,13 @@ namespace ICSharpCode.CppBinding.Project
string configurationType = project.GetEvaluatedProperty("ConfigurationType");
OutputType validOutputType = ConfigurationTypeToOutputType(configurationType, subsystem);
cbOutputType.SelectedIndex = Array.IndexOf((OutputType[])Enum.GetValues(typeof(OutputType)), validOutputType);
TextBox tbApplicationIcon = Get<TextBox>("applicationIcon");
helper.AddBinding(null, new ObservedBinding<object, TextBox>(tbApplicationIcon, SetApplicationIcon));
tbApplicationIcon.Text = GetApplicationIconPathFromResourceScripts();
DisableWin32ResourceOptions();
IsDirty = false;
}
@ -86,9 +97,82 @@ namespace ICSharpCode.CppBinding.Project @@ -86,9 +97,82 @@ namespace ICSharpCode.CppBinding.Project
return OutputType.WinExe;
else if ("DynamicLibrary" == configurationType)
return OutputType.Library;
LoggingService.Info("ConfigurationType " +configurationType + " are not supported, will use Library output type");
LoggingService.Info("ConfigurationType " +configurationType + " is not supported, will use Library output type");
return OutputType.Library;
}
#endregion
#region Application icon property mapping
const string DEFAULT_ICON_ID = "ICON0";
const string DEFAULT_RC_NAME = "app.rc";
ResourceEntry foundIconEntry;
string iconResourceScriptPath; //path to the resource script where application icon is defined
static string AddResourceScriptToProject(IProject project, string rcFileName) {
string fileName = Path.Combine(project.Directory, rcFileName);
FileProjectItem rcFileItem = new FileProjectItem(project, project.GetDefaultItemType(fileName));
rcFileItem.Include = FileUtility.GetRelativePath(project.Directory, fileName);
((IProjectItemListProvider)project).AddProjectItem(rcFileItem);
return fileName;
}
/// <summary>
/// Gets the icon file location from the rc files added to project.
/// Searches all project items of type "ResourceCompile" and returns the resource of type ICON with the lowest ID.
/// </summary>
/// <returns>path to the icon file or null if the icon wasn't specified</returns>
string GetApplicationIconPathFromResourceScripts() {
foundIconEntry = null;
iconResourceScriptPath = null;
IEnumerable <ProjectItem> resourceScripts = project.Items.Where(
item => item is FileProjectItem && ((FileProjectItem)item).BuildAction == "ResourceCompile");
foreach (ProjectItem item in resourceScripts) {
ResourceScript rc = new ResourceScript(item.FileName);
if (rc.Icons.Count == 0) continue;
if (foundIconEntry == null || rc.Icons.First().ResourceID.CompareTo(foundIconEntry.ResourceID)<0) {
foundIconEntry = rc.Icons.First();
iconResourceScriptPath = item.FileName;
}
}
//when no icon was found, then select the resource script where icon definition may be created
if (iconResourceScriptPath == null && resourceScripts.Any())
iconResourceScriptPath = resourceScripts.First().FileName;
return foundIconEntry != null ? foundIconEntry.Data : null;
}
object SetApplicationIcon(TextBox tb) {
string iconPath = tb.Text;
string newIconId;
ResourceScript rc;
if (iconPath.Trim() == "") return null;
if (iconResourceScriptPath != null)
{
rc = new ResourceScript(iconResourceScriptPath);
newIconId = foundIconEntry != null ? foundIconEntry.ResourceID : DEFAULT_ICON_ID;
rc.Save(iconResourceScriptPath);
}
else
{
iconResourceScriptPath = AddResourceScriptToProject(project, DEFAULT_RC_NAME);
rc = new ResourceScript();
newIconId = DEFAULT_ICON_ID;
}
rc.SetIcon(newIconId, iconPath);
rc.Save(iconResourceScriptPath);
return null;
}
#endregion
#region Resource file property mapping
void DisableWin32ResourceOptions() {
Button win32ResourceFileBrowseButton = Get<Button>("win32ResourceFileBrowse");
win32ResourceFileBrowseButton.Enabled = false;
TextBox win32ResourceFileTextBox = Get<TextBox>("win32ResourceFile");
win32ResourceFileTextBox.Enabled = false;
}
#endregion
}
}

33
src/AddIns/BackendBindings/CppBinding/CppBinding/Project/BuildEventOptions.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
/*
* Utworzone przez SharpDevelop.
* Użytkownik: trecio
* Data: 2009-07-14
* Godzina: 14:34
*
* Do zmiany tego szablonu użyj Narzędzia | Opcje | Kodowanie | Edycja Nagłówków Standardowych.
*/
using System;
using System.Windows.Forms;
namespace ICSharpCode.CppBinding.Project
{
/// <summary>
/// Description of BuildEventOptions.
/// </summary>
public class BuildEventOptions : ICSharpCode.SharpDevelop.Gui.OptionPanels.BuildEvents
{
public override void LoadPanelContents()
{
base.LoadPanelContents();
TextBox preBuildEventTextBox = Get<TextBox>("preBuildEvent");
helper.AddBinding(null, new ItemDefinitionGroupBinding<TextBox>(preBuildEventTextBox, "PreBuildEvent", "Command"));
TextBox postBuildEventTextBox = Get<TextBox>("postBuildEvent");
helper.AddBinding(null, new ItemDefinitionGroupBinding<TextBox>(postBuildEventTextBox, "PostBuildEvent", "Command"));
ComboBox runPostBuildEventComboBox = Get<ComboBox>("runPostBuildEvent");
runPostBuildEventComboBox.Enabled = false;
}
}
}

3
src/AddIns/BackendBindings/CppBinding/CppBinding/Project/CppProject.cs

@ -66,12 +66,15 @@ namespace ICSharpCode.CppBinding.Project @@ -66,12 +66,15 @@ namespace ICSharpCode.CppBinding.Project
public override ItemType GetDefaultItemType(string fileName)
{
const string RESOURCE_COMPILE = "ResourceCompile";
string extension = Path.GetExtension(fileName).ToLower();
switch (extension) {
case ".cpp": return ItemType.ClCompile;
case ".c": return ItemType.ClCompile;
case ".hpp": return ItemType.ClInclude;
case ".h": return ItemType.ClInclude;
case ".rc": return new ItemType(RESOURCE_COMPILE);
}
return base.GetDefaultItemType(fileName);
}

3
src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ObservedBinding.cs

@ -31,7 +31,10 @@ namespace ICSharpCode.CppBinding.Project @@ -31,7 +31,10 @@ namespace ICSharpCode.CppBinding.Project
public override bool Save()
{
if (onSave != null)
if (Property != null)
base.Set<Output>(onSave(control));
else
onSave(control);
return true;
}

159
src/AddIns/BackendBindings/CppBinding/CppBinding/Project/ResourceScript.cs

@ -0,0 +1,159 @@ @@ -0,0 +1,159 @@
/*
* Utworzone przez SharpDevelop.
* Użytkownik: trecio
* Data: 2009-07-13
* Godzina: 16:51
*
* Do zmiany tego szablonu użyj Narzędzia | Opcje | Kodowanie | Edycja Nagłówków Standardowych.
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace ICSharpCode.CppBinding.Project
{
/// <summary>
/// Resource script (.rc) files handling.
/// </summary>
public class ResourceScript
{
/// <summary>
/// Creates a new empty resource script.
/// </summary>
public ResourceScript()
{
}
/// <summary>
/// Creates the object representing a file on disk
/// </summary>
public ResourceScript(string fileName)
{
using (FileStream inStream = new FileStream(fileName, FileMode.Open)) {
Load(inStream);
}
}
public ResourceEntry AddIcon(string resourceId, string iconPath) {
ResourceIcon iconEntry = new ResourceIcon(resourceId, iconPath, lines.Count);
Icons.Add(iconEntry);
lines.Add(iconEntry);
return iconEntry;
}
public void SetIcon(string resourceId, string newPath) {
ResourceIcon iconEntry = (ResourceIcon)Icons.Where(
icon => icon.ResourceID == resourceId).SingleOrDefault();
if (iconEntry != null)
iconEntry.Data = newPath;
else
AddIcon(resourceId, newPath);
}
/// <summary>
/// List of icons defined in the resource script in ascending order of their ID's.
/// WARNING: this should be a read-only dictionary, do not modify it. Use Add/SetIcon methods instead.
/// </summary>
public ISet<ResourceEntry> Icons {
get {
return icons;
}
}
/// <summary>
/// Very simplified resource script parsing. Only the icon data is needed, and other lines should be preserved.
/// We expect no comments in the line that contains the icon definition (perhaps this should be changed).
/// </summary>
public void Load(Stream inStream) {
Regex iconMatch = new Regex("\\s*(\\w+)\\s+ICON\\s+\"([^\"]+)\"", RegexOptions.IgnoreCase);
lines.Clear();
using (StreamReader sr = new StreamReader(inStream)) {
string line;
ResourceEntry lineEntry;
while ((line = sr.ReadLine())!=null) {
Match m;
if ((m = iconMatch.Match(line)).Success) {
lineEntry = new ResourceIcon(m.Groups[1].Value, m.Groups[2].Value, lines.Count);
icons.Add(lineEntry);
} else {
lineEntry =new ResourceEntry(null, null, line, lines.Count);
}
lines.Add(lineEntry);
}
}
}
public void Save(string fileName) {
using (FileStream outStream = new FileStream(fileName, FileMode.Create)) {
Save(outStream);
}
}
/// <summary>
/// Writes resource script to a stream.
/// </summary>
public void Save(Stream outStream) {
using (StreamWriter sw = new StreamWriter(outStream)) {
foreach (ResourceEntry s in lines)
sw.WriteLine(s.ToWritableText());
}
}
ISet<ResourceEntry> icons = new SortedSet<ResourceEntry>(new ResourceEntry.ResourceIdCompared());
IList<ResourceEntry> lines = new List<ResourceEntry>();
}
public class ResourceEntry {
internal ResourceEntry(string entryType, string resourceId, string data)
: this(entryType, resourceId, data, -1)
{
}
internal ResourceEntry(string entryType, string resourceId, string data, int line) {
this.EntryType = entryType;
this.ResourceID = resourceId;
this.Data = data;
this.Line = line;
}
public readonly string EntryType;
public string Data {get; set;}
public int Line{get; private set;}
public string ResourceID {get; private set;}
public virtual string ToWritableText() {
return Data;
}
public class ResourceIdCompared : IComparer<ResourceEntry>
{
#region IComparer<ResourceEntry> Members
public int Compare(ResourceEntry x, ResourceEntry y)
{
return String.Compare(x.ResourceID, y.ResourceID);
}
#endregion
}
}
class ResourceIcon : ResourceEntry {
public ResourceIcon(string resourceId, string iconPath)
: this(resourceId, iconPath, -1)
{
}
public ResourceIcon(string resourceId, string iconPath, int line)
: base("ICON", resourceId, iconPath, line)
{
}
public override string ToWritableText() {
return String.Format("{0}\tICON\t\"{1}\"", ResourceID, Data);
}
}
}

5
src/AddIns/BackendBindings/CppBinding/CppBinding/Templates/ConsoleProject.xpt

@ -43,6 +43,11 @@ int main(array<System::String ^> ^args) @@ -43,6 +43,11 @@ int main(array<System::String ^> ^args)
}
]]></File>
<File name="AssemblyInfo.cpp" src="DefaultAssemblyInfo.cpp"/>
<File name="app.rc"><![CDATA[
// Standard resource script. Created with SharpDevelop.
//
]]></File>
</Files>
</Project>
</Template>

2
src/Main/Base/Project/Src/Project/Solution/Solution.cs

@ -683,7 +683,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -683,7 +683,7 @@ namespace ICSharpCode.SharpDevelop.Project
string key = configuration + "|" + platform;
configurations.Add(key);
string searchKey = guid + "." + key + ".ActiveCfg";
string searchKey = guid + "." + key + ".Build.0";
if (!prjSec.Items.Exists(item => item.Name == searchKey)) {
prjSec.Items.Add(new SolutionItem(searchKey, key));
changed = true;

Loading…
Cancel
Save