Start a new topic

Viewer plugin not working..

Original Post by: Thu Dec 4 17:19:49 2014


Hi,


I made a plugin which is a viewer and is working fine if its opened after opening a database. But if i have opened the plugin which is a dialogue box with few buttons prior to opening a database and it wont work.


I have to close and reopen the tool again to work on current database.

Any where i have to add mgGetCurrentDb ??

1 Comment

Original Post by: SteveThompson Thu Dec 4 17:49:06 2014


I made a plugin which is a viewer and is working fine if its opened after opening a database. But if i have opened the plugin which is a dialogue box with few buttons prior to opening a database and it wont work.

In your viewer start function, you are passed a pointer to a mgviewercallbackrec* record (in the callData parameter). This record (once you cast it to mgviewercallbackrec*) contains a mgtoolactivation record. This mgtoolactivation record contains information about "how, when, why" the tool was started. If a database is open when the user invokes your tool the db contained in the mgtoolactivation will be that open and top db. That is the db your tool normally "works" on. If no db is open when the user invokes the tool, the db in the mgtoolactivation will be MG_NULL.


This likely explains why your tool does not work when started with no db open. You grab the db from the mgtoolactivation when it is NULL, then the user opens a db, the db you grabbed is still the NULL db.


I have to close and reopen the tool again to work on current database.

Any where i have to add mgGetCurrentDb ??


Your tool can be notified when the user changes the top / current db in Creator. To do this, use mgRegisterNotifier. There are several "events" to which you can subscribe. In this case, subscribe to MNOTIFY_NEWTOPDATABASE. When you do this you register a callback function that will be called when the user switches "top" databases. At that time, if you choose to, you can switch which db you want your tool to work on.


You should also decide which "tool" model you want to support. In other words, is this viewer tool going to be a "singleton" tool that you simply reopen each time it is invoked or are you going to start a "fresh" invocation of the tool each time it is started. For editor tools you have no choice, you must obey the latter model. Each invocation of an Editor tool must be a new instance/dialog. It cannot be a singleton dialog. For viewers you have a choice. If you choose the latter, your tool should grab the db for which that invocation was launched and never switch dbs even when the user switches top dbs in Creator. For the former model (singleton) you will want to "watch" the top db and switch accordingly. Note that if you do that, you might want to think about other implications, like what do you do if the user "closes" the db while your viewer is up? If you subscribe to MNOTIFY_NEWTOPDATABASE, you get this for free because if the user closes a db, one of two things will happen. If there are other dbs open, the new top db will be one of those other dbs. If there are no other dbs open, the new top db will be MG_NULL. A carefully written viewer plugin will notice that no db is open and block itself from doing anything in order to avoid referencing a db that has gone away.


Welcome to the world of Creator Plugins. So much to consider!


Hope this helps.

Login to post a comment