File: Application.cs

package info (click to toggle)
supertux 0.6.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 264,124 kB
  • sloc: cpp: 113,426; ansic: 9,654; sh: 4,483; cs: 1,296; makefile: 407; yacc: 398; python: 382; lisp: 285; objc: 248; csh: 219; lex: 140; perl: 118; xml: 53; ruby: 36
file content (617 lines) | stat: -rw-r--r-- 21,011 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
//  $Id$
using System;
using System.IO;
using System.Collections;
using Gtk;
using Gdk;
using Glade;

public class Application {
    [Glade.Widget]
    private Gtk.Window MainWindow;
    [Glade.Widget]
    private Gtk.CheckMenuItem useNewSyntax;
    [Glade.Widget]
    private Gtk.DrawingArea DrawingArea;
    [Glade.Widget]
	//Flags CheckButtons
    private Gtk.CheckButton SolidCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton UniSolidCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton IceCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton WaterCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton HurtsCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton FireCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton BrickCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton CoinCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton FullBoxCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton SlopeCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton GoalCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton DontUseCheckButton;
    [Glade.Widget]
    private Gtk.CheckButton HiddenCheckButton;
    [Glade.Widget]

    private Gtk.Entry DataEntry;
    [Glade.Widget]
    private Gtk.Entry AnimFpsEntry;
    [Glade.Widget]
    private Gtk.Entry IDEntry;
    [Glade.Widget]
    private Gtk.TreeView TileList;
    [Glade.Widget]
    private Gtk.Combo TileGroupComboBox;
    [Glade.Widget]
    private Gtk.MenuItem AddTileGroupMenu;

    [Glade.Widget]
    private Gtk.Dialog RemapDialog;
    [Glade.Widget]
    private Gtk.SpinButton RD_spinButton;

    private string tilesetdir;
    private string tilesetfile;
    private TileSet tileset;
    private TileGroup selectedgroup;

    private Tile[] Tiles;
    private bool[] SelectionArray;
    private ArrayList Selection = new ArrayList();
    private int TilesX;
    private int TilesY;
    private bool toggling;
    private bool selecting;

    private string currentimage;
    private Gdk.Pixbuf pixbuf;

    public static int Main(string[] args) {
        Gtk.Application.Init();

        Application app = new Application();

        /* that's no proper commandlineparsing, but who'll notice... */
        if(args.Length == 1)
            app.LoadTileSet(args[0]);

        Gtk.Application.Run();
        return 0;
    }

    public Application() {
        Glade.XML gxml = new Glade.XML(null, "tiler.glade", null, null);
        gxml.Autoconnect(this);

        if(MainWindow == null || DrawingArea == null || RemapDialog == null)
            throw new Exception("some widgets not found");

        DrawingArea.AddEvents((int) Gdk.EventMask.ButtonPressMask);
        DrawingArea.AddEvents((int) Gdk.EventMask.ButtonReleaseMask);
        DrawingArea.AddEvents((int) Gdk.EventMask.ButtonMotionMask);

        MainWindow.Show();
    }

    protected void OnOpen(object o, EventArgs e) {
	FileChooserDialog fileChooser = new FileChooserDialog("Select TileSet", MainWindow, FileChooserAction.Open, new object[] {});

	fileChooser.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
	fileChooser.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok);
	fileChooser.DefaultResponse = Gtk.ResponseType.Ok;
	Gtk.FileFilter filter;
	filter = new Gtk.FileFilter();
	filter.Name = "Supertux tilesets";
	filter.AddPattern("*.strf");
	filter.AddPattern("*.stgt");
	fileChooser.AddFilter( filter );
	filter = new Gtk.FileFilter();
	filter.Name = "Supertux 0.1.x tilesets";
	filter.AddPattern("*.stgt");
	fileChooser.AddFilter( filter );
	filter = new Gtk.FileFilter();
	filter.Name = "Supertux 0.3.x tilesets";
	filter.AddPattern("*.strf");
	fileChooser.AddFilter( filter );
	Gtk.FileFilter all = new Gtk.FileFilter();
	all.Name = "All Files";
	all.AddPattern("*");
	fileChooser.AddFilter( all );
	int result = fileChooser.Run();
	fileChooser.Hide();

	if(result != (int) ResponseType.Ok)
		return;

