diff --git a/ButtonEvents.cs b/ButtonEvents.cs index 98e237e..c11f3d6 100644 --- a/ButtonEvents.cs +++ b/ButtonEvents.cs @@ -13,7 +13,7 @@ private void deleteButton_Click(object sender, EventArgs e) PerformingDeletion = true; foreach (ListViewItem item in entryList.SelectedItems) { - GlobalExchange.Inst.dlhEntries.RemoveAt(item.Index); + dlhEntries.RemoveAt(item.Index); entryList.Items.Remove(item); } PerformingDeletion = false; @@ -22,13 +22,13 @@ private void deleteButton_Click(object sender, EventArgs e) private void saveButton_Click(object sender, EventArgs e) { - if (GlobalExchange.Inst.dlhEntries.Count == 0) + if (dlhEntries.Count == 0) { MessageBox.Show("Entry list is empty!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - string serializedJson = JsonConvert.SerializeObject(GlobalExchange.Inst.dlhEntries, Formatting.Indented); + string serializedJson = JsonConvert.SerializeObject(dlhEntries, Formatting.Indented); File.WriteAllText(EntryJson, serializedJson); this.Text = WindowName; @@ -36,7 +36,7 @@ private void saveButton_Click(object sender, EventArgs e) private void copyButton_Click(object sender, EventArgs e) { - Clipboard.SetText(GlobalExchange.Inst.dlhEntries[entryList.SelectedIndices[0]].Link); + Clipboard.SetText(dlhEntries[entryList.SelectedIndices[0]].Link); } private void newButton_Click(object sender, EventArgs e) @@ -52,7 +52,7 @@ private void newButton_Click(object sender, EventArgs e) Link = newForm.linkBox.Text, Notes = newForm.notesBox.Text }; - GlobalExchange.Inst.dlhEntries.Add(newEntry); + dlhEntries.Add(newEntry); RemakeListView(); newForm.Close(); this.Text = WindowName + " - Unsaved!"; @@ -102,10 +102,10 @@ private void editButton_Click(object sender, EventArgs e) if (entryList.SelectedIndices.Count > 0) { int itemIndex = entryList.SelectedIndices[0]; - GlobalExchange.Inst.dlhEntries[entryList.SelectedIndices[0]].Name = nameBox.Text; - GlobalExchange.Inst.dlhEntries[entryList.SelectedIndices[0]].Link = linkBox.Text; - GlobalExchange.Inst.dlhEntries[entryList.SelectedIndices[0]].Notes = notesBox.Text; - GlobalExchange.Inst.dlhEntries[entryList.SelectedIndices[0]].Type = typeBox.SelectedIndex; + dlhEntries[entryList.SelectedIndices[0]].Name = nameBox.Text; + dlhEntries[entryList.SelectedIndices[0]].Link = linkBox.Text; + dlhEntries[entryList.SelectedIndices[0]].Notes = notesBox.Text; + dlhEntries[entryList.SelectedIndices[0]].Type = typeBox.SelectedIndex; RemakeListView(); entryList.Items[itemIndex].Selected = true; this.Text = WindowName + " - Unsaved!"; diff --git a/DLH.csproj b/DLH.csproj index 96b3a80..0194a46 100644 --- a/DLH.csproj +++ b/DLH.csproj @@ -62,7 +62,6 @@ Form - Form diff --git a/GlobalExchange.cs b/GlobalExchange.cs deleted file mode 100644 index 414f572..0000000 --- a/GlobalExchange.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DLH -{ - public class GlobalExchange - { - private static GlobalExchange _Instance; - - public List dlhEntries = new List(); - - public static GlobalExchange Inst - { - get - { - if (_Instance == null) _Instance = new GlobalExchange(); - return _Instance; - } - } - } -} diff --git a/MainForm.cs b/MainForm.cs index ae40630..eff4464 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -15,6 +15,8 @@ public partial class MainForm : Form public bool PerformingDeletion = false; public int? PreviousIndex = null; + public List dlhEntries = new List(); + public MainForm() { InitializeComponent(); @@ -35,15 +37,15 @@ public void LoadEntries() } //Load the entries. - GlobalExchange.Inst.dlhEntries = JsonConvert.DeserializeObject>(File.ReadAllText(EntryJson)); + dlhEntries = JsonConvert.DeserializeObject>(File.ReadAllText(EntryJson)); //Check if an entry is corrupted. bool hadToDelete = false; - foreach(DLHEntry entry in GlobalExchange.Inst.dlhEntries.ToList()) + foreach(DLHEntry entry in dlhEntries.ToList()) { if(entry.Name == string.Empty || entry.Link == string.Empty || entry.Type > 1 || entry.Type < 0) { - GlobalExchange.Inst.dlhEntries.Remove(entry); + dlhEntries.Remove(entry); hadToDelete = true; } } @@ -61,7 +63,7 @@ public void LoadEntries() public void RemakeListView() { entryList.Items.Clear(); - foreach (DLHEntry entry in GlobalExchange.Inst.dlhEntries) + foreach (DLHEntry entry in dlhEntries) { string entryType = entry.Type == 0 ? "Video" : "GIF"; ListViewItem item = new ListViewItem(new[] { entry.Name, entryType, entry.Notes }); @@ -75,10 +77,10 @@ private void entryListChanged(object sender, EventArgs e) if (entryList.SelectedIndices.Count > 0) { if (PerformingDeletion == true) return; - this.nameBox.Text = GlobalExchange.Inst.dlhEntries[entryList.SelectedIndices[0]].Name; - this.linkBox.Text = GlobalExchange.Inst.dlhEntries[entryList.SelectedIndices[0]].Link; - this.notesBox.Text = GlobalExchange.Inst.dlhEntries[entryList.SelectedIndices[0]].Notes; - this.typeBox.SelectedIndex = GlobalExchange.Inst.dlhEntries[entryList.SelectedIndices[0]].Type; + this.nameBox.Text = dlhEntries[entryList.SelectedIndices[0]].Name; + this.linkBox.Text = dlhEntries[entryList.SelectedIndices[0]].Link; + this.notesBox.Text = dlhEntries[entryList.SelectedIndices[0]].Notes; + this.typeBox.SelectedIndex = dlhEntries[entryList.SelectedIndices[0]].Type; } else return; }