gedit-commands-view.c 4.34 KB
Newer Older
Paolo Borelli's avatar
Paolo Borelli committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * gedit-view-commands.c
 * This file is part of gedit
 *
 * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
 * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
 * Copyright (C) 2002-2005 Paolo Maggi
 *
 * 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
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Paolo Borelli's avatar
Paolo Borelli committed
21 22 23 24 25 26
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

27
#include "gedit-commands.h"
28
#include "gedit-commands-private.h"
29

Paolo Borelli's avatar
Paolo Borelli committed
30 31 32
#include <gtk/gtk.h>

#include "gedit-debug.h"
33
#include "gedit-window.h"
34
#include "gedit-highlight-mode-dialog.h"
35
#include "gedit-highlight-mode-selector.h"
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50
void
_gedit_cmd_view_focus_active (GSimpleAction *action,
                              GVariant      *state,
                              gpointer       user_data)
{
	GeditView *active_view;
	GeditWindow *window = GEDIT_WINDOW (user_data);

	gedit_debug (DEBUG_COMMANDS);

	active_view = gedit_window_get_active_view (window);

	if (active_view)
	{
51
		gtk_widget_grab_focus (GTK_WIDGET (active_view));
52 53 54
	}
}

55 56 57 58 59 60
void
_gedit_cmd_view_toggle_side_panel (GSimpleAction *action,
                                   GVariant      *state,
                                   gpointer       user_data)
{
	GeditWindow *window = GEDIT_WINDOW (user_data);
61
	GtkWidget *panel;
62 63 64 65 66 67 68
	gboolean visible;

	gedit_debug (DEBUG_COMMANDS);

	panel = gedit_window_get_side_panel (window);

	visible = g_variant_get_boolean (state);
69
	gtk_widget_set_visible (panel, visible);
70 71 72

	if (visible)
	{
73
		gtk_widget_grab_focus (panel);
74 75 76 77 78 79 80 81 82 83 84
	}

	g_simple_action_set_state (action, state);
}

void
_gedit_cmd_view_toggle_bottom_panel (GSimpleAction *action,
                                     GVariant      *state,
                                     gpointer       user_data)
{
	GeditWindow *window = GEDIT_WINDOW (user_data);
85
	GtkWidget *panel;
86 87 88 89
	gboolean visible;

	gedit_debug (DEBUG_COMMANDS);

90
	panel = gedit_window_get_bottom_panel (window);
91 92

	visible = g_variant_get_boolean (state);
93
	gtk_widget_set_visible (panel, visible);
94 95 96

	if (visible)
	{
97
		gtk_widget_grab_focus (panel);
98 99 100 101 102
	}

	g_simple_action_set_state (action, state);
}

Paolo Borelli's avatar
Paolo Borelli committed
103
void
104
_gedit_cmd_view_toggle_fullscreen_mode (GSimpleAction *action,
Paolo Borelli's avatar
Paolo Borelli committed
105
                                        GVariant      *state,
106
                                        gpointer       user_data)
Paolo Borelli's avatar
Paolo Borelli committed
107
{
108
	GeditWindow *window = GEDIT_WINDOW (user_data);
Paolo Borelli's avatar
Paolo Borelli committed
109

110 111
	gedit_debug (DEBUG_COMMANDS);

Paolo Borelli's avatar
Paolo Borelli committed
112 113
	if (g_variant_get_boolean (state))
	{
114
		_gedit_window_fullscreen (window);
Paolo Borelli's avatar
Paolo Borelli committed
115 116 117 118 119
	}
	else
	{
		_gedit_window_unfullscreen (window);
	}
120 121 122
}

void
123 124 125
_gedit_cmd_view_leave_fullscreen_mode (GSimpleAction *action,
                                       GVariant      *parameter,
                                       gpointer       user_data)
126
{
127
	_gedit_window_unfullscreen (GEDIT_WINDOW (user_data));
128
}
Garrett Regier's avatar
Garrett Regier committed
129

130
static void
131 132 133
on_language_selected (GeditHighlightModeSelector *sel,
                      GtkSourceLanguage          *language,
                      GeditWindow                *window)
134 135 136 137
{
	GeditDocument *doc;

	doc = gedit_window_get_active_document (window);
138 139 140 141
	if (doc)
	{
		gedit_document_set_language (doc, language);
	}
142 143 144
}

void
145 146 147
_gedit_cmd_view_highlight_mode (GSimpleAction *action,
                                GVariant      *parameter,
                                gpointer       user_data)
148
{
149
	GtkWindow *window = GTK_WINDOW (user_data);
150
	GtkWidget *dlg;
151
	GeditHighlightModeSelector *sel;
152
	GeditDocument *doc;
153

154
	dlg = gedit_highlight_mode_dialog_new (window);
155
	sel = gedit_highlight_mode_dialog_get_selector (GEDIT_HIGHLIGHT_MODE_DIALOG (dlg));
156

157
	doc = gedit_window_get_active_document (GEDIT_WINDOW (window));
158 159
	if (doc)
	{
160 161
		gedit_highlight_mode_selector_select_language (sel,
		                                               gedit_document_get_language (doc));
162 163
	}

164
	g_signal_connect (sel, "language-selected",
165 166 167 168 169
	                  G_CALLBACK (on_language_selected), window);

	gtk_widget_show (GTK_WIDGET (dlg));
}

170
/* ex:set ts=8 noet: */