Commit d45fd33e authored by Abderrahim Kitouni's avatar Abderrahim Kitouni

ev-view: Make document direction independent of UI direction

Based on a patch by Tomo Kazahaya <tomonacci@gmail.com>

Fix #830
parent ba36247d
Pipeline #65113 passed with stages
in 11 minutes and 23 seconds
...@@ -39,6 +39,7 @@ struct _EvDocumentModel ...@@ -39,6 +39,7 @@ struct _EvDocumentModel
guint continuous : 1; guint continuous : 1;
guint dual_page : 1; guint dual_page : 1;
guint dual_page_odd_left : 1; guint dual_page_odd_left : 1;
guint rtl : 1;
guint fullscreen : 1; guint fullscreen : 1;
guint inverted_colors : 1; guint inverted_colors : 1;
...@@ -57,6 +58,7 @@ enum { ...@@ -57,6 +58,7 @@ enum {
PROP_CONTINUOUS, PROP_CONTINUOUS,
PROP_DUAL_PAGE, PROP_DUAL_PAGE,
PROP_DUAL_PAGE_ODD_LEFT, PROP_DUAL_PAGE_ODD_LEFT,
PROP_RTL,
PROP_FULLSCREEN, PROP_FULLSCREEN,
PROP_MIN_SCALE, PROP_MIN_SCALE,
PROP_MAX_SCALE, PROP_MAX_SCALE,
...@@ -134,6 +136,9 @@ ev_document_model_set_property (GObject *object, ...@@ -134,6 +136,9 @@ ev_document_model_set_property (GObject *object,
case PROP_DUAL_PAGE_ODD_LEFT: case PROP_DUAL_PAGE_ODD_LEFT:
ev_document_model_set_dual_page_odd_pages_left (model, g_value_get_boolean (value)); ev_document_model_set_dual_page_odd_pages_left (model, g_value_get_boolean (value));
break; break;
case PROP_RTL:
ev_document_model_set_rtl (model, g_value_get_boolean (value));
break;
case PROP_FULLSCREEN: case PROP_FULLSCREEN:
ev_document_model_set_fullscreen (model, g_value_get_boolean (value)); ev_document_model_set_fullscreen (model, g_value_get_boolean (value));
break; break;
...@@ -187,6 +192,9 @@ ev_document_model_get_property (GObject *object, ...@@ -187,6 +192,9 @@ ev_document_model_get_property (GObject *object,
case PROP_DUAL_PAGE_ODD_LEFT: case PROP_DUAL_PAGE_ODD_LEFT:
g_value_set_boolean (value, ev_document_model_get_dual_page_odd_pages_left (model)); g_value_set_boolean (value, ev_document_model_get_dual_page_odd_pages_left (model));
break; break;
case PROP_RTL:
g_value_set_boolean (value, ev_document_model_get_rtl (model));
break;
case PROP_FULLSCREEN: case PROP_FULLSCREEN:
g_value_set_boolean (value, ev_document_model_get_fullscreen (model)); g_value_set_boolean (value, ev_document_model_get_fullscreen (model));
break; break;
...@@ -303,6 +311,14 @@ ev_document_model_class_init (EvDocumentModelClass *klass) ...@@ -303,6 +311,14 @@ ev_document_model_class_init (EvDocumentModelClass *klass)
FALSE, FALSE,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_object_class_install_property (g_object_class,
PROP_RTL,
g_param_spec_boolean ("rtl",
"Right to Left",
"Whether the document is written from right to left",
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (g_object_class, g_object_class_install_property (g_object_class,
PROP_FULLSCREEN, PROP_FULLSCREEN,
g_param_spec_boolean ("fullscreen", g_param_spec_boolean ("fullscreen",
...@@ -720,6 +736,30 @@ ev_document_model_get_dual_page_odd_pages_left (EvDocumentModel *model) ...@@ -720,6 +736,30 @@ ev_document_model_get_dual_page_odd_pages_left (EvDocumentModel *model)
return model->dual_page_odd_left; return model->dual_page_odd_left;
} }
void
ev_document_model_set_rtl (EvDocumentModel *model,
gboolean rtl)
{
g_return_if_fail (EV_IS_DOCUMENT_MODEL (model));
rtl = rtl != FALSE;
if (rtl == model->rtl)
return;
model->rtl = rtl;
g_object_notify (G_OBJECT (model), "rtl");
}
gboolean
ev_document_model_get_rtl (EvDocumentModel *model)
{
g_return_val_if_fail (EV_IS_DOCUMENT_MODEL (model), FALSE);
return model->rtl;
}
void void
ev_document_model_set_fullscreen (EvDocumentModel *model, ev_document_model_set_fullscreen (EvDocumentModel *model,
gboolean fullscreen) gboolean fullscreen)
......
...@@ -92,6 +92,9 @@ gboolean ev_document_model_get_continuous (EvDocumentModel *model); ...@@ -92,6 +92,9 @@ gboolean ev_document_model_get_continuous (EvDocumentModel *model);
void ev_document_model_set_dual_page_odd_pages_left (EvDocumentModel *model, void ev_document_model_set_dual_page_odd_pages_left (EvDocumentModel *model,
gboolean odd_left); gboolean odd_left);
gboolean ev_document_model_get_dual_page_odd_pages_left (EvDocumentModel *model); gboolean ev_document_model_get_dual_page_odd_pages_left (EvDocumentModel *model);
void ev_document_model_set_rtl (EvDocumentModel *model,
gboolean rtl);
gboolean ev_document_model_get_rtl (EvDocumentModel *model);
void ev_document_model_set_fullscreen (EvDocumentModel *model, void ev_document_model_set_fullscreen (EvDocumentModel *model,
gboolean fullscreen); gboolean fullscreen);
gboolean ev_document_model_get_fullscreen (EvDocumentModel *model); gboolean ev_document_model_get_fullscreen (EvDocumentModel *model);
......
...@@ -8489,6 +8489,17 @@ ev_view_dual_odd_left_changed_cb (EvDocumentModel *model, ...@@ -8489,6 +8489,17 @@ ev_view_dual_odd_left_changed_cb (EvDocumentModel *model,
gtk_widget_queue_resize (GTK_WIDGET (view)); gtk_widget_queue_resize (GTK_WIDGET (view));
} }
static void
ev_view_direction_changed_cb (EvDocumentModel *model,
GParamSpec *pspec,
EvView *view)
{
gboolean rtl = ev_document_model_get_rtl (model);
gtk_widget_set_direction (GTK_WIDGET (view), rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
view->pending_scroll = SCROLL_TO_PAGE_POSITION;
gtk_widget_queue_resize (GTK_WIDGET (view));
}
static void static void
ev_view_fullscreen_changed_cb (EvDocumentModel *model, ev_view_fullscreen_changed_cb (EvDocumentModel *model,
GParamSpec *pspec, GParamSpec *pspec,
...@@ -8522,6 +8533,7 @@ ev_view_set_model (EvView *view, ...@@ -8522,6 +8533,7 @@ ev_view_set_model (EvView *view,
view->scale = ev_document_model_get_scale (view->model); view->scale = ev_document_model_get_scale (view->model);
view->continuous = ev_document_model_get_continuous (view->model); view->continuous = ev_document_model_get_continuous (view->model);
view->page_layout = ev_document_model_get_page_layout (view->model); view->page_layout = ev_document_model_get_page_layout (view->model);
gtk_widget_set_direction (GTK_WIDGET(view), ev_document_model_get_rtl (view->model));
view->fullscreen = ev_document_model_get_fullscreen (view->model); view->fullscreen = ev_document_model_get_fullscreen (view->model);
ev_view_document_changed_cb (view->model, NULL, view); ev_view_document_changed_cb (view->model, NULL, view);
...@@ -8555,6 +8567,9 @@ ev_view_set_model (EvView *view, ...@@ -8555,6 +8567,9 @@ ev_view_set_model (EvView *view,
g_signal_connect (view->model, "notify::dual-odd-left", g_signal_connect (view->model, "notify::dual-odd-left",
G_CALLBACK (ev_view_dual_odd_left_changed_cb), G_CALLBACK (ev_view_dual_odd_left_changed_cb),
view); view);
g_signal_connect (view->model, "notify::rtl",
G_CALLBACK (ev_view_direction_changed_cb),
view);
g_signal_connect (view->model, "notify::fullscreen", g_signal_connect (view->model, "notify::fullscreen",
G_CALLBACK (ev_view_fullscreen_changed_cb), G_CALLBACK (ev_view_fullscreen_changed_cb),
view); view);
......
...@@ -536,6 +536,8 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window) ...@@ -536,6 +536,8 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window)
!recent_view_mode); !recent_view_mode);
ev_window_set_action_enabled (ev_window, "dual-page", has_pages && ev_window_set_action_enabled (ev_window, "dual-page", has_pages &&
!recent_view_mode); !recent_view_mode);
ev_window_set_action_enabled (ev_window, "rtl", has_pages &&
!recent_view_mode);
ev_window_set_action_enabled (ev_window, "reload", has_pages && ev_window_set_action_enabled (ev_window, "reload", has_pages &&
!recent_view_mode); !recent_view_mode);
ev_window_set_action_enabled (ev_window, "auto-scroll", has_pages && ev_window_set_action_enabled (ev_window, "auto-scroll", has_pages &&
...@@ -1138,6 +1140,10 @@ ev_window_init_metadata_with_default_values (EvWindow *window) ...@@ -1138,6 +1140,10 @@ ev_window_init_metadata_with_default_values (EvWindow *window)
ev_metadata_set_boolean (metadata, "dual-page-odd-left", ev_metadata_set_boolean (metadata, "dual-page-odd-left",
g_settings_get_boolean (settings, "dual-page-odd-left")); g_settings_get_boolean (settings, "dual-page-odd-left"));
} }
if (!ev_metadata_has_key (metadata, "rtl")) {
ev_metadata_set_boolean (metadata, "rtl",
gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL ? TRUE : FALSE);
}
if (!ev_metadata_has_key (metadata, "inverted-colors")) { if (!ev_metadata_has_key (metadata, "inverted-colors")) {
ev_metadata_set_boolean (metadata, "inverted-colors", ev_metadata_set_boolean (metadata, "inverted-colors",
g_settings_get_boolean (settings, "inverted-colors")); g_settings_get_boolean (settings, "inverted-colors"));
...@@ -1205,6 +1211,7 @@ setup_model_from_metadata (EvWindow *window) ...@@ -1205,6 +1211,7 @@ setup_model_from_metadata (EvWindow *window)
gboolean continuous = FALSE; gboolean continuous = FALSE;
gboolean dual_page = FALSE; gboolean dual_page = FALSE;
gboolean dual_page_odd_left = FALSE; gboolean dual_page_odd_left = FALSE;
gboolean rtl = FALSE;
gboolean fullscreen = FALSE; gboolean fullscreen = FALSE;
EvWindowPrivate *priv = GET_PRIVATE (window); EvWindowPrivate *priv = GET_PRIVATE (window);
...@@ -1273,6 +1280,11 @@ setup_model_from_metadata (EvWindow *window) ...@@ -1273,6 +1280,11 @@ setup_model_from_metadata (EvWindow *window)
ev_document_model_set_dual_page_odd_pages_left (priv->model, dual_page_odd_left); ev_document_model_set_dual_page_odd_pages_left (priv->model, dual_page_odd_left);
} }
/* Right to left document */
if (ev_metadata_get_boolean (priv->metadata, "rtl", &rtl)) {
ev_document_model_set_rtl (priv->model, rtl);
}
/* Fullscreen */ /* Fullscreen */
if (ev_metadata_get_boolean (priv->metadata, "fullscreen", &fullscreen)) { if (ev_metadata_get_boolean (priv->metadata, "fullscreen", &fullscreen)) {
if (fullscreen) if (fullscreen)
...@@ -1487,6 +1499,7 @@ ev_window_setup_default (EvWindow *ev_window) ...@@ -1487,6 +1499,7 @@ ev_window_setup_default (EvWindow *ev_window)
ev_document_model_set_continuous (model, g_settings_get_boolean (settings, "continuous")); ev_document_model_set_continuous (model, g_settings_get_boolean (settings, "continuous"));
ev_document_model_set_dual_page (model, g_settings_get_boolean (settings, "dual-page")); ev_document_model_set_dual_page (model, g_settings_get_boolean (settings, "dual-page"));
ev_document_model_set_dual_page_odd_pages_left (model, g_settings_get_boolean (settings, "dual-page-odd-left")); ev_document_model_set_dual_page_odd_pages_left (model, g_settings_get_boolean (settings, "dual-page-odd-left"));
ev_document_model_set_rtl (model, gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL ? TRUE : FALSE);
ev_document_model_set_inverted_colors (model, g_settings_get_boolean (settings, "inverted-colors")); ev_document_model_set_inverted_colors (model, g_settings_get_boolean (settings, "inverted-colors"));
ev_document_model_set_sizing_mode (model, g_settings_get_enum (settings, "sizing-mode")); ev_document_model_set_sizing_mode (model, g_settings_get_enum (settings, "sizing-mode"));
if (ev_document_model_get_sizing_mode (model) == EV_SIZING_FREE) if (ev_document_model_get_sizing_mode (model) == EV_SIZING_FREE)
...@@ -4138,6 +4151,19 @@ ev_window_cmd_dual_odd_pages_left (GSimpleAction *action, ...@@ -4138,6 +4151,19 @@ ev_window_cmd_dual_odd_pages_left (GSimpleAction *action,
g_simple_action_set_state (action, state); g_simple_action_set_state (action, state);
} }
static void
ev_window_cmd_rtl (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
EvWindow *window = user_data;
EvWindowPrivate *priv = GET_PRIVATE (window);
ev_document_model_set_rtl (priv->model,
g_variant_get_boolean (state));
g_simple_action_set_state (action, state);
}
static void static void
ev_window_change_sizing_mode_action_state (GSimpleAction *action, ev_window_change_sizing_mode_action_state (GSimpleAction *action,
GVariant *state, GVariant *state,
...@@ -5316,6 +5342,25 @@ ev_window_dual_mode_odd_pages_left_changed_cb (EvDocumentModel *model, ...@@ -5316,6 +5342,25 @@ ev_window_dual_mode_odd_pages_left_changed_cb (EvDocumentModel *model,
odd_left); odd_left);
} }
static void
ev_window_direction_changed_cb (EvDocumentModel *model,
GParamSpec *pspec,
EvWindow *ev_window)
{
EvWindowPrivate *priv = GET_PRIVATE (ev_window);
gboolean rtl;
GAction *action;
rtl = ev_document_model_get_rtl (model);
action = g_action_map_lookup_action (G_ACTION_MAP (ev_window), "rtl");
g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (rtl));
if (priv->metadata && !ev_window_is_empty (ev_window))
ev_metadata_set_boolean (priv->metadata, "rtl",
rtl);
}
static void static void
ev_window_cmd_action_menu (GSimpleAction *action, ev_window_cmd_action_menu (GSimpleAction *action,
GVariant *parameter, GVariant *parameter,
...@@ -6247,6 +6292,7 @@ static const GActionEntry actions[] = { ...@@ -6247,6 +6292,7 @@ static const GActionEntry actions[] = {
{ "continuous", NULL, NULL, "true", ev_window_cmd_continuous }, { "continuous", NULL, NULL, "true", ev_window_cmd_continuous },
{ "dual-page", NULL, NULL, "false", ev_window_cmd_dual }, { "dual-page", NULL, NULL, "false", ev_window_cmd_dual },
{ "dual-odd-left", NULL, NULL, "false", ev_window_cmd_dual_odd_pages_left }, { "dual-odd-left", NULL, NULL, "false", ev_window_cmd_dual_odd_pages_left },
{ "rtl", NULL, NULL, "false", ev_window_cmd_rtl },
{ "show-side-pane", NULL, NULL, "false", ev_window_view_cmd_toggle_sidebar }, { "show-side-pane", NULL, NULL, "false", ev_window_view_cmd_toggle_sidebar },
{ "inverted-colors", NULL, NULL, "false", ev_window_cmd_view_inverted_colors }, { "inverted-colors", NULL, NULL, "false", ev_window_cmd_view_inverted_colors },
{ "enable-spellchecking", NULL, NULL, "false", ev_window_cmd_view_enable_spellchecking }, { "enable-spellchecking", NULL, NULL, "false", ev_window_cmd_view_enable_spellchecking },
...@@ -7669,6 +7715,10 @@ ev_window_init (EvWindow *ev_window) ...@@ -7669,6 +7715,10 @@ ev_window_init (EvWindow *ev_window)
"notify::dual-odd-left", "notify::dual-odd-left",
G_CALLBACK (ev_window_dual_mode_odd_pages_left_changed_cb), G_CALLBACK (ev_window_dual_mode_odd_pages_left_changed_cb),
ev_window); ev_window);
g_signal_connect (priv->model,
"notify::rtl",
G_CALLBACK (ev_window_direction_changed_cb),
ev_window);
g_signal_connect (priv->model, g_signal_connect (priv->model,
"notify::inverted-colors", "notify::inverted-colors",
G_CALLBACK (ev_window_inverted_colors_changed_cb), G_CALLBACK (ev_window_inverted_colors_changed_cb),
......
...@@ -78,6 +78,10 @@ ...@@ -78,6 +78,10 @@
<attribute name="label" translatable="yes">_Odd Pages Left</attribute> <attribute name="label" translatable="yes">_Odd Pages Left</attribute>
<attribute name="action">win.dual-odd-left</attribute> <attribute name="action">win.dual-odd-left</attribute>
</item> </item>
<item>
<attribute name="label" translatable="yes">Right to Left Document</attribute>
<attribute name="action">win.rtl</attribute>
</item>
</section> </section>
<section> <section>
<item> <item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment