diff options
Diffstat (limited to 'core/ext/pm')
-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 |
7 files changed, 136 insertions, 110 deletions
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 |