Link Here
|
24 |
import org.eclipse.dltk.ui.IDLTKUILanguageToolkit; |
24 |
import org.eclipse.dltk.ui.IDLTKUILanguageToolkit; |
25 |
import org.eclipse.jface.action.ContributionItem; |
25 |
import org.eclipse.jface.action.ContributionItem; |
26 |
import org.eclipse.jface.resource.ImageDescriptor; |
26 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
|
27 |
import org.eclipse.jface.window.Window; |
28 |
import org.eclipse.osgi.util.NLS; |
27 |
import org.eclipse.swt.SWT; |
29 |
import org.eclipse.swt.SWT; |
28 |
import org.eclipse.swt.graphics.Image; |
30 |
import org.eclipse.swt.graphics.Image; |
29 |
import org.eclipse.swt.widgets.Event; |
31 |
import org.eclipse.swt.widgets.Event; |
Link Here
|
35 |
import org.eclipse.ui.IWorkbenchPage; |
37 |
import org.eclipse.ui.IWorkbenchPage; |
36 |
import org.eclipse.ui.PartInitException; |
38 |
import org.eclipse.ui.PartInitException; |
37 |
import org.eclipse.ui.PlatformUI; |
39 |
import org.eclipse.ui.PlatformUI; |
|
|
40 |
import org.eclipse.ui.dialogs.EditorSelectionDialog; |
38 |
import org.eclipse.ui.ide.IDE; |
41 |
import org.eclipse.ui.ide.IDE; |
|
|
42 |
import org.eclipse.ui.internal.WorkbenchPage; |
43 |
import org.eclipse.ui.internal.ide.DialogUtil; |
44 |
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; |
39 |
import org.eclipse.ui.part.FileEditorInput; |
45 |
import org.eclipse.ui.part.FileEditorInput; |
40 |
|
46 |
|
41 |
import com.ibm.icu.text.Collator; |
47 |
import com.ibm.icu.text.Collator; |
Link Here
|
194 |
switch (event.type) { |
200 |
switch (event.type) { |
195 |
case SWT.Selection: |
201 |
case SWT.Selection: |
196 |
if (menuItem.getSelection()) { |
202 |
if (menuItem.getSelection()) { |
197 |
openEditor(descriptor); |
203 |
openEditor(descriptor,false); |
198 |
} |
204 |
} |
199 |
break; |
205 |
break; |
200 |
} |
206 |
} |
Link Here
|
292 |
// createMenuItem(menu, descriptor, preferredEditor); |
298 |
// createMenuItem(menu, descriptor, preferredEditor); |
293 |
// } |
299 |
// } |
294 |
createDefaultMenuItem(menu, file); |
300 |
createDefaultMenuItem(menu, file); |
295 |
} |
301 |
|
|
|
302 |
// add Other... menu item |
303 |
createOtherMenuItem(menu); |
304 |
} |
305 |
|
306 |
|
307 |
/** |
308 |
* Creates the Other... menu item |
309 |
* |
310 |
* @param menu the menu to add the item to |
311 |
*/ |
312 |
private void createOtherMenuItem(final Menu menu) { |
313 |
final IFile fileResource = getFileResource(); |
314 |
if (fileResource == null) { |
315 |
return; |
316 |
} |
317 |
new MenuItem(menu, SWT.SEPARATOR); |
318 |
final MenuItem menuItem = new MenuItem(menu, SWT.PUSH); |
319 |
menuItem.setText(IDEWorkbenchMessages.OpenWithMenu_Other); |
320 |
Listener listener = new Listener() { |
321 |
public void handleEvent(Event event) { |
322 |
switch (event.type) { |
323 |
case SWT.Selection: |
324 |
EditorSelectionDialog dialog = new EditorSelectionDialog( |
325 |
menu.getShell()); |
326 |
dialog |
327 |
.setMessage(NLS |
328 |
.bind( |
329 |
IDEWorkbenchMessages.OpenWithMenu_OtherDialogDescription, |
330 |
fileResource.getName())); |
331 |
if (dialog.open() == Window.OK) { |
332 |
IEditorDescriptor editor = dialog.getSelectedEditor(); |
333 |
if (editor != null) { |
334 |
openEditor(editor,editor.isOpenExternal()); |
335 |
} |
336 |
} |
337 |
break; |
338 |
} |
339 |
} |
340 |
}; |
341 |
menuItem.addListener(SWT.Selection, listener); |
342 |
} |
296 |
|
343 |
|
297 |
private IModelElement getModelElement() { |
344 |
private IModelElement getModelElement() { |
298 |
if (this.element instanceof IModelElement) { |
345 |
if (this.element instanceof IModelElement) { |
Link Here
|
322 |
return true; |
369 |
return true; |
323 |
} |
370 |
} |
324 |
|
371 |
|
|
|
372 |
// /** |
373 |
// * Opens the given editor on the selected file. |
374 |
// * |
375 |
// * @param editor |
376 |
// * the editor descriptor, or null for the system editor |
377 |
// */ |
378 |
// private void openEditor(IEditorDescriptor editor) { |
379 |
// IFile file = getFileResource(); |
380 |
// if (file == null) { |
381 |
// return; |
382 |
// } |
383 |
// try { |
384 |
// String editorId = editor == null ? IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID |
385 |
// : editor.getId(); |
386 |
// ((IWorkbenchPage) page).openEditor(new FileEditorInput(file), |
387 |
// editorId, true, MATCH_BOTH); |
388 |
// // only remember the default editor if the open succeeds |
389 |
// IDE.setDefaultEditor(file, editorId); |
390 |
// } catch (PartInitException e) { |
391 |
// if (DLTKCore.DEBUG) { |
392 |
// e.printStackTrace(); |
393 |
// } |
394 |
// // DialogUtil.openError(page.getWorkbenchWindow().getShell(), |
395 |
// // ActionMessages.OpenWithMenu_dialogTitle, |
396 |
// // e.getMessage(), e); |
397 |
// } |
398 |
// } |
399 |
|
325 |
/** |
400 |
/** |
326 |
* Opens the given editor on the selected file. |
401 |
* Opens the given editor on the selected file. |
327 |
* |
402 |
* |
328 |
* @param editor |
403 |
* @param editorDescriptor the editor descriptor, or null for the system editor |
329 |
* the editor descriptor, or null for the system editor |
404 |
* @param openUsingDescriptor use the descriptor's editor ID for opening if false (normal case), |
330 |
*/ |
405 |
* or use the descriptor itself if true (needed to fix bug 178235). |
331 |
private void openEditor(IEditorDescriptor editor) { |
406 |
* |
332 |
IFile file = getFileResource(); |
407 |
* @since 3.5 |
333 |
if (file == null) { |
408 |
*/ |
334 |
return; |
409 |
protected void openEditor(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) { |
335 |
} |
410 |
IFile file = getFileResource(); |
336 |
try { |
411 |
if (file == null) { |
337 |
String editorId = editor == null ? IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID |
412 |
return; |
338 |
: editor.getId(); |
413 |
} |
339 |
((IWorkbenchPage) page).openEditor(new FileEditorInput(file), |
414 |
try { |
340 |
editorId, true, MATCH_BOTH); |
415 |
if (openUsingDescriptor) { |
341 |
// only remember the default editor if the open succeeds |
416 |
((WorkbenchPage) page).openEditorFromDescriptor(new FileEditorInput(file), editorDescriptor, true, null); |
342 |
IDE.setDefaultEditor(file, editorId); |
417 |
} else { |
343 |
} catch (PartInitException e) { |
418 |
String editorId = editorDescriptor == null ? IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID |
344 |
if (DLTKCore.DEBUG) { |
419 |
: editorDescriptor.getId(); |
345 |
e.printStackTrace(); |
420 |
|
346 |
} |
421 |
((WorkbenchPage) page).openEditor(new FileEditorInput(file), editorId, true, MATCH_BOTH); |
347 |
// DialogUtil.openError(page.getWorkbenchWindow().getShell(), |
422 |
// only remember the default editor if the open succeeds |
348 |
// ActionMessages.OpenWithMenu_dialogTitle, |
423 |
IDE.setDefaultEditor(file, editorId); |
349 |
// e.getMessage(), e); |
424 |
} |
350 |
} |
425 |
} catch (PartInitException e) { |
351 |
} |
426 |
DialogUtil.openError(page.getWorkbenchWindow().getShell(), |
|
|
427 |
IDEWorkbenchMessages.OpenWithMenu_dialogTitle, |
428 |
e.getMessage(), e); |
429 |
} |
430 |
} |
352 |
|
431 |
|
353 |
/** |
432 |
/** |
354 |
* Creates the menu item for clearing the current selection. |
433 |
* Creates the menu item for clearing the current selection. |