[theminds commit] r143 - in trunk: Tabs Theminds Theminds/Filters Theminds/Tests

1 view
Skip to first unread message

codesite...@google.com

unread,
Aug 1, 2007, 4:26:51 PM8/1/07
to theminds...@googlegroups.com
Author: shadytrees
Date: Wed Aug 1 13:25:52 2007
New Revision: 143

Modified:
trunk/Tabs/Tabber.cs
trunk/Theminds/Buffer.cs
trunk/Theminds/Filters/InputBoxFilters.cs
trunk/Theminds/Filters/LogBoxFilters.cs
trunk/Theminds/Filters/Users.cs
trunk/Theminds/Filters/Who.cs
trunk/Theminds/TabsParent.cs
trunk/Theminds/Tests/JoinPartQuit.cs
trunk/Theminds/Tests/PrivmsgFilter.cs

Log:
lambdas

Modified: trunk/Tabs/Tabber.cs
==============================================================================
--- trunk/Tabs/Tabber.cs (original)
+++ trunk/Tabs/Tabber.cs Wed Aug 1 13:25:52 2007
@@ -62,19 +62,19 @@
public event TabDel Moved;
public void MoveTo(ITab tab) {
int index = tabs.IndexOf(tab);
- c(delegate { current = index; parent.GrabFocus(); });
+ c(() => { current = index; parent.GrabFocus(); });
this.Moved(tab);
}
public void MoveTo(int index) { MoveTo(tabs[index]); }

public void MoveToNext() {
- c(delegate { current = (current + 1) % tabs.Count; });
+ c(() => current = (current + 1) % tabs.Count);
Moved(this.Current);
}

public void MoveToPrev() {
// Adding tabs.Count prevents negative numbers.
- c(delegate { current = (current - 1 + tabs.Count) % tabs.Count; });
+ c(() => current = (current - 1 + tabs.Count) % tabs.Count);
Moved(this.Current);
}

@@ -89,19 +89,20 @@
int width = x.Width;
this.realWidth -= x.TrueWidth;

- parent.SuspendLayout();
// Places to clean up:
// * Parent's collection
// * Our collection
+ parent.SuspendLayout();
parent.RemoveTab((System.Windows.Forms.Control)x);
tabs.Remove(x);
- tabs.ForEach(delegate(ITab t) { t.Left -= width; });
+ tabs.ForEach(t => t.Left -= width);

