-
Notifications
You must be signed in to change notification settings - Fork 635
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-4034 : open file from json content #12671
Conversation
src/DynamoCore/Models/DynamoModel.cs
Outdated
@@ -1870,7 +1885,7 @@ private void SetPeriodicEvaluation(WorkspaceModel ws) | |||
CustomNodeManager, | |||
this.LinterManager); | |||
|
|||
workspace.FileName = filePath; | |||
workspace.FileName = String.IsNullOrEmpty(filePath) ? "" : filePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what affect does this have? Isn't workspace.FileName going to end up being null
""
or filepath
in all cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to avoid having workspace.FileName set to null and set it to empty string instead so that I can mimic the exact FIleName setting of a new Home unsaved dyn file.
src/DynamoCore/Models/DynamoModel.cs
Outdated
@@ -1852,7 +1864,10 @@ private void SetPeriodicEvaluation(WorkspaceModel ws) | |||
bool forceManualExecutionMode, | |||
out WorkspaceModel workspace) | |||
{ | |||
CustomNodeManager.AddUninitializedCustomNodesInPath(Path.GetDirectoryName(filePath), IsTestMode); | |||
if (!String.IsNullOrEmpty(filePath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is good to do, though unnecessary as ScanNodeHeadersInDirectory
already checks the directory exists and logs something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will remove
Looks good @BogdanZavu -
|
LGTM @BogdanZavu with test from Mike's comment |
@@ -1852,7 +1864,10 @@ private void SetPeriodicEvaluation(WorkspaceModel ws) | |||
bool forceManualExecutionMode, | |||
out WorkspaceModel workspace) | |||
{ | |||
CustomNodeManager.AddUninitializedCustomNodesInPath(Path.GetDirectoryName(filePath), IsTestMode); | |||
if (!string.IsNullOrEmpty(filePath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this check back because Path.GetDirectoryName throws when filePath is null.
{ | ||
// Log file open action and the number of nodes in the opened workspace | ||
Dynamo.Logging.Analytics.TrackFileOperationEvent( | ||
dynamoModel.CurrentWorkspace.Name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use something else here since Name will be an empty string ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this match the implementation/result for disk based file open?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I see, the other uses filepath - maybe something that notes this is in memory open.
@mjkkirschner @saintentropy I added a command as well to be more inline with the regular OpenFileCommand and to benefit from the AskForSave utility on the Dynamo side. Please take another look |
@@ -144,6 +144,9 @@ internal static RecordableCommand Deserialize(XmlElement element) | |||
case "OpenFileCommand": | |||
command = OpenFileCommand.DeserializeCore(element); | |||
break; | |||
case "OpenFileFromJsonCommand": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use nameof?
errorMsgString = String.Format(Resources.MessageUnkownErrorOpeningFile, "Json file content"); | ||
} | ||
model.Logger.LogNotification("Dynamo", commandString, errorMsgString, e.ToString()); | ||
System.Windows.MessageBox.Show(errorMsgString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to use the new themed dialog box where possible - @QilongTang @RobertGlobant20 can you point to an example of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refer to this PR: https://github.com/DynamoDS/Dynamo/pull/12655/files
@@ -1541,17 +1633,42 @@ private bool CanOpen(object parameters) | |||
return PathHelper.IsValidPath(filePath); | |||
} | |||
|
|||
private bool CanOpenFromJson(object parameters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about reusing this helper?
Dynamo/src/DynamoUtilities/PathHelper.cs
Line 136 in ad0dcca
public static bool isValidJson(string path, out string fileContents, out Exception ex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reuse the helper, I put a lot of thoughts into it.. Feel free to update as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -52,6 +52,8 @@ private static void RegisterDebugModes() | |||
|
|||
internal static void LoadDebugModesStatusFromConfig(string configPath) | |||
{ | |||
if (!File.Exists(configPath)) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Purpose
Allow a workspace to be created from json content.
In Generative Design, we often work with multiple variants of the same graph for which currently we save a file on disk.
We want to avoid this as it is more efficient t work with the file content directly.
Declarations
Check these if you believe they are true
*.resx
filesReviewers
@mjkkirschner @saintentropy
FYIs