Skip to content

Commit

Permalink
Add Options to hide tab icons and and show full text in view area (ec…
Browse files Browse the repository at this point in the history
…lipse-platform#1071)

* Added CSSPropertyHandler for handling selected tab image and full text

Change-Id: I220507837cf3472bfb0f5d8a24d9d596568e232a

* Added hide icons and show full text options for View tabs

Added UI controls in View Preference page
Added handlers to hide icons and show full text for view tabs in
CTabRendering

Change-Id: Ib719fcb114ec0b2edaa1a8a7d0c5dd5e4a1ca075

* Refactored SelectedImageVisibility handler

Change-Id: I0c194113893a21069788b9a99907c419dedf0d6e

* Added minimum chars tab handler,made icons & title prefs theme dependent

* Added copyright header, improved variable/method names & code formatting

* Refactored CSSPropertyHandlers and CTabRendering

---------

Co-authored-by: Shubham Waghmare <shubham.waghmare@sap.com>
Co-authored-by: shubhamWaghmare-sap <57699330+shubhamWaghmare-sap@users.noreply.github.com>
  • Loading branch information
3 people authored and amartya4256 committed Feb 8, 2024
1 parent d1fb200 commit fb0eabd
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 4 deletions.
16 changes: 16 additions & 0 deletions bundles/org.eclipse.e4.ui.css.swt/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@
name="swt-tab-height">
</property-name>
</handler>
<handler
adapter="org.eclipse.e4.ui.css.swt.dom.CTabFolderElement"
composite="false"
handler="org.eclipse.e4.ui.css.swt.properties.custom.CSSPropertyTabTextMinimumCharactersSWTHandler">
<property-name
name="swt-tab-text-minimum-characters">
</property-name>
</handler>
<handler
adapter="org.eclipse.e4.ui.css.swt.dom.CTabFolderElement"
composite="false"
Expand All @@ -373,6 +381,14 @@
name="swt-unselected-image-visible">
</property-name>
</handler>
<handler
adapter="org.eclipse.e4.ui.css.swt.dom.CTabFolderElement"
composite="false"
handler="org.eclipse.e4.ui.css.swt.properties.custom.CSSPropertySelectedImageVisibleSWTHandler">
<property-name
name="swt-selected-image-visible">
</property-name>
</handler>
<handler
adapter="org.eclipse.e4.ui.css.swt.dom.CTabFolderElement"
composite="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2023 SAP SE.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: SAP SE - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.custom;

import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.widgets.Control;
import org.w3c.dom.css.CSSValue;

public class CSSPropertySelectedImageVisibleSWTHandler extends AbstractCSSPropertySWTHandler {

@Override
public void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
throws Exception {
boolean isImageVisibleForSelectedTab = (Boolean) engine.convert(value, Boolean.class, null);
if (control instanceof CTabFolder folder) {
folder.setSelectedImageVisible(isImageVisibleForSelectedTab);
}
}

@Override
public String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine)
throws Exception {
if (control instanceof CTabFolder folder) {
return Boolean.toString(folder.getSelectedImageVisible());
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2023 SAP SE.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: SAP SE - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.custom;

import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.widgets.Control;
import org.w3c.dom.css.CSSPrimitiveValue;
import org.w3c.dom.css.CSSValue;

/**
* CSS property to influence the minimum number of characters for rendering tab text and size
*
* Can be used in CSS Scratch Pad with the property name "swt-tab-text-minimum-characters", for example:
* CTabFolder { swt-tab-text-minimum-characters: 20 }
*
* Default value for the property is 1.
*/
public class CSSPropertyTabTextMinimumCharactersSWTHandler extends AbstractCSSPropertySWTHandler {

@Override
protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
throws Exception {
if (!(control instanceof CTabFolder)) {
return;
}

if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE
&& (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_NUMBER)) {
int minimumCharacters = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
CTabFolder folder = (CTabFolder) control;
folder.setMinimumCharacters(minimumCharacters);
}
}

@Override
protected String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine)
throws Exception {
if (control instanceof CTabFolder folder) {
return Integer.toString(folder.getMinimumCharacters());
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@
package org.eclipse.e4.ui.workbench.renderers.swt;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
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.swt.AbstractPartRenderer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabFolderRenderer;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
Expand Down Expand Up @@ -54,6 +59,37 @@ public class CTabRendering extends CTabFolderRenderer implements ICTabRendering,
* Default value for "use round tabs" preference
*/
public static final boolean USE_ROUND_TABS_DEFAULT = false;
/**
* A named preference for setting CTabFolder's to be rendered without icons in view areas
* <p>
* The default value for this preference is: <code>false</code> (render
* CTabFolder's with icons)
* </p>
*/
public static final String HIDE_ICONS_FOR_VIEW_TABS = "HIDE_ICONS_FOR_VIEW_TABS"; //$NON-NLS-1$

/**
* Default value for "hide icons" preference for view tabs
*/
public static final boolean HIDE_ICONS_FOR_VIEW_TABS_DEFAULT = false;
/**
* A named preference for setting CTabFolder's to show full text in view areas
* <p>
* The default value for this preference is: <code>false</code> (render
* CTabFolder's without full text)
* </p>
*/
public static final String SHOW_FULL_TEXT_FOR_VIEW_TABS = "SHOW_FULL_TEXT_FOR_VIEW_TABS"; //$NON-NLS-1$

/**
* Default value for "show full text" preference for view tabs
*/
public static final boolean SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT = false;

private static int MIN_VIEW_CHARS = 1;
private static int MAX_VIEW_CHARS = 9999;

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

// Constants for circle drawing
static enum CirclePart {
Expand Down Expand Up @@ -139,6 +175,8 @@ public CTabRendering(CTabFolder parent) {
parent.addDisposeListener(e -> preferences.removePreferenceChangeListener(this));

cornerRadiusPreferenceChanged();
showFullTextForViewTabsPreferenceChanged();
hideIconsForViewTabsPreferenceChanged();
}

@Override
Expand Down Expand Up @@ -1253,13 +1291,55 @@ private void cornerRadiusPreferenceChanged() {

@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (!USE_ROUND_TABS.equals(event.getKey())) {
return;
if (event.getKey().equals(USE_ROUND_TABS)) {
cornerRadiusPreferenceChanged();
} else if (event.getKey().equals(HIDE_ICONS_FOR_VIEW_TABS)) {
hideIconsForViewTabsPreferenceChanged();
} else if (event.getKey().equals(SHOW_FULL_TEXT_FOR_VIEW_TABS)) {
showFullTextForViewTabsPreferenceChanged();
}
}

private void showFullTextForViewTabsPreferenceChanged() {
boolean showFullText = getShowFullTextForViewTabsPreference();
if (!isPartOfEditorStack()) {
if (showFullText) {
Optional<Integer> lengthOfLongestItemText = Arrays.stream(parent.getItems()).map(CTabItem::getText)
.map(String::length)
.max(Integer::compare);
parent.setMinimumCharacters(lengthOfLongestItemText.orElseGet(() -> MAX_VIEW_CHARS));
} else {
parent.setMinimumCharacters(MIN_VIEW_CHARS);
}
parent.redraw();
}
}

private void hideIconsForViewTabsPreferenceChanged() {
boolean hideIcons = getHideIconsForViewTabsPreference();
if (!isPartOfEditorStack()) {
parent.setSelectedImageVisible(!hideIcons);
parent.setUnselectedImageVisible(!hideIcons);
parent.redraw();
}
cornerRadiusPreferenceChanged();
}

private IEclipsePreferences getSwtRendererPreferences() {
return InstanceScope.INSTANCE.getNode("org.eclipse.e4.ui.workbench.renderers.swt"); //$NON-NLS-1$
}

private boolean isPartOfEditorStack() {
MUIElement element = (MUIElement) parent.getData(AbstractPartRenderer.OWNING_ME);
return element != null && element.getTags().contains(EditorTag);
}

private boolean getHideIconsForViewTabsPreference() {
IEclipsePreferences preferences = getSwtRendererPreferences();
return preferences.getBoolean(HIDE_ICONS_FOR_VIEW_TABS, HIDE_ICONS_FOR_VIEW_TABS_DEFAULT);
}

private boolean getShowFullTextForViewTabsPreference() {
IEclipsePreferences preferences = getSwtRendererPreferences();
return preferences.getBoolean(SHOW_FULL_TEXT_FOR_VIEW_TABS, SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ public class WorkbenchMessages extends NLS {
public static String ViewsPreference_visibleTabs_description;
public static String ViewsPreference_enableMRU;
public static String ViewsPreference_useColoredLabels;
public static String ViewsPreference_viewTabs_icons_and_titles_label;
public static String ViewsPreference_showFullTextForViewTabs;
public static String ViewsPreference_hideIconsForViewTabs;
public static String ToggleFullScreenMode_ActivationPopup_Description;
public static String ToggleFullScreenMode_ActivationPopup_Description_NoKeybinding;
public static String ToggleFullScreenMode_ActivationPopup_DoNotShowAgain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
Expand Down Expand Up @@ -107,6 +109,9 @@ public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPre

private Button themingEnabled;

private Button hideIconsForViewTabs;
private Button showFullTextForViewTabs;

@Override
protected Control createContents(Composite parent) {
initializeDialogUnits(parent);
Expand Down Expand Up @@ -162,6 +167,11 @@ protected Control createContents(Composite parent) {

createThemeIndependentComposits(comp);

// Theme dependent controls for Tab icons and titles in view areas
createShowFullTextForViewTabs(comp);
createHideIconsForViewTabs(comp);
createDependency(showFullTextForViewTabs, hideIconsForViewTabs);

if (currentTheme != null) {
String colorsAndFontsThemeId = getColorAndFontThemeIdByThemeId(currentTheme.getId());
if (colorsAndFontsThemeId != null && !currentColorsAndFontsTheme.getId().equals(colorsAndFontsThemeId)) {
Expand All @@ -180,6 +190,52 @@ private void createThemeIndependentComposits(Composite comp) {
createEnableMruPref(comp);
}

protected void createShowFullTextForViewTabs(Composite composite) {
IEclipsePreferences prefs = getSwtRendererPreferences();
boolean actualValue = prefs.getBoolean(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS,
CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT);
createLabel(composite, ""); //$NON-NLS-1$
createLabel(composite, WorkbenchMessages.ViewsPreference_viewTabs_icons_and_titles_label);
showFullTextForViewTabs = createCheckButton(composite,
WorkbenchMessages.ViewsPreference_showFullTextForViewTabs, actualValue);
}

protected void createHideIconsForViewTabs(Composite composite) {
IEclipsePreferences prefs = getSwtRendererPreferences();
boolean actualValue = prefs.getBoolean(CTabRendering.HIDE_ICONS_FOR_VIEW_TABS,
CTabRendering.HIDE_ICONS_FOR_VIEW_TABS_DEFAULT);
hideIconsForViewTabs = createCheckButton(composite, WorkbenchMessages.ViewsPreference_hideIconsForViewTabs,
actualValue);
}

/**
* @param showFullTextForViewTabs
* @param hideIconsForViewTabs
*/
private void createDependency(Button parent, Button dependent) {
GridData gridData = new GridData();
gridData.horizontalIndent = 20;
dependent.setLayoutData(gridData);

boolean parentState = parent.getSelection();
dependent.setEnabled(parentState);

SelectionListener listener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean state = parent.getSelection();
dependent.setEnabled(state);
if (!state) {
dependent.setSelection(state);
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
};
parent.addSelectionListener(listener);
}

private List<ITheme> getCSSThemes(boolean highContrastMode) {
ArrayList<ITheme> themes = new ArrayList<>();
for (ITheme theme : engine.getThemes()) {
Expand Down Expand Up @@ -257,17 +313,19 @@ public void init(IWorkbench workbench) {

@Override
public boolean performOk() {
IEclipsePreferences prefs = getSwtRendererPreferences();
if (engine != null) {
ITheme theme = getSelectedTheme();
if (theme != null) {
engine.setTheme(getSelectedTheme(), !highContrastMode);
}
prefs.putBoolean(CTabRendering.HIDE_ICONS_FOR_VIEW_TABS, hideIconsForViewTabs.getSelection());
prefs.putBoolean(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS, showFullTextForViewTabs.getSelection());
}

IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
apiStore.setValue(IWorkbenchPreferenceConstants.USE_COLORED_LABELS, useColoredLabels.getSelection());

IEclipsePreferences prefs = getSwtRendererPreferences();
prefs.putBoolean(StackRenderer.MRU_KEY, enableMru.getSelection());
boolean themingEnabledChanged = prefs.getBoolean(PartRenderingEngine.ENABLED_THEME_KEY, true) != themingEnabled
.getSelection();
Expand Down Expand Up @@ -342,6 +400,8 @@ protected void performDefaults() {
if (engine.getActiveTheme() != null) {
themeIdCombo.setSelection(new StructuredSelection(engine.getActiveTheme()));
}
hideIconsForViewTabs.setSelection(CTabRendering.HIDE_ICONS_FOR_VIEW_TABS_DEFAULT);
showFullTextForViewTabs.setSelection(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT);
}
IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
useColoredLabels.setSelection(apiStore.getDefaultBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ ViewsPreference_useRoundTabs=&Use round tabs
ViewsPreference_useColoredLabels = &Use mixed fonts and colors for labels
ViewsPreference_visibleTabs_description = Visible tabs on overflow:
ViewsPreference_enableMRU = Show &most recently used tabs
ViewsPreference_showFullTextForViewTabs = Always show full titles
ViewsPreference_hideIconsForViewTabs = Hide icons
ViewsPreference_viewTabs_icons_and_titles_label = Tab icons and titles in view areas:
ToggleFullScreenMode_ActivationPopup_Description=You have gone full screen. Use the Toggle Full Screen command ({0}) to deactivate.
ToggleFullScreenMode_ActivationPopup_Description_NoKeybinding=You have gone full screen. Use the Toggle Full Screen command to deactivate.
ToggleFullScreenMode_ActivationPopup_DoNotShowAgain=Do not show again
Expand Down

0 comments on commit fb0eabd

Please sign in to comment.