notify file changed popup correctly.

Current implementation has logical hole that skips the notification of file changes first time.
We fix this even if it depends on the time thresholds.
New implementation will skip the file changes also but
it will only skip, if the file change is happened again under 2 seconds.
This commit is contained in:
ChunEon Park 2015-07-03 20:22:36 +09:00
parent 1cc52fee57
commit e9f258a839
3 changed files with 20 additions and 13 deletions

View File

@ -8,7 +8,7 @@
typedef struct file_mgr_s {
Evas_Object *enventor;
Evas_Object *warning_layout;
int edc_modified; //1: edc is opened, 2: edc is changed
Eina_Bool edc_modified : 1;
} file_mgr_data;
static file_mgr_data *g_fmd = NULL;
@ -100,7 +100,7 @@ warning_open(file_mgr_data *fmd)
fmd->warning_layout = layout;
fmd->edc_modified = 0;
fmd->edc_modified = EINA_FALSE;
}
static void
@ -115,14 +115,11 @@ enventor_edc_modified_cb(void *data, Evas_Object *obj EINA_UNUSED,
if (modified->self_changed)
{
fmd->edc_modified = 0;
fmd->edc_modified = EINA_FALSE;
return;
}
//file is opened first time, we don't regard edc is modified, so skip here.
fmd->edc_modified++;
if (fmd->edc_modified == 1) return;
fmd->edc_modified = EINA_TRUE;
/* FIXME: Here ignore edc changes, if any menu is closed,
then we need to open warning box. */
@ -135,14 +132,14 @@ void
file_mgr_reset(void)
{
file_mgr_data *fmd = g_fmd;
fmd->edc_modified = 0;
fmd->edc_modified = EINA_FALSE;
}
int
file_mgr_edc_modified_get(void)
{
file_mgr_data *fmd = g_fmd;
return ((fmd->edc_modified == 2) ? EINA_TRUE : EINA_FALSE);
return fmd->edc_modified;
}
void

View File

@ -888,6 +888,7 @@ edit_save(edit_data *ed, const char *file)
edit_view_sync(ed);
edit_changed_set(ed, EINA_FALSE);
edit_saved_set(ed, EINA_TRUE);
return EINA_TRUE;

View File

@ -66,28 +66,37 @@ file_modified_timer(void *data)
static Eina_Bool
file_modified_cb(void *data, int type EINA_UNUSED, void *event)
{
static double timestamp = 0;
const int TIME_THRES = 2;
Eio_Monitor_Event *ev = event;
Enventor_Object_Data *pd = data;
Enventor_EDC_Modified modified;
if (ev->monitor != pd->edc_monitor) return ECORE_CALLBACK_PASS_ON;
if (!edit_saved_get(pd->ed))
{
/* FIXEME: We know this event will be called twice,
Skip the one event if the it's triggered in 3 seconds */
if (ecore_loop_time_get() - timestamp < TIME_THRES)
return ECORE_CALLBACK_DONE;
/* Don't notify info right soon,
if the source changing can be happened continously. */
if (pd->file_modified_timer) ecore_timer_del(pd->file_modified_timer);
pd->file_modified_timer = ecore_timer_add(3, file_modified_timer, pd);
pd->file_modified_timer = ecore_timer_add(TIME_THRES,
file_modified_timer, pd);
return ECORE_CALLBACK_DONE;
}
if (!edit_changed_get(pd->ed)) return ECORE_CALLBACK_DONE;
if (strcmp(ev->filename, build_edc_path_get())) return ECORE_CALLBACK_DONE;
build_edc();
edit_changed_set(pd->ed, EINA_FALSE);
edit_saved_set(pd->ed, EINA_FALSE);
modified.self_changed = EINA_TRUE;
evas_object_smart_callback_call(pd->obj, SIG_EDC_MODIFIED, &modified);
timestamp = ecore_loop_time_get();
return ECORE_CALLBACK_DONE;
}