<commit_before>// The MIT License (MIT)
//
// Copyright (c) 2015, 2019 <NAME>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions: The above copyright notice and this permission
// notice shall be included in all copies or substantial portions of the
// Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
package phasereditor.ide.ui;

import static phasereditor.ui.IEditorSharedImages.IMG_ARROW_REFRESH;
import static phasereditor.ui.IEditorSharedImages.IMG_GAME_CONTROLLER;
import static phasereditor.ui.IEditorSharedImages.IMG_SEARCH;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.renderers.swt.TrimmedPartLayout;
import org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer;
import org.eclipse.e4.ui.workbench.renderers.swt.WorkbenchRendererFactory;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
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;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveListener;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.NewWizardDropDownAction;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.quickaccess.QuickAccessDialog;
import org.eclipse.ui.statushandlers.StatusManager;

import phasereditor.ide.IDEPlugin;
import phasereditor.ui.EditorSharedImages;
import phasereditor.ui.IEditorHugeToolbar;
import phasereditor.webrun.ui.WebRunUI;

/**
 * @author arian
 *
 */
public class MyRenderFactory extends WorkbenchRendererFactory {
	private MyWBWRenderer _winRenderer;

	@Override
	public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
		if (uiElement instanceof MWindow) {
			if (_winRenderer == null) {
				_winRenderer = new MyWBWRenderer();
				initRenderer(_winRenderer);
			}
			return _winRenderer;
		}

		return super.getRenderer(uiElement, parent);
	}

}

class MyWBWRenderer extends WBWRenderer {

	public static int GUTTER_TOP;

	@Override
	public Object createWidget(MUIElement element, Object parent) {
		var widget = super.createWidget(element, parent);

		var shell = (Shell) widget;

		var layout = (TrimmedPartLayout) shell.getLayout();

		var toolbar = new HugeToolbar(shell);

		layout.gutterTop = toolbar.getBounds().height;
		GUTTER_TOP = layout.gutterTop;

		return widget;
	}

}

class HugeToolbar extends Composite implements IPartListener {

	private Composite _centerArea;
	private IEditorPart _activeEditor;

	@SuppressWarnings("unused")
	public HugeToolbar(Composite parent) {
		super(parent, 0);

		var gridLayout = new GridLayout(3, false);
		gridLayout.marginWidth = gridLayout.marginHeight = 0;
		setLayout(gridLayout);

		parent.addControlListener(new ControlListener() {

			@Override
			public void controlResized(ControlEvent e) {
				updateBounds();
			}

			@Override
			public void controlMoved(ControlEvent e) {
				updateBounds();
			}
		});

		var layout = new RowLayout();
		layout.marginWidth = layout.marginHeight = 0;
		layout.center = true;

		var leftArea = new Composite(this, 0);
		leftArea.setLayout(layout);
		leftArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		{
			_centerArea = new Composite(this, 0);
			_centerArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
			var layout2 = new RowLayout();
			layout2.marginWidth = layout2.marginHeight = 0;
			_centerArea.setLayout(layout2);
		}

		var rightArea = new Composite(this, 0);
		rightArea.setLayout(layout);

		new GoHomeWrapper(leftArea);
		new NewMenuWrapper(leftArea);
		new RunProjectWrapper(leftArea);
		new QuickAccessWrapper(rightArea);

		{
			var sep = new Label(rightArea, SWT.SEPARATOR);
			sep.setLayoutData(new RowData(SWT.DEFAULT, getFont().getFontData()[0].getHeight()));
		}

		new PerspectiveSwitcherWrapper(rightArea);

		updateBounds();

		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addPartListener(this);
	}

	private void updateBounds() {
		var size = computeSize(SWT.DEFAULT, SWT.DEFAULT);
		setBounds(0, 0, getParent().getBounds().width, size.y);
	}

