Import GeditStatusMenuButton.

This commit is contained in:
Tomasz Gąsior 2018-07-22 16:03:15 +02:00
parent ac9d0a9343
commit fe3fa259fb
5 changed files with 260 additions and 0 deletions

View File

@ -55,6 +55,7 @@ NOINST_H_FILES = \
xed-print-preview.h \
xed-settings.h \
xed-status-combo-box.h \
xed-status-menu-button.h \
xed-tab-label.h \
xed-ui.h \
xed-utils.h \
@ -134,6 +135,7 @@ libxed_c_files = \
xed-searchbar.c \
xed-statusbar.c \
xed-status-combo-box.c \
xed-status-menu-button.c \
xed-tab.c \
xed-tab-label.c \
xed-utils.c \

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.8 -->
<template class="XedStatusMenuButton" parent="GtkMenuButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">False</property>
<property name="is_focus">False</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
<property name="direction">up</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_focus">False</property>
<property name="is_focus">False</property>
<property name="spacing">3</property>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_focus">False</property>
<property name="is_focus">False</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
<property name="label">label</property>
<property name="single_line_mode">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="arrow">
<property name="visible">True</property>
<property name="valign">baseline</property>
<property name="icon_name">pan-down-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>

View File

@ -9,6 +9,7 @@
<file preprocess="xml-stripblanks">ui/xed-highlight-mode-selector.ui</file>
<file preprocess="xml-stripblanks">ui/xed-searchbar.ui</file>
<file preprocess="xml-stripblanks">ui/xed-shortcuts.ui</file>
<file preprocess="xml-stripblanks">ui/xed-status-menu-button.ui</file>
<file preprocess="xml-stripblanks">ui/xed-view-frame.ui</file>
<file>css/xed-style.css</file>
<file>css/xed.adwaita.css</file>

View File

@ -0,0 +1,163 @@
/*
* xed-status-menu-button.c
* This file is part of xed
*
* Copyright (C) 2008 - Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "xed-status-menu-button.h"
struct _XedStatusMenuButton
{
GtkMenuButton parent_instance;
GtkWidget *label;
};
typedef struct
{
GtkCssProvider *css;
} XedStatusMenuButtonClassPrivate;
enum
{
PROP_0,
PROP_LABEL,
LAST_PROP
};
G_DEFINE_TYPE_WITH_CODE (XedStatusMenuButton,
xed_status_menu_button,
GTK_TYPE_MENU_BUTTON,
g_type_add_class_private (g_define_type_id, sizeof (XedStatusMenuButtonClassPrivate)))
static void
xed_status_menu_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
XedStatusMenuButton *obj = XED_STATUS_MENU_BUTTON (object);
switch (prop_id)
{
case PROP_LABEL:
g_value_set_string (value, xed_status_menu_button_get_label (obj));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xed_status_menu_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
XedStatusMenuButton *obj = XED_STATUS_MENU_BUTTON (object);
switch (prop_id)
{
case PROP_LABEL:
xed_status_menu_button_set_label (obj, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xed_status_menu_button_class_init (XedStatusMenuButtonClass *klass)
{
static const gchar style[] =
"* {\n"
"padding: 1px 8px 2px 4px;\n"
"border: 0;\n"
"outline-width: 0;\n"
"}";
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
XedStatusMenuButtonClassPrivate *class_priv;
object_class->get_property = xed_status_menu_button_get_property;
object_class->set_property = xed_status_menu_button_set_property;
g_object_class_override_property (object_class, PROP_LABEL, "label");
/* Bind class to template */
gtk_widget_class_set_template_from_resource (widget_class,
"/org/x/editor/ui/xed-status-menu-button.ui");
gtk_widget_class_bind_template_child_internal (widget_class, XedStatusMenuButton, label);
/* Store the CSS provider in the class private data so it is shared among all instances */
class_priv = G_TYPE_CLASS_GET_PRIVATE (klass, XED_TYPE_STATUS_MENU_BUTTON, XedStatusMenuButtonClassPrivate);
class_priv->css = gtk_css_provider_new ();
gtk_css_provider_load_from_data (class_priv->css, style, -1, NULL);
}
static void
xed_status_menu_button_init (XedStatusMenuButton *self)
{
GtkStyleContext *context;
XedStatusMenuButtonClassPrivate *class_priv;
gtk_widget_init_template (GTK_WIDGET (self));
/* make it as small as possible */
context = gtk_widget_get_style_context (GTK_WIDGET (self));
class_priv = G_TYPE_CLASS_GET_PRIVATE (G_TYPE_INSTANCE_GET_CLASS (self, XED_TYPE_STATUS_MENU_BUTTON, XedStatusMenuButtonClass),
XED_TYPE_STATUS_MENU_BUTTON,
XedStatusMenuButtonClassPrivate);
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (class_priv->css),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
/**
* xed_status_menu_button_new:
* @label: (allow-none):
*/
GtkWidget *
xed_status_menu_button_new (void)
{
return g_object_new (XED_TYPE_STATUS_MENU_BUTTON, NULL);
}
/* we cannot rely on gtk_button_set_label since it manually replaces
* the internal child instead of just setting the property :( */
void
xed_status_menu_button_set_label (XedStatusMenuButton *button,
const gchar *label)
{
g_return_if_fail (XED_IS_STATUS_MENU_BUTTON (button));
gtk_label_set_markup (GTK_LABEL (button->label), label);
}
const gchar *
xed_status_menu_button_get_label (XedStatusMenuButton *button)
{
g_return_val_if_fail (XED_IS_STATUS_MENU_BUTTON (button), NULL);
return gtk_label_get_label (GTK_LABEL (button->label));
}
/* ex:set ts=8 noet: */

View File

@ -0,0 +1,43 @@
/*
* xed-status-menu-button.h
* This file is part of xed
*
* Copyright (C) 2008 - Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XED_STATUS_MENU_BUTTON_H
#define XED_STATUS_MENU_BUTTON_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define XED_TYPE_STATUS_MENU_BUTTON (xed_status_menu_button_get_type ())
G_DECLARE_FINAL_TYPE (XedStatusMenuButton, xed_status_menu_button, XED, STATUS_MENU_BUTTON, GtkMenuButton)
GtkWidget *xed_status_menu_button_new (void);
void xed_status_menu_button_set_label (XedStatusMenuButton *button,
const gchar *label);
const gchar *xed_status_menu_button_get_label (XedStatusMenuButton *button);
G_END_DECLS
#endif /* XED_STATUS_MENU_BUTTON_H */
/* ex:set ts=8 noet: */