Reworked MooEditConfig stuff, added filter settings

master
Yevgen Muntyan 2006-07-27 14:39:53 -05:00
parent 8bc4c8afb5
commit bb22db5a1b
18 changed files with 1124 additions and 363 deletions

View File

@ -26,7 +26,7 @@
</ignoreparts>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
<description></description>
<description/>
<secondaryLanguages>
<language>C</language>
</secondaryLanguages>
@ -54,15 +54,15 @@
<cxxcompiler>kdevgppoptions</cxxcompiler>
<f77compiler>kdevg77options</f77compiler>
<cflags>-O0 -g3</cflags>
<topsourcedir></topsourcedir>
<cppflags></cppflags>
<ccompilerbinary></ccompilerbinary>
<cxxcompilerbinary></cxxcompilerbinary>
<f77compilerbinary></f77compilerbinary>
<f77flags></f77flags>
<topsourcedir/>
<cppflags/>
<ccompilerbinary/>
<cxxcompilerbinary/>
<f77compilerbinary/>
<f77flags/>
<envvars/>
<ldflags></ldflags>
<cxxflags></cxxflags>
<ldflags/>
<cxxflags/>
</debug>
<gtk-print>
<configargs>--enable-debug --enable-all-gcc-warnings --without-python --prefix=/usr/local/gtk-print</configargs>
@ -221,15 +221,15 @@
</kdevautoproject>
<kdevdebugger>
<general>
<dbgshell></dbgshell>
<dbgshell/>
<programargs>--g-fatal-warnings -n</programargs>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>true</floatingtoolbar>
<gdbpath></gdbpath>
<configGdbScript></configGdbScript>
<runShellScript></runShellScript>
<runGdbScript></runGdbScript>
<gdbpath/>
<configGdbScript/>
<runShellScript/>
<runGdbScript/>
</general>
<display>
<staticmembers>true</staticmembers>
@ -327,7 +327,7 @@
</codecompletion>
<references/>
<creategettersetter>
<prefixGet></prefixGet>
<prefixGet/>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>

View File

@ -3,6 +3,9 @@
<make>
<n_jobs>3</n_jobs>
</make>
<commands>
<compile>cd $(top_builddir) &amp;&amp; $(make) $(base).o</compile>
</commands>
<configurations>
<debug>
<run>

View File

@ -39,6 +39,7 @@ mooedit_noinst_headers = \
$(mooedit)/mooedit-private.h \
$(mooedit)/mooeditdialogs.h \
$(mooedit)/mooeditfileops.h \
$(mooedit)/mooeditfiltersettings.h \
$(mooedit)/mooeditprefs-glade.h \
$(mooedit)/mooeditprogress-glade.h \
$(mooedit)/mooeditsavemultiple-glade.h \
@ -74,6 +75,7 @@ mooedit_sources = \
$(mooedit)/mooeditconfig.c \
$(mooedit)/mooeditdialogs.c \
$(mooedit)/mooeditfileops.c \
$(mooedit)/mooeditfiltersettings.c \
$(mooedit)/mooeditinput.c \
$(mooedit)/mooeditor.c \
$(mooedit)/mooeditprefs.c \

View File

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!-- Generated with glade3
Version: 2.91.3
Date: Thu Jul 27 14:15:38 2006
User: muntyan
Host: dima
-->
<glade-interface>
<widget class="GtkWindow" id="window">
<property name="visible">True</property>
@ -739,12 +745,30 @@
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<child>
<widget class="GtkLabel" id="label99">
<widget class="GtkComboBox" id="color_scheme_combo">
<property name="visible">True</property>
<property name="label">Font:</property>
<property name="moo_sensitive">!use_default_font</property>
<property name="items" translatable="yes">KDE
gvim
</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label100">
<property name="visible">True</property>
<property name="xalign">0.000000</property>
<property name="label">Color scheme:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
@ -765,34 +789,16 @@
</packing>
</child>
<child>
<widget class="GtkLabel" id="label100">
<widget class="GtkLabel" id="label99">
<property name="visible">True</property>
<property name="xalign">0.000000</property>
<property name="label">Color scheme:</property>
<property name="label">Font:</property>
<property name="moo_sensitive">!use_default_font</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="color_scheme_combo">
<property name="visible">True</property>
<property name="items" translatable="yes">KDE
gvim
</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
@ -815,118 +821,262 @@ gvim
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment3">
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="top_padding">3</property>
<property name="bottom_padding">3</property>
<property name="left_padding">3</property>
<property name="right_padding">3</property>
<child>
<widget class="GtkTable" id="table">
<widget class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="label_xalign">0.000000</property>
<child>
<widget class="GtkComboBox" id="lang_combo">
<widget class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
<property name="bottom_padding">3</property>
<property name="left_padding">3</property>
<property name="right_padding">3</property>
<child>
<widget class="GtkTable" id="table">
<property name="visible">True</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<child>
<widget class="GtkEntry" id="config">
<property name="visible">True</property>
<property name="activates_default">True</property>
<property name="tooltip">strip: bool; use-tabs: bool; indent-width: integer; tab-width: integer</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Options:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_mimetypes">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Mime types:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_extensions">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Extensions:</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="mimetypes">
<property name="visible">True</property>
<property name="activates_default">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="extensions">
<property name="visible">True</property>
<property name="activates_default">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label768">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Language:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="lang_combo">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label768">
<widget class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Language:</property>
<property name="label" translatable="yes">Language-specific options</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="extensions">
<property name="visible">True</property>
<property name="activates_default">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="mimetypes">
<property name="visible">True</property>
<property name="activates_default">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_extensions">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Extensions:</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_mimetypes">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Mime types:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Options:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="config">
<property name="visible">True</property>
<property name="activates_default">True</property>
<property name="tooltip">strip: bool; use-tabs: bool; indent-width: integer; tab-width: integer</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkFrame" id="frame2">
<property name="visible">True</property>
<property name="label_xalign">0.000000</property>
<child>
<widget class="GtkAlignment" id="alignment4">
<property name="visible">True</property>
<property name="bottom_padding">3</property>
<property name="left_padding">3</property>
<property name="right_padding">3</property>
<child>
<widget class="GtkVBox" id="vbox4">
<property name="visible">True</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<child>
<widget class="GtkTreeView" id="filter_treeview">
<property name="visible">True</property>
<property name="reorderable">True</property>
<property name="rules_hint">True</property>
<property name="enable_search">False</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<child>
<widget class="GtkButton" id="new_filter_setting">
<property name="visible">True</property>
<property name="focus_on_click">False</property>
<child>
<widget class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="stock">gtk-new</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="delete_filter_setting">
<property name="visible">True</property>
<property name="focus_on_click">False</property>
<child>
<widget class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="stock">gtk-delete</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="filter_setting_down">
<property name="visible">True</property>
<child>
<widget class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="stock">gtk-go-down</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="filter_setting_up">
<property name="visible">True</property>
<child>
<widget class="GtkImage" id="image4">
<property name="visible">True</property>
<property name="stock">gtk-go-up</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="label" translatable="yes">File filters</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
@ -937,7 +1087,7 @@ gvim
<child>
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="label" translatable="yes">Languages</property>
<property name="label" translatable="yes">Languages and files</property>
</widget>
<packing>
<property name="type">tab</property>

