* DMX-2.0.csproj:
* MainWindow.cs: Confirmation avant fermeture non sauvegardée...
This commit is contained in:
parent
b5fc4fda64
commit
1fed3ab63b
2 changed files with 49 additions and 9 deletions
|
|
@ -18,7 +18,6 @@
|
||||||
<DefineConstants>DEBUG;</DefineConstants>
|
<DefineConstants>DEBUG;</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Commandlineparameters>fullscreen aguibtn</Commandlineparameters>
|
|
||||||
<ConsolePause>false</ConsolePause>
|
<ConsolePause>false</ConsolePause>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ namespace DMX2
|
||||||
static object circuitKey = new object();
|
static object circuitKey = new object();
|
||||||
ListStore lsMatrice = null;
|
ListStore lsMatrice = null;
|
||||||
FileInfo conduiteFile=null;
|
FileInfo conduiteFile=null;
|
||||||
|
int lastSaveHash=0;
|
||||||
|
|
||||||
public static MainWindow Win {
|
public static MainWindow Win {
|
||||||
get { return win; }
|
get { return win; }
|
||||||
|
|
@ -263,12 +264,20 @@ namespace DMX2
|
||||||
|
|
||||||
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
|
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
|
||||||
{
|
{
|
||||||
Application.Quit ();
|
a.RetVal = !Quit();
|
||||||
a.RetVal = true;
|
|
||||||
}
|
}
|
||||||
protected void OnQuitActionActivated (object sender, EventArgs e)
|
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 ();
|
Application.Quit ();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -292,7 +301,9 @@ namespace DMX2
|
||||||
|
|
||||||
protected void OnCloseActionActivated (object sender, EventArgs e)
|
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();
|
Conduite.Courante.Dispose();
|
||||||
|
conduiteFile = null;
|
||||||
MajWidgets();
|
MajWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -304,12 +315,40 @@ namespace DMX2
|
||||||
SaveFile();
|
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)
|
protected void OnSaveAsActionActivated (object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SaveFileAs();
|
SaveFileAs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveFileAs ()
|
bool SaveFileAs ()
|
||||||
{
|
{
|
||||||
FileChooserDialog fcd = new FileChooserDialog ("Sauver sous ...", this, FileChooserAction.Save,
|
FileChooserDialog fcd = new FileChooserDialog ("Sauver sous ...", this, FileChooserAction.Save,
|
||||||
"Annuler", ResponseType.Cancel,
|
"Annuler", ResponseType.Cancel,
|
||||||
|
|
@ -325,7 +364,7 @@ namespace DMX2
|
||||||
|
|
||||||
if ((ResponseType)fcd.Run () == ResponseType.Cancel) {
|
if ((ResponseType)fcd.Run () == ResponseType.Cancel) {
|
||||||
fcd.Destroy ();
|
fcd.Destroy ();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
string file = fcd.Filename;
|
string file = fcd.Filename;
|
||||||
|
|
||||||
|
|
@ -347,13 +386,13 @@ namespace DMX2
|
||||||
else ok=true;
|
else ok=true;
|
||||||
}
|
}
|
||||||
fcd.Destroy();
|
fcd.Destroy();
|
||||||
SaveFile();
|
return SaveFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveFile ()
|
bool SaveFile ()
|
||||||
{
|
{
|
||||||
if (conduiteFile == null)
|
if (conduiteFile == null)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
// Copie de sauvegarde
|
// Copie de sauvegarde
|
||||||
if(conduiteFile.Exists)
|
if(conduiteFile.Exists)
|
||||||
|
|
@ -362,9 +401,10 @@ namespace DMX2
|
||||||
using (FileStream stream = conduiteFile.Open(FileMode.Create,FileAccess.Write)) {
|
using (FileStream stream = conduiteFile.Open(FileMode.Create,FileAccess.Write)) {
|
||||||
System.Xml.XmlDocument doc = Conduite.Courante.Save ();
|
System.Xml.XmlDocument doc = Conduite.Courante.Save ();
|
||||||
doc.Save (stream);
|
doc.Save (stream);
|
||||||
|
lastSaveHash = doc.InnerXml.GetHashCode();
|
||||||
stream.Close ();
|
stream.Close ();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void OnOpenActionActivated (object sender, EventArgs e)
|
protected void OnOpenActionActivated (object sender, EventArgs e)
|
||||||
|
|
@ -403,6 +443,7 @@ namespace DMX2
|
||||||
}
|
}
|
||||||
|
|
||||||
conduiteFile = openFile;
|
conduiteFile = openFile;
|
||||||
|
lastSaveHash = doc.InnerXml.GetHashCode();
|
||||||
|
|
||||||
} catch (IOException) {
|
} catch (IOException) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue