'How can I configure Eclipse to that it saves all opened documents whenever the Eclipse window loses focus?
How can I configure Eclipse to that it saves all opened documents whenever the Eclipse window loses focus? I run Eclipse on Microsoft Windows 7 and 10.
(Motivation: I code on Eclipse, then click on some other window to test the code)
Solution 1:[1]
You can use the extension Smart Save (mirror) to automatically saves files when the Eclipse editor loses focus.
Solution 2:[2]
I wrote this AutoHotkey script as a workaround. It sends Ctrl+Shift+S to the Eclipse window when it loses focus.
#SingleInstance force
#NoTrayIcon
Process, Priority, , High
CoordMode, ToolTip, Screen
onFocusChanged(wParam, lParam) {
local newWindowId, newWindowClass, newProcess
winGet newWindowId, ID, A
if (newWindowId == prevWindowId) {
return
}
winGetClass newWindowClass, A
winGet newProcess, ProcessName, A
;outputDebug focus to: %newWindowId% / %newWindowClass% / %newProcess%
if (pendingTooltipText != "" && prevWindowClass == "MultitaskingViewFrame") { ; Alt+Tab "dialog" done
;outputDebug, Alt+Tab done, pending tooltip: %pendingTooltipText%
ToolTip, %pendingTooltipText%, 200, 50
pendingTooltipText := ""
SetTimer, tooltipOff, -1500
ControlSend, , ^+s, ahk_id %prevEclipseWindowId%
} else if (prevProcess == "eclipse.exe" && prevWindowClass == "SWT_Window0") {
;outputDebug Eclipse lost focus.
local tooltipText := A_ScriptName . ": Ctrl+Shift+S in Eclipse"
if (newWindowClass == "MultitaskingViewFrame") { ; Alt+Tab "dialog" gets focus
prevEclipseWindowId := prevWindowId
pendingTooltipText := tooltipText
;outputDebug, in Alt+Tab, delaying tooltip: %pendingTooltipText%
} else {
ToolTip, %tooltipText%, 200, 50
SetTimer, tooltipOff, -1500
ControlSend, , ^+s, ahk_id %prevWindowId%
}
}
prevWindowId := newWindowId
prevWindowClass := newWindowClass
prevProcess := newProcess
}
onShellHook(wParam, lParam) {
if (wParam == 4 || wParam == 32772) { ;HSHELL_WINDOWACTIVATED || HSHELL_RUDEAPPACTIVATED
onFocusChanged(wParam, lParam)
}
}
;;outputDebug %A_ScriptName% starting
; detect focus: https://autohotkey.com/board/topic/66726-method-to-detect-active-window-change/
Gui +LastFound
DllCall("RegisterShellHookWindow", UInt, WinExist())
winGet prevWindowId, ID, A
winGetClass prevWindowClass, A
winGet prevProcess, ProcessName, A
;outputDebug initial: %prevWindowId% / %prevWindowClass% / %prevProcess%
prevEclipseWindowId := ""
pendingTooltipText := ""
OnMessage(DllCall("RegisterWindowMessage", Str, "SHELLHOOK"), "onShellHook")
tooltipOff:
ToolTip
return
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Franck Dernoncourt |
| Solution 2 |
