mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 06:16:00 +01:00
Added :offset command and some style updates
This commit is contained in:
parent
defbf056c1
commit
90796b5b5c
12 changed files with 87 additions and 30 deletions
37
commands.c
37
commands.c
|
@ -1,6 +1,7 @@
|
|||
/* See LICENSE file for license and copyright information */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "commands.h"
|
||||
|
@ -347,8 +348,7 @@ cmd_export(girara_session_t* session, girara_list_t* argument_list)
|
|||
return false;
|
||||
}
|
||||
|
||||
const unsigned int argc = girara_list_size(argument_list);
|
||||
if (argc != 2) {
|
||||
if (girara_list_size(argument_list) != 2) {
|
||||
girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments given."));
|
||||
return false;
|
||||
}
|
||||
|
@ -371,3 +371,36 @@ cmd_export(girara_session_t* session, girara_list_t* argument_list)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
cmd_offset(girara_session_t* session, girara_list_t* argument_list)
|
||||
{
|
||||
g_return_val_if_fail(session != NULL, false);
|
||||
g_return_val_if_fail(session->global.data != NULL, false);
|
||||
zathura_t* zathura = session->global.data;
|
||||
if (zathura->document == NULL) {
|
||||
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* no argument: take current page as offset */
|
||||
unsigned int page_offset = zathura->document->current_page_number;
|
||||
|
||||
/* retrieve offset from argument */
|
||||
if (girara_list_size(argument_list) == 1) {
|
||||
const char* value = girara_list_nth(argument_list, 0);
|
||||
if (value != NULL) {
|
||||
page_offset = atoi(value);
|
||||
if (page_offset == 0 && strcmp(value, "0") != 0) {
|
||||
girara_notify(session, GIRARA_WARNING, _("Argument must be a number."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (page_offset < zathura->document->number_of_pages) {
|
||||
zathura->document->page_offset = page_offset;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -124,4 +124,13 @@ bool cmd_search(girara_session_t* session, const char* input, girara_argument_t*
|
|||
*/
|
||||
bool cmd_export(girara_session_t* session, girara_list_t* argument_list);
|
||||
|
||||
/**
|
||||
* Set page offset
|
||||
*
|
||||
* @param session The used girara session
|
||||
* @param argument_list List of passed arguments
|
||||
* @return true if no error occured
|
||||
*/
|
||||
bool cmd_offset(girara_session_t* session, girara_list_t* argument_list);
|
||||
|
||||
#endif // COMMANDS_H
|
||||
|
|
1
config.c
1
config.c
|
@ -252,6 +252,7 @@ config_load_default(zathura_t* zathura)
|
|||
girara_inputbar_command_add(gsession, "write", NULL, cmd_save, cc_write, _("Save document"));
|
||||
girara_inputbar_command_add(gsession, "write!", NULL, cmd_savef, cc_write, _("Save document (and force overwriting)"));
|
||||
girara_inputbar_command_add(gsession, "export", NULL, cmd_export, cc_export, _("Save attachments"));
|
||||
girara_inputbar_command_add(gsession, "offset", NULL, cmd_offset, NULL, _("Set page offset"));
|
||||
|
||||
girara_special_command_add(gsession, '/', cmd_search, true, FORWARD, NULL);
|
||||
girara_special_command_add(gsession, '?', cmd_search, true, BACKWARD, NULL);
|
||||
|
|
|
@ -40,9 +40,9 @@ static bool plain_remove_bookmark(zathura_database_t* db, const char* file,
|
|||
static girara_list_t* plain_load_bookmarks(zathura_database_t* db,
|
||||
const char* file);
|
||||
static bool plain_set_fileinfo(zathura_database_t* db, const char* file,
|
||||
unsigned int page, int offset, double scale, int rotation);
|
||||
unsigned int page, unsigned int offset, double scale, unsigned int rotation);
|
||||
static bool plain_get_fileinfo(zathura_database_t* db, const char* file,
|
||||
unsigned int* page, int* offset, double* scale, int* rotation);
|
||||
unsigned int* page, unsigned int* offset, double* scale, unsigned int* rotation);
|
||||
static void plain_set_property(GObject* object, guint prop_id,
|
||||
const GValue* value, GParamSpec* pspec);
|
||||
|
||||
|
@ -363,7 +363,7 @@ plain_load_bookmarks(zathura_database_t* db, const char* file)
|
|||
|
||||
static bool
|
||||
plain_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
|
||||
page, int offset, double scale, int rotation)
|
||||
page, unsigned int offset, double scale, unsigned int rotation)
|
||||
{
|
||||
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
|
||||
if (priv->history == NULL) {
|
||||
|
@ -388,7 +388,7 @@ plain_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
|
|||
|
||||
static bool
|
||||
plain_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
|
||||
page, int* offset, double* scale, int* rotation)
|
||||
page, unsigned int* offset, double* scale, unsigned int* rotation)
|
||||
{
|
||||
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
|
||||
if (priv->history == NULL) {
|
||||
|
|
|
@ -20,9 +20,9 @@ static bool sqlite_remove_bookmark(zathura_database_t* db, const char* file,
|
|||
static girara_list_t* sqlite_load_bookmarks(zathura_database_t* db,
|
||||
const char* file);
|
||||
static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file,
|
||||
unsigned int page, int offset, double scale, int rotation);
|
||||
unsigned int page, unsigned int offset, double scale, unsigned int rotation);
|
||||
static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file,
|
||||
unsigned int* page, int* offset, double* scale, int* rotation);
|
||||
unsigned int* page, unsigned int* offset, double* scale, unsigned int* rotation);
|
||||
static void sqlite_set_property(GObject* object, guint prop_id,
|
||||
const GValue* value, GParamSpec* pspec);
|
||||
|
||||
|
@ -273,7 +273,7 @@ sqlite_load_bookmarks(zathura_database_t* db, const char* file)
|
|||
|
||||
static bool
|
||||
sqlite_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
|
||||
page, int offset, double scale, int rotation)
|
||||
page, unsigned int offset, double scale, unsigned int rotation)
|
||||
{
|
||||
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
|
||||
|
||||
|
@ -303,7 +303,7 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
|
|||
|
||||
static bool
|
||||
sqlite_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
|
||||
page, int* offset, double* scale, int* rotation)
|
||||
page, unsigned int* offset, double* scale, unsigned int* rotation)
|
||||
{
|
||||
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
|
||||
|
||||
|
|
25
database.c
25
database.c
|
@ -9,7 +9,8 @@ zathura_database_default_init(ZathuraDatabaseInterface* GIRARA_UNUSED(iface))
|
|||
{
|
||||
}
|
||||
|
||||
void zathura_db_free(zathura_database_t* db)
|
||||
void
|
||||
zathura_db_free(zathura_database_t* db)
|
||||
{
|
||||
if (db == NULL) {
|
||||
return;
|
||||
|
@ -18,7 +19,8 @@ void zathura_db_free(zathura_database_t* db)
|
|||
g_object_unref(db);
|
||||
}
|
||||
|
||||
bool zathura_db_add_bookmark(zathura_database_t* db, const char* file,
|
||||
bool
|
||||
zathura_db_add_bookmark(zathura_database_t* db, const char* file,
|
||||
zathura_bookmark_t* bookmark)
|
||||
{
|
||||
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && bookmark != NULL, false);
|
||||
|
@ -26,24 +28,26 @@ bool zathura_db_add_bookmark(zathura_database_t* db, const char* file,
|
|||
return ZATHURA_DATABASE_GET_INTERFACE(db)->add_bookmark(db, file, bookmark);
|
||||
}
|
||||
|
||||
bool zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const
|
||||
char* id)
|
||||
bool
|
||||
zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char*
|
||||
id)
|
||||
{
|
||||
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && id != NULL, false);
|
||||
|
||||
return ZATHURA_DATABASE_GET_INTERFACE(db)->remove_bookmark(db, file, id);
|
||||
}
|
||||
|
||||
girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char*
|
||||
file)
|
||||
girara_list_t*
|
||||
zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
|
||||
{
|
||||
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL, NULL);
|
||||
|
||||
return ZATHURA_DATABASE_GET_INTERFACE(db)->load_bookmarks(db, file);
|
||||
}
|
||||
|
||||
bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned
|
||||
int page, int offset, double scale, int rotation)
|
||||
bool
|
||||
zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
|
||||
page, unsigned int offset, double scale, unsigned int rotation)
|
||||
{
|
||||
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL, false);
|
||||
|
||||
|
@ -51,8 +55,9 @@ bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned
|
|||
scale, rotation);
|
||||
}
|
||||
|
||||
bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned
|
||||
int* page, int* offset, double* scale, int* rotation)
|
||||
bool
|
||||
zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
|
||||
page, unsigned int* offset, double* scale, unsigned int* rotation)
|
||||
{
|
||||
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && page != NULL &&
|
||||
offset != NULL && scale != NULL && rotation != NULL, false);
|
||||
|
|
|
@ -27,14 +27,15 @@ struct _ZathuraDatabaseInterface
|
|||
|
||||
/* interface methords */
|
||||
bool (*add_bookmark)(ZathuraDatabase* db, const char* file, zathura_bookmark_t* bookmark);
|
||||
|
||||
bool (*remove_bookmark)(ZathuraDatabase* db, const char* file, const char* id);
|
||||
girara_list_t* (*load_bookmarks)(ZathuraDatabase* db, const char* file);
|
||||
|
||||
bool (*set_fileinfo)(ZathuraDatabase* db, const char* file, unsigned
|
||||
int page, int offset, double scale, int rotation);
|
||||
int page, unsigned int offset, double scale, unsigned int rotation);
|
||||
|
||||
bool (*get_fileinfo)(ZathuraDatabase* db, const char* file, unsigned
|
||||
int* page, int* offset, double* scale, int* rotation);
|
||||
int* page, unsigned int* offset, double* scale, unsigned int* rotation);
|
||||
};
|
||||
|
||||
GType zathura_database_get_type(void);
|
||||
|
@ -90,7 +91,7 @@ girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char*
|
|||
* @return true on success, false otherwise.
|
||||
*/
|
||||
bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned
|
||||
int page, int offset, double scale, int rotation);
|
||||
int page, unsigned int offset, double scale, unsigned int rotation);
|
||||
|
||||
/* Get file info (last site, ...) from the database.
|
||||
*
|
||||
|
@ -103,6 +104,6 @@ bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned
|
|||
* @return true on success, false otherwise.
|
||||
*/
|
||||
bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned
|
||||
int* page, int* offset, double* scale, int* rotation);
|
||||
int* page, unsigned int* offset, double* scale, unsigned int* rotation);
|
||||
|
||||
#endif // DATABASE_H
|
||||
|
|
|
@ -345,9 +345,9 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
|
|||
}
|
||||
|
||||
/* read history file */
|
||||
int offset = 0;
|
||||
zathura_db_get_fileinfo(zathura->database, document->file_path,
|
||||
&document->current_page_number, &offset, &document->scale, &document->rotate);
|
||||
&document->current_page_number, &document->page_offset, &document->scale,
|
||||
&document->rotate);
|
||||
|
||||
/* check for valid scale value */
|
||||
if (document->scale <= FLT_EPSILON) {
|
||||
|
|
|
@ -257,10 +257,11 @@ struct zathura_document_s
|
|||
unsigned int current_page_number; /**< Current page number */
|
||||
unsigned int number_of_pages; /**< Number of pages */
|
||||
double scale; /**< Scale value */
|
||||
int rotate; /**< Rotation */
|
||||
unsigned int rotate; /**< Rotation */
|
||||
void* data; /**< Custom data */
|
||||
zathura_t* zathura; /** Zathura object */
|
||||
int adjust_mode; /**< Adjust mode (best-fit, width) */
|
||||
unsigned int page_offset; /**< Page offset */
|
||||
|
||||
struct
|
||||
{
|
||||
|
|
|
@ -246,6 +246,11 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, girara_event_t*
|
|||
g_return_val_if_fail(zathura->document != NULL, false);
|
||||
|
||||
if (t != 0) {
|
||||
/* add offset */
|
||||
if (zathura->document->page_offset > 0) {
|
||||
t += zathura->document->page_offset;
|
||||
}
|
||||
|
||||
page_set(zathura, t - 1);
|
||||
} else if (argument->n == TOP) {
|
||||
page_set(zathura, 0);
|
||||
|
|
|
@ -139,6 +139,8 @@ help
|
|||
Show help page
|
||||
open, o
|
||||
Open a document
|
||||
offset
|
||||
Set page offset
|
||||
print
|
||||
Print document
|
||||
write, write!
|
||||
|
|
|
@ -588,9 +588,9 @@ document_close(zathura_t* zathura, bool keep_monitor)
|
|||
}
|
||||
|
||||
/* store last seen page */
|
||||
zathura_db_set_fileinfo(zathura->database, zathura->document->file_path, zathura->document->current_page_number,
|
||||
/* zathura->document->offset TODO */ 0, zathura->document->scale,
|
||||
zathura->document->rotate);
|
||||
zathura_db_set_fileinfo(zathura->database, zathura->document->file_path,
|
||||
zathura->document->current_page_number, zathura->document->page_offset,
|
||||
zathura->document->scale, zathura->document->rotate);
|
||||
|
||||
render_free(zathura->sync.render_thread);
|
||||
zathura->sync.render_thread = NULL;
|
||||
|
|
Loading…
Reference in a new issue