Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit 711d508

Browse files
reworked settings dialog
1 parent 6002757 commit 711d508

3 files changed

Lines changed: 187 additions & 76 deletions

File tree

NppGZipFileViewer/Forms/SettingsDialog.Designer.cs

Lines changed: 83 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 101 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Drawing;
3+
using System.IO;
34
using System.Linq;
45
using System.Windows.Forms;
6+
using System.Xml.Serialization;
57

68
namespace NppGZipFileViewer.Forms
79
{
@@ -13,34 +15,120 @@ public SettingsDialog()
1315
Icon = Icon.FromHandle(NppGZipFileViewer.Properties.Resources.gzip_filled64.GetHicon());
1416
}
1517

16-
private void btn_Add_Click(object sender, EventArgs e)
17-
{
18-
lst_Suffixes.Items.Add(txt_Suffix.Text);
19-
txt_Suffix.Text = "";
20-
}
2118

22-
private void btn_Delete_Click(object sender, EventArgs e)
23-
{
24-
if (lst_Suffixes.SelectedIndex >= 0)
25-
lst_Suffixes.Items.RemoveAt(lst_Suffixes.SelectedIndex);
26-
}
19+
Preferences preferences;
2720

2821
public Preferences Preferences
29-
{
22+
{// ToDo:
3023
get
3124
{
32-
return new Preferences(chk_DecompressAll.Checked, lst_Suffixes.Items.Cast<string>());
25+
preferences.DecompressAll = chk_DecompressAll.Checked;
26+
preferences.CompressionAlgorithms.Clear();
27+
28+
foreach (var chkCompr in chkListBoxCompressionAlg.CheckedItems)
29+
preferences.CompressionAlgorithms.Add(chkCompr as string);
30+
31+
return preferences;
3332
}
3433
set
3534
{
35+
// clone preferences
36+
preferences = Clone(value);
3637
chk_DecompressAll.Checked = value.DecompressAll;
37-
lst_Suffixes.Items.AddRange(value.Extensions.ToArray());
38+
//lst_Suffixes.Items.AddRange(value.Extensions.ToArray());
39+
40+
var checkedItems = value.CompressionAlgorithms.ToArray();
41+
var uncheckedItems = value.EnumerateCompressions().Select(alg => alg.CompressionAlgorithm).Where(name => !checkedItems.Contains(name)).ToArray();
42+
43+
chkListBoxCompressionAlg.Items.AddRange(checkedItems);
44+
chkListBoxCompressionAlg.Items.AddRange(uncheckedItems);
45+
46+
for (int i = 0; i < checkedItems.Length; i++)
47+
SetItemCheckState(i, CheckState.Checked);
48+
for (int i = 0; i < uncheckedItems.Length; i++)
49+
SetItemCheckState(i + checkedItems.Length, CheckState.Unchecked);
3850
}
3951
}
4052

53+
private Preferences Clone(Preferences value)
54+
{
55+
// Since Preferences is serializable;
56+
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Preferences));
57+
using MemoryStream memoryStream = new();
58+
xmlSerializer.Serialize(memoryStream, value);
59+
memoryStream.Seek(0, SeekOrigin.Begin);
60+
return xmlSerializer.Deserialize(memoryStream) as Preferences;
61+
}
62+
4163
~SettingsDialog()
4264
{
4365
Icon.Dispose();
4466
}
67+
68+
private void SettingsDialog_Load(object sender, EventArgs e)
69+
{
70+
toolTip1.SetToolTip(chkListBoxCompressionAlg, "Changes the order of the compression algorithmns. \n" +
71+
"Only effects 'Toogle Compression'. To disable a compression remove the file association, too");
72+
73+
toolTip1.SetToolTip(chk_DecompressAll, "If set all files will be decompressed regardless of the suffix.");
74+
75+
76+
}
77+
78+
void SetItemCheckState(int index, CheckState checkState)
79+
{
80+
chkListBoxCompressionAlg.SetItemCheckState(index, checkState);
81+
}
82+
83+
private void ComprSettingsClick(object sender, EventArgs e)
84+
{
85+
switch (chkListBoxCompressionAlg.SelectedItem)
86+
{
87+
case "gzip":
88+
GZipSettingsDialog gZipSettingsDialog = new GZipSettingsDialog();
89+
gZipSettingsDialog.GZipSettings = Preferences.GZipSettings;
90+
if (gZipSettingsDialog.ShowDialog() == DialogResult.OK)
91+
Preferences.GZipSettings = gZipSettingsDialog.GZipSettings;
92+
break;
93+
case "bzip2":
94+
BZip2SettingsDialog bZip2SettingsDialog = new BZip2SettingsDialog();
95+
bZip2SettingsDialog.BZip2Settings = Preferences.BZip2Settings;
96+
if (bZip2SettingsDialog.ShowDialog() == DialogResult.OK)
97+
Preferences.BZip2Settings = bZip2SettingsDialog.BZip2Settings;
98+
break;
99+
}
100+
}
101+
102+
private void chkListBoxCompressionAlg_SelectedIndexChanged(object sender, EventArgs e)
103+
{
104+
btnSettings.Enabled = chkListBoxCompressionAlg.SelectedIndex >= 0;
105+
btnUp.Enabled = chkListBoxCompressionAlg.SelectedIndex > 0;
106+
btnDown.Enabled = chkListBoxCompressionAlg.SelectedIndex >= 0 &&
107+
chkListBoxCompressionAlg.SelectedIndex < (chkListBoxCompressionAlg.Items.Count - 1);
108+
}
109+
110+
private void btnUp_Click(object sender, EventArgs e)
111+
{
112+
(chkListBoxCompressionAlg.Items[chkListBoxCompressionAlg.SelectedIndex],
113+
chkListBoxCompressionAlg.Items[chkListBoxCompressionAlg.SelectedIndex - 1]) =
114+
(chkListBoxCompressionAlg.Items[chkListBoxCompressionAlg.SelectedIndex - 1],
115+
chkListBoxCompressionAlg.Items[chkListBoxCompressionAlg.SelectedIndex]);
116+
chkListBoxCompressionAlg.SelectedIndex = chkListBoxCompressionAlg.SelectedIndex - 1;
117+
}
118+
119+
private void btnDown_Click(object sender, EventArgs e)
120+
{
121+
(chkListBoxCompressionAlg.Items[chkListBoxCompressionAlg.SelectedIndex],
122+
chkListBoxCompressionAlg.Items[chkListBoxCompressionAlg.SelectedIndex + 1]) =
123+
(chkListBoxCompressionAlg.Items[chkListBoxCompressionAlg.SelectedIndex + 1],
124+
chkListBoxCompressionAlg.Items[chkListBoxCompressionAlg.SelectedIndex]);
125+
chkListBoxCompressionAlg.SelectedIndex = chkListBoxCompressionAlg.SelectedIndex + 1;
126+
}
127+
128+
private void btnDefault_Click(object sender, EventArgs e)
129+
{
130+
if (MessageBox.Show("This will reset ALL settings.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
131+
this.Preferences = Preferences.Default;
132+
}
45133
}
46134
}

NppGZipFileViewer/Forms/SettingsDialog.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121+
<value>17, 17</value>
122+
</metadata>
120123
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
121124
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
122125
<value>

0 commit comments

Comments
 (0)