mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't allow to remove predefined browsers
This commit is contained in:
@@ -39,6 +39,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import javax.swing.table.TableModel;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -68,7 +69,8 @@ public class TableModelEditor<T> implements ElementProducer<T> {
|
||||
}
|
||||
|
||||
table.getEmptyText().setText(emptyText);
|
||||
toolbarDecorator = ToolbarDecorator.createDecorator(table, this);
|
||||
MyRemoveAction removeAction = new MyRemoveAction();
|
||||
toolbarDecorator = ToolbarDecorator.createDecorator(table, this).setRemoveAction(removeAction).setRemoveActionUpdater(removeAction);
|
||||
|
||||
if (itemEditor instanceof DialogItemEditor) {
|
||||
toolbarDecorator.setEditAction(new AnActionButtonRunnable() {
|
||||
@@ -129,6 +131,10 @@ public class TableModelEditor<T> implements ElementProducer<T> {
|
||||
* Class must have empty constructor.
|
||||
*/
|
||||
public abstract Class<T> getItemClass();
|
||||
|
||||
public boolean isRemovable(@NotNull T item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class DialogItemEditor<T> extends ItemEditor<T> {
|
||||
@@ -331,4 +337,30 @@ public class TableModelEditor<T> implements ElementProducer<T> {
|
||||
public void reset(@NotNull List<T> items) {
|
||||
model.setItems(new ArrayList<T>(items));
|
||||
}
|
||||
|
||||
private class MyRemoveAction implements AnActionButtonRunnable, AnActionButtonUpdater, TableUtil.ItemChecker {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
if (TableUtil.doRemoveSelectedItems(table, model, this)) {
|
||||
table.requestFocus();
|
||||
TableUtil.updateScroller(table, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOperationApplyable(@NotNull TableModel ignored, int row) {
|
||||
T item = model.getItem(row);
|
||||
return item != null && itemEditor.isRemovable(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(AnActionEvent e) {
|
||||
for (T item : table.getSelectedObjects()) {
|
||||
if (itemEditor.isRemovable(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -265,6 +265,11 @@ public class BrowserSettingsPanel {
|
||||
public void applyEdited(@NotNull ConfigurableWebBrowser oldItem, @NotNull ConfigurableWebBrowser newItem) {
|
||||
oldItem.setSpecificSettings(newItem.getSpecificSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemovable(@NotNull ConfigurableWebBrowser item) {
|
||||
return !WebBrowserManager.isPredefinedBrowser(item);
|
||||
}
|
||||
};
|
||||
browsersEditor = new TableModelEditor<ConfigurableWebBrowser>(Collections.<ConfigurableWebBrowser>emptyList(), COLUMNS,
|
||||
itemEditor, "No web browsers configured"
|
||||
|
||||
@@ -64,6 +64,15 @@ public class WebBrowserManager implements PersistentStateComponent<Element>, Mod
|
||||
return ServiceManager.getService(WebBrowserManager.class);
|
||||
}
|
||||
|
||||
static boolean isPredefinedBrowser(@NotNull ConfigurableWebBrowser browser) {
|
||||
UUID id = browser.getId();
|
||||
return id.equals(DEFAULT_CHROME_ID) ||
|
||||
id.equals(DEFAULT_FIREFOX_ID) ||
|
||||
id.equals(DEFAULT_SAFARI_ID) ||
|
||||
id.equals(DEFAULT_OPERA_ID) ||
|
||||
id.equals(DEFAULT_EXPLORER_ID);
|
||||
}
|
||||
|
||||
public enum DefaultBrowser {
|
||||
SYSTEM, FIRST, ALTERNATIVE
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user