Add view menu entry for word wrap

Adds an entry to the "View" menu that allows temporarily overriding the word
wrap settings in the preferences.
This commit is contained in:
JosephMcc 2016-12-30 03:17:05 -08:00
parent 94188504ab
commit f3791ef8d2
6 changed files with 89 additions and 18 deletions

View File

@ -134,6 +134,28 @@ _xed_cmd_view_toggle_fullscreen_mode (GtkAction *action,
_xed_window_fullscreen (window); _xed_window_fullscreen (window);
} }
void
_xed_cmd_view_toggle_word_wrap (GtkAction *action,
XedWindow *window)
{
XedView *view;
gboolean do_word_wrap;
xed_debug (DEBUG_COMMANDS);
do_word_wrap = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
view = xed_window_get_active_view (window);
if (do_word_wrap)
{
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
}
else
{
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_NONE);
}
}
void void
_xed_cmd_view_leave_fullscreen_mode (GtkAction *action, _xed_cmd_view_leave_fullscreen_mode (GtkAction *action,
XedWindow *window) XedWindow *window)

View File

@ -47,6 +47,7 @@ void _xed_cmd_view_show_statusbar (GtkAction *action, XedWindow *window);
void _xed_cmd_view_show_side_pane (GtkAction *action, XedWindow *window); void _xed_cmd_view_show_side_pane (GtkAction *action, XedWindow *window);
void _xed_cmd_view_show_bottom_pane (GtkAction *action, XedWindow *window); void _xed_cmd_view_show_bottom_pane (GtkAction *action, XedWindow *window);
void _xed_cmd_view_toggle_fullscreen_mode (GtkAction *action, XedWindow *window); void _xed_cmd_view_toggle_fullscreen_mode (GtkAction *action, XedWindow *window);
void _xed_cmd_view_toggle_word_wrap (GtkAction *action, XedWindow *window);
void _xed_cmd_view_leave_fullscreen_mode (GtkAction *action, XedWindow *window); void _xed_cmd_view_leave_fullscreen_mode (GtkAction *action, XedWindow *window);
void _xed_cmd_search_find (GtkAction *action, XedWindow *window); void _xed_cmd_search_find (GtkAction *action, XedWindow *window);

View File

@ -156,7 +156,10 @@ static const GtkToggleActionEntry xed_always_sensitive_toggle_menu_entries[] =
G_CALLBACK (_xed_cmd_view_show_statusbar), TRUE }, G_CALLBACK (_xed_cmd_view_show_statusbar), TRUE },
{ "ViewFullscreen", GTK_STOCK_FULLSCREEN, NULL, "F11", { "ViewFullscreen", GTK_STOCK_FULLSCREEN, NULL, "F11",
N_("Edit text in fullscreen"), N_("Edit text in fullscreen"),
G_CALLBACK (_xed_cmd_view_toggle_fullscreen_mode), FALSE } G_CALLBACK (_xed_cmd_view_toggle_fullscreen_mode), FALSE },
{ "ViewWordWrap", NULL, N_("_Word wrap"), NULL,
N_("Set word wrap for the current document"),
G_CALLBACK (_xed_cmd_view_toggle_word_wrap), FALSE }
}; };
/* separate group, should be always sensitive except when there are no panes */ /* separate group, should be always sensitive except when there are no panes */

View File

@ -55,6 +55,7 @@
<separator/> <separator/>
<menuitem name="ViewFullscreenMenu" action="ViewFullscreen"/> <menuitem name="ViewFullscreenMenu" action="ViewFullscreen"/>
<separator/> <separator/>
<menuitem name="ViewWordWrapMenu" action="ViewWordWrap"/>
<menu name="ViewHighlightModeMenu" action="ViewHighlightMode"> <menu name="ViewHighlightModeMenu" action="ViewHighlightMode">
<placeholder name="LanguagesMenuPlaceholder"> <placeholder name="LanguagesMenuPlaceholder">
</placeholder> </placeholder>

View File

@ -74,6 +74,7 @@ struct _XedWindowPrivate
guint tab_width_id; guint tab_width_id;
guint spaces_instead_of_tabs_id; guint spaces_instead_of_tabs_id;
guint language_changed_id; guint language_changed_id;
guint use_word_wrap_id;
/* Menus & Toolbars */ /* Menus & Toolbars */
GtkUIManager *manager; GtkUIManager *manager;

