|
|
e43452d |
From fb6ffd0ed76b175b4eeb1c73b9fd7a3cbcf6ecbb Mon Sep 17 00:00:00 2001
|
|
|
e43452d |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
e43452d |
Date: Tue, 1 Mar 2011 11:18:13 +0100
|
|
|
f1996ec |
Subject: [PATCH] systemadm: add a wrappable label and use it for status lines
|
|
|
e43452d |
|
|
|
e43452d |
The new WrapLabel is there to work around a deficiency in GTK,
|
|
|
e43452d |
namely the fact that it is hard to make labels which are both
|
|
|
e43452d |
resizable and wrappable. The code is a port from libview.
|
|
|
e43452d |
(cherry picked from commit 0dd27daff4ba4bdad99b12b85b630ab21c84fa9e)
|
|
|
e43452d |
---
|
|
|
e43452d |
Makefile.am | 3 +-
|
|
|
e43452d |
src/systemadm.vala | 7 ++---
|
|
|
e43452d |
src/wraplabel.vala | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
e43452d |
3 files changed, 78 insertions(+), 5 deletions(-)
|
|
|
e43452d |
create mode 100644 src/wraplabel.vala
|
|
|
e43452d |
|
|
|
e43452d |
diff --git a/Makefile.am b/Makefile.am
|
|
|
e43452d |
index 8f1ffdc..54bccb5 100644
|
|
|
e43452d |
--- a/Makefile.am
|
|
|
e43452d |
+++ b/Makefile.am
|
|
|
e43452d |
@@ -1426,7 +1426,8 @@ systemd_stdio_bridge_LDADD = \
|
|
|
e43452d |
|
|
|
e43452d |
systemadm_SOURCES = \
|
|
|
e43452d |
src/systemadm.vala \
|
|
|
e43452d |
- src/systemd-interfaces.vala
|
|
|
e43452d |
+ src/systemd-interfaces.vala \
|
|
|
e43452d |
+ src/wraplabel.vala
|
|
|
e43452d |
|
|
|
e43452d |
systemadm_CFLAGS = \
|
|
|
e43452d |
$(AM_CFLAGS) \
|
|
|
e43452d |
diff --git a/src/systemadm.vala b/src/systemadm.vala
|
|
|
e43452d |
index 6126eca..68652d0 100644
|
|
|
e43452d |
--- a/src/systemadm.vala
|
|
|
e43452d |
+++ b/src/systemadm.vala
|
|
|
e43452d |
@@ -46,12 +46,11 @@ public class LeftLabel : Label {
|
|
|
e43452d |
}
|
|
|
e43452d |
}
|
|
|
e43452d |
|
|
|
e43452d |
-public class RightLabel : Label {
|
|
|
e43452d |
+public class RightLabel : WrapLabel {
|
|
|
e43452d |
+
|
|
|
e43452d |
public RightLabel(string? text = null) {
|
|
|
e43452d |
- set_text_or_na(text);
|
|
|
e43452d |
- set_alignment(0, 0);
|
|
|
e43452d |
- set_ellipsize(EllipsizeMode.START);
|
|
|
e43452d |
set_selectable(true);
|
|
|
e43452d |
+ set_text_or_na(text);
|
|
|
e43452d |
}
|
|
|
e43452d |
|
|
|
e43452d |
public void set_text_or_na(string? text = null) {
|
|
|
e43452d |
diff --git a/src/wraplabel.vala b/src/wraplabel.vala
|
|
|
e43452d |
new file mode 100644
|
|
|
e43452d |
index 0000000..49858c3
|
|
|
e43452d |
--- /dev/null
|
|
|
e43452d |
+++ b/src/wraplabel.vala
|
|
|
e43452d |
@@ -0,0 +1,73 @@
|
|
|
e43452d |
+// Copyright (c) 2005 VMware, Inc.
|
|
|
e43452d |
+
|
|
|
e43452d |
+// This is a translation of http://git.gnome.org/browse/meld/tree/meld/ui/wraplabel.py,
|
|
|
e43452d |
+// which in turn is a translation of WrapLabel from libview.
|
|
|
e43452d |
+
|
|
|
e43452d |
+// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
e43452d |
+// of this software and associated documentation files (the "Software"), to deal
|
|
|
e43452d |
+// in the Software without restriction, including without limitation the rights
|
|
|
e43452d |
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
e43452d |
+// copies of the Software, and to permit persons to whom the Software is
|
|
|
e43452d |
+// furnished to do so, subject to the following conditions:
|
|
|
e43452d |
+//
|
|
|
e43452d |
+// The above copyright notice and this permission notice shall be included in
|
|
|
e43452d |
+// all copies or substantial portions of the Software.
|
|
|
e43452d |
+//
|
|
|
e43452d |
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
e43452d |
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
e43452d |
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
e43452d |
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
e43452d |
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
e43452d |
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
e43452d |
+// SOFTWARE.
|
|
|
e43452d |
+
|
|
|
e43452d |
+// Python translation from wrapLabel.{cc|h} by Gian Mario Tagliaretti
|
|
|
e43452d |
+// Vala translation from wraplabel.py by Zbigniew Jędrzejewski-Szmek
|
|
|
e43452d |
+
|
|
|
e43452d |
+public class WrapLabel : Gtk.Label {
|
|
|
e43452d |
+ private int _wrap_width;
|
|
|
e43452d |
+
|
|
|
e43452d |
+ public WrapLabel(string? text = null) {
|
|
|
e43452d |
+ this._wrap_width = 0;
|
|
|
e43452d |
+ var layout = get_layout();
|
|
|
e43452d |
+ layout.set_wrap(Pango.WrapMode.WORD_CHAR);
|
|
|
e43452d |
+ if (text != null)
|
|
|
e43452d |
+ this.set_text(text);
|
|
|
e43452d |
+ this.set_alignment(0, 0);
|
|
|
e43452d |
+ }
|
|
|
e43452d |
+
|
|
|
e43452d |
+ public override void size_request(out Gtk.Requisition requisition) {
|
|
|
e43452d |
+ int width, height;
|
|
|
e43452d |
+ var layout = get_layout();
|
|
|
e43452d |
+ layout.get_pixel_size(out width, out height);
|
|
|
e43452d |
+ requisition.width = 0;
|
|
|
e43452d |
+ requisition.height = height;
|
|
|
e43452d |
+ }
|
|
|
e43452d |
+
|
|
|
e43452d |
+ public override void size_allocate(Gdk.Rectangle allocation) {
|
|
|
e43452d |
+ base.size_allocate (allocation);
|
|
|
e43452d |
+ this._set_wrap_width(allocation.width);
|
|
|
e43452d |
+ }
|
|
|
e43452d |
+
|
|
|
e43452d |
+ public new void set_text(string str) {
|
|
|
e43452d |
+ base.set_text(str);
|
|
|
e43452d |
+ this._set_wrap_width(this._wrap_width);
|
|
|
e43452d |
+ }
|
|
|
e43452d |
+
|
|
|
e43452d |
+ public new void set_markup(string str) {
|
|
|
e43452d |
+ base.set_markup(str);
|
|
|
e43452d |
+ this._set_wrap_width(this._wrap_width);
|
|
|
e43452d |
+ }
|
|
|
e43452d |
+
|
|
|
e43452d |
+ private void _set_wrap_width(int width) {
|
|
|
e43452d |
+ if (width == 0)
|
|
|
e43452d |
+ return;
|
|
|
e43452d |
+
|
|
|
e43452d |
+ var layout = get_layout();
|
|
|
e43452d |
+ layout.set_width(width * Pango.SCALE);
|
|
|
e43452d |
+ if (_wrap_width != width) {
|
|
|
e43452d |
+ this._wrap_width = width;
|
|
|
e43452d |
+ this.queue_resize();
|
|
|
e43452d |
+ }
|
|
|
e43452d |
+ }
|
|
|
e43452d |
+}
|
|
|
e43452d |
--
|
|
|
e43452d |
1.7.7.5
|
|
|
e43452d |
|