Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fixed brainfart
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogFeelings committed May 23, 2021
1 parent f918dd5 commit ed87bd4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 42 deletions.
18 changes: 9 additions & 9 deletions ButtonEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,21 +22,21 @@ 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;
}

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)
Expand All @@ -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!";
Expand Down Expand Up @@ -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!";
Expand Down
1 change: 0 additions & 1 deletion DLH.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<SubType>Form</SubType>
</Compile>
<Compile Include="DLHEntry.cs" />
<Compile Include="GlobalExchange.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
24 changes: 0 additions & 24 deletions GlobalExchange.cs

This file was deleted.

18 changes: 10 additions & 8 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public partial class MainForm : Form
public bool PerformingDeletion = false;
public int? PreviousIndex = null;

public List<DLHEntry> dlhEntries = new List<DLHEntry>();

public MainForm()
{
InitializeComponent();
Expand All @@ -35,15 +37,15 @@ public void LoadEntries()
}

//Load the entries.
GlobalExchange.Inst.dlhEntries = JsonConvert.DeserializeObject<List<DLHEntry>>(File.ReadAllText(EntryJson));
dlhEntries = JsonConvert.DeserializeObject<List<DLHEntry>>(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;
}
}
Expand All @@ -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 });
Expand All @@ -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;
}
Expand Down

0 comments on commit ed87bd4

Please sign in to comment.