diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java index ed0dc71982b8..0e29d5520da8 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java @@ -15,7 +15,7 @@ */ package com.intellij.facet.impl.ui.libraries; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.DownloadableLibraryType; import com.intellij.framework.library.FrameworkLibraryVersion; import com.intellij.ide.ui.ListCellRendererWrapper; @@ -118,12 +118,12 @@ public class DownloadingOptionsDialog extends DialogWrapper { init(); } - private void onVersionChanged(final @Nullable List selected) { + private void onVersionChanged(final @Nullable List selected) { final FrameworkLibraryVersion version = getSelectedVersion(); if (Comparing.equal(myLastSelectedVersion, version)) return; if (version != null) { - final List downloads = version.getLibraryFiles(); + final List downloads = version.getFiles(); myFilesList.setModel(new CollectionListModel( ContainerUtil.map2Array(downloads, JCheckBox.class, new Function() { @Override @@ -169,7 +169,7 @@ public class DownloadingOptionsDialog extends DialogWrapper { private List getSelectedDownloads(FrameworkLibraryVersion version) { List selected = new ArrayList(); - List downloads = version.getLibraryFiles(); + List downloads = version.getFiles(); for (int i = 0; i < downloads.size(); i++) { if (myFilesList.isItemSelected(i)) { selected.add(downloads.get(i)); diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java index 76becb410536..c029cd626ac6 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java @@ -15,7 +15,7 @@ */ package com.intellij.facet.impl.ui.libraries; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.DownloadableLibraryType; import com.intellij.framework.library.FrameworkLibraryVersion; import com.intellij.framework.library.LibraryVersionProperties; @@ -40,19 +40,19 @@ public class LibraryDownloadSettings { private final boolean myDownloadSources; private final boolean myDownloadJavaDocs; private final LibrariesContainer.LibraryLevel myLibraryLevel; - private final List mySelectedDownloads; + private final List mySelectedDownloads; public LibraryDownloadSettings(@NotNull FrameworkLibraryVersion libraryVersion, @Nullable DownloadableLibraryType libraryType, final LibrariesContainer.LibraryLevel libraryLevel, final String downloadedLibrariesPath) { this(libraryVersion, libraryType, downloadedLibrariesPath, libraryVersion.getDefaultLibraryName(), libraryLevel, - libraryVersion.getLibraryFiles(), true, true); + libraryVersion.getFiles(), true, true); } public LibraryDownloadSettings(@NotNull FrameworkLibraryVersion libraryVersion, @Nullable DownloadableLibraryType libraryType, @NotNull String directoryForDownloadedLibrariesPath, @NotNull String libraryName, @NotNull LibrariesContainer.LibraryLevel libraryLevel, - @NotNull List selectedDownloads, + @NotNull List selectedDownloads, boolean downloadSources, boolean downloadJavaDocs) { myVersion = libraryVersion; myLibraryType = libraryType; @@ -85,7 +85,7 @@ public class LibraryDownloadSettings { return myDirectoryForDownloadedLibrariesPath; } - public List getSelectedDownloads() { + public List getSelectedDownloads() { return mySelectedDownloads; } diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java index e2489df17ff1..1fb0c6a62010 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java @@ -15,6 +15,7 @@ */ package com.intellij.facet.impl.ui.libraries; +import com.intellij.util.download.DownloadableFileSetVersions; import com.intellij.framework.library.DownloadableLibraryDescription; import com.intellij.framework.library.FrameworkLibraryVersion; import com.intellij.ide.IdeBundle; @@ -100,7 +101,7 @@ public class LibraryOptionsPanel implements Disposable { final DownloadableLibraryDescription description = libraryDescription.getDownloadableDescription(); if (description != null) { showCard("loading"); - description.fetchLibraryVersions(new DownloadableLibraryDescription.LibraryVersionsCallback() { + description.fetchVersions(new DownloadableFileSetVersions.FileSetVersionsCallback() { @Override public void onSuccess(@NotNull final List versions) { //noinspection SSBasedInspection diff --git a/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryAssistant.java b/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryService.java similarity index 70% rename from platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryAssistant.java rename to java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryService.java index d5b605e0dbb6..72fbbc61a828 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryAssistant.java +++ b/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryService.java @@ -16,6 +16,7 @@ package com.intellij.framework.library; import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; import org.jetbrains.annotations.NotNull; import java.net.URL; @@ -23,15 +24,14 @@ import java.net.URL; /** * @author nik */ -public abstract class DownloadableLibraryAssistant { - public static DownloadableLibraryAssistant getInstance() { - return ServiceManager.getService(DownloadableLibraryAssistant.class); +public abstract class DownloadableLibraryService { + public static DownloadableLibraryService getInstance() { + return ServiceManager.getService(DownloadableLibraryService.class); } - @NotNull - public abstract DownloadableFileDescription createFileDescription(@NotNull String downloadUrl, @NotNull String fileName); - @NotNull public abstract DownloadableLibraryDescription createLibraryDescription(@NotNull String groupId, @NotNull URL... localUrls); + @NotNull + public abstract CustomLibraryDescription createDescriptionForType(Class typeClass); } diff --git a/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryEditor.java b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryEditor.java index 8869844290bd..d35a9673146b 100644 --- a/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryEditor.java +++ b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryEditor.java @@ -17,10 +17,7 @@ package com.intellij.framework.library.impl; import com.intellij.facet.impl.ui.libraries.DownloadingOptionsDialog; import com.intellij.facet.impl.ui.libraries.LibraryDownloadSettings; -import com.intellij.framework.library.DownloadableLibraryDescription; -import com.intellij.framework.library.DownloadableLibraryType; -import com.intellij.framework.library.FrameworkLibraryVersion; -import com.intellij.framework.library.LibraryVersionProperties; +import com.intellij.framework.library.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent; @@ -29,6 +26,7 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorBa import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.download.DownloadableFileSetVersions; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -72,7 +70,7 @@ public class DownloadableLibraryEditor extends LibraryPropertiesEditor { private void changeVersion() { final ModalityState current = ModalityState.current(); - myDescription.fetchLibraryVersions(new DownloadableLibraryDescription.LibraryVersionsCallback() { + myDescription.fetchVersions(new DownloadableFileSetVersions.FileSetVersionsCallback() { @Override public void onSuccess(@NotNull final List versions) { ApplicationManager.getApplication().invokeLater(new Runnable() { diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryAssistantImpl.java b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java similarity index 53% rename from platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryAssistantImpl.java rename to java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java index bc3172d75b49..5f6a84ec2b9c 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryAssistantImpl.java +++ b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java @@ -15,10 +15,13 @@ */ package com.intellij.framework.library.impl; -import com.intellij.framework.library.DownloadableFileDescription; -import com.intellij.framework.library.DownloadableLibraryAssistant; import com.intellij.framework.library.DownloadableLibraryDescription; -import com.intellij.openapi.util.io.FileUtil; +import com.intellij.framework.library.DownloadableLibraryService; +import com.intellij.framework.library.DownloadableLibraryType; +import com.intellij.ide.util.frameworkSupport.CustomLibraryDescriptionImpl; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.roots.libraries.LibraryType; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; import org.jetbrains.annotations.NotNull; import java.net.URL; @@ -26,16 +29,20 @@ import java.net.URL; /** * @author nik */ -public class DownloadableLibraryAssistantImpl extends DownloadableLibraryAssistant { - @NotNull - @Override - public DownloadableFileDescription createFileDescription(@NotNull String downloadUrl, @NotNull String fileName) { - return new DownloadableFileDescriptionImpl(downloadUrl, FileUtil.getNameWithoutExtension(fileName), FileUtil.getExtension(fileName)); - } +public class DownloadableLibraryServiceImpl extends DownloadableLibraryService { + private static final Logger LOG = Logger.getInstance("#com.intellij.framework.library.impl.DownloadableLibraryServiceImpl"); @NotNull @Override public DownloadableLibraryDescription createLibraryDescription(@NotNull String groupId, @NotNull URL... localUrls) { return new LibraryVersionsFetcher(groupId, localUrls); } + + @NotNull + @Override + public CustomLibraryDescription createDescriptionForType(Class typeClass) { + final DownloadableLibraryType libraryType = LibraryType.EP_NAME.findExtension(typeClass); + LOG.assertTrue(libraryType != null, typeClass); + return new CustomLibraryDescriptionImpl(libraryType); + } } diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java index 15cb3b424ddd..edad8b510c30 100644 --- a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java @@ -17,8 +17,6 @@ package com.intellij.ide.util.frameworkSupport; import com.intellij.framework.library.DownloadableLibraryDescription; import com.intellij.framework.library.DownloadableLibraryType; -import com.intellij.framework.library.LibraryVersionProperties; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.roots.ui.configuration.libraries.LibraryFilter; import com.intellij.openapi.vfs.VirtualFile; @@ -31,7 +29,6 @@ import java.util.List; * @author nik */ public class CustomLibraryDescriptionImpl extends CustomLibraryDescriptionBase { - private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.frameworkSupport.CustomLibraryDescriptionImpl"); private final DownloadableLibraryType myLibraryType; public CustomLibraryDescriptionImpl(@NotNull DownloadableLibraryType downloadableLibraryType) { @@ -60,10 +57,4 @@ public class CustomLibraryDescriptionImpl extends CustomLibraryDescriptionBase { } }; } - - public static CustomLibraryDescriptionImpl createDescription(Class typeClass) { - final DownloadableLibraryType libraryType = LibraryType.EP_NAME.findExtension(typeClass); - LOG.assertTrue(libraryType != null, typeClass); - return new CustomLibraryDescriptionImpl(libraryType); - } } diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java index 7955603b80d2..1d3406b1cad8 100644 --- a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java @@ -18,10 +18,10 @@ package com.intellij.ide.util.frameworkSupport; import com.intellij.facet.impl.ui.libraries.RequiredLibrariesInfo; import com.intellij.facet.ui.libraries.LibraryDownloadInfo; import com.intellij.facet.ui.libraries.LibraryInfo; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.DownloadableLibraryDescription; import com.intellij.framework.library.FrameworkLibraryVersion; -import com.intellij.framework.library.impl.DownloadableFileDescriptionImpl; +import com.intellij.util.download.impl.DownloadableFileDescriptionImpl; import com.intellij.framework.library.impl.DownloadableLibraryDescriptionImpl; import com.intellij.framework.library.impl.FrameworkLibraryVersionImpl; import com.intellij.openapi.roots.libraries.LibraryType; @@ -54,7 +54,8 @@ public class OldCustomLibraryDescription extends CustomLibraryDescriptionBase { for (LibraryInfo info : version.getLibraries()) { final LibraryDownloadInfo downloadingInfo = info.getDownloadingInfo(); if (downloadingInfo != null) { - final DownloadableFileDescription element = new DownloadableFileDescriptionImpl(downloadingInfo.getDownloadUrl(), downloadingInfo.getFileNamePrefix(), downloadingInfo.getFileNameSuffix()); + final DownloadableFileDescription + element = new DownloadableFileDescriptionImpl(downloadingInfo.getDownloadUrl(), downloadingInfo.getFileNamePrefix(), downloadingInfo.getFileNameSuffix()); downloads.add(element); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java index 9ac2bb007aa4..50b3bcbc54de 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java @@ -338,7 +338,7 @@ public class JavaCompletionContributor extends CompletionContributor { } private static boolean shouldRunClassNameCompletion(CompletionResultSet result, CompletionParameters parameters) { - if (!Registry.is("show.all.classes.on.first.completion") && parameters.getInvocationCount() < 2) { + if (!mayShowAllClasses(parameters)) { return false; } @@ -371,6 +371,10 @@ public class JavaCompletionContributor extends CompletionContributor { return mayStartClassName(result, parameters.isRelaxedMatching()); } + public static boolean mayShowAllClasses(CompletionParameters parameters) { + return Registry.is("show.all.classes.on.first.completion") || parameters.getInvocationCount() >= 2; + } + public static boolean mayStartClassName(CompletionResultSet result, final boolean relaxedMatching) { String prefix = result.getPrefixMatcher().getPrefix(); if (StringUtil.isEmpty(prefix)) { diff --git a/java/openapi/src/com/intellij/codeInsight/AttachSourcesProvider.java b/java/openapi/src/com/intellij/codeInsight/AttachSourcesProvider.java index f0651c6d88e1..7604b2ec4410 100644 --- a/java/openapi/src/com/intellij/codeInsight/AttachSourcesProvider.java +++ b/java/openapi/src/com/intellij/codeInsight/AttachSourcesProvider.java @@ -18,11 +18,13 @@ package com.intellij.codeInsight; import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.util.ActionCallback; import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.List; public interface AttachSourcesProvider { + @NotNull Collection getActions(List orderEntries, PsiFile psiFile); interface AttachSourcesAction { diff --git a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy index 4a392cd22b92..802c1dcb630c 100644 --- a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy +++ b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy @@ -27,6 +27,7 @@ import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import com.intellij.util.ui.UIUtil import java.util.concurrent.atomic.AtomicBoolean +import com.intellij.openapi.application.ApplicationManager /** * @author peter @@ -63,7 +64,7 @@ abstract class CompletionAutoPopupTestCase extends LightCodeInsightFixtureTestCa } protected void joinCompletion() { - joinCommit() + joinCommit() // file copy commit in background def controller = AutoPopupController.getInstance(getProject()) controller.executePendingRequests(); @@ -95,15 +96,10 @@ abstract class CompletionAutoPopupTestCase extends LightCodeInsightFixtureTestCa private def joinCommit() { final AtomicBoolean committed = new AtomicBoolean() - Runnable runnable = new Runnable() { - @Override - public void run() { - committed.set(true); - } - } edt { - PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject()); - manager.cancelAndRunWhenAllCommitted("wait for all comm", runnable); + PsiDocumentManager.getInstance(project).cancelAndRunWhenAllCommitted("wait for all comm") { + ApplicationManager.application.invokeLater { committed.set(true) } + } } while (!committed.get()) { UIUtil.pump(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 94525beb9d1b..29e09240eb0b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -27,7 +27,9 @@ import com.intellij.ide.DataManager; import com.intellij.injected.editor.EditorWindow; import com.intellij.lang.Language; import com.intellij.lang.injection.InjectedLanguageManager; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -220,7 +222,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { CommandProcessor.getInstance().executeCommand(project, initCmd, null, null); } - doComplete(time, initializationContext[0], hasModifiers); + insertDummyIdentifier(initializationContext[0], hasModifiers, time); } @NotNull @@ -245,11 +247,15 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { return lookup; } - private void doComplete(final int invocationCount, CompletionInitializationContext initContext, boolean hasModifiers) { + private void doComplete(CompletionInitializationContext initContext, + boolean hasModifiers, + int invocationCount, + PsiFile hostFile, + int hostStartOffset, Editor hostEditor, OffsetMap hostMap) { + CompletionContext context = createCompletionContext(hostFile, hostStartOffset, hostEditor, hostMap); + CompletionParameters parameters = createCompletionParameters(invocationCount, initContext, context); + final Editor editor = initContext.getEditor(); - - final CompletionParameters parameters = createCompletionParameters(invocationCount, initContext); - final Semaphore freezeSemaphore = new Semaphore(); freezeSemaphore.down(); final CompletionProgressIndicator indicator = new CompletionProgressIndicator(editor, parameters, this, freezeSemaphore, @@ -331,21 +337,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { return data; } - - private CompletionParameters createCompletionParameters(int invocationCount, final CompletionInitializationContext initContext) { - final Ref ref = Ref.create(null); - CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() { - @Override - public void run() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - ref.set(insertDummyIdentifier(initContext)); - } - }); - } - }); - final CompletionContext newContext = ref.get(); + private CompletionParameters createCompletionParameters(int invocationCount, + CompletionInitializationContext initContext, + final CompletionContext newContext) { final int offset = newContext.getStartOffset(); final PsiFile fileCopy = newContext.file; @@ -459,12 +453,21 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { } } - private CompletionContext insertDummyIdentifier(CompletionInitializationContext initContext) { + private void insertDummyIdentifier(final CompletionInitializationContext initContext, + final boolean hasModifiers, + final int invocationCount) { final PsiFile originalFile = initContext.getFile(); - PsiFile fileCopy = createFileCopy(originalFile); - PsiFile hostFile = InjectedLanguageUtil.getTopLevelFile(fileCopy); + final PsiFile fileCopy; + AccessToken token = WriteAction.start(); + try { + fileCopy = createFileCopy(originalFile); + } + finally { + token.finish(); + } + final PsiFile hostFile = InjectedLanguageUtil.getTopLevelFile(fileCopy); final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(hostFile.getProject()); - int hostStartOffset = injectedLanguageManager.injectedToHost(fileCopy, initContext.getStartOffset()); + final int hostStartOffset = injectedLanguageManager.injectedToHost(fileCopy, initContext.getStartOffset()); final Editor hostEditor = InjectedLanguageUtil.getTopLevelEditor(initContext.getEditor()); final OffsetMap hostMap = new OffsetMap(hostEditor.getDocument()); @@ -473,15 +476,54 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { hostMap.addOffset(key, injectedLanguageManager.injectedToHost(fileCopy, original.getOffset(key))); } - Document document = fileCopy.getViewProvider().getDocument(); + final Document document = fileCopy.getViewProvider().getDocument(); assert document != null : "no document"; - patchFileCopy(initContext, fileCopy, document); + + CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() { + @Override + public void run() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + patchFileCopy(initContext, fileCopy, document); + } + }); + } + }); final Document hostDocument = hostFile.getViewProvider().getDocument(); assert hostDocument != null : "no host document"; - PsiDocumentManager.getInstance(hostFile.getProject()).commitDocument(hostDocument); + + final Project project = hostFile.getProject(); + + if (autopopup) { + final CompletionPhase.AutoPopupAlarm phase = new CompletionPhase.AutoPopupAlarm(false); + CompletionServiceImpl.setCompletionPhase(phase); + + CompletionAutoPopupHandler.runLaterWithCommitted(project, hostDocument, new Runnable() { + @Override + public void run() { + if (phase != CompletionServiceImpl.getCompletionPhase()) return; + if (hostEditor.isDisposed()) return; + if (DumbService.getInstance(project).isDumb()) return; + + doComplete(initContext, hasModifiers, invocationCount, hostFile, hostStartOffset, hostEditor, hostMap); + } + }); + } else { + PsiDocumentManager.getInstance(hostFile.getProject()).commitDocument(hostDocument); + + doComplete(initContext, hasModifiers, invocationCount, hostFile, hostStartOffset, hostEditor, hostMap); + } + } + + private static CompletionContext createCompletionContext(PsiFile hostFile, + int hostStartOffset, + Editor hostEditor, + OffsetMap hostMap) { assert hostFile.isValid() : "file became invalid"; assert hostMap.getOffset(CompletionInitializationContext.START_OFFSET) < hostFile.getTextLength() : "startOffset outside the host file"; + InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(hostFile.getProject()); CompletionContext context; PsiFile injected = InjectedLanguageUtil.findInjectedPsiNoCommit(hostFile, hostStartOffset); if (injected != null) { @@ -494,10 +536,10 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { for (final OffsetKey key : new ArrayList(hostMap.keySet())) { map.addOffset(key, injectedEditor.logicalPositionToOffset(injectedEditor.hostToInjected(hostEditor.offsetToLogicalPosition(hostMap.getOffset(key))))); } - context = new CompletionContext(initContext.getProject(), injectedEditor, injected, map); + context = new CompletionContext(hostFile.getProject(), injectedEditor, injected, map); assert hostStartOffset == injectedLanguageManager.injectedToHost(injected, context.getStartOffset()) : "inconsistent injected offset translation"; } else { - context = new CompletionContext(initContext.getProject(), hostEditor, hostFile, hostMap); + context = new CompletionContext(hostFile.getProject(), hostEditor, hostFile, hostMap); } assert context.getStartOffset() < context.file.getTextLength() : "start outside the file"; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPhase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPhase.java index 6d59cad19edc..2494662deeee 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPhase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPhase.java @@ -50,7 +50,7 @@ public abstract class CompletionPhase implements Disposable { public final CompletionProgressIndicator indicator; - protected CompletionPhase(CompletionProgressIndicator indicator) { + protected CompletionPhase(@Nullable CompletionProgressIndicator indicator) { this.indicator = indicator; } @@ -65,8 +65,11 @@ public abstract class CompletionPhase implements Disposable { } public static class AutoPopupAlarm extends CompletionPhase { - public AutoPopupAlarm() { + final boolean copyCommit; + + public AutoPopupAlarm(boolean copyCommit) { super(null); + this.copyCommit = copyCommit; } @Override @@ -74,6 +77,11 @@ public abstract class CompletionPhase implements Disposable { CompletionServiceImpl.setCompletionPhase(NoCompletion); return time; } + + @Override + public String toString() { + return "AutoPopupAlarm{copyCommit=" + copyCommit + '}'; + } } public static class Synchronous extends CompletionPhase { public Synchronous(CompletionProgressIndicator indicator) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CompletionAutoPopupHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CompletionAutoPopupHandler.java index f1e32577e9e2..d66867da92c1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CompletionAutoPopupHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CompletionAutoPopupHandler.java @@ -91,7 +91,7 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate { public static void scheduleAutoPopup(final Project project, final Editor editor, final PsiFile file) { final boolean isMainEditor = FileEditorManager.getInstance(project).getSelectedTextEditor() == editor; - final CompletionPhase.AutoPopupAlarm phase = new CompletionPhase.AutoPopupAlarm(); + final CompletionPhase.AutoPopupAlarm phase = new CompletionPhase.AutoPopupAlarm(false); CompletionServiceImpl.setCompletionPhase(phase); final Runnable request = new Runnable() { diff --git a/platform/lang-impl/src/com/intellij/facet/impl/ui/libraries/LibraryDownloader.java b/platform/lang-impl/src/com/intellij/facet/impl/ui/libraries/LibraryDownloader.java index bbcc872a5870..942e37dd99aa 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/ui/libraries/LibraryDownloader.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/ui/libraries/LibraryDownloader.java @@ -16,7 +16,7 @@ package com.intellij.facet.impl.ui.libraries; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.ide.IdeBundle; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.Result; diff --git a/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryDescription.java b/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryDescription.java index 48068b1a15a2..e1ac7d3836db 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryDescription.java +++ b/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryDescription.java @@ -15,21 +15,10 @@ */ package com.intellij.framework.library; -import org.jetbrains.annotations.NotNull; - -import java.util.List; +import com.intellij.util.download.DownloadableFileSetVersions; /** * @author nik */ -public interface DownloadableLibraryDescription { - - void fetchLibraryVersions(@NotNull LibraryVersionsCallback callback); - - abstract class LibraryVersionsCallback { - public abstract void onSuccess(@NotNull List versions); - - public void onError(@NotNull String errorMessage) { - } - } +public interface DownloadableLibraryDescription extends DownloadableFileSetVersions { } diff --git a/platform/lang-impl/src/com/intellij/framework/library/FrameworkLibraryVersion.java b/platform/lang-impl/src/com/intellij/framework/library/FrameworkLibraryVersion.java index 17f7e891b91b..a336013b9a14 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/FrameworkLibraryVersion.java +++ b/platform/lang-impl/src/com/intellij/framework/library/FrameworkLibraryVersion.java @@ -16,22 +16,15 @@ package com.intellij.framework.library; import com.intellij.ide.util.frameworkSupport.FrameworkVersion; +import com.intellij.util.download.DownloadableFileSetDescription; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * @author nik */ -public interface FrameworkLibraryVersion { +public interface FrameworkLibraryVersion extends DownloadableFileSetDescription { @NotNull String getDefaultLibraryName(); - @NotNull - String getVersionString(); - - @NotNull - List getLibraryFiles(); - boolean isCompatibleWith(@NotNull FrameworkVersion frameworkVersion); } diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryDescriptionImpl.java b/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryDescriptionImpl.java index 5941809ddecc..ece1286b00b1 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryDescriptionImpl.java +++ b/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryDescriptionImpl.java @@ -36,7 +36,7 @@ public class DownloadableLibraryDescriptionImpl implements DownloadableLibraryDe } @Override - public void fetchLibraryVersions(@NotNull LibraryVersionsCallback callback) { + public void fetchVersions(@NotNull FileSetVersionsCallback callback) { callback.onSuccess(myVersions); } } diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/FrameworkLibraryVersionImpl.java b/platform/lang-impl/src/com/intellij/framework/library/impl/FrameworkLibraryVersionImpl.java index eff46bfde09b..171f1581e60f 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/FrameworkLibraryVersionImpl.java +++ b/platform/lang-impl/src/com/intellij/framework/library/impl/FrameworkLibraryVersionImpl.java @@ -15,9 +15,10 @@ */ package com.intellij.framework.library.impl; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.FrameworkLibraryVersion; import com.intellij.ide.util.frameworkSupport.FrameworkVersion; +import com.intellij.util.download.impl.DownloadableFileSetDescriptionImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,9 +27,7 @@ import java.util.List; /** * @author nik */ -public class FrameworkLibraryVersionImpl implements FrameworkLibraryVersion { - private final List myLibraryFiles; - private final String myVersionString; +public class FrameworkLibraryVersionImpl extends DownloadableFileSetDescriptionImpl implements FrameworkLibraryVersion { private final String myLibraryCategory; private final FrameworkVersion myFrameworkVersion; @@ -36,30 +35,17 @@ public class FrameworkLibraryVersionImpl implements FrameworkLibraryVersion { List libraryFiles, String category, @Nullable FrameworkVersion frameworkVersion) { - myVersionString = versionString; - myLibraryFiles = libraryFiles; + super(category, versionString, libraryFiles); myLibraryCategory = category; myFrameworkVersion = frameworkVersion; } - @NotNull - @Override - public String getVersionString() { - return myVersionString; - } - @NotNull @Override public String getDefaultLibraryName() { return myVersionString.length() > 0 ? myLibraryCategory + "-" + myVersionString : myLibraryCategory; } - @NotNull - @Override - public List getLibraryFiles() { - return myLibraryFiles; - } - @Override public boolean isCompatibleWith(@NotNull FrameworkVersion frameworkVersion) { return myFrameworkVersion == null || myFrameworkVersion.getVersionName().equals(frameworkVersion.getVersionName()); diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/LibraryVersionsFetcher.java b/platform/lang-impl/src/com/intellij/framework/library/impl/LibraryVersionsFetcher.java index 37f3915e3af3..9383d66d6306 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/LibraryVersionsFetcher.java +++ b/platform/lang-impl/src/com/intellij/framework/library/impl/LibraryVersionsFetcher.java @@ -15,64 +15,27 @@ */ package com.intellij.framework.library.impl; -import com.intellij.facet.frameworks.LibrariesDownloadAssistant; import com.intellij.facet.frameworks.beans.Artifact; -import com.intellij.facet.frameworks.beans.ArtifactItem; -import com.intellij.framework.library.DownloadableFileDescription; -import com.intellij.framework.library.DownloadableLibraryAssistant; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.DownloadableLibraryDescription; import com.intellij.framework.library.FrameworkLibraryVersion; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.download.impl.FileSetVersionsFetcherBase; import org.jetbrains.annotations.NotNull; import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; /** * @author nik */ -public class LibraryVersionsFetcher implements DownloadableLibraryDescription { - private static final Comparator VERSIONS_COMPARATOR = new Comparator() { - @Override - public int compare(FrameworkLibraryVersion o1, FrameworkLibraryVersion o2) { - return -StringUtil.compareVersionNumbers(o1.getVersionString(), o2.getVersionString()); - } - }; - private final String myGroupId; - private final URL[] myLocalUrls; +public class LibraryVersionsFetcher extends FileSetVersionsFetcherBase implements DownloadableLibraryDescription { public LibraryVersionsFetcher(@NotNull String groupId, @NotNull URL[] localUrls) { - myGroupId = groupId; - myLocalUrls = localUrls; + super(groupId, localUrls); } @Override - public void fetchLibraryVersions(@NotNull final LibraryVersionsCallback callback) { - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - @Override - public void run() { - final Artifact[] versions = LibrariesDownloadAssistant.getVersions(myGroupId, myLocalUrls); - final List result = new ArrayList(); - for (Artifact version : versions) { - final ArtifactItem[] items = version.getItems(); - final List files = new ArrayList(); - for (ArtifactItem item : items) { - String url = item.getUrl(); - final String prefix = version.getUrlPrefix(); - if (!url.startsWith("http://") && prefix != null) { - url = prefix + url; - } - files.add(DownloadableLibraryAssistant.getInstance().createFileDescription(url, item.getName())); - } - result.add(new FrameworkLibraryVersionImpl(version.getVersion(), files, myGroupId, null)); - } - Collections.sort(result, VERSIONS_COMPARATOR); - callback.onSuccess(result); - } - }); + protected FrameworkLibraryVersion createVersion(Artifact version, List files) { + return new FrameworkLibraryVersionImpl(version.getVersion(), files, myGroupId, null); } } diff --git a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ANSIColoredConsoleColorsPage.java b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ANSIColoredConsoleColorsPage.java index 5a4dec3eda31..d551c7a4773d 100644 --- a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ANSIColoredConsoleColorsPage.java +++ b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ANSIColoredConsoleColorsPage.java @@ -27,7 +27,9 @@ public class ANSIColoredConsoleColorsPage implements ColorSettingsPage { "- C:>\n" + "- help\n" + "Bad command or file name\n" + - "Log warning\n" + + "\n" + + "Log error\n" + + "Log warning\n" + "\n" + "# Process output highlighted using ANSI colors codes\n" + "ANSI: red\n" + @@ -42,10 +44,13 @@ public class ANSIColoredConsoleColorsPage implements ColorSettingsPage { private static final AttributesDescriptor[] ATTRS = new AttributesDescriptor[]{ new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.stdout"), ConsoleViewContentType.NORMAL_OUTPUT_KEY), - new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.warning"), ConsoleViewContentType.WARNING_OUTPUT_KEY), + new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.stderr"), ConsoleViewContentType.ERROR_OUTPUT_KEY), new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.stdin"), ConsoleViewContentType.USER_INPUT_KEY), new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.system.output"), ConsoleViewContentType.SYSTEM_OUTPUT_KEY), + new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.logError"), ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY), + new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.warning"), ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY), + new AttributesDescriptor(OptionsBundle.message("color.settings.console.red"), ConsoleHighlighter.RED), new AttributesDescriptor(OptionsBundle.message("color.settings.console.green"), ConsoleHighlighter.GREEN), new AttributesDescriptor(OptionsBundle.message("color.settings.console.yellow"), ConsoleHighlighter.YELLOW), @@ -61,7 +66,8 @@ public class ANSIColoredConsoleColorsPage implements ColorSettingsPage { ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("stdout", ConsoleViewContentType.NORMAL_OUTPUT_KEY); ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("stdin", ConsoleViewContentType.USER_INPUT_KEY); ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("stderr", ConsoleViewContentType.ERROR_OUTPUT_KEY); - ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("warning", ConsoleViewContentType.WARNING_OUTPUT_KEY); + ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("logError", ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY); + ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("logWarning", ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY); ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("red", ConsoleHighlighter.RED); ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("green", ConsoleHighlighter.GREEN); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/DocumentCommitThread.java b/platform/lang-impl/src/com/intellij/psi/impl/DocumentCommitThread.java index dc69c783ba17..77e56bbaa35e 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/DocumentCommitThread.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/DocumentCommitThread.java @@ -127,7 +127,7 @@ public class DocumentCommitThread implements Runnable, Disposable { assert !isDisposed; assert project.isInitialized(); PsiFile psiFile = PsiDocumentManager.getInstance(project).getCachedPsiFile(document); - if (psiFile == null || !psiFile.isPhysical()) return false; + if (psiFile == null) return false; doQueue(document, project, getCommitStage(document), reason); return true; diff --git a/platform/lang-impl/src/com/intellij/framework/library/DownloadableFileDescription.java b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileDescription.java similarity index 96% rename from platform/lang-impl/src/com/intellij/framework/library/DownloadableFileDescription.java rename to platform/lang-impl/src/com/intellij/util/download/DownloadableFileDescription.java index 6b7e25d1cc98..9276de81f94c 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/DownloadableFileDescription.java +++ b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileDescription.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.framework.library; +package com.intellij.util.download; import com.intellij.openapi.util.Condition; import org.jetbrains.annotations.NotNull; diff --git a/platform/lang-impl/src/com/intellij/util/download/DownloadableFileService.java b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileService.java new file mode 100644 index 000000000000..aa2aba45a14a --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileService.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download; + +import com.intellij.openapi.components.ServiceManager; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.net.URL; + +/** + * @author nik + */ +public abstract class DownloadableFileService { + public static DownloadableFileService getInstance() { + return ServiceManager.getService(DownloadableFileService.class); + } + + @NotNull + public abstract DownloadableFileDescription createFileDescription(@NotNull String downloadUrl, @NotNull String fileName); + + @NotNull + public abstract DownloadableFileSetVersions createFileSetVersions(@NotNull String groupId, @NotNull URL... localUrls); + + public abstract void loadVersionsToCombobox(@NotNull DownloadableFileSetVersions versions, @NotNull JComboBox comboBox); +} diff --git a/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetDescription.java b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetDescription.java new file mode 100644 index 000000000000..0940a2460650 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetDescription.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author nik + */ +public interface DownloadableFileSetDescription { + @NotNull + String getName(); + + @NotNull + String getVersionString(); + + @NotNull + List getFiles(); +} diff --git a/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetVersions.java b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetVersions.java new file mode 100644 index 000000000000..7cfda318183d --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetVersions.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author nik + */ +public interface DownloadableFileSetVersions { + void fetchVersions(@NotNull FileSetVersionsCallback callback); + + abstract class FileSetVersionsCallback { + public abstract void onSuccess(@NotNull List versions); + + public void onError(@NotNull String errorMessage) { + } + } +} diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableFileDescriptionImpl.java b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileDescriptionImpl.java similarity index 95% rename from platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableFileDescriptionImpl.java rename to platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileDescriptionImpl.java index 97745cf459b2..fe49aa7e249c 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableFileDescriptionImpl.java +++ b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileDescriptionImpl.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.framework.library.impl; +package com.intellij.util.download.impl; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Conditions; import com.intellij.util.text.UniqueNameGenerator; diff --git a/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileServiceImpl.java b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileServiceImpl.java new file mode 100644 index 000000000000..ce496eca5a83 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileServiceImpl.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download.impl; + +import com.intellij.facet.frameworks.beans.Artifact; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.download.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileService; +import com.intellij.util.download.DownloadableFileSetDescription; +import com.intellij.util.download.DownloadableFileSetVersions; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.net.URL; +import java.util.List; + +/** + * @author nik + */ +public class DownloadableFileServiceImpl extends DownloadableFileService { + @NotNull + @Override + public DownloadableFileDescription createFileDescription(@NotNull String downloadUrl, @NotNull String fileName) { + return new DownloadableFileDescriptionImpl(downloadUrl, FileUtil.getNameWithoutExtension(fileName), FileUtil.getExtension(fileName)); + } + + @NotNull + @Override + public DownloadableFileSetVersions createFileSetVersions(@NotNull String groupId, + @NotNull URL... localUrls) { + return new FileSetVersionsFetcherBase(groupId, localUrls) { + @Override + protected DownloadableFileSetDescription createVersion(Artifact version, List files) { + return new DownloadableFileSetDescriptionImpl(version.getName(), version.getVersion(), files); + } + }; + } + + @Override + public void loadVersionsToCombobox(@NotNull DownloadableFileSetVersions versions, @NotNull JComboBox comboBox) { + } +} diff --git a/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileSetDescriptionImpl.java b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileSetDescriptionImpl.java new file mode 100644 index 000000000000..f9ebccbfcef6 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileSetDescriptionImpl.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download.impl; + +import com.intellij.util.download.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileSetDescription; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author nik + */ +public class DownloadableFileSetDescriptionImpl implements DownloadableFileSetDescription { + protected final List myFiles; + protected final String myVersionString; + private final String myName; + + public DownloadableFileSetDescriptionImpl(@NotNull String name, + @NotNull String versionString, + @NotNull List files) { + myName = name; + myVersionString = versionString; + myFiles = files; + } + + @NotNull + @Override + public String getName() { + return myName; + } + + @NotNull + @Override + public String getVersionString() { + return myVersionString; + } + + @NotNull + @Override + public List getFiles() { + return myFiles; + } +} diff --git a/platform/lang-impl/src/com/intellij/util/download/impl/FileSetVersionsFetcherBase.java b/platform/lang-impl/src/com/intellij/util/download/impl/FileSetVersionsFetcherBase.java new file mode 100644 index 000000000000..6001a7b54cef --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/impl/FileSetVersionsFetcherBase.java @@ -0,0 +1,80 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download.impl; + +import com.intellij.facet.frameworks.LibrariesDownloadAssistant; +import com.intellij.facet.frameworks.beans.Artifact; +import com.intellij.facet.frameworks.beans.ArtifactItem; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.download.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileService; +import com.intellij.util.download.DownloadableFileSetDescription; +import com.intellij.util.download.DownloadableFileSetVersions; +import org.jetbrains.annotations.NotNull; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +/** + * @author nik + */ +public abstract class FileSetVersionsFetcherBase implements DownloadableFileSetVersions { + private static final Comparator VERSIONS_COMPARATOR = new Comparator() { + @Override + public int compare(DownloadableFileSetDescription o1, DownloadableFileSetDescription o2) { + return -StringUtil.compareVersionNumbers(o1.getVersionString(), o2.getVersionString()); + } + }; + protected final String myGroupId; + private final URL[] myLocalUrls; + + public FileSetVersionsFetcherBase(@NotNull String groupId, @NotNull URL[] localUrls) { + myLocalUrls = localUrls; + myGroupId = groupId; + } + + @Override + public void fetchVersions(@NotNull final FileSetVersionsCallback callback) { + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + @Override + public void run() { + final Artifact[] versions = LibrariesDownloadAssistant.getVersions(myGroupId, myLocalUrls); + final List result = new ArrayList(); + for (Artifact version : versions) { + final ArtifactItem[] items = version.getItems(); + final List files = new ArrayList(); + for (ArtifactItem item : items) { + String url = item.getUrl(); + final String prefix = version.getUrlPrefix(); + if (!url.startsWith("http://") && prefix != null) { + url = prefix + url; + } + files.add(DownloadableFileService.getInstance().createFileDescription(url, item.getName())); + } + result.add(createVersion(version, files)); + } + Collections.sort(result, VERSIONS_COMPARATOR); + callback.onSuccess(result); + } + }); + } + + protected abstract F createVersion(Artifact version, List files); +} diff --git a/platform/platform-api/src/com/intellij/execution/ui/ConsoleViewContentType.java b/platform/platform-api/src/com/intellij/execution/ui/ConsoleViewContentType.java index 5243263df902..f80acefc295d 100644 --- a/platform/platform-api/src/com/intellij/execution/ui/ConsoleViewContentType.java +++ b/platform/platform-api/src/com/intellij/execution/ui/ConsoleViewContentType.java @@ -39,13 +39,13 @@ public class ConsoleViewContentType { public static final ColorKey CONSOLE_BACKGROUND_KEY = ColorKey.createColorKey("CONSOLE_BACKGROUND_KEY"); public static final TextAttributesKey NORMAL_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_NORMAL_OUTPUT"); - public static final TextAttributesKey WARNING_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_WARNING_OUTPUT"); + public static final TextAttributesKey LOG_WARNING_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("LOG_WARNING_OUTPUT"); public static final TextAttributesKey ERROR_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_ERROR_OUTPUT"); + public static final TextAttributesKey LOG_ERROR_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("LOG_ERROR_OUTPUT"); public static final TextAttributesKey USER_INPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_USER_INPUT"); public static final TextAttributesKey SYSTEM_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_SYSTEM_OUTPUT"); public static final ConsoleViewContentType NORMAL_OUTPUT = new ConsoleViewContentType("NORMAL_OUTPUT", NORMAL_OUTPUT_KEY); - public static final ConsoleViewContentType WARNING_OUTPUT = new ConsoleViewContentType("ERROR_OUTPUT", WARNING_OUTPUT_KEY); public static final ConsoleViewContentType ERROR_OUTPUT = new ConsoleViewContentType("ERROR_OUTPUT", ERROR_OUTPUT_KEY); public static final ConsoleViewContentType USER_INPUT = new ConsoleViewContentType("USER_OUTPUT", USER_INPUT_KEY); public static final ConsoleViewContentType SYSTEM_OUTPUT = new ConsoleViewContentType("SYSTEM_OUTPUT", SYSTEM_OUTPUT_KEY); diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java index 4615d2fe9f16..d4ca80de5b1a 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java @@ -251,4 +251,7 @@ public interface IdeActions { String ACTION_MOVE_STATEMENT_DOWN_ACTION = "MoveStatementDown"; String ACTION_COMPARE_CLIPBOARD_WITH_SELECTION = "CompareClipboardWithSelection"; + + String ACTION_UNDO = "$Undo"; + String ACTION_REDO = "$Redo"; } diff --git a/platform/platform-api/src/com/intellij/ui/TextComponentUndoProvider.java b/platform/platform-api/src/com/intellij/ui/TextComponentUndoProvider.java index 693ae99049cd..abea57195d62 100644 --- a/platform/platform-api/src/com/intellij/ui/TextComponentUndoProvider.java +++ b/platform/platform-api/src/com/intellij/ui/TextComponentUndoProvider.java @@ -17,6 +17,7 @@ package com.intellij.ui; import com.intellij.openapi.Disposable; +import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.actionSystem.KeyboardShortcut; import com.intellij.openapi.actionSystem.Shortcut; import com.intellij.openapi.keymap.KeymapManager; @@ -50,8 +51,8 @@ public class TextComponentUndoProvider implements Disposable { myOldKeymap = myTextComponent.getKeymap(); Keymap keymap = JTextComponent.addKeymap(null, myOldKeymap); com.intellij.openapi.keymap.Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap(); - Shortcut[] undoShortcuts = activeKeymap.getShortcuts("$Undo"); - Shortcut[] redoShortcuts = activeKeymap.getShortcuts("$Redo"); + Shortcut[] undoShortcuts = activeKeymap.getShortcuts(IdeActions.ACTION_UNDO); + Shortcut[] redoShortcuts = activeKeymap.getShortcuts(IdeActions.ACTION_REDO); Action undoAction = new AbstractAction ("Undo") { public void actionPerformed(ActionEvent e) { diff --git a/platform/platform-impl/src/com/intellij/notification/EventLog.java b/platform/platform-impl/src/com/intellij/notification/EventLog.java index 7fc25e04022c..31e8c4637239 100644 --- a/platform/platform-impl/src/com/intellij/notification/EventLog.java +++ b/platform/platform-impl/src/com/intellij/notification/EventLog.java @@ -233,6 +233,20 @@ public class EventLog implements Notifications { } }); group.add(new ScrollToTheEndToolbarAction(editor)); + group.add(new DumbAwareAction("Mark all as read", "Mark all unread notifications as read", IconLoader.getIcon("/general/reset.png")) { + @Override + public void update(AnActionEvent e) { + e.getPresentation().setEnabled(!getProjectComponent(project).myProjectModel.getNotifications().isEmpty()); + } + + @Override + public void actionPerformed(AnActionEvent e) { + LogModel model = getProjectComponent(project).myProjectModel; + for (Notification notification : model.getNotifications()) { + model.removeNotification(notification); + } + } + }); ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, false); toolbar.setTargetComponent(panel); diff --git a/platform/platform-impl/src/com/intellij/notification/EventLogConsole.java b/platform/platform-impl/src/com/intellij/notification/EventLogConsole.java index 83de47d6647e..ebf03c18461a 100644 --- a/platform/platform-impl/src/com/intellij/notification/EventLogConsole.java +++ b/platform/platform-impl/src/com/intellij/notification/EventLogConsole.java @@ -26,13 +26,17 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.ScrollType; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.event.EditorMouseEvent; import com.intellij.openapi.editor.ex.EditorMarkupModel; -import com.intellij.openapi.editor.markup.*; +import com.intellij.openapi.editor.markup.HighlighterLayer; +import com.intellij.openapi.editor.markup.HighlighterTargetArea; +import com.intellij.openapi.editor.markup.RangeHighlighter; +import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.Balloon; -import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.Pair; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.EditorPopupHandler; @@ -53,7 +57,7 @@ class EventLogConsole { EventLogConsole(@NotNull Project project, LogModel model) { myProjectModel = model; - myLogEditor = ConsoleViewUtil.setupConsoleEditor(project, false, true); + myLogEditor = ConsoleViewUtil.setupConsoleEditor(project, false, false); ((EditorMarkupModel) myLogEditor.getMarkupModel()).setErrorStripeVisible(true); @@ -113,18 +117,19 @@ class EventLogConsole { Pair pair = EventLog.formatForLog(notification); final NotificationType type = notification.getType(); - ConsoleViewContentType contentType = type == NotificationType.ERROR - ? ConsoleViewContentType.ERROR_OUTPUT + TextAttributesKey key = type == NotificationType.ERROR + ? ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY : type == NotificationType.INFORMATION - ? ConsoleViewContentType.NORMAL_OUTPUT - : ConsoleViewContentType.WARNING_OUTPUT; + ? ConsoleViewContentType.NORMAL_OUTPUT_KEY + : ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY; int msgStart = document.getTextLength(); String message = pair.first; append(document, message); - myLogEditor.getMarkupModel() - .addRangeHighlighter(msgStart, document.getTextLength(), HighlighterLayer.CARET_ROW + 1, contentType.getAttributes(), - HighlighterTargetArea.EXACT_RANGE); + + TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key); + int layer = HighlighterLayer.CARET_ROW + 1; + myLogEditor.getMarkupModel().addRangeHighlighter(msgStart, document.getTextLength(), layer, attributes, HighlighterTargetArea.EXACT_RANGE); if (pair.second) { String s = " "; @@ -174,44 +179,6 @@ class EventLogConsole { : notification.getType() == NotificationType.WARNING ? Color.yellow : Color.green; lineHighlighter.setErrorStripeMarkColor(color); lineHighlighter.setErrorStripeTooltip(message); - lineHighlighter.setGutterIconRenderer(new GutterIconRenderer() { - @NotNull - @Override - public Icon getIcon() { - return IconLoader.getIcon("/general/reset.png"); - } - - @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") - @Override - public boolean equals(Object obj) { - return this == obj; - } - - @Override - public int hashCode() { - return 0; - } - - @Override - public String getTooltipText() { - return "Mark as read"; - } - - @Override - public boolean isNavigateAction() { - return true; - } - - @Override - public AnAction getClickAction() { - return new AnAction() { - @Override - public void actionPerformed(AnActionEvent e) { - myProjectModel.removeNotification(notification); - } - }; - } - }); myProjectModel.removeHandlers.put(notification, new Runnable() { @Override diff --git a/platform/platform-impl/src/com/intellij/notification/LogModel.java b/platform/platform-impl/src/com/intellij/notification/LogModel.java index 9dec2de7b15c..f2fdb78bc00b 100644 --- a/platform/platform-impl/src/com/intellij/notification/LogModel.java +++ b/platform/platform-impl/src/com/intellij/notification/LogModel.java @@ -43,7 +43,7 @@ public class LogModel { } void addNotification(Notification notification) { - if (NotificationsConfiguration.getSettings(notification.getGroupId()).getDisplayType() != NotificationDisplayType.NONE) { + if (notification.isImportant() || NotificationsConfiguration.getSettings(notification.getGroupId()).getDisplayType() != NotificationDisplayType.NONE) { synchronized (myNotifications) { myNotifications.add(notification); } diff --git a/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsListPanel.java b/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsListPanel.java deleted file mode 100644 index dab6e4eab014..000000000000 --- a/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsListPanel.java +++ /dev/null @@ -1,861 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.notification.impl.ui; - -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationType; -import com.intellij.notification.impl.NotificationModelListener; -import com.intellij.notification.impl.NotificationsManagerImpl; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.keymap.KeymapUtil; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.popup.*; -import com.intellij.openapi.ui.popup.util.MinimizeButton; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.IconLoader; -import com.intellij.openapi.wm.impl.content.GraphicsConfig; -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.components.JBList; -import com.intellij.ui.components.panels.Wrapper; -import com.intellij.util.NotNullFunction; -import com.intellij.util.Processor; -import com.intellij.util.ui.BaseButtonBehavior; -import com.intellij.util.ui.TimedDeadzone; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.event.HyperlinkListener; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import java.awt.*; -import java.awt.event.*; -import java.awt.geom.RoundRectangle2D; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.List; - -/** - * @author spleaner - */ -public class NotificationsListPanel extends JPanel implements NotificationModelListener, Disposable { - private static final Logger LOG = Logger.getInstance("#com.intellij.notification.impl.ui.NotificationsListPanel"); - private static final String REMOVE_KEY = "REMOVE"; - - private static final Icon CLOSE_ICON = IconLoader.getIcon("/general/balloonClose.png"); - - private Project myProject; - private final Wrapper myWrapper; - private JComponent myActiveComponent; - - private final JComponent myEmptyComponent; - private final JComponent myListComponent; - - public NotificationsListPanel(@Nullable final Project project) { - setLayout(new BorderLayout()); - myProject = project; - - myEmptyComponent = new JLabel("No new notifications.", JLabel.CENTER); - myListComponent = ItemsList.create(project, this); - - myWrapper = new Wrapper(); - myWrapper.setContent(getCurrentComponent(project)); - - setMinimumSize(new Dimension(350, 300)); - add(myWrapper, BorderLayout.CENTER); - } - - public void notificationsAdded(@NotNull Notification... notification) { - switchView(myProject); - } - - public void notificationsRemoved(@NotNull Notification... notification) { - switchView(myProject); - } - - public void notificationsRead(@NotNull Notification... notification) { - switchView(myProject); - } - - @Override - public void addNotify() { - super.addNotify(); - getManager().addListener(this); - } - - @Override - public void removeNotify() { - getManager().removeListener(this); - super.removeNotify(); - } - - private JComponent getCurrentComponent(@Nullable final Project project) { - final boolean empty = getManager().count(project) == 0; - final JComponent component = empty ? myEmptyComponent : myListComponent; - if (myActiveComponent == component) return null; - - myActiveComponent = component; - return myActiveComponent; - } - - protected void switchView(@Nullable final Project project) { - final JComponent component = getCurrentComponent(project); - if (component != null) { - myWrapper.setContent(component); - myWrapper.revalidate(); - myWrapper.repaint(); - } - } - - public void dispose() { - getManager().markRead(); - - myProject = null; - } - - private static NotificationsManagerImpl getManager() { - return NotificationsManagerImpl.getNotificationsManagerImpl(); - } - - static Dimension getMinSize() { - final Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); - size.width *= 0.1d; - size.height *= 0.1d; - return size; - } - - public JComponent getPreferredFocusedComponent() { - return myWrapper.getTargetComponent(); - } - - public static JBPopup show(@Nullable final Project project, @NotNull final JComponent parent) { - final NotificationsListPanel panel = new NotificationsListPanel(project); - final ComponentPopupBuilder builder = - JBPopupFactory.getInstance().createComponentPopupBuilder(panel, panel.getPreferredFocusedComponent()); - final JBPopup popup = builder.setResizable(true).setMinSize(getMinSize()).setDimensionServiceKey(null, "NotificationsPopup", true) - .setCancelOnClickOutside(false).setBelongsToGlobalPopupStack(false).setCancelButton(new MinimizeButton("Hide")).setMovable(true) - .setRequestFocus(true).setTitle("Notifications").createPopup(); - - popup.addListener(new JBPopupListener.Adapter() { - @Override - public void onClosed(LightweightWindowEvent event) { - Disposer.dispose(panel); - } - }); - - popup.showInCenterOf(SwingUtilities.getRootPane(parent)); - return popup; - } - - private static class NotificationsListRenderer extends JComponent implements ListCellRenderer { - private final JTextPane myText; - private boolean mySelected; - private boolean myHasFocus; - private final JLabel myIconLabel; - private Processor myProc; - private boolean myWasRead; - private JList myList; - private JTextPane myFakeTextPane; - private JViewport myFakeViewport; - - private NotificationsListRenderer() { - setLayout(new BorderLayout()); - setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4)); - - setOpaque(false); - - myIconLabel = new JLabel(); - myIconLabel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); - myIconLabel.setOpaque(false); - - myText = new JTextPane() { - @Override - public void setCursor(Cursor cursor) { - super.setCursor(cursor); - onCursorChanged(cursor); - } - }; - - myFakeTextPane = new JTextPane(); - myText.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0)); - myFakeTextPane.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0)); - myText.setOpaque(false); - if (UIUtil.isUnderNimbusLookAndFeel()) { - myText.setBackground(new Color(0, 0, 0, 0)); - } - - myText.setEditable(false); - myFakeTextPane.setEditable(false); - myText.setEditorKit(UIUtil.getHTMLEditorKit()); - myFakeTextPane.setEditorKit(UIUtil.getHTMLEditorKit()); - - myFakeViewport = new JViewport(); - myFakeViewport.setView(myFakeTextPane); - - final Wrapper.North comp = new Wrapper.North(myIconLabel); - comp.setOpaque(false); - add(comp, BorderLayout.WEST); - add(myText, BorderLayout.CENTER); - } - - public JTextPane getText() { - return myText; - } - - public void setCursorHandler(Processor proc) { - myProc = proc; - } - - public void resetCursorHandler() { - myProc = null; - } - - public void onCursorChanged(Cursor cursor) { - if (myProc != null) myProc.process(cursor); - } - - @Override - public Dimension getPreferredSize() { - final Container parent = myList.getParent(); - if (parent != null) { - myFakeTextPane.setText(myText.getText()); - final Dimension size = parent.getSize(); - myFakeViewport.setSize(size); - final Dimension preferredSize = myFakeTextPane.getPreferredSize(); - - final Insets insets = getInsets(); - return new Dimension(Math.min(size.width - 20, preferredSize.width), preferredSize.height + insets.top + insets.bottom); - } - - return super.getPreferredSize(); - } - - @Override - protected void paintComponent(Graphics g) { - final Graphics2D g2d = (Graphics2D)g; - - final Rectangle bounds = getBounds(); - final Insets insets = getInsets(); - - final GraphicsConfig cfg = new GraphicsConfig(g); - cfg.setAntialiasing(true); - - final Shape shape = new RoundRectangle2D.Double(insets.left, insets.top, bounds.width - 1 - insets.left - insets.right, - bounds.height - 1 - insets.top - insets.bottom, 6, 6); - - if (mySelected) { - g2d.setColor(UIUtil.getListSelectionBackground()); - g2d.fillRect(0, 0, bounds.width, bounds.height); - } - - g2d.setColor(Color.WHITE); - g2d.fill(shape); - - - Color bgColor = getBackground(); - if (myWasRead) { - bgColor = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 60); - } - - g2d.setColor(bgColor); - g2d.fill(shape); - - g2d.setColor(myHasFocus || mySelected ? getBackground().darker().darker() : myWasRead ? getBackground() : getBackground().darker()); - g2d.draw(shape); - cfg.restore(); - - super.paintComponent(g); - } - - public Component getListCellRendererComponent(final JList list, - final Object value, - final int index, - final boolean isSelected, - final boolean cellHasFocus) { - LOG.assertTrue(value instanceof Notification); - final Notification notification = (Notification)value; - - myList = list; - - mySelected = isSelected; - myHasFocus = cellHasFocus; - - myText.setText(NotificationsUtil.buildHtml(notification)); - myIconLabel.setIcon(NotificationsUtil.getIcon(notification)); - myWasRead = NotificationsManagerImpl.getNotificationsManagerImpl().wasRead(notification); - - setBackground(NotificationsUtil.getBackground(notification)); - - return this; - } - } - - private static class NotificationsListModel extends AbstractListModel implements NotificationModelListener, Disposable { - private final List myNotifications = new ArrayList(); - private NotificationType myType; - private Project myProject; - private final NotNullFunction> myRebuildFunction; - private boolean myArchive; - - private NotificationsListModel(@Nullable Project project) { - myProject = project; - - myRebuildFunction = new NotNullFunction>() { - @NotNull - public Collection fun(Project project) { - return getManager().getByType(myType, project); - } - }; - - getManager().addListener(this); - rebuildList(); - } - - public void dispose() { - getManager().removeListener(this); - myProject = null; - } - - public int getSize() { - return myNotifications.size(); - } - - public Object getElementAt(final int index) { - return index < myNotifications.size() ? myNotifications.get(index) : null; - } - - private void rebuildList() { - myNotifications.clear(); - myNotifications.addAll(myRebuildFunction.fun(myProject)); - fireContentsChanged(this, 0, myNotifications.size() - 1); - } - - public void filter(final NotificationType type) { - myType = type; - rebuildList(); - } - - public void notificationsAdded(@NotNull Notification... notification) { - rebuildList(); - } - - public void notificationsRemoved(@NotNull Notification... notification) { - rebuildList(); - } - - public void notificationsRead(@NotNull Notification... notification) { - rebuildList(); - } - } - - private static class ItemsList extends JBList { - private ItemsList(final NotificationsListModel model) { - super(model); - setOpaque(false); - - setCellRenderer(new NotificationsListRenderer()); - getSelectionModel().setSelectionInterval(0, 0); - - getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), REMOVE_KEY); - getActionMap().put(REMOVE_KEY, new AbstractAction() { - public void actionPerformed(final ActionEvent e) { - removeSelected(); - } - }); - - setBackground(UIUtil.getPanelBackground()); - - addMouseMotionListener(new MouseMotionListener() { - public void mouseMoved(MouseEvent e) { - processMouse(e, false); - } - - public void mouseDragged(MouseEvent e) { - } - }); - - addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - if (!e.isPopupTrigger()) { - processMouse(e, true); - } - } - }); - - ExpireButton.install(this); - } - - @Override - protected boolean shouldInstallItemTooltipExpander() { - return false; - } - - private void processMouse(final MouseEvent e, final boolean click) { - final int index = locationToIndex(e.getPoint()); - if (index > -1) { - final Object value = getModel().getElementAt(index); - if (value != null && value instanceof Notification) { - final Notification notification = (Notification)value; - final Component renderer = getCellRenderer().getListCellRendererComponent(this, value, index, false, false); - if (renderer instanceof NotificationsListRenderer) { - final Rectangle bounds = getCellBounds(index, index); - renderer.setBounds(bounds); - renderer.doLayout(); - - final JTextPane text = ((NotificationsListRenderer)renderer).getText(); - - Processor processor; - HyperlinkListener listener = null; - if (click) { - listener = NotificationsUtil.wrapListener(notification); - if (listener != null) text.addHyperlinkListener(listener); - } - else { - processor = new Processor() { - public boolean process(Cursor cursor) { - ItemsList.this.setCursor(cursor); - return true; - } - }; - - ((NotificationsListRenderer)renderer).setCursorHandler(processor); - } - - final Point point = e.getPoint(); - point.translate(-bounds.x, -bounds.y); - - final Rectangle r = text.getBounds(); - point.translate(-r.x, -r.y); - - final MouseEvent newEvent = - new MouseEvent(text, e.getID(), e.getWhen(), e.getModifiers(), point.x, point.y, e.getClickCount(), e.isPopupTrigger(), - e.getButton()); - - text.dispatchEvent(newEvent); - - ((NotificationsListRenderer)renderer).resetCursorHandler(); - if (listener != null) { - text.removeHyperlinkListener(listener); - } - } - } - } - } - - @SuppressWarnings({"ConstantConditions"}) - @Override - public NotificationsListModel getModel() { - final ListModel listModel = super.getModel(); - return listModel instanceof NotificationsListModel ? (NotificationsListModel)listModel : null; - } - - public void removeSelected() { - final ListSelectionModel model = getSelectionModel(); - final NotificationsListModel listModel = getModel(); - if (!model.isSelectionEmpty()) { - final int min = model.getMinSelectionIndex(); - final int max = model.getMaxSelectionIndex(); - - final List tbr = new ArrayList(); - for (int i = min; i <= max; i++) { - if (model.isSelectedIndex(i)) { - final Notification notification = (Notification)listModel.getElementAt(i); - if (notification != null) { - tbr.add(notification); - } - } - } - - if (tbr.size() > 0) { - getManager().remove(tbr.toArray(new Notification[tbr.size()])); - - final int toSelect = Math.min(min, listModel.getSize() - 1); - model.clearSelection(); - if (toSelect >= 0) { - model.setSelectionInterval(toSelect, toSelect); - scrollRectToVisible(getCellBounds(toSelect, toSelect)); - } - } - } - - revalidate(); - repaint(); - } - - private static void createFilterButton(final JPanel parent, - final ButtonGroup group, - final String title, - final ActionListener listener, - final NotNullFunction titleCallback, - final char mnemonic, - final boolean active) { - final StickyButton b = new MyButton(title, listener) { - @Override - public void updateTitle() { - setText(titleCallback.fun(this)); - } - }; - - parent.add(b); - group.add(b); - - b.setFocusable(false); - b.setSelected(active); - b.setMnemonic(mnemonic); - } - - private static void updateButtons(@NotNull final JComponent filterBar) { - final Component[] components = filterBar.getComponents(); - for (final Component c : components) { - if (c instanceof MyButton) { - ((MyButton)c).updateTitle(); - } - } - } - - private static JComponent buildFilterBar(final ItemsList list, final Project project) { - final JPanel box = new JPanel(); - box.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, box.getBackground().darker()), - BorderFactory.createEmptyBorder(3, 3, 3, 3))); - box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS)); - - final ButtonGroup buttonGroup = new ButtonGroup(); - - createFilterButton(box, buttonGroup, "All", new ActionListener() { - public void actionPerformed(final ActionEvent e) { - list.filter(null); - } - }, new NotNullFunction() { - @NotNull - public String fun(MyButton myButton) { - final int i = count(null, project); - if (i > 0) { - return String.format("All (%s)", i); - } - - return "All"; - } - }, 'A', true); - - createFilterButton(box, buttonGroup, "Error", new ActionListener() { - public void actionPerformed(final ActionEvent e) { - list.filter(NotificationType.ERROR); - } - }, new NotNullFunction() { - @NotNull - public String fun(MyButton myButton) { - final int i = count(NotificationType.ERROR, project); - myButton.setVisible(i > 0); - if (i > 0) { - return String.format("Error (%s)", i); - } - else if (myButton.isSelected()) { - switchToAll(buttonGroup); - } - - return "Error"; - } - }, 'E', false); - - createFilterButton(box, buttonGroup, "Warning", new ActionListener() { - public void actionPerformed(final ActionEvent e) { - list.filter(NotificationType.WARNING); - } - }, new NotNullFunction() { - @NotNull - public String fun(MyButton myButton) { - final int i = count(NotificationType.WARNING, project); - myButton.setVisible(i > 0); - if (i > 0) { - return String.format("Warning (%s)", i); - } - else if (myButton.isSelected()) { - switchToAll(buttonGroup); - } - - return "Warning"; - } - }, 'W', false); - - createFilterButton(box, buttonGroup, "Information", new ActionListener() { - public void actionPerformed(final ActionEvent e) { - list.filter(NotificationType.INFORMATION); - } - }, new NotNullFunction() { - @NotNull - public String fun(MyButton myButton) { - final int i = count(NotificationType.INFORMATION, project); - myButton.setVisible(i > 0); - if (i > 0) { - return String.format("Information (%s)", i); - } - else if (myButton.isSelected()) { - switchToAll(buttonGroup); - } - - return "Information"; - } - }, 'I', false); - - return box; - } - - private static void switchToAll(final ButtonGroup buttonGroup) { - final Enumeration enumeration = buttonGroup.getElements(); - while (enumeration.hasMoreElements()) { - final AbstractButton button = enumeration.nextElement(); - if (button.getText().startsWith("All")) { - button.doClick(); - return; - } - } - } - - private static int count(@Nullable final NotificationType type, @Nullable final Project project) { - return NotificationsManagerImpl.getNotificationsManagerImpl().getByType(type, project).size(); - } - - private void filter(@Nullable final NotificationType type) { - final NotificationsListModel listModel = getModel(); - listModel.filter(type); - if (listModel.getSize() > 0) setSelectedIndex(0); - } - - public static JComponent create(final Project project, final Disposable parentDisposable) { - final NotificationsListModel model = new NotificationsListModel(project); - Disposer.register(parentDisposable, model); - - // TODO: switch filter if removed all of the notifications from current one! - - final ItemsList list = new ItemsList(model); - list.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - list.setCellRenderer(new NotificationsListRenderer()); // request cell renderer size invalidation - } - }); - - final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(list); - scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - - scrollPane.setBorder(null); - scrollPane.getViewport().setBackground(UIUtil.getPanelBackground()); - - final JComponent buttonBar = buildFilterBar(list, project); - model.addListDataListener(new ListDataListener() { - public void intervalAdded(ListDataEvent e) { - updateButtons(buttonBar); - } - - public void intervalRemoved(ListDataEvent e) { - updateButtons(buttonBar); - } - - public void contentsChanged(ListDataEvent e) { - updateButtons(buttonBar); - } - }); - - final JPanel panel = new JPanel(new BorderLayout()) { - @Override - public void requestFocus() { - updateButtons(buttonBar); - list.requestFocus(); - } - }; - - panel.add(buttonBar, BorderLayout.NORTH); - panel.add(scrollPane, BorderLayout.CENTER); - - return panel; - } - } - - private static class ExpireButton extends JComponent { - private int myIndex = -1; - private BaseButtonBehavior myBehavior; - private JList myList; - - private ExpireButton(final JList list) { - myList = list; - - final MouseAdapter adapter = new MouseAdapter() { - @Override - public void mouseMoved(MouseEvent e) { - showAtPoint(e); - } - - @Override - public void mouseExited(MouseEvent e) { - hideCloseButton(e); - } - }; - - list.addMouseMotionListener(adapter); - list.addMouseListener(adapter); - - setOpaque(false); - setToolTipText("Delete (" + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke("DELETE")) + ")"); - - myBehavior = new BaseButtonBehavior(this, TimedDeadzone.NULL) { - @Override - protected void execute(final MouseEvent e) { - expire(); - - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - showAtPoint(e); - } - }); - } - }; - } - - private void showAtPoint(MouseEvent e) { - final Point point = e.getSource() == myList ? e.getPoint() : SwingUtilities.convertPoint((Component)e.getSource(), e.getPoint(), myList); - final int index = myList.locationToIndex(point); - if (index > -1) { - final Object value = myList.getModel().getElementAt(index); - if (value != null && value instanceof Notification) { - final Rectangle bounds = myList.getCellBounds(index, index); - if (myList.getVisibleRect().contains(bounds) && bounds.contains(point)) { - toggle(index, false); - } - } - } - } - - private void expire() { - if (myIndex != -1) { - final ListModel model = myList.getModel(); - final Object o = model.getElementAt(myIndex); - if (o instanceof Notification) { - final Notification notification = (Notification)o; - if (!notification.isExpired()) { - notification.expire(); - } - } - } - - myIndex = -1; - setVisible(false); - } - - public void setIndex(final int index) { - myIndex = index; - } - - @Override - public Dimension getPreferredSize() { - return getMinimumSize(); - } - - @Override - public Dimension getMinimumSize() { - return new Dimension(CLOSE_ICON.getIconWidth() + 2, CLOSE_ICON.getIconHeight() + 2); - } - - @Override - public void paint(Graphics g) { - final Rectangle r = getBounds(); - if (myBehavior.isPressedByMouse()) { - CLOSE_ICON.paintIcon(this, g, r.width - CLOSE_ICON.getIconWidth(), r.height - CLOSE_ICON.getIconHeight()); - } - else { - CLOSE_ICON.paintIcon(this, g, r.width - CLOSE_ICON.getIconWidth() - 2, r.height - CLOSE_ICON.getIconHeight() - 2); - } - } - - public static void install(final JList list) { - final ExpireButton button = new ExpireButton(list); - button.setVisible(false); - } - - public void hideCloseButton(final MouseEvent e) { - if (e != null) { - final Object source = e.getSource(); - if (source instanceof JComponent) { - final Container parent = getParent(); - if (parent != null) { - final Point point = SwingUtilities.convertPoint((Component) source, e.getPoint(), getParent()); - if (!getBounds().contains(point)) { - toggle(-1, true); - } - } - } - } - else { - toggle(-1, true); - } - } - - private void toggle(final int index, final boolean hide) { - if (hide) { - setIndex(index); - setVisible(false); - return; - } - - if (getParent() == null) { - final Window window = SwingUtilities.getWindowAncestor(myList); - if (!(window instanceof JDialog)) return; - final JLayeredPane layeredPane = ((JDialog)window).getLayeredPane(); - if (layeredPane == null) return; - layeredPane.add(this); - - layeredPane.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - toggle(-1, true); - } - }); - } - - if (getParent() != null) { - final Dimension preferredSize = getPreferredSize(); - final Rectangle cellBounds = myList.getCellBounds(index, index); - Point location = new Point(cellBounds.x + cellBounds.width - preferredSize.width, cellBounds.y); - location = SwingUtilities.convertPoint(myList, location, getParent()); - setIndex(index); - setBounds(location.x, location.y, preferredSize.width, preferredSize.height); - } - - setVisible(true); - } - - public int getIndex() { - return myIndex; - } - } - - private abstract static class MyButton extends StickyButton { - private MyButton(String text, ActionListener listener) { - super(text, listener); - } - - private MyButton(String text) { - super(text); - } - - public abstract void updateTitle(); - } -} diff --git a/platform/platform-impl/src/com/intellij/notification/impl/ui/StickyButton.java b/platform/platform-impl/src/com/intellij/notification/impl/ui/StickyButton.java index 23cd52a575cc..2dc32943164b 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/ui/StickyButton.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/ui/StickyButton.java @@ -25,11 +25,6 @@ import java.awt.event.ActionListener; */ public class StickyButton extends JToggleButton { - public StickyButton(final String text, final ActionListener listener) { - this(text); - addActionListener(listener); - } - public StickyButton(final String text) { super(text); diff --git a/platform/platform-resources-en/src/messages/OptionsBundle.properties b/platform/platform-resources-en/src/messages/OptionsBundle.properties index b3bfef5e37ce..b01256cf2be4 100644 --- a/platform/platform-resources-en/src/messages/OptionsBundle.properties +++ b/platform/platform-resources-en/src/messages/OptionsBundle.properties @@ -127,7 +127,8 @@ options.general.color.descriptor.modified.lines=Modified lines options.general.color.descriptor.console.background=Console background options.general.color.descriptor.console.stdout=Console standard output options.general.color.descriptor.console.stderr=Console error output -options.general.color.descriptor.console.warning=Console warning output +options.general.color.descriptor.console.warning=Log console warning +options.general.color.descriptor.console.logError=Log console error options.general.color.descriptor.console.stdin=Console user input options.general.color.descriptor.console.system.output=Console system output options.general.color.descriptor.hyperlink.new=Hyperlink diff --git a/platform/platform-resources/src/DefaultColorSchemesManager.xml b/platform/platform-resources/src/DefaultColorSchemesManager.xml index 7978c93214d1..a464da48aced 100644 --- a/platform/platform-resources/src/DefaultColorSchemesManager.xml +++ b/platform/platform-resources/src/DefaultColorSchemesManager.xml @@ -1139,11 +1139,16 @@ - +