Guest User

Untitled

a guest
Jun 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. --- a/menu.lua 2010-10-01 03:52:19.000000000 +0200
  2. +++ b/menu.lua 2010-10-22 17:29:37.136666674 +0200
  3. @@ -11,6 +11,7 @@
  4. local gui = gui
  5. local l = locale
  6. local gtkmenu = gui.gtkmenu
  7. +local context_mbl = {} -- Context menu buffer list
  8.  
  9. local SEPARATOR = 'separator'
  10. local ID = {
  11. @@ -128,6 +129,9 @@
  12. MANUAL = 901,
  13. LUADOC = 902,
  14. ABOUT = 903,
  15. + -- Buffers (context menu) (will be generated dynamically)
  16. + -- The limit of the context menu IDs is 1999
  17. + BUFFER_START = 1000,
  18. }
  19.  
  20.  
  21. @@ -502,6 +506,13 @@
  22. active_table =
  23. { set_lexer, lexer_menu[menu_id - ID.LEXER_START + 1][1] }
  24. end
  25. +
  26. + -- Go to buffer
  27. + if menu_id >= ID.BUFFER_START and menu_id <= ID.BUFFER_START + 999 then
  28. + active_table =
  29. + { 'goto_buffer', v, context_mbl[menu_id][2] - ID.BUFFER_START, true }
  30. + end
  31. +
  32. local f, args
  33. if active_table and #active_table > 0 then
  34. local func = active_table[1]
  35. @@ -525,14 +536,56 @@
  36. end)
  37.  
  38. -- Right-click context menu.
  39. -gui.context_menu = gtkmenu {
  40. - { l.MENU_EDIT_UNDO, ID.UNDO },
  41. - { l.MENU_EDIT_REDO, ID.REDO },
  42. - { SEPARATOR, ID.SEPARATOR },
  43. - { l.MENU_EDIT_CUT, ID.CUT },
  44. - { l.MENU_EDIT_COPY, ID.COPY },
  45. - { l.MENU_EDIT_PASTE, ID.PASTE },
  46. - { l.MENU_EDIT_DELETE, ID.DELETE },
  47. - { SEPARATOR, ID.SEPARATOR },
  48. - { l.MENU_EDIT_SELECT_ALL, ID.SELECT_ALL }
  49. -}
  50. +--gui.context_menu = gtkmenu {
  51. +-- { l.MENU_EDIT_UNDO, ID.UNDO },
  52. +-- { l.MENU_EDIT_REDO, ID.REDO },
  53. +-- { SEPARATOR, ID.SEPARATOR },
  54. +-- { l.MENU_EDIT_CUT, ID.CUT },
  55. +-- { l.MENU_EDIT_COPY, ID.COPY },
  56. +-- { l.MENU_EDIT_PASTE, ID.PASTE },
  57. +-- { l.MENU_EDIT_DELETE, ID.DELETE },
  58. +-- { SEPARATOR, ID.SEPARATOR },
  59. +-- { l.MENU_EDIT_SELECT_ALL, ID.SELECT_ALL }
  60. +--}
  61. +
  62. +-- Create an empty context menu
  63. +gui.context_menu = gtkmenu {}
  64. +
  65. +function create_buffer_list()
  66. + index = 1
  67. + context_mbl = {}
  68. +
  69. + table.foreach(_G._BUFFERS, function(key, buffer)
  70. +
  71. + -- Get a(file)name
  72. + fn = buffer.filename or buffer._type or locale.UNTITLED
  73. +
  74. + -- Check if buffer content is modified
  75. + dirty = buffer.dirty and ' *' or ''
  76. +
  77. + -- Find current buffer
  78. + if gui.focused_doc_pointer == buffer.doc_pointer then
  79. + current = ' (current)'
  80. + else
  81. + current = ''
  82. + end
  83. +
  84. + -- Create menu data
  85. + context_mbl[ID.BUFFER_START + index] = {
  86. + fn:match('[^/\\]+$'):gsub('_', '__') .. current .. dirty,
  87. + ID.BUFFER_START + index
  88. + }
  89. + index = index + 1
  90. + end)
  91. +
  92. + -- Update context menu
  93. + gui.context_menu = gtkmenu(context_mbl)
  94. +end
  95. +
  96. +-- Events that update the context menu
  97. +events.connect('file_opened', create_buffer_list)
  98. +events.connect('buffer_new', create_buffer_list)
  99. +events.connect('buffer_deleted', create_buffer_list)
  100. +events.connect('save_point_left', create_buffer_list)
  101. +events.connect('save_point_reached', create_buffer_list)
  102. +events.connect('buffer_after_switch', create_buffer_list)
Add Comment
Please, Sign In to add comment