diff options
Diffstat (limited to 'core/ext')
-rw-r--r-- | core/ext/find.lua | 15 | ||||
-rw-r--r-- | core/ext/keys.lua | 7 | ||||
-rw-r--r-- | core/ext/menu.lua | 711 | ||||
-rw-r--r-- | core/ext/pm.lua | 5 | ||||
-rw-r--r-- | core/ext/pm/buffer_browser.lua | 26 | ||||
-rw-r--r-- | core/ext/pm/ctags_browser.lua | 12 | ||||
-rw-r--r-- | core/ext/pm/file_browser.lua | 33 | ||||
-rw-r--r-- | core/ext/pm/find_browser.lua | 2 | ||||
-rw-r--r-- | core/ext/pm/macro_browser.lua | 9 | ||||
-rw-r--r-- | core/ext/pm/modules_browser.lua | 49 | ||||
-rw-r--r-- | core/ext/pm/project_browser.lua | 115 |
11 files changed, 624 insertions, 360 deletions
diff --git a/core/ext/find.lua b/core/ext/find.lua index ca3c28f0..94371689 100644 --- a/core/ext/find.lua +++ b/core/ext/find.lua @@ -25,7 +25,7 @@ local escapes = { -- for displaying useful statusbar information. This flag is used and set -- internally, and should not be set otherwise. function find.find(text, next, flags, nowrap, wrapped) - local buffer = buffer + local buffer, textadept = buffer, textadept local increment, result text = text:gsub('\\[abfnrtv\\]', escapes) find.captures = nil @@ -68,10 +68,10 @@ function find.find(text, next, flags, nowrap, wrapped) else buffer:goto_pos(buffer.length) end - textadept.statusbar_text = 'Search wrapped' + textadept.statusbar_text = textadept.locale.FIND_SEARCH_WRAPPED result = find.find(text, next, flags, true, true) if not result then - textadept.statusbar_text = 'No results found' + textadept.statusbar_text = textadept.locale.FIND_NO_RESULTS buffer:goto_pos(anchor) end return result @@ -103,11 +103,12 @@ function find.replace(rtext) end local ret, rtext = pcall( rtext.gsub, rtext, '%%(%b())', function(code) + local locale = textadept.locale local ret, val = pcall( loadstring('return '..code) ) if not ret then cocoa_dialog( 'msgbox', { - title = 'Error', - text = 'An error occured:', + title = locale.FIND_ERROR_DIALOG_TITLE, + text = locale.FIND_ERROR_DIALOG_TEXT, ['informative-text'] = val:gsub('"', '\\"') } ) error() @@ -134,11 +135,13 @@ end -- @param flags The number mask identical to the one in 'find'. -- @see find.find function find.replace_all(ftext, rtext, flags) + local textadept = textadept buffer:goto_pos(0) local count = 0 while( find.find(ftext, true, flags, true) ) do find.replace(rtext) count = count + 1 end - textadept.statusbar_text = tostring(count)..' replacement(s) made' + textadept.statusbar_text = tostring(count)..' '.. + textadept.locale.FIND_REPLACEMENTS_MADE end diff --git a/core/ext/keys.lua b/core/ext/keys.lua index fd460233..b9c17ab3 100644 --- a/core/ext/keys.lua +++ b/core/ext/keys.lua @@ -183,7 +183,7 @@ local function keypress(code, shift, control, alt) local size = #keychain - 1 clear_key_sequence() if size > 0 then -- previously in a chain - textadept.statusbar_text = 'Invalid Sequence' + textadept.statusbar_text = textadept.locale.KEYS_INVALID return true end else return true end @@ -217,9 +217,10 @@ end -- of -1. This way, pcall will return false and -1, where the -1 can easily and -- efficiently be checked rather than using a string error message. try_get_cmd = function(active_table) + local locale = textadept.locale for _, key_seq in ipairs(keychain) do active_table = active_table[key_seq] end if #active_table == 0 and next(active_table) then - textadept.statusbar_text = 'Keychain: '..table.concat(keychain, ' ') + textadept.statusbar_text = locale.KEYCHAIN..table.concat(keychain, ' ') error(-1, 0) else local func = active_table[1] @@ -233,7 +234,7 @@ try_get_cmd = function(active_table) return view[func], { view, unpack(active_table, 3) } end else - error( 'Unknown command: '..tostring(func) ) + error( locale.KEYS_UNKNOWN_COMMAND..tostring(func) ) end end end diff --git a/core/ext/menu.lua b/core/ext/menu.lua index 2fecc91e..db089ed0 100644 --- a/core/ext/menu.lua +++ b/core/ext/menu.lua @@ -5,165 +5,396 @@ -- This module, like ext/key_commands, should be 'require'ed last. module('textadept.menu', package.seeall) -local t, gtkmenu = textadept, textadept.gtkmenu +local t, gtkmenu, l = textadept, textadept.gtkmenu, textadept.locale + +local SEPARATOR = 'separator' +local ID = { + SEPARATOR = 0, + -- File + NEW = 101, + OPEN = 102, + RELOAD = 103, + SAVE = 104, + SAVEAS = 105, + CLOSE = 106, + CLOSE_ALL = 107, + LOAD_SESSION = 108, + SAVE_SESSION = 109, + QUIT = 110, + -- Edit + UNDO = 201, + REDO = 202, + CUT = 203, + COPY = 204, + PASTE = 205, + DELETE = 206, + SELECT_ALL = 207, + MATCH_BRACE = 208, + SELECT_TO_BRACE = 209, + COMPLETE_WORD = 210, + DELETE_WORD = 211, + TRANSPOSE_CHARACTERS = 212, + SQUEEZE = 213, + JOIN_LINES = 245, + MOVE_LINE_UP = 214, + MOVE_LINE_DOWN = 215, + CONVERT_INDENTATION = 216, + CUT_TO_LINE_END = 217, + COPY_TO_LINE_END = 218, + PASTE_FROM_RING = 219, + PASTE_NEXT_FROM_RING = 220, + PASTE_PREV_FROM_RING = 221, + EXECUTE_AS_RUBY = 222, + EXECUTE_AS_LUA = 223, + ENCLOSE_IN_HTML_TAGS = 224, + ENCLOSE_IN_HTML_SINGLE_TAG = 225, + ENCLOSE_IN_DOUBLE_QUOTES = 226, + ENCLOSE_IN_SINGLE_QUOTES = 227, + ENCLOSE_IN_PARENTHESES = 228, + ENCLOSE_IN_BRACKETS = 229, + ENCLOSE_IN_BRACES = 230, + ENCLOSE_IN_CHARACTER_SEQUENCE = 231, + GROW_SELECTION = 232, + SELECT_IN_STRUCTURE = 233, + SELECT_IN_HTML_TAG = 234, + SELECT_IN_DOUBLE_QUOTE = 235, + SELECT_IN_SINGLE_QUOTE = 236, + SELECT_IN_PARENTHESIS = 237, + SELECT_IN_BRACKET = 238, + SELECT_IN_BRACE = 239, + SELECT_IN_WORD = 240, + SELECT_IN_LINE = 241, + SELECT_IN_PARAGRAPH = 242, + SELECT_IN_INDENTED_BLOCK = 243, + SELECT_IN_SCOPE = 244, + -- Search + FIND = 301, + FIND_NEXT = 302, + FIND_PREV = 303, + FIND_AND_REPLACE = 304, + REPLACE = 305, + REPLACE_ALL = 306, + GOTO_LINE = 307, + -- Tools + FOCUS_COMMAND_ENTRY = 401, + INSERT_SNIPPET = 402, + PREVIOUS_SNIPPET_PLACEHOLDER = 403, + CANCEL_SNIPPET = 404, + LIST_SNIPPETS = 405, + SHOW_SCOPE = 406, + ADD_MULTIPLE_LINE = 407, + ADD_MULTIPLE_LINES = 408, + REMOVE_MULTIPLE_LINE = 409, + REMOVE_MULTIPLE_LINES = 410, + UPDATE_MULTIPLE_LINES = 411, + FINISH_MULTIPLE_LINES = 412, + START_RECORDING_MACRO = 413, + STOP_RECORDING_MACRO = 414, + PLAY_MACRO = 415, + -- Buffers + NEXT_BUFFER = 501, + PREV_BUFFER = 502, + TOGGLE_VIEW_EOL = 503, + TOGGLE_WRAP_MODE = 504, + TOGGLE_SHOW_INDENT_GUIDES = 505, + TOGGLE_USE_TABS = 506, + TOGGLE_VIEW_WHITESPACE = 507, + REFRESH_SYNTAX_HIGHLIGHTING = 508, + -- Views + NEXT_VIEW = 601, + PREV_VIEW = 602, + SPLIT_VIEW_VERTICAL = 603, + SPLIT_VIEW_HORIZONTAL = 604, + UNSPLIT_VIEW = 605, + UNSPLIT_ALL_VIEWS = 606, + GROW_VIEW = 607, + SHRINK_VIEW = 608, + -- Project Manager + TOGGLE_PM_VISIBLE = 701, + FOCUS_PM = 702, + SHOW_PM_PROJECT = 703, + SHOW_PM_CTAGS = 704, + SHOW_PM_BUFFERS = 705, + SHOW_PM_FILES = 706, + SHOW_PM_MACROS = 707, + SHOW_PM_MODULES = 708, + -- Lexers + LEXER_ACTIONSCRIPT = 801, + LEXER_ADA = 802, + LEXER_ANTLR = 803, + LEXER_APDL = 804, + LEXER_APPLESCRIPT = 805, + LEXER_ASP = 806, + LEXER_AWK = 807, + LEXER_BATCH = 808, + LEXER_BOO = 809, + LEXER_CONTAINER = 810, + LEXER_CPP = 811, + LEXER_CSHARP = 812, + LEXER_CSS = 813, + LEXER_D = 814, + LEXER_DIFF = 815, + LEXER_DJANGO = 816, + LEXER_EIFFEL = 817, + LEXER_ERLANG = 818, + LEXER_ERRORLIST = 819, + LEXER_FORTH = 820, + LEXER_FORTRAN = 821, + LEXER_GAP = 822, + LEXER_GETTEXT = 823, + LEXER_GNUPLOT = 824, + LEXER_GROOVY = 825, + LEXER_HASKELL = 826, + LEXER_HTML = 827, + LEXER_IDL = 828, + LEXER_INI = 829, + LEXER_IO = 830, + LEXER_JAVA = 831, + LEXER_JAVASCRIPT = 832, + LEXER_LATEX = 833, + LEXER_LISP = 834, + LEXER_LUA = 835, + LEXER_MAKEFILE = 836, + LEXER_MYSQL = 837, + LEXER_OBJECTIVEC = 838, + LEXER_OCAML = 839, + LEXER_PASCAL = 840, + LEXER_PERL = 841, + LEXER_PHP = 842, + LEXER_PIKE = 843, + LEXER_POSTSCRIPT = 844, + LEXER_PROPS = 845, + LEXER_PYTHON = 846, + LEXER_R = 847, + LEXER_RAGEL = 848, + LEXER_REBOL = 849, + LEXER_REXX = 850, + LEXER_RHTML = 851, + LEXER_RUBY = 852, + LEXER_SCHEME = 853, + LEXER_SHELLSCRIPT = 854, + LEXER_SMALLTALK = 855, + LEXER_TCL = 856, + LEXER_VALA = 857, + LEXER_VERILOG = 858, + LEXER_VHDL = 859, + LEXER_VISUALBASIC = 860, + LEXER_XML = 861 +} + t.menubar = { gtkmenu { - title = '_File', - 'gtk-new', - 'gtk-open', - '_Reload', - 'gtk-save', - 'gtk-save-as', - 'gtk-close', - 'Close A_ll', - 'separator', - '_Load Session...', - 'Sa_ve Session...', - 'separator', - 'gtk-quit', + title = l.MENU_FILE_TITLE, + { l.MENU_FILE_NEW, ID.NEW }, + { l.MENU_FILE_OPEN, ID.OPEN }, + { l.MENU_FILE_RELOAD, ID.RELOAD }, + { l.MENU_FILE_SAVE, ID.SAVE }, + { l.MENU_FILE_SAVEAS, ID.SAVEAS }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_FILE_CLOSE, ID.CLOSE }, + { l.MENU_FILE_CLOSE_ALL, ID.CLOSE_ALL }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_FILE_LOAD_SESSION, ID.LOAD_SESSION }, + { l.MENU_FILE_SAVE_SESSION, ID.SAVE_SESSION }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_FILE_QUIT, ID.QUIT }, }, gtkmenu { - title = '_Edit', - 'gtk-undo', - 'gtk-redo', - 'separator', - 'gtk-cut', - 'gtk-copy', - 'gtk-paste', - 'gtk-delete', - 'gtk-select-all', - 'separator', - 'Match _Brace', - 'Select t_o Brace', - 'Complete _Word', - 'De_lete Word', - 'Tran_spose Characters', - 'S_queeze', - '_Move line up', - 'Mo_ve line down', - 'Convert _Indentation', - { title = '_Kill Ring', - '_Cut to line end', - 'C_opy to line end', - '_Paste from ring', - 'Paste _next from ring', - 'Paste pre_v from ring', + title = l.MENU_EDIT_TITLE, + { l.MENU_EDIT_UNDO, ID.UNDO }, + { l.MENU_EDIT_REDO, ID.REDO }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_EDIT_CUT, ID.CUT }, + { l.MENU_EDIT_COPY, ID.COPY }, + { l.MENU_EDIT_PASTE, ID.PASTE }, + { l.MENU_EDIT_DELETE, ID.DELETE }, + { l.MENU_EDIT_SELECT_ALL, ID.SELECT_ALL }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_EDIT_MATCH_BRACE, ID.MATCH_BRACE }, + { l.MENU_EDIT_SELECT_TO_BRACE, ID.SELECT_TO_BRACE }, + { l.MENU_EDIT_COMPLETE_WORD, ID.COMPLETE_WORD }, + { l.MENU_EDIT_DELETE_WORD, ID.DELETE_WORD }, + { l.MENU_EDIT_TRANSPOSE_CHARACTERS, ID.TRANSPOSE_CHARACTERS }, + { l.MENU_EDIT_SQUEEZE, ID.SQUEEZE }, + { l.MENU_EDIT_JOIN_LINES, ID.JOIN_LINES }, + { l.MENU_EDIT_MOVE_LINE_UP, ID.MOVE_LINE_UP }, + { l.MENU_EDIT_MOVE_LINE_DOWN, ID.MOVE_LINE_DOWN }, + { l.MENU_EDIT_CONVERT_INDENTATION, ID.CONVERT_INDENTATION }, + { title = l.MENU_EDIT_KR_TITLE, + { l.MENU_EDIT_KR_CUT_TO_LINE_END, ID.CUT_TO_LINE_END }, + { l.MENU_EDIT_KR_COPY_TO_LINE_END, ID.COPY_TO_LINE_END }, + { l.MENU_EDIT_KR_PASTE_FROM, ID.PASTE_FROM_RING }, + { l.MENU_EDIT_KR_PASTE_NEXT_FROM, ID.PASTE_NEXT_FROM_RING }, + { l.MENU_EDIT_KR_PASTE_PREV_FROM, ID.PASTE_PREV_FROM_RING }, }, - { title = 'S_election', - { title = 'E_xecute as...', - '_Ruby', - '_Lua', + { title = l.MENU_EDIT_SEL_TITLE, + { title = l.MENU_EDIT_SEL_EXEC_TITLE, + { l.MENU_EDIT_SEL_EXEC_AS_RUBY, ID.EXECUTE_AS_RUBY }, + { l.MENU_EDIT_SEL_EXEC_AS_LUA, ID.EXECUTE_AS_LUA }, }, - { title = '_Enclose in...', - '_HTML Tags', - 'HTML Single _Tag', - '_Double Quotes', - '_Single Quotes', - '_Parentheses', - '_Brackets', - 'B_races', - '_Character Sequence', + { title = l.MENU_EDIT_SEL_ENC_TITLE, + { l.MENU_EDIT_SEL_ENC_HTML_TAGS, ID.ENCLOSE_IN_HTML_TAGS }, + { l.MENU_EDIT_SEL_ENC_HTML_SINGLE_TAG, ID.ENCLOSE_IN_HTML_SINGLE_TAG }, + { l.MENU_EDIT_SEL_ENC_DOUBLE_QUOTES, ID.ENCLOSE_IN_DOUBLE_QUOTES }, + { l.MENU_EDIT_SEL_ENC_SINGLE_QUOTES, ID.ENCLOSE_IN_SINGLE_QUOTES }, + { l.MENU_EDIT_SEL_ENC_PARENTHESES, ID.ENCLOSE_IN_PARENTHESES }, + { l.MENU_EDIT_SEL_ENC_BRACKETS, ID.ENCLOSE_IN_BRACKETS }, + { l.MENU_EDIT_SEL_ENC_BRACES, ID.ENCLOSE_IN_BRACES }, + { l.MENU_EDIT_SEL_ENC_CHAR_SEQ, ID.ENCLOSE_IN_CHARACTER_SEQUENCE }, }, - '_Grow', + { l.MENU_EDIT_SEL_GROW, ID.GROW_SELECTION }, }, - { title = 'Select i_n...', - 'S_tructure', - '_HTML Tag', - '_Double Quote', - '_Single Quote', - '_Parenthesis', - '_Bracket', - 'B_race', - '_Word', - '_Line', - 'Para_graph', - '_Indented Block', - 'S_cope', + { title = l.MENU_EDIT_SEL_IN_TITLE, + { l.MENU_EDIT_SEL_IN_STRUCTURE, ID.SELECT_IN_STRUCTURE }, + { l.MENU_EDIT_SEL_IN_HTML_TAG, ID.SELECT_IN_HTML_TAG }, + { l.MENU_EDIT_SEL_IN_DOUBLE_QUOTE, ID.SELECT_IN_DOUBLE_QUOTE }, + { l.MENU_EDIT_SEL_IN_SINGLE_QUOTE, ID.SELECT_IN_SINGLE_QUOTE }, + { l.MENU_EDIT_SEL_IN_PARENTHESIS, ID.SELECT_IN_PARENTHESIS }, + { l.MENU_EDIT_SEL_IN_BRACKET, ID.SELECT_IN_BRACKET }, + { l.MENU_EDIT_SEL_IN_BRACE, ID.SELECT_IN_BRACE }, + { l.MENU_EDIT_SEL_IN_WORD, ID.SELECT_IN_WORD }, + { l.MENU_EDIT_SEL_IN_LINE, ID.SELECT_IN_LINE }, + { l.MENU_EDIT_SEL_IN_PARAGRAPH, ID.SELECT_IN_PARAGRAPH }, + { l.MENU_EDIT_SEL_IN_INDENTED_BLOCK, ID.SELECT_IN_INDENTED_BLOCK }, + { l.MENU_EDIT_SEL_IN_SCOPE, ID.SELECT_IN_SCOPE }, }, }, gtkmenu { - title = '_Search', - 'gtk-find', - 'Find _Next', - 'Find _Prev', - 'gtk-find-and-replace', - 'Replace', - 'Replace _All', - 'separator', - 'gtk-jump-to', + title = l.MENU_SEARCH_TITLE, + { l.MENU_SEARCH_FIND, ID.FIND }, + { l.MENU_SEARCH_FIND_NEXT, ID.FIND_NEXT }, + { l.MENU_SEARCH_FIND_PREV, ID.FIND_PREV }, + { l.MENU_SEARCH_FIND_AND_REPLACE, ID.FIND_AND_REPLACE }, + { l.MENU_SEARCH_REPLACE, ID.REPLACE }, + { l.MENU_SEARCH_REPLACE_ALL, ID.REPLACE_ALL }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_SEARCH_GOTO_LINE, ID.GOTO_LINE }, }, gtkmenu { - title = '_Tools', - 'Focus _Command Entry', - { title = '_Snippets', - '_Insert Snippet', - '_Previous Placeholder', - '_Cancel Snippet', - '_List Snippets', - '_Show Scope', + title = l.MENU_TOOLS_TITLE, + { l.MENU_TOOLS_FOCUS_COMMAND_ENTRY, ID.FOCUS_COMMAND_ENTRY }, + { title = l.MENU_TOOLS_SNIPPETS_TITLE, + { l.MENU_TOOLS_SNIPPETS_INSERT, ID.INSERT_SNIPPET }, + { l.MENU_TOOLS_SNIPPETS_PREV_PLACE, ID.PREVIOUS_SNIPPET_PLACEHOLDER }, + { l.MENU_TOOLS_SNIPPETS_CANCEL, ID.CANCEL_SNIPPET }, + { l.MENU_TOOLS_SNIPPETS_LIST, ID.LIST_SNIPPETS }, + { l.MENU_TOOLS_SNIPPETS_SHOW_SCOPE, ID.SHOW_SCOPE }, }, - { title = '_Multiple Line Editing', - '_Add Line', - 'Add _Multiple Lines', - '_Remove Line', - 'R_emove Multiple Lines', - '_Update Multiple Lines', - '_Finished Editing', + { title = l.MENU_TOOLS_ML_TITLE, + { l.MENU_TOOLS_ML_ADD, ID.ADD_MULTIPLE_LINE }, + { l.MENU_TOOLS_ML_ADD_MULTIPLE, ID.ADD_MULTIPLE_LINES }, + { l.MENU_TOOLS_ML_REMOVE, ID.REMOVE_MULTIPLE_LINE }, + { l.MENU_TOOLS_ML_REMOVE_MULTIPLE, ID.REMOVE_MULTIPLE_LINES }, + { l.MENU_TOOLS_ML_UPDATE, ID.UPDATE_MULTIPLE_LINES }, + { l.MENU_TOOLS_ML_FINISH, ID.FINISH_MULTIPLE_LINES }, }, - { title = 'M_acros', - '_Start Recording', - 'S_top Recording', - '_Play Macro' + { title = l.MENU_TOOLS_MACROS_TITLE, + { l.MENU_TOOLS_MACROS_START, ID.START_RECORDING_MACRO }, + { l.MENU_TOOLS_MACROS_STOP, ID.STOP_RECORDING_MACRO }, + { l.MENU_TOOLS_MACROS_PLAY, ID.PLAY_MACRO }, }, }, gtkmenu { - title = '_Buffers', - '_Next Buffer', - '_Prev Buffer', - 'separator', - 'Toggle View _EOL', - 'Toggle _Wrap Mode', - 'Toggle Show _Indentation Guides', - 'Toggle Use _Tabs', - 'Toggle View White_space', - 'separator', - '_Refresh Syntax Highlighting', + title = l.MENU_BUF_TITLE, + { l.MENU_BUF_NEXT, ID.NEXT_BUFFER }, + { l.MENU_BUF_PREV, ID.PREV_BUFFER }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_BUF_TOGGLE_VIEW_EOL, ID.TOGGLE_VIEW_EOL }, + { l.MENU_BUF_TOGGLE_WRAP, ID.TOGGLE_WRAP_MODE }, + { l.MENU_BUF_TOGGLE_INDENT_GUIDES, ID.TOGGLE_SHOW_INDENT_GUIDES }, + { l.MENU_BUF_TOGGLE_TABS, ID.TOGGLE_USE_TABS }, + { l.MENU_BUF_TOGGLE_VIEW_WHITESPACE, ID.TOGGLE_VIEW_WHITESPACE }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_BUF_REFRESH, ID.REFRESH_SYNTAX_HIGHLIGHTING }, }, gtkmenu { - title = '_Views', - '_Next View', - '_Prev View', - 'separator', - 'Split _Vertical', - 'Split _Horizontal', - '_Unsplit', - 'Unsplit _All', - 'separator', - '_Grow View', - '_Shrink View', + title = l.MENU_VIEW_TITLE, + { l.MENU_VIEW_NEXT, ID.NEXT_VIEW }, + { l.MENU_VIEW_PREV, ID.PREV_VIEW }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_VIEW_SPLIT_VERTICAL, ID.SPLIT_VIEW_VERTICAL }, + { l.MENU_VIEW_SPLIT_HORIZONTAL, ID.SPLIT_VIEW_HORIZONTAL }, + { l.MENU_VIEW_UNSPLIT, ID.UNSPLIT_VIEW }, + { l.MENU_VIEW_UNSPLIT_ALL, ID.UNSPLIT_ALL_VIEWS }, + { SEPARATOR, ID.SEPARATOR }, + { l.MENU_VIEW_GROW, ID.GROW_VIEW }, + { l.MENU_VIEW_SHRINK, ID.SHRINK_VIEW }, }, gtkmenu { - title = '_Project Manager', - '_Toggle PM Visible', - '_Focus PM', - 'Show PM _Project', - 'Show PM _Ctags', - 'Show PM _Buffers', - 'Show PM _Files', - 'Show PM _Macros', - 'Show PM Mo_dules', + title = l.MENU_PM_TITLE, + { l.MENU_PM_TOGGLE_VISIBLE, ID.TOGGLE_PM_VISIBLE }, + { l.MENU_PM_FOCUS, ID.FOCUS_PM }, + { l.MENU_PM_BUFFERS, ID.SHOW_PM_BUFFERS }, + { l.MENU_PM_PROJECT, ID.SHOW_PM_PROJECT }, + { l.MENU_PM_FILES, ID.SHOW_PM_FILES }, + { l.MENU_PM_CTAGS, ID.SHOW_PM_CTAGS }, + { l.MENU_PM_MACROS, ID.SHOW_PM_MACROS }, + { l.MENU_PM_MODULES, ID.SHOW_PM_MODULES }, }, gtkmenu { - title = '_Lexers', - 'actionscript', 'ada', 'antlr', 'apdl', 'applescript', 'asp', 'awk', - 'batch', 'boo', 'container', 'cpp', 'csharp', 'css', 'd', 'diff', 'django', - 'eiffel', 'erlang', 'errorlist', 'forth', 'fortran', 'gap', 'gettext', - 'gnuplot', 'groovy', 'haskell', 'html', 'idl', 'ini', 'io', 'java', - 'javascript', 'latex', 'lisp', 'lua', 'makefile', 'mysql', 'objective__c', - 'ocaml', 'pascal', 'perl', 'php', 'pike', 'postscript', 'props', 'python', - 'r', 'ragel', 'rebol', 'rexx', 'rhtml', 'ruby', 'scheme', 'shellscript', - 'smalltalk', 'tcl', 'vala', 'verilog', 'vhdl', 'visualbasic', 'xml', + title = l.MENU_LEX_TITLE, + { 'actionscript', ID.LEXER_ACTIONSCRIPT }, + { 'ada', ID.LEXER_ADA }, + { 'antlr', ID.LEXER_ANTLR }, + { 'apdl', ID.LEXER_APDL }, + { 'applescript', ID.LEXER_APPLESCRIPT }, + { 'asp', ID.LEXER_ASP }, + { 'awk', ID.LEXER_AWK }, + { 'batch', ID.LEXER_BATCH }, + { 'boo', ID.LEXER_BOO }, + { 'container', ID.LEXER_CONTAINER }, + { 'cpp', ID.LEXER_CPP }, + { 'csharp', ID.LEXER_CSHARP }, + { 'css', ID.LEXER_CSS }, + { 'd', ID.LEXER_D }, + { 'diff', ID.LEXER_DIFF }, + { 'django', ID.LEXER_DJANGO }, + { 'eiffel', ID.LEXER_EIFFEL }, + { 'erlang', ID.LEXER_ERLANG }, + { 'errorlist', ID.LEXER_ERRORLIST }, + { 'forth', ID.LEXER_FORTH }, + { 'fortran', ID.LEXER_FORTRAN }, + { 'gap', ID.LEXER_GAP }, + { 'gettext', ID.LEXER_GETTEXT }, + { 'gnuplot', ID.LEXER_GNUPLOT }, + { 'groovy', ID.LEXER_GROOVY }, + { 'haskell', ID.LEXER_HASKELL }, + { 'html', ID.LEXER_HTML }, + { 'idl', ID.LEXER_IDL }, + { 'ini', ID.LEXER_INI }, + { 'io', ID.LEXER_IO }, + { 'java', ID.LEXER_JAVA }, + { 'javascript', ID.LEXER_JAVASCRIPT }, + { 'latex', ID.LEXER_LATEX }, + { 'lisp', ID.LEXER_LISP }, + { 'lua', ID.LEXER_LUA }, + { 'makefile', ID.LEXER_MAKEFILE }, + { 'mysql', ID.LEXER_MYSQL }, + { 'objective__c', ID.LEXER_OBJECTIVEC }, + { 'ocaml', ID.LEXER_OCAML }, + { 'pascal', ID.LEXER_PASCAL }, + { 'perl', ID.LEXER_PERL }, + { 'php', ID.LEXER_PHP }, + { 'pike', ID.LEXER_PIKE }, + { 'postscript', ID.LEXER_POSTSCRIPT }, + { 'props', ID.LEXER_PROPS }, + { 'python', ID.LEXER_PYTHON }, + { 'r', ID.LEXER_R }, + { 'ragel', ID.LEXER_RAGEL }, + { 'rebol', ID.LEXER_REBOL }, + { 'rexx', ID.LEXER_REXX }, + { 'rhtml', ID.LEXER_RHTML }, + { 'ruby', ID.LEXER_RUBY }, + { 'scheme', ID.LEXER_SCHEME }, + { 'shellscript', ID.LEXER_SHELLSCRIPT }, + { 'smalltalk', ID.LEXER_SMALLTALK }, + { 'tcl', ID.LEXER_TCL }, + { 'vala', ID.LEXER_VALA }, + { 'verilog', ID.LEXER_VERILOG }, + { 'vhdl', ID.LEXER_VHDL }, + { 'visualbasic', ID.LEXER_VISUALBASIC }, + { 'xml', ID.LEXER_XML }, }, } @@ -190,132 +421,134 @@ end local actions = { -- File - New = { t.new_buffer }, - Open = { t.io.open }, - Reload = { 'reload', b }, - Save = { 'save', b }, - ['Save As'] = { 'save_as', b }, - Close = { 'close', b }, - ['Close All'] = { t.io.close_all }, - ['Load Session...'] = { t.io.load_session }, -- TODO: file open dialog prompt - ['Save Session...'] = { t.io.save_session }, -- TODO: file save dialog prompt - Quit = { t.quit }, + [ID.NEW] = { t.new_buffer }, + [ID.OPEN] = { t.io.open }, + [ID.RELOAD] = { 'reload', b }, + [ID.SAVE] = { 'save', b }, + [ID.SAVEAS] = { 'save_as', b }, + [ID.CLOSE] = { 'close', b }, + [ID.CLOSE_ALL] = { t.io.close_all }, + [ID.LOAD_SESSION] = { t.io.load_session }, -- TODO: file open dialog prompt + [ID.SAVE_SESSION] = { t.io.save_session }, -- TODO: file save dialog prompt + [ID.QUIT] = { t.quit }, -- Edit - Undo = { 'undo', b }, - Redo = { 'redo', b }, - Cut = { 'cut', b }, - Copy = { 'copy', b }, - Paste = { 'paste', b }, - Delete = { 'clear', b }, - ['Select All'] = { 'select_all', b }, - ['Match Brace'] = { m_editing.match_brace }, - ['Select to Brace'] = { m_editing.match_brace, 'select' }, - ['Complete Word'] = { m_editing.autocomplete_word, '%w_' }, - ['Delete Word'] = { m_editing.current_word, 'delete' }, - ['Transpose Characters'] = { m_editing.transpose_chars }, - ['Squeeze'] = { m_editing.squeeze }, - ['Join Lines'] = { m_editing.join_lines }, - ['Move line up'] = { m_editing.move_line, 'up' }, - ['Move line down'] = { m_editing.move_line, 'down' }, - ['Convert Indentation'] = { m_editing.convert_indentation }, + [ID.UNDO] = { 'undo', b }, + [ID.REDO] = { 'redo', b }, + [ID.CUT] = { 'cut', b }, + [ID.COPY] = { 'copy', b }, + [ID.PASTE] = { 'paste', b }, + [ID.DELETE] = { 'clear', b }, + [ID.SELECT_ALL] = { 'select_all', b }, + [ID.MATCH_BRACE] = { m_editing.match_brace }, + [ID.SELECT_TO_BRACE] = { m_editing.match_brace, 'select' }, + [ID.COMPLETE_WORD] = { m_editing.autocomplete_word, '%w_' }, + [ID.DELETE_WORD] = { m_editing.current_word, 'delete' }, + [ID.TRANSPOSE_CHARACTERS] = { m_editing.transpose_chars }, + [ID.SQUEEZE] = { m_editing.squeeze }, + [ID.JOIN_LINES] = { m_editing.join_lines }, + [ID.MOVE_LINE_UP] = { m_editing.move_line, 'up' }, + [ID.MOVE_LINE_DOWN] = { m_editing.move_line, 'down' }, + [ID.CONVERT_INDENTATION] = { m_editing.convert_indentation }, -- Edit -> Kill Ring - ['Cut to line end'] = { m_editing.smart_cutcopy }, - ['Copy to line end'] = { m_editing.smart_cutcopy, 'copy' }, - ['Paste from ring'] = { m_editing.smart_paste }, - ['Paste next from ring'] = { m_editing.smart_paste, 'cycle' }, - ['Paste prev from ring'] = { m_editing.smart_paste, 'reverse' }, + [ID.CUT_TO_LINE_END] = { m_editing.smart_cutcopy }, + [ID.COPY_TO_LINE_END] = { m_editing.smart_cutcopy, 'copy' }, + [ID.PASTE_FROM_RING] = { m_editing.smart_paste }, + [ID.PASTE_NEXT_FROM_RING] = { m_editing.smart_paste, 'cycle' }, + [ID.PASTE_PREV_FROM_RING] = { m_editing.smart_paste, 'reverse' }, -- Edit -> Selection -> Execute as... - Ruby = { m_editing.ruby_exec }, - Lua = { m_editing.lua_exec }, + [ID.EXECUTE_AS_RUBY] = { m_editing.ruby_exec }, + [ID.EXECUTE_AS_LUA] = { m_editing.lua_exec }, -- Edit -> Selection -> Enclose in... - ['HTML Tags'] = { m_editing.enclose, 'tag' }, - ['HTML Single Tag'] = { m_editing.enclose, 'single_tag' }, - ['Double Quotes'] = { m_editing.enclose, 'dbl_quotes' }, - ['Single Quotes'] = { m_editing.enclose, 'sng_quotes' }, - Parentheses = { m_editing.enclose, 'parens' }, - Brackets = { m_editing.enclose, 'brackets' }, - Braces = { m_editing.enclose, 'braces' }, - ['Character Sequence'] = { m_editing.enclose, 'chars' }, + [ID.ENCLOSE_IN_HTML_TAGS] = { m_editing.enclose, 'tag' }, + [ID.ENCLOSE_IN_HTML_SINGLE_TAG] = { m_editing.enclose, 'single_tag' }, + [ID.ENCLOSE_IN_DOUBLE_QUOTES] = { m_editing.enclose, 'dbl_quotes' }, + [ID.ENCLOSE_IN_SINGLE_QUOTES] = { m_editing.enclose, 'sng_quotes' }, + [ID.ENCLOSE_IN_PARENTHESES] = { m_editing.enclose, 'parens' }, + [ID.ENCLOSE_IN_BRACKETS] = { m_editing.enclose, 'brackets' }, + [ID.ENCLOSE_IN_BRACES] = { m_editing.enclose, 'braces' }, + [ID.ENCLOSE_IN_CHARACTER_SEQUENCE] = { m_editing.enclose, 'chars' }, -- Edit -> Selection - Grow = { m_editing.grow_selection, 1 }, + [ID.GROW_SELECTION] = { m_editing.grow_selection, 1 }, -- Edit -> Select In... - Structure = { m_editing.select_enclosed }, - ['HTML Tag'] = { m_editing.select_enclosed, 'tags' }, - ['Double Quote'] = { m_editing.select_enclosed, 'dbl_quotes' }, - ['Single Quote'] = { m_editing.select_enclosed, 'sng_quotes' }, - Parenthesis = { m_editing.select_enclosed, 'parens' }, - Bracket = { m_editing.select_enclosed, 'brackets' }, - Brace = { m_editing.select_enclosed, 'braces' }, - Word = { m_editing.current_word, 'select' }, - Line = { m_editing.select_line }, - Paragraph = { m_editing.select_paragraph }, - ['Indented Block'] = { m_editing.select_indented_block }, - Scope = { m_editing.select_scope }, + [ID.SELECT_IN_STRUCTURE] = { m_editing.select_enclosed }, + [ID.SELECT_IN_HTML_TAG] = { m_editing.select_enclosed, 'tags' }, + [ID.SELECT_IN_DOUBLE_QUOTE] = { m_editing.select_enclosed, 'dbl_quotes' }, + [ID.SELECT_IN_SINGLE_QUOTE] = { m_editing.select_enclosed, 'sng_quotes' }, + [ID.SELECT_IN_PARENTHESIS] = { m_editing.select_enclosed, 'parens' }, + [ID.SELECT_IN_BRACKET] = { m_editing.select_enclosed, 'brackets' }, + [ID.SELECT_IN_BRACE] = { m_editing.select_enclosed, 'braces' }, + [ID.SELECT_IN_WORD] = { m_editing.current_word, 'select' }, + [ID.SELECT_IN_LINE] = { m_editing.select_line }, + [ID.SELECT_IN_PARAGRAPH] = { m_editing.select_paragraph }, + [ID.SELECT_IN_INDENTED_BLOCK] = { m_editing.select_indented_block }, + [ID.SELECT_IN_SCOPE] = { m_editing.select_scope }, -- Search - Find = { t.find.focus }, - ['Find Next'] = { t.find.call_find_next }, - ['Find Prev'] = { t.find.call_find_prev }, - ['Find and Replace'] = { t.find.focus }, - Replace = { t.find.call_replace }, - ['Replace All'] = { t.find.call_replace_all }, - ['Jump to'] = { m_editing.goto_line }, + [ID.FIND] = { t.find.focus }, + [ID.FIND_NEXT] = { t.find.call_find_next }, + [ID.FIND_PREV] = { t.find.call_find_prev }, + [ID.FIND_AND_REPLACE] = { t.find.focus }, + [ID.REPLACE] = { t.find.call_replace }, + [ID.REPLACE_ALL] = { t.find.call_replace_all }, + [ID.GOTO_LINE] = { m_editing.goto_line }, -- Tools - ['Focus Command Entry'] = { t.command_entry.focus }, + [ID.FOCUS_COMMAND_ENTRY] = { t.command_entry.focus }, -- Tools -> Snippets - ['Insert Snippet'] = { m_snippets.insert }, - ['Previous Placeholder'] = { m_snippets.prev }, - ['Cancel Snippet'] = { m_snippets.cancel_current }, - ['List Snippets'] = { m_snippets.list }, - ['Show Scope'] = { m_snippets.show_style }, + [ID.INSERT_SNIPPET] = { m_snippets.insert }, + [ID.PREVIOUS_SNIPPET_PLACEHOLDER] = { m_snippets.prev }, + [ID.CANCEL_SNIPPET] = { m_snippets.cancel_current }, + [ID.LIST_SNIPPETS] = { m_snippets.list }, + [ID.SHOW_SCOPE] = { m_snippets.show_style }, -- Tools -> Multiple Line Editing - ['Add Line'] = { m_mlines.add }, - ['Add Multiple Lines'] = { m_mlines.add_multiple }, - ['Remove Line'] = { m_mlines.remove }, - ['Remove Multiple Lines'] = { m_mlines.remove_multiple }, - ['Update Multiple Lines'] = { m_mlines.update }, - ['Finished Editing'] = { m_mlines.clear }, + [ID.ADD_MULTIPLE_LINE] = { m_mlines.add }, + [ID.ADD_MULTIPLE_LINES] = { m_mlines.add_multiple }, + [ID.REMOVE_MULTIPLE_LINE] = { m_mlines.remove }, + [ID.REMOVE_MULTIPLE_LINES] = { m_mlines.remove_multiple }, + [ID.UPDATE_MULTIPLE_LINES] = { m_mlines.update }, + [ID.FINISH_MULTIPLE_LINES] = { m_mlines.clear }, -- Tools -> Macros - ['Start Recording'] = { m_macros.start_recording }, - ['Stop Recording'] = { m_macros.stop_recording }, - ['Play Macro'] = { m_macros.play }, + [ID.START_RECORDING_MACRO] = { m_macros.start_recording }, + [ID.STOP_RECORDING_MACRO] = { m_macros.stop_recording }, + [ID.PLAY_MACRO] = { m_macros.play }, -- Buffers - ['Next Buffer'] = { 'goto_buffer', v, 1, false }, - ['Prev Buffer'] = { 'goto_buffer', v, -1, false }, - ['Toggle View EOL'] = { toggle_setting, 'view_eol' }, - ['Toggle Wrap Mode'] = { toggle_setting, 'wrap_mode' }, - ['Toggle Show Indentation Guides'] = { toggle_setting, 'indentation_guides' }, - ['Toggle Use Tabs'] = { toggle_setting, 'use_tabs' }, - ['Toggle View Whitespace'] = { toggle_setting, 'view_ws' }, - ['Refresh Syntax Highlighting'] = { 'colourise', b, 0, -1 }, + [ID.NEXT_BUFFER] = { 'goto_buffer', v, 1, false }, + [ID.PREV_BUFFER] = { 'goto_buffer', v, -1, false }, + [ID.TOGGLE_VIEW_EOL] = { toggle_setting, 'view_eol' }, + [ID.TOGGLE_WRAP_MODE] = { toggle_setting, 'wrap_mode' }, + [ID.TOGGLE_SHOW_INDENT_GUIDES] = { toggle_setting, 'indentation_guides' }, + [ID.TOGGLE_USE_TABS] = { toggle_setting, 'use_tabs' }, + [ID.TOGGLE_VIEW_WHITESPACE] = { toggle_setting, 'view_ws' }, + [ID.REFRESH_SYNTAX_HIGHLIGHTING] = { 'colourise', b, 0, -1 }, -- Views - ['Next View'] = { t.goto_view, 1, false }, - ['Prev View'] = { t.goto_view, -1, false }, - ['Split Vertical'] = { 'split', v }, - ['Split Horizontal'] = { 'split', v, false }, - ['Unsplit'] = { function() view:unsplit() end }, - ['Unsplit All'] = { function() while view:unsplit() do end end }, - ['Grow View'] = { + [ID.NEXT_VIEW] = { t.goto_view, 1, false }, + [ID.PREV_VIEW] = { t.goto_view, -1, false }, + [ID.SPLIT_VIEW_VERTICAL] = { 'split', v }, + [ID.SPLIT_VIEW_HORIZONTAL] = { 'split', v, false }, + [ID.UNSPLIT_VIEW] = { function() view:unsplit() end }, + [ID.UNSPLIT_ALL_VIEWS] = { function() while view:unsplit() do end end }, + [ID.GROW_VIEW] = { function() if view.size then view.size = view.size + 10 end end }, - ['Shrink View'] = { + [ID.SHRINK_VIEW] = { function() if view.size then view.size = view.size - 10 end end }, -- Project Manager - ['Toggle PM Visible'] = { t.pm.toggle_visible }, - ['Focus PM'] = { t.pm.focus }, - ['Show PM Project'] = { pm_activate, 'project' }, - ['Show PM Ctags'] = { pm_activate, 'ctags' }, - ['Show PM Buffers'] = { pm_activate, 'buffers' }, - ['Show PM Files'] = { pm_activate, not WIN32 and '/' or 'C:\\' }, - ['Show PM Macros'] = { pm_activate, 'macros' }, - ['Show PM Modules'] = { pm_activate, 'modules' }, + [ID.TOGGLE_PM_VISIBLE] = { t.pm.toggle_visible }, + [ID.FOCUS_PM] = { t.pm.focus }, + [ID.SHOW_PM_PROJECT] = { pm_activate, 'project' }, + [ID.SHOW_PM_CTAGS] = { pm_activate, 'ctags' }, + [ID.SHOW_PM_BUFFERS] = { pm_activate, 'buffers' }, + [ID.SHOW_PM_FILES] = { pm_activate, not WIN32 and '/' or 'C:\\' }, + [ID.SHOW_PM_MACROS] = { pm_activate, 'macros' }, + [ID.SHOW_PM_MODULES] = { pm_activate, 'modules' }, } -- Most of this handling code comes from keys.lua. t.events.add_handler('menu_clicked', - function(menu_item) - local active_table = actions[menu_item] or - { set_lexer_language, menu_item } -- anything not in actions is a lexer + function(menu_item, menu_id) + local active_table = actions[menu_id] + if menu_id >= ID.LEXER_ACTIONSCRIPT and menu_id <= ID.LEXER_XML then + active_table = { set_lexer_language, menu_item } + end local f, args if active_table and #active_table > 0 then local func = active_table[1] @@ -333,7 +566,7 @@ t.events.add_handler('menu_clicked', local ret, retval = pcall( f, unpack(args) ) if not ret then textadept.events.error(retval) end -- error else - error( 'Unknown command: '..tostring(func) ) + error( l.MENU_UNKNOWN_COMMAND..tostring(func) ) end end end) diff --git a/core/ext/pm.lua b/core/ext/pm.lua index 05b0e16a..ed997c5d 100644 --- a/core/ext/pm.lua +++ b/core/ext/pm.lua @@ -119,12 +119,13 @@ end -- Performs an action based on the selected menu item. -- This function is called internally and shouldn't be called by a script. -- @param menu_item The label text of the menu item selected. +-- @param menu_id The numeric ID of the menu item. -- @param selected_item Identical to 'full_path' in pm.get_contents_for. -- @see pm.get_contents_for -function pm.perform_menu_action(menu_item, selected_item) +function pm.perform_menu_action(menu_item, menu_id, selected_item) for _, browser in pairs(pm.browsers) do if browser.matches( selected_item[1] ) then - return browser.perform_menu_action(menu_item, selected_item) + return browser.perform_menu_action(menu_item, menu_id, selected_item) end end end diff --git a/core/ext/pm/buffer_browser.lua b/core/ext/pm/buffer_browser.lua index c2a1b787..f4822226 100644 --- a/core/ext/pm/buffer_browser.lua +++ b/core/ext/pm/buffer_browser.lua @@ -15,7 +15,7 @@ function get_contents_for() index = string.format("%02i", index) contents[index] = { pixbuf = buffer.dirty and 'gtk-edit' or 'gtk-file', - text = (buffer.filename or 'Untitled'):match('[^/\\]+$') + text = (buffer.filename or textadept.locale.UNTITLED):match('[^/\\]+$') } end return contents @@ -27,22 +27,32 @@ function perform_action(selected_item) if buffer then view:goto_buffer(index) view:focus() end end +local ID = { NEW = 1, OPEN = 2, SAVE = 3, SAVEAS = 4, CLOSE = 5 } + function get_context_menu(selected_item) - return { '_New', '_Open', '_Save', 'Save _As...', 'separator', '_Close' } + local locale = textadept.locale + return { + { locale.PM_BROWSER_BUFFER_NEW, ID.NEW }, + { locale.PM_BROWSER_BUFFER_OPEN, ID.OPEN }, + { locale.PM_BROWSER_BUFFER_SAVE, ID.SAVE }, + { locale.PM_BROWSER_BUFFER_SAVEAS, ID.SAVEAS }, + { 'separator', 0 }, + { locale.PM_BROWSER_BUFFER_CLOSE, ID.CLOSE }, + } end -function perform_menu_action(menu_item, selected_item) - if menu_item == 'New' then +function perform_menu_action(menu_item, menu_id, selected_item) + if menu_id == ID.NEW then textadept.new_buffer() - elseif menu_item == 'Open' then + elseif menu_id == ID.OPEN then textadept.io.open() - elseif menu_item == 'Save' then + elseif menu_id == ID.SAVE then view:goto_buffer( tonumber( selected_item[2] ) ) buffer:save() - elseif menu_item == 'Save As...' then + elseif menu_id == ID.SAVEAS then view:goto_buffer( tonumber( selected_item[2] ) ) buffer:save_as() - elseif menu_item == 'Close' then + elseif menu_id == ID.CLOSE then view:goto_buffer( tonumber( selected_item[2] ) ) buffer:close() end diff --git a/core/ext/pm/ctags_browser.lua b/core/ext/pm/ctags_browser.lua index b5495008..196eba5c 100644 --- a/core/ext/pm/ctags_browser.lua +++ b/core/ext/pm/ctags_browser.lua @@ -106,6 +106,7 @@ end -- of the parent being expanded. function get_contents_for(full_path, expanding) local ctags_file = full_path[1]:sub(7) -- ignore 'ctags:' + local locale = textadept.locale local f if #ctags_file == 0 then tags = {} @@ -187,9 +188,11 @@ function get_contents_for(full_path, expanding) entry.line_num = line_num if not entry.set then tags[name] = entry end else - print('Extension "'..file_ext..'" not recognized.') + print( string.format(locale.PM_BROWSER_CTAGS_BAD_EXT, file_ext) ) end - else print('unmatched ctag: '..line) end + else + print( string.format(locale.PM_BROWSER_CTAGS_UNMATCHED, line) ) + end end end f:close() @@ -213,7 +216,8 @@ function perform_action(selected_item) buffer:ensure_visible_enforce_policy(line) buffer:goto_line(line) else - error(item.text..' not found.') + error( + string.format(textadept.locale.PM_BROWSER_CTAGS_NOT_FOUND, item.text) ) end elseif item.line_num then textadept.io.open(item.filepath) @@ -226,7 +230,7 @@ function get_context_menu(selected_item) end -function perform_menu_action(menu_item, selected_item) +function perform_menu_action(menu_item, menu_id, selected_item) end diff --git a/core/ext/pm/file_browser.lua b/core/ext/pm/file_browser.lua index 5878b067..17ae3be1 100644 --- a/core/ext/pm/file_browser.lua +++ b/core/ext/pm/file_browser.lua @@ -38,35 +38,36 @@ function perform_action(selected_item) view:focus() end +local ID = { CHANGE_DIR = 1, FILE_INFO = 2 } + function get_context_menu(selected_item) - return { '_Change Directory', 'File _Details' } + local locale = textadept.locale + return { + { 'separator', 0 }, -- make it harder to click 'Change Directory' by mistake + { locale.PM_BROWSER_FILE_CD, ID.CHANGE_DIR }, + { locale.PM_BROWSER_FILE_INFO, ID.FILE_INFO }, + } end -function perform_menu_action(menu_item, selected_item) +function perform_menu_action(menu_item, menu_id, selected_item) + local locale = textadept.locale local filepath = table.concat(selected_item, '/') - if menu_item == 'Change Directory' then + if menu_id == ID.CHANGE_DIR then textadept.pm.entry_text = filepath textadept.pm.activate() - elseif menu_item == 'File Details' then + elseif menu_id == ID.FILE_INFO then local date_format = '%D %T' local attr = lfs.attributes(filepath) - local out = string.format( [[ - Mode: %s - Size: %s - UID: %s - GID: %s - Device: %s - Accessed: %s - Modified: %s - Changed: %s - ]], attr.mode, attr.size, attr.uid, attr.gid, attr.dev, + local out = string.format( locale.PM_BROWSER_FILE_DATA, + attr.mode, attr.size, attr.uid, attr.gid, attr.dev, os.date(date_format, attr.access), os.date(date_format, attr.modification), os.date(date_format, attr.change) ) cocoa_dialog( 'textbox', { - ['informative-text'] = 'File details for '..filepath, + ['informative-text'] = + string.format(locale.PM_BROWSER_FILE_INFO_TEXT, filepath), text = out, - button1 = 'OK', + button1 = locale.PM_BROWSER_FILE_INFO_OK, editable = false } ) end diff --git a/core/ext/pm/find_browser.lua b/core/ext/pm/find_browser.lua index 1c4df96a..f722664e 100644 --- a/core/ext/pm/find_browser.lua +++ b/core/ext/pm/find_browser.lua @@ -96,6 +96,6 @@ function get_context_menu(selected_item) end -function perform_menu_action(menu_item, selected_item) +function perform_menu_action(menu_item, menu_id, selected_item) end diff --git a/core/ext/pm/macro_browser.lua b/core/ext/pm/macro_browser.lua index 0dc58894..e1394e5c 100644 --- a/core/ext/pm/macro_browser.lua +++ b/core/ext/pm/macro_browser.lua @@ -23,13 +23,16 @@ function perform_action(selected_item) view:focus() end +local ID = { DELETE = 1 } + function get_context_menu(selected_item) - return { '_Delete' } + local locale = textadept.locale + return { { locale.PM_BROWSER_MACRO_DELETE, ID.DELETE } } end -function perform_menu_action(menu_item, selected_item) +function perform_menu_action(menu_item, menu_id, selected_item) local m_macros = _m.textadept.macros - if menu_item == 'Delete' then + if menu_id == ID.DELETE then m_macros.delete( selected_item[2] ) end textadept.pm.activate() diff --git a/core/ext/pm/modules_browser.lua b/core/ext/pm/modules_browser.lua index fc8b79e2..95a5bd9f 100644 --- a/core/ext/pm/modules_browser.lua +++ b/core/ext/pm/modules_browser.lua @@ -104,24 +104,33 @@ function perform_action(selected_item) view:focus() end +local ID = { + NEW = 1, DELETE = 2, CONF_MIME_TYPES = 3, CONF_KEY_COMMANDS = 4, RELOAD = 5 +} + function get_context_menu(selected_item) + local locale = textadept.locale return { - '_New Module', '_Delete Module', 'separator', - 'Configure _MIME Types', 'Configure _Key Commands', 'separator', - '_Reload Modules' + { locale.PM_BROWSER_MODULE_NEW, ID.NEW }, + { locale.PM_BROWSER_MODULE_DELETE, ID.DELETE }, + { locale.PM_BROWSER_MODULE_CONF_MIME_TYPES, ID.CONF_MIME_TYPES }, + { locale.PM_BROWSER_MODULE_CONF_KEY_COMMANDS, ID.CONF_KEY_COMMANDS }, + { 'separator', 0 }, + { locale.PM_BROWSER_MODULE_RELOAD, ID.RELOAD }, } end -function perform_menu_action(menu_item, selected_item) - if menu_item == 'New Module' then +function perform_menu_action(menu_item, menu_id, selected_item) + local locale = textadept.locale + if menu_id == ID.NEW then local status, module_name = cocoa_dialog( 'standard-inputbox', { - ['title'] = 'Module Name', - ['informative-text'] = 'Module name:' + ['title'] = locale.PM_BROWSER_MODULE_NEW_TITLE, + ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_INFO_TEXT } ):match('^(%d)%s+([^\n]+)%s+$') if status ~= '1' then return end local status, lang_name = cocoa_dialog( 'standard-inputbox', { - ['title'] = 'Language Name', - ['informative-text'] = 'Language name:' + ['title'] = locale.PM_BROWSER_MODULE_NEW_LANG_TITLE, + ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_LANG_INFO_TEXT } ):match('^(%d)%s+([^\n]+)%s+$') if status ~= '1' then return end local module_dir = _HOME..'/modules/'..module_name @@ -142,19 +151,19 @@ function perform_menu_action(menu_item, selected_item) f:write(out) f:close() else - cocoa_dialog( 'msgbox', { - ['text'] = 'Error', - ['informative-text'] = 'A module by that name already exists or\n'.. - 'you do not have permission to create the module.' + cocoa_dialog( 'ok-msgbox', { + ['text'] = locale.PM_BROWSER_MODULE_NEW_ERROR, + ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_ERROR_TEXT, + ['no-cancel'] = true } ) return end - elseif menu_item == 'Delete Module' then + elseif menu_id == ID.DELETE then local module_name = selected_item[2] if cocoa_dialog( 'yesno-msgbox', { - ['text'] = 'Delete Module?', - ['informative-text'] = 'Are you sure you want to permanently delete '.. - 'the "'..module_name..'" module?', + ['text'] = locale.PM_BROWSER_MODULE_DELETE_TITLE, + ['informative-text'] = + string.format( locale.PM_BROWSER_MODULE_DELETE_TEXT, module_name ), ['no-cancel'] = true, ['no-newline'] = true } ) == '1' then @@ -168,9 +177,9 @@ function perform_menu_action(menu_item, selected_item) else return end - elseif menu_item == 'Configure MIME Types' then + elseif menu_id == ID.CONF_MIME_TYPES then textadept.io.open(_HOME..'/core/ext/mime_types.lua') - elseif menu_item == 'Configure Key Commands' then + elseif menu_id == ID.CONF_KEY_COMMANDS then local textadept = textadept if textadept.key_commands then textadept.io.open(_HOME..'/core/ext/key_commands.lua') @@ -179,7 +188,7 @@ function perform_menu_action(menu_item, selected_item) elseif textadept.key_commands_mac then textadept.io.open(_HOME..'/core/ext/key_commands_mac.lua') end - elseif menu_item == 'Reload Modules' then + elseif menu_id == ID.RELOAD then textadept.reset() end textadept.pm.activate() diff --git a/core/ext/pm/project_browser.lua b/core/ext/pm/project_browser.lua index 8d147369..2dab8deb 100644 --- a/core/ext/pm/project_browser.lua +++ b/core/ext/pm/project_browser.lua @@ -73,29 +73,36 @@ function perform_action(selected_item) view:focus() end +local ID = { + NEW = 1, OPEN = 2, CLOSE = 3, NEW_FILE = 4, ADD_FILES = 5, NEW_DIR = 6, + ADD_DIR = 7, DELETE_FILE = 8, RENAME_FILE = 9 +} + --- Displays the project manager context menu. function get_context_menu(selected_item) + local locale = textadept.locale return { - 'separator', -- make it harder to click 'New Project' by mistake - '_New Project', - '_Open Project', - '_Close Project', - 'separator', - 'Add New File', - 'Add Existing Files', - 'Add New Directory', - 'Add Existing Director_y', - '_Delete', - '_Rename', + { 'separator', 0 }, -- make it harder to click 'New Project' by mistake + { locale.PM_BROWSER_PROJECT_NEW, ID.NEW }, + { locale.PM_BROWSER_PROJECT_OPEN, ID.OPEN }, + { locale.PM_BROWSER_PROJECT_CLOSE, ID.CLOSE }, + { 'separator', 0 }, + { locale.PM_BROWSER_PROJECT_NEW_FILE, ID.NEW_FILE }, + { locale.PM_BROWSER_PROJECT_ADD_FILES, ID.ADD_FILES }, + { locale.PM_BROWSER_PROJECT_NEW_DIR, ID.NEW_DIR }, + { locale.PM_BROWSER_PROJECT_ADD_DIR, ID.ADD_DIR }, + { locale.PM_BROWSER_PROJECT_DELETE_FILE, ID.DELETE_FILE }, + { locale.PM_BROWSER_PROJECT_RENAME_FILE, ID.RENAME_FILE }, } end -function perform_menu_action(menu_item, selected_item) - if menu_item == 'New Project' then +function perform_menu_action(menu_item, menu_id, selected_item) + local locale = textadept.locale + if menu_id == ID.NEW then -- Close all open files and prompt the user to save a project file. if textadept.io.close_all() then local file = cocoa_dialog( 'filesave', { - title = 'Save Project', + title = locale.PM_BROWSER_PROJECT_NEW_TITLE, ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), ['no-newline'] = true } ) @@ -106,11 +113,11 @@ function perform_menu_action(menu_item, selected_item) end end - elseif menu_item == 'Open Project' then + elseif menu_id == ID.OPEN then -- Close all open files and prompt the user for a project file to open. if textadept.io.close_all() then local file = cocoa_dialog( 'fileselect', { - title = 'Open Project', + title = locale.PM_BROWSER_PROJECT_OPEN_TITLE, ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), ['no-newline'] = true } ) @@ -120,7 +127,7 @@ function perform_menu_action(menu_item, selected_item) end end - elseif menu_item == 'Close Project' then + elseif menu_id == ID.CLOSE then -- Close all open files and clear the project variables. if textadept.io.close_all() then project_file = nil @@ -128,12 +135,12 @@ function perform_menu_action(menu_item, selected_item) textadept.pm.clear() end - elseif menu_item == 'Add New File' then + elseif menu_id == ID.NEW_FILE then -- If a project is open, prompts the user to save the new file. if project_file then local dir = get_live_parent_folder(selected_item) local file = cocoa_dialog( 'filesave', { - title = 'Save File', + title = locale.PM_BROWSER_PROJECT_NEW_FILE_TITLE, ['with-directory'] = dir or project_file:match('.+[/\\]'), ['no-newline'] = true } ) @@ -156,10 +163,9 @@ function perform_menu_action(menu_item, selected_item) -- project root instead. if dir and file:match('^(.+)[/\\]') ~= dir then local ret = cocoa_dialog( 'yesno-msgbox', { - text = 'Add to Project Root Instead?', - ['informative-text'] = 'You are adding a new file to a live '.. - 'folder which may not show up if the filepaths do not match.'.. - '\nAdd the file to the project root instead?', + text = locale.PM_BROWSER_PROJECT_NEW_FILE_LIVE_FOLDER_TITLE, + ['informative-text'] = + locale.PM_BROWSER_PROJECT_NEW_FILE_LIVE_FOLDER_TEXT, ['no-newline'] = true } ) if ret == '1' then add_file_to(project_root) end @@ -172,7 +178,7 @@ function perform_menu_action(menu_item, selected_item) end end - elseif menu_item == 'Add Existing Files' then + elseif menu_id == ID.ADD_FILES then -- If a project is open, prompts the user to add existing files. -- If the directory the files are being added to is a live folder, the user -- is asked to add the files to the project root instead of the live folder @@ -181,8 +187,8 @@ function perform_menu_action(menu_item, selected_item) -- not always apply when live folders are in a project. if project_file then local files = cocoa_dialog( 'fileselect', { - title = 'Select Files', - text = 'Select files to add to the project', + title = locale.PM_BROWSER_PROJECT_ADD_FILES_TITLE, + text = locale.PM_BROWSER_PROJECT_ADD_FILES_TEXT, -- in Windows, dialog:get_filenames() is unavailable; only allow single -- selection ['select-multiple'] = not WIN32 or nil, @@ -205,17 +211,16 @@ function perform_menu_action(menu_item, selected_item) add_files_to(project_folder) else if cocoa_dialog( 'yesno-msgbox', { - text = 'Add to Project Root Instead?', - ['informative-text'] = 'You are adding existing files to a live '.. - 'folder which is not possible.\nAdd them to the project root '.. - 'instead?', + text = locale.PM_BROWSER_PROJECT_ADD_FILES_LIVE_FOLDER_TITLE, + ['informative-text'] = + locale.PM_BROWSER_PROJECT_ADD_FILES_LIVE_FOLDER_TEXT, ['no-newline'] = true, } ) == '1' then add_files_to(project_root) end end end end - elseif menu_item == 'Add New Directory' then + elseif menu_id == ID.NEW_DIR then -- If a project is open, prompts the user for a directory name to add. -- This only works if the directory the directory is being added to is not a -- live directory. @@ -223,7 +228,7 @@ function perform_menu_action(menu_item, selected_item) -- does not always apply when live folders are in a project. if project_file then local ret, name = cocoa_dialog( 'standard-inputbox', { - ['informative-text'] = 'Directory Name?', + ['informative-text'] = locale.PM_BROWSER_PROJECT_NEW_DIR_TITLE, ['no-newline'] = true } ):match('^(%d)\n([^\n]+)$') if ret == '1' and name and #name > 0 then @@ -238,7 +243,7 @@ function perform_menu_action(menu_item, selected_item) end end - elseif menu_item == 'Add Existing Directory' then + elseif menu_id == ID.ADD_DIR then -- If a project is open, prompts the user for an existing directory to add. -- If the directory the directory being added to is a live folder, the user -- is asked to add the directory to the project root instead of the live @@ -247,8 +252,8 @@ function perform_menu_action(menu_item, selected_item) -- does not always apply when live folders are in a project. if project_file then local dir = cocoa_dialog( 'fileselect', { - title = 'Select Directory', - text = 'Select a directory to add to the project', + title = locale.PM_BROWSER_PROJECT_ADD_DIR_TITLE, + text = locale.PM_BROWSER_PROJECT_ADD_DIR_TEXT, ['select-only-directories'] = true, ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), ['no-newline'] = true @@ -266,17 +271,16 @@ function perform_menu_action(menu_item, selected_item) add_directory_to(project_folder) else if cocoa_dialog( 'yesno-msgbox', { - text = 'Add to Project Root Instead?', - ['informative-text'] = 'You are adding an existing directory to '.. - 'a live folder which is not possible.\nAdd it to the project '.. - 'root instead?', + text = locale.PM_BROWSER_PROJECT_ADD_DIR_LIVE_FOLDER_TITLE, + ['informative-text'] = + locale.PM_BROWSER_PROJECT_ADD_DIR_LIVE_FOLDER_TEXT, ['no-newline'] = true, } ) == '1' then add_directory_to(project_root) end end end end - elseif menu_item == 'Delete' then + elseif menu_id == ID.DELETE_FILE then -- If a project is open, deletes the file from the project unless it is -- contained in a live folder. if project_file then @@ -291,10 +295,9 @@ function perform_menu_action(menu_item, selected_item) for i, file in ipairs(project_folder) do if file == item then local ret = cocoa_dialog( 'yesno-msgbox', { - text = 'Keep on Disk?', - ['informative-text'] = 'This file will be removed from the '.. - 'project.\nLeave it on your computer? If not, it will be '.. - 'permanently deleted.', + text = locale.PM_BROWSER_PROJECT_DELETE_FILE_TITLE, + ['informative-text'] = + locale.PM_BROWSER_PROJECT_DELETE_FILE_TEXT, ['no-newline'] = true } ) if ret == '2' then os.remove(file) end @@ -319,10 +322,8 @@ function perform_menu_action(menu_item, selected_item) local parent_folder = get_parent_folder(selected_item) if item_is_dir and not parent_folder.is_live_folder then local ret = cocoa_dialog( 'yesno-msgbox', { - text = 'Keep on Disk?', - ['informative-text'] = 'This directory will be removed from the '.. - 'project.\nLeave it on your computer? If not, it will be '.. - 'permanently deleted.', + text = locale.PM_BROWSER_PROJECT_DELETE_DIR_TITLE, + ['informative-text'] = locale.PM_BROWSER_PROJECT_DELETE_DIR_TEXT, ['no-newline'] = true } ) if ret == '2' then remove_directory(item) end @@ -330,15 +331,13 @@ function perform_menu_action(menu_item, selected_item) parent_folder[item] = nil else if cocoa_dialog( 'msgbox', { - text = 'Delete Permanently?', - ['informative-text'] = 'You have selected a file from a live '.. - 'folder to delete.\nIt will be deleted permanently. Continue?\n'.. - '(To delete a live folder from the project, select the highest '.. - 'level live folder.)', + text = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_TITLE, + ['informative-text'] = + locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_TEXT, ['no-newline'] = true, - button1 = 'No', - button2 = 'Yes', - button3 = 'Cancel', + button1 = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_BUTTON1, + button2 = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_BUTTON2, + button3 = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_BUTTON3 } ) ~= '2' then return end if item_is_dir then remove_directory(item) else os.remove(item) end end @@ -347,11 +346,11 @@ function perform_menu_action(menu_item, selected_item) refresh_view() end - elseif menu_item == 'Rename' then + elseif menu_id == ID.RENAME_FILE then -- If a project is open, prompts the user for a new file/directory name. if project_file then local ret, name = cocoa_dialog( 'standard-inputbox', { - ['informative-text'] = 'New Name?', + ['informative-text'] = locale.PM_BROWSER_PROJECT_RENAME_FILE_TEXT, ['no-newline'] = true } ):match('^(%d)\n([^\n]+)$') if ret == '1' and name and #name > 0 then |