Search in sources :

Example 1 with GithubCreateGistDialog

use of org.jetbrains.plugins.github.ui.GithubCreateGistDialog in project intellij-community by JetBrains.

the class GithubCreateGistAction method createGistAction.

static void createGistAction(@NotNull final Project project, @Nullable final Editor editor, @Nullable final VirtualFile file, @Nullable final VirtualFile[] files) {
    // Ask for description and other params
    final GithubCreateGistDialog dialog = new GithubCreateGistDialog(project, editor, files, file);
    if (!dialog.showAndGet()) {
        return;
    }
    final GithubAuthDataHolder authHolder = getValidAuthData(project, dialog.isAnonymous());
    if (authHolder == null) {
        return;
    }
    final Ref<String> url = new Ref<>();
    new Task.Backgroundable(project, "Creating Gist...") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            List<FileContent> contents = collectContents(project, editor, file, files);
            if (contents.isEmpty())
                return;
            String gistUrl = createGist(project, authHolder, indicator, contents, dialog.isPrivate(), dialog.getDescription(), dialog.getFileName());
            url.set(gistUrl);
        }

        @Override
        public void onSuccess() {
            if (url.isNull()) {
                return;
            }
            if (dialog.isOpenInBrowser()) {
                BrowserUtil.browse(url.get());
            } else {
                GithubNotifications.showInfoURL(project, "Gist Created Successfully", "Your gist url", url.get());
            }
        }
    }.queue();
}
Also used : Ref(com.intellij.openapi.util.Ref) Task(com.intellij.openapi.progress.Task) GithubCreateGistDialog(org.jetbrains.plugins.github.ui.GithubCreateGistDialog) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Ref (com.intellij.openapi.util.Ref)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GithubCreateGistDialog (org.jetbrains.plugins.github.ui.GithubCreateGistDialog)1