private void selectJsonFileDialog_FileOk(object sender, CancelEventArgs e)
{
string filePath = selectJsonFileDialog.FileName;
if (filePath == null)
{
return;
}
filePath = JsonHelper.NormalizeSystemPath(filePath);
Module selectedMod = selectJsonFileDialog.Tag as Module;
if (!filePath.Contains(selectedMod.Path))
{
MessageBox.Show("The file must be under the directory " + selectedMod.Path);
return;
}
mLastModuleLocations[selectedMod.Name] = filePath;
string shortPath = filePath.Replace(selectedMod.Path + "/", "");
string[] pathSplit = shortPath.Split('/');
string samplePath = string.Empty;
for (int i = 1; i < (pathSplit.Length - 1); ++i)
{
if (string.IsNullOrEmpty(samplePath))
{
samplePath = pathSplit[i];
}
else
{
samplePath = samplePath + ':' + pathSplit[i];
}
}
if (pathSplit.Length > 2)
{
// Make the file path not contain the .json part if it doesn't have to
string fileName = pathSplit[pathSplit.Length - 1];
string extension = System.IO.Path.GetExtension(fileName);
if (extension == ".json")
{
string folder = pathSplit[pathSplit.Length - 2];
if (folder.Equals(System.IO.Path.GetFileNameWithoutExtension(fileName)))
{
shortPath = shortPath.Replace("/" + fileName, "");
}
}
else if (extension == ".lua")
{
string nameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName);
if (nameWithoutExtension.EndsWith("_action"))
{
nameWithoutExtension = nameWithoutExtension.Substring(0, nameWithoutExtension.Length - 7);
samplePath = samplePath + ':' + nameWithoutExtension;
}
}
}
NewAliasCallback callback = new NewAliasCallback(this, selectedMod, shortPath);
InputDialog dialog = new InputDialog("Add New Alias", "Type the name of the alias for " + filePath, samplePath, "Add!");
dialog.SetCallback(callback);
dialog.ShowDialog();
}