Prevent closing the Application if file not saved - eclipse

We have an application based on Eclipse-RCP. The problem I am trying to fix is as follows:
Say the user has an unsaved model file, and tries to close the application. The application rightly prompts the user for options to Save the file, Ignore it, or Cancel closing the application. Ignore and cancel are no-brainers. If the user decides to save the file, there is another dialog box that gives the user an option to either save the file or cancel the save (its a custom editor, similar to a Save-As dialog).
Now, the question:
How do I prevent killing the application when the user selects "Yes" in the first prompt, but cancels the save in the second? I thought of looking up the base class of the application, but couldn't find it. Or should I be looking at the custom-editor for the model file?
Thanks in advance, any help is appreciated...

If you are in RCP you have the luxury of returning false from WorkbenchAdvisor.preShutdown()

Let a workbench part holding the model implement org.eclipse.ui.ISaveablePart2 interface meant for cases like yours.

Related

Cocoa invoke Service, do not overwrite Pasteboard

I have created a Service in Cocoa which grabs the selected Text and sends the result back to my Main App, so i can handle it there ( Couldn't find any other way to get current selection), now that the Service works and appears in the Service Menu, i tried to invoke the Service from my parent App to get current selection, after some goggling around i found this snippet:
NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
NSPerformService(#"PCB", pboard);
This one works as far as it triggers my Service, the Problem here is it redefines the NSPasteboard, so my service doesn't get the selected text, but a NIL Value Pasteboard which is blank, how can i prevent this?
And does someone know how to convert a .service bundle into an .app bundle that performs itself and sends the data and kills itself after finish?
thx for help
You want to get the text that is selected in another application, right? Probably in the front application, while your app is in the background.
For this to work, you'd have to have the Service be invoked by the front application. If you invoke it from your app in the background, it can't access the front app's text field that contains the selected text. Instead, it'll try to find a text field in your own app's responder chain (I believe – someone correct me if I'm wrong on this detail).
But for your code to run in the app's process, you'll have to inject it somehow, which is - out of security concerns - mostly prohibited by OS X, and especially with sandboxed apps.
There are ways to accomplish code injection, one that 1Password and other popular tools use it through an osax extension. But that's an entirely different topic.
Once you have your code running inside the other app's process, you should be able to copy the selected text (provided it's a Cocoa app) with [NSTextView writeSelectionToPasteboard:types:]. I haven't tested this myself, though, so this is just an assumption.

Eclipse RCP : how to get currently selected node in preference dialog

I have added a new preference page in my application. and performing some task when user press ok button. problem is my code is executing even other node(preference page) is selected in the preference dialog.now i need to check whether currently selected node is my preference page before executing my code inside ok button. any help will be appreciated.
Sorry to say, but I think your problem have started a bit earlier. If done without too many hooks and nooks, you should only be called when necessary, so it sounds a bit odd to me.
I can usually just override performOk or in some cases performApply without these problems.
Have a look at the docs, just in case

How to read message from console tab view in eclipse plugin development

requirement is to read message from IConsoleConstants.ID_CONSOLE_VIEW and write it into text file.
Say myConsole (of type MessageConsole) is the reference to your console. The below code will give you the required.
myConsole.getDocument().get();
I don't think you will be able to retreive a direct stream to read the console content. Note also that the console view may have multiple different consoles, you will have to retrieve the good one.
Retrieving the content displayed in a single console should be possible going through the IDocument of a TextConsole. You can get the whole text content. You could also have a look to the IDocumentListener if you can be notified of changes.
Another solution should be to go with a PatternMatchListener of the TextConsole directly.
Anyway I don't think there is a direct solution to do this with the Eclipse console API.

How to show previous url after user has canceled dialog with message from Activity#mayStop()?

