From ee94ff9fa6c838edd49e213c004136d6fb69b789 Mon Sep 17 00:00:00 2001 From: sam Date: Thu, 30 Oct 2008 01:02:36 +0000 Subject: [PATCH] ThePimp: make file dialogs singletons so that they retain their properties and do not take ages to build. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3145 92316355-f0b4-4df1-b90c-862c8a59935f --- ThePimp/src/MainWindow.cs | 15 ++++++++------- ThePimp/src/OpenFile.cs | 16 +++++++++++----- ThePimp/src/SaveFile.cs | 18 ++++++++++++------ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/ThePimp/src/MainWindow.cs b/ThePimp/src/MainWindow.cs index e8445fd..9e81007 100644 --- a/ThePimp/src/MainWindow.cs +++ b/ThePimp/src/MainWindow.cs @@ -37,10 +37,7 @@ namespace ThePimp protected virtual void OnOpenActionActivated (object sender, System.EventArgs e) { - OpenFile dialog = new OpenFile(); - - string s = dialog.GetChoice(); - dialog.Destroy(); + string s = OpenFile.GetChoice(); if(s == null) return; @@ -90,10 +87,14 @@ namespace ThePimp { if(notebook1.NPages <= 0) return; - SaveFile save = new SaveFile(); + PictureView view = notebook1.CurrentPageWidget as PictureView; - save.Save(view.Picture); - save.Destroy(); + + string s = OpenFile.GetChoice(); + if(s == null) + return; + + view.Picture.Save(s); } protected virtual void OnAboutActionActivated (object sender, System.EventArgs e) diff --git a/ThePimp/src/OpenFile.cs b/ThePimp/src/OpenFile.cs index 4ac6ec8..87364c1 100644 --- a/ThePimp/src/OpenFile.cs +++ b/ThePimp/src/OpenFile.cs @@ -19,18 +19,24 @@ namespace ThePimp { public partial class OpenFile : Gtk.Dialog { - public OpenFile() + private static readonly OpenFile instance = new OpenFile(); + + // Do not mark type as beforefieldinit + static OpenFile() {} + + private OpenFile() { this.Build(); } - public string GetChoice() + public static string GetChoice() { - ResponseType rsp = (ResponseType)Run(); - Hide(); + instance.ShowAll(); + ResponseType rsp = (ResponseType)instance.Run(); + instance.Hide(); if(rsp != ResponseType.Ok) return null; - return filechooserwidget1.Filename; + return instance.filechooserwidget1.Filename; } protected virtual void OnFilechooserwidget1FileActivated (object sender, System.EventArgs e) diff --git a/ThePimp/src/SaveFile.cs b/ThePimp/src/SaveFile.cs index 1c8dddf..eab1eb7 100644 --- a/ThePimp/src/SaveFile.cs +++ b/ThePimp/src/SaveFile.cs @@ -19,18 +19,24 @@ namespace ThePimp { public partial class SaveFile : Gtk.Dialog { - public SaveFile() + private static readonly SaveFile instance = new SaveFile(); + + // Do not mark type as beforefieldinit + static SaveFile() {} + + private SaveFile() { this.Build(); } - public void Save(Pipi.Picture p) + public static string GetChoice() { - ResponseType rsp = (ResponseType)Run(); - Hide(); + instance.ShowAll(); + ResponseType rsp = (ResponseType)instance.Run(); + instance.Hide(); if(rsp != ResponseType.Ok) - return; - p.Save(filechooserwidget1.Filename); + return null; + return instance.filechooserwidget1.Filename; } protected virtual void OnFilechooserwidget1FileActivated (object sender, System.EventArgs e)