diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubCreateGistAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubCreateGistAction.java index a40ffdf2a810..0568914098d8 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubCreateGistAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubCreateGistAction.java @@ -38,10 +38,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.github.api.GithubApiUtil; import org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent; import org.jetbrains.plugins.github.ui.GithubCreateGistDialog; -import org.jetbrains.plugins.github.util.AuthLevel; -import org.jetbrains.plugins.github.util.GithubAuthDataHolder; -import org.jetbrains.plugins.github.util.GithubNotifications; -import org.jetbrains.plugins.github.util.GithubUtil; +import org.jetbrains.plugins.github.util.*; import java.io.IOException; import java.util.ArrayList; @@ -101,11 +98,17 @@ public class GithubCreateGistAction extends DumbAwareAction { @Nullable final VirtualFile file, @Nullable final VirtualFile[] files) { + GithubSettings settings = GithubSettings.getInstance(); // Ask for description and other params - final GithubCreateGistDialog dialog = new GithubCreateGistDialog(project, editor, files, file); + GithubCreateGistDialog dialog = new GithubCreateGistDialog(project, + getFileName(editor, files), + settings.isPrivateGist(), + settings.isOpenInBrowserGist()); if (!dialog.showAndGet()) { return; } + settings.setPrivateGist(dialog.isSecret()); + settings.setOpenInBrowserGist(dialog.isOpenInBrowser()); final Ref url = new Ref<>(); new Task.Backgroundable(project, "Creating Gist...") { @@ -134,6 +137,17 @@ public class GithubCreateGistAction extends DumbAwareAction { }.queue(); } + @Nullable + private static String getFileName(@Nullable Editor editor, @Nullable VirtualFile[] files) { + if (files != null && files.length == 1 && !files[0].isDirectory()) { + return files[0].getName(); + } + if (editor != null) { + return ""; + } + return null; + } + @NotNull static List collectContents(@NotNull Project project, @Nullable Editor editor, diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistDialog.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistDialog.java index 5d534a5f779e..e9a7c70ae639 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistDialog.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistDialog.java @@ -15,47 +15,34 @@ */ package org.jetbrains.plugins.github.ui; -import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.components.*; +import com.intellij.util.ui.JBDimension; +import com.intellij.util.ui.JBUI; +import com.intellij.util.ui.UI; +import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.components.BorderLayoutPanel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.github.util.GithubSettings; import javax.swing.*; -/** - * @author oleg - * @date 9/27/11 - */ +import static com.intellij.util.ui.UI.PanelFactory.panel; + public class GithubCreateGistDialog extends DialogWrapper { - private final GithubCreateGistPanel myGithubCreateGistPanel; + @Nullable private final JBTextField myFileNameField; + @NotNull private final JTextArea myDescriptionField; + @NotNull private final JBCheckBox mySecretCheckBox; + @NotNull private final JBCheckBox myOpenInBrowserCheckBox; - public GithubCreateGistDialog(@NotNull final Project project, @Nullable Editor editor, @Nullable VirtualFile[] files, @Nullable VirtualFile file) { + public GithubCreateGistDialog(@NotNull Project project, @Nullable String fileName, boolean secret, boolean openInBrowser) { super(project, true); - myGithubCreateGistPanel = new GithubCreateGistPanel(); - // Use saved settings for controls - final GithubSettings settings = GithubSettings.getInstance(); - myGithubCreateGistPanel.setSecret(settings.isPrivateGist()); - myGithubCreateGistPanel.setOpenInBrowser(settings.isOpenInBrowserGist()); - if (editor != null) { - if (file != null) { - myGithubCreateGistPanel.showFileNameField(file.getName()); - } - else { - myGithubCreateGistPanel.showFileNameField(""); - } - } - else if (files != null) { - if (files.length == 1 && !files[0].isDirectory()) { - myGithubCreateGistPanel.showFileNameField(files[0].getName()); - } - } - else if (file != null && !file.isDirectory()) { - myGithubCreateGistPanel.showFileNameField(file.getName()); - } + myFileNameField = fileName != null ? new JBTextField(fileName) : null; + myDescriptionField = new JTextArea(); + mySecretCheckBox = new JBCheckBox("Secret", secret); + myOpenInBrowserCheckBox = new JBCheckBox("Open in browser", openInBrowser); setTitle("Create Gist"); init(); @@ -63,7 +50,23 @@ public class GithubCreateGistDialog extends DialogWrapper { @Override protected JComponent createCenterPanel() { - return myGithubCreateGistPanel.getPanel(); + JBBox checkBoxes = JBBox.createHorizontalBox(); + checkBoxes.add(mySecretCheckBox); + checkBoxes.add(Box.createRigidArea(JBUI.size(UIUtil.DEFAULT_HGAP, 0))); + checkBoxes.add(myOpenInBrowserCheckBox); + + JBScrollPane descriptionPane = new JBScrollPane(myDescriptionField); + descriptionPane.setMinimumSize(new JBDimension(150, 50)); + descriptionPane.setPreferredSize(new JBDimension(150, 50)); + descriptionPane.setBorder(BorderFactory.createEtchedBorder()); + + BorderLayoutPanel panel = UI.Panels.simplePanel(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP) + .addToCenter(UI.Panels.simplePanel(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP) + .addToCenter(descriptionPane) + .addToTop(new JBLabel("Description:"))) + .addToBottom(checkBoxes); + if (myFileNameField != null) panel.addToTop(panel(myFileNameField).withLabel("Filename:").createPanel()); + return panel; } @Override @@ -76,35 +79,26 @@ public class GithubCreateGistDialog extends DialogWrapper { return "Github.CreateGistDialog"; } - @Override - protected void doOKAction() { - // Store settings - final GithubSettings settings = GithubSettings.getInstance(); - settings.setOpenInBrowserGist(myGithubCreateGistPanel.isOpenInBrowser()); - settings.setPrivateGist(myGithubCreateGistPanel.isSecret()); - super.doOKAction(); - } - @Override public JComponent getPreferredFocusedComponent() { - return myGithubCreateGistPanel.getDescriptionTextArea(); - } - - public boolean isSecret() { - return myGithubCreateGistPanel.isSecret(); - } - - @NotNull - public String getDescription() { - return myGithubCreateGistPanel.getDescriptionTextArea().getText(); + return myDescriptionField; } @Nullable public String getFileName() { - return myGithubCreateGistPanel.getFileNameField().getText(); + return myFileNameField != null ? myFileNameField.getText() : null; + } + + @NotNull + public String getDescription() { + return myDescriptionField.getText(); + } + + public boolean isSecret() { + return mySecretCheckBox.isSelected(); } public boolean isOpenInBrowser() { - return myGithubCreateGistPanel.isOpenInBrowser(); + return myOpenInBrowserCheckBox.isSelected(); } } diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistPanel.form b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistPanel.form deleted file mode 100644 index 505e6d5b9044..000000000000 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistPanel.form +++ /dev/null @@ -1,76 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistPanel.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistPanel.java deleted file mode 100644 index 9e506dffd22e..000000000000 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreateGistPanel.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.ui; - -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; - -/** - * @author oleg - * @date 9/27/11 - */ -public class GithubCreateGistPanel { - private JTextArea myDescriptionTextArea; - private JCheckBox mySecretCheckBox; - private JPanel myPanel; - private JCheckBox myOpenInBrowserCheckBox; - private JTextField myFileNameField; - private JLabel myFileNameLabel; - - public GithubCreateGistPanel() { - myDescriptionTextArea.setBorder(BorderFactory.createEtchedBorder()); - myFileNameLabel.setVisible(false); - myFileNameField.setVisible(false); - } - - public boolean isSecret(){ - return mySecretCheckBox.isSelected(); - } - - public boolean isOpenInBrowser(){ - return myOpenInBrowserCheckBox.isSelected(); - } - - public void setSecret(final boolean isSecret){ - mySecretCheckBox.setSelected(isSecret); - } - - public void setOpenInBrowser(final boolean openInBrowser) { - myOpenInBrowserCheckBox.setSelected(openInBrowser); - } - - public void showFileNameField(@NotNull String filename) { - myFileNameLabel.setVisible(true); - myFileNameField.setVisible(true); - myFileNameField.setText(filename); - } - - public JPanel getPanel() { - return myPanel; - } - - public JTextArea getDescriptionTextArea() { - return myDescriptionTextArea; - } - - public JTextField getFileNameField() { - return myFileNameField; - } -}