In our app we need to check if the data is saved when we are in a particular place before navigating away from it. So the user should be able to negate a browser back button request. But by the time that the history value change event is received the url has already been changed. The History class doesn't seem to have a way to restore the url back. Anybody have any ideas?
In GWT 2.1 you get Activities and Places. And activity has a maystop method, which is exactly what you want, if I understand you correctly.
Use a window.onunload or window.onbeforeunload javascript callback to confrim/save state.
onbeforeunload example
I haven't actually implemented this behavior yet, but here is my plan and maybe it will work for you.
1) Each time you receive an onHistoryChanged event and decide to allow it, save the current historyToken in an instance variable somewhere.
2) Keep track of activity on the page that should block navigation. Use a data structure that can keep track of multiple activities, like multiple file uploads, multiple edits, etc.
3) When you receive a new onHistoryChanged event, if your data structure from #2 indicates that it's not safe to navigate, avoid changing the page and restore the historyToken that you saved in #1. I'm assuming that you can do this either by:
a) Calling History.newItem(oldHistoryToken, false) or
b) Calling History.newItem(oldHistoryToken, true) and keeping a flag to force the next onHistoryChanged to be ignored.
Again, I haven't actually implemented this so let me know how it works out.
If you have links that allow the user to leave the app and you want to prevent that as well, you'll need to also add an onbeforeunload.
Have a look at the PlaceManagerImpl class from the gwt-platform framework. Especially the onValueChange() method and the methods dealing with the onLeaveQuestion field.
Hope that helps.
In this issue report, t.broyer explains in his comment that such behavior was planned during design of Places framework. The most important part is:
mayStop was a mistake, or it should have only been called when unloading the app, not for internal navigation within the app.
So probably it's better to not use it at all...

How can I get rid of a persistent VBA Form Object that won't honor the form deletion?

I have an MS Access 2003 database that I'm using to develop a basic little inventory app. I have added some extraneous forms along the way and I wanted to get them out of the DB. I deleted most of them just fine but one of them appears to have left behind its VBA Object. All that's in the object is Option Compare Database. Now whenever I try to work with the database, I get the following error:
The form name 'Transaction1' is misspelled or refers to a form that doesn't exist.
If the invalid form name is a macro, ...
Truncated for typings sake.
Yes, I agree, the form doesn't exist. What confuses me so much is that all of the other forms, when I deleted them, also destroyed their VBA object as well. This one, no matter what, seems to like to stick around and I have no idea how to get rid of it.
How do I get rid of it?
Things I've tried:
Compact and Repair and the DB
Create a new form named what it's expecting, verify that it gets rid of the problem, and then delete that form.
You can try the /decompile switch
Make a backup of your mdb
Open your mdb (hold the SHIFT key down to stop any code from running) via a short
cut: msaccess.exe database.mdb /decompile
Open a module and compile your app
Save and close Access
Open again (SHIFT again) without decompile
Compact and repair database
close Access
I had similar problem. I found I had named the missing form in the STARTUP menu as the default form to open when starting Access. I opened Tools>Startup and deleted the missing forms name from the "Display/Form/Page" field of the Startup. My problem solved.
The problem I was having is that the form was named ~TMPCLP8151 and would not show up in Access no matter what I tried, but I could see it in VBA in the Project Explorer. Here's how I resolved the issue. I created a new form, and created an Event Procedure for Form_Open that contained this:
DoCmd.DeleteObject acForm, "~TMPCLP8151"
Then I just opened the form, and sure enough, the VB code deleted the form that I could not delete myself.
I had a same problem. I created a form with same name and deleted the form again. That fixed the peoblem. Try. BTW try to open the new form in design mode to make sure if the VBA module is assosiated with the new form.
I had to combine both solutions to achieve the goal.
First de- and recompile
next compact and repair
then create new form with the same name and delete it
Pay attention that the form has the status Hasmodule set to Yes
I had this problem. I renamed my default form from Form Login to frmLogin which suits my naming style, but the program was still looking for it on opening. I am using 2013 so I went to File » Options » CurrentDB and in the display dropdown select the new name. The old name remains in the list until you close and restart the application.