Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-6653 Create new workspace based on Templates - Part II #14982

Merged
merged 11 commits into from
Mar 20, 2024
4 changes: 4 additions & 0 deletions src/DynamoCore/Configuration/IPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public interface IPreferences
/// Return full path to the Python (.py) file to use as a starting template when creating a new PythonScript Node.
/// </summary>
string PythonTemplateFilePath { get; set; }
/// <summary>
/// Return full path of the template directory with template file(s) to use as a starting template when creating a new graph from a template.
/// </summary>
string TemplateFilePath { get; set; }

/// <summary>
/// Returns active state of specified background preview
Expand Down
34 changes: 30 additions & 4 deletions src/DynamoCore/Configuration/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ internal static Lazy<PathManager>
private string logDirectory;
private string samplesDirectory;
private string templatesDirectory;
private string defaultTemplatesDirectory;
private string backupDirectory;
private string defaultBackupDirectory;
private string preferenceFilePath;
Expand Down Expand Up @@ -205,6 +206,16 @@ public string LogDirectory
get { return logDirectory; }
}

/// <summary>
/// The enum will contain the possible values for Preference Item
/// </summary>
public enum PreferenceItem
{
Backup,
Templates,
Samples
}

/// <summary>
/// Default directory where new packages are downloaded to.
/// This directory path is user configurable and if set to something other than the default,
Expand Down Expand Up @@ -249,6 +260,13 @@ public string TemplatesDirectory
{
get { return templatesDirectory; }
}
/// <summary>
/// Default templates directory, it is used when the user resets the custom template path
/// </summary>
public string DefaultTemplatesDirectory
{
get { return defaultTemplatesDirectory; }
}

public string BackupDirectory
{
Expand Down Expand Up @@ -473,13 +491,21 @@ internal void EnsureDirectoryExistence(List<Exception> exceptions)
exceptions.RemoveAll(x => x == null); // Remove all null entries.
}

internal bool UpdateBackupLocation(string newBackupLocation)
internal bool UpdatePreferenceItemPath(PreferenceItem item, string newLocation)
{
bool isValidFolder = PathHelper.CreateFolderIfNotExist(newBackupLocation) == null;
bool isValidFolder = PathHelper.CreateFolderIfNotExist(newLocation) == null;
if (!isValidFolder)
return false;

backupDirectory = newBackupLocation;
switch (item)
{
case PreferenceItem.Backup:
backupDirectory = newLocation;
break;
case PreferenceItem.Templates:
templatesDirectory = newLocation;
break;
}
return true;
}

Expand Down Expand Up @@ -582,7 +608,7 @@ private void BuildCommonDirectories()
commonDefinitions = Path.Combine(commonDataDir, DefinitionsDirectoryName);
commonPackages = Path.Combine(commonDataDir, PackagesDirectoryName);
samplesDirectory = GetSamplesFolder(commonDataDir);
templatesDirectory = GetTemplateFolder(commonDataDir);
defaultTemplatesDirectory = GetTemplateFolder(commonDataDir);

rootDirectories = new List<string> { userDataDir };

Expand Down
18 changes: 18 additions & 0 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private readonly static Lazy<PreferenceSettings>
private bool isTimeStampIncludedInExportFilePath;
private bool isCreatedFromValidFile = true;
private string backupLocation;
private string templateFilePath;
private bool isMLAutocompleteTOUApproved;

#region Constants
Expand Down Expand Up @@ -443,6 +444,19 @@ public string BackupLocation
}
}

/// <summary>
/// Template path
/// </summary>
public string TemplateFilePath
{
get { return templateFilePath; }
set
{
templateFilePath = value;
RaisePropertyChanged(nameof(TemplateFilePath));
}
}

/// <summary>
/// A list of backup file paths.
/// </summary>
Expand Down Expand Up @@ -932,12 +946,15 @@ public PreferenceSettings()
BackupFiles = new List<string>();
BackupLocation = string.Empty;

TemplateFilePath = string.Empty;

LibraryZoomScale = 100;
PythonScriptZoomScale = 100;

CustomPackageFolders = new List<string>();