View File

@ -2050,6 +2050,34 @@ language_changed (GObject *object,
g_list_free (items); g_list_free (items);
} }
static void
word_wrap_changed (GObject *object,
GParamSpec *pspec,
XedWindow *window)
{
XedView *view;
GtkWrapMode wrap_mode;
GtkAction *action;
gboolean wrap_enabled;
view = XED_VIEW (object);
wrap_mode = gtk_text_view_get_wrap_mode (GTK_TEXT_VIEW (view));
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group, "ViewWordWrap");
if (wrap_mode == GTK_WRAP_NONE)
{
wrap_enabled = FALSE;
}
else
{
wrap_enabled = TRUE;
}
g_signal_handlers_block_by_func (action, G_CALLBACK (_xed_cmd_view_toggle_word_wrap), window);
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), wrap_enabled);
g_signal_handlers_unblock_by_func (action, G_CALLBACK (_xed_cmd_view_toggle_word_wrap), window);
}
static void static void
notebook_switch_page (GtkNotebook *book, notebook_switch_page (GtkNotebook *book,
GtkWidget *pg, GtkWidget *pg,
@ -2080,10 +2108,15 @@ notebook_switch_page (GtkNotebook *book,
if (window->priv->spaces_instead_of_tabs_id) if (window->priv->spaces_instead_of_tabs_id)
{ {
g_signal_handler_disconnect (xed_tab_get_view (window->priv->active_tab), g_signal_handler_disconnect (xed_tab_get_view (window->priv->active_tab), window->priv->spaces_instead_of_tabs_id);
window->priv->spaces_instead_of_tabs_id);
window->priv->spaces_instead_of_tabs_id = 0; window->priv->spaces_instead_of_tabs_id = 0;
} }
if (window->priv->use_word_wrap_id)
{
g_signal_handler_disconnect (xed_tab_get_view (window->priv->active_tab), window->priv->use_word_wrap_id);
window->priv->use_word_wrap_id = 0;
}
} }
/* set the active tab */ /* set the active tab */
@ -2128,10 +2161,14 @@ notebook_switch_page (GtkNotebook *book,
window->priv->language_changed_id = g_signal_connect(xed_tab_get_document (tab), "notify::language", window->priv->language_changed_id = g_signal_connect(xed_tab_get_document (tab), "notify::language",
G_CALLBACK (language_changed), window); G_CALLBACK (language_changed), window);
window->priv->use_word_wrap_id = g_signal_connect (view, "notify::wrap-mode",
G_CALLBACK (word_wrap_changed), window);
/* call it for the first time */ /* call it for the first time */
tab_width_changed (G_OBJECT (view), NULL, window); tab_width_changed (G_OBJECT (view), NULL, window);
spaces_instead_of_tabs_changed (G_OBJECT (view), NULL, window); spaces_instead_of_tabs_changed (G_OBJECT (view), NULL, window);
language_changed (G_OBJECT (xed_tab_get_document (tab)), NULL, window); language_changed (G_OBJECT (xed_tab_get_document (tab)), NULL, window);
word_wrap_changed (G_OBJECT (view), NULL, window);
g_signal_emit (G_OBJECT (window), signals[ACTIVE_TAB_CHANGED], 0, window->priv->active_tab); g_signal_emit (G_OBJECT (window), signals[ACTIVE_TAB_CHANGED], 0, window->priv->active_tab);
} }
@ -2887,6 +2924,12 @@ notebook_tab_removed (XedNotebook *notebook,
window->priv->language_changed_id = 0; window->priv->language_changed_id = 0;
} }
if (window->priv->use_word_wrap_id && tab == xed_window_get_active_tab (window))
{
g_signal_handler_disconnect (view, window->priv->use_word_wrap_id);
window->priv->use_word_wrap_id = 0;
}
g_return_if_fail(window->priv->num_tabs >= 0); g_return_if_fail(window->priv->num_tabs >= 0);
if (window->priv->num_tabs == 0) if (window->priv->num_tabs == 0)
{ {