<commit_before>/*******************************************************************************
 * Copyright (c) 2007, 2008 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.internal.wikitext.ui.util;

import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.text.AbstractInformationControlManager;
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.DefaultInformationControl.IInformationPresenter;
import org.eclipse.jface.text.information.IInformationProvider;
import org.eclipse.jface.text.information.IInformationProviderExtension;
import org.eclipse.jface.text.information.IInformationProviderExtension2;
import org.eclipse.jface.text.information.InformationPresenter;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner;
import org.eclipse.mylyn.wikitext.ui.viewer.HtmlTextPresenter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

/**
 * 
 * @author <NAME>
 */
public class InformationPresenterUtil {
	/**
	 * @see InformationPresenter#setSizeConstraints(int, int, boolean, boolean)
	 */
	public static class SizeConstraint {
		int horizontalWidthInChars;

		int verticalWidthInChars;

		boolean enforceAsMinimumSize;

		boolean enforceAsMaximumSize;

		/**
		 * @see InformationPresenter#setSizeConstraints(int, int, boolean, boolean)
		 */
		public SizeConstraint(int horizontalWidthInChars, int verticalWidthInChars, boolean enforceAsMinimumSize,
				boolean enforceAsMaximumSize) {
			super();
			this.horizontalWidthInChars = horizontalWidthInChars;
			this.verticalWidthInChars = verticalWidthInChars;
			this.enforceAsMinimumSize = enforceAsMinimumSize;
			this.enforceAsMaximumSize = enforceAsMaximumSize;
		}
	}

	@SuppressWarnings("deprecation")
	private static final class InformationProvider implements IInformationProvider, IInformationProviderExtension,
			IInformationProviderExtension2 {

		private final IRegion hoverRegion;

		private final Object hoverInfo;

		private final IInformationControlCreator controlCreator;

		InformationProvider(IRegion hoverRegion, Object info, IInformationControlCreator controlCreator) {
			this.hoverRegion = hoverRegion;
			this.hoverInfo = info;
			this.controlCreator = controlCreator;
		}

		public IRegion getSubject(ITextViewer textViewer, int invocationOffset) {
			return hoverRegion;
		}

		public String getInformation(ITextViewer textViewer, IRegion subject) {
			return hoverInfo.toString();
		}

		public Object getInformation2(ITextViewer textViewer, IRegion subject) {
			return hoverInfo;
		}

		public IInformationControlCreator getInformationPresenterControlCreator() {
			return controlCreator;
		}
	}

	private static final String DATA_INFORMATION_PRESENTER = InformationPresenterUtil.class.getName()
			+ "#informationPresenter"; //$NON-NLS-1$

	private static final String DATA_INFORMATION_CONTROL_CREATOR = InformationPresenterUtil.class.getName()
			+ "#informationControlCreator"; //$NON-NLS-1$