View File

@ -45,11 +45,26 @@ gboolean _moo_edit_has_comments (MooEdit *edit,
/***********************************************************************/
/* Preferences
/*/
void _moo_edit_init_settings (void);
void _moo_edit_apply_settings (MooEdit *edit);
void _moo_edit_freeze_config_notify (MooEdit *edit);
void _moo_edit_thaw_config_notify (MooEdit *edit);
void _moo_edit_update_config (void);
enum {
MOO_EDIT_SETTING_LANG,
MOO_EDIT_SETTING_INDENT,
MOO_EDIT_SETTING_STRIP,
MOO_EDIT_SETTING_WRAP_MODE,
MOO_EDIT_SETTING_SHOW_LINE_NUMBERS,
MOO_EDIT_SETTING_TAB_WIDTH,
MOO_EDIT_LAST_SETTING
};
extern guint *_moo_edit_settings;
void _moo_edit_update_global_config (void);
void _moo_edit_init_config (void);
void _moo_edit_update_lang_config (void);
void _moo_edit_apply_prefs (MooEdit *edit);
void _moo_edit_freeze_config_notify (MooEdit *edit);
void _moo_edit_thaw_config_notify (MooEdit *edit);
void _moo_edit_update_config_from_global (MooEdit *edit);
/***********************************************************************/

View File

@ -20,6 +20,7 @@
#include "mooedit/mootextbuffer.h"
#include "mooedit/moolang-private.h"
#include "mooedit/mooeditprogress-glade.h"
#include "mooedit/mooeditfiltersettings.h"
#include "mooutils/moomarshals.h"
#include "mooutils/moocompat.h"
#include "mooutils/mooutils-gobject.h"
@ -102,18 +103,6 @@ enum {
PROP_HAS_COMMENTS
};
enum {
SETTING_LANG,
SETTING_INDENT,
SETTING_STRIP,
SETTING_WRAP_MODE,
SETTING_SHOW_LINE_NUMBERS,
SETTING_TAB_WIDTH,
LAST_SETTING
};
static guint settings[LAST_SETTING];
/* MOO_TYPE_EDIT */
G_DEFINE_TYPE (MooEdit, moo_edit, MOO_TYPE_TEXT_VIEW)
@ -161,31 +150,6 @@ moo_edit_class_init (MooEditClass *klass)
FALSE,
G_PARAM_READABLE));
settings[SETTING_LANG] = moo_edit_config_install_setting (
g_param_spec_string ("lang", "lang", "lang",
NULL,
G_PARAM_READWRITE));
settings[SETTING_INDENT] = moo_edit_config_install_setting (
g_param_spec_string ("indent", "indent", "indent",
NULL,
G_PARAM_READWRITE));
settings[SETTING_STRIP] = moo_edit_config_install_setting (
g_param_spec_boolean ("strip", "strip", "strip",
FALSE,
G_PARAM_READWRITE));
settings[SETTING_WRAP_MODE] = moo_edit_config_install_setting (
g_param_spec_enum ("wrap-mode", "wrap-mode", "wrap-mode",
GTK_TYPE_WRAP_MODE, GTK_WRAP_NONE,
G_PARAM_READWRITE));
settings[SETTING_SHOW_LINE_NUMBERS] = moo_edit_config_install_setting (
g_param_spec_boolean ("show-line-numbers", "show-line-numbers", "show-line-numbers",
FALSE, G_PARAM_READWRITE));
settings[SETTING_TAB_WIDTH] = moo_edit_config_install_setting (
g_param_spec_uint ("tab-width", "tab-width", "tab-width",
1, G_MAXUINT, 8, G_PARAM_READWRITE));
_moo_edit_class_init_actions (klass);
signals[CONFIG_NOTIFY] =
g_signal_new ("config-notify",
G_OBJECT_CLASS_TYPE (klass),
@ -260,7 +224,8 @@ moo_edit_class_init (MooEditClass *klass)
_moo_marshal_VOID__VOID,
G_TYPE_NONE, 0);
_moo_edit_init_settings ();
_moo_edit_init_config ();
_moo_edit_class_init_actions (klass);
}
@ -980,7 +945,7 @@ moo_edit_set_lang (MooEdit *edit,
moo_text_view_set_lang (MOO_TEXT_VIEW (edit), lang);
_moo_lang_mgr_update_config (moo_editor_get_lang_mgr (edit->priv->editor),
edit->config, moo_lang_id (lang));
_moo_edit_apply_settings (edit);
_moo_edit_update_config_from_global (edit);
g_object_notify (G_OBJECT (edit), "has-comments");
}
}
@ -1004,13 +969,14 @@ moo_edit_apply_config (MooEdit *edit)
moo_edit_apply_lang_config (edit);
moo_edit_config_get (edit->config, "wrap-mode", &wrap_mode, NULL);
moo_edit_config_get (edit->config,
"wrap-mode", &wrap_mode,
"show-line-numbers", &line_numbers,
"tab-width", &tab_width,
NULL);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (edit), wrap_mode);
line_numbers = moo_edit_config_get_bool (edit->config, "show-line-numbers");
moo_text_view_set_show_line_numbers (MOO_TEXT_VIEW (edit), line_numbers);
tab_width = moo_edit_config_get_uint (edit->config, "tab-width");
moo_text_view_set_tab_width (MOO_TEXT_VIEW (edit), tab_width);
}
@ -1037,15 +1003,25 @@ moo_edit_config_notify (MooEdit *edit,
guint var_id,
G_GNUC_UNUSED GParamSpec *pspec)
{
if (var_id == settings[SETTING_LANG])
moo_edit_apply_config (edit);
if (var_id == _moo_edit_settings[MOO_EDIT_SETTING_LANG])
moo_edit_apply_lang_config (edit);
else
moo_edit_queue_apply_config (edit);
}
void
_moo_edit_update_config (void)
_moo_edit_update_config_from_global (MooEdit *edit)
{
g_return_if_fail (MOO_IS_EDIT (edit));
/* XXX */
moo_edit_config_unset_by_source (edit->config,
MOO_EDIT_CONFIG_SOURCE_AUTO);
}
void
_moo_edit_update_lang_config (void)
{
GSList *l;
@ -1054,7 +1030,6 @@ _moo_edit_update_config (void)
MooEdit *edit = l->data;
_moo_lang_mgr_update_config (moo_editor_get_lang_mgr (edit->priv->editor), edit->config,
moo_lang_id (moo_text_view_get_lang (MOO_TEXT_VIEW (edit))));
_moo_edit_apply_settings (edit);
}
}
@ -1066,23 +1041,29 @@ moo_edit_filename_changed (MooEdit *edit,
gboolean lang_changed = FALSE;
MooLang *lang = NULL, *old_lang = NULL;
const char *lang_id = NULL;
const char *filter_config = NULL;
old_lang = moo_text_view_get_lang (MOO_TEXT_VIEW (edit));
_moo_edit_freeze_config_notify (edit);
moo_edit_config_unset_by_source (edit->config, MOO_EDIT_CONFIG_SOURCE_FILE);
_moo_edit_apply_settings (edit);
_moo_edit_update_config_from_global (edit);
if (filename)
{
MooLangMgr *mgr = moo_editor_get_lang_mgr (edit->priv->editor);
lang = moo_lang_mgr_get_lang_for_file (mgr, filename);
lang_id = lang ? moo_lang_id (lang) : NULL;
filter_config = _moo_edit_filter_settings_get_for_file (filename);
}
moo_edit_config_set (edit->config, "lang", MOO_EDIT_CONFIG_SOURCE_FILENAME, lang_id, NULL);
moo_edit_config_set (edit->config, "indent", MOO_EDIT_CONFIG_SOURCE_FILENAME, NULL, NULL);
moo_edit_config_set (edit->config, MOO_EDIT_CONFIG_SOURCE_FILENAME,
"lang", lang_id, "indent", NULL, NULL);
if (filter_config)
moo_edit_config_parse (edit->config, filter_config,
MOO_EDIT_CONFIG_SOURCE_FILENAME);
try_mode_strings (edit);
@ -1097,7 +1078,7 @@ moo_edit_filename_changed (MooEdit *edit,
{
_moo_lang_mgr_update_config (moo_editor_get_lang_mgr (edit->priv->editor),
edit->config, moo_lang_id (lang));
_moo_edit_apply_settings (edit);
_moo_edit_update_config_from_global (edit);
}
_moo_edit_thaw_config_notify (edit);

View File

@ -474,8 +474,8 @@ moo_edit_config_set_value (MooEditConfig *config,
static void
moo_edit_config_set_valist (MooEditConfig *config,
const char *first_setting,
MooEditConfigSource source,
const char *first_setting,
va_list var_args)
{
const gchar *name;
@ -520,9 +520,6 @@ moo_edit_config_set_valist (MooEditConfig *config,
g_value_unset (&value);
name = va_arg (var_args, gchar*);
if (name)
source = va_arg (var_args, guint);
}
g_object_thaw_notify (G_OBJECT (config));
@ -532,8 +529,8 @@ moo_edit_config_set_valist (MooEditConfig *config,
void
moo_edit_config_set (MooEditConfig *config,
const char *first_setting,
MooEditConfigSource source,
const char *first_setting,
...)
{
va_list var_args;
@ -541,8 +538,8 @@ moo_edit_config_set (MooEditConfig *config,
g_return_if_fail (MOO_IS_EDIT_CONFIG (config));
g_return_if_fail (first_setting != NULL);
va_start (var_args, source);
moo_edit_config_set_valist (config, first_setting, source, var_args);
va_start (var_args, first_setting);
moo_edit_config_set_valist (config, source, first_setting, var_args);
va_end (var_args);
}
@ -563,8 +560,8 @@ moo_edit_config_get (MooEditConfig *config,
void
moo_edit_config_set_global (const char *first_setting,
MooEditConfigSource source,
moo_edit_config_set_global (MooEditConfigSource source,
const char *first_setting,
...)
{
va_list var_args;
@ -573,8 +570,8 @@ moo_edit_config_set_global (const char *first_setting,
global_init ();
va_start (var_args, source);
moo_edit_config_set_valist (global, first_setting, source, var_args);
va_start (var_args, first_setting);
moo_edit_config_set_valist (global, source, first_setting, var_args);
va_end (var_args);
}

View File

@ -46,8 +46,7 @@ typedef enum {
MOO_EDIT_CONFIG_SOURCE_FILE = 10,
MOO_EDIT_CONFIG_SOURCE_FILENAME = 20,
MOO_EDIT_CONFIG_SOURCE_LANG = 30,
MOO_EDIT_CONFIG_SOURCE_PREFS = 40,
MOO_EDIT_CONFIG_SOURCE_AUTO = 50
MOO_EDIT_CONFIG_SOURCE_AUTO = 40
} MooEditConfigSource;
struct _MooEditConfig
@ -75,16 +74,16 @@ gboolean moo_edit_config_get_bool (MooEditConfig *config,
const char *setting);
void moo_edit_config_set (MooEditConfig *config,
const char *first_setting,
MooEditConfigSource source,
...) G_GNUC_NULL_TERMINATED; /* setting, source, value, ... */
const char *first_setting,
...) G_GNUC_NULL_TERMINATED; /* setting, value, ... */
void moo_edit_config_get (MooEditConfig *config,
const char *first_setting,
...) G_GNUC_NULL_TERMINATED; /* alias for g_object_get() */
void moo_edit_config_set_global (const char *first_setting,
MooEditConfigSource source,
...) G_GNUC_NULL_TERMINATED; /* setting, source, value, ... */
void moo_edit_config_set_global (MooEditConfigSource source,
const char *first_setting,
...) G_GNUC_NULL_TERMINATED; /* setting, value, ... */
void moo_edit_config_get_global (const char *first_setting,
...) G_GNUC_NULL_TERMINATED; /* alias for g_object_get(global, ...) */

View File

@ -0,0 +1,297 @@
/*
* mooeditfiltersettings.c
*
* Copyright (C) 2004-2006 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/mooeditfiltersettings.h"
#include "mooedit/mooeditprefs.h"
#include "mooutils/mooprefs.h"
#include "mooutils/eggregex.h"
#include <string.h>
#define ELEMENT_FILTER_SETTINGS MOO_EDIT_PREFS_PREFIX "/filter-settings"
#define ELEMENT_SETTING "setting"
#define PROP_FILTER "filter"
#define PROP_CONFIG "config"
typedef struct {
EggRegex *regex;
char *config;
} FilterSetting;
typedef struct {
GSList *settings;
} FilterSettingsStore;
static FilterSettingsStore *settings_store;
static void
filter_setting_free (FilterSetting *setting)
{
if (setting)
{
g_free (setting->config);
egg_regex_unref (setting->regex);
g_free (setting);
}
}
static FilterSetting *
filter_setting_new (const char *filter,
const char *config)
{
FilterSetting *setting;
setting = g_new0 (FilterSetting, 1);
setting->regex = egg_regex_new (filter, EGG_REGEX_DOTALL, 0, NULL);
setting->config = g_strdup (config);
if (!setting->regex || !setting->config)
{
filter_setting_free (setting);
setting = NULL;
}
else
{
egg_regex_optimize (setting->regex, NULL);
}
return setting;
}
static FilterSettingsStore *
filter_settings_store_new (void)
{
FilterSettingsStore *store;
store = g_new0 (FilterSettingsStore, 1);
return store;
}
static void
filter_settings_store_free (FilterSettingsStore *store)
{
g_slist_foreach (store->settings, (GFunc) filter_setting_free, NULL);
g_slist_free (store->settings);
g_free (store);
}
static void
load_node (FilterSettingsStore *store,
MooMarkupNode *node)
{
const char *filter, *config;
FilterSetting *setting;
filter = moo_markup_get_prop (node, PROP_FILTER);
config = moo_markup_get_prop (node, PROP_CONFIG);
g_return_if_fail (filter != NULL && config != NULL);
setting = filter_setting_new (filter, config);
g_return_if_fail (setting != NULL);
store->settings = g_slist_prepend (store->settings, setting);
}
static void
filter_settings_store_load (FilterSettingsStore *store)
{
MooMarkupDoc *xml;
MooMarkupNode *root, *node;
g_return_if_fail (!store->settings);
xml = moo_prefs_get_markup ();
g_return_if_fail (xml != NULL);
root = moo_markup_get_element (MOO_MARKUP_NODE (xml),
ELEMENT_FILTER_SETTINGS);
if (!root)
return;
for (node = root->children; node != NULL; node = node->next)
{
if (!MOO_MARKUP_IS_ELEMENT (node))
continue;
if (strcmp (node->name, ELEMENT_SETTING))
{
g_warning ("%s: invalid '%s' element", G_STRLOC, node->name);
continue;
}
load_node (store, node);
}
store->settings = g_slist_reverse (store->settings);
}
void
_moo_edit_filter_settings_load (void)
{
if (settings_store)
return;
settings_store = filter_settings_store_new ();
filter_settings_store_load (settings_store);
}
void
_moo_edit_filter_settings_reload (void)
{
if (settings_store)
filter_settings_store_free (settings_store);
settings_store = NULL;
_moo_edit_filter_settings_load ();
}
const char *
_moo_edit_filter_settings_get_for_file (const char *filename)
{
char *filename_utf8;
const char *result;
g_return_val_if_fail (filename != NULL, NULL);
filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
g_return_val_if_fail (filename_utf8 != NULL, NULL);
result = _moo_edit_filter_settings_get_for_file_utf8 (filename_utf8);
g_free (filename_utf8);
return result;
}
static const char *
filter_setting_match (FilterSetting *setting,
const char *filename)
{
if (egg_regex_match (setting->regex, filename, 0))
{
g_message ("file '%s' matched pattern '%s': config '%s'",
filename, egg_regex_get_pattern (setting->regex),
setting->config);
return setting->config;
}
return NULL;
}
static const char *
filter_settings_store_get_setting (FilterSettingsStore *store,
const char *filename)
{
GSList *l;
for (l = store->settings; l != NULL; l = l->next)
{
const char *result;
result = filter_setting_match (l->data, filename);
if (result)
return result;
}
return NULL;
}
const char *
_moo_edit_filter_settings_get_for_file_utf8 (const char *filename)
{
g_return_val_if_fail (settings_store != NULL, NULL);
g_return_val_if_fail (filename != NULL, NULL);
g_assert (g_utf8_validate (filename, -1, NULL));
return filter_settings_store_get_setting (settings_store, filename);
}
void
_moo_edit_filter_settings_set_strings (GSList *list)
{
MooMarkupDoc *xml;
MooMarkupNode *root;
xml = moo_prefs_get_markup ();
g_return_if_fail (xml != NULL);
root = moo_markup_get_element (MOO_MARKUP_NODE (xml),
ELEMENT_FILTER_SETTINGS);
if (root)
moo_markup_delete_node (root);
if (!list)
{
_moo_edit_filter_settings_reload ();
return;
}
root = moo_markup_create_element (MOO_MARKUP_NODE (xml),
ELEMENT_FILTER_SETTINGS);
while (list)
{
MooMarkupNode *node;
const char *filter, *config;
g_return_if_fail (list->data && list->next && list->next->data);
filter = list->data;
config = list->next->data;
node = moo_markup_create_element (root, ELEMENT_SETTING);
moo_markup_set_prop (node, PROP_FILTER, filter);
moo_markup_set_prop (node, PROP_CONFIG, config);
list = list->next->next;
}
_moo_edit_filter_settings_reload ();
}
GSList *
_moo_edit_filter_settings_get_strings (void)
{
GSList *strings = NULL, *l;
g_return_val_if_fail (settings_store != NULL, NULL);
for (l = settings_store->settings; l != NULL; l = l->next)
{
FilterSetting *setting = l->data;
strings = g_slist_prepend (strings, g_strdup (egg_regex_get_pattern (setting->regex)));
strings = g_slist_prepend (strings, g_strdup (setting->config));
}
return g_slist_reverse (strings);
}

View File

@ -0,0 +1,38 @@
/*
* mooeditfiltersettings.h
*
* Copyright (C) 2004-2006 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.
*/
#ifndef MOOEDIT_COMPILATION
#error "This file may not be used"
#endif
#ifndef __MOO_EDIT_FILTER_SETTINGS_H__
#define __MOO_EDIT_FILTER_SETTINGS_H__
#include <glib.h>
G_BEGIN_DECLS
void _moo_edit_filter_settings_load (void);
void _moo_edit_filter_settings_reload (void);
GSList *_moo_edit_filter_settings_get_strings (void);
void _moo_edit_filter_settings_set_strings (GSList *strings);
const char *_moo_edit_filter_settings_get_for_file (const char *filename);
const char *_moo_edit_filter_settings_get_for_file_utf8 (const char *filename);
G_END_DECLS
#endif /* __MOO_EDIT_FILTER_SETTINGS_H__ */

View File

@ -19,6 +19,7 @@
#include "mooedit/mooeditprefs.h"
#include "mooedit/mooedit-private.h"
#include "mooedit/moolang-private.h"
#include "mooedit/mooeditfiltersettings.h"
#include "mooutils/moomenuaction.h"
#include "mooutils/moocompat.h"
#include "mooutils/moomarshals.h"
@ -88,11 +89,6 @@ static void activate_history_item (MooEditor *editor,
MooHistoryListItem *item,
MooEditWindow *window);
static void prefs_changed (const char *key,
const GValue *newval,
MooEditor *editor);
static gboolean apply_prefs (MooEditor *editor);
static void add_new_window_action (void);
static void remove_new_window_action (void);
@ -132,9 +128,6 @@ struct _MooEditorPrivate {
char *default_lang;
guint prefs_notify;
guint prefs_idle;
gboolean autosave;
guint autosave_interval;
};
@ -178,7 +171,6 @@ G_DEFINE_TYPE (MooEditor, moo_editor, G_TYPE_OBJECT)
static void
moo_editor_class_init (MooEditorClass *klass)
{
gpointer ref_class;
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
MooWindowClass *edit_window_class;
@ -186,11 +178,9 @@ moo_editor_class_init (MooEditorClass *klass)
gobject_class->set_property = moo_editor_set_property;
gobject_class->get_property = moo_editor_get_property;
_moo_edit_init_settings ();
ref_class = g_type_class_ref (MOO_TYPE_EDIT);
g_type_class_unref (ref_class);
ref_class = g_type_class_ref (MOO_TYPE_EDIT_WINDOW);
g_type_class_unref (ref_class);
_moo_edit_init_config ();
g_type_class_unref (g_type_class_ref (MOO_TYPE_EDIT));
g_type_class_unref (g_type_class_ref (MOO_TYPE_EDIT_WINDOW));
g_object_class_install_property (gobject_class,
PROP_OPEN_SINGLE_FILE_INSTANCE,
@ -281,7 +271,8 @@ moo_editor_init (MooEditor *editor)
editor->priv->lang_mgr = moo_lang_mgr_new ();
g_signal_connect_swapped (editor->priv->lang_mgr, "loaded",
G_CALLBACK (apply_prefs), editor);
G_CALLBACK (_moo_editor_apply_prefs),
editor);
editor->priv->filter_mgr = moo_filter_mgr_new ();
@ -305,13 +296,8 @@ moo_editor_init (MooEditor *editor)
moo_prefs_new_key_string (moo_edit_setting (MOO_EDIT_PREFS_DEFAULT_LANG),
MOO_LANG_NONE);
editor->priv->prefs_notify =
moo_prefs_notify_connect (MOO_EDIT_PREFS_PREFIX "/[^/]*",
MOO_PREFS_MATCH_REGEX,
(MooPrefsNotify) prefs_changed,
editor, NULL);
apply_prefs (editor);
_moo_edit_filter_settings_load ();
_moo_editor_apply_prefs (editor);
}
@ -438,10 +424,6 @@ moo_editor_finalize (GObject *object)
g_object_unref (editor->priv->history);
g_object_unref (editor->priv->lang_mgr);
if (editor->priv->prefs_idle)
g_source_remove (editor->priv->prefs_idle);
moo_prefs_notify_disconnect (editor->priv->prefs_notify);
if (editor->priv->file_watch)
{
GError *error = NULL;
@ -963,12 +945,11 @@ moo_editor_add_doc (MooEditor *editor,
!moo_edit_config_get_string (doc->config, "lang") &&
editor->priv->default_lang)
{
moo_edit_config_set (doc->config,
"lang", MOO_EDIT_CONFIG_SOURCE_FILENAME,
editor->priv->default_lang, NULL);
moo_edit_config_set (doc->config, MOO_EDIT_CONFIG_SOURCE_FILENAME,
"lang", editor->priv->default_lang, NULL);
}
_moo_edit_apply_settings (doc);
_moo_edit_apply_prefs (doc);
}
@ -2081,17 +2062,6 @@ moo_editor_set_edit_type (MooEditor *editor,
}
static void
prefs_changed (G_GNUC_UNUSED const char *key,
G_GNUC_UNUSED const GValue *newval,
MooEditor *editor)
{
if (!editor->priv->prefs_idle)
editor->priv->prefs_idle =
g_idle_add ((GSourceFunc) apply_prefs, editor);
}
static void
set_default_lang (MooEditor *editor,
const char *name)
@ -2102,16 +2072,14 @@ set_default_lang (MooEditor *editor,
}
static gboolean
apply_prefs (MooEditor *editor)
void
_moo_editor_apply_prefs (MooEditor *editor)
{
GSList *docs;
gboolean use_tabs, autosave, backups, strip;
int indent_width, autosave_interval;
gboolean autosave, backups;
int autosave_interval;
const char *color_scheme, *default_lang;
editor->priv->prefs_idle = 0;
default_lang = moo_prefs_get_string (moo_edit_setting (MOO_EDIT_PREFS_DEFAULT_LANG));
if (default_lang && !strcmp (default_lang, MOO_LANG_NONE))
@ -2119,31 +2087,24 @@ apply_prefs (MooEditor *editor)
set_default_lang (editor, default_lang);
use_tabs = !moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_SPACES_NO_TABS));
indent_width = moo_prefs_get_int (moo_edit_setting (MOO_EDIT_PREFS_INDENT_WIDTH));
strip = moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_STRIP));
autosave = moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_AUTO_SAVE));
autosave_interval = moo_prefs_get_int (moo_edit_setting (MOO_EDIT_PREFS_AUTO_SAVE_INTERVAL));
backups = moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_MAKE_BACKUPS));
color_scheme = moo_prefs_get_string (moo_edit_setting (MOO_EDIT_PREFS_COLOR_SCHEME));
_moo_edit_update_global_config ();
moo_edit_config_set_global ("indent-use-tabs", MOO_EDIT_CONFIG_SOURCE_PREFS, use_tabs,
"indent-width", MOO_EDIT_CONFIG_SOURCE_PREFS, indent_width,
"strip", MOO_EDIT_CONFIG_SOURCE_PREFS, strip,
NULL);
color_scheme = moo_prefs_get_string (moo_edit_setting (MOO_EDIT_PREFS_COLOR_SCHEME));
if (color_scheme)
_moo_lang_mgr_set_active_scheme (editor->priv->lang_mgr, color_scheme);
docs = moo_editor_list_docs (editor);
g_slist_foreach (docs, (GFunc) _moo_edit_apply_settings, NULL);
g_slist_foreach (docs, (GFunc) _moo_edit_apply_prefs, NULL);
g_slist_free (docs);
autosave = moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_AUTO_SAVE));
autosave_interval = moo_prefs_get_int (moo_edit_setting (MOO_EDIT_PREFS_AUTO_SAVE_INTERVAL));
backups = moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_MAKE_BACKUPS));
g_object_set (editor,
"autosave", autosave,
"autosave-interval", autosave_interval,
"save-backups", backups,
NULL);
return FALSE;
}

