Raw Api Doc support for jQuery (initial download implementation)

This commit is contained in:
Rustam.Vishnyakov
2011-02-07 14:56:07 +03:00
parent 2f90c39631
commit f8c6b5d241
3 changed files with 62 additions and 9 deletions
@@ -23,6 +23,8 @@ import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author Rustam Vishnyakov
*/
@@ -44,5 +46,11 @@ public abstract class LangScriptingContextProvider {
@Nullable
public abstract String getDefaultDocUrl(VirtualFile file);
@Nullable
public abstract String getOfflineDocUrl(String defaultDocUrl);
@Nullable
public abstract String downloadOfflineDoc(Project project, String offlineDocUrl, JComponent parent);
}
@@ -91,7 +91,7 @@
</hspacer>
</children>
</grid>
<grid id="2a02c" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="2a02c" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -109,7 +109,7 @@
</component>
<component id="2c3dd" class="javax.swing.JButton" binding="myRemoveDocUrlButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/IdeBundle" key="scripting.lib.docUrl.remove"/>
@@ -117,7 +117,7 @@
</component>
<scrollpane id="2e869" class="com.intellij.ui.components.JBScrollPane">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="0" column="0" row-span="4" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="400" height="-1"/>
</grid>
</constraints>
@@ -136,14 +136,22 @@
</scrollpane>
<vspacer id="6b5fa">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<hspacer id="128aa">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="31a1" class="javax.swing.JButton" binding="myDownloadButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Download"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -65,6 +65,7 @@ public class EditLibraryDialog extends DialogWrapper {
private JButton myAddDocUrlButton;
private JButton myRemoveDocUrlButton;
private JBList myDocUrlList;
private JButton myDownloadButton;
private Project myProject;
private FileTableModel myFileTableModel;
private VirtualFile mySelectedFile;
@@ -110,6 +111,7 @@ public class EditLibraryDialog extends DialogWrapper {
@Override
public void intervalAdded(ListDataEvent e) {
myRemoveDocUrlButton.setEnabled(true);
checkDownloadOfflineDocEnabled();
}
@Override
@@ -117,6 +119,7 @@ public class EditLibraryDialog extends DialogWrapper {
Object source = e.getSource();
if (source instanceof MyDocUrlListModel && ((MyDocUrlListModel)source).getDocUrls().length == 0) {
myRemoveDocUrlButton.setEnabled(false);
checkDownloadOfflineDocEnabled();
}
}
@@ -133,6 +136,14 @@ public class EditLibraryDialog extends DialogWrapper {
}
});
myDownloadButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
downloadDocumentation();
}
});
myDownloadButton.setVisible(false); //TODO<rv> Remove
myRemoveDocUrlButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -161,6 +172,28 @@ public class EditLibraryDialog extends DialogWrapper {
if (docUrls.length > 0) {
myRemoveDocUrlButton.setEnabled(true);
}
checkDownloadOfflineDocEnabled();
}
private void checkDownloadOfflineDocEnabled() {
for (String url : getDocUrls()) {
if (myProvider.getOfflineDocUrl(url) != null) {
myDownloadButton.setEnabled(true);
return;
}
}
myDownloadButton.setEnabled(false);
}
private void downloadDocumentation() {
for (String url : getDocUrls()) {
String offlineDocUrl = myProvider.getOfflineDocUrl(url);
if (offlineDocUrl != null) {
String targetFile = myProvider.downloadOfflineDoc(myProject, offlineDocUrl, getRootPane());
myDocUrlListModel.addUrl(targetFile);
return;
}
}
}
private class MyTableCellRenderer extends DefaultTableCellRenderer {
@@ -454,10 +487,13 @@ public class EditLibraryDialog extends DialogWrapper {
}
public int addUrl(String url) {
myDocUrls.add(url);
int newIndex = myDocUrls.indexOf(url);
fireIntervalAdded(this, newIndex, newIndex);
return newIndex;
if (!myDocUrls.contains(url)) {
myDocUrls.add(url);
int newIndex = myDocUrls.indexOf(url);
fireIntervalAdded(this, newIndex, newIndex);
return newIndex;
}
return myDocUrls.indexOf(url);
}
public int indexOf(String url) {
@@ -491,6 +527,7 @@ public class EditLibraryDialog extends DialogWrapper {
int index = myDocUrlListModel.addUrl(url);
myDocUrlList.ensureIndexIsVisible(index);
myDocUrlList.setSelectedIndex(index);
checkDownloadOfflineDocEnabled();
}
}