implement context menu in UEXML instead of code

This commit is contained in:
Michael Becker 2019-11-11 05:56:01 -05:00
parent 9e513cd182
commit 09e4a15671
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12
4 changed files with 249 additions and 99 deletions

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApplicationFramework>
<Commands>
<Command ID="SolutionExplorer_ContextMenu_Project_BuildProject" />
<Command ID="SolutionExplorer_ContextMenu_Project_RebuildProject" />
<Command ID="SolutionExplorer_ContextMenu_Project_CleanProject" />
<Command ID="SolutionExplorer_ContextMenu_Project_Unload" />
<Command ID="SolutionExplorer_ContextMenu_Project_RunProject" />
<Command ID="SolutionExplorer_ContextMenu_Project_DebugProject" />
<Command ID="SolutionExplorer_ContextMenu_Project_Add_NewFile" />
<Command ID="SolutionExplorer_ContextMenu_Project_Add_ExistingFiles" />
<Command ID="SolutionExplorer_ContextMenu_Project_Add_NewFolder" />
<Command ID="SolutionExplorer_ContextMenu_Project_Add">
<Items>
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_Add_NewFile" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_Add_ExistingFiles" />
<Separator />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_Add_NewFolder" />
</Items>
</Command>
<Command ID="SolutionExplorer_ContextMenu_Project">
<Items>
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_BuildProject" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_RebuildProject" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_CleanProject" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_Unload" />
<Separator />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_RunProject" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_DebugProject" />
<Separator />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Project_Add" />
<Separator />
<CommandReference CommandID="EditCut" />
<CommandReference CommandID="EditCopy" />
<CommandReference CommandID="EditPaste" />
<CommandReference CommandID="EditDelete" />
<Separator />
<CommandReference CommandID="FileProperties" />
</Items>
</Command>
<Command ID="SolutionExplorer_ContextMenu_Solution_Build" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Rebuild" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Clean" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Unload" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Run" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Debug" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Add_NewProject" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Add_ExistingProject" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Add_NewFolder" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Add">
<Items>
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Add_NewProject" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Add_ExistingProject" />
<Separator />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Add_NewFolder" />
</Items>
</Command>
<Command ID="SolutionExplorer_ContextMenu_Solution">
<Items>
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Build" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Rebuild" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Clean" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Unload" />
<Separator />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Run" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Debug" />
<Separator />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Solution_Add" />
<Separator />
<CommandReference CommandID="EditCut" />
<CommandReference CommandID="EditCopy" />
<CommandReference CommandID="EditPaste" />
<CommandReference CommandID="EditDelete" />
<Separator />
<CommandReference CommandID="FileProperties" />
</Items>
</Command>
<Command ID="SolutionExplorer_ContextMenu_File_Open" />
<Command ID="SolutionExplorer_ContextMenu_File_Rename" />
<Command ID="SolutionExplorer_ContextMenu_File">
<Items>
<CommandReference CommandID="SolutionExplorer_ContextMenu_File_Open" />
<Separator />
<CommandReference CommandID="EditCut" />
<CommandReference CommandID="EditCopy" />
<CommandReference CommandID="EditPaste" />
<CommandReference CommandID="EditDelete" />
<Separator />
<CommandReference CommandID="SolutionExplorer_ContextMenu_File_Rename" />
<Separator />
<CommandReference CommandID="FileProperties" />
</Items>
</Command>
<Command ID="SolutionExplorer_ContextMenu_Folder_Add_NewFile" />
<Command ID="SolutionExplorer_ContextMenu_Folder_Add_ExistingFiles" />
<Command ID="SolutionExplorer_ContextMenu_Folder_Add_NewFolder" />
<Command ID="SolutionExplorer_ContextMenu_Folder_Add">
<Items>
<CommandReference CommandID="SolutionExplorer_ContextMenu_Folder_Add_NewFile" />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Folder_Add_ExistingFiles" />
<Separator />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Folder_Add_NewFolder" />
</Items>
</Command>
<Command ID="SolutionExplorer_ContextMenu_Folder_Rename" />
<Command ID="SolutionExplorer_ContextMenu_Folder">
<Items>
<CommandReference CommandID="SolutionExplorer_ContextMenu_Folder_Add" />
<Separator />
<CommandReference CommandID="EditCut" />
<CommandReference CommandID="EditCopy" />
<CommandReference CommandID="EditPaste" />
<CommandReference CommandID="EditDelete" />
<Separator />
<CommandReference CommandID="SolutionExplorer_ContextMenu_Folder_Rename" />
<Separator />
<CommandReference CommandID="FileProperties" />
</Items>
</Command>
</Commands>
</ApplicationFramework>

