Modified:
trunk/Theminds/Buffer interfaces.cs
trunk/Theminds/Buffer.cs
trunk/Theminds/Filters/JoinPartQuitFilter.cs
trunk/Theminds/Filters/QueryFilter.cs
trunk/Theminds/Filters/WhoFilter.cs
Log:
* No more `fforde` or `suppressNewTab` junk in JPQFilter: we just throw it to the null (server) tab.
* In fact, BufferData#NeedsNewTab is gone! That's right! Gone!
* No more logBoxes hashtable or TabIdShells! Fancy GetHashCode, Equals, and proust magic fixes this.
* BufferData#Broadcast allows messages to seed its way to all channels (part and quit for now).
* This is a first stab at Issue 11.
Modified: trunk/Theminds/Buffer interfaces.cs
==============================================================================
--- trunk/Theminds/Buffer interfaces.cs (original)
+++ trunk/Theminds/Buffer interfaces.cs Sat May 12 14:54:12 2007
@@ -13,35 +13,32 @@
this.LogBox = l;
}
- public TabId(TabIdShell shell, LogBox l)
- : this(shell.Connection, shell.Channel, l) { }
- }
-
- public struct TabIdShell {
- public Quirk Connection;
- public string Channel;
-
- public TabIdShell(Quirk c, string channel) {
- this.Connection = c;
- this.Channel = channel;
+ public override int GetHashCode() {
+ if (Channel == null) return 42;
+ else return Channel.GetHashCode();
}
- public TabIdShell(TabId id)
- : this(id.Connection, id.Channel) { }
+ public override bool Equals(object obj) {
+ if (obj == null) return false;
+ if (typeof(TabId) != obj.GetType()) return false;
+ TabId o = (TabId)obj;
+ return (o.Connection == this.Connection) &&
+ (o.Channel == this.Channel);
+ }
}
public struct BufferData {
public Color Color;
public string Channel;
public string Line;
- public bool NeedsNewTab;
public bool Ignore;
+ public bool Broadcast;
public BufferData(string line) {
this.Line = line;
this.Color = Color.Black;
this.Channel = null;
- this.NeedsNewTab = true;
this.Ignore = false;
+ this.Broadcast = false;
}
}
}
Modified: trunk/Theminds/Buffer.cs
==============================================================================
--- trunk/Theminds/Buffer.cs (original)
+++ trunk/Theminds/Buffer.cs Sat May 12 14:54:12 2007
@@ -8,23 +8,19 @@
using System.Diagnostics;
using System.Collections.Generic;
using Aspirations;
+using M = System.Windows.Forms.MethodInvoker;
namespace Theminds {
public class Buffer {
IAppControls app;
// I need the two-way-osity for AddLine.
- TwoWayDictionary<ITab, TabId> proust;
- // I needed this to handle new tabs (hack hackety hack).
- Dictionary<TabIdShell, LogBox> logBoxes;
+ TwoWayDictionary<ITab, TabId> proust = new TwoWayDictionary<ITab, TabId>(5);
public Buffer(IAppControls app) {
this.app = app;
- proust = new TwoWayDictionary<ITab, TabId>(5);
- logBoxes = new Dictionary<TabIdShell, LogBox>(5);
TabId id = new TabId(app.Connection, null, app.LogBox);
proust[app.Tabber.Current] = id;
- logBoxes[new TabIdShell(id)] = app.LogBox;
// Page.Buffering events.
app.Tabber.Moved += new TabDel(MoveToTab);
@@ -42,39 +38,43 @@
if (app.InvokeRequired) Line(ref data);
else SelfLine(ref data);
PostLine(ref data);
- if (data.Ignore) return;
- TabIdShell shell = new TabIdShell(app.Connection, data.Channel);
- // *Line events allows clients to modify data.NeedsNewTab.
- // This allows them to signal to their mother ship, us.
- handleNewTab(ref shell, data.NeedsNewTab);
-
- LogBox l = logBoxes[shell];
- l.Invoke(new AddLineDel(l.AddLine),
- data.Line, data.Color);
+ if (data.Ignore) return;
+ if (data.Broadcast)
+ broadcast(data.Line, data.Color);
+ else {
+ TabId tab = new TabId(app.Connection, data.Channel, null);
+ if (!proust.ContainsKey(tab))
+ app.Invoke((M)delegate { AddChannel(tab); });
+
+ // AddChannel now guarantees `tab` is inside
+ // `proust`, ripe for picking. Forward & reverse
+ // ensures that tab.LogBox is not null.
+ tab = proust[proust[tab]];
+ app.Invoke(new AddLineDel(tab.LogBox.AddLine),
+ data.Line, data.Color);
+ }
}
- void handleNewTab(ref TabIdShell shell, bool needsNewTab) {
- if (logBoxes.ContainsKey(shell)) return;
- if (!needsNewTab) shell.Channel = app.CurrentChannel;
- else {
- TabId id = new TabId(shell, null);
- app.Invoke((MethodInvoker)delegate {
- AddChannel(id.Channel);
+ private void broadcast(string line, Color color) {
+ app.BeginInvoke((M)delegate {
+ proust.Values.ForEach((Action<TabId>)delegate(TabId tab) {
+ tab.LogBox.AddLine(line, color);
});
- }
+ });
}
- public void AddChannel() { AddChannel(null); }
- public void AddChannel(string channel) {
- app.CurrentChannel = channel;
- ITab newTab = app.Tabber.Add(channel);
- TabId id = new TabId(app.Connection, channel, new LogBox());
- app.SwitchLogBox(id.LogBox);
+ public void AddChannel() {
+ AddChannel(new TabId(app.Connection, null, null));
+ }
+ public void AddChannel(TabId tab) {
+ app.CurrentChannel = tab.Channel;
+ ITab newTab = app.Tabber.Add(tab.Channel);
+ tab.LogBox = new LogBox();
+ app.SwitchLogBox(tab.LogBox);
- proust[newTab] = id;
- logBoxes[new TabIdShell(id)] = id.LogBox;
- NewChannel(channel);
+ proust[newTab] = tab;
+ NewChannel(tab.Channel);
}
// If no key exists, `t` is a new tab.
@@ -92,7 +92,6 @@
if (!proust.ContainsKey(t)) return;
string channel = proust[t].Channel;
- logBoxes.Remove(new TabIdShell(proust[t]));
proust.Remove(t);
app.Tabber.Remove(t);
if (StringEx.IsChannel(channel))
Modified: trunk/Theminds/Filters/JoinPartQuitFilter.cs
==============================================================================
--- trunk/Theminds/Filters/JoinPartQuitFilter.cs (original)
+++ trunk/Theminds/Filters/JoinPartQuitFilter.cs Sat May 12 14:54:12 2007
@@ -8,11 +8,10 @@
[DesiresAppControls]
class JoinPartQuitFilter {
Quirk quirk; IAppControls app;
- Ideas lion = App.Lion; LineDel fforde;
+ Ideas lion = App.Lion;
public JoinPartQuitFilter(IAppControls app) {
this.app = app; quirk = app.Connection;
app.Buffer.Line += new LineDel(filter);
- fforde = new LineDel(suppressNewTab);
}
// line ~ ":nick!ip join :#chan"
@@ -38,7 +37,8 @@
data.Channel = Sx.Tween(line, spaces[1], spaces[2] - 1);
reasonIndex = spaces[2] + 1; break;
case "quit":
- reasonIndex = spaces[1] + 1; break;
+ reasonIndex = spaces[1] + 1;
+ data.Broadcast = true; break;
default: return;
}
notes.ReasonIndex = reasonIndex;
@@ -46,13 +46,11 @@
findMessage(ref data, ref notes);
findReason(ref data, ref notes);
- // Regarding `fforde` and `suppressNewTabs`:
- // When I part, I output the part message
- // from the server to the (server) tab, not to
- // the already-closed tab.
+ // Output part messages caused by me to the (server)
+ // tab now that the find* twins are finished.
if ("part" == notes.Mode && notes.FromMe) {
- messageToSuppress = data.Line;
- app.Buffer.PostLine += fforde;
+ data.Channel = null;
+ data.Broadcast = true;
}
}
@@ -81,13 +79,6 @@
if (!user.Contains("!")) return;
notes.Nick = Sx.Tween(user, 1, user.IndexOf('!'));
notes.Ip = user.Substring(user.IndexOf('!') + 1);
- }
-
- string messageToSuppress;
- void suppressNewTab(ref BufferData data) {
- if (messageToSuppress != data.Line) return;
- data.NeedsNewTab = false;
- app.Buffer.PostLine -= fforde;
}
}
Modified: trunk/Theminds/Filters/QueryFilter.cs
==============================================================================
--- trunk/Theminds/Filters/QueryFilter.cs (original)
+++ trunk/Theminds/Filters/QueryFilter.cs Sat May 12 14:54:12 2007
@@ -32,7 +32,6 @@
dc.Channel = arg;
dc.Color = Color.DarkSlateBlue;
dc.Line = dc.Line.Substring(nonce.Length);
- dc.NeedsNewTab = true;
app.Buffer.SelfLine -= introFilterDel;
}
}
Modified: trunk/Theminds/Filters/WhoFilter.cs
==============================================================================
--- trunk/Theminds/Filters/WhoFilter.cs (original)
+++ trunk/Theminds/Filters/WhoFilter.cs Sat May 12 14:54:12 2007
@@ -34,6 +34,7 @@
data.Channel = tokens[1];
data.Color = Color.DarkBlue;
+ data.Ignore = true;
if (data.Line.Contains("End of /WHO"))
app.Invoke(new MethodInvoker(stop));
else