demo-links.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. return function(parent, dir)
  2. local lgi = require 'lgi'
  3. local Gtk = lgi.Gtk
  4. local window = Gtk.Window {
  5. title = 'Links',
  6. border_width = 12,
  7. Gtk.Label {
  8. id = 'label',
  9. label = [[Some <a href="http://en.wikipedia.org/wiki/Text"title="plain text">text</a> may be marked up
  10. as hyperlinks, which can be clicked
  11. or activated via <a href="keynav">keynav</a>]],
  12. use_markup = true,
  13. },
  14. }
  15. function window.child.label:on_activate_link(uri)
  16. if uri == 'keynav' then
  17. local dialog = Gtk.MessageDialog {
  18. transient_for = self:get_toplevel(),
  19. destroy_with_parent = true,
  20. message_type = 'INFO',
  21. buttons = 'OK',
  22. use_markup = true,
  23. text = [[The term <i>keynav</i> is a shorthand for ]]
  24. .. [[keyboard navigation and refers to the process of using ]]
  25. .. [[a program (exclusively) via keyboard input.]],
  26. on_response = Gtk.Widget.destroy,
  27. }
  28. dialog:present()
  29. return true
  30. else
  31. return false
  32. end
  33. end
  34. window:show_all()
  35. return window
  36. end,
  37. "Links",
  38. table.concat {
  39. [[Gtk.Label can show hyperlinks. The default action is to call ]],
  40. [[Gtk.show_uri() on their URI, but it is possible to override ]],
  41. [[this with a custom handler.]],
  42. }