Re: [code] [textadept] Reload file dialog

From: Mitchell <m.att.foicica.com>
Date: Thu, 13 Dec 2018 22:29:27 -0500 (EST)

Hi Chris,

On Thu, 13 Dec 2018, Chris Emerson wrote:

> Hi,
>
> A minor annoyance I have with the curses version is that the dialog which
> asks if I want to reload a file which has changed on disk (or also if a
> buffer is unsaved when exiting) is too small - I can only see the start
> of the filename:
>
> ┌──────────────────────────────────────┐
> │Reload modified file? │
> │ │
> │"/home/chris/working/some-project/src/│
> │has been modified. Reload │
> │it? │
> │┌────────────────────────────────────┐│
> ││ No Yes ││
> │└────────────────────────────────────┘│
> └──────────────────────────────────────┘
>
> ...which means I have no idea which file in the current project it's about.
> :-)

Yeah, I'll fix that. Thanks for the report!

> The other minor annoyance is that there isn't a "Yes to all" option, which
> would be handy after switching git branches in a large project.

You could try something like (untested):

   local reload_all = false
   events.connect(events.FILE_CHANGED, function()
     if reload_all then
       io.reload_file()
       return true -- do not run the original handler
     end
     -- Prompt the user to reload modified file.
     local button = ui.dialogs.msgbox{
       ...
       button1 = Yes, button2 = 'Yes to all', button3 = 'No'
     }
     if button == 1 then
       -- Reload just this file.
       io.reload_file()
     elseif button = 2 then
       -- Cycle through all open files. If they are detected as modified,
       -- `events.FILE_CHANGED` will be emitted again, and this handler will
       -- be called to auto-reload the file.
       local orig_buffer = buffer
       reload_all = true
       for i = 1, #_BUFFERS do
         view:goto_butter(_BUFFERS[i])
       end
       reload_all = false
       view:goto_buffer(orig_buffer)
     end
     return true -- do not run the original handler
   end, 1)

Cheers,
Mitchell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Thu 13 Dec 2018 - 22:29:27 EST

This archive was generated by hypermail 2.2.0 : Fri 14 Dec 2018 - 06:50:01 EST