EDI -> Save -> Menu/Toolbar Indicator (w/o autosave)

Reviewers: ajwillia.ms

Reviewed By: ajwillia.ms

Differential Revision: https://phab.enlightenment.org/D4819
This commit is contained in:
Al Poole 2017-04-22 22:23:32 +01:00 committed by Andy Williams
parent e3459cb526
commit 38dd432523
4 changed files with 43 additions and 3 deletions

View File

@ -28,6 +28,7 @@
int EDI_EVENT_TAB_CHANGED; int EDI_EVENT_TAB_CHANGED;
int EDI_EVENT_FILE_CHANGED; int EDI_EVENT_FILE_CHANGED;
int EDI_EVENT_FILE_SAVED;
typedef struct _Edi_Panel_Slide_Effect typedef struct _Edi_Panel_Slide_Effect
{ {
@ -47,6 +48,7 @@ static Elm_Object_Item *_edi_selected_bottompanel;
static Evas_Object *_edi_filepanel, *_edi_filepanel_icon; static Evas_Object *_edi_filepanel, *_edi_filepanel_icon;
static Evas_Object *_edi_menu_undo, *_edi_menu_redo, *_edi_toolbar_undo, *_edi_toolbar_redo; static Evas_Object *_edi_menu_undo, *_edi_menu_redo, *_edi_toolbar_undo, *_edi_toolbar_redo;
static Evas_Object *_edi_menu_save, *_edi_toolbar_save;
static Evas_Object *_edi_main_win, *_edi_main_box, *_edi_message_popup; static Evas_Object *_edi_main_win, *_edi_main_box, *_edi_message_popup;
int _edi_log_dom = -1; int _edi_log_dom = -1;
@ -882,7 +884,7 @@ _edi_menu_setup(Evas_Object *obj)
elm_menu_item_separator_add(menu, menu_it); elm_menu_item_separator_add(menu, menu_it);
elm_menu_item_add(menu, menu_it, "document-new", "New ...", _edi_menu_new_cb, NULL); elm_menu_item_add(menu, menu_it, "document-new", "New ...", _edi_menu_new_cb, NULL);
elm_menu_item_add(menu, menu_it, "folder-new", "New Directory ...", _edi_menu_new_dir_cb, NULL); elm_menu_item_add(menu, menu_it, "folder-new", "New Directory ...", _edi_menu_new_dir_cb, NULL);
elm_menu_item_add(menu, menu_it, "document-save", "Save", _edi_menu_save_cb, NULL); _edi_menu_save = elm_menu_item_add(menu, menu_it, "document-save", "Save", _edi_menu_save_cb, NULL);
elm_menu_item_add(menu, menu_it, "window-new", "New window", _edi_menu_open_window_cb, NULL); elm_menu_item_add(menu, menu_it, "window-new", "New window", _edi_menu_open_window_cb, NULL);
elm_menu_item_add(menu, menu_it, "document-close", "Close", _edi_menu_close_cb, NULL); elm_menu_item_add(menu, menu_it, "document-close", "Close", _edi_menu_close_cb, NULL);
elm_menu_item_add(menu, menu_it, "document-close", "Close all", _edi_menu_closeall_cb, NULL); elm_menu_item_add(menu, menu_it, "document-close", "Close all", _edi_menu_closeall_cb, NULL);
@ -947,7 +949,7 @@ edi_toolbar_setup(Evas_Object *win)
evas_object_size_hint_weight_set(tb, 0.0, EVAS_HINT_EXPAND); evas_object_size_hint_weight_set(tb, 0.0, EVAS_HINT_EXPAND);
_edi_toolbar_item_add(tb, "document-new", "New File", _tb_new_cb); _edi_toolbar_item_add(tb, "document-new", "New File", _tb_new_cb);
_edi_toolbar_item_add(tb, "document-save", "Save", _tb_save_cb); _edi_toolbar_save =_edi_toolbar_item_add(tb, "document-save", "Save", _tb_save_cb);
_edi_toolbar_item_add(tb, "document-close", "Close", _tb_close_cb); _edi_toolbar_item_add(tb, "document-close", "Close", _tb_close_cb);
tb_it = elm_toolbar_item_append(tb, "separator", "", NULL, NULL); tb_it = elm_toolbar_item_append(tb, "separator", "", NULL, NULL);
@ -1033,11 +1035,16 @@ _edi_resize_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
static void static void
_edi_icon_update() _edi_icon_update()
{ {
Eina_Bool can_undo, can_redo = EINA_FALSE; Eina_Bool modified, can_undo, can_redo = EINA_FALSE;
can_undo = edi_mainview_can_undo(); can_undo = edi_mainview_can_undo();
can_redo = edi_mainview_can_redo(); can_redo = edi_mainview_can_redo();
modified = edi_mainview_modified();
elm_object_item_disabled_set(_edi_menu_save, !modified);
elm_object_disabled_set(_edi_toolbar_save, !modified);
elm_object_item_disabled_set(_edi_menu_undo, !can_undo); elm_object_item_disabled_set(_edi_menu_undo, !can_undo);
elm_object_item_disabled_set(_edi_menu_redo, !can_redo); elm_object_item_disabled_set(_edi_menu_redo, !can_redo);
@ -1079,6 +1086,14 @@ _edi_file_changed(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA
return ECORE_CALLBACK_RENEW; return ECORE_CALLBACK_RENEW;
} }
static Eina_Bool
_edi_file_saved(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
{
elm_object_item_disabled_set(_edi_menu_save, EINA_TRUE);
elm_object_disabled_set(_edi_toolbar_save, EINA_TRUE);
return ECORE_CALLBACK_RENEW;
}
void void
_edi_open_tabs() _edi_open_tabs()
{ {
@ -1185,6 +1200,7 @@ edi_open(const char *inputpath)
ecore_event_handler_add(EDI_EVENT_CONFIG_CHANGED, _edi_config_changed, NULL); ecore_event_handler_add(EDI_EVENT_CONFIG_CHANGED, _edi_config_changed, NULL);
ecore_event_handler_add(EDI_EVENT_TAB_CHANGED, _edi_tab_changed, NULL); ecore_event_handler_add(EDI_EVENT_TAB_CHANGED, _edi_tab_changed, NULL);
ecore_event_handler_add(EDI_EVENT_FILE_CHANGED, _edi_file_changed, NULL); ecore_event_handler_add(EDI_EVENT_FILE_CHANGED, _edi_file_changed, NULL);
ecore_event_handler_add(EDI_EVENT_FILE_SAVED, _edi_file_saved, NULL);
free(path); free(path);
return EINA_TRUE; return EINA_TRUE;
@ -1321,6 +1337,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
EDI_EVENT_TAB_CHANGED = ecore_event_type_new(); EDI_EVENT_TAB_CHANGED = ecore_event_type_new();
EDI_EVENT_FILE_CHANGED = ecore_event_type_new(); EDI_EVENT_FILE_CHANGED = ecore_event_type_new();
EDI_EVENT_FILE_SAVED = ecore_event_type_new();
if (!project_path) if (!project_path)
{ {

View File

@ -29,6 +29,7 @@ extern int _edi_log_dom;
extern int EDI_EVENT_TAB_CHANGED; extern int EDI_EVENT_TAB_CHANGED;
extern int EDI_EVENT_FILE_CHANGED; extern int EDI_EVENT_FILE_CHANGED;
extern int EDI_EVENT_FILE_SAVED;
#define EDI_CONTENT_SAVE_TIMEOUT 1 #define EDI_CONTENT_SAVE_TIMEOUT 1

View File

@ -543,8 +543,11 @@ edi_mainview_save()
if (!editor) if (!editor)
return; return;
editor->modified = EINA_FALSE;
code = elm_code_widget_code_get(editor->entry); code = elm_code_widget_code_get(editor->entry);
elm_code_file_save(code->file); elm_code_file_save(code->file);
ecore_event_add(EDI_EVENT_FILE_SAVED, NULL, NULL, NULL);
} }
void void
@ -629,6 +632,18 @@ edi_mainview_can_redo()
return elm_code_widget_can_redo_get(editor->entry); return elm_code_widget_can_redo_get(editor->entry);
} }
Eina_Bool
edi_mainview_modified()
{
Edi_Editor *editor;
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
if (!editor)
return EINA_FALSE;
return editor->modified;
}
void void
edi_mainview_cut() edi_mainview_cut()
{ {

View File

@ -133,6 +133,13 @@ void edi_mainview_closeall();
*/ */
void edi_mainview_undo(); void edi_mainview_undo();
/**
* Return if editor has been modified
*
* @ingroup Content
*/
Eina_Bool edi_mainview_modified();
/** /**
* See whether the current view can undo a change. * See whether the current view can undo a change.
* *