<commit_before>/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.plugins.github;

import static org.jetbrains.plugins.github.api.GithubGist.FileContent;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.github.api.GithubApiUtil;
import org.jetbrains.plugins.github.api.GithubGist;
import org.jetbrains.plugins.github.exceptions.GithubAuthenticationCanceledException;
import org.jetbrains.plugins.github.ui.GithubCreateGistDialog;
import org.jetbrains.plugins.github.util.GithubAuthData;
import org.jetbrains.plugins.github.util.GithubNotifications;
import org.jetbrains.plugins.github.util.GithubUtil;
import org.mustbe.consulo.RequiredDispatchThread;
import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ThrowableConvertor;
import icons.GithubIcons;

/**
 * @author oleg
 * @date 9/27/11
 */
public class GithubCreateGistAction extends DumbAwareAction
{
	private static final Logger LOG = GithubUtil.LOG;
	private static final String FAILED_TO_CREATE_GIST = "Can't create Gist";

	protected GithubCreateGistAction()
	{
		super("Create Gist...", "Create GitHub Gist", GithubIcons.Github_icon);
	}

	@Override
	public void update(final AnActionEvent e)
	{
		Project project = e.getData(PlatformDataKeys.PROJECT);
		if(project == null || project.isDefault())
		{
			e.getPresentation().setVisible(false);
			e.getPresentation().setEnabled(false);
			return;
		}
		Editor editor = e.getData(PlatformDataKeys.EDITOR);
		VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
		VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);

		if((editor == null && file == null && files == null) || (editor != null && editor.getDocument().getTextLength
				() == 0))
		{
			GithubUtil.setVisibleEnabled(e, false, false);
			return;
		}
		GithubUtil.setVisibleEnabled(e, true, true);
	}

	@Override
	public void actionPerformed(final AnActionEvent e)
	{
		final Project project = e.getData(PlatformDataKeys.PROJECT);
		if(project == null || project.isDefault())
		{
			return;
		}

		final Editor editor = e.getData(PlatformDataKeys.EDITOR);
		final VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
		final VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
		if(editor == null && file == null && files == null)
		{
			return;
		}

		createGistAction(project, editor, file, files);
	}

	static void createGistAction(@NotNull final Project project,
			@Nullable final Editor editor,
			@Nullable final VirtualFile file,<commit_msg>annotations<commit_after>/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.plugins.github;

import static org.jetbrains.plugins.github.api.GithubGist.FileContent;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.github.api.GithubApiUtil;
import org.jetbrains.plugins.github.api.GithubGist;
import org.jetbrains.plugins.github.exceptions.GithubAuthenticationCanceledException;
import org.jetbrains.plugins.github.ui.GithubCreateGistDialog;
import org.jetbrains.plugins.github.util.GithubAuthData;
import org.jetbrains.plugins.github.util.GithubNotifications;
import org.jetbrains.plugins.github.util.GithubUtil;
import org.mustbe.consulo.RequiredDispatchThread;
import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ThrowableConvertor;
import icons.GithubIcons;

/**
 * @author oleg
 * @since 9/27/11
 */
public class GithubCreateGistAction extends DumbAwareAction
{
	private static final Logger LOG = GithubUtil.LOG;
	private static final String FAILED_TO_CREATE_GIST = "Can't create Gist";

	protected GithubCreateGistAction()
	{
		super("Create Gist...", "Create GitHub Gist", GithubIcons.Github_icon);
	}

	@RequiredDispatchThread
	@Override
	public void update(@NotNull final AnActionEvent e)
	{
		Project project = e.getData(PlatformDataKeys.PROJECT);
		if(project == null || project.isDefault())
		{
			e.getPresentation().setVisible(false);
			e.getPresentation().setEnabled(false);
			return;
		}
		Editor editor = e.getData(PlatformDataKeys.EDITOR);
		VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
		VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);

		if((editor == null && file == null && files == null) || (editor != null && editor.getDocument().getTextLength
				() == 0))
		{
			GithubUtil.setVisibleEnabled(e, false, false);
			return;
		}
		GithubUtil.setVisibleEnabled(e, true, true);
	}

	@RequiredDispatchThread
	@Override
	public void actionPerformed(@NotNull final AnActionEvent e)
	{
		final Project project = e.getData(PlatformDataKeys.PROJECT);
		if(project == null || project.isDefault())
		{
			return;
		}

		final Editor editor = e.getData(PlatformDataKeys.EDITOR);
		final VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
		final VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
		if(editor == null && file == null && files == null)
		{
			return;
		}

		createGistAction(project, editor, file, files);
	}

	static void createGistAction(@NotNull final Project project,
			@Nullable final Editor editor,
			@Nullable final VirtualFile file,
{'fraction_non_alphanumeric': 0.10537817166444094, 'fraction_numerical': 0.0043705232487556145, 'mean_word_length': 5.302983932670237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5136716', 'n_tokens_mistral': 2673, 'n_tokens_neox': 2528, 'n_words': 561}