diff --git a/DMX-2.0/DMX-2.0.csproj b/DMX-2.0/DMX-2.0.csproj
index 462ff34..574cf32 100644
--- a/DMX-2.0/DMX-2.0.csproj
+++ b/DMX-2.0/DMX-2.0.csproj
@@ -18,7 +18,6 @@
DEBUG;
prompt
4
- fullscreen aguibtn
false
diff --git a/DMX-2.0/MainWindow.cs b/DMX-2.0/MainWindow.cs
index 39ea5ea..8dcbe03 100644
--- a/DMX-2.0/MainWindow.cs
+++ b/DMX-2.0/MainWindow.cs
@@ -13,6 +13,7 @@ namespace DMX2
static object circuitKey = new object();
ListStore lsMatrice = null;
FileInfo conduiteFile=null;
+ int lastSaveHash=0;
public static MainWindow Win {
get { return win; }
@@ -263,12 +264,20 @@ namespace DMX2
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
- Application.Quit ();
- a.RetVal = true;
+ a.RetVal = !Quit();
}
protected void OnQuitActionActivated (object sender, EventArgs e)
{
+ Quit ();
+ }
+
+
+
+ bool Quit ()
+ {
+ if(!VerifSauvegarde ("Quitter ?","La conduite n'a pas été sauvegardée.\nQuitter quand même ?")) return false;
Application.Quit ();
+ return true;
}
#endregion
@@ -292,7 +301,9 @@ namespace DMX2
protected void OnCloseActionActivated (object sender, EventArgs e)
{
+ if(!VerifSauvegarde ("Fermer ?","La conduite n'a pas été sauvegardée.\nFermer quand même ?")) return;
Conduite.Courante.Dispose();
+ conduiteFile = null;
MajWidgets();
}
@@ -304,12 +315,40 @@ namespace DMX2
SaveFile();
}
+ bool VerifSauvegarde (string titre, string message)
+ {
+ if (Conduite.Courante != null) {
+ if (Conduite.Courante.Save ().InnerXml.GetHashCode () != lastSaveHash) {
+ var dlg = new Dialog (titre, this, DialogFlags.Modal);
+ dlg.VBox.Add (new Label (message));
+ dlg.AddButton (titre=="Quitter ?"?Stock.Quit:Stock.Close, ResponseType.Close);
+ dlg.AddButton (conduiteFile == null?Stock.SaveAs:Stock.Save, ResponseType.Apply);
+ dlg.AddButton (Stock.Cancel, ResponseType.Cancel).GrabDefault ();
+ dlg.VBox.ShowAll ();
+ ResponseType res = (ResponseType)dlg.Run ();
+ if (res == ResponseType.Cancel) {
+ dlg.Destroy ();
+ return false;
+ }
+ if (res == ResponseType.Apply) {
+ dlg.Destroy ();
+ if (conduiteFile == null)
+ return SaveFileAs();
+ SaveFile ();
+ return true;
+ }
+ dlg.Destroy ();
+ return true;
+ }
+ }
+ return true;
+ }
protected void OnSaveAsActionActivated (object sender, EventArgs e)
{
SaveFileAs();
}
- void SaveFileAs ()
+ bool SaveFileAs ()
{
FileChooserDialog fcd = new FileChooserDialog ("Sauver sous ...", this, FileChooserAction.Save,
"Annuler", ResponseType.Cancel,
@@ -325,7 +364,7 @@ namespace DMX2
if ((ResponseType)fcd.Run () == ResponseType.Cancel) {
fcd.Destroy ();
- return;
+ return false;
}
string file = fcd.Filename;
@@ -347,13 +386,13 @@ namespace DMX2
else ok=true;
}
fcd.Destroy();
- SaveFile();
+ return SaveFile();
}
- void SaveFile ()
+ bool SaveFile ()
{
if (conduiteFile == null)
- return;
+ return false;
// Copie de sauvegarde
if(conduiteFile.Exists)
@@ -362,9 +401,10 @@ namespace DMX2
using (FileStream stream = conduiteFile.Open(FileMode.Create,FileAccess.Write)) {
System.Xml.XmlDocument doc = Conduite.Courante.Save ();
doc.Save (stream);
+ lastSaveHash = doc.InnerXml.GetHashCode();
stream.Close ();
+ return true;
}
-
}
protected void OnOpenActionActivated (object sender, EventArgs e)
@@ -403,6 +443,7 @@ namespace DMX2
}
conduiteFile = openFile;
+ lastSaveHash = doc.InnerXml.GetHashCode();
} catch (IOException) {
}