Skip to content

Commit 57be93b

Browse files
committed
moved options to their own class
1 parent 494d1bd commit 57be93b

9 files changed

+337
-316
lines changed

Z-Chat/ActivityWindow.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ public ActivityWindow(Chat zchat)
114114

115115
private void SetRestoreType()
116116
{
117-
if (ZChat.RestoreType == ClickRestoreType.SingleClick)
117+
if (ZChat.Options.RestoreType == ClickRestoreType.SingleClick)
118118
{
119119
notifyIcon.DoubleClick -= notifyClickHandler;
120120
notifyIcon.Click += notifyClickHandler;
121121
}
122-
else if (ZChat.RestoreType == ClickRestoreType.DoubleClick)
122+
else if (ZChat.Options.RestoreType == ClickRestoreType.DoubleClick)
123123
{
124124
notifyIcon.Click -= notifyClickHandler;
125125
notifyIcon.DoubleClick += notifyClickHandler;

Z-Chat/ChannelWindow.xaml.cs

+64-64
Large diffs are not rendered by default.

Z-Chat/ChatWindow.cs

+17-17
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public ChatWindow(Chat zchat) : base(zchat)
6969
{
7070
ZChat.PropertyChanged += ZChat_PropertyChanged;
7171

72-
HyperlinkRegex = new Regex(ZChat.HyperlinkPattern, RegexOptions.Compiled);
72+
HyperlinkRegex = new Regex(ZChat.Options.HyperlinkPattern, RegexOptions.Compiled);
7373
EntryHistory.Add("");
7474

7575
Loaded += ChatWindow_Loaded;
@@ -79,17 +79,17 @@ public ChatWindow(Chat zchat) : base(zchat)
7979
void ZChat_PropertyChanged(object sender, PropertyChangedEventArgs e)
8080
{
8181
if (e.PropertyName == "EntryBack")
82-
InputBox.Background = ZChat.EntryBack;
82+
InputBox.Background = ZChat.Options.EntryBack;
8383
if (e.PropertyName == "EntryFore")
84-
InputBox.Foreground = ZChat.EntryFore;
84+
InputBox.Foreground = ZChat.Options.EntryFore;
8585
if (e.PropertyName == "ChatBack")
86-
Document.Background = ZChat.ChatBack;
86+
Document.Background = ZChat.Options.ChatBack;
8787
if (e.PropertyName == "HyperlinkPattern")
88-
HyperlinkRegex = new Regex(ZChat.HyperlinkPattern, RegexOptions.Compiled);
88+
HyperlinkRegex = new Regex(ZChat.Options.HyperlinkPattern, RegexOptions.Compiled);
8989
if (e.PropertyName == "Font")
9090
{
91-
InputBox.FontFamily = ZChat.Font;
92-
Document.FontFamily = ZChat.Font;
91+
InputBox.FontFamily = ZChat.Options.Font;
92+
Document.FontFamily = ZChat.Options.Font;
9393
}
9494
}
9595

@@ -100,11 +100,11 @@ void ChatWindow_Activated(object sender, EventArgs e)
100100

101101
private void ChatWindow_Loaded(object sender, RoutedEventArgs e)
102102
{
103-
InputBox.Background = ZChat.EntryBack;
104-
InputBox.Foreground = ZChat.EntryFore;
105-
Document.Background = ZChat.ChatBack;
106-
InputBox.FontFamily = ZChat.Font;
107-
Document.FontFamily = ZChat.Font;
103+
InputBox.Background = ZChat.Options.EntryBack;
104+
InputBox.Foreground = ZChat.Options.EntryFore;
105+
Document.Background = ZChat.Options.ChatBack;
106+
InputBox.FontFamily = ZChat.Options.Font;
107+
Document.FontFamily = ZChat.Options.Font;
108108

109109
InputBox.Focus();
110110
}
@@ -240,7 +240,7 @@ public void Output(ColorTextPair[] sourcePairs, ColorTextPair[] textPairs)
240240
Document.Blocks.Remove(Document.Blocks.FirstBlock);
241241

242242
string timeStamp;
243-
timeStamp = DateTime.Now.ToString(ZChat.TimeStampFormat);
243+
timeStamp = DateTime.Now.ToString(ZChat.Options.TimeStampFormat);
244244
TimeSourceTextGroup group = new TimeSourceTextGroup(timeStamp, sourcePairs, textPairs);
245245

246246
Dispatcher.BeginInvoke(new VoidDelegate(delegate
@@ -269,12 +269,12 @@ public void AddOutput(TimeSourceTextGroup group)
269269

270270
Span timeSourceSpan = new Span();
271271
Run timeRun = new Run(group.Time);
272-
timeRun.Foreground = ZChat.TimeFore;
272+
timeRun.Foreground = ZChat.Options.TimeFore;
273273
p.Inlines.Add(timeRun);
274274

275275
ColorTextPair[] allPairs = new ColorTextPair[group.Source.Length + 1 + group.Text.Length];
276276
for (int ii = 0; ii < group.Source.Length; ii++) allPairs[ii] = group.Source[ii];
277-
allPairs[group.Source.Length] = new ColorTextPair(ZChat.TextFore, " ");
277+
allPairs[group.Source.Length] = new ColorTextPair(ZChat.Options.TextFore, " ");
278278
for (int ii = 0; ii < group.Text.Length; ii++) allPairs[ii + group.Source.Length + 1] = group.Text[ii];
279279

280280
AddInlines(p.Inlines, allPairs, true);
@@ -299,7 +299,7 @@ public void AddInlines(InlineCollection inlineCollection, ColorTextPair[] pairs,
299299
{
300300
if (!string.IsNullOrEmpty(pair.Text))
301301
{
302-
MatchCollection matches = new Regex(ZChat.HyperlinkPattern).Matches(pair.Text);
302+
MatchCollection matches = new Regex(ZChat.Options.HyperlinkPattern).Matches(pair.Text);
303303
if (matches.Count > 0)
304304
{
305305
hasHyperlinks = true;
@@ -321,7 +321,7 @@ public void AddInlines(InlineCollection inlineCollection, ColorTextPair[] pairs,
321321
linkText = pair.Text.Substring(linkStart, linkLength);
322322

323323
Hyperlink link = new Hyperlink(new Run(linkText));
324-
link.Foreground = ZChat.LinkFore;
324+
link.Foreground = ZChat.Options.LinkFore;
325325
link.SetValue(KeyboardNavigation.IsTabStopProperty, false);
326326
//if (link.FontStyle) link.TextDecorations.Add(TextDecorations.Underline);
327327
link.Click += new RoutedEventHandler(link_Click);

Z-Chat/ConnectionWindow.xaml.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public partial class ConnectionWindow : Window
1616

1717
public ConnectionWindow(Chat zchat)
1818
{
19-
Channel = zchat.FirstChannel;
20-
Nickname = zchat.InitialNickname;
21-
Server = zchat.Server;
22-
ServerPort = zchat.ServerPort;
23-
ChannelKey = zchat.FirstChannelKey;
19+
Channel = zchat.Options.FirstChannel;
20+
Nickname = zchat.Options.InitialNickname;
21+
Server = zchat.Options.Server;
22+
ServerPort = zchat.Options.ServerPort;
23+
ChannelKey = zchat.Options.FirstChannelKey;
2424

2525
InitializeComponent();
2626
WindowStartupLocation = WindowStartupLocation.CenterOwner;

Z-Chat/Options.cs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Windows.Media;
6+
using System.ComponentModel;
7+
8+
namespace ZChat
9+
{
10+
public class ChatOptions : INotifyPropertyChanged
11+
{
12+
public string FirstChannel;
13+
public string FirstChannelKey;
14+
public string InitialNickname;
15+
public string Server;
16+
public int ServerPort;
17+
public bool SaveConnectionInfo = true;
18+
public SolidColorBrush EntryBack { get { return _entryBack; } set { _entryBack = value; FirePropertyChanged("EntryBack"); } }
19+
private SolidColorBrush _entryBack = Brushes.White;
20+
public SolidColorBrush EntryFore { get { return _entryFore; } set { _entryFore = value; FirePropertyChanged("EntryFore"); } }
21+
private SolidColorBrush _entryFore = Brushes.Black;
22+
public SolidColorBrush ChatBack { get { return _chatBack; } set { _chatBack = value; FirePropertyChanged("ChatBack"); } }
23+
private SolidColorBrush _chatBack = Brushes.White;
24+
public SolidColorBrush TimeFore = Brushes.Black;
25+
public SolidColorBrush NickFore = Brushes.Black;
26+
public SolidColorBrush BracketFore = Brushes.Black;
27+
public SolidColorBrush TextFore { get { return _textFore; } set { _textFore = value; FirePropertyChanged("TextFore"); } }
28+
public SolidColorBrush _textFore = Brushes.Black;
29+
public SolidColorBrush QueryTextFore = Brushes.Maroon;
30+
public SolidColorBrush OwnNickFore = Brushes.Green;
31+
public SolidColorBrush LinkFore { get { return _linkFore; } set { _linkFore = value; FirePropertyChanged("LinkFore"); } }
32+
public SolidColorBrush _linkFore = Brushes.Black;
33+
public SolidColorBrush UsersBack { get { return _usersBack; } set { _usersBack = value; FirePropertyChanged("UsersBack"); } }
34+
private SolidColorBrush _usersBack = Brushes.White;
35+
public SolidColorBrush UsersFore { get { return _usersFore; } set { _usersFore = value; FirePropertyChanged("UsersFore"); } }
36+
private SolidColorBrush _usersFore = Brushes.Black;
37+
public string TimeStampFormat = "HH:mm:ss ";
38+
public ClickRestoreType RestoreType { get { return _restoreType; } set { _restoreType = value; FirePropertyChanged("RestoreType"); } }
39+
private ClickRestoreType _restoreType = ClickRestoreType.SingleClick;
40+
public bool HighlightTrayIconForJoinsAndQuits = true;
41+
public FontFamily Font { get { return _font; } set { _font = value; FirePropertyChanged("Font"); } }
42+
private FontFamily _font = new FontFamily("Courier New");
43+
public bool WindowsForPrivMsgs = false;
44+
public string LastFMUserName = "";
45+
public string HyperlinkPattern { get { return _hyperlinkPattern; } set { _hyperlinkPattern = value; FirePropertyChanged("HyperlinkPattern"); } }
46+
protected string _hyperlinkPattern = "(^|[ ]|((https?|ftp):\\/\\/))(([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)|localhost|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.(com|net|org|info|biz|gov|name|edu|[a-zA-Z][a-zA-Z]))(:[0-9]+)?((\\/|\\?)[^ \"]*[^ ,;\\.:\">)])?\\)?";
47+
48+
public event PropertyChangedEventHandler PropertyChanged;
49+
protected void FirePropertyChanged(string propertyName)
50+
{
51+
if (PropertyChanged != null)
52+
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
53+
}
54+
55+
}
56+
}

Z-Chat/Options.xaml.cs

+57-57
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
3838
DataContext = this;
3939
generalTreeItem.IsSelected = true;
4040

41-
channelTextBox.Text = ZChat.FirstChannel;
42-
nickNameTextBox.Text = ZChat.InitialNickname;
43-
serverTextBox.Text = ZChat.Server;
44-
serverPortTextBox.Text = ZChat.ServerPort.ToString();
45-
channelKeyTextBox.Text = ZChat.FirstChannelKey;
41+
channelTextBox.Text = ZChat.Options.FirstChannel;
42+
nickNameTextBox.Text = ZChat.Options.InitialNickname;
43+
serverTextBox.Text = ZChat.Options.Server;
44+
serverPortTextBox.Text = ZChat.Options.ServerPort.ToString();
45+
channelKeyTextBox.Text = ZChat.Options.FirstChannelKey;
4646

47-
saveConnectionInfoCheckBox.IsChecked = ZChat.SaveConnectionInfo;
47+
saveConnectionInfoCheckBox.IsChecked = ZChat.Options.SaveConnectionInfo;
4848

49-
if (ZChat.RestoreType == ClickRestoreType.SingleClick)
49+
if (ZChat.Options.RestoreType == ClickRestoreType.SingleClick)
5050
{
5151
singleClickRestore.IsChecked = true;
5252
doubleClickRestore.IsChecked = false;
@@ -57,28 +57,28 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
5757
doubleClickRestore.IsChecked = true;
5858
}
5959

60-
joinsQuitsHighlight.IsChecked = ZChat.HighlightTrayIconForJoinsAndQuits;
61-
62-
UsersBack.Background = ZChat.UsersBack;
63-
UsersFore.Background = ZChat.UsersFore;
64-
EntryBack.Background = ZChat.EntryBack;
65-
EntryFore.Background = ZChat.EntryFore;
66-
ChatBack.Background = ZChat.ChatBack;
67-
TimeFore.Background = ZChat.TimeFore;
68-
NickFore.Background = ZChat.NickFore;
69-
BracketFore.Background = ZChat.BracketFore;
70-
TextFore.Background = ZChat.TextFore;
71-
QueryTextFore.Background = ZChat.QueryTextFore;
72-
OwnNickFore.Background = ZChat.OwnNickFore;
73-
LinkFore.Background = ZChat.LinkFore;
60+
joinsQuitsHighlight.IsChecked = ZChat.Options.HighlightTrayIconForJoinsAndQuits;
61+
62+
UsersBack.Background = ZChat.Options.UsersBack;
63+
UsersFore.Background = ZChat.Options.UsersFore;
64+
EntryBack.Background = ZChat.Options.EntryBack;
65+
EntryFore.Background = ZChat.Options.EntryFore;
66+
ChatBack.Background = ZChat.Options.ChatBack;
67+
TimeFore.Background = ZChat.Options.TimeFore;
68+
NickFore.Background = ZChat.Options.NickFore;
69+
BracketFore.Background = ZChat.Options.BracketFore;
70+
TextFore.Background = ZChat.Options.TextFore;
71+
QueryTextFore.Background = ZChat.Options.QueryTextFore;
72+
OwnNickFore.Background = ZChat.Options.OwnNickFore;
73+
LinkFore.Background = ZChat.Options.LinkFore;
7474

7575
fontsCombo.ItemsSource = Fonts.SystemFontFamilies;
76-
fontsCombo.SelectedValue = ZChat.Font.Source;
76+
fontsCombo.SelectedValue = ZChat.Options.Font.Source;
7777

78-
timeFormatBox.Text = ZChat.TimeStampFormat;
79-
windowsForPrivMsgs.IsChecked = ZChat.WindowsForPrivMsgs;
80-
lastfmUserBox.Text = ZChat.LastFMUserName;
81-
hyperlinkPatternBox.Text = ZChat.HyperlinkPattern;
78+
timeFormatBox.Text = ZChat.Options.TimeStampFormat;
79+
windowsForPrivMsgs.IsChecked = ZChat.Options.WindowsForPrivMsgs;
80+
lastfmUserBox.Text = ZChat.Options.LastFMUserName;
81+
hyperlinkPatternBox.Text = ZChat.Options.HyperlinkPattern;
8282

8383
//foreach (Plugin plugin in ZChat.LoadedScripts)
8484
// foreach (Grid pluginGrid in plugin.GetOptionGrids())
@@ -93,41 +93,41 @@ private void Cancel_Click(object sender, RoutedEventArgs e)
9393

9494
private void SaveOptions()
9595
{
96-
ZChat.FirstChannel = channelTextBox.Text;
97-
ZChat.InitialNickname = nickNameTextBox.Text;
98-
ZChat.Server = serverTextBox.Text;
99-
try { ZChat.ServerPort = int.Parse(serverPortTextBox.Text); }
100-
catch { serverPortTextBox.Text = ZChat.ServerPort.ToString(); }
101-
ZChat.FirstChannelKey = channelKeyTextBox.Text;
96+
ZChat.Options.FirstChannel = channelTextBox.Text;
97+
ZChat.Options.InitialNickname = nickNameTextBox.Text;
98+
ZChat.Options.Server = serverTextBox.Text;
99+
try { ZChat.Options.ServerPort = int.Parse(serverPortTextBox.Text); }
100+
catch { serverPortTextBox.Text = ZChat.Options.ServerPort.ToString(); }
101+
ZChat.Options.FirstChannelKey = channelKeyTextBox.Text;
102102

103-
ZChat.SaveConnectionInfo = saveConnectionInfoCheckBox.IsChecked.Value;
103+
ZChat.Options.SaveConnectionInfo = saveConnectionInfoCheckBox.IsChecked.Value;
104104

105105
if (singleClickRestore.IsChecked.Value)
106-
ZChat.RestoreType = ClickRestoreType.SingleClick;
106+
ZChat.Options.RestoreType = ClickRestoreType.SingleClick;
107107
else
108-
ZChat.RestoreType = ClickRestoreType.DoubleClick;
109-
110-
ZChat.HighlightTrayIconForJoinsAndQuits = joinsQuitsHighlight.IsChecked.Value;
111-
112-
ZChat.UsersBack = (SolidColorBrush)UsersBack.Background;
113-
ZChat.UsersFore = (SolidColorBrush)UsersFore.Background;
114-
ZChat.EntryBack = (SolidColorBrush)EntryBack.Background;
115-
ZChat.EntryFore = (SolidColorBrush)EntryFore.Background;
116-
ZChat.ChatBack = (SolidColorBrush)ChatBack.Background;
117-
ZChat.TimeFore = (SolidColorBrush)TimeFore.Background;
118-
ZChat.NickFore = (SolidColorBrush)NickFore.Background;
119-
ZChat.BracketFore = (SolidColorBrush)BracketFore.Background;
120-
ZChat.TextFore = (SolidColorBrush)TextFore.Background;
121-
ZChat.QueryTextFore = (SolidColorBrush)QueryTextFore.Background;
122-
ZChat.OwnNickFore = (SolidColorBrush)OwnNickFore.Background;
123-
ZChat.LinkFore = (SolidColorBrush)LinkFore.Background;
124-
125-
ZChat.Font = (FontFamily)fontsCombo.SelectedItem;
126-
127-
ZChat.TimeStampFormat = timeFormatBox.Text;
128-
ZChat.WindowsForPrivMsgs = windowsForPrivMsgs.IsChecked.Value;
129-
ZChat.LastFMUserName = lastfmUserBox.Text;
130-
ZChat.HyperlinkPattern = hyperlinkPatternBox.Text;
108+
ZChat.Options.RestoreType = ClickRestoreType.DoubleClick;
109+
110+
ZChat.Options.HighlightTrayIconForJoinsAndQuits = joinsQuitsHighlight.IsChecked.Value;
111+
112+
ZChat.Options.UsersBack = (SolidColorBrush)UsersBack.Background;
113+
ZChat.Options.UsersFore = (SolidColorBrush)UsersFore.Background;
114+
ZChat.Options.EntryBack = (SolidColorBrush)EntryBack.Background;
115+
ZChat.Options.EntryFore = (SolidColorBrush)EntryFore.Background;
116+
ZChat.Options.ChatBack = (SolidColorBrush)ChatBack.Background;
117+
ZChat.Options.TimeFore = (SolidColorBrush)TimeFore.Background;
118+
ZChat.Options.NickFore = (SolidColorBrush)NickFore.Background;
119+
ZChat.Options.BracketFore = (SolidColorBrush)BracketFore.Background;
120+
ZChat.Options.TextFore = (SolidColorBrush)TextFore.Background;
121+
ZChat.Options.QueryTextFore = (SolidColorBrush)QueryTextFore.Background;
122+
ZChat.Options.OwnNickFore = (SolidColorBrush)OwnNickFore.Background;
123+
ZChat.Options.LinkFore = (SolidColorBrush)LinkFore.Background;
124+
125+
ZChat.Options.Font = (FontFamily)fontsCombo.SelectedItem;
126+
127+
ZChat.Options.TimeStampFormat = timeFormatBox.Text;
128+
ZChat.Options.WindowsForPrivMsgs = windowsForPrivMsgs.IsChecked.Value;
129+
ZChat.Options.LastFMUserName = lastfmUserBox.Text;
130+
ZChat.Options.HyperlinkPattern = hyperlinkPatternBox.Text;
131131
}
132132

133133
private void OK_Click(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)