aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/interface-gtk
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2016-02-07 08:15:54 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2016-02-07 08:15:54 +0100
commitb21d294b8168e20282f31026cbc2e50a3bcd0222 (patch)
tree39c44091e03c6108f7790d06341ede6c9c1ec930 /src/interface-gtk
parentdadb20b9ba159043a892ac7050695a8a1fb04e3b (diff)
downloadsciteco-b21d294b8168e20282f31026cbc2e50a3bcd0222.tar.gz
Gtk UI: use GtkCanonicalizedLabels and many styling improvements
* the canonicalized labels are used in title bars and popups * title labels and popup labels are selectable. The latter only makes sense as long as there is no mouse support for selecting popup entries. * message bar labels are selectable * title bars can be styled according to the current document type (.info-qregister and .info-buffer classes) * .dirty has been introduced for dirty buffers. This way, dirty buffer file names can be printed in italics without hardcoding that behaviour. It can be customized in the user CSS. * The style of highlighted popup entries is now themeable as well using the .highlight style class.
Diffstat (limited to 'src/interface-gtk')
-rw-r--r--src/interface-gtk/fallback.css65
-rw-r--r--src/interface-gtk/gtk-info-popup.gob33
-rw-r--r--src/interface-gtk/interface-gtk.cpp58
-rw-r--r--src/interface-gtk/interface-gtk.h5
4 files changed, 127 insertions, 34 deletions
diff --git a/src/interface-gtk/fallback.css b/src/interface-gtk/fallback.css
index 1be431b..c8f5431 100644
--- a/src/interface-gtk/fallback.css
+++ b/src/interface-gtk/fallback.css
@@ -8,28 +8,62 @@
* to fix it up or add other style customizations.
*/
-.titlebar, /* info bar in CSD mode */
-#sciteco-info-bar,
-#sciteco-info-bar GtkLabel {
- color: @sciteco_default_bg_color;
- text-shadow: none;
+/*
+ * The info or title bar (#sciteco-info-bar).
+ * The following classes are defined:
+ * - info-qregister: The title bar if a QRegister is edited
+ * - info-buffer: The title bar if a buffer is edited
+ * - dirty: The title bar for dirty buffers
+ * - type-label: The label showing the current document type
+ * - name-label: THe label showing the current document name
+ */
+.info-qregister,
+.info-buffer {
background-color: @sciteco_default_fg_color;
background-image: none;
}
+.info-qregister GtkLabel,
+.info-buffer GtkLabel {
+ color: @sciteco_default_bg_color;
+ text-shadow: none;
+}
+
+.type-label {
+ font-variant: small-caps;
+ font-weight: 300; /* light */
+}
+
+.info-buffer.dirty .name-label {
+ font-style: italic;
+}
+
+/*
+ * Scintilla views
+ */
+ScintillaObject {}
+
/*
+ * The message bar (#sciteco-message-bar).
+ *
* The "question" class refers to G_MESSAGE_QUESTION.
* This is used for showing user-level messages for the sole
* reason that there is no class for G_MESSAGE_OTHER that
* we could use for styling.
*/
#sciteco-message-bar.question {
- color: @sciteco_default_bg_color;
- text-shadow: none;
background-color: @sciteco_default_fg_color;
background-image: none;
}
+#sciteco-message-bar.question GtkLabel {
+ color: @sciteco_default_bg_color;
+ text-shadow: none;
+}
+
+/*
+ * The command line area (#sciteco-cmdline)
+ */
#sciteco-cmdline {
color: @sciteco_default_fg_color;
text-shadow: none;
@@ -37,10 +71,21 @@
background-image: none;
}
-#sciteco-info-popup,
+/*
+ * The autocompletion popup (#sciteco-info-popup).
+ * The following classes are defined:
+ * - highlight: A highlighted popup entry
+ */
+#sciteco-info-popup {
+ background-color: @sciteco_calltip_bg_color;
+ background-image: none;
+}
+
#sciteco-info-popup GtkLabel {
color: @sciteco_calltip_fg_color;
text-shadow: none;
- background-color: @sciteco_calltip_bg_color;
- background-image: none;
+}
+
+#sciteco-info-popup .highlight GtkLabel {
+ font-weight: bold;
}
diff --git a/src/interface-gtk/gtk-info-popup.gob b/src/interface-gtk/gtk-info-popup.gob
index 6cb1b81..aae8b68 100644
--- a/src/interface-gtk/gtk-info-popup.gob
+++ b/src/interface-gtk/gtk-info-popup.gob
@@ -29,6 +29,8 @@ requires 2.0.20
#ifndef HAVE_GTK_FLOW_BOX_NEW
#include "gtkflowbox.h"
#endif
+
+#include "gtk-canonicalized-label.h"
%}
%h{
@@ -231,9 +233,11 @@ class Gtk:Info:Popup from Gtk:Event:Box {
{
GtkWidget *hbox;
GtkWidget *label;
- gchar *markup;
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
+ if (highlight)
+ gtk_style_context_add_class(gtk_widget_get_style_context(hbox),
+ "highlight");
if (type == GTK_INFO_POPUP_FILE || type == GTK_INFO_POPUP_DIRECTORY) {
const gchar *fallback = type == GTK_INFO_POPUP_FILE ? "text-x-generic"
@@ -251,17 +255,26 @@ class Gtk:Info:Popup from Gtk:Event:Box {
}
}
+ label = gtk_canonicalized_label_new(name);
+ gtk_widget_set_halign(label, GTK_ALIGN_START);
+ gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
+
/*
- * FIXME: setting Pango attributes directly would be
- * much more efficient
+ * FIXME: This makes little sense once we've got mouse support.
+ * But for the time being, it's a useful setting.
*/
- label = gtk_label_new(NULL);
- markup = g_markup_printf_escaped("<span weight=\"%s\">%s</span>",
- highlight ? "bold" : "normal",
- name);
- gtk_label_set_markup(GTK_LABEL(label), markup);
- g_free(markup);
- gtk_misc_set_alignment(GTK_MISC(label), 0., 0.5);
+ gtk_label_set_selectable(GTK_LABEL(label), TRUE);
+
+ switch (type) {
+ case GTK_INFO_POPUP_PLAIN:
+ gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_START);
+ break;
+ case GTK_INFO_POPUP_FILE:
+ case GTK_INFO_POPUP_DIRECTORY:
+ gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_MIDDLE);
+ break;
+ }
+
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
gtk_widget_show_all(hbox);
diff --git a/src/interface-gtk/interface-gtk.cpp b/src/interface-gtk/interface-gtk.cpp
index ae63e1b..49c3154 100644
--- a/src/interface-gtk/interface-gtk.cpp
+++ b/src/interface-gtk/interface-gtk.cpp
@@ -47,6 +47,7 @@
#include <ScintillaWidget.h>
#include "gtk-info-popup.h"
+#include "gtk-canonicalized-label.h"
#include "sciteco.h"
#include "string-utils.h"
@@ -230,12 +231,25 @@ InterfaceGtk::main_impl(int &argc, char **&argv)
* NOTE: Client-side decoations could fail, leaving us with a
* standard title bar and the info bar with close buttons.
* Other window managers have undesirable side-effects.
- * FIXME: At lease on Gtk 3.12 we could disable the subtitle.
*/
info_bar_widget = gtk_header_bar_new();
gtk_widget_set_name(info_bar_widget, "sciteco-info-bar");
+ info_name_widget = gtk_canonicalized_label_new(NULL);
+ gtk_widget_set_valign(info_name_widget, GTK_ALIGN_CENTER);
+ gtk_style_context_add_class(gtk_widget_get_style_context(info_name_widget),
+ "name-label");
+ gtk_label_set_selectable(GTK_LABEL(info_name_widget), TRUE);
+ /* NOTE: Header bar does not resize for multi-line labels */
+ //gtk_label_set_line_wrap(GTK_LABEL(info_name_widget), TRUE);
+ //gtk_label_set_lines(GTK_LABEL(info_name_widget), 2);
+ gtk_header_bar_set_custom_title(GTK_HEADER_BAR(info_bar_widget), info_name_widget);
info_image = gtk_image_new();
gtk_header_bar_pack_start(GTK_HEADER_BAR(info_bar_widget), info_image);
+ info_type_widget = gtk_label_new(NULL);
+ gtk_widget_set_valign(info_type_widget, GTK_ALIGN_CENTER);
+ gtk_style_context_add_class(gtk_widget_get_style_context(info_type_widget),
+ "type-label");
+ gtk_header_bar_pack_start(GTK_HEADER_BAR(info_bar_widget), info_type_widget);
if (use_csd) {
/* use client-side decorations */
gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(info_bar_widget), TRUE);
@@ -269,8 +283,10 @@ InterfaceGtk::main_impl(int &argc, char **&argv)
message_bar_widget = gtk_info_bar_new();
gtk_widget_set_name(message_bar_widget, "sciteco-message-bar");
message_bar_content = gtk_info_bar_get_content_area(GTK_INFO_BAR(message_bar_widget));
- message_widget = gtk_label_new("");
- gtk_misc_set_alignment(GTK_MISC(message_widget), 0., 0.);
+ /* NOTE: Messages are always pre-canonicalized */
+ message_widget = gtk_label_new(NULL);
+ gtk_label_set_selectable(GTK_LABEL(message_widget), TRUE);
+ gtk_label_set_line_wrap(GTK_LABEL(message_widget), TRUE);
gtk_container_add(GTK_CONTAINER(message_bar_content), message_widget);
gtk_box_pack_start(GTK_BOX(overlay_vbox), message_bar_widget,
FALSE, FALSE, 0);
@@ -364,31 +380,47 @@ InterfaceGtk::show_view_impl(ViewGtk *view)
void
InterfaceGtk::refresh_info(void)
{
+ GtkStyleContext *style = gtk_widget_get_style_context(info_bar_widget);
const gchar *info_type_str;
- gchar *info_current_canon = String::canonicalize_ctl(info_current);
+ gchar *info_current_temp = g_strdup(info_current);
+ gchar *info_current_canon;
GIcon *icon;
gchar *title;
+ gtk_style_context_remove_class(style, "info-qregister");
+ gtk_style_context_remove_class(style, "info-buffer");
+ gtk_style_context_remove_class(style, "dirty");
+
+ if (info_type == INFO_TYPE_BUFFER_DIRTY)
+ String::append(info_current_temp, "*");
+ gtk_canonicalized_label_set_text(GTK_CANONICALIZED_LABEL(info_name_widget),
+ info_current_temp);
+ info_current_canon = String::canonicalize_ctl(info_current_temp);
+ g_free(info_current_temp);
+
switch (info_type) {
case INFO_TYPE_QREGISTER:
+ gtk_style_context_add_class(style, "info-qregister");
+
info_type_str = PACKAGE_NAME " - <QRegister> ";
- gtk_header_bar_set_title(GTK_HEADER_BAR(info_bar_widget),
- info_current_canon);
- gtk_header_bar_set_subtitle(GTK_HEADER_BAR(info_bar_widget),
- "QRegister");
+ gtk_label_set_text(GTK_LABEL(info_type_widget), "QRegister");
+ gtk_label_set_ellipsize(GTK_LABEL(info_name_widget),
+ PANGO_ELLIPSIZE_START);
+ /* FIXME: Use a Q-Register icon */
gtk_image_clear(GTK_IMAGE(info_image));
break;
case INFO_TYPE_BUFFER_DIRTY:
- String::append(info_current_canon, "*");
+ gtk_style_context_add_class(style, "dirty");
/* fall through */
case INFO_TYPE_BUFFER:
+ gtk_style_context_add_class(style, "info-buffer");
+
info_type_str = PACKAGE_NAME " - <Buffer> ";
- gtk_header_bar_set_title(GTK_HEADER_BAR(info_bar_widget),
- info_current_canon);
- gtk_header_bar_set_subtitle(GTK_HEADER_BAR(info_bar_widget),
- "Buffer");
+ gtk_label_set_text(GTK_LABEL(info_type_widget), "Buffer");
+ gtk_label_set_ellipsize(GTK_LABEL(info_name_widget),
+ PANGO_ELLIPSIZE_MIDDLE);
icon = gtk_info_popup_get_icon_for_path(info_current,
"text-x-generic");
diff --git a/src/interface-gtk/interface-gtk.h b/src/interface-gtk/interface-gtk.h
index 8bd189d..80692f9 100644
--- a/src/interface-gtk/interface-gtk.h
+++ b/src/interface-gtk/interface-gtk.h
@@ -79,6 +79,8 @@ typedef class InterfaceGtk : public Interface<InterfaceGtk, ViewGtk> {
gboolean use_csd;
GtkWidget *info_bar_widget;
GtkWidget *info_image;
+ GtkWidget *info_type_widget;
+ GtkWidget *info_name_widget;
GtkWidget *event_box_widget;
@@ -98,7 +100,8 @@ public:
window(NULL),
info_type(INFO_TYPE_BUFFER), info_current(NULL),
use_csd(TRUE),
- info_bar_widget(NULL), info_image(NULL),
+ info_bar_widget(NULL),
+ info_image(NULL), info_type_widget(NULL), info_name_widget(NULL),
event_box_widget(NULL),
message_bar_widget(NULL), message_widget(NULL),
cmdline_widget(NULL),