Commit 95d5d99c authored by Alberto Fanjul's avatar Alberto Fanjul

Optional argument to parse text

parent 77f771b3
......@@ -18,3 +18,7 @@ A port in vala to https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-24/demos/gtk-dem
meson build
ninja -C build
./build/TextViewHyperLinks
## Arguments
If you want to test different texts, you can pass a `--text` argument.
public class TextViewHyperLinksApp : Gtk.Application {
private static string? text;
private const GLib.OptionEntry[] options = {
{ "text", 0, 0, OptionArg.STRING, ref text, "Provide text to parse for urls", "TEXT" },
{ null }
};
public TextViewHyperLinksApp ()
{
add_main_option_entries (options);
}
protected override void activate () {
new TextViewHyperLinksWindow (this).show_all ();
new TextViewHyperLinksWindow (this, text).show_all ();
}
}
class TextViewHyperLinksWindow: Gtk.ApplicationWindow {
internal TextViewHyperLinksWindow(TextViewHyperLinksApp app) {
internal TextViewHyperLinksWindow(TextViewHyperLinksApp app, string? text) {
Object (application: app, title: "TextView Example");
this.set_default_size (220, 200);
......@@ -20,7 +33,13 @@ class TextViewHyperLinksWindow: Gtk.ApplicationWindow {
textview.set_wrap_mode (Gtk.WrapMode.WORD); //sets line wrapping
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";
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";
}
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");
......
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