using System; using System.Collections.Generic; using System.Linq; using Core.Common.Controls.Views; using Core.Common.Gui; using Core.Common.Gui.Forms; using Core.Common.Gui.Plugin; using Core.Components.OxyPlot.Data; using Core.Plugins.OxyPlot.Commands; using Core.Plugins.OxyPlot.Forms; using Core.Plugins.OxyPlot.Legend; using Core.Plugins.OxyPlot.Properties; namespace Core.Plugins.OxyPlot { public class OxyPlotGuiPlugin : GuiPlugin, IToolViewController { private ChartingRibbon chartingRibbon; private LegendController legendController; private bool activated; public override IRibbonCommandHandler RibbonCommandHandler { get { return chartingRibbon; } } public override void Activate() { legendController = CreateLegendController(this); chartingRibbon = CreateRibbon(legendController); legendController.ToggleLegend(); Gui.ActiveViewChanged += GuiOnActiveViewChanged; activated = true; } public override IEnumerable GetViewInfoObjects() { yield return new ViewInfo { Image = Resources.ChartIcon, GetViewName = (v, o) => "Diagram" }; } public bool IsToolWindowOpen() { return Gui.ToolWindowViews.Any(t => t.GetType() == typeof(T)); } public void OpenToolView(IView toolView) { Gui.OpenToolView(toolView); UpdateComponentsForActiveView(); } public void CloseToolView(IView toolView) { Gui.CloseToolView(toolView); } public override void Dispose() { if (activated) { Gui.ActiveViewChanged -= GuiOnActiveViewChanged; } base.Dispose(); } /// /// Creates a new . /// /// The to use for the controller /// . /// A new instance. private static LegendController CreateLegendController(IToolViewController toolViewController) { var controller = new LegendController(toolViewController); return controller; } /// /// Creates the and the commands that will be used when clicking on the buttons. /// /// The to use for the /// . /// A new instance. private static ChartingRibbon CreateRibbon(LegendController legendController) { return new ChartingRibbon { OpenChartViewCommand = new OpenChartViewCommand(), ToggleLegendViewCommand = new ToggleLegendViewCommand(legendController) }; } private void GuiOnActiveViewChanged(object sender, ActiveViewChangeEventArgs activeViewChangeEventArgs) { UpdateComponentsForActiveView(); } /// /// Updates the components which the knows about so that it reflects /// the currently active view. /// private void UpdateComponentsForActiveView() { var chartView = Gui.ActiveView as IChartView; if (chartView != null) { chartingRibbon.ShowChartingTab(); legendController.UpdateForChart(chartView.Chart); } else { chartingRibbon.HideChartingTab(); legendController.UpdateForChart(null); } } } }