From acda712a50dbebafa295ccd07ce8186d9b82aa10 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Mon, 26 Aug 2013 21:47:55 -0400 Subject: Renamed `gui` to `ui` since it's more applicable. --- core/events.lua | 12 +- core/file_io.lua | 90 +++---- core/gui.lua | 456 ------------------------------------ core/init.lua | 8 +- core/keys.lua | 12 +- core/ui.lua | 456 ++++++++++++++++++++++++++++++++++++ doc/06_AdeptEditing.md | 2 +- doc/09_Themes.md | 12 +- doc/10_Advanced.md | 10 +- doc/14_Appendix.md | 45 ++-- init.lua | 2 +- modules/textadept/adeptsense.lua | 4 +- modules/textadept/bookmarks.lua | 2 +- modules/textadept/command_entry.lua | 28 +-- modules/textadept/editing.lua | 36 ++- modules/textadept/file_types.lua | 2 +- modules/textadept/find.lua | 52 ++-- modules/textadept/keys.lua | 44 ++-- modules/textadept/menu.lua | 58 ++--- modules/textadept/run.lua | 8 +- modules/textadept/session.lua | 48 ++-- modules/textadept/snippets.lua | 8 +- src/textadept.c | 42 ++-- 23 files changed, 718 insertions(+), 719 deletions(-) delete mode 100644 core/gui.lua create mode 100644 core/ui.lua diff --git a/core/events.lua b/core/events.lua index d01d5479..493fae6a 100644 --- a/core/events.lua +++ b/core/events.lua @@ -191,7 +191,7 @@ local M = {} -- Emitted after selecting a menu item. -- Arguments: -- --- * _`menu_id`_: The numeric ID of the menu item set in [`gui.menu()`][]. +-- * _`menu_id`_: The numeric ID of the menu item set in [`ui.menu()`][]. -- @field QUIT (string) -- Emitted when quitting Textadept. -- When connecting to this event, connect with an index of 1 or the handler @@ -238,22 +238,22 @@ local M = {} -- Emitted on startup and by [`view:split()`][]. -- @field VIEW_BEFORE_SWITCH (string) -- Emitted right before switching to another view. --- Emitted by [`gui.goto_view()`][]. +-- Emitted by [`ui.goto_view()`][]. -- @field VIEW_AFTER_SWITCH (string) -- Emitted right after switching to another view. --- Emitted by [`gui.goto_view()`][]. +-- Emitted by [`ui.goto_view()`][]. -- -- [`buffer:auto_c_cancel()`]: buffer.html#auto_c_cancel -- [`view:goto_buffer()`]: view.html#goto_buffer -- [`buffer.new()`]: buffer.html#new -- [`buffer:delete()`]: buffer.html#delete -- [dwell period]: buffer.html#mouse_dwell_time --- [`gui.menu()`]: gui.html#menu +-- [`ui.menu()`]: ui.html#menu -- [`quit()`]: _G.html#quit -- [`reset()`]: _G.html#reset -- [`buffer:user_list_show()`]: buffer.html#user_list_show -- [`view:split()`]: view.html#split --- [`gui.goto_view()`]: gui.html#goto_view +-- [`ui.goto_view()`]: ui.html#goto_view module('events')]] local handlers = {} @@ -266,7 +266,7 @@ local handlers = {} -- @param f The Lua function to connect to *event*. -- @param index Optional index to insert the handler into. -- @return handler ID. --- @usage events.connect('my_event', function(msg) gui.print(msg) end) +-- @usage events.connect('my_event', function(msg) ui.print(msg) end) -- @see disconnect -- @name connect function M.connect(event, f, index) diff --git a/core/file_io.lua b/core/file_io.lua index 3ff52181..2cf7f08b 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -131,11 +131,11 @@ io.encodings = {'UTF-8', 'ASCII', 'ISO-8859-1', 'MacRoman'} -- @name open_file function io.open_file(utf8_filenames) utf8_filenames = utf8_filenames or - gui.dialog('fileselect', - '--title', _L['Open'], - '--select-multiple', - '--with-directory', - (buffer.filename or ''):match('.+[/\\]') or '') + ui.dialog('fileselect', + '--title', _L['Open'], + '--select-multiple', + '--with-directory', + (buffer.filename or ''):match('.+[/\\]') or '') for utf8_filename in utf8_filenames:gmatch('[^\n]+') do utf8_filename = utf8_filename:gsub('^file://', '') if WIN32 then utf8_filename = utf8_filename:gsub('/', '\\') end @@ -259,13 +259,13 @@ local function save_as(buffer, utf8_filename) if not buffer and not utf8_filename then buffer = _G.buffer end buffer:check_global() if not utf8_filename then - utf8_filename = gui.dialog('filesave', - '--title', _L['Save'], - '--with-directory', - (buffer.filename or ''):match('.+[/\\]') or '', - '--with-file', - (buffer.filename or ''):match('[^/\\]+$') or '', - '--no-newline') + utf8_filename = ui.dialog('filesave', + '--title', _L['Save'], + '--with-directory', + (buffer.filename or ''):match('.+[/\\]') or '', + '--with-file', + (buffer.filename or ''):match('[^/\\]+$') or '', + '--no-newline') end if utf8_filename == '' then return end buffer.filename = utf8_filename @@ -291,14 +291,14 @@ local function close(buffer) if not buffer then buffer = _G.buffer end buffer:check_global() local filename = buffer.filename or buffer._type or _L['Untitled'] - if buffer.dirty and gui.dialog('msgbox', - '--title', _L['Close without saving?'], - '--text', _L['There are unsaved changes in'], - '--informative-text', filename, - '--icon', 'gtk-dialog-question', - '--button1', _L['_Cancel'], - '--button2', _L['Close _without saving'], - '--no-newline') ~= '2' then + if buffer.dirty and ui.dialog('msgbox', + '--title', _L['Close without saving?'], + '--text', _L['There are unsaved changes in'], + '--informative-text', filename, + '--icon', 'gtk-dialog-question', + '--button1', _L['_Cancel'], + '--button2', _L['Close _without saving'], + '--no-newline') ~= '2' then return nil -- returning false can cause unwanted key command propagation end buffer:delete() @@ -330,17 +330,17 @@ local function update_modified_file() if not mod_time or not buffer.mod_time then return end if buffer.mod_time < mod_time then buffer.mod_time = mod_time - if gui.dialog('yesno-msgbox', - '--title', _L['Reload?'], - '--text', _L['Reload modified file?'], - '--informative-text', - ('"%s"\n%s'):format(utf8_filename, - _L['has been modified. Reload it?']), - '--icon', 'gtk-dialog-question', - '--button1', _L['_Yes'], - '--button2', _L['_No'], - '--no-cancel', - '--no-newline') == '1' then + if ui.dialog('yesno-msgbox', + '--title', _L['Reload?'], + '--text', _L['Reload modified file?'], + '--informative-text', + ('"%s"\n%s'):format(utf8_filename, + _L['has been modified. Reload it?']), + '--icon', 'gtk-dialog-question', + '--button1', _L['_Yes'], + '--button2', _L['_No'], + '--no-cancel', + '--no-newline') == '1' then buffer:reload() end end @@ -370,8 +370,8 @@ end) -- @see recent_files -- @name open_recent_file function io.open_recent_file() - local i = gui.filteredlist(_L['Open'], _L['File'], io.recent_files, true, - CURSES and {'--width', gui.size[1] - 2} or '') + local i = ui.filteredlist(_L['Open'], _L['File'], io.recent_files, true, + CURSES and {'--width', ui.size[1] - 2} or '') if i then io.open_file(io.recent_files[i + 1]) end end @@ -393,7 +393,7 @@ end -- default filter `lfs.FILTER` in the search. If `false`, adds `lfs.FILTER` to -- *filter*. -- The default value is `false` to include the default filter. --- @param ... Optional additional parameters to pass to `gui.dialog()`. +-- @param ... Optional additional parameters to pass to `ui.dialog()`. -- @usage io.snapopen(buffer.filename:match('^.+/')) -- list all files in the -- current file's directory, subject to the default filter -- @usage io.snapopen('/project', '!%.lua$') -- list all Lua files in a project @@ -412,16 +412,16 @@ function io.snapopen(utf8_paths, filter, exclude_FILTER, ...) end, filter, exclude_FILTER) end if #list >= io.SNAPOPEN_MAX then - gui.dialog('ok-msgbox', - '--title', _L['File Limit Exceeded'], - '--text', - string.format('%d %s %d', io.SNAPOPEN_MAX, - _L['files or more were found. Showing the first'], - io.SNAPOPEN_MAX), - '--icon', 'gtk-dialog-info', - '--button1', _L['_OK']) + ui.dialog('ok-msgbox', + '--title', _L['File Limit Exceeded'], + '--text', + string.format('%d %s %d', io.SNAPOPEN_MAX, + _L['files or more were found. Showing the first'], + io.SNAPOPEN_MAX), + '--icon', 'gtk-dialog-info', + '--button1', _L['_OK']) end - local width = CURSES and {'--width', gui.size[1] - 2} or '' - io.open_file(gui.filteredlist(_L['Open'], _L['File'], list, false, - '--select-multiple', width, ...) or '') + local width = CURSES and {'--width', ui.size[1] - 2} or '' + io.open_file(ui.filteredlist(_L['Open'], _L['File'], list, false, + '--select-multiple', width, ...) or '') end diff --git a/core/gui.lua b/core/gui.lua deleted file mode 100644 index 22282a68..00000000 --- a/core/gui.lua +++ /dev/null @@ -1,456 +0,0 @@ --- Copyright 2007-2013 Mitchell mitchell.att.foicica.com. See LICENSE. - -local gui = gui - ---[[ This comment is for LuaDoc. ---- --- Utilities for interacting with Textadept's user interface. --- @field title (string, Write-only) --- The title of the Textadept window. --- @field context_menu --- The editor's context menu, a [`gui.menu()`](#menu). --- This is a low-level field. You probably want to use the higher-level --- `_M.textadept.menu.set_contextmenu()`. --- @field clipboard_text (string, Read-only) --- The text on the clipboard. --- @field statusbar_text (string, Write-only) --- The text displayed by the statusbar. --- @field docstatusbar_text (string, Write-only) --- The text displayed by the buffer statusbar. --- @field maximized (bool) --- Whether or not the Textadept window is maximized. -module('gui')]] - -local theme = package.searchpath(not CURSES and 'light' or 'term', - _USERHOME..'/themes/?.lua;'.. - _HOME..'/themes/?.lua') -local theme_props = {} - --- Helper function for printing messages to buffers. --- @see gui._print -local function _print(buffer_type, ...) - if buffer._type ~= buffer_type then - for i, view in ipairs(_VIEWS) do - if view.buffer._type == buffer_type then gui.goto_view(i) break end - end - if view.buffer._type ~= buffer_type then - view:split() - for i, buffer in ipairs(_BUFFERS) do - if buffer._type == buffer_type then view:goto_buffer(i) break end - end - if buffer._type ~= buffer_type then - buffer.new()._type = buffer_type - events.emit(events.FILE_OPENED) - end - end - end - local args, n = {...}, select('#', ...) - for i = 1, n do args[i] = tostring(args[i]) end - buffer:append_text(table.concat(args, '\t')) - buffer:append_text('\n') - buffer:goto_pos(buffer.length) - buffer:set_save_point() -end ---- --- Helper function for printing messages to buffers. --- Splits the view and opens a new buffer for printing messages to. If the --- message buffer is already open in a view, the message is printed to that --- view. Otherwise the view is split and the message buffer is opened or --- displayed before being printed to. --- @param buffer_type String type of message buffer. --- @param ... Message strings. --- @usage gui._print(_L['[Message Buffer]'], message) --- @name _print -function gui._print(buffer_type, ...) pcall(_print, buffer_type, ...) end - ---- --- Prints messages to the Textadept message buffer. --- Opens a new buffer if one has not already been opened for printing messages. --- @param ... Message strings. --- @name print -function gui.print(...) gui._print(_L['[Message Buffer]'], ...) end - ---- --- Convenience function for `gui.dialog('filteredlist', ...)` with "Ok" and --- "Cancel" buttons that returns the text or index of the selection depending on --- the boolean value of *int_return*. --- *title* is the title of the dialog, *columns* is a list of column names, and --- *items* is a list of items to show. --- @param title The title for the filtered list dialog. --- @param columns A column name or list of column names. --- @param items An item or list of items. --- @param int_return Optional flag indicating whether to return the integer --- index of the selected item in the filtered list or the string selected --- item. A `true` value is not compatible with the `'--select-multiple'` --- option. The default value is `false`. --- @param ... Optional additional parameters to pass to `gui.dialog()`. --- @return Either a string or integer on success; `nil` otherwise. In strings, --- multiple items are separated by newlines. --- @usage gui.filteredlist('Title', 'Foo', {'Bar', 'Baz'}) --- @usage gui.filteredlist('Title', {'Foo', 'Bar'}, {'a', 'b', 'c', 'd'}, false, --- '--output-column', '2') --- @see dialog --- @name filteredlist -function gui.filteredlist(title, columns, items, int_return, ...) - local out = gui.dialog('filteredlist', - '--title', title, - '--button1', _L['_OK'], - '--button2', _L['_Cancel'], - '--no-newline', - int_return and '' or '--string-output', - '--columns', columns, - '--items', items, - ...) - local patt = int_return and '^(%-?%d+)\n(%d+)$' or '^([^\n]+)\n(.+)$' - local response, value = out:match(patt) - if response == (int_return and '1' or _L['_OK']) then - return not int_return and value or tonumber(value) - end -end - ---- --- Prompts the user to select a buffer to switch to. --- @name switch_buffer -function gui.switch_buffer() - local columns, items = {_L['Name'], _L['File']}, {} - for _, buffer in ipairs(_BUFFERS) do - local filename = buffer.filename or buffer._type or _L['Untitled'] - local basename = buffer.filename and filename:match('[^/\\]+$') or filename - items[#items + 1] = (buffer.dirty and '*' or '')..basename - items[#items + 1] = filename - end - local i = gui.filteredlist(_L['Switch Buffers'], columns, items, true, - CURSES and {'--width', gui.size[1] - 2} or '--') - if i then view:goto_buffer(i + 1) end -end - ---- --- Goes to the buffer whose filename is *filename* in an existing view, --- otherwise splitting the current view if *split* is `true` or going to the --- next or *preferred_view* view instead of staying in the current one. --- If *sloppy* is `true`, only the last part of *filename* is matched to a --- buffer's `filename`. --- @param filename The filename of the buffer to go to. --- @param split Optional flag indicating whether or not to open the buffer in a --- split view if there is only one view. The default value is `false`. --- @param preferred_view Optional view to open the desired buffer in if the --- buffer is not visible in any other view. --- @param sloppy Optional flag indicating whether or not to not match *filename* --- to `buffer.filename` exactly. When `true`, matches *filename* to only the --- last part of `buffer.filename` This is useful for run and compile commands --- which output relative filenames and paths instead of full ones and it is --- likely that the file in question is already open. The default value is --- `false`. --- @name goto_file -function gui.goto_file(filename, split, preferred_view, sloppy) - local patt = '^'..filename..'$' - if sloppy then - local i = filename:reverse():find('[/\\]%.%.?') -- ./ or ../ - patt = i and filename:sub(-i + 1, -1)..'$' or filename..'$' - end - if #_VIEWS == 1 and split and not (view.buffer.filename or ''):find(patt) then - view:split() - else - local other_view = _VIEWS[preferred_view] - for i, v in ipairs(_VIEWS) do - if (v.buffer.filename or ''):find(patt) then gui.goto_view(i) return end - if not other_view and v ~= view then other_view = i end - end - if other_view then gui.goto_view(other_view) end - end - for i, buffer in ipairs(_BUFFERS) do - if (buffer.filename or ''):find(patt) then view:goto_buffer(i) return end - end - io.open_file(filename) -end - ---- --- Sets the editor theme name to *name* and optionally sets key-value pair --- argument properties. --- User themes override Textadept's default themes when they have the same name. --- If *name* contains slashes, it is assumed to be an absolute path to a theme --- instead of a theme name. --- @param name The name or absolute path of a theme to set. --- @param ... Optional key-value argument pairs for theme properties to set. --- These override the theme's defaults. --- @usage gui.set_theme('light', 'font', 'Monospace', 'fontsize', 12) --- @name set_theme -function gui.set_theme(name, ...) - if not name then return end - name = name:find('[/\\]') and name or - package.searchpath(name, _USERHOME..'/themes/?.lua;'.. - _HOME..'/themes/?.lua') - if not name or not lfs.attributes(name) then return end - local props = {...} - local current_buffer, current_view = _BUFFERS[buffer], _VIEWS[view] - for i = 1, #_BUFFERS do - view:goto_buffer(i) - dofile(name) - for j = 1, #props, 2 do buffer.property[props[j]] = props[j + 1] end - end - view:goto_buffer(current_buffer) - for i = 1, #_VIEWS do - gui.goto_view(i) - dofile(name) - for j = 1, #props, 2 do buffer.property[props[j]] = props[j + 1] end - end - gui.goto_view(current_view) - theme, theme_props = name, props -end - -local events, events_connect = events, events.connect - --- Loads the theme and properties files. -local function load_theme_and_settings() - dofile(theme) - local props = theme_props - for i = 1, #props, 2 do buffer.property[props[i]] = props[i + 1] end - dofile(_HOME..'/properties.lua') - if lfs.attributes(_USERHOME..'/properties.lua') then - dofile(_USERHOME..'/properties.lua') - end -end - --- Sets default properties for a Scintilla window. -events_connect(events.VIEW_NEW, function() - local buffer = buffer - -- Allow redefinitions of these Scintilla key commands. - local ctrl_keys = { - '[', ']', '/', '\\', 'Z', 'Y', 'X', 'C', 'V', 'A', 'L', 'T', 'D', 'U' - } - local ctrl_shift_keys = {'L', 'T', 'U', 'Z'} - for _, key in ipairs(ctrl_keys) do - buffer:clear_cmd_key(string.byte(key), buffer.SCMOD_CTRL) - end - for _, key in ipairs(ctrl_shift_keys) do - buffer:clear_cmd_key(string.byte(key), - buffer.SCMOD_CTRL + buffer.SCMOD_SHIFT) - end - -- Since BUFFER_NEW loads themes and settings on startup, only load them for - -- subsequent views. - if #_VIEWS > 1 then load_theme_and_settings() end -end) -events_connect(events.VIEW_NEW, function() events.emit(events.UPDATE_UI) end) - -local SETDIRECTFUNCTION = _SCINTILLA.properties.direct_function[1] -local SETDIRECTPOINTER = _SCINTILLA.properties.doc_pointer[2] -local SETLEXERLANGUAGE = _SCINTILLA.properties.lexer_language[2] --- Sets default properties for a Scintilla document. -events_connect(events.BUFFER_NEW, function() - buffer.code_page = buffer.SC_CP_UTF8 - buffer.style_bits = 8 - buffer.lexer_language = 'lpeg' - buffer:private_lexer_call(SETDIRECTFUNCTION, buffer.direct_function) - buffer:private_lexer_call(SETDIRECTPOINTER, buffer.direct_pointer) - buffer.property['lexer.lpeg.home'] = _USERHOME..'/lexers/?.lua;'.. - _HOME..'/lexers' - load_theme_and_settings() - buffer:private_lexer_call(SETLEXERLANGUAGE, 'text') -end) - --- Sets the title of the Textadept window to the buffer's filename. --- @param buffer The global buffer. -local function set_title() - local filename = buffer.filename or buffer._type or _L['Untitled'] - local basename = buffer.filename and filename:match('[^/\\]+$') or filename - gui.title = string.format('%s %s Textadept (%s)', basename, - buffer.dirty and '*' or '-', filename) -end - --- Changes Textadept title to show the buffer as being "clean". -events_connect(events.SAVE_POINT_REACHED, function() - buffer.dirty = false - set_title() -end) - --- Changes Textadept title to show thee buffer as "dirty". -events_connect(events.SAVE_POINT_LEFT, function() - buffer.dirty = true - set_title() -end) - --- Open uri(s). -events_connect(events.URI_DROPPED, function(utf8_uris) - for utf8_uri in utf8_uris:gmatch('[^\r\n]+') do - if utf8_uri:find('^file://') then - utf8_uri = utf8_uri:match('^file://([^\r\n]+)') - 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 mode = lfs.attributes(utf8_uri:iconv(_CHARSET, 'UTF-8'), 'mode') - if mode and mode ~= 'directory' then io.open_file(utf8_uri) end - end - end -end) -events_connect(events.APPLEEVENT_ODOC, function(uri) - return events.emit(events.URI_DROPPED, 'file://'..uri) -end) - -local EOLs = {_L['CRLF'], _L['CR'], _L['LF']} -local GETLEXERLANGUAGE = _SCINTILLA.properties.lexer_language[1] --- Sets docstatusbar text. -events_connect(events.UPDATE_UI, function() - local pos = buffer.current_pos - local line, max = buffer:line_from_position(pos) + 1, buffer.line_count - local col = buffer.column[pos] + 1 - local lexer = buffer:private_lexer_call(GETLEXERLANGUAGE):match('^[^/]+') - local eol = EOLs[buffer.eol_mode + 1] - local tabs = string.format('%s %d', buffer.use_tabs and _L['Tabs:'] or - _L['Spaces:'], buffer.tab_width) - local enc = buffer.encoding or '' - local text = not CURSES and '%s %d/%d %s %d %s %s %s %s' or - '%s %d/%d %s %d %s %s %s %s' - gui.docstatusbar_text = string.format(text, _L['Line:'], line, max, - _L['Col:'], col, lexer, eol, tabs, enc) -end) - --- Updates the statusbar and titlebar for a new Scintilla document. -events_connect(events.BUFFER_NEW, function() events.emit(events.UPDATE_UI) end) -events_connect(events.BUFFER_NEW, function() set_title() end) - --- Save buffer properties. -events_connect(events.BUFFER_BEFORE_SWITCH, function() - local buffer = buffer - -- Save view state. - buffer._anchor, buffer._current_pos = buffer.anchor, buffer.current_pos - buffer._first_visible_line = buffer.first_visible_line - -- Save fold state. - buffer._folds = {} - local folds, i = buffer._folds, buffer:contracted_fold_next(0) - while i >= 0 do - folds[#folds + 1], i = i, buffer:contracted_fold_next(i + 1) - end -end) - --- Restore buffer properties. -events_connect(events.BUFFER_AFTER_SWITCH, function() - local buffer = buffer - if not buffer._folds then return end - -- Restore fold state. - for i = 1, #buffer._folds do buffer:toggle_fold(buffer._folds[i]) end - -- Restore view state. - buffer:set_sel(buffer._anchor, buffer._current_pos) - buffer:line_scroll(0, - buffer:visible_from_doc_line(buffer._first_visible_line) - - buffer.first_visible_line) -end) - --- Updates titlebar and statusbar. -events_connect(events.BUFFER_AFTER_SWITCH, function() - set_title() - buffer:private_lexer_call(SETDIRECTPOINTER, buffer.direct_pointer) - events.emit(events.UPDATE_UI) -end) - --- Updates titlebar and statusbar. -events_connect(events.VIEW_AFTER_SWITCH, function() - set_title() - events.emit(events.UPDATE_UI) -end) - -events_connect(events.RESET_AFTER, - function() gui.statusbar_text = 'Lua reset' end) - --- Prompts for confirmation if any buffers are dirty. -events_connect(events.QUIT, function() - local list = {} - for _, buffer in ipairs(_BUFFERS) do - if buffer.dirty then - list[#list + 1] = buffer.filename or buffer._type or _L['Untitled'] - end - end - return #list < 1 or gui.dialog('msgbox', - '--title', _L['Quit without saving?'], - '--text', - _L['The following buffers are unsaved:'], - '--informative-text', table.concat(list, '\n'), - '--icon', 'gtk-dialog-question', - '--button1', _L['_Cancel'], - '--button2', _L['Quit _without saving'], - '--no-newline') == '2' -end) - -events_connect(events.ERROR, gui.print) - ---[[ The tables below were defined in C. - ---- --- A table of menus defining a menubar. (Write-only) --- @see _M.textadept.menu.set_menubar --- @class table --- @name menubar -local menubar - ---- --- A table containing the width and height values of the Textadept window. --- @class table --- @name size -local size - -The functions below are Lua C functions. - ---- --- Displays a *kind* [gtdialog][] with the given string arguments to pass to --- the dialog and returns a formatted string of the dialog's output. --- Table arguments containing strings are allowed and expanded in place. This is --- useful for filtered list dialogs with many items. --- For more information on gtdialog, see [http://foicica.com/gtdialog][]. --- --- [gtdialog]: http://foicica.com/gtdialog/02_Usage.html --- [http://foicica.com/gtdialog]: http://foicica.com/gtdialog --- @param kind The kind of gtdialog. --- @param ... Parameters to the gtdialog. --- @return string gtdialog result. --- @class function --- @name dialog -local dialog - ---- --- Returns the current split view structure. --- This is primarily used in session saving. --- @return table of split views. Each split view entry is a table with 4 --- fields: `1`, `2`, `vertical`, and `size`. `1` and `2` have values of either --- nested split view entries or the views themselves; `vertical` is a flag --- indicating if the split is vertical or not; and `size` is the integer --- position of the split resizer. --- @class function --- @name get_split_table -local get_split_table - ---- --- Goes to view number *n*. --- If *relative* is `true`, *n* is an index relative to the index of the current --- view in `_G._VIEWS` instead of an absolute index. --- Emits `VIEW_BEFORE_SWITCH` and `VIEW_AFTER_SWITCH` events. --- @param n A relative or absolute view index in `_G._VIEWS`. --- @param relative Optional flag indicating whether *n* is a relative or --- absolute index. The default value is `false`, for an absolute index. --- @see _G._G._VIEWS --- @see events.VIEW_BEFORE_SWITCH --- @see events.VIEW_AFTER_SWITCH --- @class function --- @name goto_view -local goto_view - ---- --- Low-level function for creating a menu from table *menu_table* and returning --- the userdata. --- You probably want to use the higher-level `_M.textadept.menu.set_menubar()` --- or `_M.textadept.menu.set_contextmenu()` functions. Emits a `MENU_CLICKED` --- event when a menu item is selected. --- @param menu_table A table defining the menu. It is an ordered list of tables --- with a string menu item, integer menu ID, and optional GDK keycode and --- modifier mask. The latter two are used to display key shortcuts in the --- menu. '_' characters are treated as a menu mnemonics. If the menu item is --- empty, a menu separator item is created. Submenus are just nested --- menu-structure tables. Their title text is defined with a `title` key. --- @usage gui.menu{{'_New', 1}, {'_Open', 2}, {''}, {'_Quit', 4}} --- @usage gui.menu{{'_New', 1, string.byte('n'), 4}} -- 'Ctrl+N' --- @see events.MENU_CLICKED --- @see _M.textadept.menu.set_menubar --- @see _M.textadept.menu.set_contextmenu --- @class function --- @name menu -local menu -]] diff --git a/core/init.lua b/core/init.lua index 1e184288..0049bc7a 100644 --- a/core/init.lua +++ b/core/init.lua @@ -10,7 +10,7 @@ _L = require('locale') events = require('events') require('file_io') require('lfs_ext') -require('gui') +require('ui') keys = require('keys') _M = {} -- modules table @@ -113,9 +113,9 @@ local quit local reset --- --- Calls the function *f* with the given arguments after *interval* seconds and --- then repeatedly while *f* returns `true`. A `nil` or `false` return value --- stops repetition. +-- Calls function *f* with the given arguments after *interval* seconds and then +-- repeatedly while *f* returns `true`. A `nil` or `false` return value stops +-- repetition. -- @param interval The interval in seconds to call *f* after. -- @param f The function to call. -- @param ... Additional arguments to pass to *f*. diff --git a/core/keys.lua b/core/keys.lua index 1f7a023a..59c92f51 100644 --- a/core/keys.lua +++ b/core/keys.lua @@ -80,13 +80,13 @@ local M = {} -- ['l'] = buffer.char_right, -- ['i'] = function() -- keys.MODE = nil --- gui.statusbar_text = 'INSERT MODE' +-- ui.statusbar_text = 'INSERT MODE' -- end -- } -- keys['esc'] = function() keys.MODE = 'command_mode' end -- events.connect(events.UPDATE_UI, function() -- if keys.MODE == 'command_mode' then return end --- gui.statusbar_text = 'INSERT MODE' +-- ui.statusbar_text = 'INSERT MODE' -- end) -- keys.MODE = 'command_mode' -- default mode -- @@ -221,7 +221,7 @@ local function key_command(prefix) local key_type = type(key) if key_type ~= 'function' and key_type ~= 'table' then return INVALID end if key_type == 'table' and #key == 0 and next(key) or getmetatable(key) then - gui.statusbar_text = _L['Keychain:']..' '..table.concat(keychain, ' ') + ui.statusbar_text = _L['Keychain:']..' '..table.concat(keychain, ' ') return CHAIN end return run_command(key, key_type) == false and PROPAGATE or HALT @@ -246,8 +246,8 @@ local function keypress(code, shift, control, alt, meta) (meta and OSX and META or '')..(shift and SHIFT or '')..key --print(key_seq) - gui.statusbar_text = '' - --if CURSES then gui.statusbar_text = '"'..key_seq..'"' end + ui.statusbar_text = '' + --if CURSES then ui.statusbar_text = '"'..key_seq..'"' end local keychain_size = #keychain if keychain_size > 0 and key_seq == M.CLEAR then clear_key_sequence() @@ -265,7 +265,7 @@ local function keypress(code, shift, control, alt, meta) if status ~= CHAIN then clear_key_sequence() end if status > PROPAGATE then return true end -- CHAIN or HALT if status == INVALID and keychain_size > 0 then - gui.statusbar_text = _L['Invalid sequence'] + ui.statusbar_text = _L['Invalid sequence'] return true end -- PROPAGATE otherwise. diff --git a/core/ui.lua b/core/ui.lua new file mode 100644 index 00000000..392b961f --- /dev/null +++ b/core/ui.lua @@ -0,0 +1,456 @@ +-- Copyright 2007-2013 Mitchell mitchell.att.foicica.com. See LICENSE. + +local ui = ui + +--[[ This comment is for LuaDoc. +--- +-- Utilities for interacting with Textadept's user interface. +-- @field title (string, Write-only) +-- The title of the Textadept window. +-- @field context_menu +-- The editor's context menu, a [`ui.menu()`](#menu). +-- This is a low-level field. You probably want to use the higher-level +-- `_M.textadept.menu.set_contextmenu()`. +-- @field clipboard_text (string, Read-only) +-- The text on the clipboard. +-- @field statusbar_text (string, Write-only) +-- The text displayed by the statusbar. +-- @field docstatusbar_text (string, Write-only) +-- The text displayed by the buffer statusbar. +-- @field maximized (bool) +-- Whether or not the Textadept window is maximized. +module('ui')]] + +local theme = package.searchpath(not CURSES and 'light' or 'term', + _USERHOME..'/themes/?.lua;'.. + _HOME..'/themes/?.lua') +local theme_props = {} + +-- Helper function for printing messages to buffers. +-- @see ui._print +local function _print(buffer_type, ...) + if buffer._type ~= buffer_type then + for i, view in ipairs(_VIEWS) do + if view.buffer._type == buffer_type then ui.goto_view(i) break end + end + if view.buffer._type ~= buffer_type then + view:split() + for i, buffer in ipairs(_BUFFERS) do + if buffer._type == buffer_type then view:goto_buffer(i) break end + end + if buffer._type ~= buffer_type then + buffer.new()._type = buffer_type + events.emit(events.FILE_OPENED) + end + end + end + local args, n = {...}, select('#', ...) + for i = 1, n do args[i] = tostring(args[i]) end + buffer:append_text(table.concat(args, '\t')) + buffer:append_text('\n') + buffer:goto_pos(buffer.length) + buffer:set_save_point() +end +--- +-- Helper function for printing messages to buffers. +-- Splits the view and opens a new buffer for printing messages to. If the +-- message buffer is already open in a view, the message is printed to that +-- view. Otherwise the view is split and the message buffer is opened or +-- displayed before being printed to. +-- @param buffer_type String type of message buffer. +-- @param ... Message strings. +-- @usage ui._print(_L['[Message Buffer]'], message) +-- @name _print +function ui._print(buffer_type, ...) pcall(_print, buffer_type, ...) end + +--- +-- Prints messages to the Textadept message buffer. +-- Opens a new buffer if one has not already been opened for printing messages. +-- @param ... Message strings. +-- @name print +function ui.print(...) ui._print(_L['[Message Buffer]'], ...) end + +--- +-- Convenience function for `ui.dialog('filteredlist', ...)` with "Ok" and +-- "Cancel" buttons that returns the text or index of the selection depending on +-- the boolean value of *int_return*. +-- *title* is the title of the dialog, *columns* is a list of column names, and +-- *items* is a list of items to show. +-- @param title The title for the filtered list dialog. +-- @param columns A column name or list of column names. +-- @param items An item or list of items. +-- @param int_return Optional flag indicating whether to return the integer +-- index of the selected item in the filtered list or the string selected +-- item. A `true` value is not compatible with the `'--select-multiple'` +-- option. The default value is `false`. +-- @param ... Optional additional parameters to pass to `ui.dialog()`. +-- @return Either a string or integer on success; `nil` otherwise. In strings, +-- multiple items are separated by newlines. +-- @usage ui.filteredlist('Title', 'Foo', {'Bar', 'Baz'}) +-- @usage ui.filteredlist('Title', {'Foo', 'Bar'}, {'a', 'b', 'c', 'd'}, false, +-- '--output-column', '2') +-- @see dialog +-- @name filteredlist +function ui.filteredlist(title, columns, items, int_return, ...) + local out = ui.dialog('filteredlist', + '--title', title, + '--button1', _L['_OK'], + '--button2', _L['_Cancel'], + '--no-newline', + int_return and '' or '--string-output', + '--columns', columns, + '--items', items, + ...) + local patt = int_return and '^(%-?%d+)\n(%d+)$' or '^([^\n]+)\n(.+)$' + local response, value = out:match(patt) + if response == (int_return and '1' or _L['_OK']) then + return not int_return and value or tonumber(value) + end +end + +--- +-- Prompts the user to select a buffer to switch to. +-- @name switch_buffer +function ui.switch_buffer() + local columns, items = {_L['Name'], _L['File']}, {} + for _, buffer in ipairs(_BUFFERS) do + local filename = buffer.filename or buffer._type or _L['Untitled'] + local basename = buffer.filename and filename:match('[^/\\]+$') or filename + items[#items + 1] = (buffer.dirty and '*' or '')..basename + items[#items + 1] = filename + end + local i = ui.filteredlist(_L['Switch Buffers'], columns, items, true, + CURSES and {'--width', ui.size[1] - 2} or '--') + if i then view:goto_buffer(i + 1) end +end + +--- +-- Goes to the buffer whose filename is *filename* in an existing view, +-- otherwise splitting the current view if *split* is `true` or going to the +-- next or *preferred_view* view instead of staying in the current one. +-- If *sloppy* is `true`, only the last part of *filename* is matched to a +-- buffer's `filename`. +-- @param filename The filename of the buffer to go to. +-- @param split Optional flag indicating whether or not to open the buffer in a +-- split view if there is only one view. The default value is `false`. +-- @param preferred_view Optional view to open the desired buffer in if the +-- buffer is not visible in any other view. +-- @param sloppy Optional flag indicating whether or not to not match *filename* +-- to `buffer.filename` exactly. When `true`, matches *filename* to only the +-- last part of `buffer.filename` This is useful for run and compile commands +-- which output relative filenames and paths instead of full ones and it is +-- likely that the file in question is already open. The default value is +-- `false`. +-- @name goto_file +function ui.goto_file(filename, split, preferred_view, sloppy) + local patt = '^'..filename..'$' + if sloppy then + local i = filename:reverse():find('[/\\]%.%.?') -- ./ or ../ + patt = i and filename:sub(-i + 1, -1)..'$' or filename..'$' + end + if #_VIEWS == 1 and split and not (view.buffer.filename or ''):find(patt) then + view:split() + else + local other_view = _VIEWS[preferred_view] + for i, v in ipairs(_VIEWS) do + if (v.buffer.filename or ''):find(patt) then ui.goto_view(i) return end + if not other_view and v ~= view then other_view = i end + end + if other_view then ui.goto_view(other_view) end + end + for i, buffer in ipairs(_BUFFERS) do + if (buffer.filename or ''):find(patt) then view:goto_buffer(i) return end + end + io.open_file(filename) +end + +--- +-- Sets the editor theme name to *name* and optionally sets key-value pair +-- argument properties. +-- User themes override Textadept's default themes when they have the same name. +-- If *name* contains slashes, it is assumed to be an absolute path to a theme +-- instead of a theme name. +-- @param name The name or absolute path of a theme to set. +-- @param ... Optional key-value argument pairs for theme properties to set. +-- These override the theme's defaults. +-- @usage ui.set_theme('light', 'font', 'Monospace', 'fontsize', 12) +-- @name set_theme +function ui.set_theme(name, ...) + if not name then return end + name = name:find('[/\\]') and name or + package.searchpath(name, _USERHOME..'/themes/?.lua;'.. + _HOME..'/themes/?.lua') + if not name or not lfs.attributes(name) then return end + local props = {...} + local current_buffer, current_view = _BUFFERS[buffer], _VIEWS[view] + for i = 1, #_BUFFERS do + view:goto_buffer(i) + dofile(name) + for j = 1, #props, 2 do buffer.property[props[j]] = props[j + 1] end + end + view:goto_buffer(current_buffer) + for i = 1, #_VIEWS do + ui.goto_view(i) + dofile(name) + for j = 1, #props, 2 do buffer.property[props[j]] = props[j + 1] end + end + ui.goto_view(current_view) + theme, theme_props = name, props +end + +local events, events_connect = events, events.connect + +-- Loads the theme and properties files. +local function load_theme_and_settings() + dofile(theme) + local props = theme_props + for i = 1, #props, 2 do buffer.property[props[i]] = props[i + 1] end + dofile(_HOME..'/properties.lua') + if lfs.attributes(_USERHOME..'/properties.lua') then + dofile(_USERHOME..'/properties.lua') + end +end + +-- Sets default properties for a Scintilla window. +events_connect(events.VIEW_NEW, function() + local buffer = buffer + -- Allow redefinitions of these Scintilla key commands. + local ctrl_keys = { + '[', ']', '/', '\\', 'Z', 'Y', 'X', 'C', 'V', 'A', 'L', 'T', 'D', 'U' + } + local ctrl_shift_keys = {'L', 'T', 'U', 'Z'} + for _, key in ipairs(ctrl_keys) do + buffer:clear_cmd_key(string.byte(key), buffer.SCMOD_CTRL) + end + for _, key in ipairs(ctrl_shift_keys) do + buffer:clear_cmd_key(string.byte(key), + buffer.SCMOD_CTRL + buffer.SCMOD_SHIFT) + end + -- Since BUFFER_NEW loads themes and settings on startup, only load them for + -- subsequent views. + if #_VIEWS > 1 then load_theme_and_settings() end +end) +events_connect(events.VIEW_NEW, function() events.emit(events.UPDATE_UI) end) + +local SETDIRECTFUNCTION = _SCINTILLA.properties.direct_function[1] +local SETDIRECTPOINTER = _SCINTILLA.properties.doc_pointer[2] +local SETLEXERLANGUAGE = _SCINTILLA.properties.lexer_language[2] +-- Sets default properties for a Scintilla document. +events_connect(events.BUFFER_NEW, function() + buffer.code_page = buffer.SC_CP_UTF8 + buffer.style_bits = 8 + buffer.lexer_language = 'lpeg' + buffer:private_lexer_call(SETDIRECTFUNCTION, buffer.direct_function) + buffer:private_lexer_call(SETDIRECTPOINTER, buffer.direct_pointer) + buffer.property['lexer.lpeg.home'] = _USERHOME..'/lexers/?.lua;'.. + _HOME..'/lexers' + load_theme_and_settings() + buffer:private_lexer_call(SETLEXERLANGUAGE, 'text') +end) + +-- Sets the title of the Textadept window to the buffer's filename. +-- @param buffer The global buffer. +local function set_title() + local filename = buffer.filename or buffer._type or _L['Untitled'] + local basename = buffer.filename and filename:match('[^/\\]+$') or filename + ui.title = string.format('%s %s Textadept (%s)', basename, + buffer.dirty and '*' or '-', filename) +end + +-- Changes Textadept title to show the buffer as being "clean". +events_connect(events.SAVE_POINT_REACHED, function() + buffer.dirty = false + set_title() +end) + +-- Changes Textadept title to show thee buffer as "dirty". +events_connect(events.SAVE_POINT_LEFT, function() + buffer.dirty = true + set_title() +end) + +-- Open uri(s). +events_connect(events.URI_DROPPED, function(utf8_uris) + for utf8_uri in utf8_uris:gmatch('[^\r\n]+') do + if utf8_uri:find('^file://') then + utf8_uri = utf8_uri:match('^file://([^\r\n]+)') + 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 mode = lfs.attributes(utf8_uri:iconv(_CHARSET, 'UTF-8'), 'mode') + if mode and mode ~= 'directory' then io.open_file(utf8_uri) end + end + end +end) +events_connect(events.APPLEEVENT_ODOC, function(uri) + return events.emit(events.URI_DROPPED, 'file://'..uri) +end) + +local EOLs = {_L['CRLF'], _L['CR'], _L['LF']} +local GETLEXERLANGUAGE = _SCINTILLA.properties.lexer_language[1] +-- Sets docstatusbar text. +events_connect(events.UPDATE_UI, function() + local pos = buffer.current_pos + local line, max = buffer:line_from_position(pos) + 1, buffer.line_count + local col = buffer.column[pos] + 1 + local lexer = buffer:private_lexer_call(GETLEXERLANGUAGE):match('^[^/]+') + local eol = EOLs[buffer.eol_mode + 1] + local tabs = string.format('%s %d', buffer.use_tabs and _L['Tabs:'] or + _L['Spaces:'], buffer.tab_width) + local enc = buffer.encoding or '' + local text = not CURSES and '%s %d/%d %s %d %s %s %s %s' or + '%s %d/%d %s %d %s %s %s %s' + ui.docstatusbar_text = string.format(text, _L['Line:'], line, max, _L['Col:'], + col, lexer, eol, tabs, enc) +end) + +-- Updates the statusbar and titlebar for a new Scintilla document. +events_connect(events.BUFFER_NEW, function() events.emit(events.UPDATE_UI) end) +events_connect(events.BUFFER_NEW, function() set_title() end) + +-- Save buffer properties. +events_connect(events.BUFFER_BEFORE_SWITCH, function() + local buffer = buffer + -- Save view state. + buffer._anchor, buffer._current_pos = buffer.anchor, buffer.current_pos + buffer._first_visible_line = buffer.first_visible_line + -- Save fold state. + buffer._folds = {} + local folds, i = buffer._folds, buffer:contracted_fold_next(0) + while i >= 0 do + folds[#folds + 1], i = i, buffer:contracted_fold_next(i + 1) + end +end) + +-- Restore buffer properties. +events_connect(events.BUFFER_AFTER_SWITCH, function() + local buffer = buffer + if not buffer._folds then return end + -- Restore fold state. + for i = 1, #buffer._folds do buffer:toggle_fold(buffer._folds[i]) end + -- Restore view state. + buffer:set_sel(buffer._anchor, buffer._current_pos) + buffer:line_scroll(0, + buffer:visible_from_doc_line(buffer._first_visible_line) - + buffer.first_visible_line) +end) + +-- Updates titlebar and statusbar. +events_connect(events.BUFFER_AFTER_SWITCH, function() + set_title() + buffer:private_lexer_call(SETDIRECTPOINTER, buffer.direct_pointer) + events.emit(events.UPDATE_UI) +end) + +-- Updates titlebar and statusbar. +events_connect(events.VIEW_AFTER_SWITCH, function() + set_title() + events.emit(events.UPDATE_UI) +end) + +events_connect(events.RESET_AFTER, + function() ui.statusbar_text = 'Lua reset' end) + +-- Prompts for confirmation if any buffers are dirty. +events_connect(events.QUIT, function() + local list = {} + for _, buffer in ipairs(_BUFFERS) do + if buffer.dirty then + list[#list + 1] = buffer.filename or buffer._type or _L['Untitled'] + end + end + return #list < 1 or ui.dialog('msgbox', + '--title', _L['Quit without saving?'], + '--text', + _L['The following buffers are unsaved:'], + '--informative-text', table.concat(list, '\n'), + '--icon', 'gtk-dialog-question', + '--button1', _L['_Cancel'], + '--button2', _L['Quit _without saving'], + '--no-newline') == '2' +end) + +events_connect(events.ERROR, ui.print) + +--[[ The tables below were defined in C. + +--- +-- A table of menus defining a menubar. (Write-only) +-- @see _M.textadept.menu.set_menubar +-- @class table +-- @name menubar +local menubar + +--- +-- A table containing the width and height values of the Textadept window. +-- @class table +-- @name size +local size + +The functions below are Lua C functions. + +--- +-- Displays a *kind* [gtdialog][] with the given string arguments to pass to +-- the dialog and returns a formatted string of the dialog's output. +-- Table arguments containing strings are allowed and expanded in place. This is +-- useful for filtered list dialogs with many items. +-- For more information on gtdialog, see [http://foicica.com/gtdialog][]. +-- +-- [gtdialog]: http://foicica.com/gtdialog/02_Usage.html +-- [http://foicica.com/gtdialog]: http://foicica.com/gtdialog +-- @param kind The kind of gtdialog. +-- @param ... Parameters to the gtdialog. +-- @return string gtdialog result. +-- @class function +-- @name dialog +local dialog + +--- +-- Returns the current split view structure. +-- This is primarily used in session saving. +-- @return table of split views. Each split view entry is a table with 4 +-- fields: `1`, `2`, `vertical`, and `size`. `1` and `2` have values of either +-- nested split view entries or the views themselves; `vertical` is a flag +-- indicating if the split is vertical or not; and `size` is the integer +-- position of the split resizer. +-- @class function +-- @name get_split_table +local get_split_table + +--- +-- Goes to view number *n*. +-- If *relative* is `true`, *n* is an index relative to the index of the current +-- view in `_G._VIEWS` instead of an absolute index. +-- Emits `VIEW_BEFORE_SWITCH` and `VIEW_AFTER_SWITCH` events. +-- @param n A relative or absolute view index in `_G._VIEWS`. +-- @param relative Optional flag indicating whether *n* is a relative or +-- absolute index. The default value is `false`, for an absolute index. +-- @see _G._G._VIEWS +-- @see events.VIEW_BEFORE_SWITCH +-- @see events.VIEW_AFTER_SWITCH +-- @class function +-- @name goto_view +local goto_view + +--- +-- Low-level function for creating a menu from table *menu_table* and returning +-- the userdata. +-- You probably want to use the higher-level `_M.textadept.menu.set_menubar()` +-- or `_M.textadept.menu.set_contextmenu()` functions. Emits a `MENU_CLICKED` +-- event when a menu item is selected. +-- @param menu_table A table defining the menu. It is an ordered list of tables +-- with a string menu item, integer menu ID, and optional GDK keycode and +-- modifier mask. The latter two are used to display key shortcuts in the +-- menu. '_' characters are treated as a menu mnemonics. If the menu item is +-- empty, a menu separator item is created. Submenus are just nested +-- menu-structure tables. Their title text is defined with a `title` key. +-- @usage ui.menu{{'_New', 1}, {'_Open', 2}, {''}, {'_Quit', 4}} +-- @usage ui.menu{{'_New', 1, string.byte('n'), 4}} -- 'Ctrl+N' +-- @see events.MENU_CLICKED +-- @see _M.textadept.menu.set_menubar +-- @see _M.textadept.menu.set_contextmenu +-- @class function +-- @name menu +local menu +]] diff --git a/doc/06_AdeptEditing.md b/doc/06_AdeptEditing.md index 68b0dbd4..7c885cce 100644 --- a/doc/06_AdeptEditing.md +++ b/doc/06_AdeptEditing.md @@ -196,7 +196,7 @@ tool such as [ack][]. ![Find in Files](images/findinfiles.png) -[find API]: api/gui.find.html#FILTER +[find API]: api/ui.find.html#FILTER [ack]: http://betterthangrep.com/ ### Incremental Find diff --git a/doc/09_Themes.md b/doc/09_Themes.md index eda6e47a..0fa9f5d3 100644 --- a/doc/09_Themes.md +++ b/doc/09_Themes.md @@ -28,15 +28,15 @@ display these standard colors. ## Setting Themes Override the default theme in your [*~/.textadept/init.lua*][] using the -[`gui.set_theme()`][] function. For example: +[`ui.set_theme()`][] function. For example: - gui.set_theme('dark') + ui.set_theme('dark') Either restart Textadept for changes to take effect or type [`reset()`][] in the [command entry][]. [*~/.textadept/init.lua*]: 08_Preferences.html#User.Init -[`gui.set_theme()`]: api/gui.html#set_theme +[`ui.set_theme()`]: api/ui.html#set_theme [`reset()`]: api/_G.html#reset [command entry]: 10_Advanced.html#Command.Entry @@ -54,12 +54,12 @@ scratch or tweak an existing one. Creating a new one is straightforward -- all you need to do is define a set of colors and a set of styles. Just follow the example of existing themes. If instead you want to use an existing theme like "light" but only change the font face and font size, you have two options: call -[`gui.set_theme()`][] from your *~/.textadept/init.lua* with additional +[`ui.set_theme()`][] from your *~/.textadept/init.lua* with additional parameters, or create an abbreviated *~/.textadept/themes/light.lua* using Lua's `dofile()` function. For example: -- File *~/.textadept/init.lua* - gui.set_theme('light', 'font', 'Monospace', 'fontsize', 12) + ui.set_theme('light', 'font', 'Monospace', 'fontsize', 12) -- File *~/.textadept/themes/light.lua* dofile(_HOME..'/themes/light.lua') @@ -70,7 +70,7 @@ Either one loads Textadept's "light" theme, but applies your font preferences. The same techniques work for tweaking individual theme colors and/or styles, but managing more changes is probably easier with the latter. -[`gui.set_theme()`]: api/gui.html#set_theme +[`ui.set_theme()`]: api/ui.html#set_theme ### Language diff --git a/doc/10_Advanced.md b/doc/10_Advanced.md index 9d921164..415be4e2 100644 --- a/doc/10_Advanced.md +++ b/doc/10_Advanced.md @@ -7,9 +7,9 @@ on Mac OSX | `M-C` in curses) to display the entry. It is useful for debugging, inspecting, and entering `buffer` or `view` commands. If you try to cause instability in Textadept's Lua state, you will probably succeed so be careful. The [Lua API][] lists available commands. The command entry provides abbreviated -commands for [`buffer`][], [`view`][] and [`gui`][]: you may reduce the +commands for [`buffer`][], [`view`][] and [`ui`][]: you may reduce the `buffer:append_text('foo')` command to `append_text('foo')`. Therefore, use -`_G.print()` for Lua's `print()` since `print()` expands to [`gui.print()`][]. +`_G.print()` for Lua's `print()` since `print()` expands to [`ui.print()`][]. These commands are runnable on startup using the `-e` and `--execute` command line switches. @@ -18,8 +18,8 @@ line switches. [Lua API]: api/index.html [`buffer`]: api/buffer.html [`view`]: api/view.html -[`gui`]: api/gui.html -[`gui.print()`]: api/gui.html#print +[`ui`]: api/ui.html +[`ui.print()`]: api/ui.html#print ### Tab Completion @@ -36,7 +36,7 @@ Executing Lua commands is just one of the many tools the command entry functions as. For example, *modules/textadept/find.lua* and *modules/textadept/keys.lua* extend it to implement [incremental search][]. -[incremental search]: api/gui.find.html#find_incremental +[incremental search]: api/ui.find.html#find_incremental ## Command Selection diff --git a/doc/14_Appendix.md b/doc/14_Appendix.md index 47135409..23c7312a 100644 --- a/doc/14_Appendix.md +++ b/doc/14_Appendix.md @@ -177,7 +177,7 @@ MARK\_ERROR\_BACK |Renamed |[ERROR\_COLOR][] open |Changed |\_G.[io.snapopen()][] **events** | | handlers |Removed |N/A -**gui** | | +**gui** |Renamed |[ui][] N/A |New |[maximized][] find.goto\_file\_in\_list() |Renamed |find.[goto\_file\_found()][] select\_theme |Removed |N/A @@ -200,8 +200,9 @@ try\_encodings |Renamed |[encodings][] [select\_enclosed()]: api/_M.textadept.editing.html#select_enclosed [ERROR\_COLOR]: api/_M.textadept.run.html#ERROR_COLOR [io.snapopen()]: api/io.html#snapopen -[maximized]: api/gui.html#maximized -[goto\_file\_found()]: api/gui.find.html#goto_file_found +[ui]: api/ui.html +[maximized]: api/ui.html#maximized +[goto\_file\_found()]: api/ui.find.html#goto_file_found [encodings]: api/io.html#encodings #### Theme Changes @@ -287,7 +288,7 @@ that specified your preferred Textadept 6 theme. Use *~/.textadept/init.lua* to terminal themes: -- File *~/.textadept/init.lua* - gui.set_theme(not CURSES and 'custom' or 'custom_term') + ui.set_theme(not CURSES and 'custom' or 'custom_term') You may still use absolute paths for themes instead of names. @@ -343,7 +344,7 @@ execute() |Replaced|[run()][] and [compile()][] prompt\_load() |Replaced|[load()][] prompt\_save() |Replaced|[save()][] -[menu()]: api/gui.html#menu +[menu()]: api/ui.html#menu [complete()]: api/_M.textadept.adeptsense.html#complete [show\_apidoc()]: api/_M.textadept.adeptsense.html#show_apidoc [toggle()]: api/_M.textadept.bookmarks.html#toggle @@ -577,32 +578,32 @@ views |Renamed|\_G.[\_VIEWS][] [API]: api [\_SCINTILLA]: api/_SCINTILLA.html [events]: api/events.html -[gui]: api/gui.html +[gui]: api/ui.html [_m.textadept.snippets]: api/_M.textadept.snippets.html -[gui.\_print()]: api/gui.html#_print +[gui.\_print()]: api/ui.html#_print [\_SCINTILLA.functions]: api/_SCINTILLA.html#functions [\_SCINTILLA.properties]: api/_SCINTILLA.html#properties [\_BUFFERS]: api/_G.html#_BUFFERS -[gui.clipboard\_text]: api/gui.html#clipboard_text -[gui.command\_entry]: api/gui.command_entry.html +[gui.clipboard\_text]: api/ui.html#clipboard_text +[gui.command\_entry]: api/ui.command_entry.html [\_SCINTILLA.constants]: api/_SCINTILLA.html#constants -[gui.context\_menu]: api/gui.html#context_menu -[gui.dialog()]: api/gui.html#dialog -[gui.docstatusbar\_text]: api/gui.html#docstatusbar_text +[gui.context\_menu]: api/ui.html#context_menu +[gui.dialog()]: api/ui.html#dialog +[gui.docstatusbar\_text]: api/ui.html#docstatusbar_text [events.connect()]: api/events.html#connect [events.emit()]: api/events.html#emit -[gui.find]: api/gui.find.html -[gui.get\_split\_table()]: api/gui.html#get_split_table -[gui.goto\_view()]: api/gui.html#goto_view -[gui.gtkmenu()]: api/gui.html#gtkmenu +[gui.find]: api/ui.find.html +[gui.get\_split\_table()]: api/ui.html#get_split_table +[gui.goto\_view()]: api/ui.html#goto_view +[gui.gtkmenu()]: api/ui.html#gtkmenu [string.iconv()]: api/string.html#iconv -[gui.menubar]: api/gui.html#menubar +[gui.menubar]: api/ui.html#menubar [new\_buffer()]: api/_G.html#new_buffer -[gui.print()]: api/gui.html#print +[gui.print()]: api/ui.html#print [quit()]: api/_G.html#quit [reset()]: api/_G.html#reset -[gui.size]: api/gui.html#size -[gui.statusbar\_text]: api/gui.html#statusbar_text -[gui.switch\_buffer()]: api/gui.html#switch_buffer -[gui.title]: api/gui.html#title +[gui.size]: api/ui.html#size +[gui.statusbar\_text]: api/ui.html#statusbar_text +[gui.switch\_buffer()]: api/ui.html#switch_buffer +[gui.title]: api/ui.html#title [\_VIEWS]: api/_G.html#_VIEWS diff --git a/init.lua b/init.lua index be783218..aebf0344 100644 --- a/init.lua +++ b/init.lua @@ -11,6 +11,6 @@ package.cpath = _USERHOME..so.._USERHOME..'/modules'..so..package.cpath _M.textadept = require('textadept') local ok, err = pcall(dofile, _USERHOME..'/init.lua') -if not ok and lfs.attributes(_USERHOME..'/init.lua') then gui.print(err) end +if not ok and lfs.attributes(_USERHOME..'/init.lua') then ui.print(err) end if arg then args.process(arg) end diff --git a/modules/textadept/adeptsense.lua b/modules/textadept/adeptsense.lua index 8a32f290..dd98c052 100644 --- a/modules/textadept/adeptsense.lua +++ b/modules/textadept/adeptsense.lua @@ -818,8 +818,8 @@ function M.goto_ctag(sense, kind, title) if kind == M.FUNCTION or kind == M.FIELD then table.insert(columns, 2, 'Class') end - local location = gui.filteredlist(title, columns, items, false, - '--output-column', '3') + local location = ui.filteredlist(title, columns, items, false, + '--output-column', '3') if not location then return end local path, line = location:match('^(%a?:?[^:]+):(.+)$') io.open_file(path) diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index e1d84ea0..e0031610 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -54,7 +54,7 @@ function M.goto_mark(next) marks[#marks + 1] = tostring(line + 1)..': '..text line = buffer:marker_next(line + 1, 2^MARK_BOOKMARK) until line < 0 - local line = gui.filteredlist(_L['Select Bookmark'], _L['Bookmark'], marks) + local line = ui.filteredlist(_L['Select Bookmark'], _L['Bookmark'], marks) if line then _M.textadept.editing.goto_line(line:match('^%d+')) end else local f = next and buffer.marker_next or buffer.marker_previous diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 4825faa9..7d9783bb 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -1,7 +1,7 @@ -- Copyright 2007-2013 Mitchell mitchell.att.foicica.com. See LICENSE. -- Abbreviated environment and commands from Jay Gould. -local M = gui.command_entry +local M = ui.command_entry --[[ This comment is for LuaDoc. --- @@ -16,11 +16,11 @@ local M = gui.command_entry -- for looking up key bindings. An example mode is "lua_command" mode for -- executing Lua commands: -- --- local gui_ce = gui.command_entry --- keys['ce'] = {gui_ce.enter_mode, 'lua_command'} +-- local ui_ce = ui.command_entry +-- keys['ce'] = {ui_ce.enter_mode, 'lua_command'} -- keys.lua_command = { --- ['\t'] = gui_ce.complete_lua, --- ['\n'] = {gui_ce.finish_mode, gui_ce.execute_lua} +-- ['\t'] = ui_ce.complete_lua, +-- ['\n'] = {ui_ce.finish_mode, ui_ce.execute_lua} -- } -- -- In this case, `Ctrl+E` opens the command entry and enters "lua_command" key @@ -33,7 +33,7 @@ local M = gui.command_entry -- [modes]: keys.html#Modes -- @field entry_text (string) -- The text in the entry. -module('gui.command_entry')]] +module('ui.command_entry')]] --- -- Opens the command entry in key mode *mode*. @@ -42,7 +42,7 @@ module('gui.command_entry')]] -- command entry, and restores normal key lookup. -- This function is useful for binding keys to enter a command entry mode. -- @param mode The key mode to enter into, or `nil` to exit the current mode. --- @usage keys['ce'] = {gui.command_entry.enter_mode, 'command_entry'} +-- @usage keys['ce'] = {ui.command_entry.enter_mode, 'command_entry'} -- @see _G.keys.MODE -- @name enter_mode function M.enter_mode(mode) @@ -61,7 +61,7 @@ end -- action with the entered text. -- @param f Optional function to call. It should accept the command entry text -- as an argument. --- @usage keys['\n'] = {gui.command_entry.finish_mode, gui.print} +-- @usage keys['\n'] = {ui.command_entry.finish_mode, ui.print} -- @name finish_mode function M.finish_mode(f) M.enter_mode(nil) @@ -78,12 +78,12 @@ local env = setmetatable({}, { if f and type(f) == 'function' then f = function(...) buffer[k](buffer, ...) end elseif f == nil then - f = view[k] or gui[k] or _G[k] + f = view[k] or ui[k] or _G[k] end return f end, __newindex = function(t, k, v) - for _, t2 in ipairs{buffer, view, gui} do + for _, t2 in ipairs{buffer, view, ui} do if t2[k] ~= nil then t2[k] = v return end end rawset(t, k, v) @@ -93,7 +93,7 @@ local env = setmetatable({}, { --- -- Executes string *code* as Lua code. -- Code is subject to an "abbreviated" environment where the `buffer`, `view`, --- and `gui` tables are also considered as globals. +-- and `ui` tables are also considered as globals. -- Prints the results of '=' expressions like in the Lua prompt. -- @param code The Lua code to execute. -- @name execute_lua @@ -102,7 +102,7 @@ function M.execute_lua(code) local f, err = load(code, nil, 'bt', env) if err then error(err) end local result = f() - if result ~= nil then gui.print(result) end + if result ~= nil then ui.print(result) end events.emit(events.UPDATE_UI) end args.register('-e', '--execute', 1, M.execute_lua, 'Execute Lua code') @@ -110,7 +110,7 @@ args.register('-e', '--execute', 1, M.execute_lua, 'Execute Lua code') --- -- Shows a set of Lua code completions for string *code* or `entry_text`. -- Completions are subject to an "abbreviated" environment where the `buffer`, --- `view`, and `gui` tables are also considered as globals. +-- `view`, and `ui` tables are also considered as globals. -- @param code The Lua code to complete. The default value is the value of -- `entry_text`. -- @name complete_lua @@ -122,7 +122,7 @@ function M.complete_lua(code) local cmpls = {} prefix = '^'..prefix if not ok then -- shorthand notation - for _, t in ipairs{buffer, view, gui, _G} do + for _, t in ipairs{buffer, view, ui, _G} do for k in pairs(t) do if type(k) == 'string' and k:find(prefix) then cmpls[#cmpls + 1] = k end end diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 19d3587c..897384c2 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -184,7 +184,7 @@ events.connect(events.FILE_BEFORE_SAVE, function() end) --- --- Goes to the current character's matching brace, selecting the text in-between +-- Goes to the current character's matching brace, selecting the text in between -- if *select* is `true`. -- @param select Optional flag indicating whether or not to select the text -- between matching braces. The default value is `false`. @@ -314,12 +314,12 @@ end -- @name goto_line function M.goto_line(line) if not line then - line = tonumber(gui.dialog('inputbox', - '--title', _L['Go To'], - '--text', _L['Line Number:'], - '--button1', _L['_OK'], - '--button2', _L['_Cancel'], - '--no-newline'):match('%-?%d+$')) + line = tonumber(ui.dialog('inputbox', + '--title', _L['Go To'], + '--text', _L['Line Number:'], + '--button1', _L['_OK'], + '--button2', _L['_Cancel'], + '--no-newline'):match('%-?%d+$')) if not line or line < 0 then return end end buffer:ensure_visible_enforce_policy(line - 1) @@ -371,9 +371,8 @@ function M.enclose(left, right) end --- --- Selects the text in-between strings *left* and *right* containing the caret. --- If already selected, toggles between selecting the *left* and *right* --- enclosures too. +-- Selects the text between strings *left* and *right* containing the caret. +-- If already selected, toggles between selecting *left* and *right* too. -- @param left The left part of the enclosure. -- @param right The right part of the enclosure. -- @name select_enclosed @@ -440,8 +439,7 @@ function M.select_indented_block() end --- --- Converts indentation between tabs and spaces depending on the buffer's --- indentation settings. +-- Converts indentation between tabs and spaces based on `buffer.use_tabs`. -- If `buffer.use_tabs` is `true`, `buffer.tab_width` indenting spaces are -- converted to tabs. Otherwise, all indenting tabs are converted to -- `buffer.tab_width` spaces. @@ -515,9 +513,9 @@ if buffer then set_highlight_properties() end events.connect(events.VIEW_NEW, set_highlight_properties) --- --- Passes selected or all buffer text to string shell command *cmd* as standard --- input (stdin) and replaces the input text with the command's standard output --- (stdout). +-- Passes selected or all buffer text to string shell command *command* as +-- standard input (stdin) and replaces the input text with the command's +-- standard output (stdout). -- Standard input is as follows: -- -- 1. If text is selected and spans multiple lines, all text on the lines @@ -527,10 +525,10 @@ events.connect(events.VIEW_NEW, set_highlight_properties) -- 2. If text is selected and spans a single line, only the selected text is -- used. -- 3. If no text is selected, the entire buffer is used. --- @param cmd The Linux, BSD, Mac OSX, or Windows shell command to filter text --- through. +-- @param command The Linux, BSD, Mac OSX, or Windows shell command to filter +-- text through. -- @name filter_through -function M.filter_through(cmd) +function M.filter_through(command) local s, e = buffer.selection_start, buffer.selection_end local input if s ~= e then -- use selected lines as input @@ -547,7 +545,7 @@ function M.filter_through(cmd) local f = io.open(tmpfile, 'wb') f:write(input) f:close() - local cmd = (not WIN32 and 'cat' or 'type')..' "'..tmpfile..'" | '..cmd + local cmd = (not WIN32 and 'cat' or 'type')..' "'..tmpfile..'" | '..command if WIN32 then cmd = cmd:gsub('/', '\\') end local p = io.popen(cmd) if s ~= e then diff --git a/modules/textadept/file_types.lua b/modules/textadept/file_types.lua index f54742f8..1d57070b 100644 --- a/modules/textadept/file_types.lua +++ b/modules/textadept/file_types.lua @@ -128,7 +128,7 @@ events.connect(events.RESET_AFTER, restore_lexer) -- @see buffer.set_lexer -- @name select_lexer function M.select_lexer() - local lexer = gui.filteredlist(_L['Select Lexer'], _L['Name'], M.lexers) + local lexer = ui.filteredlist(_L['Select Lexer'], _L['Name'], M.lexers) if lexer then buffer:set_lexer(lexer) end end diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index cb0bd449..d4422963 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -1,6 +1,6 @@ -- Copyright 2007-2013 Mitchell mitchell.att.foicica.com. See LICENSE. -local M = gui.find +local M = ui.find --[[ This comment is for LuaDoc. --- @@ -57,7 +57,7 @@ local M = gui.find -- previous occurrence. -- This is useful for implementing a more visual or audible notice when a -- search wraps in addition to the statusbar message. -module('gui.find')]] +module('ui.find')]] local _L = _L M.find_label_text = not CURSES and _L['_Find:'] or _L['Find:'] @@ -154,16 +154,16 @@ local function find_(text, next, flags, no_wrap, wrapped) if pos == -1 and not no_wrap then local anchor, pos = buffer.anchor, buffer.current_pos buffer:goto_pos(next and 0 or buffer.length) - gui.statusbar_text = _L['Search wrapped'] + ui.statusbar_text = _L['Search wrapped'] events.emit(events.FIND_WRAPPED) pos = find_(text, next, flags, true, true) if pos == -1 then - gui.statusbar_text = _L['No results found'] + ui.statusbar_text = _L['No results found'] buffer:line_scroll(0, first_visible_line - buffer.first_visible_line) buffer:goto_pos(anchor) end elseif not wrapped then - gui.statusbar_text = '' + ui.statusbar_text = '' end return pos @@ -203,8 +203,8 @@ end function M.find_incremental(text, next, anchor) if text then find_incremental(text, next, anchor) return end M.incremental_start = buffer.current_pos - gui.command_entry.entry_text = '' - gui.command_entry.enter_mode('find_incremental') + ui.command_entry.entry_text = '' + ui.command_entry.enter_mode('find_incremental') end --- @@ -219,12 +219,12 @@ end -- @name find_in_files function M.find_in_files(utf8_dir) if not utf8_dir then - utf8_dir = gui.dialog('fileselect', - '--title', _L['Find in Files'], - '--select-only-directories', - '--with-directory', - (buffer.filename or ''):match('^.+[/\\]') or '', - '--no-newline') + utf8_dir = ui.dialog('fileselect', + '--title', _L['Find in Files'], + '--select-only-directories', + '--with-directory', + (buffer.filename or ''):match('^.+[/\\]') or '', + '--no-newline') end if utf8_dir == '' then return end @@ -247,7 +247,7 @@ function M.find_in_files(utf8_dir) if #matches == 1 then matches[2] = _L['No results found'] end matches[#matches + 1] = '' if buffer._type ~= _L['[Files Found Buffer]'] then preferred_view = view end - gui._print(_L['[Files Found Buffer]'], table.concat(matches, '\n')) + ui._print(_L['[Files Found Buffer]'], table.concat(matches, '\n')) end -- Replaces found text. @@ -278,15 +278,15 @@ local function replace(rtext) buffer:replace_target(rtext:gsub('\\[abfnrtv\\]', escapes)) buffer:goto_pos(buffer.target_end) -- 'find' text after this replacement else - gui.dialog('ok-msgbox', - '--title', _L['Error'], - '--text', _L['An error occured:'], - '--informative-text', - rtext:match(':1:(.+)$') or rtext:match(':%d+:(.+)$'), - '--icon', 'gtk-dialog-error', - '--button1', _L['_OK'], - '--button2', _L['_Cancel'], - '--no-cancel') + ui.dialog('ok-msgbox', + '--title', _L['Error'], + '--text', _L['An error occured:'], + '--informative-text', + rtext:match(':1:(.+)$') or rtext:match(':%d+:(.+)$'), + '--icon', 'gtk-dialog-error', + '--button1', _L['_OK'], + '--button2', _L['_Cancel'], + '--no-cancel') -- Since find is called after replace returns, have it 'find' the current -- text again, rather than the next occurance so the user can fix the error. buffer:goto_pos(buffer.current_pos) @@ -327,7 +327,7 @@ local function replace_all(ftext, rtext) buffer:set_sel(s, e > 0 and e or buffer.length) buffer:indicator_clear_range(e, 1) end - gui.statusbar_text = ("%d %s"):format(count, _L['replacement(s) made']) + ui.statusbar_text = ("%d %s"):format(count, _L['replacement(s) made']) buffer:end_undo_action() end events.connect(events.REPLACE_ALL, replace_all) @@ -352,7 +352,7 @@ function M.goto_file_found(line, next) if is_ff_buf(_BUFFERS[i]) then ff_buf = i break end end if not ff_view and not ff_buf then return end - if ff_view then gui.goto_view(ff_view) else view:goto_buffer(ff_buf) end + if ff_view then ui.goto_view(ff_view) else view:goto_buffer(ff_buf) end -- If not line was given, find the next search result. if not line and next ~= nil then @@ -374,7 +374,7 @@ function M.goto_file_found(line, next) local file, line_num = buffer:get_cur_line():match('^(.+):(%d+):.+$') if not file then if CURSES then view:goto_buffer(cur_buf) end return end _M.textadept.editing.select_line() - gui.goto_file(file, true, preferred_view) + ui.goto_file(file, true, preferred_view) _M.textadept.editing.goto_line(line_num) end events.connect(events.DOUBLE_CLICK, function(pos, line) diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index c81f3602..0e1f4206 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -230,8 +230,8 @@ M.utils = { buffer:insert_text(-1, ' 1 and k:find('^[cams]*.+$') then return end - gui.find.find_incremental(gui.command_entry.entry_text..k, true) + ui.find.find_incremental(ui.command_entry.entry_text..k, true) end}) return M diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index b0cc2953..3997375b 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -51,7 +51,7 @@ local menubar = { {_L['Toggle _Block Comment'], m_editing.block_comment}, {_L['T_ranspose Characters'], m_editing.transpose_chars}, {_L['_Join Lines'], m_editing.join_lines}, - {_L['_Filter Through'], {gui.command_entry.enter_mode, 'filter_through'}}, + {_L['_Filter Through'], {ui.command_entry.enter_mode, 'filter_through'}}, { title = _L['_Select'], {_L['Select to _Matching Brace'], {m_editing.match_brace, 'select'}}, {_L['Select between _XML Tags'], {m_editing.select_enclosed, '>', '<'}}, @@ -83,21 +83,21 @@ local menubar = { }, }, { title = _L['_Search'], - {_L['_Find'], gui.find.focus}, - {_L['Find _Next'], gui.find.find_next}, - {_L['Find _Previous'], gui.find.find_prev}, - {_L['_Replace'], gui.find.replace}, - {_L['Replace _All'], gui.find.replace_all}, - {_L['Find _Incremental'], gui.find.find_incremental}, + {_L['_Find'], ui.find.focus}, + {_L['Find _Next'], ui.find.find_next}, + {_L['Find _Previous'], ui.find.find_prev}, + {_L['_Replace'], ui.find.replace}, + {_L['Replace _All'], ui.find.replace_all}, + {_L['Find _Incremental'], ui.find.find_incremental}, SEPARATOR, {_L['Find in Fi_les'], utils.find_in_files}, - {_L['Goto Nex_t File Found'], {gui.find.goto_file_found, false, true}}, - {_L['Goto Previou_s File Found'], {gui.find.goto_file_found, false, false}}, + {_L['Goto Nex_t File Found'], {ui.find.goto_file_found, false, true}}, + {_L['Goto Previou_s File Found'], {ui.find.goto_file_found, false, false}}, SEPARATOR, {_L['_Jump to'], m_editing.goto_line}, }, { title = _L['_Tools'], - {_L['Command _Entry'], {gui.command_entry.enter_mode, 'lua_command'}}, + {_L['Command _Entry'], {ui.command_entry.enter_mode, 'lua_command'}}, {_L['Select Co_mmand'], utils.select_command}, SEPARATOR, {_L['_Run'], _M.textadept.run.run}, @@ -133,7 +133,7 @@ local menubar = { { title = _L['_Buffer'], {_L['_Next Buffer'], {view.goto_buffer, view, 1, true}}, {_L['_Previous Buffer'], {view.goto_buffer, view, -1, true}}, - {_L['_Switch to Buffer...'], gui.switch_buffer}, + {_L['_Switch to Buffer...'], ui.switch_buffer}, SEPARATOR, { title = _L['_Indentation'], {_L['Tab width: _2'], {utils.set_indentation, 2}}, @@ -161,8 +161,8 @@ local menubar = { {_L['_Refresh Syntax Highlighting'], {buffer.colourise, buffer, 0, -1}}, }, { title = _L['_View'], - {_L['_Next View'], {gui.goto_view, 1, true}}, - {_L['_Previous View'], {gui.goto_view, -1, true}}, + {_L['_Next View'], {ui.goto_view, 1, true}}, + {_L['_Previous View'], {ui.goto_view, -1, true}}, SEPARATOR, {_L['Split View _Horizontal'], {view.split, view}}, {_L['Split View _Vertical'], {view.split, view, true}}, @@ -192,7 +192,7 @@ local menubar = { {_L['Show _LuaDoc'], {utils.open_webpage, _HOME..'/doc/api/index.html'}}, SEPARATOR, {_L['_About'], - {gui.dialog, 'ok-msgbox', '--title', 'Textadept', '--text', _RELEASE, + {ui.dialog, 'ok-msgbox', '--title', 'Textadept', '--text', _RELEASE, '--informative-text', 'Copyright © 2007-2013 Mitchell. See LICENSE\n'.. 'http://foicica.com/textadept', '--button1', _L['_OK'], '--no-cancel', '--icon-file', _HOME..'/core/images/ta_64x64.png'}}, @@ -247,13 +247,13 @@ end local key_shortcuts, menu_actions, contextmenu_actions --- Creates a menu suitable for `gui.menu()` from the menu table format. +-- Creates a menu suitable for `ui.menu()` from the menu table format. -- Also assigns key commands. -- @param menu The menu to create a GTK+ menu from. -- @param contextmenu Flag indicating whether or not the menu is a context menu. -- If so, menu_id offset is 1000. The default value is `false`. --- @return GTK+ menu that can be passed to `gui.menu()`. --- @see gui.menu +-- @return GTK+ menu that can be passed to `ui.menu()`. +-- @see ui.menu local function read_menu_table(menu, contextmenu) local gtkmenu = {} gtkmenu.title = menu.title @@ -297,15 +297,15 @@ end local items, commands --- --- Sets `gui.menubar` from *menubar*, a table of menus. +-- Sets `ui.menubar` from *menubar*, a table of menus. -- Each menu is an ordered list of menu items and has a `title` key for the -- title text. Menu items are tables containing menu text and either a function -- to call or a table containing a function with its parameters to call when an -- item is clicked. Menu items may also be sub-menus, ordered lists of menu -- items with an additional `title` key for the sub-menu's title text. -- @param menubar The table of menu tables to create the menubar from. --- @see gui.menubar --- @see gui.menu +-- @see ui.menubar +-- @see ui.menu -- @name set_menubar function M.set_menubar(menubar) key_shortcuts = {} @@ -313,27 +313,27 @@ function M.set_menubar(menubar) menu_actions = {} local _menubar = {} for i = 1, #menubar do - _menubar[#_menubar + 1] = gui.menu(read_menu_table(menubar[i])) + _menubar[#_menubar + 1] = ui.menu(read_menu_table(menubar[i])) end - gui.menubar = _menubar + ui.menubar = _menubar items, commands = {}, {} build_command_tables(menubar, nil, items, commands) end M.set_menubar(menubar) --- --- Sets `gui.context_menu` from *menu*, an ordered list of menu items. +-- Sets `ui.context_menu` from *menu*, an ordered list of menu items. -- Menu items are tables containing menu text and either a function to call or -- a table containing a function with its parameters to call when an item is -- clicked. Menu items may also be sub-menus, ordered lists of menu items with -- an additional `title` key for the sub-menu's title text. -- @param menu The menu table to create the context menu from. --- @see gui.context_menu --- @see gui.menu +-- @see ui.context_menu +-- @see ui.menu -- @name set_contextmenu function M.set_contextmenu(menu) contextmenu_actions = {} - gui.context_menu = gui.menu(read_menu_table(menu, true)) + ui.context_menu = ui.menu(read_menu_table(menu, true)) end if not CURSES then M.set_contextmenu(context_menu) end @@ -341,9 +341,9 @@ if not CURSES then M.set_contextmenu(context_menu) end -- Prompts the user to select a menu command to run. -- @name select_command function M.select_command() - local i = gui.filteredlist(_L['Run Command'], - {_L['Command'], _L['Key Command']}, items, true, - CURSES and {'--width', gui.size[1] - 2} or '') + local i = ui.filteredlist(_L['Run Command'], + {_L['Command'], _L['Key Command']}, items, true, + CURSES and {'--width', ui.size[1] - 2} or '') if i then keys.run_command(commands[i + 1], type(commands[i + 1])) end end diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index 7e0dc83b..38a5e0f4 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -106,9 +106,9 @@ local MARK_ERROR = _SCINTILLA.next_marker_number() -- @param lexer The current lexer. -- @param output The output to print. local function print_output(lexer, output) - gui.print(output) + ui.print(output) if get_error_details(output) then - -- Current position is one line below the error due to gui.print()'s '\n'. + -- Current position is one line below the error due to ui.print()'s '\n'. buffer:marker_add(buffer.line_count - 2, MARK_ERROR) end end @@ -214,7 +214,7 @@ function M.goto_error(line, next) if is_msg_buf(_BUFFERS[i]) then msg_buf = i break end end if not msg_view and not msg_buf then return end - if msg_view then gui.goto_view(msg_view) else view:goto_buffer(msg_buf) end + if msg_view then ui.goto_view(msg_view) else view:goto_buffer(msg_buf) end -- If no line was given, find the next error marker. if not line and next ~= nil then @@ -232,7 +232,7 @@ function M.goto_error(line, next) local err = get_error_details(buffer:get_line(line)) if not err then if CURSES then view:goto_buffer(cur_buf) end return end _M.textadept.editing.select_line() - gui.goto_file(M.cwd..err.filename, true, preferred_view, true) + ui.goto_file(M.cwd..err.filename, true, preferred_view, true) local line, message = err.line, err.message buffer:goto_line(line - 1) if message then diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index d9783512..3aca6453 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -40,13 +40,13 @@ M.MAX_RECENT_FILES = 10 -- @see DEFAULT_SESSION -- @name load function M.load(filename) - filename = filename or gui.dialog('fileselect', - '--title', _L['Load Session'], - '--with-directory', - M.DEFAULT_SESSION:match('.+[/\\]') or '', - '--with-file', - M.DEFAULT_SESSION:match('[^/\\]+$') or '', - '--no-newline'):iconv(_CHARSET, 'UTF-8') + filename = filename or ui.dialog('fileselect', + '--title', _L['Load Session'], + '--with-directory', + M.DEFAULT_SESSION:match('.+[/\\]') or '', + '--with-file', + M.DEFAULT_SESSION:match('[^/\\]+$') or '', + '--no-newline'):iconv(_CHARSET, 'UTF-8') if filename == '' then return end local not_found = {} local f = io.open(filename, 'rb') @@ -91,7 +91,7 @@ function M.load(filename) elseif line:find('^size:') then local maximized, width, height = line:match('^size: (%l*) ?(%d+) (%d+)$') maximized = maximized == 'true' - if maximized then gui.maximized = true else gui.size = {width, height} end + if maximized then ui.maximized = true else ui.size = {width, height} end elseif line:find('^recent:') then local filename = line:match('^recent: (.+)$') local recent, exists = io.recent_files, false @@ -102,14 +102,14 @@ function M.load(filename) end end f:close() - gui.goto_view(current_view) + ui.goto_view(current_view) if #not_found > 0 then - gui.dialog('msgbox', - '--title', _L['Session Files Not Found'], - '--text', _L['The following session files were not found'], - '--informative-text', table.concat(not_found, '\n'), - '--icon', 'gtk-dialog-warning', - '--button1', _L['_OK']) + ui.dialog('msgbox', + '--title', _L['Session Files Not Found'], + '--text', _L['The following session files were not found'], + '--informative-text', table.concat(not_found, '\n'), + '--icon', 'gtk-dialog-warning', + '--button1', _L['_OK']) end return true end @@ -127,13 +127,13 @@ end) -- @see DEFAULT_SESSION -- @name save function M.save(filename) - filename = filename or gui.dialog('filesave', - '--title', _L['Save Session'], - '--with-directory', - M.DEFAULT_SESSION:match('.+[/\\]') or '', - '--with-file', - M.DEFAULT_SESSION:match('[^/\\]+$') or '', - '--no-newline'):iconv(_CHARSET, 'UTF-8') + filename = filename or ui.dialog('filesave', + '--title', _L['Save Session'], + '--with-directory', + M.DEFAULT_SESSION:match('.+[/\\]') or '', + '--with-file', + M.DEFAULT_SESSION:match('[^/\\]+$') or '', + '--no-newline'):iconv(_CHARSET, 'UTF-8') if filename == '' then return end local session = {} local buffer_line = "buffer: %d %d %d %s" -- anchor, cursor, line, filename @@ -171,7 +171,7 @@ function M.save(filename) session[#session + 1] = view_line:format(spaces, 2, _BUFFERS[c2.buffer]) end end - local splits = gui.get_split_table() + local splits = ui.get_split_table() if splits[1] and splits[2] then write_split(splits, 0, 0) else @@ -180,7 +180,7 @@ function M.save(filename) -- Write out the current focused view. session[#session + 1] = ("current_view: %d"):format(_VIEWS[view]) -- Write out other things. - local maximized, size = tostring(gui.maximized), gui.size + local maximized, size = tostring(ui.maximized), ui.size session[#session + 1] = ("size: %s %d %d"):format(maximized, size[1], size[2]) for i = 1, #io.recent_files do if i > M.MAX_RECENT_FILES then break end diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua index e25f7a81..aa2933f8 100644 --- a/modules/textadept/snippets.lua +++ b/modules/textadept/snippets.lua @@ -187,10 +187,10 @@ function M._select() for i = 1, #list do t[#t + 1], t[#t + 2], t[#t + 3] = list[i]:match('^(%Z+)%z(%Z+)%z(%Z+)$') end - local i = gui.filteredlist(_L['Select Snippet'], - {_L['Trigger'], _L['Scope'], _L['Snippet Text']}, - t, true, '--output-column', '2', - CURSES and {'--width', gui.size[1] - 2} or '') + local i = ui.filteredlist(_L['Select Snippet'], + {_L['Trigger'], _L['Scope'], _L['Snippet Text']}, + t, true, '--output-column', '2', + CURSES and {'--width', ui.size[1] - 2} or '') if i then M._insert(t[(i + 1) * 3]) end end diff --git a/src/textadept.c b/src/textadept.c index 3e150bd1..a7136f44 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -679,8 +679,8 @@ static int lce__newindex(lua_State *L) { return 0; } -/** `gui.dialog()` Lua function. */ -static int lgui_dialog(lua_State *L) { +/** `ui.dialog()` Lua function. */ +static int lui_dialog(lua_State *L) { GTDialogType type = gtdialog_type(luaL_checkstring(L, 1)); int i, j, k, n = lua_gettop(L) - 1, argc = n; for (i = 2; i < n + 2; i++) @@ -737,8 +737,8 @@ static void l_pushsplittable(lua_State *L, GtkWidget *c1, GtkWidget *c2) { } #endif -/** `gui.get_split_table()` Lua function. */ -static int lgui_get_split_table(lua_State *L) { +/** `ui.get_split_table()` Lua function. */ +static int lui_get_split_table(lua_State *L) { #if GTK GtkWidget *pane = gtk_widget_get_parent(focused_view); if (GTK_IS_PANED(pane)) { @@ -790,8 +790,8 @@ static void goto_view(Scintilla *view) { if (!closing) lL_event(lua, "view_after_switch", -1); } -/** `gui.goto_view()` Lua function. */ -static int lgui_goto_view(lua_State *L) { +/** `ui.goto_view()` Lua function. */ +static int lui_goto_view(lua_State *L) { int n = luaL_checkinteger(L, 1), relative = lua_toboolean(L, 2); if (relative && n == 0) return 0; lua_getfield(L, LUA_REGISTRYINDEX, "ta_views"); @@ -811,7 +811,7 @@ static int lgui_goto_view(lua_State *L) { Scintilla *view = l_toview(L, -1); focus_view(view); #if GTK - // gui.dialog() interferes with focus so gtk_widget_grab_focus() does not + // ui.dialog() interferes with focus so gtk_widget_grab_focus() does not // always work. If this is the case, ensure goto_view() is called. if (!gtk_widget_has_focus(view)) goto_view(view); #endif @@ -895,8 +895,8 @@ static void m_clicked(GtkWidget*_, void *id) { } #endif -/** `gui.menu()` Lua function. */ -static int lgui_menu(lua_State *L) { +/** `ui.menu()` Lua function. */ +static int lui_menu(lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); #if GTK return (l_pushmenu(L, -1, G_CALLBACK(m_clicked), FALSE), 1); @@ -905,8 +905,8 @@ static int lgui_menu(lua_State *L) { #endif } -/** `gui.__index` Lua metatable. */ -static int lgui__index(lua_State *L) { +/** `ui.__index` Lua metatable. */ +static int lui__index(lua_State *L) { const char *key = lua_tostring(L, 2); if (strcmp(key, "clipboard_text") == 0) { #if GTK @@ -952,8 +952,8 @@ static void set_statusbar_text(const char *text, int bar) { #endif } -/** `gui.__newindex` Lua metatable. */ -static int lgui__newindex(lua_State *L) { +/** `ui.__newindex` Lua metatable. */ +static int lui__newindex(lua_State *L) { const char *key = lua_tostring(L, 2); if (strcmp(key, "title") == 0) { #if GTK @@ -1528,12 +1528,12 @@ static int lL_init(lua_State *L, int argc, char **argv, int reinit) { l_setcfunction(L, -1, "show_completions", lce_show_completions); l_setmetatable(L, -1, "ta_command_entry", lce__index, lce__newindex); lua_setfield(L, -2, "command_entry"); - l_setcfunction(L, -1, "dialog", lgui_dialog); - l_setcfunction(L, -1, "get_split_table", lgui_get_split_table); - l_setcfunction(L, -1, "goto_view", lgui_goto_view); - l_setcfunction(L, -1, "menu", lgui_menu); - l_setmetatable(L, -1, "ta_gui", lgui__index, lgui__newindex); - lua_setglobal(L, "gui"); + l_setcfunction(L, -1, "dialog", lui_dialog); + l_setcfunction(L, -1, "get_split_table", lui_get_split_table); + l_setcfunction(L, -1, "goto_view", lui_goto_view); + l_setcfunction(L, -1, "menu", lui_menu); + l_setmetatable(L, -1, "ta_ui", lui__index, lui__newindex); + lua_setglobal(L, "ui"); lua_getglobal(L, "_G"); l_setcfunction(L, -1, "quit", lquit); @@ -1818,7 +1818,7 @@ static int s_keypress(GtkWidget*_, GdkEventKey *event, void*__) { * @param event An optional GTK mouse button event. */ static void lL_showcontextmenu(lua_State *L, void *event) { - lua_getglobal(L, "gui"); + lua_getglobal(L, "ui"); if (lua_istable(L, -1)) { lua_getfield(L, -1, "context_menu"); if (lua_isuserdata(L, -1)) { @@ -1828,7 +1828,7 @@ static void lL_showcontextmenu(lua_State *L, void *event) { event ? ((GdkEventButton *)event)->button : 0, gdk_event_get_time((GdkEvent *)event)); } - lua_pop(L, 1); // gui.context_menu + lua_pop(L, 1); // ui.context_menu } else lua_pop(L, 1); // non-table } -- cgit v1.2.3