View File

@ -0,0 +1,40 @@
<ApplicationFramework>
<Languages>
<Language ID="English">
<Commands>
<Command ID="SolutionExplorer_ContextMenu_Project_BuildProject" Title="B_uild Project" />
<Command ID="SolutionExplorer_ContextMenu_Project_RebuildProject" Title="R_ebuild Project" />
<Command ID="SolutionExplorer_ContextMenu_Project_CleanProject" Title="C_lean Project" />
<Command ID="SolutionExplorer_ContextMenu_Project_Unload" Title="Unload" />
<Command ID="SolutionExplorer_ContextMenu_Project_RunProject" Title="Run Pro_ject" />
<Command ID="SolutionExplorer_ContextMenu_Project_DebugProject" Title="_Debug Project" />
<Command ID="SolutionExplorer_ContextMenu_Project_Add_NewFile" Title="New _File..." />
<Command ID="SolutionExplorer_ContextMenu_Project_Add_ExistingFiles" Title="E_xisting File(s)..." />
<Command ID="SolutionExplorer_ContextMenu_Project_Add_NewFolder" Title="New Fol_der" />
<Command ID="SolutionExplorer_ContextMenu_Project_Add" Title="A_dd" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Build" Title="B_uild Solution" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Rebuild" Title="R_ebuild Solution" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Clean" Title="C_lean Solution" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Unload" Title="Unload" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Run" Title="Run Solution" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Debug" Title="_Debug Solution" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Add_NewProject" Title="New _Project..." />
<Command ID="SolutionExplorer_ContextMenu_Solution_Add_ExistingProject" Title="E_xisting Project..." />
<Command ID="SolutionExplorer_ContextMenu_Solution_Add_NewFolder" Title="New Fol_der" />
<Command ID="SolutionExplorer_ContextMenu_Solution_Add" Title="A_dd" />
<Command ID="SolutionExplorer_ContextMenu_File_Open" Title="_Open" />
<Command ID="SolutionExplorer_ContextMenu_File_Rename" Title="Rena_me" />
<Command ID="SolutionExplorer_ContextMenu_Folder_Rename" Title="Rena_me" />
<Command ID="SolutionExplorer_ContextMenu_Folder_Add_NewFile" Title="New _File..." />
<Command ID="SolutionExplorer_ContextMenu_Folder_Add_ExistingFiles" Title="E_xisting File(s)..." />
<Command ID="SolutionExplorer_ContextMenu_Folder_Add_NewFolder" Title="New Fol_der..." />
<Command ID="SolutionExplorer_ContextMenu_Folder_Add" Title="A_dd" />
</Commands>
</Language>
</Languages>
</ApplicationFramework>

View File

@ -645,6 +645,8 @@
<Content Include="Editors\Executable\Commands.uexml" />
<Content Include="Extensions\GraphicDesigner\Associations\Palette\NewWorldComputingPAL.uexml" />
<Content Include="Extensions\Microsoft\Associations\RKV.uexml" />
<Content Include="Panels\SolutionExplorer\Languages\English.uexml" />
<Content Include="Panels\SolutionExplorer\Commands.uexml" />
</ItemGroup>
<ItemGroup>
<Content Include="Configuration\Application.upl" />
@ -665,6 +667,8 @@
<Folder Include="Editors\Multimedia\Audio\Synthesized\" />
<Folder Include="Editors\Multimedia\Audio\Synthesized\PianoRoll\" />
<Folder Include="Editors\Executable\" />
<Folder Include="Panels\SolutionExplorer\" />
<Folder Include="Panels\SolutionExplorer\Languages\" />
</ItemGroup>
<ItemGroup>
<Content Include="Extensions\SoftwareDeveloper\Templates\Project\Software Development\Arduino\Images\Blink.xcf" />

