MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / NewItem

Method NewItem

Source/Editor/Windows/ContentWindow.cs:996–1072  ·  view source on GitHub ↗

Starts creating new item. The new item proxy. The argument passed to the proxy for the item creation. In most cases it is null. The event called when the item is crated by the user. The argument is the new item. The initial item name. <param name="withRena

(ContentProxy proxy, object argument = null, Action<ContentItem> created = null, string initialName = null, bool withRenaming = true)

Source from the content-addressed store, hash-verified

994 /// <param name="initialName">The initial item name.</param>
995 /// <param name="withRenaming">True if start initial item renaming by user, or tru to skip it.</param>
996 public void NewItem(ContentProxy proxy, object argument = null, Action<ContentItem> created = null, string initialName = null, bool withRenaming = true)
997 {
998 Assert.IsNull(_newElement);
999 if (proxy == null)
1000 throw new ArgumentNullException(nameof(proxy));
1001
1002 // Setup name
1003 string name = initialName ?? proxy.NewItemName;
1004 if (!proxy.IsFileNameValid(name) || Utilities.Utils.HasInvalidPathChar(name))
1005 name = proxy.NewItemName;
1006
1007 // If the proxy can not be created in the current folder, then navigate to the content folder
1008 if (!proxy.CanCreate(CurrentViewFolder))
1009 Navigate(Editor.Instance.ContentDatabase.Game.Content);
1010
1011 ContentFolder parentFolder = CurrentViewFolder;
1012 string parentFolderPath = parentFolder.Path;
1013
1014 // Create asset name
1015 string extension = '.' + proxy.FileExtension;
1016 string path = StringUtils.CombinePaths(parentFolderPath, name + extension);
1017 if (parentFolder.FindChild(path) != null)
1018 {
1019 int i = 0;
1020 do
1021 {
1022 path = StringUtils.CombinePaths(parentFolderPath, string.Format("{0} {1}", name, i++) + extension);
1023 } while (parentFolder.FindChild(path) != null);
1024 }
1025
1026 if (withRenaming)
1027 {
1028 // Create new asset proxy, add to view and rename it
1029 _newElement = new NewItem(path, proxy, argument)
1030 {
1031 ParentFolder = parentFolder,
1032 Tag = created,
1033 };
1034 RefreshView();
1035 Rename(_newElement);
1036 }
1037 else
1038 {
1039 // Create new asset
1040 try
1041 {
1042 Editor.Log(string.Format("Creating asset {0} in {1}", proxy.Name, path));
1043 proxy.Create(path, argument);
1044 }
1045 catch (Exception ex)
1046 {
1047 Editor.LogWarning(ex);
1048 Editor.LogError("Failed to create asset.");
1049 return;
1050 }
1051
1052 // Focus content window
1053 Focus();

Callers

nothing calls this directly

Calls 13

FocusFunction · 0.85
IsNullMethod · 0.80
HasInvalidPathCharMethod · 0.80
CombinePathsMethod · 0.80
FindChildMethod · 0.80
FormatMethod · 0.80
RefreshFolderMethod · 0.80
IsFileNameValidMethod · 0.45
CanCreateMethod · 0.45
LogMethod · 0.45
CreateMethod · 0.45
LogWarningMethod · 0.45

Tested by

no test coverage detected