DataManager.DataSourceManager.Saved event doesn't seem to fire on save for Petrel 2012.1

StackOverflow https://stackoverflow.com/questions/16916437

  •  31-05-2022
  •  | 
  •  

Question

I have a plugin originally written for Petrel 2011. Recently, we have needed to use this with Petrel 2012. I have connected the debugger to Petrel and confirmed that the plugin is being loaded and that Initialize() on the module is being called. This simply adds an event handler to the DataManager.DataSourceManager.Saved event.

With Petrel 2011, this event is fired near the end of the save process. However, with 2012, this event no longer seems to be fired.

Is there a new event I should use for 2012 to detect when a project is being saved? Preferably one compatible with 2011.

Was it helpful?

Solution

OK, I found the answer to this in the 2012 release notes, appendix A:

"Every time a new workspace is created (when creating a new project or loading one), it needs its own DataSourceManager. So caching the DataSourceManager is obviously not working anymore and sub-scribing to the DataSourceManager.Saved events should be done every time the project is opened. The best place for this is in a DataManager.WorkspaceEvent.Opened event handler."

The solution that works for me is along the lines of:

public void Initialize()
{
    DataManager.WorkspaceOpened += ProjectOpened;
}

private void ProjectOpened(object sender, EventArgs e)
{
    DataManager.DataSourceManager.Saved += DataSourceManagerSaved;
}

private void DataSourceManagerSaved(object sender, EventArgs e)
{
    whatever needs doing on save...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top