FileSelectionDialog.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // FileSelectionDialog.cs
  3. //
  4. // Author: Duncan Mak ([email protected])
  5. // Daniel Morgan <[email protected]>
  6. //
  7. // Copyright (C) 2002, Duncan Mak, Ximian Inc.
  8. // Copyright (C) 2002, Daniel Morgan
  9. //
  10. using System;
  11. using Gtk;
  12. using GtkSharp;
  13. namespace Mono.GtkSharp.Goodies
  14. {
  15. public class FileSelectionEventArgs
  16. {
  17. private string filename;
  18. public FileSelectionEventArgs (string filename)
  19. {
  20. this.filename = filename;
  21. }
  22. public string Filename {
  23. get {
  24. return filename;
  25. }
  26. }
  27. }
  28. public delegate void FileSelectionEventHandler (object sender, FileSelectionEventArgs e);
  29. public class FileSelectionDialog
  30. {
  31. FileSelection window = null;
  32. ToggleButton toggle_button = null;
  33. CheckButton check_button = null;
  34. public event FileSelectionEventHandler fh;
  35. public FileSelectionDialog (string title, FileSelectionEventHandler fileSelectedHandler)
  36. {
  37. window = new FileSelection (title);
  38. window.OkButton.Clicked += new EventHandler (OnFileSelectionOk);
  39. window.CancelButton.Clicked += new EventHandler (OnFileSelectionCancel);
  40. if(fileSelectedHandler == null)
  41. throw new Exception ("FileSelectionDialog fileSelectedHandler is null");
  42. fh = fileSelectedHandler;
  43. window.ShowAll ();
  44. }
  45. void OnFileSelectionOk(object o, EventArgs args)
  46. {
  47. Gtk.Button fsbutton = (Gtk.Button) o;
  48. string filename = window.Filename;
  49. FileSelectionEventArgs fa = new FileSelectionEventArgs (filename);
  50. if (fh != null) {
  51. fh (this, fa);
  52. }
  53. window.Destroy ();
  54. }
  55. void OnFileSelectionCancel (object o, EventArgs args)
  56. {
  57. window.Destroy ();
  58. }
  59. }
  60. }