[latexila/gnome-3] Document Tab: smaller close button
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/gnome-3] Document Tab: smaller close button
- Date: Sun, 4 Mar 2012 22:37:32 +0000 (UTC)
commit e7d336e51da7b0c343c81e2cf949dbbf66208696
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Sun Mar 4 23:35:10 2012 +0100
Document Tab: smaller close button
The close button comes from gedit. It was quite easy to integrate the C
code, say to CMake to compile it, and use it in Vala.
CMakeLists.txt | 2 +-
src/CMakeLists.txt | 3 +-
src/document_tab.vala | 7 +--
src/gedit/gedit-close-button.c | 82 ++++++++++++++++++++++++++++++++++++++++
src/gedit/gedit-close-button.h | 60 +++++++++++++++++++++++++++++
src/latexila.vala | 13 ------
vapi/gedit.vapi | 8 ++++
7 files changed, 155 insertions(+), 20 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ff06c6..41d9bdd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -97,7 +97,7 @@ add_subdirectory (man)
add_subdirectory (po)
add_subdirectory (src/ui)
-include_directories (vapi src/C ${latexila_BINARY_DIR}/src)
+include_directories (vapi src/C ${latexila_BINARY_DIR}/src src/gedit)
if (BUILD_VALA)
add_subdirectory (src)
else ()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c61a5e1..3ee156c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,6 @@
file (GLOB vala_sources RELATIVE "${latexila_SOURCE_DIR}/src/" "*.vala")
file (GLOB vapi_files "${latexila_SOURCE_DIR}/vapi/*.vapi")
+file (GLOB gedit_files "${latexila_SOURCE_DIR}/src/gedit/*")
vala_precompile (
VALA_C
@@ -19,5 +20,5 @@ vala_precompile (
"C"
)
-add_executable (latexila ${VALA_C})
+add_executable (latexila ${VALA_C} ${gedit_files})
install (TARGETS latexila DESTINATION "bin")
diff --git a/src/document_tab.vala b/src/document_tab.vala
index 1adfe88..0b0b501 100644
--- a/src/document_tab.vala
+++ b/src/document_tab.vala
@@ -169,12 +169,9 @@ public class DocumentTab : Grid
update_label_text ();
- Button close_button = new Button ();
- close_button.relief = ReliefStyle.NONE;
- close_button.focus_on_click = false;
- close_button.name = "my-close-button";
+ Gedit.CloseButton close_button = new Gedit.CloseButton ();
+ close_button.set_margin_left (2);
close_button.tooltip_text = _("Close document");
- close_button.add (new Image.from_stock (Stock.CLOSE, IconSize.MENU));
close_button.clicked.connect (() => this.close_document ());
_label = new Grid ();
diff --git a/src/gedit/gedit-close-button.c b/src/gedit/gedit-close-button.c
new file mode 100644
index 0000000..f99861c
--- /dev/null
+++ b/src/gedit/gedit-close-button.c
@@ -0,0 +1,82 @@
+/*
+ * gedit-close-button.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Paolo Borelli
+ * Copyright (C) 2011 - Ignacio Casal Quinteiro
+ *
+ * gedit is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gedit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "gedit-close-button.h"
+
+struct _GeditCloseButtonClassPrivate
+{
+ GtkCssProvider *css;
+};
+
+G_DEFINE_TYPE_WITH_CODE (GeditCloseButton, gedit_close_button, GTK_TYPE_BUTTON,
+ g_type_add_class_private (g_define_type_id, sizeof (GeditCloseButtonClassPrivate)))
+
+static void
+gedit_close_button_class_init (GeditCloseButtonClass *klass)
+{
+ static const gchar button_style[] =
+ "* {\n"
+ "-GtkButton-default-border : 0;\n"
+ "-GtkButton-default-outside-border : 0;\n"
+ "-GtkButton-inner-border: 0;\n"
+ "-GtkWidget-focus-line-width : 0;\n"
+ "-GtkWidget-focus-padding : 0;\n"
+ "padding: 0;\n"
+ "}";
+
+ klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButtonClassPrivate);
+
+ klass->priv->css = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (klass->priv->css, button_style, -1, NULL);
+}
+
+static void
+gedit_close_button_init (GeditCloseButton *button)
+{
+ GtkStyleContext *context;
+ GtkWidget *image;
+ GIcon *icon;
+
+ icon = g_themed_icon_new_with_default_fallbacks ("window-close-symbolic");
+ image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
+ gtk_widget_show (image);
+ g_object_unref (icon);
+
+ gtk_container_add (GTK_CONTAINER (button), image);
+
+ /* make it small */
+ context = gtk_widget_get_style_context (GTK_WIDGET (button));
+ gtk_style_context_add_provider (context,
+ GTK_STYLE_PROVIDER (GEDIT_CLOSE_BUTTON_GET_CLASS (button)->priv->css),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
+GtkWidget *
+gedit_close_button_new ()
+{
+ return GTK_WIDGET (g_object_new (GEDIT_TYPE_CLOSE_BUTTON,
+ "relief", GTK_RELIEF_NONE,
+ "focus-on-click", FALSE,
+ NULL));
+}
+
+/* ex:set ts=8 noet: */
diff --git a/src/gedit/gedit-close-button.h b/src/gedit/gedit-close-button.h
new file mode 100644
index 0000000..791a730
--- /dev/null
+++ b/src/gedit/gedit-close-button.h
@@ -0,0 +1,60 @@
+/*
+ * gedit-close-button.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Paolo Borelli
+ *
+ * gedit is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gedit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __GEDIT_CLOSE_BUTTON_H__
+#define __GEDIT_CLOSE_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_CLOSE_BUTTON (gedit_close_button_get_type ())
+#define GEDIT_CLOSE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButton))
+#define GEDIT_CLOSE_BUTTON_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButton const))
+#define GEDIT_CLOSE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButtonClass))
+#define GEDIT_IS_CLOSE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_CLOSE_BUTTON))
+#define GEDIT_IS_CLOSE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_CLOSE_BUTTON))
+#define GEDIT_CLOSE_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButtonClass))
+
+typedef struct _GeditCloseButton GeditCloseButton;
+typedef struct _GeditCloseButtonClass GeditCloseButtonClass;
+typedef struct _GeditCloseButtonClassPrivate GeditCloseButtonClassPrivate;
+
+struct _GeditCloseButton
+{
+ GtkButton parent;
+};
+
+struct _GeditCloseButtonClass
+{
+ GtkButtonClass parent_class;
+
+ GeditCloseButtonClassPrivate *priv;
+};
+
+GType gedit_close_button_get_type (void) G_GNUC_CONST;
+
+GtkWidget *gedit_close_button_new (void);
+
+G_END_DECLS
+
+#endif /* __GEDIT_CLOSE_BUTTON_H__ */
+/* ex:set ts=8 noet: */
diff --git a/src/latexila.vala b/src/latexila.vala
index 79400b2..1d0f1d4 100644
--- a/src/latexila.vala
+++ b/src/latexila.vala
@@ -130,19 +130,6 @@ public class Latexila : GLib.Object
{
windows = new List<MainWindow> ();
- /* personal style */
- // make the close buttons in tabs smaller
- Gtk.rc_parse_string ("""
- style "my-button-style"
- {
- GtkWidget::focus-padding = 0
- GtkWidget::focus-line-width = 0
- xthickness = 0
- ythickness = 0
- }
- widget "*.my-close-button" style "my-button-style"
- """);
-
/* application icons */
string[] filenames =
{
diff --git a/vapi/gedit.vapi b/vapi/gedit.vapi
new file mode 100644
index 0000000..1f50081
--- /dev/null
+++ b/vapi/gedit.vapi
@@ -0,0 +1,8 @@
+namespace Gedit
+{
+ [CCode (cheader_filename = "gedit-close-button.h")]
+ public class CloseButton : Gtk.Button
+ {
+ public CloseButton ();
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]