mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Migrate github gist dialog from UIDesigner to UI.Panels
This commit is contained in:
@@ -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<String> 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<FileContent> collectContents(@NotNull Project project,
|
||||
@Nullable Editor editor,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.github.ui.GithubCreateGistPanel">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="595" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="3a02a" class="javax.swing.JLabel" binding="myFileNameLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="6b34f"/>
|
||||
<text value="Filename:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6b34f" class="javax.swing.JTextField" binding="myFileNameField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="b0e4d" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="51bc1"/>
|
||||
<text value="Description:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<scrollpane id="6c5d2" class="com.intellij.ui.components.JBScrollPane">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="150" height="50"/>
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="empty"/>
|
||||
<children>
|
||||
<component id="51bc1" class="javax.swing.JTextArea" binding="myDescriptionTextArea">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<component id="3fe2f" class="javax.swing.JCheckBox" binding="mySecretCheckBox">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Secret"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9e4f3" class="javax.swing.JCheckBox" binding="myOpenInBrowserCheckBox">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Open in browser"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="192a4">
|
||||
<constraints>
|
||||
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user