Exemple #1
0
        void MainTree_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                // Get hovered node
                var n = MainTree.GetNodeAt(e.Location);
                if (n == null)
                {
                    return;
                }
                MainTree.SelectedNode = n;

                var cm = new System.Windows.Forms.ContextMenuStrip();
                // Set node tag to our node
                cm.Tag = n;

                cm.Items.Add("Rename", null, delegate(Object o, EventArgs _e)
                {
                    n.BeginEdit();
                });

                #region Build context menu

                #region File Node
                if (n is FileNode)
                {
                    var     fn  = n as FileNode;
                    Project prj = fn.ParentProjectNode.Project;

                    cm.Items.Add("Open", CommonIcons.open16, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.Instance.OpenFile(fn.AbsolutePath);
                    });

                    AddCutCopyPasteButtons(cm, fn, true, true, false);

                    cm.Items.Add("Exlude", null, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.FileManagement.ExludeFileFromProject(prj, fn.RelativeFilePath);
                    });

                    cm.Items.Add("Delete", CommonIcons.delete16, delegate(Object o, EventArgs _e)
                    {
                        if (Util.ShowDeleteFileDialog(fn.FileName))
                        {
                            IDEManager.FileManagement.RemoveFileFromProject(prj, fn.RelativeFilePath);
                        }
                    });

                    cm.Items.Add(new ToolStripSeparator());

                    cm.Items.Add("Open File Path", null, delegate(Object o, EventArgs _e)
                    {
                        System.Diagnostics.Process.Start("explorer", System.IO.Path.GetDirectoryName(fn.AbsolutePath));
                    });
                }
                #endregion

                #region Directory Node
                else if (n is DirectoryNode)
                {
                    var dn = n as DirectoryNode;

                    var subMenu = new ToolStripMenuItem("Add");
                    cm.Items.Add(subMenu);

                    subMenu.DropDownItems.Add("File", CommonIcons.addfile16, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.FileManagement.AddNewSourceToProject(
                            dn.ParentProjectNode.Project, dn.RelativePath);
                    });

                    subMenu.DropDownItems.Add("Directory", CommonIcons.dir, delegate(Object o, EventArgs _e)
                    {
                        IsAddingDirectory = true;
                        var nd            = new DirectoryNode("");
                        dn.Nodes.Add(nd);
                        dn.Expand();
                        nd.BeginEdit();
                    });

                    subMenu.DropDownItems.Add("Existing File", null, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.FileManagement.AddExistingSourceToProject(
                            dn.ParentProjectNode.Project, dn.RelativePath);
                    });

                    cm.Items.Add(new ToolStripSeparator());

                    cm.Items.Add("Exclude", null, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.FileManagement.ExcludeDirectoryFromProject(
                            dn.ParentProjectNode.Project, dn.RelativePath);
                    });

                    cm.Items.Add("Delete", CommonIcons.delete16, delegate(Object o, EventArgs _e)
                    {
                        if (Util.ShowDeleteFileDialog(dn.DirectoryName))
                        {
                            IDEManager.FileManagement.RemoveDirectoryFromProject(
                                dn.ParentProjectNode.Project, dn.RelativePath);
                        }
                    });

                    AddCutCopyPasteButtons(cm, dn, true, true, true);

                    cm.Items.Add(new ToolStripSeparator());

                    cm.Items.Add("Open Path", null, delegate(Object o, EventArgs _e)
                    {
                        System.Diagnostics.Process.Start("explorer", dn.AbsolutePath);
                    });
                }
                #endregion

                #region Solution Node
                else if (n is SolutionNode)
                {
                    var sln = (n as SolutionNode).Solution;

                    cm.Items.Add("Build", CommonIcons.Icons_16x16_BuildCurrentSelectedProject, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.BuildManagement.Build(sln, true);
                    });

                    cm.Items.Add("Rebuild", null, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.BuildManagement.Build(sln, false);
                    });

                    cm.Items.Add("CleanUp", null, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.BuildManagement.CleanUpOutput(sln);
                    });

                    cm.Items.Add(new ToolStripSeparator());

                    var subMenu = new ToolStripMenuItem("Add", CommonIcons.addfile16);
                    cm.Items.Add(subMenu);

                    subMenu.DropDownItems.Add("New Project", CommonIcons.prj_16, delegate(Object o, EventArgs _e)
                    {
                        var pdlg = new NewProjectDlg(NewProjectDlg.DialogMode.Add)
                        {
                            ProjectDir = sln.BaseDirectory
                        };

                        if (pdlg.ShowDialog().Value)
                        {
                            IDEManager.ProjectManagement.AddNewProjectToSolution(
                                sln,
                                pdlg.SelectedLanguageBinding,
                                pdlg.SelectedProjectType,
                                pdlg.ProjectName,
                                pdlg.ProjectDir);
                        }
                    });

                    subMenu.DropDownItems.Add("Existing Project", null, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.ProjectManagement.AddExistingProjectToSolution(sln);
                    });

                    cm.Items.Add("Project Dependencies", null, delegate(Object o, EventArgs _e)
                    {
                        IDEManager.ProjectManagement.ShowProjectDependenciesDialog(sln);
                    });

                    AddCutCopyPasteButtons(cm, n as PrjExplorerNode, false, false, true);

                    cm.Items.Add(new ToolStripSeparator());

                    cm.Items.Add("Open File Path", null, delegate(Object o, EventArgs _e)
                    {
                        System.Diagnostics.Process.Start("explorer", System.IO.Path.GetDirectoryName(sln.FileName));
                    });
                }
                #endregion

                #region Project Node
                else if (n is ProjectNode)
                {
                    var pn = n as ProjectNode;

                    if (pn.IsUnloaded)
                    {
                        cm.Items.Add("Load", CommonIcons.Refresh, delegate(Object o, EventArgs _e)
                        {
                            var prjFile = pn.AbsolutePath;

                            if (string.IsNullOrEmpty(prjFile))
                            {
                                prjFile = pn.Solution.ToAbsoluteFileName(pn.Text);
                            }

                            var prj = Project.LoadProjectFromFile(pn.Solution, prjFile);
                            if (prj != null)
                            {
                                Update();
                            }
                        });

                        AddCutCopyPasteButtons(cm, pn, true, false, false);

                        cm.Items.Add(new ToolStripSeparator());

                        cm.Items.Add("Exclude", CommonIcons.delete16, delegate(Object o, EventArgs _e)
                        {
                            if (MessageBox.Show("Continue with excluding project?", "Excluding project", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                            {
                                IDEManager.ProjectManagement.ExcludeProject(pn.Solution, pn.AbsolutePath);
                            }
                        });
                    }
                    else
                    {
                        var prj = pn.Project;

                        cm.Items.Add("Build", CommonIcons.Icons_16x16_BuildCurrentSelectedProject, delegate(Object o, EventArgs _e)
                        {
                            IDEManager.BuildManagement.Build(prj, true);
                        });

                        cm.Items.Add("Rebuild", null, delegate(Object o, EventArgs _e)
                        {
                            IDEManager.BuildManagement.Build(prj, false);
                        });

                        cm.Items.Add("CleanUp", null, delegate(Object o, EventArgs _e)
                        {
                            IDEManager.BuildManagement.CleanUpOutput(prj);
                        });

                        cm.Items.Add(new ToolStripSeparator());

                        var subMenu = new ToolStripMenuItem("Add");
                        cm.Items.Add(subMenu);

                        subMenu.DropDownItems.Add("File", CommonIcons.addfile16, delegate(Object o, EventArgs _e)
                        {
                            IDEManager.FileManagement.AddNewSourceToProject(prj, "");
                        });

                        subMenu.DropDownItems.Add("Directory", CommonIcons.dir, delegate(Object o, EventArgs _e)
                        {
                            IsAddingDirectory = true;
                            var nd            = new DirectoryNode("");
                            n.Nodes.Add(nd);
                            n.Expand();
                            nd.BeginEdit();
                        });

                        subMenu.DropDownItems.Add("Existing File", null, delegate(Object o, EventArgs _e)
                        {
                            IDEManager.FileManagement.AddExistingSourceToProject(prj, "");
                        });

                        cm.Items.Add("Project Dependencies", null, delegate(Object o, EventArgs _e)
                        {
                            IDEManager.ProjectManagement.ShowProjectDependenciesDialog(prj);
                        });

                        AddCutCopyPasteButtons(cm, pn, true, false, true);

                        cm.Items.Add(new ToolStripSeparator());

                        cm.Items.Add("Unload", null, delegate(Object o, EventArgs _e)
                        {
                            IDEManager.ProjectManagement.UnloadProject(prj);
                            Update();
                        });

                        cm.Items.Add("Exclude", CommonIcons.delete16, delegate(Object o, EventArgs _e)
                        {
                            if (MessageBox.Show("Continue with excluding project?", "Excluding project", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                            {
                                IDEManager.ProjectManagement.ExcludeProject(prj);
                            }
                        });

                        cm.Items.Add(new ToolStripSeparator());

                        cm.Items.Add("Open File Path", null, delegate(Object o, EventArgs _e)
                        {
                            System.Diagnostics.Process.Start("explorer", prj.BaseDirectory);
                        });

                        cm.Items.Add("Properties", CommonIcons.properties16, delegate(Object o, EventArgs _e)
                        {
                            IDEManager.ProjectManagement.ShowProjectPropertiesDialog(prj);
                        });
                    }
                }
                #endregion

                #endregion

                // Show it
                cm.Show(MainTree, e.Location);
            }
        }
		void MainTree_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right)
			{
				// Get hovered node
				var n = MainTree.GetNodeAt(e.Location);
				if (n == null) return;
				MainTree.SelectedNode = n;

				var cm = new System.Windows.Forms.ContextMenuStrip();
				// Set node tag to our node
				cm.Tag = n;

				cm.Items.Add("Rename", null, delegate(Object o, EventArgs _e)
				{
					n.BeginEdit();
				});

				#region Build context menu

				#region File Node
				if (n is FileNode)
				{
					var fn = n as FileNode;
					Project prj = fn.ParentProjectNode.Project;

					cm.Items.Add("Open", CommonIcons.open16, delegate(Object o, EventArgs _e)
					{
						IDEManager.Instance.OpenFile(fn.AbsolutePath);
					});

					AddCutCopyPasteButtons(cm, fn, true, true, false);

					cm.Items.Add("Exlude", null, delegate(Object o, EventArgs _e)
					{
						IDEManager.FileManagement.ExludeFileFromProject(prj, fn.RelativeFilePath);
					});

					cm.Items.Add("Delete", CommonIcons.delete16, delegate(Object o, EventArgs _e)
					{
						if(Util.ShowDeleteFileDialog(fn.FileName))
							IDEManager.FileManagement.RemoveFileFromProject(prj, fn.RelativeFilePath);
					});

					cm.Items.Add(new ToolStripSeparator());

					cm.Items.Add("Open File Path", null, delegate(Object o, EventArgs _e)
					{
						System.Diagnostics.Process.Start("explorer",System.IO.Path.GetDirectoryName( fn.AbsolutePath));
					});
				}
				#endregion

				#region Directory Node
				else if (n is DirectoryNode)
				{
					var dn = n as DirectoryNode;

					var subMenu = new ToolStripMenuItem("Add");
					cm.Items.Add(subMenu);

					subMenu.DropDownItems.Add("File", CommonIcons.addfile16, delegate(Object o, EventArgs _e)
					{
						IDEManager.FileManagement.AddNewSourceToProject(
							dn.ParentProjectNode.Project, dn.RelativePath);
					});

					subMenu.DropDownItems.Add("Directory", CommonIcons.dir, delegate(Object o, EventArgs _e)
					{
						IsAddingDirectory = true;
						var nd = new DirectoryNode("");
						dn.Nodes.Add(nd);
						dn.Expand();
						nd.BeginEdit();
					});

					subMenu.DropDownItems.Add("Existing File", null, delegate(Object o, EventArgs _e)
					{
						IDEManager.FileManagement.AddExistingSourceToProject(
							dn.ParentProjectNode.Project, dn.RelativePath);
					});

					cm.Items.Add(new ToolStripSeparator());

					cm.Items.Add("Exclude", null, delegate(Object o, EventArgs _e)
					{
						IDEManager.FileManagement.ExcludeDirectoryFromProject(
							dn.ParentProjectNode.Project, dn.RelativePath);
					});

					cm.Items.Add("Delete", CommonIcons.delete16, delegate(Object o, EventArgs _e)
					{
						if (Util.ShowDeleteFileDialog(dn.DirectoryName))
						IDEManager.FileManagement.RemoveDirectoryFromProject(
							dn.ParentProjectNode.Project, dn.RelativePath);
					});

					AddCutCopyPasteButtons(cm, dn, true, true, true);

					cm.Items.Add(new ToolStripSeparator());

					cm.Items.Add("Open Path", null, delegate(Object o, EventArgs _e)
					{
						System.Diagnostics.Process.Start("explorer", dn.AbsolutePath);
					});
				}
				#endregion

				#region Solution Node
				else if (n is SolutionNode)
				{
					var sln = (n as SolutionNode).Solution;

					cm.Items.Add("Build", CommonIcons.Icons_16x16_BuildCurrentSelectedProject, delegate(Object o, EventArgs _e)
					{
						IDEManager.BuildManagement.Build(sln, true);
					});

					cm.Items.Add("Rebuild", null, delegate(Object o, EventArgs _e)
					{
						IDEManager.BuildManagement.Build(sln, false);
					});

					cm.Items.Add("CleanUp", null, delegate(Object o, EventArgs _e)
					{
						IDEManager.BuildManagement.CleanUpOutput(sln);
					});

					cm.Items.Add(new ToolStripSeparator());

					var subMenu = new ToolStripMenuItem("Add", CommonIcons.addfile16);
					cm.Items.Add(subMenu);

					subMenu.DropDownItems.Add("New Project", CommonIcons.prj_16, delegate(Object o, EventArgs _e)
					{
						var pdlg = new NewProjectDlg(NewProjectDlg.DialogMode.Add) { ProjectDir = sln.BaseDirectory };

						if (pdlg.ShowDialog().Value)
							IDEManager.ProjectManagement.AddNewProjectToSolution(
							sln,
							pdlg.SelectedLanguageBinding,
							pdlg.SelectedProjectType,
							pdlg.ProjectName,
							pdlg.ProjectDir);
					});

					subMenu.DropDownItems.Add("Existing Project", null, delegate(Object o, EventArgs _e)
					{
						IDEManager.ProjectManagement.AddExistingProjectToSolution(sln);
					});

					cm.Items.Add("Project Dependencies", null, delegate(Object o, EventArgs _e)
					{
						IDEManager.ProjectManagement.ShowProjectDependenciesDialog(sln);
					});

					AddCutCopyPasteButtons(cm, n as PrjExplorerNode, false, false, true);

					cm.Items.Add(new ToolStripSeparator());

					cm.Items.Add("Open File Path", null, delegate(Object o, EventArgs _e)
					{
						System.Diagnostics.Process.Start("explorer", System.IO.Path.GetDirectoryName(sln.FileName));
					});
				}
				#endregion

				#region Project Node
				else if (n is ProjectNode)
				{
					var pn = n as ProjectNode;

					if (pn.IsUnloaded)
					{
						cm.Items.Add("Load", CommonIcons.Refresh, delegate(Object o, EventArgs _e)
						{
							var prjFile=pn.AbsolutePath;

							if (string.IsNullOrEmpty(prjFile))
								prjFile = pn.Solution.ToAbsoluteFileName(pn.Text);

							var prj =Project.LoadProjectFromFile(pn.Solution,prjFile);
							if (prj!=null)
									Update();
						});

						AddCutCopyPasteButtons(cm, pn, true, false, false);

						cm.Items.Add(new ToolStripSeparator());

						cm.Items.Add("Exclude", CommonIcons.delete16, delegate(Object o, EventArgs _e)
						{
							if(MessageBox.Show("Continue with excluding project?","Excluding project",MessageBoxButtons.YesNo,MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button2)==DialogResult.Yes)
								IDEManager.ProjectManagement.ExcludeProject(pn.Solution,pn.AbsolutePath);
						});
					}
					else
					{
						var prj = pn.Project;

						cm.Items.Add("Build", CommonIcons.Icons_16x16_BuildCurrentSelectedProject, delegate(Object o, EventArgs _e)
						{
							IDEManager.BuildManagement.Build(prj, true);
						});

						cm.Items.Add("Rebuild", null, delegate(Object o, EventArgs _e)
						{
							IDEManager.BuildManagement.Build(prj, false);
						});

						cm.Items.Add("CleanUp", null, delegate(Object o, EventArgs _e)
						{
							IDEManager.BuildManagement.CleanUpOutput(prj);
						});

						cm.Items.Add(new ToolStripSeparator());

						var subMenu = new ToolStripMenuItem("Add");
						cm.Items.Add(subMenu);

						subMenu.DropDownItems.Add("File", CommonIcons.addfile16, delegate(Object o, EventArgs _e)
						{
							IDEManager.FileManagement.AddNewSourceToProject(prj, "");
						});

						subMenu.DropDownItems.Add("Directory", CommonIcons.dir, delegate(Object o, EventArgs _e)
						{
							IsAddingDirectory = true;
							var nd = new DirectoryNode("");
							n.Nodes.Add(nd);
							n.Expand();
							nd.BeginEdit();
						});

						subMenu.DropDownItems.Add("Existing File", null, delegate(Object o, EventArgs _e)
						{
							IDEManager.FileManagement.AddExistingSourceToProject(prj, "");
						});

						cm.Items.Add("Project Dependencies", null, delegate(Object o, EventArgs _e)
						{
							IDEManager.ProjectManagement.ShowProjectDependenciesDialog(prj);
						});

						AddCutCopyPasteButtons(cm, pn, true, false, true);

						cm.Items.Add(new ToolStripSeparator());

						cm.Items.Add("Unload", null, delegate(Object o, EventArgs _e)
						{
							IDEManager.ProjectManagement.UnloadProject(prj);
							Update();
						});

						cm.Items.Add("Exclude", CommonIcons.delete16, delegate(Object o, EventArgs _e)
						{
							if (MessageBox.Show("Continue with excluding project?", "Excluding project", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
							IDEManager.ProjectManagement.ExcludeProject(prj);
						});

						cm.Items.Add(new ToolStripSeparator());

						cm.Items.Add("Open File Path", null, delegate(Object o, EventArgs _e)
						{
							System.Diagnostics.Process.Start("explorer", prj.BaseDirectory);
						});

						cm.Items.Add("Properties", CommonIcons.properties16, delegate(Object o, EventArgs _e)
						{
							IDEManager.ProjectManagement.ShowProjectPropertiesDialog(prj);
						});
					}
				}
				#endregion

				#endregion

				// Show it
				cm.Show(MainTree, e.Location);
			}
		}