diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index 2c02442..7f26418 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -389,6 +389,18 @@ _item_menu_scm_stage_cb(void *data, Evas_Object *obj EINA_UNUSED, edi_filepanel_item_update(sd->path); } +static void +_item_menu_scm_undo_cb(void *data, Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Edi_Dir_Data *sd = data; + + edi_scm_undo(sd->path); + edi_filepanel_scm_status_update(); + edi_filepanel_item_update(sd->path); +} + + static void _item_menu_scm_unstage_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) @@ -484,6 +496,12 @@ _item_menu_create(Evas_Object *win, Edi_Dir_Data *sd) menu_it = elm_menu_item_add(menu, NULL, NULL, eina_slstr_printf("%s...", _("Source Control")), NULL, NULL); + menu_it2 = elm_menu_item_add(menu, menu_it, "edit-undo", _("Undo Changes"), _item_menu_scm_undo_cb, sd); + if (status == EDI_FILE_STATUS_UNMODIFIED || status == EDI_FILE_STATUS_STAGED) + elm_object_item_disabled_set(menu_it2, EINA_TRUE); + + elm_menu_item_separator_add(menu, menu_it); + menu_it2 = elm_menu_item_add(menu, menu_it, "document-save-as", _("Stage Changes"), _item_menu_scm_stage_cb, sd); if (status == EDI_FILE_STATUS_UNMODIFIED || status == EDI_FILE_STATUS_STAGED) elm_object_item_disabled_set(menu_it2, EINA_TRUE); diff --git a/src/lib/edi_scm.c b/src/lib/edi_scm.c index 1553f8b..8c54bae 100644 --- a/src/lib/edi_scm.c +++ b/src/lib/edi_scm.c @@ -141,6 +141,21 @@ _edi_scm_git_file_unstage(const char *path) return code; } +static int +_edi_scm_git_file_undo(const char *path) +{ + int code; + Eina_Strbuf *command = eina_strbuf_new(); + + eina_strbuf_append_printf(command, "git checkout %s", path); + + code = _edi_scm_exec(eina_strbuf_string_get(command)); + + eina_strbuf_free(command); + + return code; +} + static int _edi_scm_git_file_mod(const char *path) { @@ -645,6 +660,22 @@ edi_scm_unstage(const char *path) return result; } +EAPI int +edi_scm_undo(const char *path) +{ + char *escaped; + int result; + Edi_Scm_Engine *e = edi_scm_engine_get(); + + escaped = ecore_file_escape_name(path); + + result = e->file_undo(escaped); + + free(escaped); + + return result; +} + EAPI int edi_scm_move(const char *src, const char *dest) { @@ -809,6 +840,7 @@ _edi_scm_git_init(const char *rootdir) engine->file_mod = _edi_scm_git_file_mod; engine->file_del = _edi_scm_git_file_del; engine->file_unstage = _edi_scm_git_file_unstage; + engine->file_undo = _edi_scm_git_file_undo; engine->move = _edi_scm_git_file_move; engine->status = _edi_scm_git_status; engine->diff = _edi_scm_git_diff; diff --git a/src/lib/edi_scm.h b/src/lib/edi_scm.h index ad3858e..aad00a1 100644 --- a/src/lib/edi_scm.h +++ b/src/lib/edi_scm.h @@ -35,6 +35,7 @@ typedef struct _Edi_Scm_Status typedef int (scm_fn_stage)(const char *path); typedef int (scm_fn_unstage)(const char *path); +typedef int (scm_fn_undo)(const char *path); typedef int (scm_fn_mod)(const char *path); typedef int (scm_fn_del)(const char *path); typedef int (scm_fn_move)(const char *src, const char *dest); @@ -63,6 +64,7 @@ typedef struct _Edi_Scm_Engine scm_fn_stage *file_stage; scm_fn_unstage *file_unstage; + scm_fn_undo *file_undo; scm_fn_mod *file_mod; scm_fn_del *file_del; scm_fn_move *move; @@ -176,6 +178,16 @@ int edi_scm_stage(const char *path); */ int edi_scm_unstage(const char *path); +/** + * Reset file changes to last commit state. + * + * @param path The file path. + * @return The status code of command executed. + * + * @ingroup Scm +*/ +int edi_scm_undo(const char *path); + /** * Del file from those monitored by SCM. *