Determining if File is being closed

Mike Bray (Quote Loader Author)'s Avatar

Mike Bray (Quote Loader Author)

11 Jun, 2015 01:26 PM

How do I determine if a MD File is being closed whilst my extension is active? If you open a different file all of the object references in the extension become invalid.


  1. Support Staff 1 Posted by Sean Reilly on 11 Jun, 2015 02:22 PM

    Sean Reilly's Avatar

    Hi Mike,

    Great question!

    You can cast the FeatureModuleContext to and then call mainObj.addAppEventListener(new {
      public void handleEvent(String eventID) {
        if("md:file:closing".equals(eventID)) {
          // call some cleanup code here


  2. 2 Posted by Kevin Stembridg... on 11 Jun, 2015 09:50 PM

    Kevin Stembridge's Avatar

    Hi chaps,

    You can also override the handleEvent method in your Main class (I assume it extends FeatureModule) if that's an appropriate place for you to be notified.

    public void handleEvent(String appEvent) {
        if ("md:file:opened".equals(appEvent)) {
        if ("md:file:closing".equals(appEvent)) {


  3. Support Staff 3 Posted by Sean Reilly on 11 Jun, 2015 10:39 PM

    Sean Reilly's Avatar

    Ah yes, that is far better. Thanks Kevin!

  4. 4 Posted by Mike Bray (Quot... on 12 Jun, 2015 07:18 AM

    Mike Bray (Quote Loader Author)'s Avatar

    Thanks Kevin and Sean

    Kevin's answer made me look at FeatureModule in more detail and I saw the cleanUp() method. Would that do what I want, i.e. to know when to close my extension down?

  5. 5 Posted by Mike Bray (Quot... on 12 Jun, 2015 07:42 AM

    Mike Bray (Quote Loader Author)'s Avatar

    Interesting, I have just done a test and put a breakpoint on the cleanup method. It was not called when I changed files.

    Next test is Kevin's solution

  6. 6 Posted by Mike Bray (Quot... on 12 Jun, 2015 07:49 AM

    Mike Bray (Quote Loader Author)'s Avatar

    That worked and all windows were closed. I will add this to my Wiki concerning extension writing.

    Thanks for the help

  7. Mike Bray (Quote Loader Author) closed this discussion on 13 Jun, 2015 04:57 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

29 May, 2024 07:01 AM
29 May, 2024 06:26 AM
29 May, 2024 02:38 AM
29 May, 2024 12:43 AM
28 May, 2024 11:59 PM