Index: messages.properties =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties,v retrieving revision 1.6 diff -u -r1.6 messages.properties --- messages.properties 8 Oct 2002 15:00:23 -0000 1.6 +++ messages.properties 23 Oct 2002 14:21:52 -0000 @@ -843,6 +843,8 @@ WelcomeEditor.readFileError = Error in WelcomeEditor.readFile WelcomeEditor.title = Welcome WelcomeEditor.toolTip = Welcome to {0} +WelcomeEditor.copy.text=&Copy + WelcomeItem.unableToLoadClass = Unable to load class WelcomeParser.parseError = Error in WelcomeParser.parse WelcomeParser.parseException = An exception occurred when parsing the welcome page Index: dialogs/WelcomeEditor.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WelcomeEditor.java,v retrieving revision 1.7 diff -u -r1.7 WelcomeEditor.java --- dialogs/WelcomeEditor.java 22 Oct 2002 15:18:06 -0000 1.7 +++ dialogs/WelcomeEditor.java 23 Oct 2002 14:21:52 -0000 @@ -12,6 +12,7 @@ import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.*; +import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.preference.JFacePreferences; import org.eclipse.jface.resource.JFaceColors; import org.eclipse.jface.resource.JFaceResources; @@ -62,16 +63,19 @@ private boolean dragEvent = false; private StyledText firstText, lastText; - private StyledText lastNavigatedText; + private StyledText lastNavigatedText, currentText; private boolean nextTabAbortTraversal, previousTabAbortTraversal = false; + private WelcomeEditorCopyAction copyAction; /** * Create a new instance of the welcome editor */ public WelcomeEditor() { super(); - setTitle(WorkbenchMessages.getString("WelcomeEditor.title")); //$NON-NLS-1$ + setTitle(WorkbenchMessages.getString("WelcomeEditor.title")); //$NON-NLS-1$ + copyAction = new WelcomeEditorCopyAction(this); + copyAction.setEnabled(false); } /** @@ -121,6 +125,19 @@ } /** + * Return the current text */ +protected StyledText getCurrentText() { + return currentText; +} + +/** + * Return the copy action + */ +protected WelcomeEditorCopyAction getCopyAction() { + return copyAction; +} + +/** * Find the next link after the current selection. */ private StyleRange findNextLink(StyledText text) { @@ -197,10 +214,12 @@ } } else if (item.isLinkAt(offset)) { text.setCursor(busyCursor); - item.triggerLinkAt(offset); - StyleRange selectionRange = getCurrentLink(text); - text.setSelectionRange(selectionRange.start, selectionRange.length); - text.setCursor(null); + if (e.button == 1) { + item.triggerLinkAt(offset); + StyleRange selectionRange = getCurrentLink(text); + text.setSelectionRange(selectionRange.start, selectionRange.length); + text.setCursor(null); + } } } }); @@ -368,14 +387,29 @@ }); styledText.addFocusListener(new FocusAdapter() { - // Handle mouse events, retain current position, remove highlights public void focusLost(FocusEvent e) { - StyledText text = (StyledText)e.widget; - text.setSelection(text.getSelection().x); - lastNavigatedText = text; + // Remember current text widget + lastNavigatedText = (StyledText)e.widget; } -}); + public void focusGained(FocusEvent e) { + currentText = (StyledText)e.widget; + + // Remove highlighted selection if text widget has changed + if ((currentText != lastNavigatedText) && (lastNavigatedText != null)) + lastNavigatedText.setSelection(lastNavigatedText.getSelection().x); + + // enable/disable copy action + copyAction.setEnabled(currentText.getSelectionCount()>0); + } + }); + styledText.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + // enable/disable copy action + StyledText text = (StyledText)e.widget; + copyAction.setEnabled(text.getSelectionCount()>0); + } + }); } /** @@ -480,7 +514,13 @@ gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; spacer.setLayoutData(gd); + + // create context menu + MenuManager menuMgr = new MenuManager("#PopUp"); //$NON-NLS-1$ + menuMgr.add(copyAction); + sampleStyledText.setMenu(menuMgr.createContextMenu(sampleStyledText)); } + lastText = sampleStyledText; this.scrolledComposite.setContent(infoArea); Point p = infoArea.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); @@ -802,18 +842,6 @@ *

*/ public void setFocus() { - if (editorComposite != null) { - editorComposite.setFocus(); - - if (lastNavigatedText != null) { - StyleRange selectionRange = getCurrentLink(lastNavigatedText); - if (selectionRange != null) - lastNavigatedText.setSelectionRange(selectionRange.start, selectionRange.length); - else - lastNavigatedText.setSelection(lastNavigatedText.getSelection().x); - focusOn(lastNavigatedText, lastNavigatedText.getCaretOffset()); - } - } } /** * Sets the styled text's link (blue) ranges Index: dialogs/WelcomeEditorActionContributor.java =================================================================== RCS file: dialogs/WelcomeEditorActionContributor.java diff -N dialogs/WelcomeEditorActionContributor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dialogs/WelcomeEditorActionContributor.java 23 Oct 2002 14:21:52 -0000 @@ -0,0 +1,34 @@ +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation +**********************************************************************/ + +package org.eclipse.ui.internal.dialogs; + +import org.eclipse.ui.*; +import org.eclipse.ui.part.EditorActionBarContributor; + + +/** + * Manages the installation and deinstallation of global actions for + * the welcome editor. + */ +public class WelcomeEditorActionContributor extends EditorActionBarContributor { + /** + * The WelcomeEditorActionContributor implementation of this + * IEditorActionBarContributor method installs the global + * action handler for the given editor. + */ + public void setActiveEditor(IEditorPart part) { + IActionBars actionBars= getActionBars(); + if (actionBars != null) { + actionBars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, ((WelcomeEditor)part).getCopyAction()); + } + } +} \ No newline at end of file Index: dialogs/WelcomeEditorCopyAction.java =================================================================== RCS file: dialogs/WelcomeEditorCopyAction.java diff -N dialogs/WelcomeEditorCopyAction.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dialogs/WelcomeEditorCopyAction.java 23 Oct 2002 14:21:52 -0000 @@ -0,0 +1,31 @@ +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation +**********************************************************************/ + +package org.eclipse.ui.internal.dialogs; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.internal.WorkbenchMessages; + +/** + * Global copy action for the welcome editor. + */ +public class WelcomeEditorCopyAction extends Action { + private WelcomeEditor editorPart; + + public WelcomeEditorCopyAction(WelcomeEditor editor) { + editorPart = editor; + setText(WorkbenchMessages.getString("WelcomeEditor.copy.text")); + } + + public void run() { + editorPart.getCurrentText().copy(); + } +} \ No newline at end of file