Search in sources :

Example 76 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class DockableEditorTabbedContainer method addListener.

@Override
public void addListener(final Listener listener, Disposable parent) {
    myListeners.add(listener);
    Disposer.register(parent, new Disposable() {

        @Override
        public void dispose() {
            myListeners.remove(listener);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable)

Example 77 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class IdeFrameImpl method installDefaultProjectStatusBarWidgets.

private void installDefaultProjectStatusBarWidgets(@NotNull final Project project) {
    final StatusBar statusBar = getStatusBar();
    final PositionPanel positionPanel = new PositionPanel(project);
    statusBar.addWidget(positionPanel, "before " + IdeMessagePanel.FATAL_ERROR);
    final IdeNotificationArea notificationArea = new IdeNotificationArea();
    statusBar.addWidget(notificationArea, "before " + IdeMessagePanel.FATAL_ERROR);
    final EncodingPanel encodingPanel = new EncodingPanel(project);
    statusBar.addWidget(encodingPanel, "after Position");
    final LineSeparatorPanel lineSeparatorPanel = new LineSeparatorPanel(project);
    statusBar.addWidget(lineSeparatorPanel, "before " + encodingPanel.ID());
    final ToggleReadOnlyAttributePanel readOnlyAttributePanel = new ToggleReadOnlyAttributePanel(project);
    final InsertOverwritePanel insertOverwritePanel = new InsertOverwritePanel(project);
    statusBar.addWidget(insertOverwritePanel, "after Encoding");
    statusBar.addWidget(readOnlyAttributePanel, "after InsertOverwrite");
    Disposer.register(project, new Disposable() {

        public void dispose() {
            statusBar.removeWidget(encodingPanel.ID());
            statusBar.removeWidget(lineSeparatorPanel.ID());
            statusBar.removeWidget(positionPanel.ID());
            statusBar.removeWidget(notificationArea.ID());
            statusBar.removeWidget(readOnlyAttributePanel.ID());
            statusBar.removeWidget(insertOverwritePanel.ID());
            ((StatusBarEx) statusBar).removeCustomIndicationComponents();
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) IdeNotificationArea(com.intellij.notification.impl.IdeNotificationArea) StatusBar(com.intellij.openapi.wm.StatusBar)

Example 78 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class IdeGlassPaneImpl method addPainter.

public void addPainter(final Component component, final Painter painter, final Disposable parent) {
    getPainters().addPainter(painter, component);
    activateIfNeeded();
    Disposer.register(parent, new Disposable() {

        public void dispose() {
            SwingUtilities.invokeLater(() -> removePainter(painter));
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable)

Example 79 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class IdeGlassPaneImpl method _addListener.

private void _addListener(final EventListener listener, final Disposable parent) {
    if (!myMouseListeners.contains(listener)) {
        myMouseListeners.add(listener);
        updateSortedList();
    }
    activateIfNeeded();
    Disposer.register(parent, new Disposable() {

        public void dispose() {
            UIUtil.invokeLaterIfNeeded(() -> removeListener(listener));
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable)

Example 80 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class EncodingUtil method reloadIn.

static void reloadIn(@NotNull final VirtualFile virtualFile, @NotNull final Charset charset) {
    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    if (documentManager.getCachedDocument(virtualFile) == null) {
        // no need to reload document
        EncodingManager.getInstance().setEncoding(virtualFile, charset);
        return;
    }
    final Disposable disposable = Disposer.newDisposable();
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(disposable);
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {

        @Override
        public void beforeFileContentReload(VirtualFile file, @NotNull Document document) {
            if (!file.equals(virtualFile))
                return;
            // disconnect
            Disposer.dispose(disposable);
            EncodingManager.getInstance().setEncoding(file, charset);
            LoadTextUtil.setCharsetWasDetectedFromBytes(file, null);
        }
    });
    // if file was modified, the user will be asked here
    try {
        EncodingProjectManagerImpl.suppressReloadDuring(() -> ((VirtualFileListener) documentManager).contentsChanged(new VirtualFileEvent(null, virtualFile, virtualFile.getName(), virtualFile.getParent())));
    } finally {
        Disposer.dispose(disposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document)

Aggregations

Disposable (com.intellij.openapi.Disposable)282 NotNull (org.jetbrains.annotations.NotNull)52 Test (org.junit.Test)25 Project (com.intellij.openapi.project.Project)18 TestOnly (org.jetbrains.annotations.TestOnly)17 ArrayList (java.util.ArrayList)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 RelativePoint (com.intellij.ui.awt.RelativePoint)11 Nullable (org.jetbrains.annotations.Nullable)10 Document (com.intellij.openapi.editor.Document)9 File (java.io.File)9 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Editor (com.intellij.openapi.editor.Editor)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)6 Content (com.intellij.ui.content.Content)6 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)5 Alarm (com.intellij.util.Alarm)5 ActionEvent (java.awt.event.ActionEvent)5 ListSelectionEvent (javax.swing.event.ListSelectionEvent)5