简体   繁体   中英

Avoid Close Editor when no unsaved changes Eclipse RCP

Is there anyway to stop the editor from closing even though there are no unsaved changes?

Whenever there are some unsaved changes, then using the ISaveablePart interface can trap the event before editor close - but I'm looking for a way to trap the event before the editor closes, even if there are no unsaved changes.

A possible way to do this is to maintain two 'dirty' flags in your ISaveablePart implementation - one so that the Eclipse saving framework will think your editor is dirty and call your hooks preventing the editor to close.

To avoid Eclipse incorrectly displaying messages about your editor having unsaved changes, you'll probably want to actually implement ISaveablePart2 ( docs here ) and implement promptToSaveOnClose() - this can check whether the editor is really dirty, and only prompt to save (or whatever else you want) in that case.

You may want to re-examine the underlying reason you want to keep the editor open though - the framework doesn't normally work like this (so issues might creep in), and it seems like it would be a confusing experience to users who really really want to close the editor (and decide your application is buggy).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM