SYS : Confirm Save when exit

This commit is contained in:
Edouard Dupin 2011-09-01 13:38:12 +02:00
parent 1c01dbd7cd
commit 28b709bfb8
4 changed files with 61 additions and 11 deletions

View File

@ -47,6 +47,7 @@ Buffer::Buffer()
Edn::String mString = "Untitle - "; Edn::String mString = "Untitle - ";
mString += fileBasicID++; mString += fileBasicID++;
SetFileName(mString); SetFileName(mString);
m_haveName = false;
} }
/** /**

View File

@ -51,7 +51,7 @@ class BufferManager: public Singleton<BufferManager>, public MsgBroadcast
int32_t Open(Edn::File &myFile); int32_t Open(Edn::File &myFile);
int32_t GetSelected(void) { return m_idSelected;}; int32_t GetSelected(void) { return m_idSelected;};
void SetSelected(int32_t id) {m_idSelected = id;}; void SetSelected(int32_t id) {m_idSelected = id;};
Buffer * Get(int32_t BufferID); Buffer * Get(int32_t BufferID);
bool Exist(int32_t BufferID); bool Exist(int32_t BufferID);
bool Exist(Edn::File &myFile); bool Exist(Edn::File &myFile);
int32_t GetId(Edn::File &myFile); int32_t GetId(Edn::File &myFile);

View File

@ -93,10 +93,8 @@ void WindowsManager::OnMessage(int32_t id, int32_t dataID)
GtkWidget *dialog = gtk_file_chooser_dialog_new( "Open File", NULL, GtkWidget *dialog = gtk_file_chooser_dialog_new( "Open File", NULL,
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, // button text GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_RESPONSE_CANCEL, // response id GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
GTK_STOCK_OPEN, // button text
GTK_RESPONSE_ACCEPT, // response id
NULL); // end button/response list NULL); // end button/response list
// this element did not apear in the miniature of the windows // this element did not apear in the miniature of the windows
gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), TRUE); gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), TRUE);
@ -137,10 +135,8 @@ void WindowsManager::OnMessage(int32_t id, int32_t dataID)
tmpString += myBuffer->GetFileName().GetShortFilename().c_str(); tmpString += myBuffer->GetFileName().GetShortFilename().c_str();
GtkWidget *dialog = gtk_file_chooser_dialog_new( tmpString.c_str(), NULL, GtkWidget *dialog = gtk_file_chooser_dialog_new( tmpString.c_str(), NULL,
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, // button text GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_RESPONSE_CANCEL, // response id GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
GTK_STOCK_SAVE, // button text
GTK_RESPONSE_ACCEPT, // response id
NULL); // end button/response list NULL); // end button/response list
// this element did not apear in the miniature of the windows // this element did not apear in the miniature of the windows
gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), TRUE); gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), TRUE);
@ -262,13 +258,67 @@ void WindowsManager::OnMessage(int32_t id, int32_t dataID)
NULL); NULL);
GtkWidget *p_label = gtk_label_new ("Do you want exit Edn ?"); GtkWidget *p_label = gtk_label_new ("Do you want exit Edn ?");
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area( GTK_DIALOG(p_dialog) )), p_label, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area( GTK_DIALOG(p_dialog) )), p_label, TRUE, TRUE, 0);
gtk_widget_show(p_label); gtk_widget_show(p_label);
switch (gtk_dialog_run (GTK_DIALOG (p_dialog))) switch (gtk_dialog_run (GTK_DIALOG (p_dialog)))
{ {
case GTK_RESPONSE_YES: case GTK_RESPONSE_YES:
gtk_widget_destroy (p_dialog); gtk_widget_destroy (p_dialog);
p_dialog = NULL;
{
BufferManager * myBufferMng = BufferManager::getInstance();
for (int32_t iii=0 ; iii<myBufferMng->Size() ; iii++) {
if (true==myBufferMng->Exist(iii) ) {
Buffer * myBuffer = myBufferMng->Get(iii);
if (NULL != myBuffer) {
if (true == myBuffer->IsModify()) {
if (true == myBuffer->HaveName()) {
p_dialog = gtk_dialog_new_with_buttons("Save Before Exit",
GTK_WINDOW(m_mainWindow->GetWidget()),
GTK_DIALOG_MODAL,
GTK_STOCK_SAVE, GTK_RESPONSE_YES,
GTK_STOCK_SAVE_AS, GTK_RESPONSE_ACCEPT,
GTK_STOCK_NO, GTK_RESPONSE_NO,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
} else {
p_dialog = gtk_dialog_new_with_buttons("Save Before Exit",
GTK_WINDOW(m_mainWindow->GetWidget()),
GTK_DIALOG_MODAL,
GTK_STOCK_SAVE_AS, GTK_RESPONSE_ACCEPT,
GTK_STOCK_NO, GTK_RESPONSE_NO,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
}
char tmpName[1024];
sprintf(tmpName, "Save file \"%s\" ?", myBuffer->GetFileName().GetCompleateName().c_str());
p_label = gtk_label_new(tmpName);
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area( GTK_DIALOG(p_dialog) )), p_label, TRUE, TRUE, 0);
gtk_widget_show(p_label);
switch (gtk_dialog_run (GTK_DIALOG (p_dialog)))
{
case GTK_RESPONSE_YES:
myBuffer->Save();
break;
case GTK_RESPONSE_ACCEPT:
OnMessage(EDN_MSG__GUI_SHOW_SAVE_AS, iii);
break;
case GTK_RESPONSE_NO:
// nothing to do ...
break;
case GTK_RESPONSE_CANCEL:
gtk_widget_destroy (p_dialog);
return;
break;
}
gtk_widget_destroy (p_dialog);
p_dialog = NULL;
}
}
}
}
}
gtk_main_quit(); gtk_main_quit();
break; break;
case GTK_RESPONSE_NO: case GTK_RESPONSE_NO:

View File

@ -16,7 +16,6 @@
# action a faire (ordonner par révision) : # action a faire (ordonner par révision) :
* 0.1.X : * 0.1.X :
- gui : demander l'enregistrement avant de fermer (quand c'est nécessaire)
- Edn::VectorType : Rewrite the erase fuction to support start => stop and Erase len methode ... - Edn::VectorType : Rewrite the erase fuction to support start => stop and Erase len methode ...
* 0.2.X : * 0.2.X :
- gui : Mise en place d'un display ligne par ligne - gui : Mise en place d'un display ligne par ligne