removeHelperForCounters(index, width);
MoveTo(current); resize();
- // On the ITab's lifetime:
- // It should die out after this event call unless
- // an event help stores it, which is a Bad Idea.
+
+ // ITab's lifetime:
+ // It should die out after this event call unless
+ // an event help stores it, which is a Bad Idea.
Removed(x);
parent.ResumeLayout();
}
@@ -118,14 +119,12 @@
void resize() {
int maxWidth = parent.TabsWidth;
int realTotalWidth = 0;
- tabs.ForEach(delegate(ITab tab) {
- realTotalWidth += tab.TrueWidth;
- });
+ tabs.ForEach(tab => realTotalWidth += tab.TrueWidth);

double sB = (double)maxWidth / realTotalWidth;
this.right = 0;
double shrinkBy = (sB < 1.0) ? sB : 1.0;
- tabs.ForEach(delegate(ITab tab) {
+ tabs.ForEach(tab => {
tab.Shrinkage = shrinkBy;
tab.Left = right;
right += tab.Width;

Modified: trunk/Theminds/Buffer.cs
==============================================================================
--- trunk/Theminds/Buffer.cs (original)
+++ trunk/Theminds/Buffer.cs Wed Aug 1 13:25:52 2007
@@ -46,8 +46,7 @@
broadcastHelper(data);
else {
Room tab = new Room(this.connection, data.Channel, null);
- if (!proust.ContainsKey(tab))
- app.Invoke((M)delegate { AddChannel(tab); });
+ if (!proust.ContainsKey(tab)) app.Invoke((M)(() => AddChannel(tab)));

// AddChannel now guarantees `tab` is inside
// `proust`, ripe for picking. Forward & reverse
@@ -61,11 +60,9 @@
private void broadcastHelper(BufferData data) {
List<Room> tabs = proust.Values;
Broadcast(ref tabs, data.BroadcastId);
- app.BeginInvoke((M)delegate {
- tabs.ForEach((Action<Room>)delegate(Room tab) {
- tab.LogBox.AddLine(data.Line, data.Color);
- });
- });
+ app.BeginInvoke((M)(
+ () => tabs.ForEach(t => t.LogBox.AddLine(data.Line, data.Color))
+ ));
}

public void AddChannel() {

Modified: trunk/Theminds/Filters/InputBoxFilters.cs
==============================================================================
--- trunk/Theminds/Filters/InputBoxFilters.cs (original)
+++ trunk/Theminds/Filters/InputBoxFilters.cs Wed Aug 1 13:25:52 2007
@@ -14,18 +14,18 @@
InputBox inputBox = app.InputBox;
Quirk connection = app.Connection;

- inputBox.StopPresses += delegate(ref bool shouldStop) {
+ inputBox.StopPresses += (ref bool shouldStop) => {
if (!connection.Started) shouldStop = true;
};

- inputBox.Command += delegate(string cmd, string msg) {
+ inputBox.Command += (cmd, msg) => {
if ("me" != cmd) return;
connection.Message("PRIVMSG {0} :\u0001ACTION {1}\u0001",
app.CurrentChannel, msg);
};

inputBox.Message += new InputBox.MessageDel(PrivmsgCurrentChannel);
- inputBox.Command += delegate(string cmd, string arg) {
+ inputBox.Command += (cmd, arg) => {
switch (cmd) {
// arg is a channel.
case "j": connection.Message("JOIN " + arg); break;
@@ -34,7 +34,7 @@
case "q": connection.Dispose(arg); break;
}
};
- inputBox.Command += delegate(string cmd, string arg) {
+ inputBox.Command += (cmd, arg) => {
if (!cmd.StartsWith("/")) return;
if (arg.Length != 0) arg = " " + arg;
PrivmsgCurrentChannel(S.Format("{0}{1}", cmd, arg));
@@ -45,8 +45,7 @@
if (app.CurrentChannel == null)
app.LogBox.AddLine(App.Lion.Get("error.cannot.privmsg"), Color.Purple);
else
- app.Connection.Message(
- "PRIVMSG " + app.CurrentChannel + " " + msg);
+ app.Connection.Message("PRIVMSG " + app.CurrentChannel + " " + msg);
}
}
}

Modified: trunk/Theminds/Filters/LogBoxFilters.cs
==============================================================================
--- trunk/Theminds/Filters/LogBoxFilters.cs (original)
+++ trunk/Theminds/Filters/LogBoxFilters.cs Wed Aug 1 13:25:52 2007
@@ -23,12 +23,10 @@

buffer.Line += new LineDel(ping);
buffer.SelfLine += new LineDel(selfJoin);
- buffer.SelfLine += delegate(ref BufferData data) {
- data.Color = Color.DarkRed;
- };
- buffer.Line += delegate(ref BufferData dc) {
+ buffer.SelfLine += (ref BufferData data) => data.Color = Color.DarkRed;
+ buffer.Line += (ref BufferData data) => {
// Strip mIRC colors.
- string line = dc.Line;
+ string line = data.Line;
if (line.Contains("\u0003")) line = mircRegex.Replace(line, "");
};
}

Modified: trunk/Theminds/Filters/Users.cs
==============================================================================
--- trunk/Theminds/Filters/Users.cs (original)
+++ trunk/Theminds/Filters/Users.cs Wed Aug 1 13:25:52 2007
@@ -12,15 +12,12 @@

// Only broadcast quit messages to the channels
// that actually contain the quitting user.
- // The `id` is "quit.[user]". See JPQF.cs.
- app.Buffer.Broadcast += delegate(ref List<Room> tabs, string id) {
+ // The `id` is "quit.[user]". See JPQ.cs.
+ app.Buffer.Broadcast += (ref List<Room> tabs, string id) => {
if (!id.StartsWith("quit.")) return;
string quitter = id.Split('.')[1];
- // Todo: Handle @+% fun.
- tabs = tabs.FindAll(delegate(Room room) {
- List<string> nicks = Users.Instance[room];
- return nicks.Contains(quitter);
- });
+ // Todo: Handle @+% fun via custom Contains method
+ tabs = tabs.FindAll(t => Users.Instance[t].Contains(quitter));
};
}

Modified: trunk/Theminds/Filters/Who.cs
==============================================================================
--- trunk/Theminds/Filters/Who.cs (original)
+++ trunk/Theminds/Filters/Who.cs Wed Aug 1 13:25:52 2007
@@ -11,7 +11,7 @@
public Who(IAppControls app) {
// Hook me up to the command /w in addition to filtering
// WHO commands; thus, Who serves as a dual purpose class.
- app.InputBox.Command += delegate(string cmd, string arg) {
+ app.InputBox.Command += (cmd, arg) => {
if ("w" != cmd) return;
if (!Sx.IsChannel(app.CurrentChannel)) return;
app.Buffer.Line += filterDel;

Modified: trunk/Theminds/TabsParent.cs
==============================================================================
--- trunk/Theminds/TabsParent.cs (original)
+++ trunk/Theminds/TabsParent.cs Wed Aug 1 13:25:52 2007
@@ -8,7 +8,7 @@
sealed partial class App : Form, ITabsParent {
public void AddTab(Control c) {
if (InvokeRequired) {
- BeginInvoke((MethodInvoker) delegate { AddTab(c); });
+ BeginInvoke((MethodInvoker) (() => AddTab(c)));
return;
}
tabsPanel.Controls.Add(c);

Modified: trunk/Theminds/Tests/JoinPartQuit.cs
==============================================================================
--- trunk/Theminds/Tests/JoinPartQuit.cs (original)
+++ trunk/Theminds/Tests/JoinPartQuit.cs Wed Aug 1 13:25:52 2007
@@ -79,7 +79,7 @@
void test(string line, string msg, string id) {
if (null == msg) msg = line;

- MockApp.PokeBuffer(app, line, delegate(ref BufferData data) {
+ MockApp.PokeBuffer(app, line, (ref BufferData data) => {
if (channel == data.Channel && msg == data.Line) return;
throw new InvalidOperationException("JoinPartQuit failure in filter() " + id);
});

Modified: trunk/Theminds/Tests/PrivmsgFilter.cs
==============================================================================
--- trunk/Theminds/Tests/PrivmsgFilter.cs (original)
+++ trunk/Theminds/Tests/PrivmsgFilter.cs Wed Aug 1 13:25:52 2007
@@ -43,7 +43,7 @@
void test(string line, string template,
string nick, string msg, string id) {
if (null == template) template = line;
- MockApp.PokeBuffer(app, line, delegate(ref BufferData data) {
+ MockApp.PokeBuffer(app, line, (ref BufferData data) => {
if (channel == data.Channel &&
S.Format(template, nick, msg) == data.Line) return;
throw new InvalidOperationException("PrimvsgFilter failure in filter() " + id);

Reply all
Reply to author
Forward
0 new messages