	private void updateWithCurrentEditor() {
		var editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
		if (editor == _activeEditor) {
			return;
		}
<commit_msg>Fixes new main bar in Windows OS.<commit_after>// The MIT License (MIT)
//
// Copyright (c) 2015, 2019 <NAME>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions: The above copyright notice and this permission
// notice shall be included in all copies or substantial portions of the
// Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
package phasereditor.ide.ui;

import static phasereditor.ui.IEditorSharedImages.IMG_ARROW_REFRESH;
import static phasereditor.ui.IEditorSharedImages.IMG_GAME_CONTROLLER;
import static phasereditor.ui.IEditorSharedImages.IMG_SEARCH;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.renderers.swt.TrimmedPartLayout;
import org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer;
import org.eclipse.e4.ui.workbench.renderers.swt.WorkbenchRendererFactory;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
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;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveListener;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.NewWizardDropDownAction;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.quickaccess.QuickAccessDialog;
import org.eclipse.ui.statushandlers.StatusManager;

import phasereditor.ide.IDEPlugin;
import phasereditor.ui.EditorSharedImages;
import phasereditor.ui.IEditorHugeToolbar;
import phasereditor.webrun.ui.WebRunUI;

/**
 * @author arian
 *
 */
public class MyRenderFactory extends WorkbenchRendererFactory {
	private MyWBWRenderer _winRenderer;

	@Override
	public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
		if (uiElement instanceof MWindow) {
			if (_winRenderer == null) {
				_winRenderer = new MyWBWRenderer();
				initRenderer(_winRenderer);
			}
			return _winRenderer;
		}

		return super.getRenderer(uiElement, parent);
	}

}

class MyWBWRenderer extends WBWRenderer {

	public static int GUTTER_TOP;

	@Override
	public Object createWidget(MUIElement element, Object parent) {
		var widget = super.createWidget(element, parent);

		var shell = (Shell) widget;

		var layout = (TrimmedPartLayout) shell.getLayout();

		var toolbar = new HugeToolbar(shell);

		layout.gutterTop = toolbar.getBounds().height;
		GUTTER_TOP = layout.gutterTop;

		return widget;
	}

}

class HugeToolbar extends Composite implements IPartListener {

	private Composite _centerArea;
	private IEditorPart _activeEditor;

	@SuppressWarnings("unused")
	public HugeToolbar(Composite parent) {
		super(parent, 0);

		var gridLayout = new GridLayout(3, false);
		gridLayout.marginWidth = gridLayout.marginHeight = 0;
		setLayout(gridLayout);

		parent.addControlListener(new ControlListener() {

			@Override
			public void controlResized(ControlEvent e) {
				updateBounds();
			}

			@Override
			public void controlMoved(ControlEvent e) {
				updateBounds();
			}
		});

		var layout = new RowLayout();
		layout.marginWidth = layout.marginHeight = 0;
		layout.center = true;

		var leftArea = new Composite(this, 0);
		leftArea.setLayout(layout);
		leftArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		{
			_centerArea = new Composite(this, 0);
			_centerArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
			var layout2 = new RowLayout();
			layout2.marginWidth = layout2.marginHeight = 0;
			_centerArea.setLayout(layout2);
		}

		var rightArea = new Composite(this, 0);
		rightArea.setLayout(layout);

		new GoHomeWrapper(leftArea);
		new NewMenuWrapper(leftArea);
		new RunProjectWrapper(leftArea);
		new QuickAccessWrapper(rightArea);

		{
			var sep = new Label(rightArea, SWT.SEPARATOR);
			sep.setLayoutData(new RowData(SWT.DEFAULT, getFont().getFontData()[0].getHeight()));
		}

		new PerspectiveSwitcherWrapper(rightArea);

		updateBounds();

		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addPartListener(this);
	}

	private void updateBounds() {
		var size = computeSize(SWT.DEFAULT, SWT.DEFAULT);
		setBounds(0, 0, getParent().getClientArea().width, size.y);
	}

	private void updateWithCurrentEditor() {
		var editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
		if (editor == _activeEditor) {
			return;
		}

{'fraction_non_alphanumeric': 0.10041171088746569, 'fraction_numerical': 0.004422079902409271, 'mean_word_length': 5.193106704438149, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '380168', 'n_tokens_mistral': 4255, 'n_tokens_neox': 3938, 'n_words': 950}