Skip to content

Commit

Permalink
git-ui: Add a preference dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
b4n committed Feb 16, 2015
1 parent 216fe98 commit 147c188
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 1 deletion.
1 change: 1 addition & 0 deletions build/git-ui.m4
Expand Up @@ -11,6 +11,7 @@ AC_DEFUN([GP_CHECK_GITUI],
AC_CONFIG_FILES([
git-ui/Makefile
git-ui/data/Makefile
git-ui/src/Makefile
])
])
2 changes: 1 addition & 1 deletion git-ui/Makefile.am
@@ -1,4 +1,4 @@
include $(top_srcdir)/build/vars.auxfiles.mk
plugin = git-ui

SUBDIRS = src
SUBDIRS = data src
4 changes: 4 additions & 0 deletions git-ui/data/Makefile.am
@@ -0,0 +1,4 @@
include $(top_srcdir)/build/vars.docs.mk
plugin = git-ui

dist_plugindata_DATA = prefs.ui
162 changes: 162 additions & 0 deletions git-ui/data/prefs.ui
@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkVBox" id="base">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
<child>
<object class="GtkVBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkHBox" id="box3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Added lines:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">added-color-button</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="added-color-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="box4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Changed lines:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">changed-color-button</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="changed-color-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="box5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Removed lines:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">removed-color-button</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="removed-color-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Colors</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</interface>
119 changes: 119 additions & 0 deletions git-ui/src/ggu-plugin.c
Expand Up @@ -1039,3 +1039,122 @@ plugin_cleanup (void)

git_threads_shutdown ();
}

/* --- configuration dialog --- */

typedef struct ConfigureWidgets ConfigureWidgets;
struct ConfigureWidgets {
GtkWidget *base;
GtkWidget *added_color_button;
GtkWidget *changed_color_button;
GtkWidget *removed_color_button;
};

static void configure_widgets_free (ConfigureWidgets *cw)
{
g_object_unref (cw->base);
g_free (cw);
}

static void
color_from_int (GdkColor *color,
guint32 val)
{
color->red = ((val & 0xff0000) >> 16) * 0x101;
color->green = ((val & 0x00ff00) >> 8) * 0x101;
color->blue = ((val & 0x0000ff) >> 0) * 0x101;
}

static guint32
color_to_int (const GdkColor *color)
{
return (((color->red / 0x101) << 16) |
((color->green / 0x101) << 8) |
((color->blue / 0x101) << 0));
}

static void
on_plugin_configure_response (GtkDialog *dialog,
gint response,
ConfigureWidgets *cw)
{
switch (response) {
case GTK_RESPONSE_APPLY:
case GTK_RESPONSE_OK: {
guint i;
GdkColor color;
GeanyDocument *doc = document_get_current ();

gtk_color_button_get_color (GTK_COLOR_BUTTON (cw->added_color_button),
&color);
G_markers[MARKER_LINE_ADDED].color = color_to_int (&color);
gtk_color_button_get_color (GTK_COLOR_BUTTON (cw->changed_color_button),
&color);
G_markers[MARKER_LINE_CHANGED].color = color_to_int (&color);
gtk_color_button_get_color (GTK_COLOR_BUTTON (cw->removed_color_button),
&color);
G_markers[MARKER_LINE_REMOVED].color = color_to_int (&color);

/* update everything */
foreach_document (i) {
release_resources (documents[i]->editor->sci);
}
if (doc) {
update_diff_push (doc, FALSE);
}
}
}
}

GtkWidget *
plugin_configure (GtkDialog *dialog)
{
GError *error = NULL;
GtkWidget *base = NULL;
GtkBuilder *builder = gtk_builder_new ();

gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
if (! gtk_builder_add_from_file (builder, PKGDATADIR"/"PLUGIN"/prefs.ui",
&error)) {
g_critical (_("Failed to load UI definition, please check your "
"installation. The error was: %s"), error->message);
g_error_free (error);
} else {
GdkColor color;
ConfigureWidgets *cw = g_malloc (sizeof *cw);
struct {
const gchar *name;
GtkWidget **ptr;
} map[] = {
{ "base", &cw->base },
{ "added-color-button", &cw->added_color_button },
{ "changed-color-button", &cw->changed_color_button },
{ "removed-color-button", &cw->removed_color_button },
};
guint i;

for (i = 0; i < G_N_ELEMENTS (map); i++) {
*map[i].ptr = GTK_WIDGET (gtk_builder_get_object (builder, map[i].name));
}

color_from_int (&color, G_markers[MARKER_LINE_ADDED].color);
gtk_color_button_set_color (GTK_COLOR_BUTTON (cw->added_color_button),
&color);
color_from_int (&color, G_markers[MARKER_LINE_CHANGED].color);
gtk_color_button_set_color (GTK_COLOR_BUTTON (cw->changed_color_button),
&color);
color_from_int (&color, G_markers[MARKER_LINE_REMOVED].color);
gtk_color_button_set_color (GTK_COLOR_BUTTON (cw->removed_color_button),
&color);

base = g_object_ref_sink (cw->base);

g_signal_connect_data (dialog, "response",
G_CALLBACK (on_plugin_configure_response),
cw, (GClosureNotify) configure_widgets_free, 0);
}

g_object_unref (builder);

return base;
}
1 change: 1 addition & 0 deletions po/POTFILES.in
Expand Up @@ -217,6 +217,7 @@ geanyvc/src/utils.c
geniuspaste/src/geniuspaste.c

# GitUI
[type: gettext/glade]git-ui/data/prefs.ui
git-ui/src/ggu-plugin.c

# Markdown
Expand Down

0 comments on commit 147c188

Please sign in to comment.