/// <summary> /// Does a command</summary> /// <param name="commandTag">Command</param> public void DoCommand(object commandTag) { if (commandTag.Equals(CommandTag.TestCreateCircuitDoc)) { var circuitDomNode = CircuitEditorTester.CreateTestCircuitProgrammatically(m_schemaLoader); if (m_circuitEditor != null && m_controlHostService != null) { AdaptableControl control = m_circuitEditor.CreateCircuitControl(circuitDomNode); var viewingContext = circuitDomNode.Cast<ViewingContext>(); viewingContext.Control = control; var circuitDocument = circuitDomNode.Cast<CircuitDocument>(); var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"SCEA\Circuit Editor\Test Circuit.circuit"); var controlInfo = new ControlInfo(fileName, fileName, StandardControlGroup.Center); circuitDocument.ControlInfo = controlInfo; circuitDocument.Uri = new Uri(fileName, UriKind.Absolute); var editingContext = circuitDomNode.Cast<CircuitEditingContext>(); control.Context = editingContext; editingContext.GetLocalBound = Editor.GetLocalBound; editingContext.GetWorldOffset = Editor.GetWorldOffset; editingContext.GetTitleHeight = Editor.GetTitleHeight; editingContext.GetLabelHeight = Editor.GetLabelHeight; editingContext.GetSubContentOffset = Editor.GetSubContentOffset; // now that the data is complete, initialize all other extensions to the Dom data circuitDomNode.InitializeExtensions(); circuitDocument.Dirty = false; m_controlHostService.RegisterControl(control, controlInfo, m_circuitEditor); } } }
void IInitializable.Initialize() { m_control = new TerrainEditorControl(); ControlInfo cinfo = new ControlInfo("Terrain Editor", "Edit terrain properties", StandardControlGroup.Right); m_controlHostService.RegisterControl(m_control, cinfo, null); m_contextRegistry.ActiveContextChanged += ContextRegistry_ActiveContextChanged; }
public ResourceMetadataEditor() { m_propertyGrid = new PropertyGrid(); m_controlInfo = new ControlInfo( "Resource Metadata".Localize(), "Edits selected resource metadata".Localize(), StandardControlGroup.Hidden); }
protected override void Configure(out PropertyGrid propertyGrid, out ControlInfo controlInfo) { propertyGrid = new PropertyGrid(); controlInfo = new ControlInfo( "Unit Property Editor".Localize(), "Edits selected object properties".Localize(), StandardControlGroup.Center, null, "asdf".Localize()); }
void IInitializable.Initialize() { m_control = new TerrainEditorControl(); ControlInfo cinfo = new ControlInfo("Terrain Editor", "Edit terrain properties", StandardControlGroup.Right); m_controlHostService.RegisterControl(m_control, cinfo, null); m_contextRegistry.ActiveContextChanged += ContextRegistry_ActiveContextChanged; m_settingsService.RegisterSettings( this, new BoundPropertyDescriptor(this, () => SplitterDistance, "SplitterDistance", null, null)); m_mainForm.Loaded += (sender, e) => m_control.SplitterDistance = m_splitterDistance; }
/// <summary> /// Registers rendering control and subscribes to ActiveDocumentChanged event</summary> void IInitializable.Initialize() { ControlInfo cinfo = new ControlInfo("3D View", "3d viewer", StandardControlGroup.CenterPermanent); m_controlHostService.RegisterControl(m_designControl, cinfo, null); m_documentRegistry.ActiveDocumentChanged += (sender, e) => { ClearRenderGraph(m_context); m_context = null; ModelDocument doc = m_documentRegistry.GetActiveDocument<ModelDocument>(); if (doc != null) { m_context = doc.RootNode; SceneGraphBuilder builder = new SceneGraphBuilder(typeof(IRenderThumbnail)); builder.Build(doc.RootNode, m_scene); Fit(); } }; }
private static string GetPersistenceId(ControlInfo info) { Control control = info.Control; // first, try Name string name = info.Name; // if no label, try Text if (string.IsNullOrEmpty(name)) { name = control.Text; } // if no label, use generic tag if (string.IsNullOrEmpty(name)) { name = "document_panel"; } string label = name; if (name.StartsWith("@")) // literal control name { label = label.TrimStart('@'); } else { int lastDelimiter = label.LastIndexOfAny(s_pathDelimiters); if (lastDelimiter >= 0) { label = "document_panel"; } } return(label); }
private void UpdateDockContent(DockContent dockContent, ControlInfo info) { if (!string.IsNullOrEmpty(dockContent.Text)) { m_uniqueNamer.Retire(dockContent.Text); } // the hosting control's name should be unique string displayName = info.Name; string uniqueDisplayName = m_uniqueNamer.Name(displayName); dockContent.Text = uniqueDisplayName; // the persistence ID should be unique to the editor, but not include a document's name string persistenceId = GetPersistenceId(info); if (persistenceId == displayName) { persistenceId = uniqueDisplayName; } dockContent.Name = info.Client.GetType().Name + ":" + persistenceId; dockContent.ToolTipText = info.Description; dockContent.ShowIcon = info.Image != null; dockContent.Icon = info.Image == null ? null : GdiUtil.CreateIcon(info.Image, 16, true); // To update the icon, we need to invalidate this Pane. if (dockContent.DockState == DockState.Document) { dockContent.Pane.Invalidate(true); } }
void IInitializable.Initialize() { m_listbox = new CommandList(); m_listbox.DrawMode = DrawMode.OwnerDrawFixed; m_listbox.BorderStyle = BorderStyle.None; m_listbox.SelectedIndexChanged += (sender, e) => { try { m_undoingOrRedoing = true; int indexLastDone = m_commandHistory.Current - 1; int cmdIndex = m_listbox.SelectedIndex + m_startIndex; if (cmdIndex < indexLastDone) { while (cmdIndex < indexLastDone) { m_historyContext.Undo(); indexLastDone = m_commandHistory.Current - 1; } } else { while (cmdIndex >= m_commandHistory.Current) { m_historyContext.Redo(); } } } finally { m_undoingOrRedoing = false; } }; m_listbox.DrawItem2 += (sender, e) => { if (e.Index < 0) { return; } int cmdIndex = e.Index + m_startIndex; Command cmd = (Command)m_listbox.Items[e.Index]; if (cmdIndex >= m_commandHistory.Current) { m_textBrush.Color = m_redoForeColor; m_fillBrush.Color = m_redoBackColor; } else { m_textBrush.Color = m_undoForeColor; m_fillBrush.Color = m_undoBackColor; } if (e.State == DrawItemState.Selected) { e.DrawBackground(); e.DrawFocusRectangle(); } else { e.Graphics.FillRectangle(m_fillBrush, e.Bounds); } e.Graphics.DrawString(cmd.Description, e.Font, m_textBrush, e.Bounds, StringFormat.GenericDefault); }; ControlInfo cinfo = new ControlInfo("History", "Undo/Redo stack", StandardControlGroup.Right); m_controlHostService.RegisterControl(m_listbox, cinfo, null); m_documentRegistry.ActiveDocumentChanged += m_documentRegistry_ActiveDocumentChanged; m_listbox.BackColorChanged += (sender, e) => ComputeColors(); m_listbox.ForeColorChanged += (sender, e) => ComputeColors(); if (m_settingsService != null) { var descriptor = new BoundPropertyDescriptor( this, () => MaxCommandCount, "Max Visual Command History Count".Localize(), null, "Maximum number of commands in the visual command history".Localize()); m_settingsService.RegisterSettings(this, descriptor); m_settingsService.RegisterUserSettings("Application", descriptor); } ComputeColors(); }
private DockContent FindContent(Control control) { ControlInfo controlInfo = FindControlInfo(control); return(FindContent(controlInfo)); }
/// <summary> /// Registers a control so it becomes visible as part of the main form</summary> /// <param name="control">Control to register</param> /// <param name="info">Control display information</param> /// <param name="client">Client that owns the control and will receive notifications /// about its status, or null if no notifications are needed</param> public void RegisterControl(Control control, ControlInfo info, IControlHostClient client) { if (control == null) { throw new ArgumentNullException("control"); } if (info == null) { throw new ArgumentNullException("info"); } if (FindControlInfo(control) != null) { throw new ArgumentException("Control already registered"); } // allow null client if (client == null) { client = Global <DefaultClient> .Instance; } info.Client = client; info.Control = control; info.Changed += new EventHandler(info_Changed); DockContent dockContent = new DockContent(this); UpdateDockContent(dockContent, info); m_dockContent.Add(info, dockContent); m_controls.ActiveItem = info; info.HostControl = dockContent; // Any property we set on this Control needs to be restored in UnregisterControl. // For example, QuadPanelControl was broken by setting Dock property but not restoring it. info.OriginalDock = control.Dock; control.Dock = DockStyle.Fill; dockContent.Controls.Add(control); dockContent.FormClosing += new FormClosingEventHandler(dockContent_FormClosing); if (IsCenterGroup(info.Group)) { dockContent.Show(m_dockPanel, DockState.Document); RegisterMenuCommand(control, "@" + dockContent.Text); // tells m_commandService not to interpret slashes as submenus } else { DockState state; switch (info.Group) { case StandardControlGroup.Left: state = DockState.DockLeft; break; case StandardControlGroup.Right: state = DockState.DockRight; break; case StandardControlGroup.Top: state = DockState.DockTop; break; case StandardControlGroup.Bottom: state = DockState.DockBottom; break; case StandardControlGroup.Floating: state = DockState.Float; break; default: state = DockState.DockLeftAutoHide; break; } dockContent.Show(m_dockPanel, state); RegisterMenuCommand(control, dockContent.Text); // tells m_commandService not to interpret slashes as submenus } UpdateContent(control); ActivateClient(client, true); Show(control); }
/// <summary> /// Removes the given control if it is open</summary> /// <param name="control">Control to remove</param> /// <returns>True iff the control was removed</returns> public bool RemoveControl(ControlInfo control) { return(m_controls.Remove(control)); }
void IInitializable.Initialize() { m_commandListbox = new CommandList(); m_commandListbox.MouseDown += (sender, e) => { var item = m_commandListbox.GetItemAt(e.X, e.Y); if (item == null) { return; } int indexLastDone = m_commandHistory.Current - 1; int cmdIndex = item.Index - 1; if (cmdIndex <= indexLastDone) { while (cmdIndex < indexLastDone) { m_historyContext.Undo(); indexLastDone = m_commandHistory.Current - 1; } } else { while (cmdIndex >= m_commandHistory.Current) { m_historyContext.Redo(); } } }; m_commandListbox.RetrieveCommandListItem += (sender, e) => { e.Item = e.ItemIndex == 0 ? new CommandListItem("< Clean State >".Localize()) : new CommandListItem(m_commandHistory[e.ItemIndex - 1].Description); }; m_commandListbox.DrawItem += (sender, e) => { if (e.Item.Index < 0) { return; } int cmdIndex = e.Item.Index - 1; Rectangle bound = e.Item.Bounds; var cmd = e.Item; if (cmdIndex >= m_commandHistory.Current) { m_textBrush.Color = m_redoForeColor; m_fillBrush.Color = m_redoBackColor; } else { m_textBrush.Color = m_undoForeColor; m_fillBrush.Color = m_undoBackColor; } e.Graphics.FillRectangle(m_fillBrush, bound); e.Graphics.DrawString(cmd.Text, m_commandListbox.Font, m_textBrush, bound, StringFormat.GenericDefault); }; ControlInfo cinfo = new ControlInfo("History", "Undo/Redo stack", StandardControlGroup.Right); m_controlHostService.RegisterControl(m_commandListbox, cinfo, null); m_documentRegistry.ActiveDocumentChanged += m_documentRegistry_ActiveDocumentChanged; m_commandListbox.BackColorChanged += (sender, e) => ComputeColors(); m_commandListbox.ForeColorChanged += (sender, e) => ComputeColors(); ComputeColors(); }