Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Lots of changes to json editor. (See desc)
Browse files Browse the repository at this point in the history
- Added right click context menu for tabs
- added middle click close for tabs
- changed tab arrays to lists (much better)
  • Loading branch information
Gurrenm3 authored and Gurrenm3 committed Mar 30, 2020
1 parent f6b9f71 commit acc469d
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 187 deletions.
32 changes: 12 additions & 20 deletions BTDToolbox/Classes/JsonEditorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public static void ValidateEditor()
if (jeditor == null)
{
jeditor = new New_JsonEditor();
jeditor.userControls = new JsonEditor_Instance[0];
jeditor.tabPages = new TabPage[0];
jeditor.tabFilePaths = new string[0];
jeditor.tabPages = new List<TabPage>();
jeditor.tabFilePaths = new List<string>();
jeditor.userControls = new List<JsonEditor_Instance>();
jeditor.Show();
}
else if (jeditor.Visible == false)
Expand All @@ -33,19 +33,11 @@ public static void OpenFile(string path)
if (Serializer.Deserialize_Config().useExternalEditor == false)
{
ValidateEditor();

int i = 0;
bool isFileOpened = false;
foreach (string tp in jeditor.tabFilePaths)
if(jeditor.tabFilePaths.Contains(path))
{
if (path == tp)
{
isFileOpened = true;
jeditor.tabControl1.SelectedTab = jeditor.tabPages[i];
}
i++;
jeditor.tabControl1.SelectedIndex = jeditor.tabFilePaths.IndexOf(path);
}
if (!isFileOpened)
else
{
jeditor.NewTab(path);
}
Expand All @@ -54,16 +46,16 @@ public static void OpenFile(string path)
public static void OpenOriginalFile(string path)
{
string[] split = path.Split('\\');
string filename = split[split.Length - 1];
string backupProj = Environment.CurrentDirectory + "\\Backups\\" + Main.gameName + "_BackupProject\\" + path.Replace(Environment.CurrentDirectory,"").Replace(Serializer.Deserialize_Config().LastProject + "\\", "");
string backupProj = "";
if (!path.Contains("\\Backups\\" + Main.gameName + "_BackupProject\\"))
backupProj = Environment.CurrentDirectory + "\\Backups\\" + Main.gameName + "_BackupProject\\" + path.Replace(Environment.CurrentDirectory, "").Replace(Serializer.Deserialize_Config().LastProject + "\\", "");
else
backupProj = path;

if (File.Exists(backupProj))
{
OpenFile(backupProj);
}
else
{
ConsoleHandler.appendLog_CanRepeat("Could not find file in backup project... Unable to view original file");
}
}
public static void CloseFile(string path)
{
Expand Down
2 changes: 1 addition & 1 deletion BTDToolbox/Classes/ProjectConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class ConfigFile
public int JSON_Editor_PosX { get; set; }
public int JSON_Editor_PosY { get; set; }
public float JSON_Editor_FontSize { get; set; }
public string[] JsonEditor_OpenedTabs { get; set; }
public List<string> JsonEditor_OpenedTabs { get; set; }
}
}
}
6 changes: 4 additions & 2 deletions BTDToolbox/Classes/SerializeOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ public static void SaveJSONEditor_Instance(JsonEditor_Instance jeditor, ConfigFi
public static void SaveJSONEditor_Tabs(ConfigFile cfg)
{
if (JsonEditorHandler.jeditor != null)
{
cfg.JsonEditor_OpenedTabs = JsonEditorHandler.jeditor.tabFilePaths;
}
else
cfg.JsonEditor_OpenedTabs = new string[0];
cfg.JsonEditor_OpenedTabs = new List<string>();

string output_Cfg = JsonConvert.SerializeObject(cfg, Formatting.Indented);

Expand Down Expand Up @@ -170,7 +172,7 @@ public static ConfigFile Deserialize_Config()
programData.useExternalEditor = false;
programData.disableUpdates = false;

programData.JsonEditor_OpenedTabs = new string[0];
programData.JsonEditor_OpenedTabs = new List<string>();


programData.BTD5_Directory = "";
Expand Down
7 changes: 3 additions & 4 deletions BTDToolbox/JetForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public JetForm(DirectoryInfo dirInfo, Main Form, string projName)

if (projName == Serializer.Deserialize_Config().LastProject)
{
if (Serializer.Deserialize_Config().JsonEditor_OpenedTabs.Length > 0)
if (Serializer.Deserialize_Config().JsonEditor_OpenedTabs.Count > 0)
{
DialogResult dialogResult = MessageBox.Show("Do you want to re-open your previous files?", "Reopen previous files?", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
Expand All @@ -56,14 +56,14 @@ public JetForm(DirectoryInfo dirInfo, Main Form, string projName)
}
else
{
programData.JsonEditor_OpenedTabs = new string[0];
programData.JsonEditor_OpenedTabs = new List<string>();
Serializer.SaveJSONEditor_Tabs(programData);
}
}
}
else
{
programData.JsonEditor_OpenedTabs = new string[0];
programData.JsonEditor_OpenedTabs = new List<string>();
Serializer.SaveJSONEditor_Tabs(programData);
}

Expand Down Expand Up @@ -752,7 +752,6 @@ private void paste()
private void restoreOriginal()
{
string filepath = this.Text + "\\" + listView1.SelectedItems[0].Text;

if (listView1.SelectedItems.Count == 1)
{
if(listView1.SelectedItems[0].Text.Contains("."))
Expand Down
57 changes: 40 additions & 17 deletions BTDToolbox/JsonEditor_Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ private void Editor_TextBox_RightClicked(object sender, MouseEventArgs e)
}
}
}

private void ShowFindMenu_Button_Click(object sender, EventArgs e)
{
if (Find_Panel.Visible == false)
Expand All @@ -721,7 +720,6 @@ private void ShowFindMenu_Button_Click(object sender, EventArgs e)
FindText();

}

private void ShowReplaceMenu_Button_Click(object sender, EventArgs e)
{
if (Find_Panel.Visible == false)
Expand Down Expand Up @@ -753,37 +751,62 @@ private void EZCard_Button_Click(object sender, EventArgs e)

private void RestoreToOriginal_Button_Click(object sender, EventArgs e)
{
string backupProj = Environment.CurrentDirectory + "\\Backups\\" + Main.gameName + "_BackupProject\\" + path.Replace(Environment.CurrentDirectory, "").Replace("\\" + Serializer.Deserialize_Config().LastProject + "\\", "");
if (File.Exists(backupProj))
RestoreToOriginal();
}
public void RestoreToOriginal()
{
if (!filename.EndsWith("_original"))
{
if (!filename.Contains("_original"))
DialogResult diag = MessageBox.Show("You are trying to restore this file to the original unmodded version. Are you sure you want to do this?", "Restore to original?", MessageBoxButtons.YesNo);
if (diag == DialogResult.Yes)
{
if (path.Contains("."))
string backupProj = Environment.CurrentDirectory + "\\Backups\\" + Main.gameName + "_BackupProject\\" + path.Replace(Environment.CurrentDirectory, "").Replace("\\" + Serializer.Deserialize_Config().LastProject + "\\", "");
if (File.Exists(backupProj))
{
if (File.Exists(path))
if (path.Contains("."))
{
JsonEditorHandler.CloseFile(path);
File.Delete(path);
if (File.Exists(path))
{
JsonEditorHandler.CloseFile(path);
File.Delete(path);
}
File.Copy(backupProj, path);
JsonEditorHandler.OpenFile(path);
ConsoleHandler.appendLog_CanRepeat(filename + "has been restored");
}
File.Copy(backupProj, path);
JsonEditorHandler.OpenFile(path);
ConsoleHandler.appendLog_CanRepeat(filename + "has been restored");
}
else
{
ConsoleHandler.appendLog_CanRepeat("Could not find file in backup project... Unable to restore file");
}
}
else
{
ConsoleHandler.appendLog_CanRepeat("User cancelled restore");
}
}
else
{
ConsoleHandler.appendLog_CanRepeat("Could not find file in backup project... Unable to restore file");
}
ConsoleHandler.appendLog_CanRepeat("You can't restore the backup to original because it IS the original");
}
}

private void OpenInFileExplorerToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenInFileExplorer();
}
public void OpenInFileExplorer()
{
string[] split = path.Split('\\');
string foldername = path.Replace(split[split.Length - 1], "");
Process.Start(foldername);
if(!foldername.Contains("BackupProject"))
{
Process.Start(foldername);
}
else
{
ConsoleHandler.appendNotice("Operation cancelled. We don't want you to edit the backup on accident... If you really need to look at it, you can find it in the Backups folder");
}
}

private void ViewOriginalToolStripMenuItem_Click(object sender, EventArgs e)
{
JsonEditorHandler.OpenOriginalFile(path);
Expand Down
1 change: 1 addition & 0 deletions BTDToolbox/New_JsonEditor.Designer.cs

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

Loading

0 comments on commit acc469d

Please sign in to comment.