Skip to content

Commit

Permalink
Removed Code tab if a there is no element, or if the element is a Sta…
Browse files Browse the repository at this point in the history
…ndard type.
  • Loading branch information
vchelaru committed Dec 24, 2024
1 parent 8ee5ad3 commit 4ce97b1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions CodeOutputPlugin/MainCodeOutputPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -88,6 +89,8 @@ private void AssignEvents()
this.ProjectLoad += HandleProjectLoaded;
}

#endregion

private void HandleElementDeleted(ElementSave element)
{
var elementSettings = CodeOutputElementSettingsManager.LoadOrCreateSettingsFor(element);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -395,5 +407,7 @@ private void GenerateCodeForElement(bool showPopups, ElementSave element)
_codeGenerationService.GenerateCodeForElement(element, settings, codeOutputProjectSettings, showPopups);
}
}

public override bool ShutDown(PluginShutDownReason shutDownReason) => true;
}
}

0 comments on commit 4ce97b1

Please sign in to comment.