xed/xedit/xedit-prefs-manager-app.c

1433 lines
30 KiB
C
Raw Normal View History

2011-11-07 13:46:58 -06:00
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
2016-01-25 08:13:49 -06:00
* xedit-prefs-manager.c
* This file is part of xedit
2011-11-07 13:46:58 -06:00
*
2011-11-07 18:10:16 -06:00
* Copyright (C) 2002-2005 Paolo Maggi
2011-11-07 13:46:58 -06:00
*
* 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
* along with this program; if not, write to the Free Software
2012-11-18 19:54:49 -06:00
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
2011-11-07 13:46:58 -06:00
*/
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
/*
2016-01-25 08:13:49 -06:00
* Modified by the xedit Team, 2002-2003. See the AUTHORS file for a
* list of people on the xedit Team.
2011-11-07 13:46:58 -06:00
* See the ChangeLog files for a list of changes.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
2013-01-24 14:03:53 -06:00
#include <gio/gio.h>
2016-01-25 08:13:49 -06:00
#include "xedit-prefs-manager.h"
#include "xedit-prefs-manager-private.h"
#include "xedit-prefs-manager-app.h"
#include "xedit-app.h"
#include "xedit-debug.h"
#include "xedit-view.h"
#include "xedit-window.h"
#include "xedit-window-private.h"
#include "xedit-plugins-engine.h"
#include "xedit-style-scheme-manager.h"
#include "xedit-dirs.h"
static void xedit_prefs_manager_editor_font_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_system_font_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_tabs_size_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_wrap_mode_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_line_numbers_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_auto_indent_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_undo_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_right_margin_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_smart_home_end_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_hl_current_line_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2011-11-07 18:10:16 -06:00
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_bracket_matching_changed(GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_syntax_hl_enable_changed(GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_search_hl_enable_changed(GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_source_style_scheme_changed(GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_max_recents_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_auto_save_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2016-01-25 08:13:49 -06:00
static void xedit_prefs_manager_active_plugins_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data);
2013-01-24 14:03:53 -06:00
/* GUI state is serialized to a .desktop file, not in GSettings */
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
#define XEDIT_STATE_DEFAULT_WINDOW_STATE 0
#define XEDIT_STATE_DEFAULT_WINDOW_WIDTH 650
#define XEDIT_STATE_DEFAULT_WINDOW_HEIGHT 500
#define XEDIT_STATE_DEFAULT_SIDE_PANEL_SIZE 200
#define XEDIT_STATE_DEFAULT_BOTTOM_PANEL_SIZE 140
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
#define XEDIT_STATE_FILE_LOCATION "xedit.ini"
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
#define XEDIT_STATE_WINDOW_GROUP "window"
#define XEDIT_STATE_WINDOW_STATE "state"
#define XEDIT_STATE_WINDOW_HEIGHT "height"
#define XEDIT_STATE_WINDOW_WIDTH "width"
#define XEDIT_STATE_SIDE_PANEL_SIZE "side_panel_size"
#define XEDIT_STATE_BOTTOM_PANEL_SIZE "bottom_panel_size"
#define XEDIT_STATE_SIDE_PANEL_ACTIVE_PAGE "side_panel_active_page"
#define XEDIT_STATE_BOTTOM_PANEL_ACTIVE_PAGE "bottom_panel_active_page"
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
#define XEDIT_STATE_FILEFILTER_GROUP "filefilter"
#define XEDIT_STATE_FILEFILTER_ID "id"
2011-11-07 13:46:58 -06:00
static gint window_state = -1;
static gint window_height = -1;
static gint window_width = -1;
static gint side_panel_size = -1;
static gint bottom_panel_size = -1;
static gint side_panel_active_page = -1;
static gint bottom_panel_active_page = -1;
static gint active_file_filter = -1;
static gchar *
get_state_filename (void)
{
gchar *config_dir;
gchar *filename = NULL;
2016-01-25 08:13:49 -06:00
config_dir = xedit_dirs_get_user_config_dir ();
2011-11-07 13:46:58 -06:00
if (config_dir != NULL)
{
filename = g_build_filename (config_dir,
2016-01-25 08:13:49 -06:00
XEDIT_STATE_FILE_LOCATION,
2011-11-07 13:46:58 -06:00
NULL);
g_free (config_dir);
}
return filename;
}
static GKeyFile *
2016-01-25 08:13:49 -06:00
get_xedit_state_file (void)
2011-11-07 13:46:58 -06:00
{
static GKeyFile *state_file = NULL;
if (state_file == NULL)
{
gchar *filename;
GError *err = NULL;
state_file = g_key_file_new ();
filename = get_state_filename ();
if (!g_key_file_load_from_file (state_file,
filename,
G_KEY_FILE_NONE,
&err))
{
if (err->domain != G_FILE_ERROR ||
err->code != G_FILE_ERROR_NOENT)
{
2016-01-25 08:13:49 -06:00
g_warning ("Could not load xedit state file: %s\n",
2011-11-07 13:46:58 -06:00
err->message);
}
g_error_free (err);
}
g_free (filename);
}
return state_file;
}
static void
2016-01-25 08:13:49 -06:00
xedit_state_get_int (const gchar *group,
2011-11-07 13:46:58 -06:00
const gchar *key,
gint defval,
gint *result)
{
GKeyFile *state_file;
gint res;
GError *err = NULL;
2016-01-25 08:13:49 -06:00
state_file = get_xedit_state_file ();
2011-11-07 13:46:58 -06:00
res = g_key_file_get_integer (state_file,
group,
key,
&err);
if (err != NULL)
{
if ((err->domain != G_KEY_FILE_ERROR) ||
((err->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND &&
err->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND)))
{
g_warning ("Could not get state value %s::%s : %s\n",
group,
key,
err->message);
}
*result = defval;
g_error_free (err);
}
else
{
*result = res;
}
}
static void
2016-01-25 08:13:49 -06:00
xedit_state_set_int (const gchar *group,
2011-11-07 13:46:58 -06:00
const gchar *key,
gint value)
{
GKeyFile *state_file;
2016-01-25 08:13:49 -06:00
state_file = get_xedit_state_file ();
2011-11-07 13:46:58 -06:00
g_key_file_set_integer (state_file,
group,
key,
value);
}
static gboolean
2016-01-25 08:13:49 -06:00
xedit_state_file_sync (void)
2011-11-07 13:46:58 -06:00
{
GKeyFile *state_file;
gchar *config_dir;
gchar *filename = NULL;
gchar *content = NULL;
gsize length;
gint res;
GError *err = NULL;
gboolean ret = FALSE;
2016-01-25 08:13:49 -06:00
state_file = get_xedit_state_file ();
2011-11-07 13:46:58 -06:00
g_return_val_if_fail (state_file != NULL, FALSE);
2016-01-25 08:13:49 -06:00
config_dir = xedit_dirs_get_user_config_dir ();
2011-11-07 13:46:58 -06:00
if (config_dir == NULL)
{
g_warning ("Could not get config directory\n");
return ret;
}
res = g_mkdir_with_parents (config_dir, 0755);
if (res < 0)
{
g_warning ("Could not create config directory\n");
goto out;
}
content = g_key_file_to_data (state_file,
&length,
&err);
if (err != NULL)
{
g_warning ("Could not get data from state file: %s\n",
err->message);
goto out;
}
if (content != NULL)
{
filename = get_state_filename ();
if (!g_file_set_contents (filename,
content,
length,
&err))
{
2016-01-25 08:13:49 -06:00
g_warning ("Could not write xedit state file: %s\n",
2011-11-07 13:46:58 -06:00
err->message);
goto out;
}
}
ret = TRUE;
out:
if (err != NULL)
g_error_free (err);
g_free (config_dir);
g_free (filename);
g_free (content);
return ret;
}
/* Window state */
gint
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_window_state (void)
2011-11-07 13:46:58 -06:00
{
if (window_state == -1)
{
2016-01-25 08:13:49 -06:00
xedit_state_get_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_WINDOW_STATE,
XEDIT_STATE_DEFAULT_WINDOW_STATE,
2011-11-07 13:46:58 -06:00
&window_state);
}
return window_state;
}
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_set_window_state (gint ws)
2011-11-07 13:46:58 -06:00
{
g_return_if_fail (ws > -1);
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
window_state = ws;
2016-01-25 08:13:49 -06:00
xedit_state_set_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_WINDOW_STATE,
2011-11-07 13:46:58 -06:00
ws);
}
gboolean
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_window_state_can_set (void)
2011-11-07 13:46:58 -06:00
{
return TRUE;
}
/* Window size */
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_window_size (gint *width, gint *height)
2011-11-07 13:46:58 -06:00
{
g_return_if_fail (width != NULL && height != NULL);
if (window_width == -1)
{
2016-01-25 08:13:49 -06:00
xedit_state_get_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_WINDOW_WIDTH,
XEDIT_STATE_DEFAULT_WINDOW_WIDTH,
2011-11-07 13:46:58 -06:00
&window_width);
}
if (window_height == -1)
{
2016-01-25 08:13:49 -06:00
xedit_state_get_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_WINDOW_HEIGHT,
XEDIT_STATE_DEFAULT_WINDOW_HEIGHT,
2011-11-07 13:46:58 -06:00
&window_height);
}
*width = window_width;
*height = window_height;
}
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_default_window_size (gint *width, gint *height)
2011-11-07 13:46:58 -06:00
{
g_return_if_fail (width != NULL && height != NULL);
2016-01-25 08:13:49 -06:00
*width = XEDIT_STATE_DEFAULT_WINDOW_WIDTH;
*height = XEDIT_STATE_DEFAULT_WINDOW_HEIGHT;
2011-11-07 13:46:58 -06:00
}
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_set_window_size (gint width, gint height)
2011-11-07 13:46:58 -06:00
{
g_return_if_fail (width > -1 && height > -1);
window_width = width;
window_height = height;
2016-01-25 08:13:49 -06:00
xedit_state_set_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_WINDOW_WIDTH,
2011-11-07 13:46:58 -06:00
width);
2016-01-25 08:13:49 -06:00
xedit_state_set_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_WINDOW_HEIGHT,
2011-11-07 13:46:58 -06:00
height);
}
2011-11-07 18:10:16 -06:00
gboolean
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_window_size_can_set (void)
2011-11-07 13:46:58 -06:00
{
return TRUE;
}
/* Side panel */
gint
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_side_panel_size (void)
2011-11-07 13:46:58 -06:00
{
if (side_panel_size == -1)
{
2016-01-25 08:13:49 -06:00
xedit_state_get_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_SIDE_PANEL_SIZE,
XEDIT_STATE_DEFAULT_SIDE_PANEL_SIZE,
2011-11-07 13:46:58 -06:00
&side_panel_size);
}
return side_panel_size;
}
2011-11-07 18:10:16 -06:00
gint
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_default_side_panel_size (void)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
return XEDIT_STATE_DEFAULT_SIDE_PANEL_SIZE;
2011-11-07 13:46:58 -06:00
}
2011-11-07 18:10:16 -06:00
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_set_side_panel_size (gint ps)
2011-11-07 13:46:58 -06:00
{
g_return_if_fail (ps > -1);
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
if (side_panel_size == ps)
return;
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
side_panel_size = ps;
2016-01-25 08:13:49 -06:00
xedit_state_set_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_SIDE_PANEL_SIZE,
2011-11-07 13:46:58 -06:00
ps);
}
2011-11-07 18:10:16 -06:00
gboolean
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_side_panel_size_can_set (void)
2011-11-07 13:46:58 -06:00
{
return TRUE;
}
gint
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_side_panel_active_page (void)
2011-11-07 13:46:58 -06:00
{
if (side_panel_active_page == -1)
{
2016-01-25 08:13:49 -06:00
xedit_state_get_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_SIDE_PANEL_ACTIVE_PAGE,
2011-11-07 13:46:58 -06:00
0,
&side_panel_active_page);
}
return side_panel_active_page;
}
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_set_side_panel_active_page (gint id)
2011-11-07 13:46:58 -06:00
{
if (side_panel_active_page == id)
return;
side_panel_active_page = id;
2016-01-25 08:13:49 -06:00
xedit_state_set_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_SIDE_PANEL_ACTIVE_PAGE,
2011-11-07 13:46:58 -06:00
id);
}
2011-11-07 18:10:16 -06:00
gboolean
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_side_panel_active_page_can_set (void)
2011-11-07 13:46:58 -06:00
{
return TRUE;
}
/* Bottom panel */
gint
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_bottom_panel_size (void)
2011-11-07 13:46:58 -06:00
{
if (bottom_panel_size == -1)
{
2016-01-25 08:13:49 -06:00
xedit_state_get_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_BOTTOM_PANEL_SIZE,
XEDIT_STATE_DEFAULT_BOTTOM_PANEL_SIZE,
2011-11-07 13:46:58 -06:00
&bottom_panel_size);
}
return bottom_panel_size;
}
2011-11-07 18:10:16 -06:00
gint
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_default_bottom_panel_size (void)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
return XEDIT_STATE_DEFAULT_BOTTOM_PANEL_SIZE;
2011-11-07 13:46:58 -06:00
}
2011-11-07 18:10:16 -06:00
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_set_bottom_panel_size (gint ps)
2011-11-07 13:46:58 -06:00
{
g_return_if_fail (ps > -1);
if (bottom_panel_size == ps)
return;
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
bottom_panel_size = ps;
2016-01-25 08:13:49 -06:00
xedit_state_set_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_BOTTOM_PANEL_SIZE,
2011-11-07 13:46:58 -06:00
ps);
}
2011-11-07 18:10:16 -06:00
gboolean
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_bottom_panel_size_can_set (void)
2011-11-07 13:46:58 -06:00
{
return TRUE;
}
gint
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_bottom_panel_active_page (void)
2011-11-07 13:46:58 -06:00
{
if (bottom_panel_active_page == -1)
{
2016-01-25 08:13:49 -06:00
xedit_state_get_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_BOTTOM_PANEL_ACTIVE_PAGE,
2011-11-07 13:46:58 -06:00
0,
&bottom_panel_active_page);
}
return bottom_panel_active_page;
}
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_set_bottom_panel_active_page (gint id)
2011-11-07 13:46:58 -06:00
{
if (bottom_panel_active_page == id)
return;
bottom_panel_active_page = id;
2016-01-25 08:13:49 -06:00
xedit_state_set_int (XEDIT_STATE_WINDOW_GROUP,
XEDIT_STATE_BOTTOM_PANEL_ACTIVE_PAGE,
2011-11-07 13:46:58 -06:00
id);
}
2011-11-07 18:10:16 -06:00
gboolean
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_bottom_panel_active_page_can_set (void)
2011-11-07 13:46:58 -06:00
{
return TRUE;
}
/* File filter */
gint
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_get_active_file_filter (void)
2011-11-07 13:46:58 -06:00
{
if (active_file_filter == -1)
{
2016-01-25 08:13:49 -06:00
xedit_state_get_int (XEDIT_STATE_FILEFILTER_GROUP,
XEDIT_STATE_FILEFILTER_ID,
2011-11-07 13:46:58 -06:00
0,
&active_file_filter);
}
return active_file_filter;
}
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_set_active_file_filter (gint id)
2011-11-07 13:46:58 -06:00
{
g_return_if_fail (id >= 0);
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
if (active_file_filter == id)
return;
active_file_filter = id;
2016-01-25 08:13:49 -06:00
xedit_state_set_int (XEDIT_STATE_FILEFILTER_GROUP,
XEDIT_STATE_FILEFILTER_ID,
2011-11-07 13:46:58 -06:00
id);
}
2011-11-07 18:10:16 -06:00
gboolean
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_active_file_filter_can_set (void)
2011-11-07 13:46:58 -06:00
{
return TRUE;
}
2013-01-24 14:03:53 -06:00
/* Normal prefs are stored in GSettings */
2011-11-07 13:46:58 -06:00
gboolean
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_app_init (void)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
g_return_val_if_fail (xedit_prefs_manager == NULL, FALSE);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_init ();
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
if (xedit_prefs_manager != NULL)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_USE_DEFAULT_FONT,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_editor_font_changed),
2011-11-07 13:46:58 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_EDITOR_FONT,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_editor_font_changed),
2011-11-07 13:46:58 -06:00
NULL);
2011-11-07 18:10:16 -06:00
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->interface_settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_SYSTEM_FONT,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_system_font_changed),
2011-11-07 13:46:58 -06:00
NULL);
2011-11-07 18:10:16 -06:00
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_TABS_SIZE,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_tabs_size_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_INSERT_SPACES,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_tabs_size_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_WRAP_MODE,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_wrap_mode_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_DISPLAY_LINE_NUMBERS,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_line_numbers_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_AUTO_INDENT,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_auto_indent_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_UNDO_ACTIONS_LIMIT,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_undo_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_DISPLAY_RIGHT_MARGIN,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_right_margin_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_RIGHT_MARGIN_POSITION,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_right_margin_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_SMART_HOME_END,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_smart_home_end_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_HIGHLIGHT_CURRENT_LINE,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_hl_current_line_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_BRACKET_MATCHING,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_bracket_matching_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_SYNTAX_HL_ENABLE,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_syntax_hl_enable_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_SEARCH_HIGHLIGHTING_ENABLE,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_search_hl_enable_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_SOURCE_STYLE_SCHEME,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_source_style_scheme_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_MAX_RECENTS,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_max_recents_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_CREATE_BACKUP_COPY,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_auto_save_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_AUTO_SAVE_INTERVAL,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_auto_save_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_WRITABLE_VFS_SCHEMES,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_auto_save_changed),
2013-01-24 14:03:53 -06:00
NULL);
2016-01-25 08:13:49 -06:00
g_signal_connect (xedit_prefs_manager->settings,
2013-01-24 14:03:53 -06:00
"changed::" GPM_ACTIVE_PLUGINS,
2016-01-25 08:13:49 -06:00
G_CALLBACK (xedit_prefs_manager_active_plugins_changed),
2013-01-24 14:03:53 -06:00
NULL);
2011-11-07 13:46:58 -06:00
}
2016-01-25 08:13:49 -06:00
return xedit_prefs_manager != NULL;
2011-11-07 13:46:58 -06:00
}
2016-01-25 08:13:49 -06:00
/* This function must be called before exiting xedit */
2011-11-07 13:46:58 -06:00
void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_app_shutdown (void)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_shutdown ();
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_state_file_sync ();
2011-11-07 13:46:58 -06:00
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_editor_font_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
GList *views;
GList *l;
gchar *font = NULL;
gboolean def = TRUE;
gint ts;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_USE_DEFAULT_FONT) == 0)
2011-11-07 13:46:58 -06:00
{
2013-01-24 14:03:53 -06:00
def = g_settings_get_boolean (settings, key);
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
if (def)
2016-01-25 08:13:49 -06:00
font = xedit_prefs_manager_get_system_font ();
2011-11-07 13:46:58 -06:00
else
2016-01-25 08:13:49 -06:00
font = xedit_prefs_manager_get_editor_font ();
2011-11-07 13:46:58 -06:00
}
2013-01-24 14:03:53 -06:00
else if (strcmp (key, GPM_EDITOR_FONT) == 0)
2011-11-07 13:46:58 -06:00
{
2013-01-24 14:03:53 -06:00
font = g_settings_get_string (settings, key);
2011-11-07 18:10:16 -06:00
2016-01-25 08:13:49 -06:00
def = xedit_prefs_manager_get_use_default_font ();
2011-11-07 13:46:58 -06:00
}
else
return;
g_return_if_fail (font != NULL);
2011-11-07 18:10:16 -06:00
2016-01-25 08:13:49 -06:00
ts = xedit_prefs_manager_get_tabs_size ();
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
2016-01-25 08:13:49 -06:00
/* Note: we use def=FALSE to avoid XeditView to query GSettings */
xedit_view_set_font (XEDIT_VIEW (l->data), FALSE, font);
2011-11-07 13:46:58 -06:00
gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts);
l = l->next;
}
g_list_free (views);
g_free (font);
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_system_font_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
GList *views;
GList *l;
gchar *font;
gint ts;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_SYSTEM_FONT) != 0)
2011-11-07 13:46:58 -06:00
return;
2016-01-25 08:13:49 -06:00
if (!xedit_prefs_manager_get_use_default_font ())
2011-11-07 13:46:58 -06:00
return;
2013-01-24 14:03:53 -06:00
font = g_settings_get_string (settings, key);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
ts = xedit_prefs_manager_get_tabs_size ();
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
2016-01-25 08:13:49 -06:00
/* Note: we use def=FALSE to avoid XeditView to query GSettings */
xedit_view_set_font (XEDIT_VIEW (l->data), FALSE, font);
2011-11-07 13:46:58 -06:00
gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts);
l = l->next;
}
g_list_free (views);
g_free (font);
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_tabs_size_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_TABS_SIZE) == 0)
2011-11-07 13:46:58 -06:00
{
gint tab_width;
GList *views;
GList *l;
2013-01-24 14:03:53 -06:00
tab_width = g_settings_get_int (settings, key);
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
tab_width = CLAMP (tab_width, 1, 24);
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
2011-11-07 18:10:16 -06:00
gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data),
2011-11-07 13:46:58 -06:00
tab_width);
l = l->next;
}
g_list_free (views);
}
2013-01-24 14:03:53 -06:00
else if (strcmp (key, GPM_INSERT_SPACES) == 0)
2011-11-07 13:46:58 -06:00
{
gboolean enable;
GList *views;
GList *l;
2013-01-24 14:03:53 -06:00
enable = g_settings_get_boolean (settings, key);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
gtk_source_view_set_insert_spaces_instead_of_tabs (
2011-11-07 18:10:16 -06:00
GTK_SOURCE_VIEW (l->data),
2011-11-07 13:46:58 -06:00
enable);
l = l->next;
}
g_list_free (views);
}
}
2011-11-07 18:10:16 -06:00
static GtkWrapMode
2011-11-07 13:46:58 -06:00
get_wrap_mode_from_string (const gchar* str)
{
GtkWrapMode res;
g_return_val_if_fail (str != NULL, GTK_WRAP_WORD);
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
if (strcmp (str, "GTK_WRAP_NONE") == 0)
res = GTK_WRAP_NONE;
else
{
if (strcmp (str, "GTK_WRAP_CHAR") == 0)
res = GTK_WRAP_CHAR;
else
res = GTK_WRAP_WORD;
}
return res;
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_wrap_mode_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
gpointer user_data)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_WRAP_MODE) == 0)
2011-11-07 13:46:58 -06:00
{
GtkWrapMode wrap_mode;
GList *views;
GList *l;
2013-01-24 14:03:53 -06:00
wrap_mode = get_wrap_mode_from_string (g_settings_get_string(settings, key));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data),
wrap_mode);
l = l->next;
}
g_list_free (views);
}
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_line_numbers_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_DISPLAY_LINE_NUMBERS) == 0)
2011-11-07 13:46:58 -06:00
{
gboolean dln;
GList *views;
GList *l;
2013-01-24 14:03:53 -06:00
dln = g_settings_get_boolean (settings, key);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
2011-11-07 18:10:16 -06:00
gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data),
2011-11-07 13:46:58 -06:00
dln);
l = l->next;
}
g_list_free (views);
}
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_hl_current_line_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_HIGHLIGHT_CURRENT_LINE) == 0)
2011-11-07 13:46:58 -06:00
{
gboolean hl;
GList *views;
GList *l;
2013-01-24 14:03:53 -06:00
hl = g_settings_get_boolean (settings, key);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
2011-11-07 18:10:16 -06:00
gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data),
2011-11-07 13:46:58 -06:00
hl);
l = l->next;
}
g_list_free (views);
}
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_bracket_matching_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_BRACKET_MATCHING) == 0)
2011-11-07 13:46:58 -06:00
{
gboolean enable;
GList *docs;
GList *l;
2013-01-24 14:03:53 -06:00
enable = g_settings_get_boolean (settings, key);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
docs = xedit_app_get_documents (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = docs;
while (l != NULL)
{
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data),
enable);
l = l->next;
}
g_list_free (docs);
}
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_auto_indent_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_AUTO_INDENT) == 0)
2011-11-07 13:46:58 -06:00
{
gboolean enable;
GList *views;
GList *l;
2013-01-24 14:03:53 -06:00
enable = g_settings_get_boolean (settings, key);
2011-11-07 18:10:16 -06:00
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
2011-11-07 18:10:16 -06:00
{
gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data),
2011-11-07 13:46:58 -06:00
enable);
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
l = l->next;
}
g_list_free (views);
}
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_undo_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_UNDO_ACTIONS_LIMIT) == 0)
2011-11-07 13:46:58 -06:00
{
gint ul;
GList *docs;
GList *l;
2013-01-24 14:03:53 -06:00
ul = g_settings_get_int (settings, key);
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
ul = CLAMP (ul, -1, 250);
2016-01-25 08:13:49 -06:00
docs = xedit_app_get_documents (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = docs;
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
while (l != NULL)
{
2011-11-07 18:10:16 -06:00
gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data),
2011-11-07 13:46:58 -06:00
ul);
l = l->next;
}
g_list_free (docs);
}
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_right_margin_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_RIGHT_MARGIN_POSITION) == 0)
2011-11-07 13:46:58 -06:00
{
gint pos;
GList *views;
GList *l;
2013-01-24 14:03:53 -06:00
pos = g_settings_get_int (settings, key);
2011-11-07 13:46:58 -06:00
pos = CLAMP (pos, 1, 160);
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data),
pos);
l = l->next;
}
g_list_free (views);
}
2013-01-24 14:03:53 -06:00
else if (strcmp (key, GPM_DISPLAY_RIGHT_MARGIN) == 0)
2011-11-07 13:46:58 -06:00
{
gboolean display;
GList *views;
GList *l;
2013-01-24 14:03:53 -06:00
display = g_settings_get_boolean (settings, key);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data),
display);
l = l->next;
}
g_list_free (views);
}
}
static GtkSourceSmartHomeEndType
get_smart_home_end_from_string (const gchar *str)
{
GtkSourceSmartHomeEndType res;
g_return_val_if_fail (str != NULL, GTK_SOURCE_SMART_HOME_END_AFTER);
if (strcmp (str, "DISABLED") == 0)
res = GTK_SOURCE_SMART_HOME_END_DISABLED;
else if (strcmp (str, "BEFORE") == 0)
res = GTK_SOURCE_SMART_HOME_END_BEFORE;
else if (strcmp (str, "ALWAYS") == 0)
res = GTK_SOURCE_SMART_HOME_END_ALWAYS;
else
res = GTK_SOURCE_SMART_HOME_END_AFTER;
return res;
}
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_smart_home_end_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_SMART_HOME_END) == 0)
2011-11-07 13:46:58 -06:00
{
GtkSourceSmartHomeEndType smart_he;
GList *views;
GList *l;
2013-01-24 14:03:53 -06:00
smart_he = get_smart_home_end_from_string (g_settings_get_string (settings, key));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
views = xedit_app_get_views (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = views;
while (l != NULL)
{
gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data),
smart_he);
l = l->next;
}
g_list_free (views);
}
}
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_syntax_hl_enable_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_SYNTAX_HL_ENABLE) == 0)
2011-11-07 13:46:58 -06:00
{
gboolean enable;
GList *docs;
GList *l;
const GList *windows;
2013-01-24 14:03:53 -06:00
enable = g_settings_get_boolean (settings, key);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
docs = xedit_app_get_documents (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = docs;
while (l != NULL)
{
2013-10-29 18:56:56 -05:00
#if GTK_CHECK_VERSION (3, 0, 0)
g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data));
#else
2011-11-07 13:46:58 -06:00
g_return_if_fail (GTK_IS_SOURCE_BUFFER (l->data));
2013-10-29 18:56:56 -05:00
#endif
2011-11-07 13:46:58 -06:00
gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data),
enable);
l = l->next;
}
g_list_free (docs);
/* update the sensitivity of the Higlight Mode menu item */
2016-01-25 08:13:49 -06:00
windows = xedit_app_get_windows (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
while (windows != NULL)
{
GtkUIManager *ui;
GtkAction *a;
2016-01-25 08:13:49 -06:00
ui = xedit_window_get_ui_manager (XEDIT_WINDOW (windows->data));
2011-11-07 13:46:58 -06:00
a = gtk_ui_manager_get_action (ui,
"/MenuBar/ViewMenu/ViewHighlightModeMenu");
gtk_action_set_sensitive (a, enable);
windows = g_list_next (windows);
}
}
}
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_search_hl_enable_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_SEARCH_HIGHLIGHTING_ENABLE) == 0)
2011-11-07 13:46:58 -06:00
{
gboolean enable;
GList *docs;
GList *l;
2013-01-24 14:03:53 -06:00
enable = g_settings_get_boolean (settings, key);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
docs = xedit_app_get_documents (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = docs;
while (l != NULL)
{
2016-01-25 08:13:49 -06:00
g_return_if_fail (XEDIT_IS_DOCUMENT (l->data));
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_document_set_enable_search_highlighting (XEDIT_DOCUMENT (l->data),
2011-11-07 13:46:58 -06:00
enable);
l = l->next;
}
g_list_free (docs);
}
}
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_source_style_scheme_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_SOURCE_STYLE_SCHEME) == 0)
2011-11-07 13:46:58 -06:00
{
static gchar *old_scheme = NULL;
2013-01-24 14:03:53 -06:00
gchar *scheme;
2011-11-07 13:46:58 -06:00
GtkSourceStyleScheme *style;
GList *docs;
GList *l;
2013-01-24 14:03:53 -06:00
scheme = g_settings_get_string (settings, key);
2011-11-07 13:46:58 -06:00
if (old_scheme != NULL && (strcmp (scheme, old_scheme) == 0))
return;
g_free (old_scheme);
2013-01-24 14:03:53 -06:00
old_scheme = scheme;
2011-11-07 13:46:58 -06:00
style = gtk_source_style_scheme_manager_get_scheme (
2016-01-25 08:13:49 -06:00
xedit_get_style_scheme_manager (),
2011-11-07 13:46:58 -06:00
scheme);
if (style == NULL)
{
g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme);
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
style = gtk_source_style_scheme_manager_get_scheme (
2016-01-25 08:13:49 -06:00
xedit_get_style_scheme_manager (),
2011-11-07 13:46:58 -06:00
"classic");
2011-11-07 18:10:16 -06:00
if (style == NULL)
2011-11-07 13:46:58 -06:00
{
g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation.");
return;
}
}
2016-01-25 08:13:49 -06:00
docs = xedit_app_get_documents (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
for (l = docs; l != NULL; l = l->next)
{
2013-10-29 18:56:56 -05:00
#if GTK_CHECK_VERSION (3, 0, 0)
g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data));
#else
2011-11-07 13:46:58 -06:00
g_return_if_fail (GTK_IS_SOURCE_BUFFER (l->data));
2013-10-29 18:56:56 -05:00
#endif
2011-11-07 13:46:58 -06:00
gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data),
style);
}
g_list_free (docs);
}
}
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_max_recents_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_MAX_RECENTS) == 0)
2011-11-07 13:46:58 -06:00
{
const GList *windows;
gint max;
2013-01-24 14:03:53 -06:00
max = g_settings_get_int (settings, key);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (max < 0) {
2011-11-07 13:46:58 -06:00
max = GPM_DEFAULT_MAX_RECENTS;
2013-01-24 14:03:53 -06:00
}
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
windows = xedit_app_get_windows (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
while (windows != NULL)
{
2016-01-25 08:13:49 -06:00
XeditWindow *w = windows->data;
2011-11-07 13:46:58 -06:00
gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (w->priv->toolbar_recent_menu),
max);
windows = g_list_next (windows);
}
/* FIXME: we have no way at the moment to trigger the
* update of the inline recents in the File menu */
}
}
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_auto_save_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
GList *docs;
GList *l;
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_AUTO_SAVE) == 0)
2011-11-07 13:46:58 -06:00
{
gboolean auto_save;
2013-01-24 14:03:53 -06:00
auto_save = g_settings_get_boolean (settings, key);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
docs = xedit_app_get_documents (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = docs;
while (l != NULL)
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc = XEDIT_DOCUMENT (l->data);
XeditTab *tab = xedit_tab_get_from_document (doc);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_tab_set_auto_save_enabled (tab, auto_save);
2011-11-07 13:46:58 -06:00
l = l->next;
}
g_list_free (docs);
}
2013-01-24 14:03:53 -06:00
else if (strcmp (key, GPM_AUTO_SAVE_INTERVAL) == 0)
2011-11-07 13:46:58 -06:00
{
gint auto_save_interval;
2013-01-24 14:03:53 -06:00
auto_save_interval = g_settings_get_int (settings, key);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (auto_save_interval <= 0)
2011-11-07 13:46:58 -06:00
auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;
2016-01-25 08:13:49 -06:00
docs = xedit_app_get_documents (xedit_app_get_default ());
2011-11-07 13:46:58 -06:00
l = docs;
while (l != NULL)
{
2016-01-25 08:13:49 -06:00
XeditDocument *doc = XEDIT_DOCUMENT (l->data);
XeditTab *tab = xedit_tab_get_from_document (doc);
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_tab_set_auto_save_interval (tab, auto_save_interval);
2011-11-07 13:46:58 -06:00
l = l->next;
}
g_list_free (docs);
}
}
2011-11-07 18:10:16 -06:00
static void
2016-01-25 08:13:49 -06:00
xedit_prefs_manager_active_plugins_changed (GSettings *settings,
2013-01-24 14:03:53 -06:00
gchar *key,
2011-11-07 13:46:58 -06:00
gpointer user_data)
{
2016-01-25 08:13:49 -06:00
xedit_debug (DEBUG_PREFS);
2011-11-07 13:46:58 -06:00
2013-01-24 14:03:53 -06:00
if (strcmp (key, GPM_ACTIVE_PLUGINS) == 0)
2011-11-07 13:46:58 -06:00
{
2016-01-25 08:13:49 -06:00
XeditPluginsEngine *engine;
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
engine = xedit_plugins_engine_get_default ();
2011-11-07 13:46:58 -06:00
2016-01-25 08:13:49 -06:00
xedit_plugins_engine_active_plugins_changed (engine);
2011-11-07 13:46:58 -06:00
}
}