mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WI-2477: Ability to specify to a file a JavaScript library/file to autocomplete from (in progress)
This commit is contained in:
+1
-2
@@ -20,8 +20,6 @@ import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -60,6 +58,7 @@ public class ScriptingLibraryManager {
|
||||
public void commitModel() {
|
||||
if (myRootModel != null && !myRootModel.isDisposed()) {
|
||||
myRootModel.commit();
|
||||
resetModel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+33
-12
@@ -19,6 +19,8 @@ import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
@@ -33,7 +35,7 @@ public class ScriptingLibrariesPanel {
|
||||
private JPanel myScriptingLibrariesPanel;
|
||||
private JBTable myLibraryTable;
|
||||
private ScriptingLibraryTableModel myLibTableModel;
|
||||
private boolean myModified;
|
||||
private String mySelectedLibName;
|
||||
|
||||
public ScriptingLibrariesPanel(LibraryTable libTable) {
|
||||
myLibTableModel = new ScriptingLibraryTableModel(libTable);
|
||||
@@ -44,12 +46,26 @@ public class ScriptingLibrariesPanel {
|
||||
addLibrary();
|
||||
}
|
||||
});
|
||||
myRemoveLibraryButton.addActionListener(new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (mySelectedLibName != null) {
|
||||
myLibTableModel.removeLibrary(mySelectedLibName);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (libTable == null) {
|
||||
myAddLibraryButton.setEnabled(false);
|
||||
}
|
||||
myRemoveLibraryButton.setEnabled(false);
|
||||
myEditLibraryButton.setEnabled(false);
|
||||
myModified = false;
|
||||
myLibraryTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
myLibraryTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
onSelectionChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
@@ -60,24 +76,29 @@ public class ScriptingLibrariesPanel {
|
||||
EditLibraryDialog editLibDialog = new EditLibraryDialog();
|
||||
editLibDialog.show();
|
||||
if (editLibDialog.isOK()) {
|
||||
createLibrary(editLibDialog.getLibName());
|
||||
myModified = true;
|
||||
myLibTableModel.createLibrary(editLibDialog.getLibName());
|
||||
}
|
||||
}
|
||||
|
||||
private void createLibrary(String name) {
|
||||
myLibTableModel.getLibraryTable().createLibrary(name);
|
||||
myLibraryTable.repaint();
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return myModified;
|
||||
return myLibTableModel.isChanged();
|
||||
}
|
||||
|
||||
public void resetTable(LibraryTable libTable) {
|
||||
myLibTableModel.resetTable(libTable);
|
||||
myModified = false;
|
||||
myLibraryTable.repaint();
|
||||
}
|
||||
|
||||
private void onSelectionChange() {
|
||||
int selectedRow = myLibraryTable.getSelectedRow();
|
||||
if (selectedRow >= 0) {
|
||||
mySelectedLibName = myLibTableModel.getLibNameAt(selectedRow);
|
||||
myEditLibraryButton.setEnabled(true);
|
||||
myRemoveLibraryButton.setEnabled(true);
|
||||
}
|
||||
else {
|
||||
myEditLibraryButton.setEnabled(false);
|
||||
myRemoveLibraryButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+33
-6
@@ -15,11 +15,9 @@
|
||||
*/
|
||||
package com.intellij.ide.scriptingContext.ui;
|
||||
|
||||
import com.intellij.ide.scriptingContext.ScriptingLibraryManager;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
@@ -31,13 +29,17 @@ public class ScriptingLibraryTableModel extends AbstractTableModel {
|
||||
private static final int LIB_NAME_COL = 0;
|
||||
|
||||
private LibraryTable myLibTable;
|
||||
private boolean myTableChanged;
|
||||
|
||||
public ScriptingLibraryTableModel(LibraryTable libTable) {
|
||||
myLibTable = libTable;
|
||||
myTableChanged = false;
|
||||
}
|
||||
|
||||
public void resetTable(LibraryTable libTable) {
|
||||
myLibTable = libTable;
|
||||
myTableChanged = false;
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,8 +71,33 @@ public class ScriptingLibraryTableModel extends AbstractTableModel {
|
||||
return "?";
|
||||
}
|
||||
|
||||
public LibraryTable getLibraryTable() {
|
||||
return myLibTable;
|
||||
public void createLibrary(String name) {
|
||||
myLibTable.createLibrary(name);
|
||||
fireLibTableChanged();
|
||||
}
|
||||
|
||||
public void removeLibrary(String name) {
|
||||
Library libToRemove = myLibTable.getLibraryByName(name);
|
||||
if (libToRemove != null) {
|
||||
myLibTable.removeLibrary(libToRemove);
|
||||
fireLibTableChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void fireLibTableChanged() {
|
||||
myTableChanged = true;
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLibNameAt(int row) {
|
||||
Library[] libs = myLibTable.getLibraries();
|
||||
if (row < 0 || row > libs.length - 1) return null;
|
||||
return libs[row].getName();
|
||||
}
|
||||
|
||||
public boolean isChanged() {
|
||||
return myTableChanged;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user