use of com.intellij.uiDesigner.componentTree.ComponentPtr in project intellij-community by JetBrains.
the class SelectionState method restoreSelection.
public static void restoreSelection(final GuiEditor editor, final ComponentPtr[] ptrs) {
FormEditingUtil.clearSelection(editor.getRootContainer());
for (int i = ptrs.length - 1; i >= 0; i--) {
final ComponentPtr ptr = ptrs[i];
ptr.validate();
if (ptr.isValid()) {
ptr.getComponent().setSelected(true);
}
}
}
use of com.intellij.uiDesigner.componentTree.ComponentPtr in project intellij-community by JetBrains.
the class SelectionState method getSelection.
public static ComponentPtr[] getSelection(final GuiEditor editor) {
final ArrayList<RadComponent> selection = FormEditingUtil.getAllSelectedComponents(editor);
final ComponentPtr[] ptrs = new ComponentPtr[selection.size()];
for (int i = selection.size() - 1; i >= 0; i--) {
ptrs[i] = new ComponentPtr(editor, selection.get(i));
}
return ptrs;
}
use of com.intellij.uiDesigner.componentTree.ComponentPtr in project intellij-community by JetBrains.
the class GuiEditor method readFromFile.
/**
* Creates and sets new <code>RadRootContainer</code>
*
* @param keepSelection if true, the GUI designer tries to preserve the selection state after reload.
*/
public void readFromFile(final boolean keepSelection) {
try {
ComponentPtr[] selection = null;
Map<String, String> tabbedPaneSelectedTabs = null;
if (keepSelection) {
selection = SelectionState.getSelection(this);
tabbedPaneSelectedTabs = saveTabbedPaneSelectedTabs();
}
Locale oldLocale = null;
if (myRootContainer != null) {
oldLocale = myRootContainer.getStringDescriptorLocale();
}
final String text = myDocument.getText();
final ClassLoader classLoader = LoaderFactory.getInstance(getProject()).getLoader(myFile);
final LwRootContainer rootContainer = Utils.getRootContainer(text, new CompiledClassPropertiesProvider(classLoader));
final RadRootContainer container = XmlReader.createRoot(this, rootContainer, classLoader, oldLocale);
setRootContainer(container);
if (keepSelection) {
SelectionState.restoreSelection(this, selection);
restoreTabbedPaneSelectedTabs(tabbedPaneSelectedTabs);
}
myInvalid = false;
myCardLayout.show(myCardPanel, CARD_VALID);
refresh();
} catch (Exception exc) {
Throwable original = exc;
while (original instanceof InvocationTargetException) {
original = original.getCause();
}
showInvalidCard(original);
} catch (final LinkageError exc) {
showInvalidCard(exc);
}
}
use of com.intellij.uiDesigner.componentTree.ComponentPtr in project intellij-community by JetBrains.
the class ExpandSelectionAction method actionPerformed.
public void actionPerformed(final AnActionEvent e) {
final GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());
assert editor != null;
final SelectionState selectionState = editor.getSelectionState();
selectionState.setInsideChange(true);
ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder();
if (builder != null) {
builder.beginUpdateSelection();
}
final Stack<ComponentPtr[]> history = selectionState.getSelectionHistory();
try {
final ComponentPtr[] ptrs = history.peek();
for (int i = ptrs.length - 1; i >= 0; i--) {
// Skip invalid components
final ComponentPtr ptr = ptrs[i];
ptr.validate();
if (!ptr.isValid()) {
continue;
}
// Extend selection
final RadComponent component = ptr.getComponent();
final RadContainer parent = component.getParent();
if (parent == null) {
// skip components without parents
continue;
}
boolean shouldSelectParent = true;
for (int j = parent.getComponentCount() - 1; j >= 0; j--) {
final RadComponent sibling = parent.getComponent(j);
if (!sibling.isSelected()) {
shouldSelectParent = false;
sibling.setSelected(true);
}
}
if (shouldSelectParent) {
parent.setSelected(true);
}
}
// Store new selection
history.push(SelectionState.getSelection(editor));
} finally {
if (builder != null) {
builder.endUpdateSelection();
}
selectionState.setInsideChange(false);
}
}
Aggregations