Skip to content

Commit

Permalink
Use the rest of the GtkSourceView properties with GSettings
Browse files Browse the repository at this point in the history
Rename existing settings to make them match GtkSourceView property
names for consistency.
  • Loading branch information
codebrainz committed Jul 7, 2014
1 parent f0391f0 commit fd87858
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 85 deletions.
9 changes: 2 additions & 7 deletions mousepad/mousepad-document.c
Expand Up @@ -176,9 +176,8 @@ static void
mousepad_document_init (MousepadDocument *document)
{
GtkTargetList *target_list;
gboolean word_wrap, insert_spaces;
gboolean word_wrap;
gchar *color_scheme;
gint tab_size;
GtkSourceStyleScheme *scheme = NULL;

/* private structure */
Expand Down Expand Up @@ -218,14 +217,10 @@ mousepad_document_init (MousepadDocument *document)

/* read all the default settings */
word_wrap = mousepad_settings_get_boolean ("view-word-wrap");
tab_size = mousepad_settings_get_int ("view-tab-size");
insert_spaces = mousepad_settings_get_boolean ("view-insert-spaces");
color_scheme = mousepad_settings_get_string ("view-color-scheme");

/* set all the settings */
mousepad_document_set_word_wrap (document, word_wrap);
mousepad_view_set_tab_size (document->textview, tab_size);
mousepad_view_set_insert_spaces (document->textview, insert_spaces);

if (g_strcmp0 (color_scheme, "none") != 0)
scheme = gtk_source_style_scheme_manager_get_scheme (gtk_source_style_scheme_manager_get_default (), color_scheme);
Expand Down Expand Up @@ -286,7 +281,7 @@ mousepad_document_notify_cursor_position (GtkTextBuffer *buffer,
line = gtk_text_iter_get_line (&iter) + 1;

/* get the tab size */
tab_size = mousepad_view_get_tab_size (document->textview);
tab_size = mousepad_settings_get_int ("view-tab-width");

/* get the column */
column = mousepad_util_get_real_line_offset (&iter, tab_size);
Expand Down
54 changes: 10 additions & 44 deletions mousepad/mousepad-view.c
Expand Up @@ -213,11 +213,20 @@ mousepad_view_init (MousepadView *view)
G_CALLBACK (mousepad_view_commit_handler), view);

/* bind Gsettings */
mousepad_settings_bind ("view-line-numbers", view, "show-line-numbers", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-auto-indent", view, "auto-indent", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-font-name", view, "font-name", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-show-whitespace", view, "show-whitespace", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-show-line-endings", view, "show-line-endings", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-highlight-current-line", view, "highlight-current-line", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-indent-on-tab", view, "indent-on-tab", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-indent-width", view, "indent-width", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-insert-spaces", view, "insert-spaces-instead-of-tabs", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-right-margin-position", view, "right-margin-position", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-show-line-marks", view, "show-line-marks", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-show-line-numbers", view, "show-line-numbers", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-show-right-margin", view, "show-right-margin", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-smart-home-end", view, "smart-home-end", G_SETTINGS_BIND_DEFAULT);
mousepad_settings_bind ("view-tab-width", view, "tab-width", G_SETTINGS_BIND_DEFAULT);
}


Expand Down Expand Up @@ -2394,29 +2403,6 @@ mousepad_view_indent (MousepadView *view,



void
mousepad_view_set_tab_size (MousepadView *view,
gint tab_size)
{
mousepad_return_if_fail (MOUSEPAD_IS_VIEW (view));
mousepad_return_if_fail (GTK_IS_TEXT_VIEW (view));

gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (view), tab_size);
}



void
mousepad_view_set_insert_spaces (MousepadView *view,
gboolean insert_spaces)
{
mousepad_return_if_fail (MOUSEPAD_IS_VIEW (view));

gtk_source_view_set_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (view), insert_spaces);
}



gboolean
mousepad_view_get_selection_length (MousepadView *view,
gboolean *is_column_selection)
Expand Down Expand Up @@ -2456,26 +2442,6 @@ mousepad_view_get_selection_length (MousepadView *view,



gint
mousepad_view_get_tab_size (MousepadView *view)
{
mousepad_return_val_if_fail (MOUSEPAD_IS_VIEW (view), -1);

return gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (view));
}