PythonTemplateFilePath = "";
PythonTemplateFilePath = PathManager.TemplateDirectoryName;
zeusongit marked this conversation as resolved.
Show resolved Hide resolved
IsIronPythonDialogDisabled = false;
ShowTabsAndSpacesInScriptEditor = false;
EnableNodeAutoComplete = true;
Expand Down Expand Up @@ -1260,6 +1277,7 @@ internal void AddDefaultTrustedLocations()
if (!IsFirstRun) return;
string ProgramData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
AddTrustedLocation(Path.Combine(ProgramData, Configurations.AutodeskAsString));
AddTrustedLocation(Path.Combine(ProgramData, Configurations.DynamoAsString));
zeusongit marked this conversation as resolved.
Show resolved Hide resolved

string ProgramFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
AddTrustedLocation(Path.Combine(ProgramFiles, Configurations.AutodeskAsString));
Expand Down
5 changes: 5 additions & 0 deletions src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ internal int CurrentPasteOffset
/// </summary>
internal bool ContainsLegacyTraceData { get; set; }

/// <summary>
/// Denotes if the current workspace was created from a template.
/// </summary>
internal bool IsTemplate { get; set; }

internal bool ScaleFactorChanged = false;

/// <summary>
Expand Down
70 changes: 57 additions & 13 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
using Newtonsoft.Json.Linq;
using ProtoCore;
using ProtoCore.Runtime;
using static Dynamo.Core.PathManager;
using Compiler = ProtoAssociative.Compiler;
// Dynamo package manager
using FunctionGroup = Dynamo.Engine.FunctionGroup;
Expand Down Expand Up @@ -1738,29 +1739,71 @@ private void InitializePreferences()
{
ProtoCore.Mirror.MirrorData.PrecisionFormat = DynamoUnits.Display.PrecisionFormat = PreferenceSettings.NumberFormat;
PreferenceSettings.InitializeNamespacesToExcludeFromLibrary();
InitializePreferenceLocations();
}
}

if (string.IsNullOrEmpty(PreferenceSettings.BackupLocation))
{
PreferenceSettings.BackupLocation = pathManager.DefaultBackupDirectory;
}
private void InitializePreferenceLocations()
{
if (string.IsNullOrEmpty(PreferenceSettings.BackupLocation))
{
PreferenceSettings.BackupLocation = pathManager.DefaultBackupDirectory;
}
if (string.IsNullOrEmpty(PreferenceSettings.TemplateFilePath))
{
PreferenceSettings.TemplateFilePath = pathManager.DefaultTemplatesDirectory;
}

UpdateBackupLocation(PreferenceSettings.BackupLocation);
UpdatePreferenceItemLocation(PreferenceItem.Backup, PreferenceSettings.BackupLocation);
UpdatePreferenceItemLocation(PreferenceItem.Templates, PreferenceSettings.TemplateFilePath);
}
internal bool UpdatePreferenceItemLocation(PreferenceItem item, string newLocation)
{
if (string.IsNullOrEmpty(newLocation)) return false;
switch (item)
{
case PreferenceItem.Backup:
PreferenceSettings.BackupLocation = newLocation;
break;
case PreferenceItem.Templates:
PreferenceSettings.TemplateFilePath = newLocation;
break;
default:
break;
}
return pathManager.UpdatePreferenceItemPath(item, newLocation);
}

internal bool UpdateBackupLocation(string selectedBackupLocation)
internal bool IsDefaultPreferenceItemLocation(PreferenceItem item)
{
return pathManager.UpdateBackupLocation(selectedBackupLocation);
switch (item)
{
case PreferenceItem.Backup:
return PreferenceSettings.BackupLocation.Equals(pathManager.DefaultBackupDirectory);
case PreferenceItem.Templates:
return PreferenceSettings.TemplateFilePath.Equals(pathManager.DefaultTemplatesDirectory);
default:
return false;
}
}

internal bool IsDefaultBackupLocation()
internal string DefaultPreferenceItemLocation(PreferenceItem item)
{
return PreferenceSettings.BackupLocation.Equals(pathManager.DefaultBackupDirectory);
switch (item)
{
case PreferenceItem.Backup:
return pathManager.DefaultBackupDirectory;
case PreferenceItem.Templates:
return pathManager.DefaultTemplatesDirectory;
default:
return string.Empty;
}
}

