use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.
the class KeymapUtil method parseMouseShortcut.
/**
* Factory method. It parses passed string and creates <code>MouseShortcut</code>.
*
* @param keystrokeString target keystroke
* @return shortcut for the given keystroke
* @throws InvalidDataException if <code>keystrokeString</code> doesn't represent valid <code>MouseShortcut</code>.
*/
public static MouseShortcut parseMouseShortcut(String keystrokeString) throws InvalidDataException {
if (Registry.is("ide.mac.forceTouch") && keystrokeString.startsWith("Force touch")) {
return new PressureShortcut(2);
}
int button = -1;
int modifiers = 0;
int clickCount = 1;
for (StringTokenizer tokenizer = new StringTokenizer(keystrokeString); tokenizer.hasMoreTokens(); ) {
String token = tokenizer.nextToken();
if (SHIFT.equals(token)) {
modifiers |= InputEvent.SHIFT_DOWN_MASK;
} else if (CONTROL.equals(token) || CTRL.equals(token)) {
modifiers |= InputEvent.CTRL_DOWN_MASK;
} else if (META.equals(token)) {
modifiers |= InputEvent.META_DOWN_MASK;
} else if (ALT.equals(token)) {
modifiers |= InputEvent.ALT_DOWN_MASK;
} else if (ALT_GRAPH.equals(token)) {
modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
} else if (token.startsWith("button") && token.length() > 6) {
try {
button = Integer.parseInt(token.substring(6));
} catch (NumberFormatException e) {
throw new InvalidDataException("unparseable token: " + token);
}
} else if (DOUBLE_CLICK.equals(token)) {
clickCount = 2;
} else {
throw new InvalidDataException("unknown token: " + token);
}
}
return new MouseShortcut(button, modifiers, clickCount);
}
use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.
the class Converter01 method convert.
/**
* Converts keymap from version "0" (no version specified)
* to version "1".
* @param keymapElement XML element that corresponds to "keymap" tag.
*/
public static void convert(Element keymapElement) throws InvalidDataException {
if (!KEY_MAP.equals(keymapElement.getName())) {
throw new IllegalArgumentException(UNKNOWN_ELEMENT + keymapElement);
}
String version = keymapElement.getAttributeValue(VERSION);
if (version != null) {
throw new InvalidDataException(UNKNOWN_VERSION + version);
}
// Add version
keymapElement.setAttribute(VERSION, Integer.toString(1));
// disableMnemonics -> disable-mnemonics
boolean disableMnemonics = Boolean.valueOf(DISABLE_MNEMONICS).booleanValue();
keymapElement.removeAttribute(DISABLE_MNEMONICS);
keymapElement.setAttribute(DISABLE_MNEMONICS_ATTRIBUTE, Boolean.toString(disableMnemonics));
// Now we have to separate all shortcuts by action's ID and convert binding to keyboard-shortcut
String name = keymapElement.getAttributeValue(NAME_ATTRIBUTE);
if (name == null) {
throw new InvalidDataException("Attribute 'name' of <keymap> must be specified");
}
HashMap id2elements = new HashMap();
for (Iterator i = keymapElement.getChildren().iterator(); i.hasNext(); ) {
Element oldChild = (Element) i.next();
if (BINDING.equals(oldChild.getName())) {
// binding -> keyboard-shortcut
// Remove attribute "id"
String id = oldChild.getAttributeValue(ID_ATTRIBUTE);
if (id == null) {
throw new InvalidDataException("attribute 'id' must be specified");
}
// keystroke -> first-keystroke
String keystroke = oldChild.getAttributeValue(KEYSTROKE_ATTRIBUTE);
// suffix -> second-keystroke
String suffix = oldChild.getAttributeValue(SUFFIX_ATTRIBUTE);
if (keystroke != null) {
Element newChild = new Element(KEYBOARD_SHORTCUT);
newChild.setAttribute(FIRST_KEYSTROKE_ATTRIBUTE, keystroke);
if (suffix != null) {
newChild.setAttribute(SECOND_KEYSTROKE_ATTRIBUTE, suffix);
}
// Put new child into the map
ArrayList elements = (ArrayList) id2elements.get(id);
if (elements == null) {
elements = new ArrayList(2);
id2elements.put(id, elements);
}
elements.add(newChild);
} else {
id2elements.put(id, new ArrayList(0));
}
// Remove old child
i.remove();
} else if (MOUSE_SHORTCUT.equals(oldChild.getName())) {
// Remove attribute "id"
String id = oldChild.getAttributeValue(ID_ATTRIBUTE);
if (id == null) {
throw new InvalidDataException("Attribute 'id' of <mouse-shortcut> must be specified; keymap name=" + name);
}
oldChild.removeAttribute(ID_ATTRIBUTE);
// Remove old child
i.remove();
// Put new child into the map
ArrayList elements = (ArrayList) id2elements.get(id);
if (elements == null) {
elements = new ArrayList(2);
id2elements.put(id, elements);
}
elements.add(oldChild);
} else {
throw new InvalidDataException("unknown element : " + oldChild.getName());
}
}
for (Iterator i = id2elements.keySet().iterator(); i.hasNext(); ) {
String id = (String) i.next();
Element actionElement = new Element(ACTION);
actionElement.setAttribute(ID_ATTRIBUTE, id);
ArrayList elements = (ArrayList) id2elements.get(id);
for (Iterator j = elements.iterator(); j.hasNext(); ) {
Element newChild = (Element) j.next();
actionElement.addContent(newChild);
}
keymapElement.addContent(actionElement);
}
}
use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.
the class HistoryEntry method parseEntry.
@NotNull
private static EntryData parseEntry(@NotNull Project project, @NotNull Element e) throws InvalidDataException {
if (!e.getName().equals(TAG)) {
throw new IllegalArgumentException("unexpected tag: " + e);
}
String url = e.getAttributeValue(FILE_ATTR);
List<Pair<FileEditorProvider, FileEditorState>> providerStates = new ArrayList<>();
FileEditorProvider selectedProvider = null;
VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
for (Element _e : e.getChildren(PROVIDER_ELEMENT)) {
String typeId = _e.getAttributeValue(EDITOR_TYPE_ID_ATTR);
FileEditorProvider provider = FileEditorProviderManager.getInstance().getProvider(typeId);
if (provider == null) {
continue;
}
if (Boolean.valueOf(_e.getAttributeValue(SELECTED_ATTR_VALUE))) {
selectedProvider = provider;
}
Element stateElement = _e.getChild(STATE_ELEMENT);
if (stateElement == null) {
throw new InvalidDataException();
}
if (file != null) {
FileEditorState state = provider.readState(stateElement, project, file);
providerStates.add(Pair.create(provider, state));
}
}
return new EntryData(url, providerStates, selectedProvider);
}
use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.
the class EditorHistoryManager method loadState.
@Override
public void loadState(@NotNull Element element) {
// we have to delay xml processing because history entries require EditorStates to be created
// which is done via corresponding EditorProviders, those are not accessible before their
// is initComponent() called
final Element state = element.clone();
StartupManager.getInstance(myProject).runWhenProjectIsInitialized((DumbAwareRunnable) () -> {
for (Element e : state.getChildren(HistoryEntry.TAG)) {
try {
addEntry(HistoryEntry.createHeavy(myProject, e));
} catch (InvalidDataException | ProcessCanceledException e1) {
} catch (Exception anyException) {
LOG.error(anyException);
}
}
trimToSize();
});
}
use of com.intellij.openapi.util.InvalidDataException in project android by JetBrains.
the class ImportModuleTask method perform.
@Override
public Exception perform() {
final Module[] moduleWrapper = { null };
final Exception exception = ApplicationManager.getApplication().runWriteAction(new Computable<Exception>() {
@Override
public Exception compute() {
try {
moduleWrapper[0] = ModuleManager.getInstance(myProject).loadModule(myModuleFilePath);
} catch (InvalidDataException e) {
return e;
} catch (IOException e) {
return e;
} catch (JDOMException e) {
return e;
} catch (ModuleWithNameAlreadyExists e) {
return e;
}
return null;
}
});
if (exception != null) {
return exception;
}
assert moduleWrapper[0] != null;
if (AndroidFacet.getInstance(moduleWrapper[0]) == null) {
AndroidUtils.addAndroidFacetInWriteAction(moduleWrapper[0], myContentRoot, true);
}
AndroidSdkUtils.setupAndroidPlatformIfNecessary(moduleWrapper[0], false);
setDepModule(moduleWrapper[0]);
return null;
}
Aggregations