REQ_(STOP_LOADING, "Stop all loading views"), \
REQ_(TOGGLE_LINENO, "Toggle line numbers"), \
REQ_(TOGGLE_REV_GRAPH, "Toggle revision graph visualization"), \
- REQ_(STATUS_UPDATE, "Update file status") \
+ REQ_(STATUS_UPDATE, "Update file status"), \
+ REQ_(EDIT, "Open in editor")
/* User action requests. */
static char opt_search[SIZEOF_STR] = "";
static char opt_cdup[SIZEOF_STR] = "";
static char opt_git_dir[SIZEOF_STR] = "";
+static char opt_editor[SIZEOF_STR] = "";
enum option_type {
OPT_NONE,
{ 'g', REQ_TOGGLE_REV_GRAPH },
{ ':', REQ_PROMPT },
{ 'u', REQ_STATUS_UPDATE },
+ { 'e', REQ_EDIT },
/* Using the ncurses SIGWINCH handler. */
{ KEY_RESIZE, REQ_SCREEN_RESIZE },
update_view_title(view);
}
+static void
+open_editor(struct view *view, char *file)
+{
+ char cmd[SIZEOF_STR];
+ char file_sq[SIZEOF_STR];
+ char *editor;
+
+ editor = getenv("GIT_EDITOR");
+ if (!editor && *opt_editor)
+ editor = opt_editor;
+ if (!editor)
+ editor = getenv("VISUAL");
+ if (!editor)
+ editor = getenv("EDITOR");
+ if (!editor)
+ editor = "vi";
+
+ if (sq_quote(file_sq, 0, file) < sizeof(file_sq) &&
+ string_format(cmd, "%s %s", editor, file_sq)) {
+ def_prog_mode(); /* save current tty modes */
+ endwin(); /* restore original tty modes */
+ system(cmd);
+ reset_prog_mode();
+ redraw_display();
+ }
+}
/*
* User request switch noodle
redraw_display();
break;
+ case REQ_EDIT:
+ report("Nothing to edit");
+ break;
+
+ case REQ_ENTER:
+ report("Nothing to enter");
+ break;
case REQ_NONE:
doupdate();
return TRUE;
}
-static void status_update(struct view *view);
-
static enum request
-status_request(struct view *view, enum request request, struct line *line)
+status_enter(struct view *view, struct line *line)
{
struct status *status = line->data;
char path[SIZEOF_STR] = "";
char *info;
size_t cmdsize = 0;
- if (request == REQ_STATUS_UPDATE) {
- status_update(view);
- return REQ_NONE;
- }
-
- if (request != REQ_ENTER)
- return request;
-
if (line->type == LINE_STAT_NONE ||
(!status && line[1].type == LINE_STAT_NONE)) {
report("No file to diff");
return REQ_NONE;
}
+
static bool
status_update_file(struct view *view, struct status *status, enum line_type type)
{
open_view(view, REQ_VIEW_STATUS, OPEN_RELOAD);
}
+static enum request
+status_request(struct view *view, enum request request, struct line *line)
+{
+ struct status *status = line->data;
+
+ switch (request) {
+ case REQ_STATUS_UPDATE:
+ status_update(view);
+ break;
+
+ case REQ_EDIT:
+ if (!status)
+ return request;
+
+ open_editor(view, status->name);
+ break;
+
+ case REQ_ENTER:
+ status_enter(view, line);
+ break;
+
+ default:
+ return request;
+ }
+
+ return REQ_NONE;
+}
+
static void
status_select(struct view *view, struct line *line)
{
if (!strcmp(name, "i18n.commitencoding"))
string_ncopy(opt_encoding, value, valuelen);
+ if (!strcmp(name, "core.editor"))
+ string_ncopy(opt_editor, value, valuelen);
+
return OK;
}