<commit_before>package org.metaborg.spoofax.eclipse.editor;

import java.util.Collection;
import java.util.Set;

import org.apache.commons.vfs2.FileObject;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import org.metaborg.core.editor.IEditor;
import org.metaborg.core.project.IProject;
import org.metaborg.spoofax.eclipse.resource.IEclipseResourceService;
import org.metaborg.spoofax.eclipse.util.EditorUtils;
import org.metaborg.spoofax.eclipse.util.Nullable;
import org.metaborg.util.iterators.Iterables2;
import org.metaborg.util.log.ILogger;
import org.metaborg.util.log.LoggerUtils;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.inject.Inject;

/**
 * Keeps track of all editors, which one is currently active, and which one was active previously.
 */
public class EditorRegistry<F>
    implements IWindowListener, IPartListener2, IEclipseEditorRegistry<F>, IEclipseEditorRegistryInternal {
    private static final ILogger logger = LoggerUtils.logger(EditorRegistry.class);

    public static final String contextId = SpoofaxEditor.id + ".context";

    private static final int OPENING_EDITORS_THRESHOLD = 3;

    private final IEclipseResourceService resourceService;

    private IContextService contextService;
    private IContextActivation contextActivation;

    private volatile Set<IEclipseEditor<F>> editors = Sets.newConcurrentHashSet();
    private volatile IEclipseEditor<F> currentActive;
    private volatile IEclipseEditor<F> previousActive;


    @Inject public EditorRegistry(IEclipseResourceService resourceService) {
        this.resourceService = resourceService;
    }


    @SuppressWarnings("cast") @Override public void register() {<commit_msg>Go for least surprise when opening multiple editors.<commit_after>package org.metaborg.spoofax.eclipse.editor;

import java.util.Collection;
import java.util.Set;

import org.apache.commons.vfs2.FileObject;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import org.metaborg.core.editor.IEditor;
import org.metaborg.core.project.IProject;
import org.metaborg.spoofax.eclipse.resource.IEclipseResourceService;
import org.metaborg.spoofax.eclipse.util.EditorUtils;
import org.metaborg.spoofax.eclipse.util.Nullable;
import org.metaborg.util.iterators.Iterables2;
import org.metaborg.util.log.ILogger;
import org.metaborg.util.log.LoggerUtils;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.inject.Inject;

/**
 * Keeps track of all editors, which one is currently active, and which one was active previously.
 */
public class EditorRegistry<F>
    implements IWindowListener, IPartListener2, IEclipseEditorRegistry<F>, IEclipseEditorRegistryInternal {
    private static final ILogger logger = LoggerUtils.logger(EditorRegistry.class);

    public static final String contextId = SpoofaxEditor.id + ".context";

    private static final int OPENING_EDITORS_THRESHOLD = 1;

    private final IEclipseResourceService resourceService;

    private IContextService contextService;
    private IContextActivation contextActivation;

    private volatile Set<IEclipseEditor<F>> editors = Sets.newConcurrentHashSet();
    private volatile IEclipseEditor<F> currentActive;
    private volatile IEclipseEditor<F> previousActive;


    @Inject public EditorRegistry(IEclipseResourceService resourceService) {
        this.resourceService = resourceService;
    }


    @SuppressWarnings("cast") @Override public void register() {
{'fraction_non_alphanumeric': 0.0903183885640026, 'fraction_numerical': 0.0021659085986571367, 'mean_word_length': 5.683068017366136, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2021256', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1343, 'n_words': 281}