From 4ce97b11cda3097817df405048f1735518274671 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 24 Dec 2024 05:51:35 -0700 Subject: [PATCH] Removed Code tab if a there is no element, or if the element is a Standard type. --- CodeOutputPlugin/MainCodeOutputPlugin.cs | 30 +++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/CodeOutputPlugin/MainCodeOutputPlugin.cs b/CodeOutputPlugin/MainCodeOutputPlugin.cs index 25819c7e..707a3b8c 100644 --- a/CodeOutputPlugin/MainCodeOutputPlugin.cs +++ b/CodeOutputPlugin/MainCodeOutputPlugin.cs @@ -33,19 +33,20 @@ public class MainCodeOutputPlugin : PluginBase private readonly CodeGenerationFileLocationsService _codeGenerationFileLocationsService; private readonly CodeGenerationService _codeGenerationService; + private readonly ISelectedState _selectedState; + PluginTab pluginTab; #endregion + #region Init/Startup + public MainCodeOutputPlugin() { _codeGenerationFileLocationsService = new CodeGenerationFileLocationsService(); _codeGenerationService = new CodeGenerationService(); - } - public override bool ShutDown(PluginShutDownReason shutDownReason) - { - return true; + _selectedState = SelectedState.Self; } public override void StartUp() @@ -88,6 +89,8 @@ private void AssignEvents() this.ProjectLoad += HandleProjectLoaded; } + #endregion + private void HandleElementDeleted(ElementSave element) { var elementSettings = CodeOutputElementSettingsManager.LoadOrCreateSettingsFor(element); @@ -237,6 +240,18 @@ private void HandleViewCodeClicked(object sender, EventArgs e) private void RefreshCodeDisplay() { + var shouldShow = _selectedState.SelectedElement != null && + _selectedState.SelectedElement is not StandardElementSave; + + if(shouldShow) + { + pluginTab.Show(focus:false); + } + else + { + pluginTab.Hide(); + } + control.CodeOutputProjectSettings = codeOutputProjectSettings; if(control.CodeOutputElementSettings == null) { @@ -309,10 +324,7 @@ private void CreateControl() control.DataContext = viewModel; - // We don't actually want it to show, just associate, so add and immediately remove. - // Eventually we want this to be done with a single call but I don't know if there's Gum - // support for it yet - GumCommands.Self.GuiCommands.AddControl(control, "Code", TabLocation.RightBottom); + pluginTab = GumCommands.Self.GuiCommands.AddControl(control, "Code", TabLocation.RightBottom); } private void HandleMainViewModelPropertyChanged(string propertyName) @@ -395,5 +407,7 @@ private void GenerateCodeForElement(bool showPopups, ElementSave element) _codeGenerationService.GenerateCodeForElement(element, settings, codeOutputProjectSettings, showPopups); } } + + public override bool ShutDown(PluginShutDownReason shutDownReason) => true; } }