use of com.intellij.openapi.fileEditor.FileEditorManager in project android by JetBrains.
the class ConfigurationMatcher method selectConfigMatch.
@NotNull
private ConfigMatch selectConfigMatch(@NotNull List<ConfigMatch> matches) {
List<String> deviceIds = myManager.getStateManager().getProjectState().getDeviceIds();
Map<String, Integer> idRank = Maps.newHashMapWithExpectedSize(deviceIds.size());
int rank = 0;
for (String id : deviceIds) {
idRank.put(id, rank++);
}
// API 11-13: look for a x-large device
Comparator<ConfigMatch> comparator = null;
IAndroidTarget projectTarget = myManager.getProjectTarget();
if (projectTarget != null) {
int apiLevel = projectTarget.getVersion().getFeatureLevel();
if (apiLevel >= 11 && apiLevel < 14) {
// TODO: Maybe check the compatible-screen tag in the manifest to figure out
// what kind of device should be used for display.
comparator = new TabletConfigComparator(idRank);
}
}
if (comparator == null) {
// lets look for a high density device
comparator = new PhoneConfigComparator(idRank);
}
Collections.sort(matches, comparator);
// Look at the currently active editor to see if it's a layout editor, and if so,
// look up its configuration and if the configuration is in our match list,
// use it. This means we "preserve" the current configuration when you open
// new layouts.
// TODO: This is running too late for the layout preview; the new editor has
// already taken over so getSelectedTextEditor() returns self. Perhaps we
// need to fish in the open editors instead.
// We use FileEditorManagerImpl instead of FileEditorManager to get access to the lock-free version
// (also used by DebuggerContextUtil) since the normal method only works from the dispatch thread
// (grabbing a read lock is not enough).
FileEditorManager editorManager = FileEditorManager.getInstance(myManager.getProject());
if (editorManager instanceof FileEditorManagerImpl) {
// not the case under test fixtures apparently
Editor activeEditor = ((FileEditorManagerImpl) editorManager).getSelectedTextEditor(true);
if (activeEditor != null) {
FileDocumentManager documentManager = FileDocumentManager.getInstance();
VirtualFile file = documentManager.getFile(activeEditor.getDocument());
if (file != null && !file.equals(myFile) && file.getFileType() == StdFileTypes.XML && ResourceHelper.getFolderType(myFile) == ResourceHelper.getFolderType(file)) {
Configuration configuration = myManager.getConfiguration(file);
FolderConfiguration fullConfig = configuration.getFullConfig();
for (ConfigMatch match : matches) {
if (fullConfig.equals(match.testConfig)) {
return match;
}
}
}
}
}
// the list has been sorted so that the first item is the best config
return matches.get(0);
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project android by JetBrains.
the class PermissionUsageQuickFix method openFile.
public static void openFile(Project project, PsiFile file) {
String path = file.getVirtualFile().getCanonicalPath();
assert path != null;
FileEditorManager manager = FileEditorManager.getInstance(project);
VirtualFile virtFile = LocalFileSystem.getInstance().findFileByPath(path);
assert virtFile != null;
manager.openFile(virtFile, true, true);
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project android by JetBrains.
the class WorkBenchTest method before.
@Before
public void before() {
initMocks(this);
myContent = new JPanel();
myContent.setPreferredSize(new Dimension(500, 400));
mySplitter = new ThreeComponentsSplitter();
Project project = ProjectManager.getInstance().getDefaultProject();
myPropertiesComponent = PropertiesComponent.getInstance();
myWorkBenchManager = WorkBenchManager.getInstance();
myFloatingToolWindowManager = FloatingToolWindowManager.getInstance(project);
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
myModel = new SideModel<>(project);
myLeftMinimizePanel = spy(new MinimizedPanel<>(Side.RIGHT, myModel));
myLeftMinimizePanel.setLayout(new BoxLayout(myLeftMinimizePanel, BoxLayout.Y_AXIS));
myRightMinimizePanel = spy(new MinimizedPanel<>(Side.RIGHT, myModel));
myRightMinimizePanel.setLayout(new BoxLayout(myRightMinimizePanel, BoxLayout.Y_AXIS));
WorkBench.InitParams<String> initParams = new WorkBench.InitParams<>(myModel, mySplitter, myLeftMinimizePanel, myRightMinimizePanel);
myWorkBench = new WorkBench<>(project, "BENCH", myFileEditor, initParams);
JRootPane rootPane = new JRootPane();
rootPane.add(myWorkBench);
List<ToolWindowDefinition<String>> definitions = ImmutableList.of(PalettePanelToolContent.getDefinition(), PalettePanelToolContent.getOtherDefinition(), PalettePanelToolContent.getThirdDefinition());
myWorkBench.init(myContent, "CONTEXT", definitions);
myToolWindow1 = myModel.getAllTools().get(0);
myToolWindow2 = myModel.getAllTools().get(1);
myToolWindow3 = myModel.getAllTools().get(2);
when(fileEditorManager.getSelectedEditors()).thenReturn(new FileEditor[] { myFileEditor, myFileEditor2 });
verify(myWorkBenchManager).register(eq(myWorkBench));
verify(myFloatingToolWindowManager).register(eq(myFileEditor), eq(myWorkBench));
reset(myWorkBenchManager, myFloatingToolWindowManager);
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project android by JetBrains.
the class NlModel method overrideConfigurationScreenSize.
/**
* Changes the configuration to use a custom device with screen size defined by xDimension and yDimension.
*/
public void overrideConfigurationScreenSize(@AndroidCoordinate int xDimension, @AndroidCoordinate int yDimension) {
Device original = myConfiguration.getDevice();
// doesn't copy tag id
Device.Builder deviceBuilder = new Device.Builder(original);
if (original != null) {
deviceBuilder.setTagId(original.getTagId());
}
deviceBuilder.setName("Custom");
deviceBuilder.setId(Configuration.CUSTOM_DEVICE_ID);
Device device = deviceBuilder.build();
for (State state : device.getAllStates()) {
Screen screen = state.getHardware().getScreen();
screen.setXDimension(xDimension);
screen.setYDimension(yDimension);
double dpi = screen.getPixelDensity().getDpiValue();
double width = xDimension / dpi;
double height = yDimension / dpi;
double diagonalLength = Math.sqrt(width * width + height * height);
screen.setDiagonalLength(diagonalLength);
screen.setSize(AvdScreenData.getScreenSize(diagonalLength));
screen.setRatio(AvdScreenData.getScreenRatio(xDimension, yDimension));
screen.setScreenRound(device.getDefaultHardware().getScreen().getScreenRound());
screen.setChin(device.getDefaultHardware().getScreen().getChin());
}
// If a custom device already exists, remove it before adding the latest one
List<Device> devices = myConfiguration.getConfigurationManager().getDevices();
boolean customDeviceReplaced = false;
for (int i = 0; i < devices.size(); i++) {
if ("Custom".equals(devices.get(i).getId())) {
devices.set(i, device);
customDeviceReplaced = true;
break;
}
}
if (!customDeviceReplaced) {
devices.add(device);
}
VirtualFile better;
State newState;
//Change the orientation of the device depending on the shape of the canvas
if (xDimension > yDimension) {
better = ConfigurationMatcher.getBetterMatch(myConfiguration, device, "Landscape", null, null);
newState = device.getState("Landscape");
} else {
better = ConfigurationMatcher.getBetterMatch(myConfiguration, device, "Portrait", null, null);
newState = device.getState("Portrait");
}
if (better != null) {
VirtualFile old = myConfiguration.getFile();
assert old != null;
Project project = mySurface.getProject();
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, better, -1);
FileEditorManager manager = FileEditorManager.getInstance(project);
FileEditor selectedEditor = manager.getSelectedEditor(old);
manager.openEditor(descriptor, true);
// Switch to the same type of editor (XML or Layout Editor) in the target file
if (selectedEditor instanceof NlEditor) {
manager.setSelectedEditor(better, NlEditorProvider.DESIGNER_ID);
} else if (selectedEditor != null) {
manager.setSelectedEditor(better, TextEditorProvider.getInstance().getEditorTypeId());
}
AndroidFacet facet = AndroidFacet.getInstance(myConfiguration.getModule());
assert facet != null;
Configuration configuration = facet.getConfigurationManager().getConfiguration(better);
configuration.setEffectiveDevice(device, newState);
} else {
myConfiguration.setEffectiveDevice(device, newState);
}
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project android by JetBrains.
the class GenerateLayoutTestSkeletonAction method getSurface.
@Nullable
private static DesignSurface getSurface(@NotNull Project project) {
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
FileEditor[] editors = fileEditorManager.getSelectedEditors();
for (FileEditor fileEditor : editors) {
if (fileEditor instanceof NlEditor) {
return ((NlEditor) fileEditor).getComponent().getSurface();
}
}
Editor editor = fileEditorManager.getSelectedTextEditor();
if (editor == null) {
return null;
}
NlPreviewManager previewManager = NlPreviewManager.getInstance(project);
if (previewManager.isWindowVisible()) {
return previewManager.getPreviewForm().getSurface();
}
PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
if (file == null) {
return null;
}
for (FileEditor fileEditor : fileEditorManager.getEditors(file.getVirtualFile())) {
if (fileEditor instanceof NlEditor) {
return ((NlEditor) fileEditor).getComponent().getSurface();
}
}
return null;
}
Aggregations