ファイルを右クリックすると表示される[ソース]メニューの下に作成したポップアップメニュー拡張機能を使用して、ファイルの内容を正常に更新することができました。
ファイルが変更されており、保存する必要があることを示したいと思います。現在、ファイルの内容は自動的に変更されて保存されます。IFile.touchメソッドを使用すると、ファイルを保存する必要がある状態になると思いましたが、それが発生することはありません。
これが私のコードです...
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
IEditorInput input = editorPart.getEditorInput();
InputStream is = null;
if (input instanceof FileEditorInput) {
IFile file = ((FileEditorInput) input).getFile();
try {
is = file.getContents();
String originalContents = convertStreamToString(is);
String newContents = originalContents + "testing changing the contents...";
InputStream newInput = new ByteArrayInputStream(newContents.getBytes());
file.setContents(newInput, false, true, null);
file.touch(null);
} catch (CoreException e) {
MessageDialog.openError(
window.getShell(),
"Generate Builder Error",
"An Exception has been thrown when interacting with file " + file.getName() +
": " + e.getMessage());
}
}
return null;
}