View File

@ -163,6 +163,7 @@ gboolean _moo_editor_save_as (MooEditor *editor,
void _moo_editor_post_message (MooEditor *editor,
GQuark domain,
const char *message);
void _moo_editor_apply_prefs (MooEditor *editor);
#endif /* MOOEDIT_COMPILATION */

View File

@ -16,29 +16,48 @@
#include <string.h>
#define STR_STACK_SIZE 4
static void _moo_edit_init_prefs (void);
const char *moo_edit_setting (const char *setting_name)
static guint settings[MOO_EDIT_LAST_SETTING];
guint *_moo_edit_settings = settings;
void
_moo_edit_init_config (void)
{
static GString *stack[STR_STACK_SIZE];
static guint p;
static gboolean done = FALSE;
g_return_val_if_fail (setting_name != NULL, NULL);
if (done)
return;
done = TRUE;
if (!stack[0])
{
for (p = 0; p < STR_STACK_SIZE; ++p)
stack[p] = g_string_new ("");
p = STR_STACK_SIZE - 1;
}
_moo_edit_init_prefs ();
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;
_moo_edit_settings[MOO_EDIT_SETTING_LANG] =
moo_edit_config_install_setting (g_param_spec_string ("lang", "lang", "lang",
NULL,
G_PARAM_READWRITE));
_moo_edit_settings[MOO_EDIT_SETTING_INDENT] =
moo_edit_config_install_setting (g_param_spec_string ("indent", "indent", "indent",
NULL,
G_PARAM_READWRITE));
_moo_edit_settings[MOO_EDIT_SETTING_STRIP] =
moo_edit_config_install_setting (g_param_spec_boolean ("strip", "strip", "strip",
FALSE,
G_PARAM_READWRITE));
_moo_edit_settings[MOO_EDIT_SETTING_WRAP_MODE] =
moo_edit_config_install_setting (g_param_spec_enum ("wrap-mode", "wrap-mode", "wrap-mode",
GTK_TYPE_WRAP_MODE, GTK_WRAP_NONE,
G_PARAM_READWRITE));
_moo_edit_settings[MOO_EDIT_SETTING_SHOW_LINE_NUMBERS] =
moo_edit_config_install_setting (g_param_spec_boolean ("show-line-numbers", "show-line-numbers", "show-line-numbers",
FALSE,
G_PARAM_READWRITE));
_moo_edit_settings[MOO_EDIT_SETTING_TAB_WIDTH] =
moo_edit_config_install_setting (g_param_spec_uint ("tab-width", "tab-width", "tab-width",
1, G_MAXUINT, 8,
G_PARAM_READWRITE));
}
@ -49,8 +68,8 @@ const char *moo_edit_setting (const char *setting_name)
#define NEW_KEY_ENUM(s,t,v) moo_prefs_new_key_enum (MOO_EDIT_PREFS_PREFIX "/" s, t, v)
#define NEW_KEY_FLAGS(s,t,v) moo_prefs_new_key_flags (MOO_EDIT_PREFS_PREFIX "/" s, t, v)
void
_moo_edit_init_settings (void)
static void
_moo_edit_init_prefs (void)
{
static gboolean done = FALSE;
@ -107,7 +126,41 @@ _moo_edit_init_settings (void)
#define get_flags(key) moo_prefs_get_flags (MOO_EDIT_PREFS_PREFIX "/" key)
void
_moo_edit_apply_settings (MooEdit *edit)
_moo_edit_update_global_config (void)
{
gboolean use_tabs, strip, show_line_numbers;
int indent_width;
GtkWrapMode wrap_mode;
use_tabs = !get_bool (MOO_EDIT_PREFS_SPACES_NO_TABS);
indent_width = get_int (MOO_EDIT_PREFS_INDENT_WIDTH);
strip = get_bool (MOO_EDIT_PREFS_STRIP);
show_line_numbers = get_bool (MOO_EDIT_PREFS_SHOW_LINE_NUMBERS);
if (get_bool (MOO_EDIT_PREFS_WRAP_ENABLE))
{
if (get_bool (MOO_EDIT_PREFS_WRAP_WORDS))
wrap_mode = GTK_WRAP_WORD;
else
wrap_mode = GTK_WRAP_CHAR;
}
else
{
wrap_mode = GTK_WRAP_NONE;
}
moo_edit_config_set_global (MOO_EDIT_CONFIG_SOURCE_AUTO,
"indent-use-tabs", use_tabs,
"indent-width", indent_width,
"strip", strip,
"show-line-numbers", show_line_numbers,
"wrap-mode", wrap_mode,
NULL);
}
void
_moo_edit_apply_prefs (MooEdit *edit)
{
GtkTextView *text_view;
MooLangMgr *mgr;
@ -115,7 +168,6 @@ _moo_edit_apply_settings (MooEdit *edit)
g_return_if_fail (MOO_IS_EDIT (edit));
g_object_freeze_notify (G_OBJECT (edit));
_moo_edit_freeze_config_notify (edit);
text_view = GTK_TEXT_VIEW (edit);
@ -133,33 +185,6 @@ _moo_edit_apply_settings (MooEdit *edit)
"backspace-indents", get_bool (MOO_EDIT_PREFS_BACKSPACE_INDENTS),
NULL);
moo_edit_config_set (edit->config,
"indent-use-tabs", MOO_EDIT_CONFIG_SOURCE_PREFS,
!get_bool (MOO_EDIT_PREFS_SPACES_NO_TABS),
"indent-width", MOO_EDIT_CONFIG_SOURCE_PREFS,
get_int (MOO_EDIT_PREFS_INDENT_WIDTH),
"show-line-numbers", MOO_EDIT_CONFIG_SOURCE_PREFS,
get_bool (MOO_EDIT_PREFS_SHOW_LINE_NUMBERS),
NULL);
if (get_bool (MOO_EDIT_PREFS_WRAP_ENABLE))
{
if (get_bool (MOO_EDIT_PREFS_WRAP_WORDS))
moo_edit_config_set (edit->config, "wrap-mode",
MOO_EDIT_CONFIG_SOURCE_PREFS,
GTK_WRAP_WORD, NULL);
else
moo_edit_config_set (edit->config, "wrap-mode",
MOO_EDIT_CONFIG_SOURCE_PREFS,
GTK_WRAP_CHAR, NULL);
}
else
{
moo_edit_config_set (edit->config, "wrap-mode",
MOO_EDIT_CONFIG_SOURCE_PREFS,
GTK_WRAP_NONE, NULL);
}
if (get_bool (MOO_EDIT_PREFS_USE_DEFAULT_FONT))
moo_text_view_set_font_from_string (MOO_TEXT_VIEW (edit), NULL);
else
@ -170,6 +195,32 @@ _moo_edit_apply_settings (MooEdit *edit)
moo_text_view_set_scheme (MOO_TEXT_VIEW (edit),
moo_lang_mgr_get_active_scheme (mgr));
_moo_edit_thaw_config_notify (edit);
g_object_thaw_notify (G_OBJECT (edit));
}
const char *
moo_edit_setting (const char *setting_name)
{
#define STR_STACK_SIZE 4
static GString *stack[STR_STACK_SIZE];
static guint p;
g_return_val_if_fail (setting_name != NULL, NULL);
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;
#undef STR_STACK_SIZE
}

View File

@ -64,36 +64,6 @@ const char *moo_edit_setting (const char *setting_name);
#define MOO_EDIT_PREFS_QUICK_SEARCH_FLAGS "quick_search_flags"
#define MOO_EDIT_PREFS_SEARCH_FLAGS "search_flags"
//
// #define MOO_EDIT_PREFS_ON_EXTERNAL_CHANGES "on_external_changes"
// #define MOO_EDIT_PREFS_TABS_WIDTH "tabs_width"
// #define MOO_EDIT_PREFS_AUTO_INDENT "auto_indent"
// #define MOO_EDIT_PREFS_TAB_INDENTS "tab_indents"
// #define MOO_EDIT_PREFS_BACKSPACE_INDENTS "backspace_indents"
// #define MOO_EDIT_PREFS_LIMIT_UNDO "limit_undo"
// #define MOO_EDIT_PREFS_LIMIT_UNDO_NUM "limit_undo_num"
// #define MOO_EDIT_PREFS_SHOW_MARGIN "show_right_margin"
// #define MOO_EDIT_PREFS_MARGIN "right_margin"
// #define MOO_EDIT_STYLE_ALERT "Alert"
// #define MOO_EDIT_STYLE_BASE_N "BaseN"
// #define MOO_EDIT_STYLE_CHAR "Char"
// #define MOO_EDIT_STYLE_COMMENT "Comment"
// #define MOO_EDIT_STYLE_DATA_TYPE "Data Type"
// #define MOO_EDIT_STYLE_DECIMAL "Decimal"
// #define MOO_EDIT_STYLE_ERROR "Error"
// #define MOO_EDIT_STYLE_FLOAT "Float"
// #define MOO_EDIT_STYLE_FUNCTION "Function"
// #define MOO_EDIT_STYLE_KEYWORD "Keyword"
// #define MOO_EDIT_STYLE_NORMAL "Normal"
// #define MOO_EDIT_STYLE_OTHERS "Others"
// #define MOO_EDIT_STYLE_STRING "String"
// #define MOO_EDIT_PREFS_BOLD "bold"
// #define MOO_EDIT_PREFS_ITALIC "italic"
// #define MOO_EDIT_PREFS_UNDERLINE "underline"
// #define MOO_EDIT_PREFS_STRIKETHROUGH "strikethrough"
G_END_DECLS

View File

@ -16,6 +16,7 @@
#include "mooedit/mooeditprefs.h"
#include "mooedit/mooeditprefs-glade.h"
#include "mooedit/moolang-private.h"
#include "mooedit/mooeditfiltersettings.h"
#include "mooutils/mooprefsdialog.h"
#include "mooutils/moocompat.h"
#include "mooutils/moostock.h"
@ -28,6 +29,7 @@
static void prefs_page_init (MooPrefsDialogPage *page);
static void prefs_page_apply (MooPrefsDialogPage *page);
static void prefs_page_apply_lang_prefs (MooPrefsDialogPage *page);
static void apply_filter_settings (MooPrefsDialogPage *page);
static void scheme_combo_init (GtkComboBox *combo,
MooEditor *editor);
@ -46,6 +48,8 @@ static void default_lang_combo_set_lang (GtkComboBox *combo,
static void lang_combo_init (GtkComboBox *combo,
MooPrefsDialogPage *page);
static void filter_treeview_init (MooGladeXML *xml);
static GtkTreeModel *create_lang_model (MooEditor *editor);
static MooEditor *page_get_editor (MooPrefsDialogPage *page);
@ -64,7 +68,7 @@ moo_edit_prefs_page_new (MooEditor *editor)
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
_moo_edit_init_settings ();
_moo_edit_init_config ();
xml = moo_glade_xml_new_empty ();
moo_glade_xml_map_id (xml, "fontbutton", MOO_TYPE_FONT_BUTTON);
@ -92,6 +96,8 @@ moo_edit_prefs_page_new (MooEditor *editor)
lang_combo = moo_glade_xml_get_widget (page->xml, "lang_combo");
lang_combo_init (lang_combo, page);
filter_treeview_init (page->xml);
return page_widget;
}
@ -251,6 +257,10 @@ prefs_page_apply (MooPrefsDialogPage *page)
{
MooTextStyleScheme *scheme;
char *lang;
MooEditor *editor;
editor = page_get_editor (page);
g_return_if_fail (editor != NULL);
scheme = page_get_scheme (page);
g_return_if_fail (scheme != NULL);
@ -262,6 +272,8 @@ prefs_page_apply (MooPrefsDialogPage *page)
g_free (lang);
prefs_page_apply_lang_prefs (page);
apply_filter_settings (page);
_moo_editor_apply_prefs (editor);
}
@ -695,5 +707,200 @@ prefs_page_apply_lang_prefs (MooPrefsDialogPage *page)
mgr = moo_editor_get_lang_mgr (page_get_editor (page));
gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) apply_one_lang, mgr);
_moo_lang_mgr_save_config (mgr);
_moo_edit_update_config ();
_moo_edit_update_lang_config ();
}
/*********************************************************************/
/* Filters
*/
enum {
FILTER_COLUMN_FILTER,
FILTER_COLUMN_CONFIG,
FILTER_NUM_COLUMNS
};
static void
filter_store_set_modified (gpointer store,
gboolean modified)
{
g_return_if_fail (GTK_IS_LIST_STORE (store));
g_object_set_data (store, "filter-store-modified",
GINT_TO_POINTER (modified));
}
static gboolean
filter_store_get_modified (gpointer store)
{
g_return_val_if_fail (GTK_IS_LIST_STORE (store), FALSE);
return g_object_get_data (store, "filter-store-modified") != NULL;
}
static void
populate_filter_settings_store (GtkListStore *store)
{
GSList *strings, *l;
_moo_edit_filter_settings_load ();
l = strings = _moo_edit_filter_settings_get_strings ();
while (l)
{
GtkTreeIter iter;
g_return_if_fail (l->next != NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
FILTER_COLUMN_FILTER, l->data,
FILTER_COLUMN_CONFIG, l->next->data,
-1);
l = l->next->next;
}
g_slist_foreach (strings, (GFunc) g_free, NULL);
g_slist_free (strings);
}
static gboolean
strings_equal (const char *s1,
const char *s2)
{
return !strcmp (s1 ? s1 : "", s2 ? s2 : "");
}
static void
filter_cell_edited (GtkCellRendererText *cell,
const char *path_string,
const char *text,
GtkListStore *store)
{
GtkTreeIter iter;
GtkTreePath *path;
int column;
char *old_text;
g_return_if_fail (GTK_IS_LIST_STORE (store));
column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "filter-store-column-id"));
g_return_if_fail (column >= 0 && column < FILTER_NUM_COLUMNS);
path = gtk_tree_path_new_from_string (path_string);
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
{
gtk_tree_path_free (path);
return;
}
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, column, &old_text, -1);
if (!strings_equal (old_text, text))
{
gtk_list_store_set (store, &iter, column, text, -1);
filter_store_set_modified (store, TRUE);
}
g_free (old_text);
gtk_tree_path_free (path);
}
static void
create_filter_cell (GtkTreeView *treeview,
GtkListStore *store,
const char *title,
int column_id)
{
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
cell = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (title, cell, "text", column_id, NULL);
gtk_tree_view_append_column (treeview, column);
g_object_set (cell, "editable", TRUE, NULL);
g_object_set_data (G_OBJECT (cell), "filter-store-column-id", GINT_TO_POINTER (column_id));
g_signal_connect (cell, "edited", G_CALLBACK (filter_cell_edited), store);
}
static void
filter_treeview_init (MooGladeXML *xml)
{
GtkTreeView *filter_treeview;
GtkListStore *store;
MooTreeHelper *helper;
filter_treeview = moo_glade_xml_get_widget (xml, "filter_treeview");
g_return_if_fail (filter_treeview != NULL);
store = gtk_list_store_new (FILTER_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
populate_filter_settings_store (store);
gtk_tree_view_set_model (filter_treeview, GTK_TREE_MODEL (store));
create_filter_cell (filter_treeview, store, "Filter", FILTER_COLUMN_FILTER);
create_filter_cell (filter_treeview, store, "Options", FILTER_COLUMN_CONFIG);
helper = moo_tree_helper_new (GTK_WIDGET (filter_treeview),
moo_glade_xml_get_widget (xml, "new_filter_setting"),
moo_glade_xml_get_widget (xml, "delete_filter_setting"),
moo_glade_xml_get_widget (xml, "filter_setting_up"),
moo_glade_xml_get_widget (xml, "filter_setting_down"));
gtk_object_sink (g_object_ref (helper));
g_object_set_data_full (G_OBJECT (filter_treeview), "tree-helper", helper, g_object_unref);
g_object_unref (store);
}
static gboolean
prepend_filter_and_config (GtkTreeModel *model,
G_GNUC_UNUSED GtkTreePath *path,
GtkTreeIter *iter,
GSList **list)
{
char *filter = NULL, *config = NULL;
gtk_tree_model_get (model, iter,
FILTER_COLUMN_FILTER, &filter,
FILTER_COLUMN_CONFIG, &config,
-1);
*list = g_slist_prepend (*list, filter ? filter : g_strdup (""));
*list = g_slist_prepend (*list, config ? config : g_strdup (""));
return FALSE;
}
static void
apply_filter_settings (MooPrefsDialogPage *page)
{
GtkTreeView *filter_treeview;
GSList *strings = NULL;
GtkTreeModel *model;
filter_treeview = moo_glade_xml_get_widget (page->xml, "filter_treeview");
g_return_if_fail (filter_treeview != NULL);
model = gtk_tree_view_get_model (filter_treeview);
if (!filter_store_get_modified (model))
return;
gtk_tree_model_foreach (model,
(GtkTreeModelForeachFunc) prepend_filter_and_config,
&strings);
strings = g_slist_reverse (strings);
_moo_edit_filter_settings_set_strings (strings);
filter_store_set_modified (model, FALSE);
g_slist_foreach (strings, (GFunc) g_free, NULL);
g_slist_free (strings);
}

View File

@ -1349,7 +1349,7 @@ wrap_text_toggled (MooEditWindow *window,
mode = GTK_WRAP_CHAR;
}
moo_edit_config_set (doc->config, "wrap-mode", MOO_EDIT_CONFIG_SOURCE_USER, mode, NULL);
moo_edit_config_set (doc->config, MOO_EDIT_CONFIG_SOURCE_USER, "wrap-mode", mode, NULL);
}
@ -1368,8 +1368,8 @@ line_numbers_toggled (MooEditWindow *window,
if ((active && show) || (!active && !show))
return;
moo_edit_config_set (doc->config, "show-line-numbers",
MOO_EDIT_CONFIG_SOURCE_USER, active,
moo_edit_config_set (doc->config, MOO_EDIT_CONFIG_SOURCE_USER,
"show-line-numbers", active,
NULL);
}
@ -2651,9 +2651,8 @@ lang_item_activated (MooEditWindow *window,
do_set = !!lang_name;
if (do_set)
moo_edit_config_set (doc->config, "lang",
MOO_EDIT_CONFIG_SOURCE_USER,
lang_name, NULL);
moo_edit_config_set (doc->config, MOO_EDIT_CONFIG_SOURCE_USER,
"lang", lang_name, NULL);
}

View File

@ -446,8 +446,15 @@ file_selector_create_file (MooFileSelector *filesel)
dir = selected->data;
g_list_free (selected);
selected = NULL;
if (!g_file_test (dir, G_FILE_TEST_IS_DIR))
{
g_free (dir);
dir = NULL;
}
}
else
if (!dir)
{
g_object_get (filesel, "current-directory", &dir, NULL);

View File

@ -55,6 +55,17 @@ static gboolean moo_tree_helper_get_selected (MooTreeHelper *helper,
GtkTreeModel **model,
GtkTreeIter *iter);
static gboolean tree_helper_new_row_default (MooTreeHelper *helper,
GtkTreeModel *model,
GtkTreePath *path);
static gboolean tree_helper_delete_row_default (MooTreeHelper *helper,
GtkTreeModel *model,
GtkTreePath *path);
static gboolean tree_helper_move_row_default (MooTreeHelper *helper,
GtkTreeModel *model,
GtkTreePath *old_path,
GtkTreePath *new_path);
G_DEFINE_TYPE (MooTreeHelper, _moo_tree_helper, GTK_TYPE_OBJECT)
@ -245,11 +256,83 @@ moo_tree_helper_destroy (GtkObject *object)
}
static gboolean
tree_helper_new_row_default (G_GNUC_UNUSED MooTreeHelper *helper,
GtkTreeModel *model,
GtkTreePath *path)
{
GtkTreeIter iter;
if (!GTK_IS_LIST_STORE (model))
return FALSE;
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (path) == 1, FALSE);
gtk_list_store_insert (GTK_LIST_STORE (model), &iter,
gtk_tree_path_get_indices(path)[0]);
return TRUE;
}
static gboolean
tree_helper_delete_row_default (G_GNUC_UNUSED MooTreeHelper *helper,
GtkTreeModel *model,
GtkTreePath *path)
{
GtkTreeIter iter;
if (!GTK_IS_LIST_STORE (model))
return FALSE;
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (path) == 1, FALSE);
gtk_tree_model_get_iter (model, &iter, path);
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
return TRUE;
}
static gboolean
tree_helper_move_row_default (G_GNUC_UNUSED MooTreeHelper *helper,
GtkTreeModel *model,
GtkTreePath *old_path,
GtkTreePath *new_path)
{
GtkTreeIter old_iter, new_iter;
int new, old;
if (!GTK_IS_LIST_STORE (model))
return FALSE;
g_return_val_if_fail (old_path && new_path, FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (old_path) == 1, FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (new_path) == 1, FALSE);
new = gtk_tree_path_get_indices(new_path)[0];
old = gtk_tree_path_get_indices(old_path)[0];
g_return_val_if_fail (ABS (new - old) == 1, FALSE);
gtk_tree_model_get_iter (model, &old_iter, old_path);
gtk_tree_model_get_iter (model, &new_iter, new_path);
gtk_list_store_swap (GTK_LIST_STORE (model), &old_iter, &new_iter);
return TRUE;
}
static void
_moo_tree_helper_class_init (MooTreeHelperClass *klass)
{
GTK_OBJECT_CLASS(klass)->destroy = moo_tree_helper_destroy;
klass->move_row = tree_helper_move_row_default;
klass->new_row = tree_helper_new_row_default;
klass->delete_row = tree_helper_delete_row_default;
tree_signals[NEW_ROW] =
g_signal_new ("new-row",
G_OBJECT_CLASS_TYPE (klass),