Plugin - save participant project save [message #1063185] |
Wed, 12 June 2013 14:48 |
Kevin Regan Messages: 33 Registered: May 2013 |
Member |
|
|
Hi, I am playing with plugin development for the first time. I currently have a startup plugin (launches on startup of the workbench using the IStartup interface) - I know people caution to avoid these in general but the purpose is that I need to check the command line passed to eclipse and automatically/programmatically generate a project based on that command line information on startup (if there is a better way to do this I'm all ears).
The startup plugin registers a save participant:
ISaveParticipant saveParticipant = new MySaveParticipant();
try {
ISavedState lastState = ResourcesPlugin.getWorkspace().addSaveParticipant(Activator.PLUGIN_ID, saveParticipant);
} catch (CoreException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
But the participant "saving" method only seems to be getting called for the ISaveContext.SNAPSHOT save:
public void prepareToSave(ISaveContext context) throws CoreException {
try {
FileOutputStream os = new FileOutputStream(s_fname, true);
os.write("testing 6666".getBytes());
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void saving(ISaveContext context) throws CoreException {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
FileOutputStream os = new FileOutputStream(s_fname, true);
String message = "testing 1234" + dateFormat.format(new Date()) + "\n";
os.write(message.getBytes());
switch (context.getKind()) {
case ISaveContext.FULL_SAVE:
message = "Full Save" + dateFormat.format(new Date()) + "\n";
os.write(message.getBytes());
break;
case ISaveContext.PROJECT_SAVE:
message = "Project Save" + dateFormat.format(new Date()) + "\n";
os.write(message.getBytes());
break;
case ISaveContext.SNAPSHOT:
message ="Snapshot Save" + dateFormat.format(new Date()) + "\n";
os.write(message.getBytes());
break;
}
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Basically, the workbench opens and I programmatically create a project. I then go and modify a source file in the project and hit save and expect the "saving" method to be invoked in the save participant but that doesn't appear to be happening... the test text file I'm writing to only seems to indicate snapshot saves:
testing 6666testing 12342013/06/11 16:26:11
Snapshot Save2013/06/11 16:26:11
testing 6666testing 12342013/06/11 16:31:11
Snapshot Save2013/06/11 16:31:11
testing 6666testing 12342013/06/11 17:29:19
Snapshot Save2013/06/11 17:29:19
I'm sure I'm doing something wrong but am having a hard time finding any good resources online to help me figure it out. So 1) if anyone here can point out my mistake I would appreciate it and 2) if anyone can point me to some good resources for learning this stuff in detail I would also appreciate that.
Thanks a lot!
[Updated on: Mon, 08 July 2013 16:26] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03469 seconds