Bug 37148 - [EditorMgmt] Provide save(CollectionMake internal org.eclipse.ui Save Dialog APIs public
Summary: [EditorMgmt] Provide save(CollectionMake internal org.eclipse.ui Save Dialog ...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-01 16:22 EDT by Tom Mutdosch CLA
Modified: 2019-09-06 15:30 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Mutdosch CLA 2003-05-01 16:22:51 EDT
I am making use of some eclipse code that shows a save dialog for all dirty
editors.  The code that I am using makes use of several internal classes - could
these be made public?  Or could some API be exposed to allow me to utilize a
Save Dirty Editors dialog?

org.eclipse.ui.internal.WorkbenchMessages
org.eclipse.ui.internal.WorkbenchPartLabelProvider
org.eclipse.ui.internal.WorkbenchPlugin
org.eclipse.ui.internal.dialogs.EventLoopProgressMonitor
org.eclipse.ui.internal.model.AdapterAdaptableList
Comment 1 Debbie Wilson CLA 2003-05-05 15:25:42 EDT
Not sure if this is the right category.  Let me know Nick.

Comment 2 Nick Edgar CLA 2003-05-05 16:16:07 EDT
Tom, rather than simply making these internal classes public, we should 
consider a better, more flexible API that meets your needs.
Could you please describe why the current API does not meet your needs, and 
what end-user use cases you're trying to support?

Thanks,
Nick
Comment 3 Tom Mutdosch CLA 2003-05-22 14:40:09 EDT
Sorry for the delay in response.  I've looked at it some more, and I don't
really need access to WorkbenchPlugin.  That was only being used for logging
purposes.

Basically, what I want to do is to be able to save a list of editors, using the
normal checkbox-list dialog that eclipse shows for when dirty editors need
saving before some type of refactoring operation.  Then I want to save all of
the editors that are selected.  

I just borrowed some code from eclipse that did what I wanted to do, and it
seems generally useful enough that I didn't think I should just rewrite it.  


I don't really need access to the WorkbenchMessages either, though I would just
be using duplicate messages.  But the AdapterAdaptableList,
EventLoopProgressMonitor, and the WorkbenchPartLabelProvider I would like to
have access to, so I don't have to duplicate the effort.  

I've added the code that I'm using that makes use of these internal classes below.

You mentioned instead having a more general API?  That would work too.  I would
like something where I could create a Save All type of dialog and just pass it a
list of IEditorParts, and then get those back that were selected to be saved.
And I would like a way to have all of those editors save themselves. 



	public boolean saveAll(List dirtyEditors,boolean confirm,final IWorkbenchWindow
window) {
		String SAVE_RESOURCES_TITLE =
ResourceHandler.getString("Save_resources_for_links_refactoring_2"); //$NON-NLS-1$
		String RESOURCES_TO_SAVE_MESSAGE =
ResourceHandler.getString("Select_resources_to_be_saved_to_correctly_refactor_links_3");
//  These resources should be saved in order to have \n their links refactored
properly.  Select resources to save"; //$NON-NLS-1$
		if (confirm) { 
			// Convert the list into an element collection.
			AdaptableList input = new AdaptableList();
			input.add(dirtyEditors.iterator());
		
			final ListSelectionDialog dlg =
				new ListSelectionDialog(window.getShell(), input, new
WorkbenchContentProvider(), new WorkbenchPartLabelProvider(),
RESOURCES_TO_SAVE_MESSAGE);
		
			dlg.setInitialSelections(dirtyEditors.toArray(new Object[dirtyEditors.size()]));
			dlg.setTitle(SAVE_RESOURCES_TITLE);
	
			int result = dlg.open();
			
			//Just return false to prevent the operation continuing
			if (result == IDialogConstants.CANCEL_ID)
				return false;
		
			dirtyEditors = Arrays.asList(dlg.getResult());
			if (dirtyEditors == null)
				return false;
		
			// If the editor list is empty return.
			if (dirtyEditors.size() == 0)
				return true;
		}
		
		// Create save block.
		final List finalEditors = dirtyEditors;
		final IWorkspaceRunnable workspaceOp = new IWorkspaceRunnable() {
			public void run(IProgressMonitor monitor) {
				monitor.beginTask("", finalEditors.size()); //$NON-NLS-1$
				Iterator enum = finalEditors.iterator();
				while (enum.hasNext()) {
					IEditorPart part = (IEditorPart) enum.next();
					// save the file
					part.doSave(new SubProgressMonitor(monitor, 1));					
					
					IEditorInput edInput = part.getEditorInput();
					if (edInput instanceof IFileEditorInput) {
						IFileEditorInput input= (IFileEditorInput) edInput;									
						IFile file= input.getFile();
						// DO CUSTOM CODE HERE
					}

					if (monitor.isCanceled())
						break;
				}
			}
		};
		IRunnableWithProgress progressOp = new IRunnableWithProgress() {
			public void run(IProgressMonitor monitor) {
				try {
					IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor);
					ResourcesPlugin.getWorkspace().run(workspaceOp, monitorWrap);
				} catch (CoreException e) {
					IStatus status = new Status(Status.WARNING, PlatformUI.PLUGIN_ID, 0,
WorkbenchMessages.getString("EditorManager.saveFailed"), e); //$NON-NLS-1$
				
WorkbenchPlugin.log(WorkbenchMessages.getString("EditorManager.saveFailed"),
status); //$NON-NLS-1$
					MessageDialog.openError(window.getShell(),
WorkbenchMessages.getString("Error"), //$NON-NLS-1$
					WorkbenchMessages.format("EditorManager.saveFailedMessage", new Object[] {
e.getMessage()})); //$NON-NLS-1$
				}
			}
		};
		
		// Do the save.
		return runProgressMonitorOperation(WorkbenchMessages.getString("Save_All"),
progressOp,window); //$NON-NLS-1$
	}
	
	/**
	 * Runs a progress monitor operation.
	 * Returns true if success, false if cancelled.
	 */
	private static boolean runProgressMonitorOperation(String opName,
IRunnableWithProgress progressOp,IWorkbenchWindow window) {
		ProgressMonitorDialog dlg = new ProgressMonitorDialog(window.getShell());
		try {
			dlg.run(false, true, progressOp);
		} catch (InvocationTargetException e) {
			String title = WorkbenchMessages.format("EditorManager.operationFailed", new
Object[] { opName }); //$NON-NLS-1$
			Throwable targetExc = e.getTargetException();
			WorkbenchPlugin.log(title, new Status(Status.WARNING, PlatformUI.PLUGIN_ID,
0, title, targetExc));
			MessageDialog.openError(window.getShell(),
WorkbenchMessages.getString("Error"), //$NON-NLS-1$
			title + ':' + targetExc.getMessage());
		} catch (InterruptedException e) {
			// Ignore.  The user pressed cancel.
		}
		return !dlg.getProgressMonitor().isCanceled();
	}	
	  
Comment 4 Simon Arsenault CLA 2003-06-17 16:49:18 EDT
Why can't you make use of the IWorkbench.saveAllEditors(boolean) or 
IWorkbenchPage.saveAllEditors(boolean). If you specify true to these api, we 
will prompt the user with a list of dirty editors within the workbench or 
within the page depending which api you called, and save the ones the user 
selects.

If these two APIs are still not quite what you want, please reopen.
Comment 5 Masabumi Koinuma CLA 2004-02-16 03:49:29 EST
I have similar requirement for the save dialog. As shown in Simon's remark, 
IWorkbench.saveAllEditors(boolean) is also the closest candidate API in my 
case, but I use internal classes because:
- I cannot customize title and messages of the save dialog with the API,
- I'd like to list not all dirty editors but a certain list of dirty editors, 
but I cannot specify such editor list with the API.

Could you add or expose some API so that I can utilize the Save Dirty Editors 
dialog with the above customizations?
Comment 6 Tom Mutdosch CLA 2004-02-16 08:59:47 EST
Reopening based on new comments...
Comment 7 Nick Edgar CLA 2004-02-16 09:53:01 EST
Simon has moved on to another team.
We are looking at similar API to handle the new Close Other menu item on the 
editor tabs.

Could you provide details on requirements other than simply specifying the list 
of editors?  E.g. why do you want to change the title and message, and what 
would you change them to.  Perhaps you can describe your scenario in a little 
more detail.
Comment 8 Masabumi Koinuma CLA 2004-02-16 20:33:59 EST
I have an extension of org.eclipse.core.resources.builders extension-point, and 
my builder modifies html or jsp files in a project. Before running actual 
modify operation in my builder, dirty editors for only *related* resources need 
to be saved to storage. Then, Save Dirty Editors dialog is shown during my 
builder and the dialog's title and massage shows that my builder prompts 
customers to save dirty html/jsp files.
That's why I need the customizations in my previous comment.
Comment 9 Nick Edgar CLA 2004-02-17 09:46:47 EST
Having a builder prompt to save resources is pretty unusual.  Normally builders 
run without any UI intervention.  Wouldn't this cause many unwanted prompts, 
especially if you have autobuild turned on?  Doesn't the existing 
preference "Save all modified resources prior to manual build" suffice?

Comment 10 Masabumi Koinuma CLA 2004-02-18 06:34:21 EST
I agree this is unusual, but this is not so frequent prompt than you expected, 
I guess. And "Save all modified resources prior to manual build" is not 
sufficient for my builder because it is applicable only to manual build and is 
unchecked by default.

I think this is not so minor requirement because Java refactoring function has 
similar save prompt (though they uses their implemented classes instead of 
using eclipse's internal classes). It prompts users to save dirty java file 
before refactoring a java file.

Or, should I create copies of internal classes in my plugin? In my case, I uses 
the following internal classes:
org.eclipse.ui.internal.WorkbenchPartLabelProvider
org.eclipse.ui.internal.dialogs.EventLoopProgressMonitor
org.eclipse.ui.internal.model.AdaptableList
Comment 11 Douglas Pollock CLA 2004-07-15 11:17:57 EDT
Is "IDE.saveAllEditors(IResource[] resourceRoots, boolean confirm)" sufficient?    
Would you still like to be able to control the title of the save dialog? 
 
Moving to P5 while waiting for response.... 
Comment 12 Douglas Pollock CLA 2004-09-28 12:00:21 EDT
Ping.... 
Comment 13 Michael Van Meekeren CLA 2006-04-21 13:19:26 EDT
Moving Dougs bugs
Comment 14 Susan McCourt CLA 2009-07-09 19:02:51 EDT
As per http://wiki.eclipse.org/Platform_UI/Bug_Triage_Change_2009
Comment 15 Boris Bokowski CLA 2009-11-17 13:03:53 EST
Remy is now responsible for watching the [EditorMgmt] component area.
Comment 16 Eclipse Webmaster CLA 2019-09-06 15:30:52 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.