internal void Localise(GuiPresenter presenter, Control targetControl) { if (_LocalPath != null) { targetControl.Text = presenter.GetString(_LocalPath); } if (_Locals.Count != 0) { if (targetControl is TabControl) { foreach (LocalDef MyLocal in _Locals) { ((TabControl)targetControl).TabPages[MyLocal.Name].Text = presenter.GetString(MyLocal.LocalPath); } } else if (targetControl is ListView) { foreach (LocalDef MyLocal in _Locals) { ((ListView)targetControl).Columns[MyLocal.Index].Text = presenter.GetString(MyLocal.LocalPath); } } } if (targetControl is ToolStrip) { // TODO: Localise Toolstrip } }
//**************************************** internal void AttachTo(GuiPresenter presenter, System.ComponentModel.Component targetControl) { _Presenter = presenter; if (targetControl is ButtonBase) { (targetControl as ButtonBase).Click += OnCommand; } else if (targetControl is LinkLabel) { (targetControl as LinkLabel).Click += OnCommand; } else if (targetControl is ToolStripButton) { (targetControl as ToolStripButton).Click += OnCommand; } else if (targetControl is ToolStripDropDownButton) { (targetControl as ToolStripDropDownButton).Click += OnCommand; } else { throw new ArgumentException("Target Control does not support Command bindings"); } }
//**************************************** internal void Execute(GuiPresenter parent, string commandName) { //**************************************** GuiPresenter CurrentPresenter = parent; GuiCommandTemplate MyTemplate; //**************************************** while (CurrentPresenter != null) { MyTemplate = CurrentPresenter.Host.GetCommandTemplate(CurrentPresenter, commandName); if (MyTemplate != null && (!MyTemplate.CanCheckExecute || MyTemplate.CheckExecute(CurrentPresenter))) { MyTemplate.Execute(CurrentPresenter); return; } CurrentPresenter = CurrentPresenter.Parent; } // Not found on the parent, try the active context if (parent != _ActivePresenter) { Execute(_ActivePresenter, commandName); return; } Log.Warning("Command {0} was not found in the Presenter hierarchy", commandName); //throw new InvalidOperationException(string.Format("Command {0} was not found in the Presenter hierarchy", commandName)); }
internal void AttachController(GuiPresenter parent, GuiChildPresenter presenter, UserControl control) { var MyParentView = GetView(parent); var MyController = new WinChildController(presenter, MyParentView, control); SetView(presenter, MyController); }
protected void SetView(GuiPresenter presenter, GuiViewController controller) { if (presenter.View != null) { throw new InvalidOperationException("View has already been set"); } presenter.View = controller; }
//**************************************** private void ApplyToolbar(GuiPresenter presenter, Control targetControl) { //**************************************** var MyToolStrip = (ToolStrip)targetControl; //**************************************** foreach (ToolbarItemDef MyItemDef in _Toolbar.Items) { MyToolStrip.Items.Add(CreateToolbarItem(presenter, MyItemDef)); } }
private ToolStripButton CreateButton(GuiPresenter presenter, ToolbarItemDef itemDef) { //**************************************** var MyButton = new ToolStripButton(); //**************************************** new WinCommand(itemDef.Command).AttachTo(presenter, MyButton); //**************************************** return(MyButton); }
/// <summary> /// Retrieves all the Command Templates defined by this Presenter /// </summary> /// <param name="presenter">The Presenter to check</param> /// <returns>The matching Command Templates</returns> public ICollection <GuiCommandTemplate> GetCommandTemplates(GuiPresenter presenter) { //**************************************** IDictionary <string, GuiCommandTemplate> CommandTemplates; //**************************************** if (_CommandMappings.TryGetValue(presenter.GetType(), out CommandTemplates)) { return(CommandTemplates.Values); } throw new ArgumentException("Presenter does not exist"); }
//**************************************** internal void Connect(GuiPresenter presenter) { _Presenter = presenter; foreach (WinBoundControl MySource in _BoundControls.Values) { MySource.Attach(); } if (Connected != null) { Connected(this, EventArgs.Empty); } }
private ToolStripDropDownButton CreateDropDownButton(GuiPresenter presenter, ToolbarItemDef itemDef) { //**************************************** var MyButton = new ToolStripDropDownButton(); //**************************************** foreach (ToolbarItemDef MyItemDef in itemDef.Children) { MyButton.DropDownItems.Add(CreateToolbarItem(presenter, MyItemDef)); } //**************************************** return(MyButton); }
//**************************************** private void OnAttach(object sender, EventArgs e) { _Presenter = (GuiPresenter)_TargetElement.TryFindResource("Proximity.Gui.Presentation.GuiPresenter"); // No Presenter yet, the attach event wasn't for us if (_Presenter == null) { return; } //**************************************** Value = _Presenter.GetString(_Path); ((WpfToolkit)GuiService.Toolkit).Attach -= OnAttach; }
private ToolStripSplitButton CreateSplitButton(GuiPresenter presenter, ToolbarItemDef itemDef) { //**************************************** var MyButton = new ToolStripSplitButton(); //**************************************** new WinCommand(itemDef.Command).AttachTo(presenter, MyButton); foreach (ToolbarItemDef MyItemDef in itemDef.Children) { MyButton.DropDownItems.Add(CreateToolbarItem(presenter, MyItemDef)); } //**************************************** return(MyButton); }
/// <summary> /// Retrieves the named Command Template if defined by this Presenter /// </summary> /// <param name="presenter">The Presenter to check</param> /// <param name="commandName">The name of the Command Template</param> /// <returns>The requested Command Template, or null if not defined</returns> public GuiCommandTemplate GetCommandTemplate(GuiPresenter presenter, string commandName) { //**************************************** IDictionary <string, GuiCommandTemplate> CommandTemplates; GuiCommandTemplate MyTemplate; //**************************************** if (!_CommandMappings.TryGetValue(presenter.GetType(), out CommandTemplates)) { throw new ArgumentException("Presenter does not exist"); } if (CommandTemplates.TryGetValue(commandName, out MyTemplate)) { return(MyTemplate); } return(null); }
internal void Localise(GuiPresenter presenter, ContainerControl targetControl) { //**************************************** Control[] MyControls; Control MyControl; //**************************************** foreach (ControlDef MyControlDef in _Controls) { MyControls = targetControl.Controls.Find(MyControlDef.Name, true); if (MyControls.Length == 0) { continue; } MyControl = MyControls[0]; MyControlDef.Localise(presenter, MyControl); } }
//**************************************** internal void ApplyTo(GuiPresenter presenter, ContainerControl targetControl) { //**************************************** Control[] MyControls; Control MyControl; //**************************************** if (!_HasScanned) { _LocalPath = targetControl.Text; // First application, scan the view for localisation codes WalkControls(targetControl); _HasScanned = true; } //**************************************** if (_LocalPath != null) { targetControl.Text = presenter.GetString(_LocalPath); } foreach (ControlDef MyControlDef in _Controls) { MyControls = targetControl.Controls.Find(MyControlDef.Name, true); if (MyControls.Length == 0) { continue; } MyControl = MyControls[0]; MyControlDef.ApplyTo(presenter, MyControl); MyControlDef.Localise(presenter, MyControl); } }
//**************************************** internal void ApplyTo(GuiPresenter presenter, Control targetControl) { if (!_HasScanned) { if (targetControl.Text != null) { _LocalPath = targetControl.Text; } if (targetControl is TabControl) { foreach (TabPage MyPage in ((TabControl)targetControl).TabPages) { _Locals.Add(new LocalDef(MyPage.Name, MyPage.Text)); } } else if (targetControl is ListView) { foreach (ColumnHeader MyColumn in ((ListView)targetControl).Columns) { _Locals.Add(new LocalDef(MyColumn.Index, MyColumn.Text)); } } _HasScanned = true; } //**************************************** if (_Toolbar != null) { ApplyToolbar(presenter, targetControl); } //**************************************** Localise(presenter, targetControl); }
private ToolStripItem CreateToolbarItem(GuiPresenter presenter, ToolbarItemDef itemDef) { //**************************************** ToolStripItem MyItem; //**************************************** if (itemDef.Children != null) { if (!string.IsNullOrEmpty(itemDef.Command)) // Item has children and is clickable, use a Split Button { MyItem = CreateSplitButton(presenter, itemDef); } else // Children, but not clickable, use a Drop Down { MyItem = CreateDropDownButton(presenter, itemDef); } } else { if (itemDef.Style == null) // No style, use a Separator { MyItem = new ToolStripSeparator(); } else if (!string.IsNullOrEmpty(itemDef.Command)) // Clickable, use a Button { MyItem = CreateButton(presenter, itemDef); } else // Not clickable, styled, use a Label { MyItem = new ToolStripLabel(); } } //**************************************** if (itemDef.Style != null) { if (itemDef.Style.Icon != null) { MyItem.Image = itemDef.Style.Icon; MyItem.ImageAlign = ContentAlignment.MiddleLeft; if (itemDef.HasText) { MyItem.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText; } else { MyItem.DisplayStyle = ToolStripItemDisplayStyle.Image; } } else { MyItem.DisplayStyle = ToolStripItemDisplayStyle.Text; } } switch (itemDef.Align) { case ToolbarItemAlign.Left: MyItem.Alignment = ToolStripItemAlignment.Left; break; case ToolbarItemAlign.Right: MyItem.Alignment = ToolStripItemAlignment.Right; break; } //**************************************** return(MyItem); }
internal void AttachTo(GuiPresenter presenter, FrameworkElement element) { _Attach.Invoke(this, EventArgs.Empty); }
protected GuiViewController GetView(GuiPresenter presenter) { return(presenter.View); }
//**************************************** internal GuiViewController(GuiPresenter presenter) { _Presenter = presenter; }
//**************************************** internal void SwitchPresenter(GuiPresenter presenter) { _ActivePresenter = presenter; }
//**************************************** internal void ApplyTo(GuiPresenter presenter, Component targetComponent) { }