icetee / remote-ftp

FTP/FTPS/SFTP client for Atom.io
MIT License
555 stars 102 forks source link

Auto-save active file before upload? #1129

Open cronoklee opened 6 years ago

cronoklee commented 6 years ago

Is it possible to add a setting to auto-save the file before upload? I like to have full control of when I upload so I dont use the "upload on save" setting.

However, when I do tap CTRL-SHIFT-U, I'd like the file I'm working on to save and then upload. Currently it uploads the old version of the script I'm working on which is probably never what anyone wants to happen.

cronoklee commented 6 years ago

I added some custom code to make this work. In general I think remote-ftp needs to better consider developer workflows and implement simple features like these to support them. Anyway here's what I did for anyone interested:

In my init.coffee (File>Init script) I added:

#saveAndUpload: (Saves the active file and uploads it)
atom.commands.add 'atom-text-editor', 'editor:saveAndUpload', (event) ->
    atom.commands.dispatch(document.querySelector('atom-text-editor'), 'core:save')
    atom.commands.dispatch(document.querySelector('atom-text-editor'), 'remote-ftp:upload-active')

#downloadAndRevert: (Downloads the active file and reloads it in the editor)
atom.commands.add 'atom-text-editor', 'editor:downloadAndRevert', (event) ->
    atom.commands.dispatch(document.querySelector('atom-text-editor'), 'remote-ftp:download-active')
    event.target.closest('atom-text-editor').getModel().getBuffer().reload() #reload active file
    atom.notifications.addInfo('Reloading '+atom.workspace.getActiveTextEditor()?.getTitle()+' <b>from the server</b>') #show notification

Then in keymap.cson (File>keymap) I overwrote the remote-ftp shortcuts with my own:

'atom-text-editor':
  'shift-ctrl-u': 'editor:saveAndUpload'
  'ctrl-alt-d': 'editor:downloadAndRevert'