Solved Best way to update objects after preference change?

Hello,

in my plugin, I have a PrefsDialogObject. After the user changed something in those preferences, I need to notify all my plugin objects in all open documents. What's the best way of doing this?

Cheers,
Frank

www.frankwilleke.de
Only asking personal code questions here.

I'd go for SpecialEventAdd.

That would work... if NodeDatas would receive CoreMessages ;-)

www.frankwilleke.de
Only asking personal code questions here.

Ah yea, my bad. You were talking about objects, not GUI.
Maybe implement a Scenehook that notifies all objects in question.

Yeah, I thought about a SceneHook, too. But if that scene hook would only iterate over the objects in the document and send a message to each object of the desired type, I can simply do that from within the PrefsDialogObject.

I was hoping for some message-based approach that would spare me more code :D

www.frankwilleke.de
Only asking personal code questions here.

Maybe the SDK Team has an idea(@r_gigante )? If I could just have all object in the scene receive a message like MSG_MYPREFSHAVECHANGED, that would be nice.

www.frankwilleke.de
Only asking personal code questions here.

Oh wait, I think I found a way. In case anybody else wants to know, here it is...

In the PrefsDialogObject:

Bool MyPrefsDialog::SetDParameter(GeListNode *node, const DescID &id,const GeData &t_data,DESCFLAGS_SET &flags)
{
	BaseContainer* bc = MyPlugin::GetPreferences();
	if (!bc)
		SUPER::SetDParameter(node, id, t_data, flags);
	
	switch (id[0].id)
	{
		// If PREFS_MYPLUGIN_SOMEVALUE was changed, store value and notify plugin objects in all open documents.
		case PREFS_MYPLUGIN_SOMEVALUE:
			bc->SetInt32(PREFS_MYPLUGIN_SOMEVALUE, t_data.GetInt32());
			flags |= DESCFLAGS_SET::PARAM_SET;
			
			// Iterate open documents
			for (BaseDocument *doc = GetFirstDocument(); doc; doc = doc->GetNext())
			{
				// Send broadcast message to each document, use unique ID
				doc->MultiMessage(MULTIMSG_ROUTE::BROADCAST, MyPlugin::UNIQUE_ID_PREFS, nullptr);
			}
			
			GeUpdateUI();
			return true;
	}
	
	return SUPER::SetDParameter(node, id, t_data, flags);
}

And then, in the plugin object:

Bool MyPluginObject::Message(GeListNode *node, Int32 type, void *data)
{
	if (type == MyPlugin::UNIQUE_ID_PREFS)
	{
		GePrint("Aha! My prefs have changed!"_s);
		return true;
	}
	return SUPER::Message(node, type, data);
}

www.frankwilleke.de
Only asking personal code questions here.