in sources/Google.Solutions.IapDesktop.Application/ToolWindows/ProjectExplorer/ProjectExplorerView.cs [95:277]
public void Bind(
ProjectExplorerViewModel viewModel,
IBindingContext bindingContext)
{
this.viewModel.Value = viewModel;
//
// Bind tree view.
//
this.treeView.BindChildren(node => node.GetFilteredChildrenAsync(false));
this.treeView.BindImageIndex(node => node.ImageIndex);
this.treeView.BindSelectedImageIndex(node => node.ImageIndex);
this.treeView.BindIsExpanded(node => node.IsExpanded);
this.treeView.BindIsLeaf(node => node.IsLeaf);
this.treeView.BindText(node => node.Text);
this.treeView.Bind(viewModel.RootNode, bindingContext);
this.treeView.OnControlPropertyChange(
c => c.SelectedModelNode,
node => viewModel.SelectedNode = node,
bindingContext);
this.treeView.LoadingChildrenFailed += (sender, args) =>
{
if (!args.Exception.IsCancellation())
{
this.exceptionDialog.Show(
this,
"Loading project failed", args.Exception);
}
};
//
// Bind search box and progress bar.
//
var searchButton = this.searchTextBox.AddOverlayButton(Resources.Search_16);
this.progressBar.BindProperty(
c => c.Enabled,
viewModel,
m => m.IsLoading,
bindingContext);
this.progressBar.BindProperty(
c => c.Visible,
viewModel,
m => m.IsLoading,
bindingContext);
this.searchTextBox.BindProperty(
c => c.Text,
viewModel,
m => m.InstanceFilter,
bindingContext);
//
// Menus.
//
var contextSource = new ContextSource<IProjectModelNode>();
viewModel.OnPropertyChange(
m => m.SelectedNode,
node =>
{
//
// NB. Due to lazily loading, the model might not
// be available yet.
//
if (node != null && node.IsLoaded)
{
contextSource.Context = node.ModelNode;
}
},
bindingContext);
this.contextMenuCommands.Value = new CommandContainer<IProjectModelNode>(
ToolStripItemDisplayStyle.ImageAndText,
contextSource,
bindingContext);
this.toolbarCommands.Value = new CommandContainer<IProjectModelNode>(
ToolStripItemDisplayStyle.Image,
contextSource,
bindingContext);
//
// Toolbar.
//
this.linuxInstancesToolStripMenuItem.BindProperty(
c => c.Checked,
viewModel,
m => m.IsLinuxIncluded,
bindingContext);
this.windowsInstancesToolStripMenuItem.BindProperty(
c => c.Checked,
viewModel,
m => m.IsWindowsIncluded,
bindingContext);
this.refreshButton.BindObservableCommand(
viewModel,
m => m.RefreshSelectedNodeCommand,
bindingContext);
//
// Context menu.
//
this.contextMenuCommands.Value.AddCommand(
new ContextCommand<IProjectModelNode>(
"&Unload projects...",
node => node is IProjectModelCloudNode
? CommandState.Enabled
: CommandState.Unavailable,
_ => UnloadProjectsAsync())
{
Id = "UnloadProject",
ActivityText = "Unloading projects"
});
this.contextMenuCommands.Value.AddCommand(
new ContextCommand<IProjectModelNode>(
"&Refresh project",
_ => viewModel.IsRefreshProjectsCommandVisible
? CommandState.Enabled
: CommandState.Unavailable,
_ => viewModel.RefreshSelectedNodeAsync())
{
Id = "RefreshProject",
Image = Resources.Refresh_16,
ActivityText = "Refreshing project"
});
this.contextMenuCommands.Value.AddCommand(
new ContextCommand<IProjectModelNode>(
"Refresh &all projects",
_ => viewModel.IsRefreshAllProjectsCommandVisible
? CommandState.Enabled
: CommandState.Unavailable,
_ => viewModel.RefreshAsync(false))
{
Id = "RefeshAllProjects",
Image = Resources.Refresh_16,
ActivityText = "Refreshing project"
});
this.contextMenuCommands.Value.AddCommand(
new ContextCommand<IProjectModelNode>(
"&Unload project",
_ => viewModel.IsUnloadProjectCommandVisible
? CommandState.Enabled
: CommandState.Unavailable,
_ => viewModel.UnloadSelectedProjectAsync())
{
Id = "UnloadProject",
ActivityText = "Unloading project"
});
this.contextMenuCommands.Value.AddSeparator();
this.contextMenuCommands.Value.AddCommand(
new ContextCommand<IProjectModelNode>(
"Open in Cloud Consol&e",
_ => viewModel.IsCloudConsoleCommandVisible
? CommandState.Enabled
: CommandState.Unavailable,
_ => viewModel.OpenInCloudConsole())
{
Id = "OpenCloudConsole",
ActivityText = "Opening Cloud Console"
});
this.contextMenuCommands.Value.AddCommand(
new ContextCommand<IProjectModelNode>(
"Configure IAP a&ccess",
_ => viewModel.IsCloudConsoleCommandVisible
? CommandState.Enabled
: CommandState.Unavailable,
_ => viewModel.ConfigureIapAccess())
{
Id = "ConfigureIapAccess",
ActivityText = "Opening Cloud Console"
});
this.contextMenuCommands.Value.AddSeparator();
//
// All commands added, apply to menu.
//
this.contextMenuCommands.Value.BindTo(
this.contextMenu.Items,
bindingContext);
this.toolbarCommands.Value.BindTo(
this.toolStrip.Items,
bindingContext);
}