[chronojump] Autodetect devices cuts verylong device code with elipsis on the middle
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Autodetect devices cuts verylong device code with elipsis on the middle
- Date: Tue, 11 Oct 2022 15:33:33 +0000 (UTC)
commit c905249249404ff640b0b530c38c04fc2f7d4e16
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Oct 11 17:32:12 2022 +0200
Autodetect devices cuts verylong device code with elipsis on the middle
src/gui/chronopicRegister.cs | 3 ++-
src/util.cs | 11 +++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
---
diff --git a/src/gui/chronopicRegister.cs b/src/gui/chronopicRegister.cs
index a01de08f6..a1f42369c 100644
--- a/src/gui/chronopicRegister.cs
+++ b/src/gui/chronopicRegister.cs
@@ -258,7 +258,8 @@ public class DiscoverWindow
if (portNameShort.StartsWith ("/dev/"))
portNameShort = portNameShort.Replace ("/dev/", "");
- Gtk.Label l = new Gtk.Label (string.Format("{0}\n{1}", portNameShort, crp.SerialNumber));
+ Gtk.Label l = new Gtk.Label (string.Format("{0}\n{1}",
+ portNameShort, Util.RemoveCenterCharsOnLongString (crp.SerialNumber,
12)));
table_micro_discover.Attach (l, (uint) 0, (uint) 1, (uint) i, (uint) i+1, //left, right, top,
bottom
AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
diff --git a/src/util.cs b/src/util.cs
index 56517ca27..e6ea00e01 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -545,6 +545,17 @@ public class Util
return myStringBuilder.ToString();
}
+ public static string RemoveCenterCharsOnLongString (string str, int maxLength)
+ {
+ if (str.Length > maxLength)
+ {
+ int charsAtSide = Convert.ToInt32 (Math.Floor (maxLength / 2.0));
+ return (
+ str.Substring (0, charsAtSide) + "…" +
+ str.Substring (str.Length -charsAtSide, charsAtSide) );
+ }
+ return str;
+ }
//old code sends and returns strings
public static string GetHeightInCentimeters (string time) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]