diff options
Diffstat (limited to 'core/ext/pm')
-rw-r--r-- | core/ext/pm/buffer_browser.lua | 13 | ||||
-rw-r--r-- | core/ext/pm/ctags_browser.lua | 12 | ||||
-rw-r--r-- | core/ext/pm/file_browser.lua | 15 | ||||
-rw-r--r-- | core/ext/pm/find_browser.lua | 3 | ||||
-rw-r--r-- | core/ext/pm/macro_browser.lua | 4 | ||||
-rw-r--r-- | core/ext/pm/modules_browser.lua | 28 | ||||
-rw-r--r-- | core/ext/pm/project_browser.lua | 142 |
7 files changed, 118 insertions, 99 deletions
diff --git a/core/ext/pm/buffer_browser.lua b/core/ext/pm/buffer_browser.lua index f4822226..73b09d55 100644 --- a/core/ext/pm/buffer_browser.lua +++ b/core/ext/pm/buffer_browser.lua @@ -23,8 +23,11 @@ end function perform_action(selected_item) local index = selected_item[2] - local buffer = textadept.buffers[ tonumber(index) ] - if buffer then view:goto_buffer(index) view:focus() end + local buffer = textadept.buffers[tonumber(index)] + if buffer then + view:goto_buffer(index) + view:focus() + end end local ID = { NEW = 1, OPEN = 2, SAVE = 3, SAVEAS = 4, CLOSE = 5 } @@ -47,13 +50,13 @@ function perform_menu_action(menu_item, menu_id, selected_item) elseif menu_id == ID.OPEN then textadept.io.open() elseif menu_id == ID.SAVE then - view:goto_buffer( tonumber( selected_item[2] ) ) + view:goto_buffer(tonumber(selected_item[2])) buffer:save() elseif menu_id == ID.SAVEAS then - view:goto_buffer( tonumber( selected_item[2] ) ) + view:goto_buffer(tonumber(selected_item[2])) buffer:save_as() elseif menu_id == ID.CLOSE then - view:goto_buffer( tonumber( selected_item[2] ) ) + view:goto_buffer(tonumber(selected_item[2])) buffer:close() end textadept.pm.activate() diff --git a/core/ext/pm/ctags_browser.lua b/core/ext/pm/ctags_browser.lua index 196eba5c..e1b4586d 100644 --- a/core/ext/pm/ctags_browser.lua +++ b/core/ext/pm/ctags_browser.lua @@ -112,7 +112,7 @@ function get_contents_for(full_path, expanding) tags = {} current_file = nil current_dir = '' -- ctags file will specify absolute paths - os.execute( 'ctags -f '..FILE_OUT..' '..(buffer.filename or '') ) + os.execute('ctags -f '..FILE_OUT..' '..(buffer.filename or '')) f = io.open(FILE_OUT) if not f then return {} end elseif not expanding then @@ -182,16 +182,16 @@ function get_contents_for(full_path, expanding) end entry.text = name -- The following keys are ignored by caller. - entry.filepath = filepath:sub(1, 1) == '/' and - filepath or current_dir..filepath + entry.filepath = + filepath:sub(1, 1) == '/' and filepath or current_dir..filepath entry.pattern = pattern entry.line_num = line_num if not entry.set then tags[name] = entry end else - print( string.format(locale.PM_BROWSER_CTAGS_BAD_EXT, file_ext) ) + print(string.format(locale.PM_BROWSER_CTAGS_BAD_EXT, file_ext)) end else - print( string.format(locale.PM_BROWSER_CTAGS_UNMATCHED, line) ) + print(string.format(locale.PM_BROWSER_CTAGS_UNMATCHED, line)) end end end @@ -217,7 +217,7 @@ function perform_action(selected_item) buffer:goto_line(line) else error( - string.format(textadept.locale.PM_BROWSER_CTAGS_NOT_FOUND, item.text) ) + string.format(textadept.locale.PM_BROWSER_CTAGS_NOT_FOUND, item.text)) end elseif item.line_num then textadept.io.open(item.filepath) diff --git a/core/ext/pm/file_browser.lua b/core/ext/pm/file_browser.lua index 17ae3be1..c658b6c0 100644 --- a/core/ext/pm/file_browser.lua +++ b/core/ext/pm/file_browser.lua @@ -58,17 +58,18 @@ function perform_menu_action(menu_item, menu_id, selected_item) elseif menu_id == ID.FILE_INFO then local date_format = '%D %T' local attr = lfs.attributes(filepath) - 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', { + 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'] = string.format(locale.PM_BROWSER_FILE_INFO_TEXT, filepath), text = out, button1 = locale.PM_BROWSER_FILE_INFO_OK, editable = false - } ) + }) end end diff --git a/core/ext/pm/find_browser.lua b/core/ext/pm/find_browser.lua index f722664e..a8722e78 100644 --- a/core/ext/pm/find_browser.lua +++ b/core/ext/pm/find_browser.lua @@ -59,7 +59,8 @@ function get_contents_for(full_path, expanding) p = io.popen('grep -'..opts..' "'..search_string..'" "'.. search_directory..'"') for line in p:lines() do - local filename, line_num, line_text = line:match('^([^:]+):(%d+):%s-(.+)$') + local filename, line_num, line_text = + line:match('^([^:]+):(%d+):%s-(.+)$') if filename and line_num and line_text then if not find_matches[filename] then find_matches[filename] = { diff --git a/core/ext/pm/macro_browser.lua b/core/ext/pm/macro_browser.lua index e1394e5c..c2892fa7 100644 --- a/core/ext/pm/macro_browser.lua +++ b/core/ext/pm/macro_browser.lua @@ -19,7 +19,7 @@ function get_contents_for() end function perform_action(selected_item) - _m.textadept.macros.play( selected_item[2] ) + _m.textadept.macros.play(selected_item[2]) view:focus() end @@ -33,7 +33,7 @@ end function perform_menu_action(menu_item, menu_id, selected_item) local m_macros = _m.textadept.macros if menu_id == ID.DELETE then - m_macros.delete( selected_item[2] ) + m_macros.delete(selected_item[2]) end textadept.pm.activate() end diff --git a/core/ext/pm/modules_browser.lua b/core/ext/pm/modules_browser.lua index 95a5bd9f..4fc97206 100644 --- a/core/ext/pm/modules_browser.lua +++ b/core/ext/pm/modules_browser.lua @@ -123,15 +123,17 @@ end 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'] = locale.PM_BROWSER_MODULE_NEW_TITLE, - ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_INFO_TEXT - } ):match('^(%d)%s+([^\n]+)%s+$') + local status, module_name = + cocoa_dialog('standard-inputbox', { + ['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'] = locale.PM_BROWSER_MODULE_NEW_LANG_TITLE, - ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_LANG_INFO_TEXT - } ):match('^(%d)%s+([^\n]+)%s+$') + local status, lang_name = + cocoa_dialog('standard-inputbox', { + ['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 if lfs.mkdir(module_dir) then @@ -151,22 +153,22 @@ function perform_menu_action(menu_item, menu_id, selected_item) f:write(out) f:close() else - cocoa_dialog( 'ok-msgbox', { + 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_id == ID.DELETE then local module_name = selected_item[2] - if cocoa_dialog( 'yesno-msgbox', { + if cocoa_dialog('yesno-msgbox', { ['text'] = locale.PM_BROWSER_MODULE_DELETE_TITLE, ['informative-text'] = - string.format( locale.PM_BROWSER_MODULE_DELETE_TEXT, module_name ), + string.format(locale.PM_BROWSER_MODULE_DELETE_TEXT, module_name), ['no-cancel'] = true, ['no-newline'] = true - } ) == '1' then + }) == '1' then local function remove_directory(dirpath) for name in lfs.dir(dirpath) do if not name:match('^%.%.?$') then os.remove(dirpath..'/'..name) end diff --git a/core/ext/pm/project_browser.lua b/core/ext/pm/project_browser.lua index 2dab8deb..30c6a847 100644 --- a/core/ext/pm/project_browser.lua +++ b/core/ext/pm/project_browser.lua @@ -69,7 +69,7 @@ end --- Opens the selected project file. function perform_action(selected_item) - textadept.io.open( selected_item[#selected_item] ) + textadept.io.open(selected_item[#selected_item]) view:focus() end @@ -101,11 +101,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) 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 = locale.PM_BROWSER_PROJECT_NEW_TITLE, - ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), - ['no-newline'] = true - } ) + local file = + cocoa_dialog('filesave', { + title = locale.PM_BROWSER_PROJECT_NEW_TITLE, + ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), + ['no-newline'] = true + }) if #file > 0 then project_file = file project_root = {} @@ -116,11 +117,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) 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 = locale.PM_BROWSER_PROJECT_OPEN_TITLE, - ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), - ['no-newline'] = true - } ) + local file = + cocoa_dialog('fileselect', { + title = locale.PM_BROWSER_PROJECT_OPEN_TITLE, + ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), + ['no-newline'] = true + }) if #file > 0 then load_project(file) refresh_view() @@ -139,11 +141,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- 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 = locale.PM_BROWSER_PROJECT_NEW_FILE_TITLE, - ['with-directory'] = dir or project_file:match('.+[/\\]'), - ['no-newline'] = true - } ) + local file = + cocoa_dialog('filesave', { + title = locale.PM_BROWSER_PROJECT_NEW_FILE_TITLE, + ['with-directory'] = dir or project_file:match('.+[/\\]'), + ['no-newline'] = true + }) if #file > 0 then local function add_file_to(pfolder) local exists = false @@ -162,17 +165,20 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- caution them about unexpected behavior and ask to save in the -- project root instead. if dir and file:match('^(.+)[/\\]') ~= dir then - local ret = cocoa_dialog( 'yesno-msgbox', { - text = locale.PM_BROWSER_PROJECT_NEW_FILE_LIVE_FOLDER_TITLE, - ['informative-text'] = - locale.PM_BROWSER_PROJECT_NEW_FILE_LIVE_FOLDER_TEXT, - ['no-newline'] = true - } ) + local ret = + cocoa_dialog('yesno-msgbox', { + 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 if ret == '3' then return end end end - local f = io.open(file, 'w') f:write('') f:close() + local f = io.open(file, 'w') + f:write('') + f:close() update_project() refresh_view() end @@ -186,14 +192,15 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- Files are added if they do not already exist in the project. This does -- not always apply when live folders are in a project. if project_file then - local files = cocoa_dialog( 'fileselect', { - 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, - ['with-directory'] = (buffer.filename or project_file):match('.+[/\\]') - } ) + local files = + cocoa_dialog('fileselect', { + 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, + ['with-directory'] = (buffer.filename or project_file):match('.+[/\\]') + }) if #files > 0 then local function add_files_to(pfolder) for file in files:gmatch('[^\n]+') do @@ -210,12 +217,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) if not project_folder.is_live_folder then add_files_to(project_folder) else - if cocoa_dialog( 'yesno-msgbox', { + if cocoa_dialog('yesno-msgbox', { 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 + }) == '1' then add_files_to(project_root) end end end end @@ -227,16 +234,17 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- The directory is added if it does not already exist in the project. This -- does not always apply when live folders are in a project. if project_file then - local ret, name = cocoa_dialog( 'standard-inputbox', { - ['informative-text'] = locale.PM_BROWSER_PROJECT_NEW_DIR_TITLE, - ['no-newline'] = true - } ):match('^(%d)\n([^\n]+)$') + local ret, name = + cocoa_dialog('standard-inputbox', { + ['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 local project_folder = get_parent_folder(selected_item) if not project_folder.is_live_folder then if not project_folder[name] then project_folder[name] = {} end else - lfs.mkdir( get_live_parent_folder(selected_item)..'/'..name ) + lfs.mkdir(get_live_parent_folder(selected_item)..'/'..name) end update_project() refresh_view() @@ -251,13 +259,14 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- The directory is added if it does not already exist in the project. This -- does not always apply when live folders are in a project. if project_file then - local dir = cocoa_dialog( 'fileselect', { - 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 - } ) + local dir = + cocoa_dialog('fileselect', { + 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 + }) if #dir > 0 then local function add_directory_to(pfolder) if not pfolder[dir] then @@ -270,12 +279,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) if not project_folder.is_live_folder then add_directory_to(project_folder) else - if cocoa_dialog( 'yesno-msgbox', { + if cocoa_dialog('yesno-msgbox', { 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 + }) == '1' then add_directory_to(project_root) end end end end @@ -294,12 +303,13 @@ function perform_menu_action(menu_item, menu_id, selected_item) else -- file for i, file in ipairs(project_folder) do if file == item then - local ret = cocoa_dialog( 'yesno-msgbox', { - text = locale.PM_BROWSER_PROJECT_DELETE_FILE_TITLE, - ['informative-text'] = - locale.PM_BROWSER_PROJECT_DELETE_FILE_TEXT, - ['no-newline'] = true - } ) + local ret = + cocoa_dialog('yesno-msgbox', { + 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 if ret == '3' then return end table.remove(project_folder, i) @@ -321,16 +331,17 @@ function perform_menu_action(menu_item, menu_id, selected_item) table.remove(selected_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 = locale.PM_BROWSER_PROJECT_DELETE_DIR_TITLE, - ['informative-text'] = locale.PM_BROWSER_PROJECT_DELETE_DIR_TEXT, - ['no-newline'] = true - } ) + local ret = + cocoa_dialog('yesno-msgbox', { + 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 if ret == '3' then return end parent_folder[item] = nil else - if cocoa_dialog( 'msgbox', { + if cocoa_dialog('msgbox', { text = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_TITLE, ['informative-text'] = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_TEXT, @@ -338,7 +349,7 @@ function perform_menu_action(menu_item, menu_id, selected_item) 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 + }) ~= '2' then return end if item_is_dir then remove_directory(item) else os.remove(item) end end end @@ -349,10 +360,11 @@ function perform_menu_action(menu_item, menu_id, selected_item) 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'] = locale.PM_BROWSER_PROJECT_RENAME_FILE_TEXT, - ['no-newline'] = true - } ):match('^(%d)\n([^\n]+)$') + local ret, name = + cocoa_dialog('standard-inputbox', { + ['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 local oldname = selected_item[#selected_item] local newname = oldname:match('^.+[/\\]')..name @@ -457,7 +469,7 @@ get_live_parent_folder = function(selected_item) local dir = nil if get_parent_folder(selected_item).is_live_folder then if lfs.attributes( - selected_item[#selected_item], 'mode' ) == 'directory' then + selected_item[#selected_item], 'mode') == 'directory' then dir = selected_item[#selected_item] else dir = selected_item[#selected_item - 1] |