2005-09-06 09:21:05 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*-
|
2005-06-22 11:20:32 -07:00
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MOOEDIT_COMPILATION
|
|
|
|
#include "mooedit/mooeditprefs.h"
|
|
|
|
#include "mooedit/mooedit-private.h"
|
2005-09-09 02:40:10 -07:00
|
|
|
#include "mooedit/mootextbuffer.h"
|
2005-06-22 11:20:32 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2005-07-29 04:51:36 -07:00
|
|
|
#define STR_STACK_SIZE 4
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
const char *moo_edit_setting (const char *setting_name)
|
|
|
|
{
|
2005-07-29 04:51:36 -07:00
|
|
|
static GString *stack[STR_STACK_SIZE];
|
|
|
|
static guint p;
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
g_return_val_if_fail (setting_name != NULL, NULL);
|
2005-07-29 04:51:36 -07:00
|
|
|
|
|
|
|
if (!stack[0])
|
|
|
|
{
|
|
|
|
for (p = 0; p < STR_STACK_SIZE; ++p)
|
|
|
|
stack[p] = g_string_new ("");
|
|
|
|
p = STR_STACK_SIZE - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p == STR_STACK_SIZE - 1)
|
|
|
|
p = 0;
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
|
|
|
|
g_string_printf (stack[p], MOO_EDIT_PREFS_PREFIX "/%s", setting_name);
|
|
|
|
return stack[p]->str;
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void set_font (MooEdit *edit);
|
|
|
|
|
|
|
|
|
2005-07-28 12:25:10 -07:00
|
|
|
#define NEW_KEY_BOOL(s,v) moo_prefs_new_key_bool (MOO_EDIT_PREFS_PREFIX "/" s, v)
|
|
|
|
#define NEW_KEY_INT(s,v) moo_prefs_new_key_int (MOO_EDIT_PREFS_PREFIX "/" s, v)
|
|
|
|
#define NEW_KEY_STRING(s,v) moo_prefs_new_key_string (MOO_EDIT_PREFS_PREFIX "/" s, v)
|
|
|
|
#define NEW_KEY_COLOR(s,v) moo_prefs_new_key_color (MOO_EDIT_PREFS_PREFIX "/" s, v)
|
2005-07-29 04:51:36 -07:00
|
|
|
#define NEW_KEY_ENUM(s,t,v) moo_prefs_new_key_enum (MOO_EDIT_PREFS_PREFIX "/" s, t, v)
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
void _moo_edit_set_default_settings (void)
|
|
|
|
{
|
2005-07-28 12:25:10 -07:00
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_SEARCH_SELECTED, FALSE);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_SMART_HOME_END, TRUE);
|
|
|
|
NEW_KEY_INT (MOO_EDIT_PREFS_TABS_WIDTH, 8);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_SPACES_NO_TABS, FALSE);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_AUTO_INDENT, FALSE);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_LIMIT_UNDO, FALSE);
|
|
|
|
NEW_KEY_INT (MOO_EDIT_PREFS_LIMIT_UNDO_NUM, 25);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_WRAP_ENABLE, FALSE);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_WRAP_DONT_SPLIT_WORDS, TRUE);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_SHOW_LINE_NUMBERS, FALSE);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_SHOW_MARGIN, FALSE);
|
|
|
|
NEW_KEY_INT (MOO_EDIT_PREFS_MARGIN, 80);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_USE_DEFAULT_FONT, FALSE);
|
|
|
|
NEW_KEY_STRING (MOO_EDIT_PREFS_FONT, "Courier New 11");
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_HIGHLIGHT_CURRENT_LINE, TRUE);
|
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_USE_SYNTAX_HIGHLIGHTING, TRUE);
|
2005-07-29 04:51:36 -07:00
|
|
|
NEW_KEY_ENUM (MOO_EDIT_PREFS_ON_EXTERNAL_CHANGES,
|
|
|
|
MOO_TYPE_EDIT_ON_EXTERNAL_CHANGES,
|
|
|
|
MOO_EDIT_RELOAD_IF_SAFE);
|
2005-09-14 00:06:17 -07:00
|
|
|
NEW_KEY_BOOL (MOO_EDIT_PREFS_AUTO_SAVE, FALSE);
|
|
|
|
NEW_KEY_INT (MOO_EDIT_PREFS_AUTO_SAVE_INTERVAL, 5);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-28 12:25:10 -07:00
|
|
|
#define get_string(key) moo_prefs_get_string (MOO_EDIT_PREFS_PREFIX "/" key)
|
|
|
|
#define get_bool(key) moo_prefs_get_bool (MOO_EDIT_PREFS_PREFIX "/" key)
|
|
|
|
#define get_int(key) moo_prefs_get_int (MOO_EDIT_PREFS_PREFIX "/" key)
|
|
|
|
#define get_color(key) moo_prefs_get_color (MOO_EDIT_PREFS_PREFIX "/" key)
|
2005-07-29 04:51:36 -07:00
|
|
|
#define get_enum(key) moo_prefs_get_enum (MOO_EDIT_PREFS_PREFIX "/" key)
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
void _moo_edit_apply_settings (MooEdit *edit)
|
|
|
|
{
|
|
|
|
GtkTextView *text_view = GTK_TEXT_VIEW (edit);
|
|
|
|
|
2005-07-28 12:25:10 -07:00
|
|
|
if (get_bool (MOO_EDIT_PREFS_WRAP_ENABLE))
|
|
|
|
{
|
2005-06-22 11:20:32 -07:00
|
|
|
if (get_bool (MOO_EDIT_PREFS_WRAP_DONT_SPLIT_WORDS))
|
|
|
|
gtk_text_view_set_wrap_mode (text_view, GTK_WRAP_WORD);
|
|
|
|
else
|
|
|
|
gtk_text_view_set_wrap_mode (text_view, GTK_WRAP_CHAR);
|
|
|
|
}
|
|
|
|
else
|
2005-07-28 12:25:10 -07:00
|
|
|
{
|
2005-06-22 11:20:32 -07:00
|
|
|
gtk_text_view_set_wrap_mode (text_view, GTK_WRAP_NONE);
|
2005-07-28 12:25:10 -07:00
|
|
|
}
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _moo_edit_apply_style_settings (MooEdit *edit)
|
|
|
|
{
|
|
|
|
set_font (edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _moo_edit_settings_changed (const char *key,
|
2005-08-04 23:32:53 -07:00
|
|
|
G_GNUC_UNUSED const GValue *newval,
|
2005-06-22 11:20:32 -07:00
|
|
|
MooEdit *edit)
|
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
if (!strcmp (key, MOO_EDIT_PREFS_PREFIX "/" MOO_EDIT_PREFS_USE_DEFAULT_FONT) ||
|
2005-07-28 12:25:10 -07:00
|
|
|
!strcmp (key, MOO_EDIT_PREFS_PREFIX "/" MOO_EDIT_PREFS_FONT))
|
|
|
|
{
|
2005-06-22 11:20:32 -07:00
|
|
|
set_font (edit);
|
2005-07-28 12:25:10 -07:00
|
|
|
}
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void set_font (MooEdit *edit)
|
|
|
|
{
|
|
|
|
if (get_bool (MOO_EDIT_PREFS_USE_DEFAULT_FONT))
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_text_view_set_font_from_string (MOO_TEXT_VIEW (edit), NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
else
|
2005-09-09 02:54:58 -07:00
|
|
|
moo_text_view_set_font_from_string (MOO_TEXT_VIEW (edit),
|
2005-09-09 02:40:10 -07:00
|
|
|
get_string (MOO_EDIT_PREFS_FONT));
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|