View File

@ -139,11 +139,6 @@ namespace UniversalEditor.UserInterface.Panels
}
}
private Menu mnuContextProject = null;
private Menu mnuContextSolution = null;
private Menu mnuContextFolder = null;
private Menu mnuContextFile = null;
public SolutionExplorerPanel()
{
this.Layout = new BoxLayout(Orientation.Vertical);
@ -158,91 +153,15 @@ namespace UniversalEditor.UserInterface.Panels
this.Controls.Add(tvSolutionExplorer, new BoxLayout.Constraints(true, true));
mnuContextProject = new Menu();
mnuContextProject.Items.AddRange(new MBS.Framework.UserInterface.MenuItem[]
{
new MBS.Framework.UserInterface.CommandMenuItem("B_uild Project"),
new MBS.Framework.UserInterface.CommandMenuItem("R_ebuild Project"),
new MBS.Framework.UserInterface.CommandMenuItem("C_lean Project"),
new MBS.Framework.UserInterface.CommandMenuItem("Unload"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("Run Pro_ject"),
new MBS.Framework.UserInterface.CommandMenuItem("_Debug Project"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("A_dd", new MBS.Framework.UserInterface.MenuItem[]
{
new MBS.Framework.UserInterface.CommandMenuItem("New _File..."),
new MBS.Framework.UserInterface.CommandMenuItem("E_xisting File(s)...", null, mnuContextProjectAddExistingFiles_Click)
}),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("Cu_t"),
new MBS.Framework.UserInterface.CommandMenuItem("_Copy"),
new MBS.Framework.UserInterface.CommandMenuItem("_Paste"),
new MBS.Framework.UserInterface.CommandMenuItem("_Delete"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("P_roperties...")
});
mnuContextSolution = new Menu();
mnuContextSolution.Items.AddRange(new MBS.Framework.UserInterface.MenuItem[]
{
new MBS.Framework.UserInterface.CommandMenuItem("B_uild Solution"),
new MBS.Framework.UserInterface.CommandMenuItem("R_ebuild Solution"),
new MBS.Framework.UserInterface.CommandMenuItem("C_lean Solution"),
new MBS.Framework.UserInterface.CommandMenuItem("Unload"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("Run Solution"),
new MBS.Framework.UserInterface.CommandMenuItem("_Debug Solution"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("A_dd", new MBS.Framework.UserInterface.MenuItem[]
{
new MBS.Framework.UserInterface.CommandMenuItem("New _Project...", null, mnuContextSolutionAddNewProject_Click),
new MBS.Framework.UserInterface.CommandMenuItem("E_xisting Project...", null, mnuContextSolutionAddExistingProject_Click),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("New Fol_der")
}),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("Cu_t"),
new MBS.Framework.UserInterface.CommandMenuItem("_Copy"),
new MBS.Framework.UserInterface.CommandMenuItem("_Paste"),
new MBS.Framework.UserInterface.CommandMenuItem("_Delete"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("P_roperties...")
});
mnuContextFile = new Menu();
mnuContextFile.Items.AddRange(new MBS.Framework.UserInterface.MenuItem[]
{
new MBS.Framework.UserInterface.CommandMenuItem("Open", null, mnuContextFileOpen_Click),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("Cu_t"),
new MBS.Framework.UserInterface.CommandMenuItem("_Copy"),
// new MBS.Framework.UserInterface.CommandMenuItem("_Paste"),
new MBS.Framework.UserInterface.CommandMenuItem("_Delete"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("Rena_me"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("P_roperties...")
});
mnuContextFolder = new Menu();
mnuContextFolder.Items.AddRange(new MBS.Framework.UserInterface.MenuItem[]
{
new MBS.Framework.UserInterface.CommandMenuItem("A_dd", new MBS.Framework.UserInterface.MenuItem[]
{
new MBS.Framework.UserInterface.CommandMenuItem("New _File...", null, mnuContextFolderAddNewFile_Click),
new MBS.Framework.UserInterface.CommandMenuItem("E_xisting File...", null, mnuContextFolderAddExistingFile_Click),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("New Fol_der")
}),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("Cu_t"),
new MBS.Framework.UserInterface.CommandMenuItem("_Copy"),
// new MBS.Framework.UserInterface.CommandMenuItem("_Paste"),
new MBS.Framework.UserInterface.CommandMenuItem("_Delete"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("Rena_me"),
new MBS.Framework.UserInterface.SeparatorMenuItem(),
new MBS.Framework.UserInterface.CommandMenuItem("P_roperties...")
});
Application.AttachCommandEventHandler("SolutionExplorer_ContextMenu_Project_Add_ExistingFiles", mnuContextProjectAddExistingFiles_Click);
Application.AttachCommandEventHandler("SolutionExplorer_ContextMenu_Project_Add_NewFolder", mnuContextProjectAddNewFolder_Click);
Application.AttachCommandEventHandler("SolutionExplorer_ContextMenu_Solution_Add_ExistingFiles", mnuContextSolutionAddExistingProject_Click);
Application.AttachCommandEventHandler("SolutionExplorer_ContextMenu_Solution_Add_ExistingProject", mnuContextSolutionAddExistingProject_Click);
Application.AttachCommandEventHandler("SolutionExplorer_ContextMenu_Solution_Add_NewProject", mnuContextSolutionAddNewProject_Click);
Application.AttachCommandEventHandler("SolutionExplorer_ContextMenu_File_Open", mnuContextFileOpen_Click);
Application.AttachCommandEventHandler("SolutionExplorer_ContextMenu_Folder_Add_NewFile", mnuContextFolderAddNewFile_Click);
Application.AttachCommandEventHandler("SolutionExplorer_ContextMenu_Folder_Add_ExistingFiles", mnuContextFolderAddExistingFile_Click);
Application.AttachCommandEventHandler("SolutionExplorer_ContextMenu_Folder_Add_NewFolder", mnuContextFolderAddNewFolder_Click);
}
private void mnuContextFileOpen_Click(object sender, EventArgs e)
@ -255,6 +174,27 @@ namespace UniversalEditor.UserInterface.Panels
private void mnuContextFolderAddExistingFile_Click(object sender, EventArgs e)
{
TreeModelRow row = tvSolutionExplorer.LastHitTest.Row;
if (row == null) return;
ProjectFolder fldr = row.GetExtraData<ProjectFolder>("folder");
if (fldr == null) return;
FileDialog dlg = new FileDialog();
dlg.Mode = FileDialogMode.Open;
dlg.MultiSelect = true;
if (dlg.ShowDialog() == DialogResult.OK)
{
foreach (string filename in dlg.SelectedFileNames)
{
ObjectModels.Project.ProjectFile pf = new ObjectModels.Project.ProjectFile();
pf.SourceFileName = filename;
pf.DestinationFileName = System.IO.Path.GetFileName(filename);
fldr.Files.Add(pf);
}
UpdateSolutionExplorer();
}
}
void tvSolutionExplorer_RowActivated(object sender, ListViewRowActivatedEventArgs e)
@ -282,6 +222,43 @@ namespace UniversalEditor.UserInterface.Panels
}
}
private void mnuContextProjectAddNewFolder_Click(object sender, EventArgs e)
{
TreeModelRow row = tvSolutionExplorer.LastHitTest.Row;
if (row == null) return;
ProjectObjectModel proj = row.GetExtraData<ProjectObjectModel>("project");
if (proj == null) return;
string folderName = "New folder";
ProjectFolder folder = proj.FileSystem.Folders.Add(folderName);
TreeModelRow rowFolder = new TreeModelRow();
rowFolder.RowColumns.Add(new TreeModelRowColumn(tmSolutionExplorer.Columns[0], folderName));
rowFolder.SetExtraData<ProjectFolder>("folder", folder);
row.Rows.Add(rowFolder);
UpdateSolutionExplorer();
}
private void mnuContextFolderAddNewFolder_Click(object sender, EventArgs e)
{
TreeModelRow row = tvSolutionExplorer.LastHitTest.Row;
if (row == null) return;
ProjectFolder proj = row.GetExtraData<ProjectFolder>("folder");
if (proj == null) return;
string folderName = "New folder";
ProjectFolder folder = proj.Folders.Add(folderName);
TreeModelRow rowFolder = new TreeModelRow();
rowFolder.RowColumns.Add(new TreeModelRowColumn(tmSolutionExplorer.Columns[0], folderName));
rowFolder.SetExtraData<ProjectFolder>("folder", folder);
row.Rows.Add(rowFolder);
UpdateSolutionExplorer();
}
private void mnuContextProjectAddExistingFiles_Click(object sender, EventArgs e)
{
@ -298,7 +275,7 @@ namespace UniversalEditor.UserInterface.Panels
{
foreach (string filename in dlg.SelectedFileNames)
{
ObjectModels.Project.ProjectFile pf = new ObjectModels.Project.ProjectFile();
ProjectFile pf = new ProjectFile();
pf.SourceFileName = filename;
pf.DestinationFileName = System.IO.Path.GetFileName(filename);
proj.FileSystem.Files.Add(pf);
@ -330,26 +307,26 @@ namespace UniversalEditor.UserInterface.Panels
{
if (tvSolutionExplorer.LastHitTest.Row != null)
{
ObjectModels.Project.ProjectObjectModel project = tvSolutionExplorer.LastHitTest.Row.GetExtraData<ObjectModels.Project.ProjectObjectModel>("project");
ObjectModels.Solution.SolutionObjectModel solution = tvSolutionExplorer.LastHitTest.Row.GetExtraData<ObjectModels.Solution.SolutionObjectModel>("solution");
ObjectModels.Project.ProjectFolder folder = tvSolutionExplorer.LastHitTest.Row.GetExtraData<ObjectModels.Project.ProjectFolder>("folder");
ObjectModels.Project.ProjectFile file = tvSolutionExplorer.LastHitTest.Row.GetExtraData<ObjectModels.Project.ProjectFile>("file");
ProjectObjectModel project = tvSolutionExplorer.LastHitTest.Row.GetExtraData<ProjectObjectModel>("project");
SolutionObjectModel solution = tvSolutionExplorer.LastHitTest.Row.GetExtraData<SolutionObjectModel>("solution");
ProjectFolder folder = tvSolutionExplorer.LastHitTest.Row.GetExtraData<ProjectFolder>("folder");
ProjectFile file = tvSolutionExplorer.LastHitTest.Row.GetExtraData<ProjectFile>("file");
if (project != null)
{
tvSolutionExplorer.ContextMenu = mnuContextProject;
tvSolutionExplorer.ContextMenuCommandID = "SolutionExplorer_ContextMenu_Project";
}
else if (solution != null)
{
tvSolutionExplorer.ContextMenu = mnuContextSolution;
tvSolutionExplorer.ContextMenuCommandID = "SolutionExplorer_ContextMenu_Solution";
}
else if (folder != null)
{
tvSolutionExplorer.ContextMenu = mnuContextFolder;
tvSolutionExplorer.ContextMenuCommandID = "SolutionExplorer_ContextMenu_Folder";
}
else if (file != null)
{
tvSolutionExplorer.ContextMenu = mnuContextFile;
tvSolutionExplorer.ContextMenuCommandID = "SolutionExplorer_ContextMenu_File";
}
}
}