yakov pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=a752b9126e4446d597706f6b76fff8c5c14e4898

commit a752b9126e4446d597706f6b76fff8c5c14e4898
Author: Yakov Goldberg <yako...@samsung.com>
Date:   Tue Nov 17 17:03:33 2015 +0200

    Implement popup message when closing project
    
    When trying to close project which was not saved, show popup message.
---
 src/bin/gui/egui_logic.c | 59 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 51 insertions(+), 8 deletions(-)

diff --git a/src/bin/gui/egui_logic.c b/src/bin/gui/egui_logic.c
index 045c836..155a9e5 100644
--- a/src/bin/gui/egui_logic.c
+++ b/src/bin/gui/egui_logic.c
@@ -72,6 +72,9 @@ enum
    FACTORY_VIEW
 };
 
+static void
+_context_save(const Gui_Context *ctx);
+
 Eo *
 canvas_get()
 {
@@ -114,16 +117,55 @@ _project_close_internal(Gui_Context *ctx)
 
 /* Wrapper to handle project closure and allow to show popup window for not 
saved project. */
 static void
+_main_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void 
*event EINA_UNUSED);
+
+/* Callback to call, when popup button pressed */
+static void
+_project_save_popup_cb(Popup_Button_Type button_type, void *data)
+{
+   Gui_Context *ctx = _active_context_get();
+   /* If OK button pressed - save file */
+   if (button_type == POPUP_OK_BUTTON)
+     {
+        _context_save(ctx);
+     }
+   /* Remove swap file if DISCARD button was pressed */
+   else if (button_type == POPUP_DISCARD_BUTTON)
+     {
+        const char *path = gui_context_project_path_get(ctx);
+        const char *filename = gui_context_project_filename_get(ctx);
+        char full_path[PATH_MAX];
+        sprintf(full_path, "%s/%s", path, filename);
+
+        char *swap_file = autosave_ctx_swapfile_name_get(full_path);
+        if (swap_file)
+          {
+             if (ecore_file_exists(swap_file))
+               {
+                  ecore_file_remove(swap_file);
+               }
+             free(swap_file);
+          }
+     }
+   _project_close_internal(ctx);
+   Eina_Bool close_erigo = (intptr_t) data;
+   if (close_erigo) _main_win_del_cb(NULL, NULL, NULL);
+}
+
+static void
 project_close(Gui_Context *ctx, Eina_Bool erigo_close)
 {
    if (context_current_memento_get(ctx) == context_saved_memento_get(ctx))
      {
         _project_close_internal(ctx);
+        if (erigo_close) _main_win_del_cb(NULL, NULL, NULL);
      }
    else
      {
-        ERR("show popup");
-        _project_close_internal(ctx);
+        const char *title = "Warning";
+        char text[PATH_MAX];
+        sprintf(text, "Project '%s' was not saved. Do you want to save it?", 
gui_context_project_name_get(ctx));
+        popup_show(g_main_wdgs->main_win->main_win, title, text, 
POPUP_OK_BUTTON | POPUP_CANCEL_BUTTON | POPUP_DISCARD_BUTTON, 
_project_save_popup_cb, (void *)(intptr_t) erigo_close);
      }
 }
 
@@ -131,13 +173,14 @@ static void
 _main_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void 
*event EINA_UNUSED)
 {
    Gui_Context *close_ctx = _active_context_get();
-   while ((close_ctx = _active_context_get()))
+   if (close_ctx)
      {
-        project_close(close_ctx);
+        project_close(close_ctx, EINA_TRUE);
+     }
+   else
+     {
+        elm_exit();
      }
-
-   printf("win del\n");
-   elm_exit();
 }
 
 static Elm_Object_Item*
@@ -573,7 +616,7 @@ _project_menu_item_sel_cb(void *data, Evas_Object *obj 
EINA_UNUSED, void *event_
       case ITEM_CLOSE:
            {
               Gui_Context *close_ctx = _active_context_get();
-              project_close(close_ctx);
+              project_close(close_ctx, EINA_FALSE);
 
              _canvas_name_update(_active_context_get(), EINA_FALSE);
              _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_FALSE);

-- 


Reply via email to