Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Eclipse script to sync browser with editor
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
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
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
@gsaqui

This comment has been minimized.

Copy link

commented Apr 29, 2014

I've added the following which has made it even snappier

SensitivityWatchEventModifier.metaClass.sensitivityValueInSeconds = {-> return 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.