Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable theming preference check box is not working as expected and forces to restart twice #2522

Open
2 tasks done
opcoach opened this issue Nov 18, 2024 · 4 comments · May be fixed by #2606
Open
2 tasks done

Enable theming preference check box is not working as expected and forces to restart twice #2522

opcoach opened this issue Nov 18, 2024 · 4 comments · May be fixed by #2606
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@opcoach
Copy link
Member

opcoach commented Nov 18, 2024

Let's make sure issue is not already fixed in latest builds first.

Steps to reproduce

From a fresh installation and clean workspace:

Install the setup of 'platform ui' by dragging the setup link in the banner of the installer : see Setting your environment and projects guide

Open the preference dialog and filter on 'theme'. Disable theming if there is one selected by unchecking the 'Enable Theming' checkbox and restart. Eclipse restarts without any theme.

Then reopen the preference dialog and filter on 'theme' then check the 'Enable theming' check box again and click Apply.

Eclipse will ask to restart, while no Theme has been yet selected.. and no theme has been proposed. The possible themes will appear after the restart and will be applicable, but we will have to restart again... this is not straightforward and totally counterintuitive.

Actually, when the 'Enable theming' is selected, it must display the themes and then propose to select one and restart when it is applied (even if the theme was not changed in the combo).

This is the current situation when we switch from 'Enable theming' unchecked to checked:

What we have (unchecked to checked) What we expect
image image

On the other hand, if we unchecked the theme while it was checked, the list of themes should be hidden:

What we have (checked to unchecked) What we expect
image image

|

The Plugin Spy (Alt Shift F1), launched when the preference page is displayed says that this preference page is managed by the ViewsPreferencePage in the org.eclipse.ui.workbench plugin :

image

A change event listener could be added on the preference checkbox editor so as to react on the change and display or not the bloc of theme list.

Tested under this environment:

  • OS & version: macOS X 15.1 (sequoia).
  • Eclipse IDE/Platform version (as shown in Help > About): Version: 2024-12 (4.34) Build id: I20241117-1800 (got from the platform.ui current setup)

Community

  • I understand reporting an issue to this OSS project does not mandate anyone to fix it. Other contributors may consider the issue, or not, at their own convenience. The most efficient way to get it fixed is that I fix it myself and contribute it back as a good quality patch to the project.
@opcoach opcoach added bug Something isn't working good first issue Good for newcomers labels Nov 18, 2024
@mai-tran-03
Copy link

I'm working on this.

@mai-tran-03
Copy link

I added the event listener to the createContents method to respond to a change in the selection of the themingEnabled button. It works for checked-to-unchecked, hiding the theme-dependent elements when clicked. However, after restarting the dialog, when themingEnabled button is clicked again (unchecked-to-checked), the content is still hidden. We still need to restart twice to get the desired effect of enabling and changing themes.

protected Control createContents(Composite parent) {
	// same code

	Composite comp = new Composite(parent, SWT.NONE);
	GridLayout mainLayout = new GridLayout();
	comp.setLayout(mainLayout);

	themingEnabled = createCheckButton(comp, WorkbenchMessages.ThemingEnabled, engine != null);

	// same code

	Composite themeDependentComp = new Composite(comp, SWT.NONE);
	GridLayout dependentLayout = new GridLayout(2, false);
	dependentLayout.horizontalSpacing = 10;
	themeDependentComp.setLayout(dependentLayout);
	GridData dependentData = new GridData(SWT.FILL, SWT.TOP, true, false);
	themeDependentComp.setLayoutData(dependentData);

	createThemeDependentComposite(themeDependentComp);
	createThemeIndependentComposite(comp);
	currentColorsAndFontsTheme = getCurrentColorsAndFontsTheme();

	// same code

	SelectionListener listener = new SelectionListener() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			boolean isThemingEnabled = themingEnabled.getSelection();
				themeDependentComp.setVisible(isThemingEnabled);
			GridData gridData = ((GridData) themeDependentComp.getLayoutData());
			gridData.exclude = !isThemingEnabled;
			comp.layout();
		}

		@Override
		public void widgetDefaultSelected(SelectionEvent e) {
				themeDependentComp.setVisible(true);
			}
		};
		themingEnabled.addSelectionListener(listener);

I organized the theme-dependent elements in a private method.

private void createThemeDependentComposite(Composite comp) {
	createThemeIdCombo(comp);
	createColorsAndFontsThemeCombo(comp);

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

@opcoach
Copy link
Member Author

opcoach commented Dec 7, 2024

Hi,

I think you didn't consider to save/restore the preference value associated to your boolean checkbox. And when you restart your application, the saved value is not applied on your swt widgets.

You can check the calls to

private boolean getSwtRendererPreference(String prefName, boolean defaultValue) {
		return Platform.getPreferencesService().getBoolean(PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT,
				prefName, defaultValue, null);
	}

which gets the value from the preference store.

The file that contains the preference values managed by this screen is located in your workspace, in the folder : .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.e4.ui.workbench.renderers.swt.prefs

For my sample, it contains :

HIDE_ICONS_FOR_VIEW_TABS=false
SHOW_FULL_TEXT_FOR_VIEW_TABS=true
USE_ROUND_TABS=true
eclipse.preferences.version=1
enableMRU=true
themeEnabled=true

When you change your values and you apply the preferences, you could check which values have changed in this file and write the code to restore the value when you create (for the first time) the preference page.

@mai-tran-03
Copy link

Hello!

It seems the problem stems from disabling themingEnabled disables engine which is needed to create the theme combo dropdown and other components that depend on the engine to be initialized. When engine is null, the page only shows the basic buttons that do not rely on themingEnabled, so that's why we need to restart twice. Once to initialize engine so it can getThemes(), and twice to apply any other new changes. I'm not sure about other workarounds.

@mai-tran-03 mai-tran-03 linked a pull request Dec 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants