Friday, 15 March 2013

eclipse - How to indicate a file has changed after modifying it using IFile -



eclipse - How to indicate a file has changed after modifying it using IFile -

i've been able update contents of file via popup menu extension i've created underneath source menu comes when right-clicking on file.

i'd indicate file has been changed , needs saved. right now, file contents alter , save automatically. thought ifile.touch method cause file in state needed saved i'm not seeing happen.

here's code...

public object execute(executionevent event) throws executionexception { iworkbenchwindow window = handlerutil.getactiveworkbenchwindowchecked(event); ieditorpart editorpart = handlerutil.getactiveeditor(event); ieditorinput input = editorpart.geteditorinput(); inputstream = null; if (input instanceof fileeditorinput) { ifile file = ((fileeditorinput) input).getfile(); seek { = file.getcontents(); string originalcontents = convertstreamtostring(is); string newcontents = originalcontents + "testing changing contents..."; inputstream newinput = new bytearrayinputstream(newcontents.getbytes()); file.setcontents(newinput, false, true, null); file.touch(null); } grab (coreexception e) { messagedialog.openerror( window.getshell(), "generate builder error", "an exception has been thrown when interacting file " + file.getname() + ": " + e.getmessage()); } } homecoming null; }

if want file's contents marked needing saved, need interacting in-memory representation want prompt needing saved--the editor you're getting input.

eclipse eclipse-plugin

No comments:

Post a Comment