Commit 2ea23c0c authored by Alberto Fanjul's avatar Alberto Fanjul

Custom links

parent 95d5d99c
......@@ -19,6 +19,6 @@ A port in vala to https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-24/demos/gtk-dem
ninja -C build
./build/TextViewHyperLinks
## Arguments
## Example
If you want to test different texts, you can pass a `--text` argument.
./TextViewHyperLinks --custom-link '!([0-9]+),https://gitlab.gnome.org/GNOME/gitg/merge_requests/\\1,orange' --custom-link '#([0-9]+),https://gitlab.gnome.org/GNOME/gitg/issues/\\1,green' --text "this is a text with an url https://gitlab.gnome.org/GNOME/gitg/issues/152 and a hidden link #152 and hidden MR !21 and documentation http://example.com/doc?param=1&chapter=4 for sure'
public class TextViewHyperLinksApp : Gtk.Application {
private static string? text;
private static string? text = null;
[CCode (array_length = false, array_null_terminated = true)]
private static string[]? custom_links = null;
private const GLib.OptionEntry[] options = {
{ "text", 0, 0, OptionArg.STRING, ref text, "Provide text to parse for urls", "TEXT" },
{ "custom-link", 0, 0, OptionArg.STRING_ARRAY, ref custom_links, "Provide pattern to transform custom links", "REGEX,REPLACEMENT,COLOR" },
{ null }
};
......@@ -12,13 +15,13 @@ public class TextViewHyperLinksApp : Gtk.Application {
}
protected override void activate () {
new TextViewHyperLinksWindow (this, text).show_all ();
new TextViewHyperLinksWindow (this, text, custom_links).show_all ();
}
}
class TextViewHyperLinksWindow: Gtk.ApplicationWindow {
internal TextViewHyperLinksWindow(TextViewHyperLinksApp app, string? text) {
internal TextViewHyperLinksWindow(TextViewHyperLinksApp app, string? text, string[]? custom_links) {
Object (application: app, title: "TextView Example");
this.set_default_size (220, 200);
......@@ -33,17 +36,18 @@ class TextViewHyperLinksWindow: Gtk.ApplicationWindow {
textview.set_wrap_mode (Gtk.WrapMode.WORD); //sets line wrapping
if (text != null)
if (text == null)
{
message("not is null");
buffer.text = text;
} else {
buffer.text = "this is a text with an url https://gitlab.gnome.org/GNOME/gitg/issues/152 and a hidden link #152 and hidden MR !21 and documentation http://example.com/doc?param=1&chapter=4 for sure";
text = "";
}
buffer.text = text;
apply_link_tags(buffer, "https?://[a-zA-Z/&#.0-9=?]+", null, "blue");
apply_link_tags(buffer, "#([0-9]+)", "https://gitlab.gnome.org/GNOME/gitg/issues/\\1", "green");
apply_link_tags(buffer, "!([0-9]+)", "https://gitlab.gnome.org/GNOME/gitg/merge_requests/\\1", "orange");
foreach (string custom_link in custom_links)
{
string[] params = custom_link.split(",");
apply_link_tags(buffer, params[0], params[1], params[2]);
}
var scrolled_window = new Gtk.ScrolledWindow (null, null);
scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment