[theminds commit] r140 - in trunk: Structures Theminds

0 views
Skip to first unread message

codesite...@google.com

unread,
Jul 24, 2007, 2:15:18 PM7/24/07
to theminds...@googlegroups.com
Author: shadytrees
Date: Tue Jul 24 11:14:40 2007
New Revision: 140

Modified:
trunk/Structures/Ideas.cs
trunk/Theminds/App.cs
trunk/Theminds/Theminds.csproj

Log:
Ideas gains write ability

Modified: trunk/Structures/Ideas.cs
==============================================================================
--- trunk/Structures/Ideas.cs (original)
+++ trunk/Structures/Ideas.cs Tue Jul 24 11:14:40 2007
@@ -1,16 +1,33 @@
+using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Specialized;

namespace Aspirations {
- public class Ideas {
+ public class Ideas : IDisposable {
public string Get(string id) { return dict[id]; }

public string Get(string id, string id2) {
return Get(id + "." + id2);
}

- public Ideas(string file) {
+ public Ideas Set(string id, string value) {
+ dict[id] = value;
+ return this;
+ }
+
+ public Ideas Set(string id, string id2, string value) {
+ return Set(id, id2, value);
+ }
+
+ // Serves as the flag for Dispose() and for a read-only
+ // Ideas instance used, for example, on an internationalization
+ // file like lion.txt. A read/write example is a configuration
+ // file like config.txt.
+ bool trackChanges; string file;
+ public Ideas(string file, bool trackChanges) {
+ this.trackChanges = trackChanges;
+ this.file = file;
dict = new StringDictionary();
using (TextReader t = new StreamReader(file)) {
string line;
@@ -18,8 +35,14 @@
}
}

+ public Ideas(string file) : this(file, false) { }
+
/**** Private members ****/
StringDictionary dict;
+
+ // [Ad hoc] The format of each line is two strings,
+ // each separated by a quotation mark. A simple
+ // string split and a check for \" suffices to parse.
void parseLine(string line) {
if (!line.StartsWith("\"")) return;

@@ -28,6 +51,18 @@
catch (System.ArgumentException) {
dict[tokens[1]] = tokens[3];
}
+ }
+
+ public void Dispose() {
+ if (!trackChanges) return;
+
+ using (TextWriter t = new StreamWriter(file)) {
+ foreach (string key in dict.Keys) {
+ t.WriteLine(String.Format("\"{0}\" \"{1}\"", key, dict[key]));
+ }
+ }
+
+ trackChanges = false;
}
} // class Ideas
}

Modified: trunk/Theminds/App.cs
==============================================================================
--- trunk/Theminds/App.cs (original)
+++ trunk/Theminds/App.cs Tue Jul 24 11:14:40 2007
@@ -1,9 +1,9 @@
using System;
-using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using Aspirations;
+using CancelEventArgs = System.ComponentModel.CancelEventArgs;

namespace Theminds {
public sealed partial class App : Form {
@@ -13,7 +13,7 @@
set { currentChannel = value; }
}

- public static Ideas Lion = new Ideas(@"lion.txt");
+ public static Ideas Lion = new Ideas(@"lion.txt", true);

Buffer buffer; Quirk quirk;
public App() {
@@ -29,31 +29,31 @@
quirk.NewLine += new Quirk.NewLineDel(Buffer.AddLine);
App.LoadAttributeLovers(
typeof(DesiresAppControlsAttribute), this);
+
PostOffice();
-
quirk.Start();
}

/**** Event handlers ****/
- protected override void OnClosing(
- System.ComponentModel.CancelEventArgs e) {
+ protected override void OnClosing(CancelEventArgs e) {
quirk.Dispose();
+ Lion.Dispose();
base.OnClosing(e);
}

protected override void OnKeyDown(KeyEventArgs e) {
- if (false == e.Control) goto noControl;
- e.SuppressKeyPress = true;
- switch (e.KeyCode) {
- case Keys.PageUp: tabber.MoveToPrev(); break;
- case Keys.PageDown: tabber.MoveToNext(); break;
- case Keys.T: buffer.AddChannel(); break;
- case Keys.W: buffer.Remove(tabber.Current); break;
- case Keys.Q: this.Close(); break;
- default: e.SuppressKeyPress = false; break;
+ if (e.Control) {
+ e.SuppressKeyPress = true;
+ switch (e.KeyCode) {
+ case Keys.PageUp: tabber.MoveToPrev(); break;
+ case Keys.PageDown: tabber.MoveToNext(); break;
+ case Keys.T: buffer.AddChannel(); break;
+ case Keys.W: buffer.Remove(tabber.Current); break;
+ case Keys.Q: this.Close(); break;
+ default: e.SuppressKeyPress = false; break;
+ }
}

- noControl:
base.OnKeyDown(e);
}

@@ -84,6 +84,9 @@
}
}

+ // Called after I construct all DesireAppControls filters
+ // so those filters may start mingling among each other,
+ // swapping body fluids and pirate stories.
public event MethodInvoker PostOffice = delegate { };
}
}

Modified: trunk/Theminds/Theminds.csproj
==============================================================================
--- trunk/Theminds/Theminds.csproj (original)
+++ trunk/Theminds/Theminds.csproj Tue Jul 24 11:14:40 2007
@@ -51,12 +51,12 @@
<Compile Include="Buffer interfaces.cs" />
<Compile Include="Buffer.cs" />
<Compile Include="Filters\InputBoxFilters.cs" />
- <Compile Include="Filters\JoinPartQuitFilter.cs" />
+ <Compile Include="Filters\JoinPartQuit.cs" />
<Compile Include="Filters\LogBoxFilters.cs" />
- <Compile Include="Filters\NamesFilter.cs" />
- <Compile Include="Filters\PrivmsgFilter.cs" />
- <Compile Include="Filters\QueryFilter.cs" />
- <Compile Include="Filters\WhoFilter.cs" />
+ <Compile Include="Filters\Names.cs" />
+ <Compile Include="Filters\Privmsg.cs" />
+ <Compile Include="Filters\Query.cs" />
+ <Compile Include="Filters\Who.cs" />
<Compile Include="SetUpForm.cs">
<SubType>Form</SubType>
</Compile>
@@ -66,11 +66,13 @@
<Compile Include="Tests\InputBox.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="Tests\JoinPartQuitFilter.cs" />
+ <Compile Include="Tests\JoinPartQuit.cs" />
<Compile Include="Tests\MockApp.cs" />
- <Compile Include="Tests\NamesFilter.cs" />
- <Compile Include="Tests\PrivmsgFilter.cs" />
<Compile Include="Filters\Users.cs" />
+ <Compile Include="Tests\Names.cs" />
+ <Compile Include="Tests\PrivmsgFilter.cs">
+ <SubType>Code</SubType>
+ </Compile>
</ItemGroup>
<ItemGroup>
<Content Include="Plainclothes\lion.txt" />

Reply all
Reply to author
Forward
0 new messages