From 50fae1b177547afa9adf371f3488b4f8256951e3 Mon Sep 17 00:00:00 2001
From: Victor Chelaru <VicChelaru@gmail.com>
Date: Fri, 18 Aug 2023 13:11:10 -0600
Subject: [PATCH] Open project in VS and window folder no longer show if a
 project is unloaded.

---
 .../SyncedProjects/Controls/ToolbarControl.xaml    |  3 +++
 .../EmbeddedPlugins/SyncedProjects/MainPlugin.cs   |  7 +++++++
 .../ViewModels/ToolbarControlViewModel.cs          | 14 ++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/Controls/ToolbarControl.xaml b/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/Controls/ToolbarControl.xaml
index 95529ca70..747fc969d 100644
--- a/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/Controls/ToolbarControl.xaml
+++ b/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/Controls/ToolbarControl.xaml
@@ -9,6 +9,7 @@
              mc:Ignorable="d" >
     <StackPanel Orientation="Horizontal">
         <xctk:SplitButton
+            Visibility="{Binding VisualStudioButtonVisibility}"
             Click="VisualStudioButtonClick" 
              ToolTip="Open Project in Visual Studio"
              Height="22" Width="40">
@@ -21,6 +22,8 @@
         </xctk:SplitButton>
 
         <Button Click="FolderButtonClick" 
+            Visibility="{Binding FolderButtonVisibility}"
+                
              ToolTip="Open Project Folder"
              Height="22" Width="22" Margin="2,0,0,0">
             <Image Source="/Plugins/EmbeddedPlugins/SyncedProjects/Images/OpenFolder.png"></Image>
diff --git a/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/MainPlugin.cs b/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/MainPlugin.cs
index ae9784e47..4ad03e3a8 100644
--- a/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/MainPlugin.cs
+++ b/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/MainPlugin.cs
@@ -26,10 +26,16 @@ public override void StartUp()
             this.AddMenuItemTo("View Projects", HandleSyncedProjectsClick, "Project", preferredIndex:0);
 
             this.ReactToLoadedGlux += HandleGluxLoad;
+            this.ReactToUnloadedGlux += HandleGluxUnload;
 
             AddToolbarUi();
         }
 
+        private void HandleGluxUnload()
+        {
+            toolbarControlViewModel.HasProjectLoaded = false;
+        }
+
         private void HandleGluxLoad()
         {
             var glueProject = GlueState.Self.CurrentGlueProject;
@@ -39,6 +45,7 @@ private void HandleGluxLoad()
 
             var value = openAutomaticallyProperty?.Value as bool? == true;
             toolbarControlViewModel.IsOpenVisualStudioAutomaticallyChecked = value;
+            toolbarControlViewModel.HasProjectLoaded = true;
 
             if (value)
             {
diff --git a/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/ViewModels/ToolbarControlViewModel.cs b/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/ViewModels/ToolbarControlViewModel.cs
index 8139149ff..6967bcf91 100644
--- a/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/ViewModels/ToolbarControlViewModel.cs
+++ b/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/SyncedProjects/ViewModels/ToolbarControlViewModel.cs
@@ -2,6 +2,7 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using System.Windows;
 
 namespace GlueFormsCore.Plugins.EmbeddedPlugins.SyncedProjects.ViewModels
 {
@@ -12,5 +13,18 @@ public bool IsOpenVisualStudioAutomaticallyChecked
             get => Get<bool>();
             set => Set(value);
         }
+
+        public bool HasProjectLoaded
+        {
+            get => Get<bool>();
+            set => Set(value);
+        }
+
+        [DependsOn(nameof(HasProjectLoaded))]
+        public Visibility VisualStudioButtonVisibility => HasProjectLoaded.ToVisibility();
+
+        [DependsOn(nameof(HasProjectLoaded))]
+        public Visibility FolderButtonVisibility => HasProjectLoaded.ToVisibility();
+
     }
 }