Skip to content

Commit

Permalink
Fixes #3187 with an explicit flag to turn off the "new style" tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Sep 10, 2021
1 parent 3aa8de6 commit 913ea62
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 55 deletions.
29 changes: 1 addition & 28 deletions msi.gama.application/plugin.xml
Expand Up @@ -139,34 +139,7 @@
</property>
</product>
</extension>
<extension
point="org.eclipse.e4.ui.css.swt.theme">
<stylesheet
uri="css/tabs.css">
<themeid
refid="org.eclipse.e4.ui.css.theme.e4_default">
</themeid>
<themeid
refid="org.eclipse.e4.ui.css.theme.e4_classic">
</themeid>
<themeid
refid="org.eclipse.e4.ui.css.theme.e4_dark">
</themeid>
<themeid
refid="org.eclipse.e4.ui.css.theme.e4_system">
</themeid>
</stylesheet>
</extension>
<extension
id="gama.theming"
name="Dark theme for GAMA"
point="org.eclipse.e4.ui.css.swt.theme">
<theme
basestylesheeturi="msi.gama.application.theme1"
id="gama.dark.theme"
label="Gama Dark Theme">
</theme>
</extension>

<extension
id="testNature"
name="GAMA test project"
Expand Down
Expand Up @@ -32,6 +32,7 @@
import msi.gama.common.interfaces.IGui;
import msi.gama.common.preferences.GamaPreferences;
import msi.gama.runtime.GAMA;
import ummisco.gama.dev.utils.FLAGS;

/**
* The Class ApplicationWorkbenchWindowAdvisor.
Expand Down Expand Up @@ -101,6 +102,10 @@ public void pageClosed(final IWorkbenchPage page) {}
@Override
public void pageOpened(final IWorkbenchPage page) {}
});
// See #3187 -
if (FLAGS.USE_OLD_TABS) {
ThemeHelper.injectCSS(".MPartStack {\n" + " swt-tab-renderer: null;\n" + " swt-simple: true;\n" + "}");
}
configurer.setShowMenuBar(true);
configurer.setShowCoolBar(true);
configurer.setShowStatusLine(true);
Expand Down
Expand Up @@ -43,8 +43,8 @@
import org.osgi.service.event.EventHandler;
import org.osgi.service.prefs.BackingStoreException;
import org.w3c.css.sac.CSSParseException;
import org.w3c.dom.stylesheets.StyleSheet;
import org.w3c.dom.stylesheets.StyleSheetList;

import com.google.common.collect.Iterables;

import msi.gama.common.preferences.Pref;
import msi.gaml.types.IType;
Expand Down Expand Up @@ -196,7 +196,6 @@ public static void install() {
eventBroker.subscribe(IThemeEngine.Events.THEME_CHANGED, themeChangedHandler);
}
chooseThemeBasedOnPreferences();
// injectCSS(".MPartStack {\n" + " swt-tab-renderer: null;\n" + " swt-simple: true;\n" + "}");
}

/**
Expand Down Expand Up @@ -301,32 +300,28 @@ private static ThemeEngine getThemeEngine() {
*/
public static void injectCSS(final String cssText) {
StringBuilder sb = new StringBuilder();
// FIXME: expose these new protocols: resetCurrentTheme() and
// getCSSEngines()
getThemeEngine().resetCurrentTheme();
CSSEngine engine = Iterables.getFirst(getThemeEngine().getCSSEngines(), null);
if (engine == null) return;
// sb.append("Engine[").append(engine.getClass().getSimpleName()).append("]");
ExtendedDocumentCSS doc = (ExtendedDocumentCSS) engine.getDocumentCSS();
// List<StyleSheet> sheets = new ArrayList<>();
// StyleSheetList list = doc.getStyleSheets();
// for (int i = 0; i < list.getLength(); i++) { sheets.add(list.item(i)); }

int count = 0;
for (CSSEngine engine : getThemeEngine().getCSSEngines()) {
if (count++ > 0) { sb.append("\n\n"); }
sb.append("Engine[").append(engine.getClass().getSimpleName()).append("]");
ExtendedDocumentCSS doc = (ExtendedDocumentCSS) engine.getDocumentCSS();
List<StyleSheet> sheets = new ArrayList<>();
StyleSheetList list = doc.getStyleSheets();
for (int i = 0; i < list.getLength(); i++) { sheets.add(list.item(i)); }

try {
Reader reader = new StringReader(cssText);
sheets.add(0, engine.parseStyleSheet(reader));
doc.removeAllStyleSheets();
for (StyleSheet sheet : sheets) { doc.addStyleSheet(sheet); }
engine.reapply();

} catch (CSSParseException e) {
sb.append("\nError: line ").append(e.getLineNumber()).append(" col ").append(e.getColumnNumber())
.append(": ").append(e.getLocalizedMessage());
} catch (IOException e) {
sb.append("\nError: ").append(e.getLocalizedMessage());
}
try {
Reader reader = new StringReader(cssText);
doc.addStyleSheet(engine.parseStyleSheet(reader));
// sheets.add(/* 0, */ engine.parseStyleSheet(reader));
// doc.removeAllStyleSheets();
// for (StyleSheet sheet : sheets) { doc.addStyleSheet(sheet); }
engine.reapply();

} catch (CSSParseException e) {
sb.append("\nError: line ").append(e.getLineNumber()).append(" col ").append(e.getColumnNumber())
.append(": ").append(e.getLocalizedMessage());
} catch (IOException e) {
sb.append("\nError: ").append(e.getLocalizedMessage());
}
}

Expand Down
Expand Up @@ -83,4 +83,10 @@ private static boolean get(final String name, final boolean def) {
*/
public static final boolean IS_READ_ONLY = get("read_only", false);

/**
* Used in msi.gama.application.workbench.ApplicationWorkbenchWindowAdvisor to impose the use of the "classic" view
* tabs (with a visible border) and inject a specific CSS stylesheet. See #3187. True by default.
*/
public static final boolean USE_OLD_TABS = get("use_old_tabs", true);

}

0 comments on commit 913ea62

Please sign in to comment.