aboutsummaryrefslogtreecommitdiffhomepage
path: root/core/ext
diff options
context:
space:
mode:
Diffstat (limited to 'core/ext')
-rw-r--r--core/ext/key_commands.lua38
-rw-r--r--core/ext/pm.lua60
-rw-r--r--core/ext/pm/buffer_browser.lua91
-rw-r--r--core/ext/pm/ctags_browser.lua253
-rw-r--r--core/ext/pm/file_browser.lua111
-rw-r--r--core/ext/pm/modules_browser.lua210
6 files changed, 0 insertions, 763 deletions
diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua
index 738199e6..6181d378 100644
--- a/core/ext/key_commands.lua
+++ b/core/ext/key_commands.lua
@@ -246,25 +246,6 @@ if not MAC then
-- TODO: { function() view.size = view.size - 10 end }
}
- -- Project Manager
- local function pm_activate(text)
- t.pm.entry_text = text
- t.pm.activate()
- end
- keys.cP = { function() if t.pm.width > 0 then t.pm.toggle_visible() end end }
- keys.cp = {
- function()
- if t.pm.width == 0 then t.pm.toggle_visible() end
- t.pm.focus()
- end
- }
- keys.cap = {
- c = { pm_activate, 'ctags' },
- b = { pm_activate, 'buffers' },
- f = { pm_activate, '/' },
- m = { pm_activate, 'modules' },
- }
-
-- Miscellaneous not in standard menu.
-- Recent files.
local RECENT_FILES = 1
@@ -426,25 +407,6 @@ else
-- TODO: { function() view.size = view.size - 10 end }
}
- -- Project Manager
- local function pm_activate(text)
- t.pm.entry_text = text
- t.pm.activate()
- end
- keys.aP = { function() if t.pm.width > 0 then t.pm.toggle_visible() end end }
- keys.ap = {
- function()
- if t.pm.width == 0 then t.pm.toggle_visible() end
- t.pm.focus()
- end
- }
- keys.cap = {
- c = { pm_activate, 'ctags' },
- b = { pm_activate, 'buffers' },
- f = { pm_activate, '/' },
- m = { pm_activate, 'modules' },
- }
-
-- Miscellaneous not in standard menu.
-- Recent files.
local RECENT_FILES = 1
diff --git a/core/ext/pm.lua b/core/ext/pm.lua
deleted file mode 100644
index cec2fd5b..00000000
--- a/core/ext/pm.lua
+++ /dev/null
@@ -1,60 +0,0 @@
--- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE.
-
-local pm = textadept.pm
-
-local current_browser = nil
-
--- For restoring browser cursors
-local last_browser_text = nil
-local browser_cursors = {}
-
-textadept.events.add_handler('pm_contents_request',
- function(full_path, expanding)
- for _, browser in pairs(pm.browsers) do
- if browser.matches(full_path[1]) then
- current_browser = browser
- if last_browser_text and last_browser_text ~= pm.entry_text then
- -- Switching browsers, save the current one's cursor.
- -- Don't reset last_browser_text here though, we still need to detect
- -- the switch when the 'pm_view_filled' event is called so as to restore
- -- the cursor to the new browser.
- browser_cursors[last_browser_text] = pm.cursor
- end
- pm.fill(browser.get_contents_for(full_path, expanding), expanding)
- textadept.events.handle('pm_view_filled')
- end
- end
- end)
-
-textadept.events.add_handler('pm_item_selected',
- function(selected_item) current_browser.perform_action(selected_item) end)
-
-textadept.events.add_handler('pm_context_menu_request',
- function(selected_item, event)
- local menu = current_browser.get_context_menu(selected_item)
- if menu then pm.show_context_menu(menu, event) end
- end)
-
-textadept.events.add_handler('pm_menu_clicked',
- function(menu_id, selected_item)
- current_browser.perform_menu_action(menu_id, selected_item)
- end)
-
--- LuaDoc is in core/.browser.lua.
-function pm.toggle_visible()
- if pm.width > 0 then
- pm.prev_width = pm.width
- pm.width = 0
- else
- pm.width = pm.prev_width or 150
- end
-end
-
-textadept.events.add_handler('pm_view_filled',
- function() -- try to restore previous browser cursor
- if last_browser_text ~= pm.entry_text then
- last_browser_text = pm.entry_text
- local previous_cursor = browser_cursors[pm.entry_text]
- if previous_cursor then pm.cursor = previous_cursor end
- end
- end)
diff --git a/core/ext/pm/buffer_browser.lua b/core/ext/pm/buffer_browser.lua
deleted file mode 100644
index a97db8ea..00000000
--- a/core/ext/pm/buffer_browser.lua
+++ /dev/null
@@ -1,91 +0,0 @@
--- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE.
-
-local textadept = _G.textadept
-local locale = _G.locale
-
----
--- Buffer browser for the Textadept project manager.
--- It is enabled with the prefix 'buffers' in the project manager entry field.
-module('textadept.pm.browsers.buffer', package.seeall)
-
-if not RESETTING then textadept.pm.add_browser('buffers') end
-
-function matches(entry_text)
- return entry_text:sub(1, 7) == 'buffers'
-end
-
-function get_contents_for()
- local contents = {}
- for index, buffer in ipairs(textadept.buffers) do
- index = string.format("%02i", index)
- contents[index] = {
- pixbuf = buffer.dirty and 'gtk-edit' or 'gtk-file',
- text =
- (buffer.filename or buffer._type or locale.UNTITLED):match('[^/\\]+$')
- }
- end
- return contents
-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
-end
-
-local ID = { NEW = 1, OPEN = 2, SAVE = 3, SAVEAS = 4, CLOSE = 5 }
-
-function get_context_menu(selected_item)
- 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_id, selected_item)
- if menu_id == ID.NEW then
- textadept.new_buffer()
- elseif menu_id == ID.OPEN then
- textadept.io.open()
- elseif menu_id == ID.SAVE then
- view:goto_buffer(tonumber(selected_item[2]))
- buffer:save()
- elseif menu_id == ID.SAVEAS then
- view:goto_buffer(tonumber(selected_item[2]))
- buffer:save_as()
- elseif menu_id == ID.CLOSE then
- view:goto_buffer(tonumber(selected_item[2]))
- buffer:close()
- end
- textadept.pm.activate()
-end
-
-local function update_view()
- if matches(textadept.pm.entry_text) then textadept.pm.activate() end
-end
-textadept.events.add_handler('file_opened', update_view)
-textadept.events.add_handler('buffer_new', update_view)
-textadept.events.add_handler('buffer_deleted', update_view)
-textadept.events.add_handler('save_point_reached', update_view)
-textadept.events.add_handler('save_point_left', update_view)
-textadept.events.add_handler('buffer_after_switch', update_view)
-textadept.events.add_handler('view_after_switch', update_view)
-
-local function set_cursor()
- if matches(textadept.pm.entry_text) then
- for idx, buf in ipairs(textadept.buffers) do
- if buf == buffer then
- textadept.pm.cursor = idx - 1
- break
- end
- end
- end
-end
-textadept.events.add_handler('pm_view_filled', set_cursor)
diff --git a/core/ext/pm/ctags_browser.lua b/core/ext/pm/ctags_browser.lua
deleted file mode 100644
index db2ea27e..00000000
--- a/core/ext/pm/ctags_browser.lua
+++ /dev/null
@@ -1,253 +0,0 @@
--- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE.
-
-local textadept = _G.textadept
-local locale = _G.locale
-
----
--- CTags Browser for the Textadept project manager.
--- It is enabled with the prefix 'ctags' in the project manager entry field
--- followed by either nothing or ':' and the path to a ctags file. If no path
--- is specified, the current file is parsed via ctags and its structure shown.
-module('textadept.pm.browsers.ctags', package.seeall)
-
-if not RESETTING then textadept.pm.add_browser('ctags') end
-
-local FILE_OUT = '/tmp/textadept_output'
-
----
--- The current ctags file and current directory.
--- When a ctags file is opened, current_dir is set to its dirname.
-local current_file, current_dir
-
----
--- The table of ctags with property values.
--- Each key is the name of a ctags identifier (function, class, etc.) and the
--- value is a table containing:
--- * The GTK stock-id for the pixbuf to display next to the identifier in the
--- tree view (pixbuf key).
--- * The display text used for displaying the identifier in the tree view
--- (text key).
--- * Boolean parent value if the identifier is a container.
--- * The line number or pattern used to goto the identifier.
--- Note this table is returned by get_contents_for, but only 'pixbuf',
--- 'text' and 'parent' fields are read; all others are ignored.
--- @class table
--- @name tags
-local tags
-
----
--- Table of associations of tag identifier types for specific languages with
--- GTK stock-id pixbufs.
--- @class table
--- @name pixbuf
-local pixbuf = {
- lua = { f = 'prog-method' },
- ruby = {
- c = 'prog-class',
- f = 'prog-method',
- F = 'prog-method',
- m = 'prog-namespace'
- },
- cpp = {
- c = 'prog-class',
- e = 'prog-enum',
- f = 'prog-method',
- g = 'prog-enum',
- m = 'prog-field',
- n = 'prog-namespace',
- s = 'prog-struct'
- }
-}
-
----
--- Table of associations of file extensions with languages.
--- @class table
--- @name language
-local language = {
- lua = 'lua',
- rb = 'ruby',
- h = 'cpp', c = 'cpp', cxx = 'cpp' -- C++
-}
-
----
--- Table used to determine if a tag kind is a container or not in a specific
--- language.
--- Top-level keys are language names from the languages table with table
--- values. These table values have tag kind keys with boolean values indicating
--- if they are containers or not.
--- @class table
--- @name container
--- @return true if the tag kind is a container.
--- @see language
-local container = {
- lua = {},
- ruby = { c = true, m = true },
- cpp = { c = true, g = true, s = true }
-}
-
----
--- Table used to determine if a construct name is a container or not in a
--- specific language.
--- Top-level keys are language names from the languages table with table
--- values. These table values have construct name keys with boolean values
--- indicating if they are containers or not.
--- @class table
--- @name container_construct
--- @return true if the construct name is a container.
--- @see language
-local container_construct = {
- lua = {},
- ruby = { class = true, module = true },
- cpp = { class = true, enum = true, struct = true }
-}
-
---- Matches 'ctags:[/absolute/path/to/ctags/file]'
-function matches(entry_text)
- return entry_text:sub(1, 5) == 'ctags'
-end
-
----
--- If not expanding, creates the entire tree; otherwise returns the child table
--- of the parent being expanded.
-function get_contents_for(full_path, expanding)
- local ctags_file = full_path[1]:sub(7) -- ignore 'ctags:'
- local f
- if #ctags_file == 0 then
- tags = {}
- current_file = nil
- current_dir = '' -- ctags file will specify absolute paths
- os.execute('ctags -f "'..FILE_OUT..'" '..(buffer.filename or ''))
- f = io.open(FILE_OUT, 'rb')
- if not f then return {} end
- elseif not expanding then
- tags = {}
- current_file = ctags_file
- current_dir = ctags_file:match('^.+/') -- ctags file dirname
- f = io.open(ctags_file, 'rb')
- if not f then return {} end
- else
- local parent = tags
- for i = 2, #full_path do
- local identifier = full_path[i]
- if not parent[identifier] then return {} end
- parent = parent[identifier].children
- end
- return parent
- end
- for line in f:lines() do
- if line:sub(1, 2) ~= '!_' then
- -- Parse ctags line to get identifier attributes.
- local name, filepath, pattern, line_num, ext
- name, filepath, pattern, ext =
- line:match('^([^\t]+)\t([^\t]+)\t/^(.+)$/;"\t(.*)$')
- if not name then
- name, filepath, line_num, ext =
- line:match('^([^\t]+)\t([^\t]+)\t(%d+);"\t(.*)$')
- end
- -- If the ctag line is parsed correctly, create the entry.
- if name and #name > 0 then
- local entry = {}
- local file_ext = filepath:match('%.([^.]+)$')
- local lang = language[file_ext]
- if lang then
- -- Parse the extension fields for details on if this identifier is a
- -- child or parent and where to put it.
- local fields = {}
- --print(ext)
- for key, val in ext:gmatch('([^:%s]+):?(%S*)') do
- if #val == 0 and #key == 1 then -- kind
- if container[lang][key] then
- -- This identifier is a container. Place it in the toplevel of
- -- tags.
- entry.parent = true
- entry.children = {}
- if tags[name] then
- -- If previously defined by a child, preserve the children
- -- field.
- entry.children = tags[name].children
- end
- tags[name] = entry
- entry.set = true
- end
- entry.pixbuf = pixbuf[lang][key]
- elseif container_construct[lang][key] then
- -- This identifier belongs to a container, so define the
- -- container if it hasn't been already and place this identifier
- -- in it. Just in case there is no ctag entry for container later
- -- on, define 'parent' and 'text'.
- if not tags[val] then
- tags[val] = { parent = true, text = val }
- end
- local parent = tags[val]
- if not parent.children then parent.children = {} end
- parent.children[name] = entry -- add to parent
- entry.set = true
- end
- end
- entry.text = name
- -- The following keys are ignored by caller.
- 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))
- end
- else
- print(string.format(locale.PM_BROWSER_CTAGS_UNMATCHED, line))
- end
- end
- end
- f:close()
- return tags
-end
-
-function perform_action(selected_item)
- local item = tags
- for i = 2, #selected_item do
- local identifier = selected_item[i]
- item = item[identifier]
- if item.children then item = item.children end
- end
- if item.pattern then
- local buffer_text = buffer:get_text(buffer.length)
- local search_text = item.pattern:gsub('\\/', '/')
- local s = buffer_text:find(search_text, 1, true)
- if s then
- textadept.io.open(item.filepath)
- local line = buffer:line_from_position(s)
- buffer:ensure_visible_enforce_policy(line)
- buffer:goto_line(line)
- else
- error(
- string.format(locale.PM_BROWSER_CTAGS_NOT_FOUND, item.text))
- end
- elseif item.line_num then
- textadept.io.open(item.filepath)
- buffer:goto_line(item.line_num - 1)
- end
- view:focus()
-end
-
-function get_context_menu(selected_item)
-
-end
-
-function perform_menu_action(menu_id, selected_item)
-
-end
-
-local function update_view()
- if matches(textadept.pm.entry_text) then
- if buffer.filename then
- textadept.pm.activate()
- else
- textadept.pm.clear()
- end
- end
-end
-textadept.events.add_handler('file_opened', update_view)
-textadept.events.add_handler('buffer_deleted', update_view)
-textadept.events.add_handler('buffer_after_switch', update_view)
-textadept.events.add_handler('save_point_reached', update_view)
diff --git a/core/ext/pm/file_browser.lua b/core/ext/pm/file_browser.lua
deleted file mode 100644
index 69d3fe76..00000000
--- a/core/ext/pm/file_browser.lua
+++ /dev/null
@@ -1,111 +0,0 @@
--- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE.
-
-local textadept = _G.textadept
-local locale = _G.locale
-
----
--- File browser for the Textadept project manager.
--- It is enabled by providing the absolute path to a directory in the project
--- manager entry field.
-module('textadept.pm.browsers.file', package.seeall)
-
-if not RESETTING then textadept.pm.add_browser(not WIN32 and '/' or 'C:\\') end
-
-local lfs = require 'lfs'
-local os = require 'os'
-
-show_dot_files = false
-
-function matches(entry_text)
- if not WIN32 then
- return entry_text:sub(1, 1) == '/'
- else
- return entry_text:match('[A-Za-z]:[\\/]')
- end
-end
-
-function get_contents_for(full_path)
- local iconv = textadept.iconv
- local dir = {}
- local dirpath = iconv(table.concat(full_path, '/'), _CHARSET, 'UTF-8')
- local path = lfs.attributes(dirpath)
- if path and path.mode == 'directory' then
- local invalid_file = show_dot_files and '^%.%.?$' or '^%.'
- for filename in lfs.dir(dirpath) do
- if not filename:find(invalid_file) then
- local utf8_filename = iconv(filename, 'UTF-8', _CHARSET)
- dir[utf8_filename] = { text = utf8_filename }
- if lfs.attributes(dirpath..'/'..filename, 'mode') == 'directory' then
- dir[utf8_filename].parent = true
- dir[utf8_filename].pixbuf = 'gtk-directory'
- end
- end
- end
- end
- return dir
-end
-
-function perform_action(selected_item)
- local utf8_filepath = table.concat(selected_item, '/')
- textadept.io.open(utf8_filepath)
- view:focus()
-end
-
-local ID = { CHANGE_DIR = 1, FILE_INFO = 2, SHOW_DOT_FILES = 3 }
-
-function get_context_menu(selected_item)
- 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 },
- { locale.PM_BROWSER_FILE_SHOW_DOT_FILES, ID.SHOW_DOT_FILES },
- }
-end
-
-function perform_menu_action(menu_id, selected_item)
- local utf8_filepath = table.concat(selected_item, '/'):gsub('[/\\]+', '/')
- local filepath = textadept.iconv(utf8_filepath, _CHARSET, 'UTF-8')
- if menu_id == ID.CHANGE_DIR then
- textadept.pm.entry_text = utf8_filepath
- textadept.pm.activate()
- 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))
- textadept.dialog('textbox',
- '--informative-text',
- string.format(locale.PM_BROWSER_FILE_INFO_TEXT,
- utf8_filepath),
- '--text', out,
- '--button1', locale.PM_BROWSER_FILE_INFO_OK)
- elseif menu_id == ID.SHOW_DOT_FILES then
- show_dot_files = not show_dot_files
- textadept.pm.activate()
- end
-end
-
--- load the dropped directory (if any) into the file browser; events.lua's
--- "uri_dropped" handler already opens dropped files
-textadept.events.add_handler('uri_dropped',
- function(utf8_uris)
- local lfs = require 'lfs'
- for utf8_uri in utf8_uris:gmatch('[^\r\n\f]+') do
- if utf8_uri:find('^file://') then
- utf8_uri = utf8_uri:match('^file://([^\r\n\f]+)')
- utf8_uri = utf8_uri:gsub('%%(%x%x)',
- function(hex) return string.char(tonumber(hex, 16)) end)
- if WIN32 then utf8_uri = utf8_uri:sub(2, -1) end -- ignore leading '/'
- local uri = textadept.iconv(utf8_uri, _CHARSET, 'UTF-8')
- if lfs.attributes(uri).mode == 'directory' then
- textadept.pm.add_browser(utf8_uri)
- textadept.pm.entry_text = utf8_uri
- textadept.pm.activate()
- end
- end
- end
- end)
diff --git a/core/ext/pm/modules_browser.lua b/core/ext/pm/modules_browser.lua
deleted file mode 100644
index 1d615e76..00000000
--- a/core/ext/pm/modules_browser.lua
+++ /dev/null
@@ -1,210 +0,0 @@
--- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE.
-
-local textadept = _G.textadept
-local locale = _G.locale
-
----
--- Modules browser for the Textadept project manager.
--- It is enabled with the prefix 'modules' in the project manager entry field.
-module('textadept.pm.browsers.modules', package.seeall)
-
-if not RESETTING then textadept.pm.add_browser('modules') end
-
-local lfs = require 'lfs'
-local os = require 'os'
-
-local INIT = [[
--- The $1 module.
--- It provides utilities for editing $2 code.
-module('_m.$1', package.seeall)
-
-if type(_G.snippets) == 'table' then
--- Container for $2-specific snippets.
--- @class table
--- @name snippets.$1
- _G.snippets.$1 = {}
-end
-
-if type(_G.keys) == 'table' then
--- Container for $2-specific key commands.
--- @class table
--- @name keys.$1
- _G.keys.$1 = {}
-end
-
-require '$1.commands'
-require '$1.snippets'
-
-function set_buffer_properties()
-
-end
-]]
-
-local SNIPPETS = [[
--- Snippets for the $1 module.
-module('_m.$1.snippets', package.seeall)
-
-local snippets = _G.snippets
-
-if type(snippets) == 'table' then
- snippets.$1 = {}
-end
-]]
-
-local COMMANDS = [[
--- Commands for the $1 module.
-module('_m.$1.commands', package.seeall)
-
--- $2-specific key commands.
-local keys = _G.keys
-if type(keys) == 'table' then
- keys.$1 = {
- al = {
- m = { textadept.io.open,
- textadept.iconv(_USERHOME..'/modules/$1/init.lua',
- 'UTF-8', _CHARSET) },
- },
- }
-end
-]]
-
-function matches(entry_text)
- return entry_text:sub(1, 7) == 'modules'
-end
-
-function get_contents_for(full_path)
- local dir = {}
- local iconv = textadept.iconv
- if #full_path == 1 and full_path[1] == 'modules' then
- -- toplevel modules
- local dirpaths = {
- iconv(_USERHOME..'/modules', _CHARSET, 'UTF-8'),
- iconv(_HOME..'/modules', _CHARSET, 'UTF-8')
- }
- for _, dirpath in ipairs(dirpaths) do
- if lfs.attributes(dirpath) then
- for filename in lfs.dir(dirpath) do
- local filepath = dirpath..'/'..filename
- if lfs.attributes(filepath, 'mode') == 'directory' and
- not filename:find('^%.') then
- dir[filepath] = {
- parent = true,
- pixbuf = 'gtk-directory',
- text = iconv(filename, 'UTF-8', _CHARSET)
- }
- end
- end
- end
- end
- else
- -- expanding a module
- local dirpath = iconv(full_path[#full_path], _CHARSET, 'UTF-8')
- for filename in lfs.dir(dirpath) do
- if not filename:find('^%.') then
- local filepath = dirpath..'/'..filename
- dir[filepath] = { text = iconv(filename, 'UTF-8', _CHARSET) }
- if lfs.attributes(filepath, 'mode') == 'directory' then
- dir[filepath].parent = true
- dir[filepath].pixbuf = 'gtk-directory'
- end
- end
- end
- end
- return dir
-end
-
-function perform_action(selected_item)
- local filepath = selected_item[#selected_item]
- textadept.io.open(filepath)
- 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)
- return {
- { 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_id, selected_item)
- if menu_id == ID.NEW then
- local status, module_name =
- textadept.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 =
- textadept.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
- lfs.mkdir(_USERHOME..'/modules')
- local module_dir = _USERHOME..'/modules/'..module_name
- if lfs.mkdir(module_dir) then
- -- write init.lua from template
- local f = io.open(module_dir..'/init.lua', 'wb')
- local out = INIT:gsub('$1', module_name):gsub('$2', lang_name)
- f:write(out)
- f:close()
- -- write snippets.lua from template
- f = io.open(module_dir..'/snippets.lua', 'wb')
- out = SNIPPETS:gsub('$1', module_name):gsub('$2', lang_name)
- f:write(out)
- f:close()
- -- write commands.lua from template
- f = io.open(module_dir..'/commands.lua', 'wb')
- out = COMMANDS:gsub('$1', module_name):gsub('$2', lang_name)
- f:write(out)
- f:close()
- else
- textadept.dialog('ok-msgbox',
- '--text', locale.PM_BROWSER_MODULE_NEW_ERROR,
- '--informative-text',
- locale.PM_BROWSER_MODULE_NEW_ERROR_TEXT,
- '--no-cancel')
- return
- end
- elseif menu_id == ID.DELETE then
- local dirpath = selected_item[2]
- if textadept.dialog('yesno-msgbox',
- '--text', locale.PM_BROWSER_MODULE_DELETE_TITLE,
- '--informative-text',
- string.format(locale.PM_BROWSER_MODULE_DELETE_TEXT,
- dirpath:match('[^/\\]+$')),
- '--no-cancel',
- '--no-newline') == '1' then
- local function remove_directory(dirpath)
- for name in lfs.dir(dirpath) do
- if not name:find('^%.%.?$') then os.remove(dirpath..'/'..name) end
- end
- lfs.rmdir(dirpath)
- end
- remove_directory(dirpath)
- else
- return
- end
- elseif menu_id == ID.CONF_MIME_TYPES then
- textadept.io.open(
- textadept.iconv(_HOME..'/core/ext/mime_types.lua', 'UTF-8', _CHARSET))
- elseif menu_id == ID.CONF_KEY_COMMANDS then
- if textadept.key_commands then
- textadept.io.open(
- textadept.iconv(_HOME..'/core/ext/key_commands.lua', 'UTF-8', _CHARSET))
- end
- elseif menu_id == ID.RELOAD then
- textadept.reset()
- end
- textadept.pm.activate()
-end