Programming WordBuilder

WordBuilder 3.0.0 release

Okay, I think it should be working now, so I’m hereby releasing WordBuilder v3.0.0

Download at: http://whee.dk/wordbuilder/gtkwordbuilder-3.0.0.zip

It’s a simple zip file with an exe and a dll. As with the previous GTK version, you’ll need GTK# installed. http://www.go-mono.com/mono-downloads/download.html

To my knowledge, it runs equally well on .NET and Mono.

The new things I’ve added are:

– Syntax highlighting
– Support for c-style brackets (so you can drop the { to a line of its own) and ; line enders
– Support for python-style blocks (use two spaces or one tab for each level of indentation)

In order to do this, I had to rewrite the parser, so it is now much more flexible and I think I’ll be able to add IntelliSense and contextual help and such to the UI in time.

Now I think it’s time to do some clean up of the old code, but first, a commit to the GIT repo.

Programming WordBuilder

WordBuilder Mono

Ok, I’ve taken my first stab at a mono-compatible tool. Turns out I couldn’t get MonoDevelop to build my VB code for some reason… So now I’ve spent some time converting the most important bits of code to C#, and it looks like I’m able to compile and run under mono.

What I have at the moment is a command line tool:

monowordbuilder <file_name>[ -v][ -r <starting_rule> <amount>]*

Which outputs a number of generated words, either just the root word or the larger output which contains marks and branches (using the -v argument).

If you don’t enter any rules at the command line, it’ll use the defaults you’ve set up in the .wordo file using the StartingRule directive. If there are none, it’ll default to generating the ‘root’ rule 100 times.

Oh, and I’ve no idea how to package it, so if anyone’s able to help out there, that’d be great. The source code is available at github.

Programming WordBuilder

InkScape fun

Well, I’ve been working on making an InkScape effect extension to allow me to generate place names directly into the map using WordBuilder rules.

I can report some success, but also some woes. As of yesternight, I can select a textbox and run the effect, and a name appears, albeit not quite in the right place. I think I’m just putting the text in the wrong tag, so that should be easily fixable.

The interesting thing is that I can’t get InkScape to accept the output from my .net console application. I’m writing to stdout, and running it from the command prompt allows me to stream the output to a file, so I’m pretty sure it’s going the right way. I ended up using a python script that executes the .net application, reads the output (from what it considers stdout), and then outputs that on its own stdout. Why that works better, I’ve no idea.

Other than that, I’ve implemented the loop command:

loop <list of numeric tokens> {

Which will pick a number from the list and repeat the commands that number of times. Since it takes a token list, 4[5] 6 will make 5 loops four times as likely as 6.

Programming Role playing

WordBuilder 1.0 released

WordBuilder is the latest thing to make me go Whee! – It’s an application for building vocabularies, word lists, and other small tricks (I made a list of a town’s inhabitants with occupations and first and last names, for example)

The WordBuilder main screen
The WordBuilder main screen

Fixes since 0.9:

  • Drop command now works, dropping from the end of the word.
  • Translate command now supports begin and end markers:
    Translate {
      # a a => a
      a a # => a

    Only removes double a’s at the beginning and end of the word.

  • The generate dialog now supports any number of starting rules.
  • The new Column directive allows you to show marks and branches as columns in the list view.
    Column Title1 Branch1
    Column Title2 !Mark1
    Column Title3 Branch1.!Mark2
  • The new Leave command takes tokens off the word until the requested number of tokens are left.
    Leave 2
  • WordBuilder now has an icon. Anyone want to make a better one?
  • The installer now asks where to install. Uninstall 0.9 before installing the new one.
  • New example project at http://whee.dk/wordbuilder/prach_eboch.wordo
  • Detail view now shows details for all selected words as preview of what you’ll copy with Copy details to clipboard.

Download at http://whee.dk/wordbuilder/WordBuilder.msi – and please, please give me some feedback?


LINQ code side cascading deletes

Over the last week or so, I’ve been searching around the net for a solution to a problem at work. The problem being that I have a bunch of LINQed objects with parent-child relations between them – the classic Orders -> OrderLines problem.

Normally, you’d create a relation with CASCADE DELETE set on it, but for these objects, I had to do more than just delete the relevant records – for example, I could have a file on disk related to each OrderLine. Deleting the OrderLine should delete the file as well – even if it was a cascaded delete.

You could implement the partial methods DeleteOrder and DeleteOrderLine on the Context class, and delete the file from there. That works for direct deletes, but not for the cascade case, since that only takes place on the sql-server. Also, you cannot call DeleteOnSubmit during SubmitChanges, which is where the partial methods are called.

All I got from google was a bunch of notes on using DeleteOnNull, which doesn’t help me any.

Finally, it dawned on me: You can override SubmitChanges on the Context class. Here’s how I did it:

Public Overrides Sub SubmitChanges(ByVal failureMode As System.Data.Linq.ConflictMode)
  Dim c As Integer = 0
    Dim cs As Changeset = Me.GetChangeSet()

    ' Use a While loop because the count can (will) increase
    While c > cs.Deletes.Count
        Dim deleted As IDeleteEventHandler = TryCast(cs.Deleted(c), IDeleteEventHandler)
        If deleted IsNot Nothing Then
            ' Notify the object that it is about to be deleted.
        End If
    End While


    ' Here I can use a For Each loop because it's
    ' too late to add to the collection anyhow.
    For Each deleted As IDeleteEventHandler In cs.Deleted
        ' Notify the object that it has been deleted.
End Sub

And on each object that had to cascade deletes code side, I’d implement the IDeleteEventHandler interface (that I defined to have two methods – OnDelete and OnDeleted), like so:

Partial Public Class Order
    Implements IDeleteEventHandler

    Public Sub OnDeleting(ByVal context As Context) Implements IDeleteEventHandler.OnDeleting
        ' Also delete OrderLines
    End Sub 

    Public Sub OnDeleted() Implements IDeleteEventHandler.OnDeleted
        ' No context passed to this method because you shouldn't
        ' do stuff with the context here.

        ' Delete order file from disk
    End Sub
End Class

Tah daaaah! There you have it, code side cascading deletes in LINQ.