yakov pushed a commit to branch master.

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

commit e5cc25086d767411d79fe125964e3129e53d63e9
Author: Yakov Goldberg <[email protected]>
Date:   Tue Mar 10 14:08:28 2015 +0200

    Add infrastructure to create popups for warnings
    
    Add popup for existing file when "SaveAs"
---
 src/bin/egui_gui/CMakeLists.txt |  1 +
 src/bin/egui_gui/egui_logic.c   | 46 ++++++++++++++++++++++++++----
 src/bin/egui_gui/popup.c        | 62 +++++++++++++++++++++++++++++++++++++++++
 src/bin/egui_gui/popup.h        | 15 ++++++++++
 4 files changed, 118 insertions(+), 6 deletions(-)

diff --git a/src/bin/egui_gui/CMakeLists.txt b/src/bin/egui_gui/CMakeLists.txt
index 5f47a0a..6565d4c 100644
--- a/src/bin/egui_gui/CMakeLists.txt
+++ b/src/bin/egui_gui/CMakeLists.txt
@@ -71,6 +71,7 @@ add_executable(${TARGET}
    editor.c
    dnd.c
    key_bindings.c
+   popup.c
    )
 
 add_dependencies(${TARGET} erigo_cmd)
diff --git a/src/bin/egui_gui/egui_logic.c b/src/bin/egui_gui/egui_logic.c
index 05a2390..7dea1c0 100644
--- a/src/bin/egui_gui/egui_logic.c
+++ b/src/bin/egui_gui/egui_logic.c
@@ -26,6 +26,7 @@
 #include "egui_logic.h"
 #include "settings_view.h"
 #include "rmview.h"
+#include "popup.h"
 
 static const Egui_Layout_Widgets *g_main_wdgs = NULL;
 static Egui_Layout_Fs_Win_Widgets *fs_win = NULL;
@@ -120,6 +121,30 @@ _canvas_name_update(const Gui_Context *ctx)
    eo_do(g_main_wdgs->main_win->main_win, elm_obj_win_title_set(name));
 }
 
+/* Callback to be called after clicking popup button */
+static void
+_popup_cb(Popup_Button_Type button_type, void *data)
+{
+   Eina_Stringshare *path = data;
+   /* If OK button pressed rewrite file */
+   if (button_type == POPUP_OK_BUTTON)
+     {
+        const Gui_Context *ctx = _active_context_get();
+        const char *filename = ecore_file_file_get(path);
+        char *parent_dir = ecore_file_dir_get(path);
+
+        gui_context_project_filename_set((Gui_Context *) ctx, filename);
+        gui_context_project_path_set((Gui_Context *) ctx, (const char *) 
parent_dir);
+        generator_ctx_source_generate(ctx, GENERATE_JSON);
+        _canvas_name_update(ctx);
+
+        free(parent_dir);
+        /* Close fileselector win. */
+        eo_del(fs_win->fs_win);
+     }
+   eina_stringshare_del(path);
+}
+
 static void
 _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, void *event)
 {
@@ -253,13 +278,20 @@ _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, 
void *event)
               if (!ecore_file_exists(parent_dir)) goto end;
               if (path_exists)
                 {
-                   /* FIXME: File exists, check if want to save*/
-                   ERR("can save, but file exists, show confirmation window");
+                   const char *title = "Warning";
+                   const char *text = "File already exists. Do you want to 
overwrite?";
+
+                   void *_popup_cb_data = (void *) eina_stringshare_add(path);
+                   popup_show(fs_win->fs_win, title, text, POPUP_OK_BUTTON | 
POPUP_CANCEL_BUTTON, _popup_cb, _popup_cb_data);
+                   goto dont_delete_fileselector_because_of_popup;
+                }
+              else
+                {
+                   gui_context_project_filename_set((Gui_Context *) ctx, 
filename);
+                   gui_context_project_path_set((Gui_Context *) ctx, (const 
char *) parent_dir);
+                   generator_ctx_source_generate(ctx, GENERATE_JSON);
+                   _canvas_name_update(ctx);
                 }
