Last active
July 12, 2016 13:07
-
-
Save DinisCruz-Dev/9214909 to your computer and use it in GitHub Desktop.
Eclipse script to sync browser with editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def editorTitle = "Firebase_Login.html" | |
import java.nio.file.*; | |
import com.sun.nio.file.* | |
def refreshBrowser = { path -> | |
eclipse.log("Opening browser with: " + path); | |
eclipse.views.create(path).clear().add.browser().open(path); | |
}; | |
def startWatch = { file -> | |
def filePath = file.toString(); | |
def folder = file.getParent(); | |
def tmpPath = Paths.get(folder); | |
refreshBrowser(filePath); | |
def watchService =FileSystems.getDefault().newWatchService(); | |
tmpPath.register(watchService, (WatchEvent.Kind[] )[StandardWatchEventKinds.ENTRY_MODIFY], SensitivityWatchEventModifier.HIGH); | |
while(true) | |
{ | |
eclipse.log("About to start watching folder: " + folder); | |
def key = watchService.take(); | |
eclipse.log("After .take()"); | |
for (def event : key.pollEvents()) | |
{ | |
eclipse.log(" event: " + event.kind()); | |
} | |
refreshBrowser(filePath); | |
key.reset() | |
} | |
return key; | |
} | |
def editor = eclipse.editors.get(editorTitle).getEditor(true); | |
def file = editor.getEditorInput().getPath().toFile(); | |
startWatch(file); | |
//Config:UIThread_False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def editorTitle = "Firebase_Login.html" | |
import java.nio.file.*; | |
import com.sun.nio.file.* | |
def refreshBrowser = { path -> | |
eclipse.log("Opening browser with: " + path); | |
def view = eclipse.views.create("Synced WebBrowser"); | |
if (view.controls().size() == 0) | |
view.add.browser(); | |
view.controls().first().open(path); | |
}; | |
def startWatch = { file -> | |
def filePath = file.toString(); | |
def folder = file.getParent(); | |
def tmpPath = Paths.get(folder); | |
refreshBrowser(filePath); | |
def watchService =FileSystems.getDefault().newWatchService(); | |
tmpPath.register(watchService, (WatchEvent.Kind[] )[StandardWatchEventKinds.ENTRY_MODIFY], SensitivityWatchEventModifier.HIGH); | |
while(true) | |
{ | |
eclipse.log("About to start watching folder: " + folder); | |
def key = watchService.take(); | |
eclipse.log("After .take()"); | |
for (def event : key.pollEvents()) | |
{ | |
eclipse.log(" event: " + event.kind()); | |
} | |
refreshBrowser(filePath); | |
key.reset() | |
} | |
return key; | |
} | |
def editor = eclipse.editors.get(editorTitle).getEditor(true); | |
def file = editor.getEditorInput().getPath().toFile(); | |
startWatch(file); | |
//Config:UIThread_False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def editorTitle = "index.html" | |
import java.nio.file.*; | |
import com.sun.nio.file.* | |
import java.nio.file.attribute.*; | |
def refreshBrowser = { path -> | |
eclipse.log("Opening browser with: " + path); | |
def view = eclipse.views.create("Synced WebBrowser"); | |
if (view.controls().size() == 0) | |
view.add.browser(); | |
view.controls().first().open(path); | |
}; | |
def startWatch = { file -> | |
def filePath = file.toString(); | |
def folder = file.getParent(); | |
def path_Root = Paths.get(folder); | |
refreshBrowser(filePath); | |
def watchService =FileSystems.getDefault().newWatchService(); | |
path_Root.register(watchService, (WatchEvent.Kind[] )[StandardWatchEventKinds.ENTRY_MODIFY], SensitivityWatchEventModifier.HIGH); | |
Files.walkFileTree(path_Root, new SimpleFileVisitor<Path>() | |
{ | |
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException | |
{ | |
dir.register(watchService, (WatchEvent.Kind[] )[StandardWatchEventKinds.ENTRY_MODIFY], SensitivityWatchEventModifier.HIGH); | |
return FileVisitResult.CONTINUE; | |
} | |
}); | |
while(true) | |
{ | |
eclipse.log("About to start watching folder: " + folder); | |
def key = watchService.take(); | |
eclipse.log("After .take()"); | |
for (def event : key.pollEvents()) | |
{ | |
eclipse.log(" event: " + event.kind()); | |
} | |
refreshBrowser(filePath); | |
key.reset() | |
} | |
return key; | |
} | |
def editor = eclipse.editors.get(editorTitle).getEditor(true); | |
def file = editor.getEditorInput().getPath().toFile(); | |
startWatch(file); | |
//Config:UIThread_False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've added the following which has made it even snappier