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:
parent
94188504ab
commit
f3791ef8d2
|
@ -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)
|
||||||
|
|
|
@ -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);
|
||||||
|
|
19
xed/xed-ui.h
19
xed/xed-ui.h
|
@ -2,7 +2,7 @@
|
||||||
* xed-ui.h
|
* xed-ui.h
|
||||||
* This file is part of xed
|
* This file is part of xed
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 - Paolo Maggi
|
* Copyright (C) 2005 - Paolo Maggi
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -16,14 +16,14 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Modified by the xed Team, 2005. See the AUTHORS file for a
|
* Modified by the xed Team, 2005. See the AUTHORS file for a
|
||||||
* list of people on the xed Team.
|
* list of people on the xed Team.
|
||||||
* See the ChangeLog files for a list of changes.
|
* See the ChangeLog files for a list of changes.
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
@ -67,7 +67,7 @@ static const GtkActionEntry xed_always_sensitive_menu_entries[] =
|
||||||
N_("Open the xed manual"), G_CALLBACK (_xed_cmd_help_contents) },
|
N_("Open the xed manual"), G_CALLBACK (_xed_cmd_help_contents) },
|
||||||
{ "HelpAbout", "help-about-symbolic", N_("_About"), NULL,
|
{ "HelpAbout", "help-about-symbolic", N_("_About"), NULL,
|
||||||
N_("About this application"), G_CALLBACK (_xed_cmd_help_about) },
|
N_("About this application"), G_CALLBACK (_xed_cmd_help_about) },
|
||||||
|
|
||||||
/* Fullscreen toolbar */
|
/* Fullscreen toolbar */
|
||||||
{ "LeaveFullscreen", "view-restore-symbolic", NULL,
|
{ "LeaveFullscreen", "view-restore-symbolic", NULL,
|
||||||
NULL, N_("Leave fullscreen mode"),
|
NULL, N_("Leave fullscreen mode"),
|
||||||
|
@ -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 */
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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 */
|
||||||
|
@ -2102,7 +2135,7 @@ notebook_switch_page (GtkNotebook *book,
|
||||||
*/
|
*/
|
||||||
if (action != NULL)
|
if (action != NULL)
|
||||||
{
|
{
|
||||||
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action), TRUE);
|
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (action_name);
|
g_free (action_name);
|
||||||
|
@ -2113,8 +2146,8 @@ notebook_switch_page (GtkNotebook *book,
|
||||||
view = xed_tab_get_view (tab);
|
view = xed_tab_get_view (tab);
|
||||||
|
|
||||||
/* sync the statusbar */
|
/* sync the statusbar */
|
||||||
update_cursor_position_statusbar (GTK_TEXT_BUFFER(xed_tab_get_document (tab)), window);
|
update_cursor_position_statusbar (GTK_TEXT_BUFFER (xed_tab_get_document (tab)), window);
|
||||||
xed_statusbar_set_overwrite (XED_STATUSBAR(window->priv->statusbar),
|
xed_statusbar_set_overwrite (XED_STATUSBAR (window->priv->statusbar),
|
||||||
gtk_text_view_get_overwrite (GTK_TEXT_VIEW(view)));
|
gtk_text_view_get_overwrite (GTK_TEXT_VIEW(view)));
|
||||||
|
|
||||||
gtk_widget_show (window->priv->tab_width_combo);
|
gtk_widget_show (window->priv->tab_width_combo);
|
||||||
|
@ -2128,12 +2161,16 @@ 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);
|
||||||
|
|
||||||
/* call it for the first time */
|
window->priv->use_word_wrap_id = g_signal_connect (view, "notify::wrap-mode",
|
||||||
tab_width_changed (G_OBJECT(view), NULL, window);
|
G_CALLBACK (word_wrap_changed), window);
|
||||||
spaces_instead_of_tabs_changed (G_OBJECT(view), NULL, window);
|
|
||||||
language_changed (G_OBJECT(xed_tab_get_document (tab)), NULL, window);
|
|
||||||
|
|
||||||
g_signal_emit (G_OBJECT(window), signals[ACTIVE_TAB_CHANGED], 0, window->priv->active_tab);
|
/* call it for the first time */
|
||||||
|
tab_width_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);
|
||||||
|
word_wrap_changed (G_OBJECT (view), NULL, window);
|
||||||
|
|
||||||
|
g_signal_emit (G_OBJECT (window), signals[ACTIVE_TAB_CHANGED], 0, window->priv->active_tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue