Skip to content

Commit

Permalink
Move layout files to workflow settings folder
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Sep 3, 2024
1 parent 39a8fa3 commit 76ba898
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
15 changes: 13 additions & 2 deletions Bonsai.Editor/EditorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ bool OpenWorkflow(string fileName, bool setWorkingDirectory)
editorControl.Workflow = workflowBuilder.Workflow;
editorSite.ValidateWorkflow();

#pragma warning disable CS0612 // Support for deprecated layout config files
var layoutPath = LayoutHelper.GetLayoutPath(fileName);
if (File.Exists(layoutPath))
{
Expand All @@ -850,6 +851,7 @@ bool OpenWorkflow(string fileName, bool setWorkingDirectory)
catch (InvalidOperationException) { }
}
}
#pragma warning restore CS0612 // Support for deprecated layout config files

saveWorkflowDialog.FileName = fileName;
ResetProjectStatus();
Expand Down Expand Up @@ -903,8 +905,17 @@ bool SaveWorkflow(string fileName)
editorControl.UpdateVisualizerLayout();
if (editorControl.VisualizerLayout != null)
{
var layoutPath = LayoutHelper.GetLayoutPath(fileName);
SaveVisualizerLayout(layoutPath, editorControl.VisualizerLayout);
var layoutPath = new FileInfo(Project.GetLayoutConfigPath(fileName));
layoutPath.Directory?.Create();

SaveVisualizerLayout(layoutPath.FullName, editorControl.VisualizerLayout);
#pragma warning disable CS0612 // Support for deprecated layout config files
var legacyLayoutPath = new FileInfo(Project.GetLegacyLayoutConfigPath(fileName));
if (legacyLayoutPath.Exists)
{
legacyLayoutPath.Delete();
}
#pragma warning restore CS0612 // Support for deprecated layout config files
}

UpdateWorkflowDirectory(fileName);
Expand Down
7 changes: 5 additions & 2 deletions Bonsai.Editor/Layout/LayoutHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Bonsai.Design
{
static class LayoutHelper
{
const string LayoutExtension = ".layout";
static readonly XName XsdAttributeName = ((XNamespace)"http://www.w3.org/2000/xmlns/") + "xsd";
static readonly XName XsiAttributeName = ((XNamespace)"http://www.w3.org/2000/xmlns/") + "xsi";
const string XsdAttributeValue = "http://www.w3.org/2001/XMLSchema";
Expand All @@ -25,9 +24,13 @@ public static VisualizerDialogSettings GetLayoutSettings(this VisualizerLayout v
return visualizerLayout?.DialogSettings.FirstOrDefault(xs => xs.Tag == key || xs.Tag == null);
}

[Obsolete]
public static string GetLayoutPath(string fileName)
{
return Path.ChangeExtension(fileName, Path.GetExtension(fileName) + LayoutExtension);
var newLayoutPath = Editor.Project.GetLayoutConfigPath(fileName);
return File.Exists(newLayoutPath)
? newLayoutPath
: Editor.Project.GetLegacyLayoutConfigPath(fileName);
}

public static void SetLayoutTags(ExpressionBuilderGraph source, VisualizerLayout layout)
Expand Down
17 changes: 17 additions & 0 deletions Bonsai.Editor/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Bonsai.Editor
static class Project
{
internal const string BonsaiExtension = ".bonsai";
internal const string LayoutExtension = ".layout";

public static string GetCurrentBaseDirectory()
{
Expand Down Expand Up @@ -33,5 +34,21 @@ public static string GetWorkflowBaseDirectory(string fileName)
{
return Path.GetDirectoryName(fileName);
}

public static string GetWorkflowSettingsDirectory(string fileName)
{
return Path.Combine(BonsaiExtension, Path.GetFileNameWithoutExtension(fileName));
}

public static string GetLayoutConfigPath(string fileName)
{
return Path.Combine(GetWorkflowSettingsDirectory(fileName), LayoutExtension);
}

[Obsolete]
internal static string GetLegacyLayoutConfigPath(string fileName)
{
return Path.ChangeExtension(fileName, Path.GetExtension(fileName) + LayoutExtension);
}
}
}
2 changes: 2 additions & 0 deletions Bonsai.Editor/WorkflowRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public static void Run(
}

var workflowBuilder = ElementStore.LoadWorkflow(fileName);
#pragma warning disable CS0612 // Support for deprecated layout config files
layoutPath ??= LayoutHelper.GetLayoutPath(fileName);
#pragma warning restore CS0612 // Support for deprecated layout config files
if (visualizerProvider != null && File.Exists(layoutPath))
{
VisualizerLayout layout = null;
Expand Down

0 comments on commit 76ba898

Please sign in to comment.