diff options
-rw-r--r-- | core/ext/menu.lua | 30 | ||||
-rw-r--r-- | core/file_io.lua | 6 | ||||
-rw-r--r-- | core/locale.conf | 8 |
3 files changed, 40 insertions, 4 deletions
diff --git a/core/ext/menu.lua b/core/ext/menu.lua index 25e9950c..0fe2cfb5 100644 --- a/core/ext/menu.lua +++ b/core/ext/menu.lua @@ -358,8 +358,34 @@ local actions = { [ID.SAVEAS] = { 'save_as', b }, [ID.CLOSE] = { 'close', b }, [ID.CLOSE_ALL] = { t.io.close_all }, - [ID.LOAD_SESSION] = { t.io.load_session }, -- TODO: file open dialog prompt - [ID.SAVE_SESSION] = { t.io.save_session }, -- TODO: file save dialog prompt + [ID.LOAD_SESSION] = { + function() + local utf8_filename = + cocoa_dialog('fileselect', { + title = l.MENU_LOAD_SESSION_TITLE, + ['with-directory'] = (textadept.session_file or ''):match('.+[/\\]'), + ['with-file'] = (textadept.session_file or ''):match('[^/\\]+$'), + ['no-newline'] = true + }) + if #utf8_filename > 0 then + t.io.load_session(t.iconv(utf8_filename, _CHARSET, 'UTF-8')) + end + end + }, + [ID.SAVE_SESSION] = { + function() + local utf8_filename = + cocoa_dialog('filesave', { + title = l.MENU_SAVE_SESSION_TITLE, + ['with-directory'] = (textadept.session_file or ''):match('.+[/\\]'), + ['with-file'] = (textadept.session_file or ''):match('[^/\\]+$'), + ['no-newline'] = true + }) + if #utf8_filename > 0 then + t.io.save_session(t.iconv(utf8_filename, _CHARSET, 'UTF-8')) + end + end + }, [ID.QUIT] = { t.quit }, -- Edit [ID.UNDO] = { 'undo', b }, diff --git a/core/file_io.lua b/core/file_io.lua index 4cb9210f..b0131aa1 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -374,6 +374,7 @@ function load_session(filename, only_pm) end f:close() textadept.views[current_view]:focus() + textadept.session_file = filename or ta_session return true end @@ -382,7 +383,8 @@ end -- Saves split views, opened buffers, cursor information, and project manager -- details. -- @param filename The absolute path to the session file to save. Defaults to --- $HOME/.textadept/session if not specified. +-- either the current session file or $HOME/.textadept/session if not +-- specified. -- @usage textadept.io.save_session(filename) function save_session(filename) local session = {} @@ -444,7 +446,7 @@ function save_session(filename) ("pm: %d %s %s"):format(pm.width, pm.cursor or '0', pm.entry_text) -- Write the session. local ta_session = _USERHOME..'/session' - local f = io.open(filename or ta_session, 'wb') + local f = io.open(filename or textadept.session_file or ta_session, 'wb') if f then f:write(table.concat(session, '\n')) f:close() diff --git a/core/locale.conf b/core/locale.conf index 98f48b97..a7ce2028 100644 --- a/core/locale.conf +++ b/core/locale.conf @@ -648,6 +648,14 @@ MENU_HELP_LUADOC "_LuaDoc" MENU_BROWSER_ERROR "Error loading webpage.\nCheck the browser path in core/ext/menu.lua" % core/ext/menu.lua +% "Load Session" +MENU_LOAD_SESSION_TITLE "Load Session" + +% core/ext/menu.lua +% "Save Session" +MENU_SAVE_SESSION_TITLE "Save Session" + +% core/ext/menu.lua % "Unknown command: " MENU_UNKNOWN_COMMAND "Unknown command: " |