-              gui_context_project_filename_set((Gui_Context *) ctx, filename);
-              gui_context_project_path_set((Gui_Context *) ctx, (const char *) 
parent_dir);
-              generator_ctx_source_generate(ctx, GENERATE_JSON);
-              _canvas_name_update(ctx);
               break;
            }
      }
@@ -267,6 +299,8 @@ _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, void 
*event)
 
 end:
    eo_del(fs_win->fs_win);
+dont_delete_fileselector_because_of_popup:
+   ;
 }
 
 static void
diff --git a/src/bin/egui_gui/popup.c b/src/bin/egui_gui/popup.c
new file mode 100644
index 0000000..c63f301
--- /dev/null
+++ b/src/bin/egui_gui/popup.c
@@ -0,0 +1,62 @@
+#include <Elementary.h>
+#include "egui_log.h"
+#include "egui_layout.h"
+#include "popup.h"
+
+#include "elm_widget.h"
+
+/* Only one popup at the moment is supported */
+static Eo *_popup = NULL;
+
+/* User callback to be called after popup closes. */
+static Popup_Cb _popup_cb = NULL;
+static void *_data = NULL;
+
+static Eina_Bool
+_popup_close_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description 
*desc EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+   Popup_Button_Type _pressed_button_type = (uintptr_t) data;
+   /* Delete popup and call a callback afterwards. */
+   eo_del(_popup);
+
+   if (_popup_cb)
+     {
+       _popup_cb(_pressed_button_type, _data);
+     }
+
+   _popup = NULL;
+   _popup_cb = NULL;
+   _data = 0;
+   return EINA_TRUE;
+}
+
+void
+popup_show(void *parent, const char *title, const char *text, 
Popup_Button_Type button_type, Popup_Cb cb, void *data)
+{
+   if (_popup) return;
+   _popup = eo_add(ELM_POPUP_CLASS, parent);
+   _popup_cb = cb;
+   _data = data;
+
+   eo_do(_popup, elm_obj_widget_part_text_set("title,text", title));
+   eo_do(_popup, elm_obj_widget_part_text_set(NULL, text));
+
+   if (button_type & POPUP_OK_BUTTON)
+     {
+        Eo *btn = eo_add(ELM_BUTTON_CLASS, _popup);
+        eo_do(btn, elm_obj_widget_part_text_set(NULL, "OK"));
+        eo_do(_popup, elm_obj_container_content_set("button1", btn));
+        eo_do(btn, 
eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _popup_close_cb, 
(void*)(uintptr_t) POPUP_OK_BUTTON));
+     }
+
+   if (button_type & POPUP_CANCEL_BUTTON)
+     {
+        Eo *btn = eo_add(ELM_BUTTON_CLASS, _popup);
+        eo_do(btn, elm_obj_widget_part_text_set(NULL, "Cancel"));
+        eo_do(_popup, elm_obj_container_content_set("button2", btn));
+        eo_do(btn, 
eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _popup_close_cb, 
(void*)(uintptr_t) POPUP_CANCEL_BUTTON));
+     }
+
+   eo_do(_popup, evas_obj_visibility_set(EINA_TRUE));
+}
+
diff --git a/src/bin/egui_gui/popup.h b/src/bin/egui_gui/popup.h
new file mode 100644
index 0000000..c965a5c
--- /dev/null
+++ b/src/bin/egui_gui/popup.h
@@ -0,0 +1,15 @@
+#ifndef _POPUP_H
+#define _POPUP_H
+
+typedef enum
+{
+   POPUP_OK_BUTTON = 1 << 0,
+   POPUP_CANCEL_BUTTON = 1 << 1
+} Popup_Button_Type;
+
+typedef void (*Popup_Cb)(Popup_Button_Type, void *);
+
+void
+popup_show(void *parent, const char *title, const char *text, 
Popup_Button_Type button_type, Popup_Cb cb, void *data);
+
+#endif

-- 


Reply via email to