Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…latform.ui into master-shah1
  • Loading branch information
ShahzaibIbrahim committed Apr 22, 2024
2 parents 0964792 + aced78a commit 55b2a8b
Show file tree
Hide file tree
Showing 17 changed files with 448 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.e4.ui.internal.css.swt.ICTabRendering;
import org.eclipse.e4.ui.internal.workbench.PartStackUtil;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
import org.eclipse.e4.ui.model.application.ui.MContext;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabFolderRenderer;
Expand Down Expand Up @@ -1329,15 +1326,7 @@ private void hideIconsForViewTabsPreferenceChanged() {

private boolean isPartOfEditorStack() {
MUIElement element = (MUIElement) parent.getData(AbstractPartRenderer.OWNING_ME);
EObject root = EcoreUtil.getRootContainer((EObject) element, true);
if (root instanceof MContext context) {
EModelService eModelService = context.getContext().get(EModelService.class);
if (eModelService != null) {
int location = eModelService.getElementLocation(element);
return (location & EModelService.IN_SHARED_AREA) != 0;
}
}
return false;
return PartStackUtil.isEditorStack(element);
}

private boolean getSwtRendererPreference(String prefName, boolean defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.internal.workbench.OpaqueElementUtil;
import org.eclipse.e4.ui.internal.workbench.PartStackUtil;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.BasicPartList;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.SWTRenderersMessages;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
Expand Down Expand Up @@ -128,8 +129,6 @@ public class StackRenderer extends LazyStackRenderer {
private static final String ONBOARDING_IMAGE = "EditorStack.OnboardingImage"; //$NON-NLS-1$
private static final String ONBOARDING_TEXT = "EditorStack.OnboardingText"; //$NON-NLS-1$

private static final String EDITOR_STACK_ID = "EditorStack"; //$NON-NLS-1$

/**
* Id of a a control.
*/
Expand Down Expand Up @@ -703,7 +702,7 @@ public Object createWidget(MUIElement element, Object parent) {
int location = modelService.getElementLocation(element);
boolean isInSharedArea = (location & EModelService.IN_SHARED_AREA) != 0;
if (isInSharedArea) {
pStack.getTags().add(EDITOR_STACK_ID);
PartStackUtil.makeEditorStack(pStack);
}

Composite parentComposite = (Composite) parent;
Expand All @@ -717,7 +716,7 @@ public Object createWidget(MUIElement element, Object parent) {
int styleOverride = getStyleOverride(pStack);
int style = styleOverride == -1 ? SWT.BORDER : styleOverride;
CTabFolder tabFolder = new CTabFolder(parentComposite, style);
if (pStack.getTags().contains("EditorStack")) { //$NON-NLS-1$
if (PartStackUtil.isEditorStack(element)) {
createOnboardingControls(tabFolder);
initializeOnboardingInformationInEditorStack(tabFolder);
}
Expand Down Expand Up @@ -1926,7 +1925,8 @@ private Stream<CTabFolder> getEditorTabFolders(MPerspective perspective) {
Predicate<Object> tabFolders = CTabFolder.class::isInstance;
Function<Object, CTabFolder> toTabFolder = CTabFolder.class::cast;

List<MPartStack> elements = modelService.findElements(perspective, null, MPartStack.class, List.of(EDITOR_STACK_ID));
List<MPartStack> elements = modelService.findElements(perspective, null, MPartStack.class,
List.of(PartStackUtil.EDITOR_STACK_TAG));
return elements.stream().map(MUIElement::getWidget).filter(tabFolders).map(toTabFolder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ private PartStackUtil() {
* @param partStack the part stack to make the primary data stack
*/
public static void initializeAsPrimaryDataStack(MPartStack partStack) {
makeEditorStack(partStack);
partStack.getTags().add(PRIMARY_DATA_STACK_ID);
if (!partStack.getTags().contains(EDITOR_STACK_TAG)) {
partStack.getTags().add(EDITOR_STACK_TAG);
}
partStack.setElementId(PRIMARY_DATA_STACK_ID);
}

Expand All @@ -42,4 +40,26 @@ public static void initializeAsPrimaryDataStack(MPartStack partStack) {
public static boolean isPrimaryDataStack(MApplicationElement element) {
return element instanceof MPartStack && PRIMARY_DATA_STACK_ID.equals(element.getElementId());
}

/**
* @param element the element to check for being an editor stack
* @return whether the given element is marked as an editor stack
*/
public static boolean isEditorStack(MApplicationElement element) {
return element instanceof MPartStack && element.getTags().contains(EDITOR_STACK_TAG);
}

/**
* Marks the given part stack as an editor stack. In consequence calling
* {{@link #isEditorStack(MApplicationElement)} for the element will return
* {@code true}.
*
* @param partStack the part stack to mark as an editor stack
*/
public static void makeEditorStack(MPartStack partStack) {
if (!partStack.getTags().contains(EDITOR_STACK_TAG)) {
partStack.getTags().add(EDITOR_STACK_TAG);
}
}

}
1 change: 1 addition & 0 deletions bundles/org.eclipse.ui.genericeditor/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ gotoMatchingBracketCommand_name = Go to Matching Bracket
gotoMatchingBracketCommand_description = Moves the cursor to the matching bracket
systemEditorOrGenericEditorStrategy=System Editor; if none: Advanced Text Editor
genericEditorStrategy=Advanced Text Editor
PreferencePages.GenericTextEditors=Generic Text Editors
9 changes: 9 additions & 0 deletions bundles/org.eclipse.ui.genericeditor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,13 @@
label="%genericEditorStrategy">
</strategy>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="org.eclipse.ui.preferencePages.GeneralTextEditor"
class="org.eclipse.ui.internal.genericeditor.preferences.GenericEditorPreferencePage"
id="org.eclipse.ui.genericeditor.GenericTextEditor"
name="%PreferencePages.GenericTextEditors">
</page>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.genericeditor.preferences.GenericEditorPreferenceConstants;

Expand All @@ -43,11 +45,12 @@
*
* @author christoph
*/
public class GenericEditorContentAssistant extends ContentAssistant {
public class GenericEditorContentAssistant extends ContentAssistant implements IPropertyChangeListener {
private static final DefaultContentAssistProcessor DEFAULT_CONTENT_ASSIST_PROCESSOR = new DefaultContentAssistProcessor();
private ContentTypeRelatedExtensionTracker<IContentAssistProcessor> contentAssistProcessorTracker;
private Set<IContentType> types;
private List<IContentAssistProcessor> processors;
private final IPreferenceStore preferenceStore;

/**
* Creates a new GenericEditorContentAssistant instance for the given content
Expand Down Expand Up @@ -90,20 +93,17 @@ public GenericEditorContentAssistant(
this.contentAssistProcessorTracker = contentAssistProcessorTracker;
this.processors = Objects.requireNonNullElseGet(processors, () -> Collections.emptyList());
this.types = types;
this.preferenceStore = preferenceStore;

setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_BELOW);
setProposalPopupOrientation(IContentAssistant.PROPOSAL_REMOVE);
enableColoredLabels(true);
if (preferenceStore != null) {
enableAutoActivation(
preferenceStore.getBoolean(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION));
setAutoActivationDelay(
preferenceStore.getInt(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY));
enableAutoActivateCompletionOnType(preferenceStore
.getBoolean(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_ON_TYPE));
updateAutoActivationPreferences();
preferenceStore.addPropertyChangeListener(this);
} else {
enableAutoActivation(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_DEFAULT);
setAutoActivationDelay(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY_DEFUALT);
setAutoActivationDelay(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY_DEFAULT);
enableAutoActivateCompletionOnType(
GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_ON_TYPE_DEFAULT);
}
Expand Down Expand Up @@ -150,9 +150,21 @@ private void updateProcessorToken(IContentAssistProcessor processor, IDocument d
}
}

private void updateAutoActivationPreferences() {
enableAutoActivation(
preferenceStore.getBoolean(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION));
setAutoActivationDelay(
preferenceStore.getInt(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY));
enableAutoActivateCompletionOnType(
preferenceStore.getBoolean(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_ON_TYPE));
}

@Override
public void uninstall() {
contentAssistProcessorTracker.stopTracking();
if (preferenceStore != null) {
preferenceStore.removePropertyChangeListener(this);
}
super.uninstall();
}

Expand All @@ -175,4 +187,9 @@ public void install(ITextViewer textViewer) {
});
contentAssistProcessorTracker.startTracking();
}

@Override
public void propertyChange(PropertyChangeEvent event) {
updateAutoActivationPreferences();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public class Messages extends NLS {
public static String GotoMatchingBracket_error_bracketOutsideSelectedElement;
public static String GenericEditorMergeViewer_title;

public static String ContentAssistant;
public static String ContentAssistant_autoActivation;
public static String ContentAssistant_autoActivation_Tooltip;
public static String ContentAssistant_autoActivationDelay;
public static String ContentAssistant_autoActivationDelay_Tooltip;
public static String ContentAssistant_autoActivationOnType;
public static String ContentAssistant_autoActivationOnType_Tooltip;
public static String ContentAssistant_autoActivationDelay_InvalidInput;
public static String ContentAssistant_autoActivationDelay_EmptyInput;

static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ TextViewer_open_hyperlink_error_message=The operation is not applicable to the c
GotoMatchingBracket_error_noMatchingBracket=No matching bracket found
GotoMatchingBracket_error_bracketOutsideSelectedElement=Matching bracket is outside the selected element

ContentAssistant=Content Assist
ContentAssistant_autoActivation=Enable auto activation
ContentAssistant_autoActivation_Tooltip=The content assist will be activated on typing or on trigger characters if auto activation is enabled.
ContentAssistant_autoActivationDelay=Auto activation delay (ms):
ContentAssistant_autoActivationDelay_Tooltip=Activation delay in milliseconds for content assist.
ContentAssistant_autoActivationOnType=Enable auto activation on typing
ContentAssistant_autoActivationOnType_Tooltip=Controls whether auto activation on typing is enabled. If disabled, content assist will be activated by trigger characters only.
ContentAssistant_autoActivationDelay_InvalidInput=''{0}'' is not a valid input.
ContentAssistant_autoActivationDelay_EmptyInput=Empty input.

GenericEditorMergeViewer_title={0} Compare
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private GenericEditorPreferenceConstants() {
* @since 1.3
*/
public final static String CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY = "contentAssistant.autoActivationDelay"; //$NON-NLS-1$
public final static int CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY_DEFUALT = 10;
public final static int CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY_DEFAULT = 10;

/**
* A named preference that controls whether auto activation on typing is enabled
Expand Down Expand Up @@ -138,7 +138,7 @@ public static void initializeDefaultValues(IPreferenceStore store) {
store.setDefault(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION,
CONTENT_ASSISTANT_AUTO_ACTIVATION_DEFAULT);
store.setDefault(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY,
CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY_DEFUALT);
CONTENT_ASSISTANT_AUTO_ACTIVATION_DELAY_DEFAULT);
store.setDefault(GenericEditorPreferenceConstants.CONTENT_ASSISTANT_AUTO_ACTIVATION_ON_TYPE,
CONTENT_ASSISTANT_AUTO_ACTIVATION_ON_TYPE_DEFAULT);
// Colors that are set by the current theme
Expand Down
Loading

0 comments on commit 55b2a8b

Please sign in to comment.