Verified Commit fe00d993 authored by Ivan Molodetskikh's avatar Ivan Molodetskikh
Browse files

Add relative line numbers settings

parent 7193213b
......@@ -50,6 +50,11 @@
<summary>Show line numbers</summary>
<description>If enabled, the editor will show line numbers.</description>
</key>
<key name="show-relative-line-numbers" type="b">
<default>true</default>
<summary>Show relative line numbers</summary>
<description>If enabled, the editor will show relative line numbers.</description>
</key>
<key name="smart-backspace" type="b">
<default>true</default>
<summary>Smart Backspace</summary>
......
......@@ -163,6 +163,10 @@ _ide_editor_page_init_settings (IdeEditorPage *self)
source_view, "show-line-numbers",
G_SETTINGS_BIND_GET);
g_settings_bind (self->editor_settings, "show-relative-line-numbers",
source_view, "show-relative-line-numbers",
G_SETTINGS_BIND_GET);
g_settings_bind (self->editor_settings, "smart-backspace",
source_view, "smart-backspace",
G_SETTINGS_BIND_GET);
......
......@@ -97,6 +97,13 @@
<property name="visible">true</property>
</object>
</child>
<child>
<object class="GtkCheckButton">
<property name="label" translatable="yes">Display relative line numbers</property>
<property name="action-name">source-view.show-relative-line-numbers</property>
<property name="visible">true</property>
</object>
</child>
<child>
<object class="GtkCheckButton">
<property name="label" translatable="yes">Display right margin</property>
......
......@@ -163,6 +163,7 @@ ide_preferences_builtin_register_editor (DzlPreferences *preferences)
dzl_preferences_add_list_group (preferences, "editor", "line", _("Line Information"), GTK_SELECTION_NONE, 50);
dzl_preferences_add_switch (preferences, "editor", "line", "org.gnome.builder.editor", "show-line-numbers", NULL, NULL, _("Line numbers"), _("Show line number at beginning of each line"), NULL, 0);
dzl_preferences_add_switch (preferences, "editor", "line", "org.gnome.builder.editor", "show-relative-line-numbers", NULL, NULL, _("Relative line numbers"), _("Show line numbers relative to the cursor line"), NULL, 0);
dzl_preferences_add_switch (preferences, "editor", "line", "org.gnome.builder.editor", "show-line-changes", NULL, NULL, _("Line changes"), _("Show if a line was added or modified next to line number"), NULL, 1);
dzl_preferences_add_switch (preferences, "editor", "line", "org.gnome.builder.editor", "show-line-diagnostics", NULL, NULL, _("Line diagnostics"), _("Show an icon next to line numbers indicating type of diagnostic"), NULL, 2);
......
......@@ -57,6 +57,13 @@ ide_gutter_default_init (IdeGutterInterface *iface)
FALSE,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_interface_install_property (iface,
g_param_spec_boolean ("show-relative-line-numbers",
"Show Relative Line Numbers",
"If line numbers should be displayed relative to the cursor line",
FALSE,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
signals [STYLE_CHANGED] =
g_signal_new ("style-changed",
G_TYPE_FROM_INTERFACE (iface),
......@@ -92,6 +99,14 @@ ide_gutter_get_show_line_numbers (IdeGutter *self)
return ret;
}
gboolean
ide_gutter_get_show_relative_line_numbers (IdeGutter *self)
{
gboolean ret;
g_object_get (self, "show-relative-line-numbers", &ret, NULL);
return ret;
}
gboolean
ide_gutter_get_show_line_diagnostics (IdeGutter *self)
{
......@@ -118,6 +133,15 @@ ide_gutter_set_show_line_numbers (IdeGutter *self,
g_object_set (self, "show-line-numbers", show_line_numbers, NULL);
}
void
ide_gutter_set_show_relative_line_numbers (IdeGutter *self,
gboolean show_relative_line_numbers)
{
g_return_if_fail (IDE_IS_GUTTER (self));
g_object_set (self, "show-relative-line-numbers", show_relative_line_numbers, NULL);
}
void
ide_gutter_set_show_line_diagnostics (IdeGutter *self,
gboolean show_line_diagnostics)
......
......@@ -38,21 +38,26 @@ struct _IdeGutterInterface
};
IDE_AVAILABLE_IN_3_32
gboolean ide_gutter_get_show_line_changes (IdeGutter *self);
gboolean ide_gutter_get_show_line_changes (IdeGutter *self);
IDE_AVAILABLE_IN_3_32
gboolean ide_gutter_get_show_line_numbers (IdeGutter *self);
gboolean ide_gutter_get_show_line_numbers (IdeGutter *self);
IDE_AVAILABLE_IN_3_36
gboolean ide_gutter_get_show_relative_line_numbers (IdeGutter *self);
IDE_AVAILABLE_IN_3_32
gboolean ide_gutter_get_show_line_diagnostics (IdeGutter *self);
gboolean ide_gutter_get_show_line_diagnostics (IdeGutter *self);
IDE_AVAILABLE_IN_3_32
void ide_gutter_set_show_line_changes (IdeGutter *self,
gboolean show_line_changes);
void ide_gutter_set_show_line_changes (IdeGutter *self,
gboolean show_line_changes);
IDE_AVAILABLE_IN_3_32
void ide_gutter_set_show_line_numbers (IdeGutter *self,
gboolean show_line_numbers);
void ide_gutter_set_show_line_numbers (IdeGutter *self,
gboolean show_line_numbers);
IDE_AVAILABLE_IN_3_36
void ide_gutter_set_show_relative_line_numbers (IdeGutter *self,
gboolean show_relative_line_numbers);
IDE_AVAILABLE_IN_3_32
void ide_gutter_set_show_line_diagnostics (IdeGutter *self,
gboolean show_line_diagnostics);
void ide_gutter_set_show_line_diagnostics (IdeGutter *self,
gboolean show_line_diagnostics);
IDE_AVAILABLE_IN_3_32
void ide_gutter_style_changed (IdeGutter *self);
void ide_gutter_style_changed (IdeGutter *self);
G_END_DECLS
......@@ -158,6 +158,7 @@ typedef struct
guint show_line_changes : 1;
guint show_line_diagnostics : 1;
guint show_line_numbers : 1;
guint show_relative_line_numbers : 1;
} IdeSourceViewPrivate;
typedef struct
......@@ -193,6 +194,7 @@ enum {
PROP_SHOW_GRID_LINES,
PROP_SHOW_LINE_CHANGES,
PROP_SHOW_LINE_DIAGNOSTICS,
PROP_SHOW_RELATIVE_LINE_NUMBERS,
PROP_OVERSCROLL,
LAST_PROP,
......@@ -5504,6 +5506,10 @@ ide_source_view_get_property (GObject *object,
g_value_set_boolean (value, ide_source_view_get_show_line_numbers (self));
break;
case PROP_SHOW_RELATIVE_LINE_NUMBERS:
g_value_set_boolean (value, ide_source_view_get_show_relative_line_numbers (self));
break;
case PROP_OVERSCROLL:
g_value_set_int (value, priv->overscroll_num_lines);
break;
......@@ -5590,6 +5596,10 @@ ide_source_view_set_property (GObject *object,
ide_source_view_set_show_line_numbers (self, g_value_get_boolean (value));
break;
case PROP_SHOW_RELATIVE_LINE_NUMBERS:
ide_source_view_set_show_relative_line_numbers (self, g_value_get_boolean (value));
break;
case PROP_OVERSCROLL:
ide_source_view_set_overscroll_num_lines (self, g_value_get_int (value));
break;
......@@ -5804,6 +5814,13 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
g_object_class_override_property (object_class, PROP_SHOW_LINE_NUMBERS, "show-line-numbers");
properties [PROP_SHOW_RELATIVE_LINE_NUMBERS] =
g_param_spec_boolean ("show-relative-line-numbers",
"Show Relative Line Numbers",
"Show line numbers relative to the cursor line",
FALSE,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
properties [PROP_OVERSCROLL] =
g_param_spec_int ("overscroll",
"Overscroll",
......@@ -7821,6 +7838,33 @@ ide_source_view_set_show_line_numbers (IdeSourceView *self,
}
}
gboolean
ide_source_view_get_show_relative_line_numbers (IdeSourceView *self)
{
IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
g_return_val_if_fail (IDE_IS_SOURCE_VIEW (self), FALSE);
return priv->show_relative_line_numbers;
}
void
ide_source_view_set_show_relative_line_numbers (IdeSourceView *self,
gboolean show_relative_line_numbers)
{
IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
g_return_if_fail (IDE_IS_SOURCE_VIEW (self));
priv->show_relative_line_numbers = !!show_relative_line_numbers;
if (priv->gutter)
{
ide_gutter_set_show_relative_line_numbers (priv->gutter, show_relative_line_numbers);
g_object_notify (G_OBJECT (self), "show-relative-line-numbers");
}
}
gboolean
ide_source_view_is_processing_key (IdeSourceView *self)
{
......@@ -7914,6 +7958,7 @@ ide_source_view_set_gutter (IdeSourceView *self,
GTK_SOURCE_GUTTER_RENDERER (gutter),
0);
ide_gutter_set_show_line_numbers (priv->gutter, priv->show_line_numbers);
ide_gutter_set_show_relative_line_numbers (priv->gutter, priv->show_relative_line_numbers);
ide_gutter_set_show_line_changes (priv->gutter, priv->show_line_changes);
ide_gutter_set_show_line_diagnostics (priv->gutter, priv->show_line_diagnostics);
ide_gutter_style_changed (gutter);
......@@ -7922,6 +7967,7 @@ ide_source_view_set_gutter (IdeSourceView *self,
g_object_notify (G_OBJECT (self), "show-line-changes");
g_object_notify (G_OBJECT (self), "show-line-diagnostics");
g_object_notify (G_OBJECT (self), "show-line-numbers");
g_object_notify (G_OBJECT (self), "show-relative-line-numbers");
}
gboolean
......
This diff is collapsed.
......@@ -192,6 +192,7 @@ enum {
PROP_0,
PROP_SHOW_LINE_CHANGES,
PROP_SHOW_LINE_NUMBERS,
PROP_SHOW_RELATIVE_LINE_NUMBERS,
PROP_SHOW_LINE_DIAGNOSTICS,
N_PROPS
};
......@@ -1638,6 +1639,10 @@ gbp_omni_gutter_renderer_get_property (GObject *object,
g_value_set_boolean (value, self->show_line_numbers);
break;
case PROP_SHOW_RELATIVE_LINE_NUMBERS:
g_value_set_boolean (value, self->show_relative_line_numbers);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
......@@ -1665,6 +1670,10 @@ gbp_omni_gutter_renderer_set_property (GObject *object,
gbp_omni_gutter_renderer_set_show_line_numbers (self, g_value_get_boolean (value));
break;
case PROP_SHOW_RELATIVE_LINE_NUMBERS:
gbp_omni_gutter_renderer_set_show_relative_line_numbers (self, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
......@@ -1695,6 +1704,10 @@ gbp_omni_gutter_renderer_class_init (GbpOmniGutterRendererClass *klass)
g_param_spec_boolean ("show-line-numbers", NULL, NULL, TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
properties [PROP_SHOW_RELATIVE_LINE_NUMBERS] =
g_param_spec_boolean ("show-relative-line-numbers", NULL, NULL, FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
properties [PROP_SHOW_LINE_DIAGNOSTICS] =
g_param_spec_boolean ("show-line-diagnostics", NULL, NULL, TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
......@@ -1800,6 +1813,14 @@ gbp_omni_gutter_renderer_get_show_line_numbers (GbpOmniGutterRenderer *self)
return self->show_line_numbers;
}
gboolean
gbp_omni_gutter_renderer_get_show_relative_line_numbers (GbpOmniGutterRenderer *self)
{
g_return_val_if_fail (GBP_IS_OMNI_GUTTER_RENDERER (self), FALSE);
return self->show_relative_line_numbers;
}
void
gbp_omni_gutter_renderer_set_show_line_changes (GbpOmniGutterRenderer *self,
gboolean show_line_changes)
......@@ -1848,6 +1869,22 @@ gbp_omni_gutter_renderer_set_show_line_numbers (GbpOmniGutterRenderer *self,
}
}
void
gbp_omni_gutter_renderer_set_show_relative_line_numbers (GbpOmniGutterRenderer *self,
gboolean show_relative_line_numbers)
{
g_return_if_fail (GBP_IS_OMNI_GUTTER_RENDERER (self));
show_relative_line_numbers = !!show_relative_line_numbers;
if (show_relative_line_numbers != self->show_relative_line_numbers)
{
self->show_relative_line_numbers = show_relative_line_numbers;
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SHOW_RELATIVE_LINE_NUMBERS]);
gtk_source_gutter_renderer_queue_draw (GTK_SOURCE_GUTTER_RENDERER (self));
}
}
static void
gbp_omni_gutter_renderer_style_changed (IdeGutter *gutter)
{
......
......@@ -28,15 +28,18 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpOmniGutterRenderer, gbp_omni_gutter_renderer, GBP, OMNI_GUTTER_RENDERER, GtkSourceGutterRenderer)
GbpOmniGutterRenderer *gbp_omni_gutter_renderer_new (void);
gboolean gbp_omni_gutter_renderer_get_show_line_changes (GbpOmniGutterRenderer *self);
gboolean gbp_omni_gutter_renderer_get_show_line_diagnostics (GbpOmniGutterRenderer *self);
gboolean gbp_omni_gutter_renderer_get_show_line_numbers (GbpOmniGutterRenderer *self);
void gbp_omni_gutter_renderer_set_show_line_changes (GbpOmniGutterRenderer *self,
gboolean show_line_changes);
void gbp_omni_gutter_renderer_set_show_line_diagnostics (GbpOmniGutterRenderer *self,
gboolean show_line_diagnostics);
void gbp_omni_gutter_renderer_set_show_line_numbers (GbpOmniGutterRenderer *self,
gboolean show_line_numbers);
GbpOmniGutterRenderer *gbp_omni_gutter_renderer_new (void);
gboolean gbp_omni_gutter_renderer_get_show_line_changes (GbpOmniGutterRenderer *self);
gboolean gbp_omni_gutter_renderer_get_show_line_diagnostics (GbpOmniGutterRenderer *self);
gboolean gbp_omni_gutter_renderer_get_show_line_numbers (GbpOmniGutterRenderer *self);
gboolean gbp_omni_gutter_renderer_get_show_relative_line_numbers (GbpOmniGutterRenderer *self);
void gbp_omni_gutter_renderer_set_show_line_changes (GbpOmniGutterRenderer *self,
gboolean show_line_changes);
void gbp_omni_gutter_renderer_set_show_line_diagnostics (GbpOmniGutterRenderer *self,
gboolean show_line_diagnostics);
void gbp_omni_gutter_renderer_set_show_line_numbers (GbpOmniGutterRenderer *self,
gboolean show_line_numbers);
void gbp_omni_gutter_renderer_set_show_relative_line_numbers (GbpOmniGutterRenderer *self,
gboolean show_relative_line_numbers);
G_END_DECLS
......@@ -220,6 +220,26 @@ gb_vim_set_number (GtkSourceView *source_view,
return TRUE;
}
static gboolean
gb_vim_set_norelativenumber (GtkSourceView *source_view,
const gchar *key,
const gchar *value,
GError **error)
{
g_object_set (source_view, "show-relative-line-numbers", FALSE, NULL);
return TRUE;
}
static gboolean
gb_vim_set_relativenumber (GtkSourceView *source_view,
const gchar *key,
const gchar *value,
GError **error)
{
g_object_set (source_view, "show-relative-line-numbers", TRUE, NULL);
return TRUE;
}
static gboolean
gb_vim_set_scrolloff (GtkSourceView *source_view,
const gchar *key,
......@@ -269,16 +289,18 @@ gb_vim_set_tabstop (GtkSourceView *source_view,
}
static const GbVimSet vim_sets [] = {
{ "autoindent", gb_vim_set_autoindent },
{ "expandtab", gb_vim_set_expandtab },
{ "filetype", gb_vim_set_filetype },
{ "noautoindent", gb_vim_set_noautoindent },
{ "noexpandtab", gb_vim_set_noexpandtab },
{ "nonumber", gb_vim_set_nonumber },
{ "number", gb_vim_set_number },
{ "scrolloff", gb_vim_set_scrolloff },
{ "shiftwidth", gb_vim_set_shiftwidth },
{ "tabstop", gb_vim_set_tabstop },
{ "autoindent", gb_vim_set_autoindent },
{ "expandtab", gb_vim_set_expandtab },
{ "filetype", gb_vim_set_filetype },
{ "noautoindent", gb_vim_set_noautoindent },
{ "noexpandtab", gb_vim_set_noexpandtab },
{ "nonumber", gb_vim_set_nonumber },
{ "number", gb_vim_set_number },
{ "norelativenumber", gb_vim_set_norelativenumber },
{ "relativenumber", gb_vim_set_relativenumber },
{ "scrolloff", gb_vim_set_scrolloff },
{ "shiftwidth", gb_vim_set_shiftwidth },
{ "tabstop", gb_vim_set_tabstop },
{ NULL }
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment