filepanel: Add Undo (checkout) to SCM Menu.

Add an option to checkout file to last commit to
the menu.
This commit is contained in:
Alastair Poole 2019-12-15 17:09:12 +00:00
parent 905d232d31
commit ee376c04a9
3 changed files with 62 additions and 0 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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.
*