Skip to content

Commit

Permalink
register context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 13, 2023
1 parent a12bcd5 commit c86c041
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/OneWare.ProjectExplorer/ViewModels/ProjectExplorerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ProjectExplorerViewModel : ProjectViewModelBase, IProjectExplorerSe

private IProjectRoot? _activeProject;

private readonly List<Func<IList<IProjectEntry>, IEnumerable<IMenuItem>?>> _registerContextMenu = new();

private IEnumerable<IMenuItem>? _treeViewContextMenu;

public IEnumerable<IMenuItem>? TreeViewContextMenu
Expand All @@ -56,9 +58,6 @@ public IProjectRoot? ActiveProject
}
}

public ICommand? DoubleTabCommand { get; protected set; }
public Action<Action<string>>? RequestRename { get; set; }

public event EventHandler<IFile>? FileRemoved;
public event EventHandler<IProjectRoot>? ProjectRemoved;

Expand Down Expand Up @@ -162,6 +161,11 @@ public void ConstructContextMenu(TopLevel topLevel)
break;
}

foreach (var reg in _registerContextMenu)
{
if(reg.Invoke(SelectedItems) is {} items) menuItems.AddRange(items);
}

if (manager != null) menuItems.AddRange(manager.ConstructContextMenu(entry));

if (entry is IProjectRoot root)
Expand Down Expand Up @@ -797,6 +801,11 @@ public async Task OpenLastProjectsFileAsync()
}
}

public void RegisterContextMenu(Func<IList<IProjectEntry>, IEnumerable<IMenuItem>?> construct)
{
_registerContextMenu.Add(construct);
}

private class ProjectSerialization
{
public string ProjectType { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/OneWare.Shared/Services/IProjectExplorerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public interface IProjectExplorerService : IDockable, INotifyPropertyChanged
public Task SaveProjectAsync(IProjectRoot project);
public Task SaveLastProjectsFileAsync();
public Task OpenLastProjectsFileAsync();
public void RegisterContextMenu(Func<IList<IProjectEntry>, IEnumerable<IMenuItem>?> construct);
}
18 changes: 17 additions & 1 deletion src/OneWare.Vhdl/VhdlModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OneWare.Shared.Services;
using OneWare.Shared.Models;
using OneWare.Shared.Services;
using OneWare.UniversalFpgaProjectSystem.Services;
using OneWare.Vhdl.Parsing;
using Prism.Ioc;
Expand All @@ -20,5 +21,20 @@ public void OnInitialized(IContainerProvider containerProvider)
containerProvider.Resolve<ILanguageManager>().RegisterService(typeof(LanguageServiceVhdl),true, ".vhd", ".vhdl");

containerProvider.Resolve<NodeProviderService>().RegisterNodeProvider(new VhdlNodeProvider(), ".vhd", ".vhdl");

containerProvider.Resolve<IProjectExplorerService>().RegisterContextMenu(x =>
{
if (x.Count == 1 && x.First() is IProjectFile { Extension: ".vhd" or ".vhdl" })
{
return new[]
{
new MenuItemModel("Test")
{
Header = "Test"
}
};
}
return null;
});
}
}

0 comments on commit c86c041

Please sign in to comment.