Commits

Ikey Doherty committed a9cdc89

Per link handling, only use LMB

Comments (0)

Files changed (1)

src/pages/summary/summary.vala

 		textview.get_iter_at_location (out tmp, x, y);
 		var tags = tmp.get_tags ();
 		foreach (unowned Gtk.TextTag tag in tags) {
-			if (tag.name == "hyperlink") {
+			if (tag.name.has_prefix("hyperlink://")) {
 				unowned Gdk.Window win = textview.get_window (Gtk.TextWindowType.TEXT);
 				win.set_cursor (new Gdk.Cursor (Gdk.CursorType.HAND2));
 				return false;
 	// bulletpoint
 	bullet = new Gdk.Pixbuf.from_file ("%s/bullet-point.png".printf(RESOURCE_DIR));
 
-
-	// TextTag for a hyperlink
-	var HyperLink = new Gtk.TextTag("hyperlink");
-	HyperLink.event.connect ( (o,e,i) => {
-		if (e.type == Gdk.EventType.BUTTON_PRESS) {
-			message ("Hyperlinky");
-		}
-		return false;
-	} );
-	HyperLink.foreground = "#0000FF";
-	HyperLink.size_points = 16;
-	HyperLink.indent = 3;
-	HyperLink.underline = Pango.Underline.SINGLE;
-	tags.add(HyperLink);
-
 	var BulletPoint = new Gtk.TextTag("bulletpoint");
 	tags.add(BulletPoint);
 
 	// Demo stuffs
 	buffer.get_start_iter(out iter);
 
-	add_header ("Sample Header");
+	add_header ("Sample Header", 0);
 	add_bullet ("Sample item #1");
 	add_bullet ("Sample item #2");
 	add_bullet ("Sample item #3");
 
-	add_header ("Sample Header #2", true);
+	add_header ("Sample Header #2", 1, true);
 
 	textview.set_buffer (buffer);
    }
    /**
     * Add a header to the buffer 
     */
-   private void add_header (string header, bool space = false) {
+   private void add_header (string header, int index, bool space = false) {
 	if (space) {
 		var spacing = "\n";
 		buffer.insert (iter, spacing, (int)spacing.length);
 	}
-	buffer.insert_with_tags_by_name (iter, header, (int)header.length, "hyperlink");
+
+	var HyperLink = buffer.create_tag("hyperlink://%d".printf(index));
+	HyperLink.event.connect ( (o,e,i) => {
+		if (e.type == Gdk.EventType.BUTTON_PRESS) {
+			if (e.button.button != 1) return false;
+			message (header);
+		}
+		return false;
+	} );
+	HyperLink.foreground = "#0000FF";
+	HyperLink.size_points = 16;
+	HyperLink.indent = 3;
+	HyperLink.underline = Pango.Underline.SINGLE;
+
+	buffer.insert_with_tags (iter, header, (int)header.length, HyperLink);
 
 	// Add two new blank lines
 	var lines = "\n\n";