	/**
	 * Get an information presenter to present the provided HTML content. The returned presenter is ready for displaying
	 * the information, all that is left to do is call {@link InformationPresenter#showInformation()}.
	 * 
	 * @param viewer
	 *            the viewer for which the information control should be created
	 * @param constraint
	 *            the size constraint
	 * @param toolBarManager
	 *            the tool bar manager, or null if there should be none
	 * @param htmlContent
	 *            the HTML content to be displayed by the information presenter.
	 * 
	 * @return the presenter
	 */
	public static InformationPresenter getHtmlInformationPresenter(ISourceViewer viewer, SizeConstraint constraint,
			final ToolBarManager toolBarManager, String htmlContent) {
		Control control = viewer.getTextWidget();
		InformationPresenter presenter = (InformationPresenter) control.getData(DATA_INFORMATION_PRESENTER);

		int offset = 0;
<commit_msg>NEW - bug 270059: the markup cheat sheet is not always visible https://bugs.eclipse.org/bugs/show_bug.cgi?id=270059<commit_after>/*******************************************************************************
 * Copyright (c) 2007, 2008 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.internal.wikitext.ui.util;

import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.text.AbstractInformationControlManager;
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.DefaultInformationControl.IInformationPresenter;
import org.eclipse.jface.text.information.IInformationProvider;
import org.eclipse.jface.text.information.IInformationProviderExtension;
import org.eclipse.jface.text.information.IInformationProviderExtension2;
import org.eclipse.jface.text.information.InformationPresenter;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner;
import org.eclipse.mylyn.wikitext.ui.viewer.HtmlTextPresenter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

/**
 * 
 * @author <NAME>
 */
public class InformationPresenterUtil {
	/**
	 * @see InformationPresenter#setSizeConstraints(int, int, boolean, boolean)
	 */
	public static class SizeConstraint {
		int horizontalWidthInChars;

		int verticalWidthInChars;

		boolean enforceAsMinimumSize;

		boolean enforceAsMaximumSize;

		/**
		 * @see InformationPresenter#setSizeConstraints(int, int, boolean, boolean)
		 */
		public SizeConstraint(int horizontalWidthInChars, int verticalWidthInChars, boolean enforceAsMinimumSize,
				boolean enforceAsMaximumSize) {
			super();
			this.horizontalWidthInChars = horizontalWidthInChars;
			this.verticalWidthInChars = verticalWidthInChars;
			this.enforceAsMinimumSize = enforceAsMinimumSize;
			this.enforceAsMaximumSize = enforceAsMaximumSize;
		}
	}

	@SuppressWarnings("deprecation")
	private static final class InformationProvider implements IInformationProvider, IInformationProviderExtension,
			IInformationProviderExtension2 {

		private final IRegion hoverRegion;

		private final Object hoverInfo;

		private final IInformationControlCreator controlCreator;

		InformationProvider(IRegion hoverRegion, Object info, IInformationControlCreator controlCreator) {
			this.hoverRegion = hoverRegion;
			this.hoverInfo = info;
			this.controlCreator = controlCreator;
		}

		public IRegion getSubject(ITextViewer textViewer, int invocationOffset) {
			return hoverRegion;
		}

		public String getInformation(ITextViewer textViewer, IRegion subject) {
			return hoverInfo.toString();
		}

		public Object getInformation2(ITextViewer textViewer, IRegion subject) {
			return hoverInfo;
		}

		public IInformationControlCreator getInformationPresenterControlCreator() {
			return controlCreator;
		}
	}

	private static final String DATA_INFORMATION_PRESENTER = InformationPresenterUtil.class.getName()
			+ "#informationPresenter"; //$NON-NLS-1$

	private static final String DATA_INFORMATION_CONTROL_CREATOR = InformationPresenterUtil.class.getName()
			+ "#informationControlCreator"; //$NON-NLS-1$

	/**
	 * Get an information presenter to present the provided HTML content. The returned presenter is ready for displaying
	 * the information, all that is left to do is call {@link InformationPresenter#showInformation()}.
	 * 
	 * @param viewer
	 *            the viewer for which the information control should be created
	 * @param constraint
	 *            the size constraint
	 * @param toolBarManager
	 *            the tool bar manager, or null if there should be none
	 * @param htmlContent
	 *            the HTML content to be displayed by the information presenter.
	 * 
	 * @return the presenter
	 */
	public static InformationPresenter getHtmlInformationPresenter(ISourceViewer viewer, SizeConstraint constraint,
			final ToolBarManager toolBarManager, String htmlContent) {
		Control control = viewer.getTextWidget();
		InformationPresenter presenter = (InformationPresenter) control.getData(DATA_INFORMATION_PRESENTER);

		// bug 270059: ensure that the size/positioning math works by specifying the offet of the
		// current selection.
		int offset = viewer.getSelectedRange().x;

{'fraction_non_alphanumeric': 0.10904800984817399, 'fraction_numerical': 0.0054370127205580635, 'mean_word_length': 5.277527366387637, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, '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': '6278192', 'n_tokens_mistral': 2845, 'n_tokens_neox': 2538, 'n_words': 643}