Added support for markers

It is now possible to add markers by using "m" followed by the id key
that should identify the marker. To jump back to the page that is
represented by the marker "'" is used. To toggle between the latest
positions the command "''" is used.
This commit is contained in:
Moritz Lipp 2010-01-30 23:48:36 +01:00
parent acf114b2ec
commit 8d449e3ff7
2 changed files with 132 additions and 29 deletions

View file

@ -46,30 +46,32 @@ static const char DEFAULT_TEXT[] = "[No Name]";
/* shortcuts */
Shortcut shortcuts[] = {
/* mask, key, function, mode, argument */
{GDK_CONTROL_MASK, GDK_n, sc_toggle_statusbar, -1, {0} },
{GDK_CONTROL_MASK, GDK_m, sc_toggle_inputbar, -1, {0} },
{GDK_CONTROL_MASK, GDK_n, sc_toggle_statusbar, NORMAL, {0} },
{GDK_CONTROL_MASK, GDK_m, sc_toggle_inputbar, NORMAL, {0} },
{GDK_CONTROL_MASK, GDK_q, sc_quit, -1, {0} },
{GDK_CONTROL_MASK, GDK_c, sc_abort, -1, {0} },
{GDK_CONTROL_MASK, GDK_i, sc_revert_video, -1, {0} },
{GDK_SHIFT_MASK, GDK_slash, sc_focus_inputbar, -1, { .data = "/" } },
{GDK_SHIFT_MASK, GDK_question, sc_focus_inputbar, -1, { .data = "?" } },
{0, GDK_Tab, sc_toggle_index, -1, {0} },
{0, GDK_J, sc_navigate, -1, { NEXT } },
{0, GDK_K, sc_navigate, -1, { PREVIOUS } },
{GDK_CONTROL_MASK, GDK_i, sc_revert_video, NORMAL, {0} },
{GDK_SHIFT_MASK, GDK_slash, sc_focus_inputbar, NORMAL, { .data = "/" } },
{GDK_SHIFT_MASK, GDK_question, sc_focus_inputbar, NORMAL, { .data = "?" } },
{0, GDK_Tab, sc_toggle_index, NORMAL, {0} },
{0, GDK_J, sc_navigate, NORMAL, { NEXT } },
{0, GDK_K, sc_navigate, NORMAL, { PREVIOUS } },
{0, GDK_Escape, sc_abort, -1, {0} },
{0, GDK_i, sc_change_mode, NORMAL, { INSERT } },
{0, GDK_v, sc_change_mode, NORMAL, { VISUAL } },
{0, GDK_colon, sc_focus_inputbar, -1, { .data = ":" } },
{0, GDK_o, sc_focus_inputbar, -1, { .data = ":open " } },
{0, GDK_r, sc_rotate, -1, {0} },
{0, GDK_h, sc_scroll, -1, { LEFT } },
{0, GDK_j, sc_scroll, -1, { UP } },
{0, GDK_k, sc_scroll, -1, { DOWN } },
{0, GDK_l, sc_scroll, -1, { RIGHT } },
{0, GDK_n, sc_search, -1, { FORWARD } },
{0, GDK_N, sc_search, -1, { BACKWARD } },
{0, GDK_a, sc_adjust_window, -1, { ADJUST_BESTFIT } },
{0, GDK_s, sc_adjust_window, -1, { ADJUST_WIDTH } },
{0, GDK_m, sc_change_mode, NORMAL, { ADD_MARKER } },
{0, GDK_apostrophe, sc_change_mode, NORMAL, { EVAL_MARKER } },
{0, GDK_colon, sc_focus_inputbar, NORMAL, { .data = ":" } },
{0, GDK_o, sc_focus_inputbar, NORMAL, { .data = ":open " } },
{0, GDK_r, sc_rotate, NORMAL, {0} },
{0, GDK_h, sc_scroll, NORMAL, { LEFT } },
{0, GDK_j, sc_scroll, NORMAL, { UP } },
{0, GDK_k, sc_scroll, NORMAL, { DOWN } },
{0, GDK_l, sc_scroll, NORMAL, { RIGHT } },
{0, GDK_n, sc_search, NORMAL, { FORWARD } },
{0, GDK_N, sc_search, NORMAL, { BACKWARD } },
{0, GDK_a, sc_adjust_window, NORMAL, { ADJUST_BESTFIT } },
{0, GDK_s, sc_adjust_window, NORMAL, { ADJUST_WIDTH } },
{0, GDK_BackSpace, sc_change_buffer, -1, { DELETE_LAST } },
};
@ -102,15 +104,15 @@ Command commands[] = {
/* buffer commands */
BufferCommand buffer_commands[] = {
/* regex, function, argument */
{"^gg$", bcmd_goto, { TOP } },
{"^G$", bcmd_goto, { BOTTOM } },
{"^[0-9]+G$", bcmd_goto, {0} },
{"^zI$", bcmd_zoom, { ZOOM_IN } },
{"^zO$", bcmd_zoom, { ZOOM_OUT } },
{"^z0$", bcmd_zoom, { ZOOM_ORIGINAL } },
{"^[0-9]+Z$", bcmd_zoom, { ZOOM_SPECIFIC } },
{"^[0-9]+%$", bcmd_scroll, {0} },
/* regex, function, argument */
{"^gg$", bcmd_goto, { TOP } },
{"^G$", bcmd_goto, { BOTTOM } },
{"^[0-9]+G$", bcmd_goto, {0} },
{"^zI$", bcmd_zoom, { ZOOM_IN } },
{"^zO$", bcmd_zoom, { ZOOM_OUT } },
{"^z0$", bcmd_zoom, { ZOOM_ORIGINAL } },
{"^[0-9]+Z$", bcmd_zoom, { ZOOM_SPECIFIC } },
{"^[0-9]+%$", bcmd_scroll, {0} },
};
/* special commands */

103
zathura.c
View file

@ -26,7 +26,7 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN,
ERROR, WARNING, NEXT_GROUP, PREVIOUS_GROUP,
ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC,
FORWARD, BACKWARD, ADJUST_BESTFIT, ADJUST_WIDTH,
CONTINUOUS, DELETE_LAST };
CONTINUOUS, DELETE_LAST, ADD_MARKER, EVAL_MARKER };
/* typedefs */
struct CElement
@ -123,6 +123,12 @@ typedef struct
char* description;
} Setting;
typedef struct
{
int id;
int page;
} Marker;
/* zathura */
struct
{
@ -196,6 +202,13 @@ struct
int scroll_percentage;
} State;
struct
{
Marker* markers;
int number_of_markers;
int last;
} Marker;
struct
{
PopplerDocument *document;
@ -212,10 +225,12 @@ struct
/* function declarations */
void init_zathura();
void add_marker(int);
void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*);
void change_mode(int);
void highlight_result(int, PopplerRectangle*);
void draw(int);
void eval_marker(int);
void notify(int, char*);
void update_status();
void recalcRectangle(int, PopplerRectangle*);
@ -267,8 +282,10 @@ Completion* cc_print(char*);
Completion* cc_set(char*);
/* buffer command declarations */
void bcmd_evalmarker(char*, Argument*);
void bcmd_goto(char*, Argument*);
void bcmd_scroll(char*, Argument*);
void bcmd_setmarker(char*, Argument*);
void bcmd_zoom(char*, Argument*);
/* special command delcarations */
@ -324,6 +341,10 @@ init_zathura()
Zathura.State.pages = "";
Zathura.State.scroll_percentage = 0;
Zathura.Marker.markers = NULL;
Zathura.Marker.number_of_markers = 0;
Zathura.Marker.last = -1;
/* UI */
Zathura.UI.window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
Zathura.UI.box = GTK_BOX(gtk_vbox_new(FALSE, 0));
@ -416,6 +437,37 @@ init_zathura()
gtk_box_pack_end( Zathura.UI.box, GTK_WIDGET(Zathura.UI.inputbar), FALSE, FALSE, 0);
}
void
add_marker(int id)
{
if( (id < 0x30) || (id > 0x7A))
return;
/* current information */
int page_number = Zathura.PDF.page_number;
/* search if entry already exists */
int i;
for(i = 0; i < Zathura.Marker.number_of_markers; i++)
{
if(Zathura.Marker.markers[i].id == id)
{
Zathura.Marker.markers[i].page = page_number;
Zathura.Marker.last = page_number;
return;
}
}
/* add new marker */
int marker_index = Zathura.Marker.number_of_markers++;
Zathura.Marker.markers = realloc(Zathura.Marker.markers, sizeof(Marker) *
(Zathura.Marker.number_of_markers));
Zathura.Marker.markers[marker_index].id = id;
Zathura.Marker.markers[marker_index].page = page_number;
Zathura.Marker.last = page_number;
}
void
build_index(GtkTreeModel* model, GtkTreeIter* parent, PopplerIndexIter* index_iter)
{
@ -551,6 +603,12 @@ change_mode(int mode)
case VISUAL:
mode_text = "-- VISUAL --";
break;
case ADD_MARKER:
mode_text = "";
break;
case EVAL_MARKER:
mode_text = "";
break;
default:
mode_text = "";
mode = NORMAL;
@ -561,6 +619,30 @@ change_mode(int mode)
notify(DEFAULT, mode_text);
}
void
eval_marker(int id)
{
/* go to last marker */
if(id == 0x27)
{
int current_page = Zathura.PDF.page_number;
set_page(Zathura.Marker.last);
Zathura.Marker.last = current_page;
return;
}
/* search markers */
int i;
for(i = 0; i < Zathura.Marker.number_of_markers; i++)
{
if(Zathura.Marker.markers[i].id == id)
{
set_page(Zathura.Marker.markers[i].page);
return;
}
}
}
void
highlight_result(int page_id, PopplerRectangle* rectangle)
{
@ -1464,6 +1546,12 @@ cmd_close(int argc, char** argv)
Zathura.UI.information = NULL;
}
/* free markers */
if(Zathura.Marker.markers)
free(Zathura.Marker.markers);
Zathura.Marker.number_of_markers = 0;
Zathura.Marker.last = -1;
update_status();
return TRUE;
@ -2222,6 +2310,19 @@ cb_view_kb_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
}
}
if(Zathura.Global.mode == ADD_MARKER)
{
add_marker(event->keyval);
change_mode(NORMAL);
return TRUE;
}
else if(Zathura.Global.mode == EVAL_MARKER)
{
eval_marker(event->keyval);
change_mode(NORMAL);
return TRUE;
}
/* append only numbers and characters to buffer */
if( (event->keyval >= 0x21) && (event->keyval <= 0x7A))
{