gboolean
mousepad_view_get_insert_spaces (MousepadView *view)
{
mousepad_return_val_if_fail (MOUSEPAD_IS_VIEW (view), FALSE);

return gtk_source_view_get_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (view));
}



void
mousepad_view_set_font_name (MousepadView *view,
const gchar *font_name)
Expand Down
12 changes: 0 additions & 12 deletions mousepad/mousepad-view.h
Expand Up @@ -92,21 +92,9 @@ void mousepad_view_duplicate (MousepadView *view
void mousepad_view_indent (MousepadView *view,
gint type);

void mousepad_view_set_tab_size (MousepadView *view,
gint tab_size);

void mousepad_view_set_insert_spaces (MousepadView *view,
gboolean insert_spaces);

gint mousepad_view_get_selection_length (MousepadView *view,
gboolean *is_column_selection);

gboolean mousepad_view_get_line_numbers (MousepadView *view);

gint mousepad_view_get_tab_size (MousepadView *view);

gboolean mousepad_view_get_insert_spaces (MousepadView *view);

void mousepad_view_set_font_name (MousepadView *view,
const gchar *font_name);

Expand Down
39 changes: 27 additions & 12 deletions mousepad/mousepad-window.c
Expand Up @@ -539,6 +539,18 @@ mousepad_window_class_init (MousepadWindowClass *klass)



/* Called in response to any settings changed which affect the statusbar labels. */
static void
mousepad_window_update_statusbar_settings (MousepadWindow *window,
gchar *key,
MousepadSettings *settings)
{
if (G_LIKELY (MOUSEPAD_IS_DOCUMENT (window->active)))
mousepad_document_send_signals (window->active);
}



static void
mousepad_window_init (MousepadWindow *window)
{
Expand Down Expand Up @@ -698,6 +710,15 @@ mousepad_window_init (MousepadWindow *window)
gtk_drag_dest_set (GTK_WIDGET (window), GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, drop_targets, G_N_ELEMENTS (drop_targets), GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (G_OBJECT (window), "drag-data-received", G_CALLBACK (mousepad_window_drag_data_received), window);

/* update the statusbar with certain settings */
g_signal_connect_swapped (MOUSEPAD_GSETTINGS,
"changed::view-tab-width",
G_CALLBACK (mousepad_window_update_statusbar_settings),
window);
g_signal_connect_swapped (MOUSEPAD_GSETTINGS,
"changed::view-insert-spaces",
G_CALLBACK (mousepad_window_update_statusbar_settings),
window);
}


Expand Down Expand Up @@ -2099,7 +2120,7 @@ mousepad_window_menu_tab_sizes_update (MousepadWindow *window)
lock_menu_updates++;

/* get tab size of active document */
tab_size = mousepad_view_get_tab_size (window->active->textview);
tab_size = mousepad_settings_get_int ("view-tab-width");

/* check if there is a default item with this number */
name = g_strdup_printf ("tab-size_%d", tab_size);
Expand Down Expand Up @@ -2251,7 +2272,7 @@ mousepad_window_update_actions (MousepadWindow *window)
action = gtk_action_group_get_action (window->action_group, "word-wrap");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);

active = mousepad_settings_get_boolean ("view-line-numbers");
active = mousepad_settings_get_boolean ("view-show-line-numbers");
action = gtk_action_group_get_action (window->action_group, "line-numbers");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);

Expand All @@ -2262,7 +2283,7 @@ mousepad_window_update_actions (MousepadWindow *window)
/* update the tabs size menu */
mousepad_window_menu_tab_sizes_update (window);

active = mousepad_view_get_insert_spaces (document->textview);
active = mousepad_settings_get_boolean ("view-insert-spaces");
action = gtk_action_group_get_action (window->action_group, "insert-spaces");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);

Expand Down Expand Up @@ -4509,7 +4530,7 @@ mousepad_window_action_line_numbers (GtkToggleAction *action,
active = gtk_toggle_action_get_active (action);

/* save as the last used line number setting */
mousepad_settings_set_boolean ("view-line-numbers", active);
mousepad_settings_set_boolean ("view-show-line-numbers", active);
}


