gui: Update undo/redo icons to show what actions can apply.

Also actually hook in the redo feature :)
This commit is contained in:
Andy Williams 2017-04-07 23:39:44 +01:00
parent 67709ae536
commit 2735b3f6c7
5 changed files with 131 additions and 3 deletions

View File

@ -26,6 +26,9 @@
#include "edi_private.h"
int EDI_EVENT_TAB_CHANGED;
int EDI_EVENT_FILE_CHANGED;
typedef struct _Edi_Panel_Slide_Effect
{
double max;
@ -43,6 +46,7 @@ static Elm_Object_Item *_edi_logpanel_item, *_edi_consolepanel_item, *_edi_testp
static Elm_Object_Item *_edi_selected_bottompanel;
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_main_win, *_edi_main_box, *_edi_message_popup;
int _edi_log_dom = -1;
@ -573,6 +577,13 @@ _tb_undo_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUS
edi_mainview_undo();
}
static void
_tb_redo_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
elm_toolbar_item_selected_set(elm_toolbar_selected_item_get(obj), EINA_FALSE);
edi_mainview_redo();
}
static void
_tb_cut_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
@ -754,6 +765,13 @@ _edi_menu_undo_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
edi_mainview_undo();
}
static void
_edi_menu_redo_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
edi_mainview_redo();
}
static void
_edi_menu_cut_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
@ -876,7 +894,8 @@ _edi_menu_setup(Evas_Object *win)
elm_menu_item_add(menu, menu_it, "application-exit", "Quit", _edi_menu_quit_cb, NULL);
menu_it = elm_menu_item_add(menu, NULL, NULL, "Edit", NULL, NULL);
elm_menu_item_add(menu, menu_it, "edit-undo", "Undo", _edi_menu_undo_cb, NULL);
_edi_menu_undo = elm_menu_item_add(menu, menu_it, "edit-undo", "Undo", _edi_menu_undo_cb, NULL);
_edi_menu_redo = elm_menu_item_add(menu, menu_it, "edit-redo", "Redo", _edi_menu_redo_cb, NULL);
elm_menu_item_separator_add(menu, menu_it);
elm_menu_item_add(menu, menu_it, "edit-cut", "Cut", _edi_menu_cut_cb, NULL);
elm_menu_item_add(menu, menu_it, "edit-copy", "Copy", _edi_menu_copy_cb, NULL);
@ -901,7 +920,7 @@ _edi_menu_setup(Evas_Object *win)
elm_menu_item_add(menu, menu_it, "help-about", "About", _edi_menu_about_cb, NULL);
}
static void
static Evas_Object *
_edi_toolbar_item_add(Evas_Object *tb, const char *icon, const char *name, Evas_Smart_Cb func)
{
Evas_Object *content;
@ -910,6 +929,8 @@ _edi_toolbar_item_add(Evas_Object *tb, const char *icon, const char *name, Evas_
tb_it = elm_toolbar_item_append(tb, icon, NULL, func, NULL);
content = elm_toolbar_item_object_get(tb_it);
elm_object_tooltip_text_set(content, name);
return content;
}
static Evas_Object *
@ -934,7 +955,8 @@ edi_toolbar_setup(Evas_Object *win)
tb_it = elm_toolbar_item_append(tb, "separator", "", NULL, NULL);
elm_toolbar_item_separator_set(tb_it, EINA_TRUE);
_edi_toolbar_item_add(tb, "edit-undo", "Undo", _tb_undo_cb);
_edi_toolbar_undo = _edi_toolbar_item_add(tb, "edit-undo", "Undo", _tb_undo_cb);
_edi_toolbar_redo = _edi_toolbar_item_add(tb, "edit-redo", "Redo", _tb_redo_cb);
tb_it = elm_toolbar_item_append(tb, "separator", "", NULL, NULL);
elm_toolbar_item_separator_set(tb_it, EINA_TRUE);
@ -1010,6 +1032,21 @@ _edi_resize_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
_edi_project_config_save();
}
static void
_edi_icon_update()
{
Eina_Bool can_undo, can_redo = EINA_FALSE;
can_undo = edi_mainview_can_undo();
can_redo = edi_mainview_can_redo();
elm_object_item_disabled_set(_edi_menu_undo, !can_undo);
elm_object_item_disabled_set(_edi_menu_redo, !can_redo);
elm_object_disabled_set(_edi_toolbar_undo, !can_undo);
elm_object_disabled_set(_edi_toolbar_redo, !can_redo);
}
static void
_edi_toolbar_set_visible(Eina_Bool visible)
{
@ -1030,6 +1067,20 @@ _edi_config_changed(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EI
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_edi_tab_changed(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
{
_edi_icon_update();
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_edi_file_changed(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
{
_edi_icon_update();
return ECORE_CALLBACK_RENEW;
}
void
_edi_open_tabs()
{
@ -1119,7 +1170,11 @@ edi_open(const char *inputpath)
_edi_config_project_add(path);
_edi_open_tabs();
_edi_icon_update();
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_FILE_CHANGED, _edi_file_changed, NULL);
free(path);
return EINA_TRUE;
@ -1254,6 +1309,9 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
elm_app_info_set(elm_main, "edi", "images/edi.png");
EDI_EVENT_TAB_CHANGED = ecore_event_type_new();
EDI_EVENT_FILE_CHANGED = ecore_event_type_new();
if (!project_path)
{
if (create)

View File

@ -27,6 +27,9 @@ extern int _edi_log_dom;
#endif
#define DBG(...) EINA_LOG_DOM_DBG(_edi_log_dom, __VA_ARGS__)
extern int EDI_EVENT_TAB_CHANGED;
extern int EDI_EVENT_FILE_CHANGED;
#define EDI_CONTENT_SAVE_TIMEOUT 1
#define FONT_PREVIEW " Evas *dostuff(void) {...}"

View File

@ -657,6 +657,12 @@ _edit_cursor_moved(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EI
elm_object_text_set((Evas_Object *)data, buf);
}
static void
_edit_file_changed(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
ecore_event_add(EDI_EVENT_FILE_CHANGED, NULL, NULL, NULL);
}
static void
_edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_Item *item)
{
@ -708,6 +714,7 @@ _edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_I
_edit_cursor_moved(position, editor->entry, NULL);
evas_object_smart_callback_add(editor->entry, "cursor,changed", _edit_cursor_moved, position);
evas_object_smart_callback_add(editor->entry, "changed,user", _edit_file_changed, position);
}
#if HAVE_LIBCLANG

View File

@ -142,6 +142,8 @@ edi_mainview_item_select(Edi_Mainview_Item *item)
evas_object_geometry_get(item->tab, NULL, NULL, &tabw, NULL);
elm_scroller_region_bring_in(_tab_scroller, region_x, 0, tabw, 0);
}
ecore_event_add(EDI_EVENT_TAB_CHANGED, NULL, NULL, NULL);
}
static void
@ -590,6 +592,43 @@ edi_mainview_undo()
elm_code_widget_undo(editor->entry);
}
Eina_Bool
edi_mainview_can_undo()
{
Edi_Editor *editor;
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
if (!editor)
return EINA_FALSE;
return elm_code_widget_can_undo_get(editor->entry);
}
void
edi_mainview_redo()
{
Edi_Editor *editor;
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
if (editor)
elm_code_widget_redo(editor->entry);
}
Eina_Bool
edi_mainview_can_redo()
{
Edi_Editor *editor;
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
if (!editor)
return EINA_FALSE;
return elm_code_widget_can_redo_get(editor->entry);
}
void
edi_mainview_cut()
{

View File

@ -133,6 +133,27 @@ void edi_mainview_closeall();
*/
void edi_mainview_undo();
/**
* See whether the current view can undo a change.
*
* @ingroup Content
*/
Eina_Bool edi_mainview_can_undo();
/**
* Redo the most recent change in the current view.
*
* @ingroup Content
*/
void edi_mainview_redo();
/**
* See whether the current view can redo a change.
*
* @ingroup Content
*/
Eina_Bool edi_mainview_can_redo();
/**
* Cut the current selection into the clipboard.
*