Skip to content

Commit

Permalink
Manual merge from branch v1_0 to trunk
Browse files Browse the repository at this point in the history
git-svn-id: https://fsprojectextender.svn.codeplex.com/svn@44045 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5
  • Loading branch information
SND\svlasova_cp authored and SND\svlasova_cp committed May 4, 2010
1 parent 16bc975 commit c429fde
Show file tree
Hide file tree
Showing 48 changed files with 1,944 additions and 167 deletions.
115 changes: 63 additions & 52 deletions trunk/ProjectExtender/Commands/ProjectExtender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Xml;
using System.Runtime.InteropServices;
using OleConstants = Microsoft.VisualStudio.OLE.Interop.Constants;
using Microsoft.Build.BuildEngine;
using Microsoft.VisualStudio.FSharp.ProjectSystem;

namespace FSharp.ProjectExtender.Commands
{
Expand All @@ -22,7 +24,7 @@ public ProjectExtender()

private const string enable_extender_text = "Enable F# project extender";
private const string disable_extender_text = "Disable F# project extender";
private const string disable_warning = "For projects with subdirectories disabling extender can produce a project file incompatible with the F# project system.\n Press OK to proceed or Cancel to cancel";
private const string disable_warning = "For projects with subdirectories it may or may not be possible to keep compilation order as defined in the extender.\n\n Press OK to proceed or Cancel to cancel";

/// <summary>
/// Modifies caption on the project extender command
Expand Down Expand Up @@ -66,18 +68,15 @@ private static void Execute(object sender, EventArgs e)
/// </summary>
/// <param name="vsProject">project to be modified</param>
/// <param name="effector"></param>
private static void ModifyProject(IVsProject vsProject, Action<XmlDocument> effector)
private static void ModifyProject(IVsProject vsProject, Func<string, string> effector)
{
var project = GlobalServices.getFSharpProjectNode(vsProject);
var MSBuildProject = project.BuildProject;

// method get_XmlDocument on the MSBuild project is internal
// We will have to use reflection to call it
var minfo = typeof(Microsoft.Build.BuildEngine.Project)
.GetMethod("get_XmlDocument", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

// apply modifications to XML
effector((XmlDocument)minfo.Invoke(MSBuildProject, new object[] { }));
set_ProjectTypeGuids(
project,
effector(
get_ProjectTypeGuids(project)
));

// Set dirty flag to true to force project save
project.SetProjectFileDirty(true);
Expand All @@ -89,62 +88,74 @@ private static void ModifyProject(IVsProject vsProject, Action<XmlDocument> effe
GlobalServices.dte.ExecuteCommand("Project.ReloadProject", "");
}

private const string msBuildNamespace = "http://schemas.microsoft.com/developer/msbuild/2003";
private static XmlNamespaceManager namespace_manager = NamespaceManager();
private static string get_ProjectTypeGuids(ProjectNode project)
{
#if VS2008
foreach (BuildPropertyGroup group in project.BuildProject.PropertyGroups)
{
foreach (BuildProperty property in group)
{
if (property.Name == "ProjectTypeGuids")
{
group.RemoveProperty(property);
return property.Value;
}
}
}
return null;
#elif VS2010
var property = project.BuildProject.Properties.FirstOrDefault(prop => prop.Name == "ProjectTypeGuids");
if (property == null)
return null;
return property.EvaluatedValue;
#endif
}

private static XmlNamespaceManager NamespaceManager()
private static void set_ProjectTypeGuids(ProjectNode project, string value)
{
var result = new XmlNamespaceManager(new NameTable());
result.AddNamespace("default", msBuildNamespace);
return result;
#if VS2008
foreach (BuildPropertyGroup group in project.BuildProject.PropertyGroups)
{
foreach (BuildProperty property in group)
{
if (property.Name == "ProjectGuid")
{
group.AddNewProperty("ProjectTypeGuids", value);
return;
}
}
}
#elif VS2010
project.BuildProject.Xml.AddProperty("ProjectTypeGuids", value);
#endif
}

/// <summary>
/// Modifies the XML to enable the extender
/// </summary>
/// <param name="project"></param>
private static void enable_extender(XmlDocument project)
private static string enable_extender(string old_types)
{
// Locate the ProjectTypeGuids node
var projectTypeGuids = project.SelectSingleNode("//default:Project/default:PropertyGroup/default:ProjectTypeGuids", namespace_manager);
if (projectTypeGuids == null)
{
// Not found - create a new one
projectTypeGuids = project.CreateElement("ProjectTypeGuids", msBuildNamespace);
var projectGuid = project.SelectSingleNode("//default:Project/default:PropertyGroup/default:ProjectGuid", namespace_manager);
// insert it after the ProjectGuid node
projectGuid.ParentNode.InsertAfter(projectTypeGuids, projectGuid);
// initialize the project type guid list
projectTypeGuids.InnerText = "{" + Constants.guidProjectExtenderFactoryString + "};{" + Constants.guidFSharpProjectString + "}";
}
else
{
// parse the existing guid list
var types = new List<string>(projectTypeGuids.InnerText.Split(';'));
if (old_types == null)
return "{" + Constants.guidProjectExtenderFactoryString + "};{" + Constants.guidFSharpProjectString + "}";

// prepend the guid list with the extender project type
types.Insert(0, '{' + Constants.guidProjectExtenderFactoryString + '}');
// parse the existing guid list
var types = new List<string>(old_types.Split(';'));

// format the guid list
var typestring = "";
types.ForEach(type => typestring += ';' + type);
// replace the guid list
projectTypeGuids.InnerText = typestring.Substring(1);
}
// prepend the guid list with the extender project type
types.Insert(0, '{' + Constants.guidProjectExtenderFactoryString + '}');

// format the guid list
var typestring = "";
types.ForEach(type => typestring += ';' + type);

return typestring.Substring(1);
}

/// <summary>
/// Modifies XML to disable extender
/// </summary>
/// <param name="project"></param>
private static void disable_extender(XmlDocument project)
private static string disable_extender(string old_types)
{
// locate the ProjectTypeGuids node
var projectTypeGuids = project.SelectSingleNode("//default:Project/default:PropertyGroup/default:ProjectTypeGuids", namespace_manager);
// remove the extender guid from the list
if (projectTypeGuids != null)
projectTypeGuids.InnerText =
projectTypeGuids.InnerText.Replace('{' + Constants.guidProjectExtenderFactoryString + "};", "");
return old_types.Replace('{' + Constants.guidProjectExtenderFactoryString + "};", "");
}

}
}
46 changes: 24 additions & 22 deletions trunk/ProjectExtender/CompileOrderDialog/Viewer.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
using FSharp.ProjectExtender.Project;
using Microsoft.Build.BuildEngine;

namespace FSharp.ProjectExtender
{
public partial class CompileOrderViewer : UserControl
{
IProjectManager project;

public CompileOrderViewer(IProjectManager project)
{
this.project = project;
Expand All @@ -30,21 +33,22 @@ public TreeView CompileItemsTree
public void refresh_file_list()
{
CompileItems.Nodes.Clear();
foreach (BuildElement element in
project.BuildManager.GetElements(item => item.Name == "Compile"))
foreach (IBuildItem element in project.BuildItems)
{
TreeNode compileItem = new TreeNode(element.Path);
compileItem.Tag = element;
//compileItem.ContextMenuStrip = compileItemMenu;
BuildDependencies(compileItem);
CompileItems.Nodes.Add(compileItem);
}
if (element.Type != "Compile")
continue;
TreeNode compileItem = new TreeNode(element.Include);
compileItem.Tag = project.Items[project.ProjectDir + "\\" + element.Include];
//compileItem.ContextMenuStrip = compileItemMenu;
BuildDependencies(compileItem);
CompileItems.Nodes.Add(compileItem);
}
}

private void BuildDependencies(TreeNode node)
{
node.Nodes.Clear();
string dependencies = ((BuildElement)node.Tag).GetDependencies();
string dependencies = ((ShadowFileNode)node.Tag).GetDependencies();
if (dependencies != null)
foreach (var d in dependencies.Split(','))
if (d != "")
Expand Down Expand Up @@ -72,16 +76,16 @@ private void compileItemMenu_Click(object sender, EventArgs e)
{
if (origin.Node != n)
addForm.Dependencies.Items.Add(n.Tag);
if (((BuildElement)origin.Node.Tag).GetDependencies().IndexOf(n.Tag.ToString()) >= 0)
if (((ShadowFileNode)origin.Node.Tag).GetDependencies().IndexOf(n.Tag.ToString()) >= 0)
addForm.Dependencies.SetItemChecked(addForm.Dependencies.Items.Count - 1, true);
}
if (addForm.ShowDialog() == DialogResult.OK)
{
List<BuildElement> dependencies = new List<BuildElement>();
foreach (BuildElement item in addForm.Dependencies.CheckedItems)
var dependencies = new List<ShadowFileNode>();
foreach (ShadowFileNode item in addForm.Dependencies.CheckedItems)
dependencies.Add(item);

((BuildElement)origin.Node.Tag).UpdateDependencies(dependencies);
((ShadowFileNode)origin.Node.Tag).UpdateDependencies(dependencies);
BuildDependencies(origin.Node);
}
addForm.Dispose();
Expand All @@ -90,24 +94,22 @@ private void compileItemMenu_Click(object sender, EventArgs e)
private void MoveUp_Click(object sender, EventArgs e)
{
if (CompileItems.SelectedNode != null)
MoveElement(CompileItems.SelectedNode, Direction.Up);
MoveElement(CompileItems.SelectedNode, ShadowFileNode.Direction.Up);
}


private void MoveDown_Click(object sender, EventArgs e)
{
if (CompileItems.SelectedNode != null)
MoveElement(CompileItems.SelectedNode, Direction.Down);
MoveElement(CompileItems.SelectedNode, ShadowFileNode.Direction.Down);
}

public enum Direction { Up, Down }

/// <summary>
/// Moves a compile item in the compilation order list one position up or down
/// </summary>
/// <param name="n">item to move</param>
/// <param name="dir">direction</param>
private void MoveElement(TreeNode n, Direction dir)
private void MoveElement(TreeNode n, ShadowFileNode.Direction dir)
{
if (!CompileItems.Nodes.Contains(n))
return;
Expand All @@ -116,12 +118,12 @@ private void MoveElement(TreeNode n, Direction dir)
int new_index = 0;
switch (dir)
{
case Direction.Up:
case ShadowFileNode.Direction.Up:
if (n.Index <= 0) // already at the top - nowehere to go up
return;
new_index = n.Index - 1;
break;
case Direction.Down:
case ShadowFileNode.Direction.Down:
if (n.Index >= CompileItems.Nodes.Count - 1) // already at the bottom - nowehere to go down
return;
new_index = n.Index + 1;
Expand All @@ -130,7 +132,7 @@ private void MoveElement(TreeNode n, Direction dir)
if (OnPageUpdated != null)
OnPageUpdated(this, EventArgs.Empty);

((BuildElement)n.Tag).SwapWith((BuildElement)CompileItems.Nodes[new_index].Tag);
((Project.ShadowFileNode)n.Tag).SwapWith((Project.ShadowFileNode)CompileItems.Nodes[new_index].Tag);

// Update the UI (the TreeView)
CompileItems.Nodes.Remove(n);
Expand Down
2 changes: 2 additions & 0 deletions trunk/ProjectExtender/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static class Constants

public const uint cmdidExploreFolderInWindows = 0x663;
public const uint cmdidNewFolder = 0xf5;

public const string moveByTag = "move-by";

public enum ImageName
{
Expand Down
5 changes: 3 additions & 2 deletions trunk/ProjectExtender/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)

public int OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
{
if (pHierarchy is IProjectManager)
((IProjectManager)pHierarchy).BuildManager.FixupProject();
var project = pHierarchy as IProjectManager;
if (project != null)
project.FixupProject();
return VSConstants.S_OK;
}

Expand Down
22 changes: 22 additions & 0 deletions trunk/ProjectExtender/IProjectManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using FSharp.ProjectExtender.Project;
using System.Collections;

namespace FSharp.ProjectExtender
{
[ComVisible(true)]
public interface IProjectManager
{
Project.ItemList Items {get;}
string ProjectDir { get; set; }

IEnumerable BuildItems { get; }
void FlipShowAll();
void Refresh();
void FixupProject();
}
}
Loading

0 comments on commit c429fde

Please sign in to comment.