*/
VbResult ex_keypress(int key)
{
- /* TODO allow to get the right prompt like ':', '/', ';o', ... */
- char *prompt = ":";
GtkTextIter start, end;
GtkTextBuffer *buffer = vb.gui.buffer;
GtkTextMark *mark;
case CTRL('B'):
/* move the cursor direct behind the prompt */
- gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(prompt));
+ gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(vb.state.prompt));
gtk_text_buffer_place_cursor(buffer, &start);
break;
/* remove everythings between cursor and prompt */
mark = gtk_text_buffer_get_insert(buffer);
gtk_text_buffer_get_iter_at_mark(buffer, &end, mark);
- gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(prompt));
+ gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(vb.state.prompt));
gtk_text_buffer_delete(buffer, &start, &end);
break;
/**
* Write a new history entry to the end of history file.
- * TODO identify the history by the promt char
*/
void history_add(HistoryType type, const char *value, const char *additional)
{
gboolean is_inspecting;
GList *downloads;
gboolean processed_key;
- char *title; /* holds the window title */
+ char *title; /* holds the window title */
+#define PROMPT_SIZE 3
+ char prompt[PROMPT_SIZE]; /* current prompt ':', ';o', '/' */
} State;
typedef struct {
vb_update_statusbar();
}
+/**
+ * Set the prompt chars and switch to new mode.
+ *
+ * @id: Mode id.
+ * @prompt: Prompt string to set as current promt.
+ * @print_prompt: Indicates if the new set prompt should be put into inputbox
+ * after switching the mode.
+ */
+void mode_enter_promt(char id, const char *prompt, gboolean print_prompt)
+{
+ /* set the prompt to be accessible in mode_enter */
+ strncpy(vb.state.prompt, prompt, PROMPT_SIZE - 1);
+ vb.state.prompt[PROMPT_SIZE - 1] = '\0';
+
+ mode_enter(id);
+
+ if (print_prompt) {
+ /* set it after the mode was entered so that the modes input change
+ * event listener could grep the new prompt */
+ vb_set_input_text(vb.state.prompt);
+ }
+}
+
VbResult mode_handle_key(int key)
{
VbResult res;
void mode_add(char id, ModeTransitionFunc enter, ModeTransitionFunc leave,
ModeKeyFunc keypress, ModeInputChangedFunc input_changed);
void mode_enter(char id);
+void mode_enter_promt(char id, const char *prompt, gboolean print_prompt);
VbResult mode_handle_key(int key);
gboolean mode_input_focusin(GtkWidget *widget, GdkEventFocus *event, gpointer data);
gboolean mode_input_focusout(GtkWidget *widget, GdkEventFocus *event, gpointer data);
*/
void normal_leave(void)
{
- /* TODO clean those only if they where active */
command_search(&((Arg){0}));
}
static VbResult normal_ex(const NormalCmdInfo *info)
{
- mode_enter('c');
if (info->cmd == 'F') {
- vb_set_input_text(";t");
+ mode_enter_promt('c', ";t", true);
} else if (info->cmd == 'f') {
- vb_set_input_text(";o");
+ mode_enter_promt('c', ";o", true);
} else {
char prompt[2] = {info->cmd, '\0'};
- vb_set_input_text(prompt);
+ mode_enter_promt('c', prompt, true);
}
return RESULT_COMPLETE;
return RESULT_ERROR;
}
- mode_enter('c');
- vb_set_input_text(prompt);
+ mode_enter_promt('c', prompt, true);
return RESULT_COMPLETE;
}
}
/* switch mode after setting the input text to not trigger the
* commands modes input change handler */
- mode_enter('c');
+ mode_enter_promt('c', ":", false);
return RESULT_COMPLETE;
}
}
}
}
- /* TODO sort the store model */
g_list_free(src);
return found;