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.

Regards
Mike

  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 com.moneydance.apps.md.controller.Main and then call mainObj.addAppEventListener(new com.moneydance.apps.md.controller.AppEventListener() {
      public void handleEvent(String eventID) {
        if("md:file:closing".equals(eventID)) {
          // call some cleanup code here
        }
      }
    });

    Thanks,
    Sean

  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.

    @Override
    public void handleEvent(String appEvent) {
    
        if ("md:file:opened".equals(appEvent)) {
            onAccountSetOpened();
        }
    
        if ("md:file:closing".equals(appEvent)) {
            onAccountSetClosing();
        }
    
    }
    

    Cheers,
    Kevin

  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?
    Mike

  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
    Regards
    Mike

  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

Generic

? 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