internal string DefaultBackupLocation()
internal string ResetPreferenceItemLocation(PreferenceItem item)
{
return pathManager.DefaultBackupDirectory;
var loc = DefaultPreferenceItemLocation(item);
UpdatePreferenceItemLocation(item, loc);

return loc;
}

/// <summary>
Expand Down Expand Up @@ -2341,6 +2384,7 @@ private bool OpenJsonFile(
workspace.FileName = string.IsNullOrEmpty(filePath) || isTemplate? string.Empty : filePath;
workspace.FromJsonGraphId = string.IsNullOrEmpty(filePath) ? WorkspaceModel.ComputeGraphIdFromJson(fileContents) : string.Empty;
workspace.ScaleFactor = dynamoPreferences.ScaleFactor;
workspace.IsTemplate = isTemplate;

if (!IsTestMode && !IsHeadless)
{
Expand Down
4 changes: 4 additions & 0 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ Dynamo.Configuration.PreferenceSettings.ShowRunPreview.set -> void
Dynamo.Configuration.PreferenceSettings.ShowTabsAndSpacesInScriptEditor.get -> bool
Dynamo.Configuration.PreferenceSettings.ShowTabsAndSpacesInScriptEditor.set -> void
Dynamo.Configuration.PreferenceSettings.StaticFields() -> System.Collections.Generic.List<string>
Dynamo.Configuration.PreferenceSettings.TemplateFilePath.get -> string
Dynamo.Configuration.PreferenceSettings.TemplateFilePath.set -> void
Dynamo.Configuration.PreferenceSettings.TrustedLocations.get -> System.Collections.Generic.List<string>
Dynamo.Configuration.PreferenceSettings.UseHardwareAcceleration.get -> bool
Dynamo.Configuration.PreferenceSettings.UseHardwareAcceleration.set -> void
Expand Down Expand Up @@ -1582,6 +1584,8 @@ Dynamo.Interfaces.IPreferences.ShowEdges.get -> bool
Dynamo.Interfaces.IPreferences.ShowEdges.set -> void
Dynamo.Interfaces.IPreferences.ShowPreviewBubbles.get -> bool
Dynamo.Interfaces.IPreferences.ShowPreviewBubbles.set -> void
Dynamo.Interfaces.IPreferences.TemplateFilePath.get -> string
Dynamo.Interfaces.IPreferences.TemplateFilePath.set -> void
Dynamo.Interfaces.IPreferences.WindowH.get -> double
Dynamo.Interfaces.IPreferences.WindowH.set -> void
Dynamo.Interfaces.IPreferences.WindowW.get -> double
Expand Down
63 changes: 63 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3931,6 +3931,27 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<value>Enable Paneling nodes</value>
<comment>Preferences | Features | Experimental | Enable Paneling nodes</comment>
</data>
<data name="PreferencesSettingTemplateLocationLabel" xml:space="preserve">
<value>Templates Path</value>
</data>
<data name="PreferencesSettingResetTemplateLocationTooltip" xml:space="preserve">
<value>Reset Template Location</value>
</data>
<data name="PreferencesSettingsTemplateFailedMessage" xml:space="preserve">
<value>Failed to update template location</value>
</data>
<data name="PreferencesSettingsTemplateFailedTitle" xml:space="preserve">
<value>Invalid Template Location</value>
</data>
<data name="PreferencesSettingsTemplateLocationDialogTitle" xml:space="preserve">
<value>Select Folder for Templates</value>
</data>
<data name="PreferencesSettingUpdateTemplateLocationTooltip" xml:space="preserve">
<value>Edit Template Location</value>
</data>
<data name="PreferencesViewGeneralSettingsTemplate" xml:space="preserve">
<value>Templates</value>
</data>
<data name="DynamoXmlFileFormat" xml:space="preserve">
<value>Dynamo 1.x file format</value>
</data>
Expand Down
Loading
Loading