aboutsummaryrefslogtreecommitdiffhomepage
path: root/core
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2009-02-14 13:17:08 -0500
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2009-02-14 13:17:08 -0500
commit3b6617f2df302470c23aa0124001d277e6996a2e (patch)
treed14f89ec1e7c704317d134b713b5640b0eddebe6 /core
parent11b06ce10256daad65a4dae95657710dc1902218 (diff)
Prompt for file reload if it was modified outside of Textadept.
Diffstat (limited to 'core')
-rw-r--r--core/file_io.lua30
-rw-r--r--core/locale.lua12
2 files changed, 42 insertions, 0 deletions
diff --git a/core/file_io.lua b/core/file_io.lua
index d65c5c2f..7500667c 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -12,6 +12,8 @@ local locale = _G.locale
-- file_saved_as(filename)
module('textadept.io', package.seeall)
+local lfs = require 'lfs'
+
---
-- List of recently opened files.
-- @class table
@@ -40,6 +42,7 @@ local function open_helper(filename)
buffer:add_text(text, #text)
buffer:goto_pos(0)
buffer:empty_undo_buffer()
+ buffer.modification_time = lfs.attributes(filename).modification
end
buffer.filename = filename
buffer:set_save_point()
@@ -101,6 +104,7 @@ function save(buffer)
f:write(txt)
f:close()
buffer:set_save_point()
+ buffer.modification_time = lfs.attributes(buffer.filename).modification
else
textadept.events.error(err)
end
@@ -346,3 +350,29 @@ function read_api_file(filename, word_chars)
end
return api
end
+
+---
+-- [Local function] Prompts the user to reload the current file if it has been
+-- modified outside of Textadept.
+local function update_modified_file()
+ local filename = buffer.filename
+ if filename then
+ local attributes = lfs.attributes(filename)
+ if not attributes then return end
+ if buffer.modification_time < attributes.modification then
+ if cocoa_dialog('yesno-msgbox', {
+ title = locale.IO_RELOAD_TITLE,
+ text = locale.IO_RELOAD_TEXT,
+ ['informative-text'] = string.format(locale.IO_RELOAD_MSG, filename),
+ ['no-cancel'] = true,
+ ['no-newline'] = true
+ }) == '1' then
+ buffer:reload()
+ else
+ buffer.modification_time = attributes.modification
+ end
+ end
+ end
+end
+textadept.events.add_handler('buffer_switch', update_modified_file)
+textadept.events.add_handler('view_switch', update_modified_file)
diff --git a/core/locale.lua b/core/locale.lua
index 22113b1e..7b584a5c 100644
--- a/core/locale.lua
+++ b/core/locale.lua
@@ -66,6 +66,18 @@ IO_CLOSE_TITLE = 'Save?'
IO_CLOSE_TEXT = 'Save changes before closing?'
-- You will have to save changes manually.
IO_CLOSE_MSG = 'You will have to save changes manually.'
+-- Reload?
+IO_RELOAD_TITLE = 'Reload?'
+-- Reload modified file?
+IO_RELOAD_TEXT = 'Reload modified file?'
+-- '%s'
+-- has been modified outside of Textadept.
+-- Reload it to reflect the newest version?
+IO_RELOAD_MSG = [[
+'%s'
+has been modified outside of Textadept.
+Reload it to reflect the newest version?
+]]
-- core/iface.lua