[gitg] Added preference for showing commit message markup
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Added preference for showing commit message markup
- Date: Sun, 7 Jul 2013 09:13:47 +0000 (UTC)
commit 0352e77abb3669c24651d60eab6a0a24aa89568a
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sun Jul 7 11:13:02 2013 +0200
Added preference for showing commit message markup
data/org.gnome.gitg.gschema.xml.in.in | 23 ++-
gitg/commit/gitg-commit-dialog.vala | 264 ++++++++++++++++++-------
gitg/preferences/gitg-preferences-commit.vala | 40 ++++-
gitg/resources/ui/gitg-preferences-commit.ui | 159 ++++++++++-----
4 files changed, 357 insertions(+), 129 deletions(-)
---
diff --git a/data/org.gnome.gitg.gschema.xml.in.in b/data/org.gnome.gitg.gschema.xml.in.in
index c9cdb5f..5da75a4 100644
--- a/data/org.gnome.gitg.gschema.xml.in.in
+++ b/data/org.gnome.gitg.gschema.xml.in.in
@@ -77,6 +77,9 @@
<child name="message" schema="org.gnome.gitg.preferences.commit.message" />
</schema>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.commit.message"
path="/org/gnome/gitg/preferences/commit/message/">
+ <key name="show-markup" type="b">
+ <default>true</default>
+ </key>
<key name="show-right-margin" type="b">
<default>true</default>
<_summary>Show Right Margin in Commit Message View</_summary>
@@ -86,20 +89,28 @@
a particular column.
</_description>
</key>
- <key name="right-margin-at" type="i">
+ <key name="right-margin-position" type="i">
<default>72</default>
<_summary>Column at Which Right Margin is Shown</_summary>
<_description>
- The column at which the right margin is shown if the right-margin
+ The column at which the right margin is shown if the show-right-margin
preference is set to TRUE.
</_description>
</key>
- <key name="subject-right-margin-at" type="i">
+ <key name="show-subject-margin" type="b">
+ <default>true</default>
+ <_summary>Show Subject Margin in Commit Message View</_summary>
+ <_description>
+ Highlight the subject text of the commit message when it passes the
+ margin specified by subject-margin-position.
+ </_description>
+ </key>
+ <key name="subject-margin-position" type="i">
<default>50</default>
- <_summary>Column at Which Subject Right Margin is Shown</_summary>
+ <_summary>Column at Which Subject Margin is Shown</_summary>
<_description>
- The column at which the right margin is shown for the subject
- if the right-margin preference is set to TRUE.
+ The column at which the subject margin is shown if the show-subject-margin
+ preference is set to TRUE.
</_description>
</key>
</schema>
diff --git a/gitg/commit/gitg-commit-dialog.vala b/gitg/commit/gitg-commit-dialog.vala
index d0270e7..48a417f 100644
--- a/gitg/commit/gitg-commit-dialog.vala
+++ b/gitg/commit/gitg-commit-dialog.vala
@@ -44,7 +44,17 @@ class Dialog : Gtk.Dialog
[GtkChild (name = "label_date")]
private Gtk.Label d_label_date;
- private Settings d_fontsettings;
+ private bool d_show_markup;
+ private bool d_show_right_margin;
+ private bool d_show_subject_margin;
+ private int d_right_margin_position;
+ private int d_subject_margin_position;
+ private Ggit.Signature d_author;
+ private Cancellable? d_cancel_avatar;
+ private bool d_constructed;
+ private Settings? d_message_settings;
+ private Settings? d_font_settings;
+ private Settings? d_commit_settings;
public GtkSource.View source_view_message
{
@@ -93,6 +103,77 @@ class Dialog : Gtk.Dialog
public bool sign_off { get; set; }
[Notify]
+ public bool show_markup
+ {
+ get { return d_show_markup; }
+
+ set
+ {
+ d_show_markup = value;
+ update_highlight();
+ }
+
+ default = true;
+ }
+
+ [Notify]
+ public bool show_right_margin
+ {
+ get { return d_show_right_margin; }
+
+ construct set
+ {
+ d_show_right_margin = value;
+ update_highlight();
+ }
+
+ default = true;
+ }
+
+ [Notify]
+ public bool show_subject_margin
+ {
+ get { return d_show_subject_margin; }
+
+ construct set
+ {
+ d_show_subject_margin = value;
+ update_highlight();
+ }
+
+ default = true;
+ }
+
+
+ [Notify]
+ public int right_margin_position
+ {
+ get { return d_right_margin_position; }
+
+ construct set
+ {
+ d_right_margin_position = value;
+ update_highlight();
+ }
+
+ default = 72;
+ }
+
+ [Notify]
+ public int subject_margin_position
+ {
+ get { return d_subject_margin_position; }
+
+ construct set
+ {
+ d_subject_margin_position = value;
+ update_highlight();
+ }
+
+ default = 50;
+ }
+
+ [Notify]
public Ggit.Signature author
{
owned get { return d_author; }
@@ -104,9 +185,6 @@ class Dialog : Gtk.Dialog
}
}
- [Notify]
- public int subject_right_margin_position { get; set; }
-
private void load_author_info()
{
if (d_cancel_avatar != null)
@@ -145,24 +223,27 @@ class Dialog : Gtk.Dialog
});
}
- private Ggit.Signature d_author;
- private Cancellable? d_cancel_avatar;
-
- ~Dialog()
+ protected override void destroy()
{
if (d_cancel_avatar != null)
{
d_cancel_avatar.cancel();
}
+
+ d_message_settings = null;
+ d_font_settings = null;
+ d_commit_settings = null;
+
+ base.destroy();
}
construct
{
- d_fontsettings = new Settings("org.gnome.desktop.interface");
+ d_font_settings = new Settings("org.gnome.desktop.interface");
update_font_settings();
- d_fontsettings.changed["monospace-font-name"].connect((s, k) => {
+ d_font_settings.changed["monospace-font-name"].connect((s, k) => {
update_font_settings();
});
@@ -182,33 +263,42 @@ class Dialog : Gtk.Dialog
BindingFlags.BIDIRECTIONAL |
BindingFlags.SYNC_CREATE);
- var commit_settings = new Settings("org.gnome.gitg.state.commit");
+ d_commit_settings = new Settings("org.gnome.gitg.state.commit");
- commit_settings.bind("sign-off",
+ d_commit_settings.bind("sign-off",
this,
"sign-off",
SettingsBindFlags.GET |
SettingsBindFlags.SET);
- var message_settings = new Settings("org.gnome.gitg.preferences.commit.message");
+ d_message_settings = new Settings("org.gnome.gitg.preferences.commit.message");
- message_settings.bind("show-right-margin",
- d_source_view_message,
- "show-right-margin",
- SettingsBindFlags.GET |
- SettingsBindFlags.SET);
+ d_message_settings.bind("show-markup",
+ this,
+ "show-markup",
+ SettingsBindFlags.GET);
- message_settings.bind("right-margin-at",
- d_source_view_message,
- "right-margin-position",
- SettingsBindFlags.GET |
- SettingsBindFlags.SET);
+ d_message_settings.bind("show-right-margin",
+ this,
+ "show-right-margin",
+ SettingsBindFlags.GET);
- message_settings.bind("subject-right-margin-at",
- this,
- "subject-right-margin-position",
- SettingsBindFlags.GET |
- SettingsBindFlags.SET);
+ d_message_settings.bind("right-margin-position",
+ this,
+ "right-margin-position",
+ SettingsBindFlags.GET);
+
+ d_message_settings.bind("show-subject-margin",
+ this,
+ "show-subject-margin",
+ SettingsBindFlags.GET);
+
+ d_message_settings.bind("subject-margin-position",
+ this,
+ "subject-margin-position",
+ SettingsBindFlags.GET);
+
+ d_constructed = true;
init_message_area();
}
@@ -216,31 +306,56 @@ class Dialog : Gtk.Dialog
private Gtk.TextTag d_subject_tag;
private Gtk.TextTag d_too_long_tag;
- private void init_message_area()
+ private void update_too_long_tag()
{
- var b = d_source_view_message.buffer;
-
+ // Get the warning fg/bg colors
var ctx = d_source_view_message.get_style_context();
+
ctx.save();
ctx.add_class("warning");
+
var fg = ctx.get_color(Gtk.StateFlags.NORMAL);
var bg = ctx.get_background_color(Gtk.StateFlags.NORMAL);
+
ctx.restore();
+ d_too_long_tag.background_rgba = bg;
+ d_too_long_tag.foreground_rgba = fg;
+ }
+
+ private void init_message_area()
+ {
+ var b = d_source_view_message.buffer;
+
d_subject_tag = b.create_tag("subject",
"weight", Pango.Weight.BOLD);
- d_too_long_tag = b.create_tag("too-long",
- "background-rgba", bg,
- "foreground-rgba", fg);
+ d_too_long_tag = b.create_tag("too-long");
- b.changed.connect(() => {
- do_highlight();
+ update_too_long_tag();
+
+ d_source_view_message.style_updated.connect(() => {
+ update_too_long_tag();
});
- d_source_view_message.notify["show-right-margin"].connect(() => {
+ b.changed.connect(() => {
do_highlight();
});
+
+ update_highlight();
+ }
+
+ private void update_highlight()
+ {
+ if (!d_constructed)
+ {
+ return;
+ }
+
+ d_source_view_message.show_right_margin = (d_show_markup && d_show_right_margin);
+ d_source_view_message.right_margin_position = d_right_margin_position;
+
+ do_highlight();
}
private void do_highlight()
@@ -254,7 +369,7 @@ class Dialog : Gtk.Dialog
b.remove_tag(d_subject_tag, start, end);
b.remove_tag(d_too_long_tag, start, end);
- if (!d_source_view_message.show_right_margin)
+ if (!d_show_markup)
{
return;
}
@@ -274,50 +389,53 @@ class Dialog : Gtk.Dialog
b.apply_tag(d_subject_tag, start, sstart);
- var toolong = sstart;
- var smargin = subject_right_margin_position;
-
- while (true)
+ if (d_show_subject_margin)
{
- var off = toolong.get_line_offset();
-
- if (off > smargin)
- {
- var border = toolong;
- border.set_line_offset(smargin);
-
- b.apply_tag(d_too_long_tag, border, toolong);
- }
+ var toolong = sstart;
- if (toolong.get_line() == 0)
+ while (true)
{
- break;
- }
-
- toolong.backward_line();
- toolong.forward_to_line_end();
- }
+ var off = toolong.get_line_offset();
- var rmargin = (int)d_source_view_message.right_margin_position;
+ if (off > d_subject_margin_position)
+ {
+ var border = toolong;
+ border.set_line_offset(d_subject_margin_position);
- while (!send.equal(end))
- {
- if (!send.ends_line())
- {
- send.forward_to_line_end();
- }
+ b.apply_tag(d_too_long_tag, border, toolong);
+ }
- if (send.get_line_offset() > rmargin)
- {
- var lstart = send;
- lstart.set_line_offset(rmargin);
+ if (toolong.get_line() == 0)
+ {
+ break;
+ }
- b.apply_tag(d_too_long_tag, lstart, send);
+ toolong.backward_line();
+ toolong.forward_to_line_end();
}
+ }
- if (!send.forward_line())
+ if (d_show_right_margin)
+ {
+ while (!send.equal(end))
{
- break;
+ if (!send.ends_line())
+ {
+ send.forward_to_line_end();
+ }
+
+ if (send.get_line_offset() > d_right_margin_position)
+ {
+ var lstart = send;
+ lstart.set_line_offset(d_right_margin_position);
+
+ b.apply_tag(d_too_long_tag, lstart, send);
+ }
+
+ if (!send.forward_line())
+ {
+ break;
+ }
}
}
}
@@ -329,7 +447,7 @@ class Dialog : Gtk.Dialog
private void update_font_settings()
{
- var mfont = d_fontsettings.get_string("monospace-font-name");
+ var mfont = d_font_settings.get_string("monospace-font-name");
var desc = Pango.FontDescription.from_string(mfont);
d_source_view_message.override_font(desc);
diff --git a/gitg/preferences/gitg-preferences-commit.vala b/gitg/preferences/gitg-preferences-commit.vala
index 4b1fadb..2df8e05 100644
--- a/gitg/preferences/gitg-preferences-commit.vala
+++ b/gitg/preferences/gitg-preferences-commit.vala
@@ -26,16 +26,38 @@ public class PreferencesCommit : Gtk.Grid, GitgExt.Preferences
// Do this to pull in config.h before glib.h (for gettext...)
private const string version = Gitg.Config.VERSION;
+ [GtkChild (name = "check_button_show_markup")]
+ private Gtk.CheckButton d_check_button_show_markup;
+
+ [GtkChild (name = "grid_show_markup")]
+ private Gtk.Grid d_grid_show_markup;
+
[GtkChild (name = "check_button_show_right_margin")]
private Gtk.CheckButton d_check_button_show_right_margin;
[GtkChild (name = "spin_button_right_margin")]
private Gtk.SpinButton d_spin_button_right_margin;
+ [GtkChild (name = "check_button_show_subject_margin")]
+ private Gtk.CheckButton d_check_button_show_subject_margin;
+
+ [GtkChild (name = "spin_button_subject_margin")]
+ private Gtk.SpinButton d_spin_button_subject_margin;
+
construct
{
var settings = new Settings("org.gnome.gitg.preferences.commit.message");
+ settings.bind("show-markup",
+ d_check_button_show_markup,
+ "active",
+ SettingsBindFlags.GET | SettingsBindFlags.SET);
+
+ settings.bind("show-markup",
+ d_grid_show_markup,
+ "sensitive",
+ SettingsBindFlags.GET);
+
settings.bind("show-right-margin",
d_check_button_show_right_margin,
"active",
@@ -46,10 +68,26 @@ public class PreferencesCommit : Gtk.Grid, GitgExt.Preferences
"sensitive",
SettingsBindFlags.GET);
- settings.bind("right-margin-at",
+ settings.bind("right-margin-position",
d_spin_button_right_margin,
"value",
SettingsBindFlags.GET | SettingsBindFlags.SET |
SettingsBindFlags.NO_SENSITIVITY);
+
+ settings.bind("show-subject-margin",
+ d_check_button_show_subject_margin,
+ "active",
+ SettingsBindFlags.GET | SettingsBindFlags.SET);
+
+ settings.bind("show-subject-margin",
+ d_spin_button_subject_margin,
+ "sensitive",
+ SettingsBindFlags.GET);
+
+ settings.bind("subject-margin-position",
+ d_spin_button_subject_margin,
+ "value",
+ SettingsBindFlags.GET | SettingsBindFlags.SET |
SettingsBindFlags.NO_SENSITIVITY);
+
}
public Gtk.Widget widget
diff --git a/gitg/resources/ui/gitg-preferences-commit.ui b/gitg/resources/ui/gitg-preferences-commit.ui
index 472252c..dd06c7d 100644
--- a/gitg/resources/ui/gitg-preferences-commit.ui
+++ b/gitg/resources/ui/gitg-preferences-commit.ui
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <!-- interface-requires gtk+ 3.0 -->
+ <!-- interface-requires gtk+ 3.0 -->
<object class="GtkAdjustment" id="spin_button_right_margin_adjustment">
<property name="lower">1</property>
<property name="upper">160</property>
@@ -8,12 +8,17 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
+ <object class="GtkAdjustment" id="spin_button_subject_margin_adjustment">
+ <property name="upper">100</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
<template class="GitgPreferencesCommit" parent="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="border_width">12</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
+ <property name="border_width">12</property>
<property name="row_spacing">18</property>
<property name="column_spacing">18</property>
<child>
@@ -35,20 +40,57 @@
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
- <property name="width">1</property>
+ <property name="width">3</property>
<property name="height">1</property>
</packing>
</child>
<child>
- <object class="GtkGrid" id="grid3">
+ <object class="GtkCheckButton" id="check_button_show_markup">
+ <property name="label" translatable="yes">Show markup</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">2</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid_show_markup">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="column_spacing">6</property>
<child>
- <object class="GtkLabel" id="label2">
+ <object class="GtkCheckButton" id="check_button_show_subject_margin">
+ <property name="label" translatable="yes">Display _subject margin at column:</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label"> </property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -58,58 +100,77 @@
</packing>
</child>
<child>
- <object class="GtkGrid" id="grid4">
+ <object class="GtkSpinButton" id="spin_button_subject_margin">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="hexpand">True</property>
- <property name="vexpand">True</property>
- <property name="column_spacing">6</property>
- <child>
- <object class="GtkCheckButton" id="check_button_show_right_margin">
- <property name="label" translatable="yes">Display right _margin at column:</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_underline">True</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkSpinButton" id="spin_button_right_margin">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="adjustment">spin_button_right_margin_adjustment</property>
- <property name="climb_rate">1</property>
- <property name="snap_to_ticks">True</property>
- <property name="numeric">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
+ <property name="can_focus">True</property>
+ <property name="text" translatable="yes">50</property>
+ <property name="adjustment">spin_button_subject_margin_adjustment</property>
+ <property name="climb_rate">1</property>
+ <property name="snap_to_ticks">True</property>
+ <property name="numeric">True</property>
+ <property name="value">50</property>
</object>
<packing>
- <property name="left_attach">0</property>
+ <property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="check_button_show_right_margin">
+ <property name="label" translatable="yes">Display right _margin at column:</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="spin_button_right_margin">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="text" translatable="yes">72</property>
+ <property name="adjustment">spin_button_right_margin_adjustment</property>
+ <property name="climb_rate">1</property>
+ <property name="snap_to_ticks">True</property>
+ <property name="numeric">True</property>
+ <property name="value">72</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
<packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
+ <property name="left_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]