Expand Down Expand Up @@ -4818,17 +4839,14 @@ mousepad_window_action_tab_size (GtkToggleAction *action,
if (tab_size == 0)
{
/* get tab size from document */
tab_size = mousepad_view_get_tab_size (window->active->textview);
tab_size = mousepad_settings_get_int ("view-tab-width");

/* select other size in dialog */
tab_size = mousepad_dialogs_other_tab_size (GTK_WINDOW (window), tab_size);
}

/* store as last used value */
mousepad_settings_set_int ("view-tab-size", tab_size);

/* set the value */
mousepad_view_set_tab_size (window->active->textview, tab_size);
mousepad_settings_set_int ("view-tab-width", tab_size);

/* update menu */
mousepad_window_menu_tab_sizes_update (window);
Expand Down Expand Up @@ -4940,9 +4958,6 @@ mousepad_window_action_insert_spaces (GtkToggleAction *action,

/* save as the last auto indent mode */
mousepad_settings_set_boolean ("view-insert-spaces", insert_spaces);

/* update the active document */
mousepad_view_set_insert_spaces (window->active->textview, insert_spaces);
}
}

Expand Down
87 changes: 77 additions & 10 deletions mousepad/org.xfce.Mousepad.gschema.xml
@@ -1,5 +1,14 @@
<schemalist>

<!-- Enums and flags -->

<enum id="org.xfce.Mousepad.SmartHomeEnd">
<value nick="disabled" value="0"/>
<value nick="before" value="1"/>
<value nick="after" value="2"/>
<value nick="always" value="3"/>
</enum>

<schema id="org.xfce.Mousepad" path="/org/xfce/Mousepad/" gettext-domain="mousepad">

<!-- Search preferences -->
Expand Down Expand Up @@ -90,21 +99,30 @@
</description>
</key>

<key name="view-line-numbers" type="b">
<default>false</default>
<summary>Show line numbers</summary>
<key name="view-highlight-current-line" type="b">
<default>true</default>
<summary>Highlight current line</summary>
<description>
When true the line numbers gutter/margin will be visible, when false
it will not be visible.
When true visually indicate the line with the caret on it, when false
provide no such indication.
</description>
</key>

<key name="view-tab-size" type="i">
<range min="1" max="32"/>
<default>8</default>
<summary>Tab width</summary>
<key name="view-indent-on-tab" type="b">
<default>true</default>
<summary>Indent on tab</summary>
<description>
The number of characters wide that a tab character appears as.
When true indent selected text when tab key is pressed, when false,
don't indent on tab.
</description>
</key>

<key name="view-indent-width" type="i">
<range min="-1" max="32"/>
<default>-1</default>
<summary>Indentation width</summary>
<description>
Width of an indentation step expressed in number of spaces.
</description>
</key>

Expand All @@ -116,6 +134,55 @@
of tab characters, when false tab characters will be inserted.
</description>
</key>

<key name="view-right-margin-position" type="i">
<range min="1" max="1000"/>
<default>80</default>
<summary>Right margin position</summary>
<description>
Position of the right margin (line drawn vertically down right side
of the view).
</description>
</key>

<key name="view-show-line-marks" type="b">
<default>false</default>
<summary>Show line marks</summary>
<description>Whether to display line mark pixbufs.</description>
</key>

<key name="view-show-line-numbers" type="b">
<default>false</default>
<summary>Show line numbers</summary>
<description>
When true the line numbers gutter/margin will be visible, when false
it will not be visible.
</description>
</key>

<key name="view-show-right-margin" type="b">
<default>false</default>
<summary>Show right margin</summary>
<description>
When true the right margin is displayed at the column specified in
'view-right-margin-position', when false it is not drawn.
</description>
</key>

<key name="view-smart-home-end" enum="org.xfce.Mousepad.SmartHomeEnd">
<default>'disabled'</default>
<summary>Smart home end type</summary>
<description>Sets the behaviour of the HOME and END keys.</description>
</key>

<key name="view-tab-width" type="i">
<range min="1" max="32"/>
<default>8</default>
<summary>Tab width</summary>
<description>
The number of characters wide that a tab character appears as.
</description>
</key>

<key name="view-word-wrap" type="b">
<default>false</default>
Expand Down

0 comments on commit fd87858

Please sign in to comment.