public LanguageConsoleImpl( Project project, String title, LightVirtualFile lightFile, boolean initComponents) { myProject = project; myTitle = title; myVirtualFile = lightFile; EditorFactory editorFactory = EditorFactory.getInstance(); myHistoryFile = new LightVirtualFile(getTitle() + ".history.txt", FileTypes.PLAIN_TEXT, ""); myEditorDocument = FileDocumentManager.getInstance().getDocument(lightFile); reparsePsiFile(); assert myEditorDocument != null; myConsoleEditor = (EditorEx) editorFactory.createEditor(myEditorDocument, myProject); myConsoleEditor.addFocusListener(myFocusListener); myCurrentEditor = myConsoleEditor; myHistoryViewer = (EditorEx) editorFactory.createViewer( ((EditorFactoryImpl) editorFactory).createDocument(true), myProject); myUpdateQueue = new MergingUpdateQueue("ConsoleUpdateQueue", 300, true, null); Disposer.register(this, myUpdateQueue); // action shortcuts are not yet registered ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { installEditorFactoryListener(); } }); if (initComponents) { initComponents(); } }
@Override public void dispose() { saveLocation(getBounds()); super.dispose(); Disposer.dispose(myScreen); WelcomeFrame.resetInstance(); }
private DiffPanel createPanel(final boolean horizontal) { final DiffPanel diffPanel = new DiffPanelImpl(null, myProject, false, horizontal) { @Override protected DiffPanelState createDiffPanelState(@NotNull Disposable parentDisposable) { return new FragmentedDiffPanelState(this, myProject, !horizontal, parentDisposable); } }; diffPanel.enableToolbar(false); diffPanel.removeStatusBar(); DiffPanelOptions o = ((DiffPanelEx) diffPanel).getOptions(); o.setRequestFocusOnNewContent(false); Disposer.register(this, diffPanel); return diffPanel; }
private MyFocusCommand(DialogWrapper wrapper) { myWrapper = getDialogWrapper(); setToInvalidateRequestors(false); Disposer.register( wrapper.getDisposable(), new Disposable() { @Override public void dispose() { if (!myTypeAheadDone.isProcessed()) { myTypeAheadDone.setDone(); } flushEvents(); } }); }
public FlatWelcomeFrame() { final JRootPane rootPane = getRootPane(); myScreen = new FlatWelcomeScreen(); final IdeGlassPaneImpl glassPane = new IdeGlassPaneImpl(rootPane) { @Override public void addNotify() { super.addNotify(); rootPane.remove(getProxyComponent()); //noinspection SSBasedInspection SwingUtilities.invokeLater( new Runnable() { public void run() { JBProtocolCommand.handleCurrentCommand(); } }); } }; setGlassPane(glassPane); glassPane.setVisible(false); // setUndecorated(true); setContentPane(myScreen.getWelcomePanel()); setTitle("Welcome to " + ApplicationNamesInfo.getInstance().getFullProductName()); AppUIUtil.updateWindowIcon(this); final int width = RecentProjectsManager.getInstance().getRecentProjectsActions(false).length == 0 ? 666 : 777; setSize(JBUI.size(width, 460)); setResizable(false); // int x = bounds.x + (bounds.width - getWidth()) / 2; // int y = bounds.y + (bounds.height - getHeight()) / 2; Point location = DimensionService.getInstance().getLocation(WelcomeFrame.DIMENSION_KEY, null); Rectangle screenBounds = ScreenUtil.getScreenRectangle(location != null ? location : new Point(0, 0)); setLocation( new Point( screenBounds.x + (screenBounds.width - getWidth()) / 2, screenBounds.y + (screenBounds.height - getHeight()) / 3)); // setLocation(x, y); ProjectManager.getInstance() .addProjectManagerListener( new ProjectManagerAdapter() { @Override public void projectOpened(Project project) { dispose(); } }); myBalloonLayout = new BalloonLayoutImpl(rootPane, JBUI.insets(8)); WelcomeFrame.setupCloseAction(this); MnemonicHelper.init(this); Disposer.register( ApplicationManager.getApplication(), new Disposable() { @Override public void dispose() { FlatWelcomeFrame.this.dispose(); } }); }
public void show() { // final long time = System.currentTimeMillis(); JComponent panel = createCenterPanel(); new MnemonicHelper().register(panel); boolean shouldSetWidth = DimensionService.getInstance().getSize(getDimensionServiceKey(), myProject) == null; myPopup = JBPopupFactory.getInstance() .createComponentPopupBuilder(panel, null) .setTitle(myTitle) .setResizable(true) .setModalContext(false) .setFocusable(true) .setMovable(true) .setBelongsToGlobalPopupStack(true) // .setCancelOnClickOutside(false) //for debug and snapshots .setCancelKeyEnabled(false) .setDimensionServiceKey(null, getDimensionServiceKey(), false) .setCancelCallback( new Computable<Boolean>() { @Override public Boolean compute() { DimensionService.getInstance() .setLocation( getDimensionServiceKey(), myPopup.getLocationOnScreen(), myProject); return true; } }) .createPopup(); myTree.addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { if (myPopup.isVisible()) { final PopupUpdateProcessor updateProcessor = myPopup.getUserData(PopupUpdateProcessor.class); if (updateProcessor != null) { final AbstractTreeNode node = getSelectedNode(); updateProcessor.updatePopup(node); } } } }); Disposer.register(myPopup, this); Disposer.register( myPopup, new Disposable() { @Override public void dispose() { if (!myTreeHasBuilt.isDone()) { myTreeHasBuilt.setRejected(); } } }); myTree.getEmptyText().setText("Loading..."); final Point location = DimensionService.getInstance().getLocation(getDimensionServiceKey(), myProject); if (location != null) { myPopup.showInScreenCoordinates(myEditor.getContentComponent(), location); } else { myPopup.showCenteredInCurrentWindow(myProject); } ((AbstractPopup) myPopup).setShowHints(true); if (shouldSetWidth) { myPopup.setSize(new Dimension(myPreferredWidth + 10, myPopup.getSize().height)); } IdeFocusManager.getInstance(myProject).requestFocus(myTree, true); ApplicationManager.getApplication() .executeOnPooledThread( new Runnable() { @Override public void run() { final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock(); try { myFilteringStructure.rebuild(); } finally { token.finish(); } SwingUtilities.invokeLater( new Runnable() { @Override public void run() { myAbstractTreeBuilder .queueUpdate() .doWhenDone( new Runnable() { @Override public void run() { myTreeHasBuilt.setDone(); //noinspection SSBasedInspection SwingUtilities.invokeLater( new Runnable() { @Override public void run() { selectPsiElement(myInitialPsiElement); } }); } }); } }); installUpdater(); } }); }
public FileStructurePopup( StructureViewModel structureViewModel, @Nullable Editor editor, Project project, @NotNull final Disposable auxDisposable, final boolean applySortAndFilter) { myProject = project; myEditor = editor; // Stop code analyzer to speedup EDT final DaemonCodeAnalyzer analyzer = DaemonCodeAnalyzer.getInstance(myProject); if (analyzer != null) { myDaemonUpdateEnabled = ((DaemonCodeAnalyzerImpl) analyzer).isUpdateByTimerEnabled(); analyzer.setUpdateByTimerEnabled(false); } else { myDaemonUpdateEnabled = false; } IdeFocusManager.getInstance(myProject).typeAheadUntil(myTreeHasBuilt); myBaseTreeModel = structureViewModel; Disposer.register(this, auxDisposable); if (applySortAndFilter) { myTreeActionsOwner = new TreeStructureActionsOwner(myBaseTreeModel); myTreeModel = new TreeModelWrapper(structureViewModel, myTreeActionsOwner); } else { myTreeActionsOwner = null; myTreeModel = structureViewModel; } myTreeStructure = new SmartTreeStructure(project, myTreeModel) { public void rebuildTree() { if (ApplicationManager.getApplication().isUnitTestMode() || !myPopup.isDisposed()) { super.rebuildTree(); } } public boolean isToBuildChildrenInBackground(final Object element) { return getRootElement() == element; } protected TreeElementWrapper createTree() { return new StructureViewComponent.StructureViewTreeElementWrapper( myProject, myModel.getRoot(), myModel); } @Override public String toString() { return "structure view tree structure(model=" + myTreeModel + ")"; } }; myTree = new FileStructureTree( myTreeStructure.getRootElement(), Registry.is("fast.tree.expand.in.structure.view")); myTree.setCellRenderer( new NodeRenderer() { @Override protected void doAppend( @NotNull @Nls String fragment, @NotNull SimpleTextAttributes attributes, boolean isMainText, boolean selected) { SpeedSearchUtil.appendFragmentsForSpeedSearch( myTree, fragment, attributes, selected, this); } @Override public void doAppend( @NotNull String fragment, @NotNull SimpleTextAttributes attributes, boolean selected) { SpeedSearchUtil.appendFragmentsForSpeedSearch( myTree, fragment, attributes, selected, this); } @Override public void doAppend(String fragment, boolean selected) { SpeedSearchUtil.appendFragmentsForSpeedSearch( myTree, fragment, SimpleTextAttributes.REGULAR_ATTRIBUTES, selected, this); } }); mySpeedSearch = new MyTreeSpeedSearch(); mySpeedSearch.setComparator(new SpeedSearchComparator(false, true)); final FileStructurePopupFilter filter = new FileStructurePopupFilter(); myFilteringStructure = new FilteringTreeStructure( filter, myTreeStructure, ApplicationManager.getApplication().isUnitTestMode()); myAbstractTreeBuilder = new FilteringTreeBuilder(myTree, filter, myFilteringStructure, null) { @Override public void initRootNode() {} @Override protected boolean validateNode(Object child) { return StructureViewComponent.isValid(child); } @Override public void revalidateTree() { // myTree.revalidate(); // myTree.repaint(); } @Override public boolean isToEnsureSelectionOnFocusGained() { return false; } }; myTreeExpander = new DefaultTreeExpander(myTree); // myAbstractTreeBuilder.getUi().setPassthroughMode(true); myAbstractTreeBuilder.getUi().getUpdater().setDelay(1); myInitialPsiElement = getCurrentElement(getPsiFile(myProject)); // myAbstractTreeBuilder.setCanYieldUpdate(true); Disposer.register(this, myAbstractTreeBuilder); }
public StructureViewComponent( final FileEditor editor, final StructureViewModel structureViewModel, final Project project, final boolean showRootNode) { super(true, true); myProject = project; myFileEditor = editor; myTreeModel = structureViewModel; myTreeModelWrapper = new TreeModelWrapper(myTreeModel, this); SmartTreeStructure treeStructure = new SmartTreeStructure(project, myTreeModelWrapper) { public void rebuildTree() { if (!isDisposed()) { super.rebuildTree(); } } public boolean isToBuildChildrenInBackground(final Object element) { return getRootElement() == element; } protected TreeElementWrapper createTree() { return new StructureViewTreeElementWrapper(myProject, myModel.getRoot(), myModel); } @Override public String toString() { return "structure view tree structure(model=" + myTreeModel + ")"; } }; final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode(treeStructure.getRootElement())); myTree = new Tree(model); myTree.setRootVisible(showRootNode); myTree.setShowsRootHandles(true); myAbstractTreeBuilder = new StructureTreeBuilder( project, myTree, (DefaultTreeModel) myTree.getModel(), treeStructure, myTreeModelWrapper) { @Override protected boolean validateNode(Object child) { return isValid(child); } }; Disposer.register(this, myAbstractTreeBuilder); Disposer.register( myAbstractTreeBuilder, new Disposable() { public void dispose() { storeState(); } }); setContent(ScrollPaneFactory.createScrollPane(myAbstractTreeBuilder.getTree())); myAbstractTreeBuilder.getTree().setCellRenderer(new NodeRenderer()); myAutoScrollToSourceHandler = new MyAutoScrollToSourceHandler(); myAutoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler(myProject, this); JComponent toolbarComponent = ActionManager.getInstance() .createActionToolbar(ActionPlaces.STRUCTURE_VIEW_TOOLBAR, createActionGroup(), true) .getComponent(); setToolbar(toolbarComponent); installTree(); myCopyPasteDelegator = new CopyPasteDelegator(myProject, getTree()) { @NotNull protected PsiElement[] getSelectedElements() { return getSelectedPsiElements(); } }; }
private void uninstallSynchronizer() { if (myMenuItemSynchronizer != null) { Disposer.dispose(myMenuItemSynchronizer); myMenuItemSynchronizer = null; } }
EditorTabbedContainer(final EditorWindow window, Project project, final int tabPlacement) { myWindow = window; myProject = project; final ActionManager actionManager = ActionManager.getInstance(); myTabs = new JBEditorTabs(project, actionManager, IdeFocusManager.getInstance(project), this); myTabs .setDataProvider(new MyDataProvider()) .setPopupGroup( new Getter<ActionGroup>() { public ActionGroup get() { return (ActionGroup) CustomActionsSchema.getInstance() .getCorrectedAction(IdeActions.GROUP_EDITOR_TAB_POPUP); } }, ActionPlaces.EDITOR_TAB_POPUP, false) .setNavigationActionsEnabled(false) .addTabMouseListener(new TabMouseListener()) .getPresentation() .setTabDraggingEnabled(true) .setUiDecorator( new UiDecorator() { @NotNull public UiDecoration getDecoration() { return new UiDecoration( null, new Insets( TabsUtil.TAB_VERTICAL_PADDING, 10, TabsUtil.TAB_VERTICAL_PADDING, 10)); } }) .setTabLabelActionsMouseDeadzone(TimedDeadzone.NULL) .setGhostsAlwaysVisible(true) .setTabLabelActionsAutoHide(false) .setActiveTabFillIn( EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()) .setPaintFocus(false) .getJBTabs() .addListener( new TabsListener.Adapter() { public void selectionChanged(final TabInfo oldSelection, final TabInfo newSelection) { final FileEditorManager editorManager = FileEditorManager.getInstance(myProject); final FileEditor oldEditor = oldSelection != null ? editorManager.getSelectedEditor((VirtualFile) oldSelection.getObject()) : null; if (oldEditor != null) { oldEditor.deselectNotify(); } final FileEditor newEditor = editorManager.getSelectedEditor((VirtualFile) newSelection.getObject()); if (newEditor != null) { newEditor.selectNotify(); } } }) .setAdditionalSwitchProviderWhenOriginal(new MySwitchProvider()) .setSelectionChangeHandler( new JBTabs.SelectionChangeHandler() { @Override public ActionCallback execute( TabInfo info, boolean requestFocus, final ActiveRunnable doChangeSelection) { final ActionCallback result = new ActionCallback(); CommandProcessor.getInstance() .executeCommand( myProject, new Runnable() { @Override public void run() { ((IdeDocumentHistoryImpl) IdeDocumentHistory.getInstance(myProject)) .onSelectionChanged(); result.notify(doChangeSelection.run()); } }, "EditorChange", null); return result; } }) .getPresentation() .setRequestFocusOnLastFocusedComponent(true); setTabPlacement(UISettings.getInstance().EDITOR_TAB_PLACEMENT); updateTabBorder(); ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject)) .addToolWindowManagerListener( new ToolWindowManagerAdapter() { public void stateChanged() { updateTabBorder(); } public void toolWindowRegistered(@NotNull final String id) { updateTabBorder(); } }); UISettings.getInstance() .addUISettingsListener( new UISettingsListener() { public void uiSettingsChanged(UISettings source) { updateTabBorder(); } }, this); Disposer.register(project, this); }