Hello, I'm working on a file manager. One of the rules is that you can't have duplicate names. I have written the code to give me a unique name just fine. And I'm using it:
1- each time I create a new folder/file.
2- after I submit the changes to a file/folder's name (inside OnSubmit(string name))
Problem is, you see whenever I create a new folder, I give my input 'selected = true' so that I can name a folder right after I create it, BUT if I deselect the input (click elsewhere), OnSubmit doesn't seem to trigger, instead OnSelect(false) is what's being called, and then I can end up with multiple folders having the same name (due to mDefaultText). (See attachment) So I should also inject my code in there as well, specifically:
if (string.IsNullOrEmpty(mText))
{
label.text = mDefaultText;
// TODO: INJECT
//
here...
//
label.color = mDefaultColor;
if (isPassword) label.password = false;
}
else label.text = mText;
I tried inserting a call to 'onSubmit(label.text);' because I do have my code there - but I got an exception onSubmit is null
Can I assign onSubmit somehow? Or do I have to make my own custom inherited UIInput and then override OnSelect?
Thanks
And here's my code if somebody wants to benefit
(I give it the names of all the contents of the current folder, and the name I'm trying to name a certain file/folder with and it gives me back a unique name for that file/folder, in the fashion of file_N, file_N+1, ... file_N+n. Just like MS Windows)
public static string GetUniqueName(List<string> names, string name)
{
int index = MiscOps.LinearSearch(names.ToArray(), name);
if (index == -1)
return name;
if (!name.Contains("_"))
return GetUniqueName(names, name + "_0");
short n;
string postfix = name.Substring(name.LastIndexOf('_') + 1);
bool isNum = Int16.TryParse(postfix, out n);
if (!isNum)
return GetUniqueName(names, name + "_0");
int postfixNum = Convert.ToInt16(postfix);
postfixNum++;
name = name.Substring(0, name.LastIndexOf('_') + 1);
name += postfixNum.ToString();
return GetUniqueName(names, name);
}