        LoadTileSet(fileChooser.Filename);
    }

    private void LoadTileSet(string file) {
        try {
            tileset = new TileSet();
            tileset.Parse(file);
            tilesetfile = file;
            tilesetdir = new FileInfo(file).Directory.ToString();
        } catch(Exception exception) {
            ShowException(exception);
        }

        Selection.Clear();
        SelectionChanged();
        FillTileGroupComboBox();
        FillTileList();

	useNewSyntax.Active = tileset.IsNew;
	if (tileset.IsNew)
		Console.WriteLine("Warning: new syntax of 0.3.x files \"More tiles in one image\" isn't currently supported for WRITING");

    }

    protected void OnImportImage(object o, EventArgs e) {
	FileChooserDialog fileChooser = new FileChooserDialog("Select ImageFile", MainWindow, FileChooserAction.Open, new object[] {});

	fileChooser.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
	fileChooser.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok);
	fileChooser.DefaultResponse = Gtk.ResponseType.Ok;
	Gtk.FileFilter all = new Gtk.FileFilter();
	all.Name = "All Files";
	all.AddPattern("*");
	fileChooser.AddFilter( all );
	int result = fileChooser.Run();
	fileChooser.Hide();

	if(result != (int) ResponseType.Ok)
		return;

	string file = fileChooser.Filename;
	string trim = tilesetdir + "/";

	if (!file.StartsWith(trim)){
		Console.WriteLine(
			"Imported file must be located inside tileset directory");
		return;
	}

        ChangeImage(file.TrimStart(trim.ToCharArray()));

        int startid = tileset.Tiles.Count;
        for(int y = 0; y < TilesY; ++y) {
            for(int x = 0; x < TilesX; ++x) {
                int i = y*TilesX+x;
                Tile tile = new Tile();
                tile.ID = startid + i;
                ImageRegion region = new ImageRegion();
                region.ImageFile = currentimage;
                region.Region = new System.Drawing.Rectangle(x*TileSet.TILE_WIDTH, y*TileSet.TILE_HEIGHT, TileSet.TILE_WIDTH, TileSet.TILE_HEIGHT);
                tile.Images.Add(region);
                if(Tiles[i] != null) {
                    Console.WriteLine(
                            "Warning Tile in this region already existed...");
                }
                Tiles[i] = tile;
                tileset.Tiles.Add(tile);
            }
        }

        FillTileList();
    }

    private void ChangeImage(string file) {
        if(file == "") {
            currentimage = "";
            pixbuf = null;
            return;
        }
        try {
            pixbuf = new Pixbuf(tilesetdir + "/" + file);
            if(pixbuf.Width % TileSet.TILE_WIDTH != 0 || pixbuf.Height % TileSet.TILE_HEIGHT != 0)
                Console.WriteLine("Warning: Image Width or Height is not a multiple of 32");
        } catch(Exception e) {
            ShowException(e);
            return;
        }
        currentimage = new FileInfo(file).Name;
        TilesX = pixbuf.Width / TileSet.TILE_WIDTH;
        TilesY = pixbuf.Height / TileSet.TILE_HEIGHT;
        SelectionArray = new bool[TilesX * TilesY];
        Tiles = new Tile[TilesX * TilesY];

        // search tileset for tiles with matching image
        foreach(Tile tile in tileset.Tiles) {
            if(tile == null)
                continue;
            if(tile.Images.Count == 0)
                continue;
            ImageRegion region = (ImageRegion) tile.Images[0];
            if(region.ImageFile == currentimage) {
                int px = region.Region.X / TileSet.TILE_WIDTH;
                int py = region.Region.Y / TileSet.TILE_HEIGHT;
                int i = py*TilesX+px;
                if(i < 0 || i >= Tiles.Length) {
                    Console.WriteLine("Invalid Imageregion at tile " +
                            tile.ID);
                    continue;
                }
                if(Tiles[i] != null) {
                    Console.WriteLine("Multiple tiles for region " +
                            px*TileSet.TILE_WIDTH + " , " + py*TileSet.TILE_HEIGHT);
                    continue;
                }
                Tiles[i] = tile;
            }
        }

        /*   DrawingArea.Allocation
            = new Gdk.Rectangle(0, 0, pixbuf.Width, pixbuf.Height);*/
        DrawingArea.WidthRequest = pixbuf.Width;
        DrawingArea.HeightRequest = pixbuf.Height;
        DrawingArea.QueueResize();
    }

    protected void OnSave(object o, EventArgs e) {
	if (tileset.IsNew && useNewSyntax.Active) {
		MessageDialog dialog = new MessageDialog(MainWindow, DialogFlags.Modal | DialogFlags.DestroyWithParent,	MessageType.Error, ButtonsType.Ok,
								"Sorry, the file you are editing is too new and 0.3.x syntax is not supported yet.");
		dialog.Run();
		dialog.Destroy();
	} else {
		tileset.Write(tilesetfile);
	}
    }

    protected void OnQuit(object o, EventArgs e) {
        Gtk.Application.Quit();
    }

    protected void OnDeleteQuit(object o, DeleteEventArgs e) {
        Gtk.Application.Quit();
    }

    protected void OnAbout(object o, EventArgs e) {
//		string[] authors = new string[]{
//			"<autors?>",
//		};

		Gtk.AboutDialog dialog = new Gtk.AboutDialog();
//		dialog.Icon = <icon>;
		dialog.ProgramName = "SuperTux Tiler";
		dialog.Version = "0.0.3";
		dialog.Comments = "A tileset editor for SuperTux 0.1.x";
//		dialog.Authors = authors;
		dialog.Copyright = "Copyright (c) 2006 SuperTux Devel Team";
		dialog.License =
			"This program is free software; you can redistribute it and/or modify" + Environment.NewLine +
			"it under the terms of the GNU General Public License as published by" + Environment.NewLine +
			"the Free Software Foundation; either version 2 of the License, or" + Environment.NewLine +
			"(at your option) any later version." + Environment.NewLine +
			Environment.NewLine +
			"This program is distributed in the hope that it will be useful," + Environment.NewLine +
			"but WITHOUT ANY WARRANTY; without even the implied warranty of" + Environment.NewLine +
			"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" + Environment.NewLine +
			"GNU General Public License for more details." + Environment.NewLine +
			Environment.NewLine +
			"You should have received a copy of the GNU General Public License" + Environment.NewLine +
			"along with this program; if not, write to the Free Software Foundation, Inc.," + Environment.NewLine +
			"59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" + Environment.NewLine;
		dialog.Website = "http://supertux.lethargik.org/";
		dialog.WebsiteLabel = "SuperTux on the Web";
		dialog.Run();
		dialog.Destroy();
    }

    protected void OnRemapTiles(object o, EventArgs e) {
	if(Tiles == null)
		return;
	RemapDialog.Show();
    }

    protected void OnRemapDialogCancel(object o, EventArgs e) {
	RemapDialog.Hide();
    }

    protected void OnRemapDialogApply(object o, EventArgs e) {
	RemapDialog.Hide();
        try {

            // remap tiles
            int id;
            try {
                id = RD_spinButton.ValueAsInt;
            } catch(Exception exception) {
                ShowException(exception);
                return;
            }
            RemapTiles(id);
        } finally {
            RD_spinButton.Value = 1;
        }
    }

    protected void OnCreateTileGroup(object o, EventArgs e) {
    }

    protected void OnRenameTileGroup(object o, EventArgs e) {
    }

    protected void RemapTiles(int startID) {
	if(Tiles == null)
		return;

	// remap tiles
	int id = startID;
	foreach(Tile tile in Selection) {
		if(tile.ID == -1)
			continue;

		int oldid = tile.ID;
		tile.ID = id++;
		// remap in all tilegroups...
		foreach(TileGroup tilegroup in tileset.TileGroups) {
			int idx = tilegroup.Tiles.IndexOf(oldid);
			if(idx >= 0) {
				tilegroup.Tiles[idx] = tile.ID;
			}
		}
	}
	FillTileList();
	SelectionChanged();
    }

    protected void OnDrawingAreaExpose(object o, ExposeEventArgs e) {
        if(pixbuf == null)
            return;

        Drawable drawable = e.Event.Window;
        Gdk.GC gc = new Gdk.GC(drawable);
        drawable.DrawPixbuf(gc, pixbuf, 0, 0, 0, 0,
                pixbuf.Width, pixbuf.Height, RgbDither.None, 0, 0);

        gc.RgbFgColor = new Color(0xff, 0, 0);
        foreach(Tile tile in Selection) {
            System.Drawing.Rectangle rect
                = ((ImageRegion) tile.Images[0]).Region;
            drawable.DrawRectangle(gc, false, rect.X, rect.Y, rect.Width,
                    rect.Height);
        }

        e.RetVal = false;
    }

    protected void OnDrawingAreaButtonPress(object o, ButtonPressEventArgs e) {
        if(SelectionArray == null)
            return;

        selecting = true;

        for(int i = 0; i < SelectionArray.Length; ++i)
            SelectionArray[i] = false;
        select((int) e.Event.X, (int) e.Event.Y);
    }

    private void select(int x, int y) {
        int tile = y/TileSet.TILE_HEIGHT * TilesX + x/TileSet.TILE_WIDTH;
        if(tile < 0 || tile >= SelectionArray.Length)
            return;

        SelectionArray[tile] = true;
        SelectionArrayChanged();
    }

    protected void OnDrawingAreaMotionNotify(object i, MotionNotifyEventArgs e) {
        if(!selecting)
            return;
        select((int) e.Event.X, (int) e.Event.Y);
    }

    protected void OnDrawingAreaButtonRelease(object o, ButtonPressEventArgs e) {
        selecting = false;
    }

    protected void OnCheckButtonToggled(object sender, EventArgs e) {
        if(toggling)
            return;
        foreach(Tile tile in Selection) {
            if(sender == SolidCheckButton)
                tile.SetAttribute(Attribute.SOLID, SolidCheckButton.Active);
            if(sender == UniSolidCheckButton)
                tile.SetAttribute(Attribute.UNISOLID, UniSolidCheckButton.Active);
            if(sender == IceCheckButton)
                tile.SetAttribute(Attribute.ICE, IceCheckButton.Active);
            if(sender == WaterCheckButton)
                tile.SetAttribute(Attribute.WATER, WaterCheckButton.Active);
            if(sender == HurtsCheckButton)
                tile.SetAttribute(Attribute.HURTS, HurtsCheckButton.Active);
            if(sender == FireCheckButton)
                tile.SetAttribute(Attribute.FIRE, FireCheckButton.Active);
            if(sender == BrickCheckButton)
                tile.SetAttribute(Attribute.BRICK, BrickCheckButton.Active);
            if(sender == CoinCheckButton)
                tile.SetAttribute(Attribute.COIN, CoinCheckButton.Active);
            if(sender == FullBoxCheckButton)
                tile.SetAttribute(Attribute.FULLBOX, FullBoxCheckButton.Active);
            if(sender == SlopeCheckButton)
                tile.SetAttribute(Attribute.SLOPE, SlopeCheckButton.Active);
            if(sender == GoalCheckButton)
                tile.SetAttribute(Attribute.GOAL, GoalCheckButton.Active);
            if(sender == HiddenCheckButton)
                tile.Hidden = HiddenCheckButton.Active;
            if(sender == DontUseCheckButton)
                tile.ID = DontUseCheckButton.Active ? -1 : 0;
        }
    }

    protected void OnEntryChanged(object sender, EventArgs e) {
        if(toggling)
            return;
        foreach(Tile tile in Selection) {
            try {
                if(sender == IDEntry)
                    tile.ID = Int32.Parse(IDEntry.Text);
                if(sender == DataEntry)
                    tile.Data = Int32.Parse(DataEntry.Text);
                if(sender == AnimFpsEntry)
                    tile.AnimFps = Single.Parse(AnimFpsEntry.Text);
            } catch(Exception) {
                // ignore parse errors for now...
            }
        }
    }

    private void SelectionArrayChanged() {
        Selection.Clear();
        for(int i = 0; i < SelectionArray.Length; ++i) {
            if(!SelectionArray[i])
                continue;

            if(Tiles[i] == null) {
                Console.WriteLine("Tile doesn't exist yet");
                // TODO ask user to create new tile...
                continue;
            }
            Selection.Add(Tiles[i]);
        }

        SelectionChanged();
    }

    private void SelectionChanged() {
        bool first = true;
        toggling = true;
        string nextimage = "";
        foreach(Tile tile in Selection) {
            if(first) {
                SolidCheckButton.Active = tile.HasAttribute(Attribute.SOLID);
                UniSolidCheckButton.Active = tile.HasAttribute(Attribute.UNISOLID);
                IceCheckButton.Active = tile.HasAttribute(Attribute.ICE);
                WaterCheckButton.Active = tile.HasAttribute(Attribute.WATER);
                HurtsCheckButton.Active = tile.HasAttribute(Attribute.HURTS);
                FireCheckButton.Active = tile.HasAttribute(Attribute.FIRE);
                BrickCheckButton.Active = tile.HasAttribute(Attribute.BRICK);
                CoinCheckButton.Active = tile.HasAttribute(Attribute.COIN);
                FullBoxCheckButton.Active = tile.HasAttribute(Attribute.FULLBOX);
                SlopeCheckButton.Active = tile.HasAttribute(Attribute.SLOPE);
                GoalCheckButton.Active = tile.HasAttribute(Attribute.GOAL);
                HiddenCheckButton.Active = tile.Hidden;
                DontUseCheckButton.Active = tile.ID == -1;
                DataEntry.Text = tile.Data.ToString();
                AnimFpsEntry.Text = tile.AnimFps.ToString();
                IDEntry.Text = tile.ID.ToString();
                IDEntry.IsEditable = true;
                first = false;

                if(tile.Images.Count > 0) {
                    nextimage = ((ImageRegion) tile.Images[0]).ImageFile;
                }
            } else {
                IDEntry.Text += "," + tile.ID.ToString();
                IDEntry.IsEditable = false;
                if(tile.Images.Count > 0
                        && ((ImageRegion) tile.Images[0]).ImageFile != nextimage) {
                    nextimage = "";
                    pixbuf = null;
                }
            }
        }
        if(nextimage != currentimage)
            ChangeImage(nextimage);
        toggling = false;
        DrawingArea.QueueDraw();
    }

    private void FillTileList() {
        TileList.HeadersVisible = true;
        if(TileList.Columns.Length == 0)
            TileList.AppendColumn("Tile", new CellRendererText(), "text", 0);

        ListStore store = new ListStore(typeof(string));

        if(selectedgroup == null) {
            foreach(Tile tile in tileset.Tiles) {
                if(tile == null)
                    continue;
                store.AppendValues(new object[] { tile.ID.ToString() });
            }
        } else {
            foreach(int id in selectedgroup.Tiles) {
		Tile tile;
		if (id >= tileset.Tiles.Count){
			Console.WriteLine("Tile ID is above Tiles.Count: " + id.ToString());
			continue;
		} else {
			tile = (Tile) tileset.Tiles[id];
		}
                if(tile == null) {
                    Console.WriteLine("tilegroup contains deleted tile");
                    continue;
                }
                store.AppendValues(new object[] { id.ToString() });
            }
        }

        TileList.Model = store;
        TileList.Selection.Mode = SelectionMode.Multiple;
    }

    private void FillTileGroupComboBox() {
        string[] groups = new string[tileset.TileGroups.Count+1];
        groups[0] = "All";

        //Submenu submenu = new Submenu();
        for(int i = 0; i < tileset.TileGroups.Count; ++i) {
            String tilegroup = ((TileGroup) tileset.TileGroups[i]).Name;
            groups[i+1] = tilegroup;
            //submenu.Add(new MenuItem(tilegroup));
        }
        TileGroupComboBox.PopdownStrings = groups;
        TileGroupComboBox.Entry.IsEditable = false;

        //AddTileGroupMenu.Submenu = submenu;
    }

    protected void OnTileGroupComboBoxEntryActivated(object o, EventArgs args) {
        if(TileGroupComboBox.Entry.Text == "All") {
            selectedgroup = null;
        } else {
            foreach(TileGroup tilegroup in tileset.TileGroups) {
                if(tilegroup.Name == TileGroupComboBox.Entry.Text) {
                    selectedgroup = tilegroup;
                    break;
                }
            }
        }
        FillTileList();
    }

    protected void OnTileListCursorChanged(object sender, EventArgs e) {
        TreeModel model;
        TreePath[] selectpaths =
            TileList.Selection.GetSelectedRows(out model);

        Selection.Clear();
        foreach(TreePath path in selectpaths) {
            TreeIter iter;
            model.GetIter(out iter, path);
            int id = Int32.Parse(model.GetValue(iter, 0).ToString());
            Selection.Add(tileset.Tiles[id]);
        }
        SelectionChanged();
    }

    private void ShowException(Exception e) {
        MessageDialog dialog = new MessageDialog(MainWindow,
                DialogFlags.Modal | DialogFlags.DestroyWithParent,
                MessageType.Error, ButtonsType.Ok,
                e.Message);
        dialog.Run();
        dialog.Destroy();
    }
}