display the last log message in the status bar

This commit is contained in:
peter
2011-05-31 21:45:54 +02:00
parent ae45b8e608
commit ced8bf91ae
6 changed files with 118 additions and 15 deletions
@@ -26,8 +26,8 @@ import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.openapi.wm.*;
import com.intellij.openapi.wm.ex.StatusBarEx;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;
@@ -74,14 +74,14 @@ public class EventLog implements Notifications {
getApplicationComponent().addGlobalNotifications(notification);
}
for (Project p : openProjects) {
printNotification(getProjectComponent(p).myConsoleView, notification);
printNotification(getProjectComponent(p).myConsoleView, p, notification);
}
} else {
printNotification(getProjectComponent(project).myConsoleView, notification);
printNotification(getProjectComponent(project).myConsoleView, project, notification);
}
}
private static void printNotification(ConsoleViewImpl view, final Notification notification) {
private static void printNotification(ConsoleViewImpl view, Project project, final Notification notification) {
view.print(DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date()) + " ", ConsoleViewContentType.NORMAL_OUTPUT);
boolean showLink = notification.getListener() != null;
@@ -119,6 +119,8 @@ public class EventLog implements Notifications {
view.print(" ", ConsoleViewContentType.NORMAL_OUTPUT);
}
view.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
((StatusBarEx)WindowManager.getInstance().getIdeFrame(project).getStatusBar()).setLogMessage(mainText);
}
private static int eolIndex(String mainText) {
@@ -53,4 +53,6 @@ public interface StatusBarEx extends StatusBar, Disposable {
@Nullable
String getInfoRequestor();
void setLogMessage(String text);
}
@@ -109,6 +109,10 @@ public final class TestWindowManager extends WindowManagerEx implements Applicat
return null;
}
@Override
public void setLogMessage(String text) {
}
public boolean isVisible() {
return false;
}
@@ -403,6 +403,12 @@ public class IdeStatusBarImpl extends JComponent implements StatusBarEx {
return myRequestor;
}
@Override
public void setLogMessage(String text) {
myInfoAndProgressPanel.setLogMessage(text);
setInfo(null, "Log message");
}
public void addProgress(ProgressIndicatorEx indicator, TaskInfo info) {
myInfoAndProgressPanel.addProgress(indicator, info);
}
@@ -55,15 +55,12 @@ import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidget {
private final ProcessPopup myPopup;
private final TextPanel myInfoPanel = new TextPanel();
private final StatusPanel myInfoPanel = new StatusPanel();
private final JPanel myRefreshAndInfoPanel = new JPanel();
private final AsyncProcessIcon myProgressIcon;
@@ -177,7 +174,11 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
public void addProgress(final ProgressIndicatorEx original, TaskInfo info) {
synchronized (myOriginals) {
final boolean veryFirst = myOriginals.isEmpty();
final boolean veryFirst = !hasProgressIndicators();
if (veryFirst) {
myInfoPanel.hideLog();
}
myOriginals.add(original);
myInfos.add(info);
@@ -202,6 +203,12 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
}
}
private boolean hasProgressIndicators() {
synchronized (myOriginals) {
return !myOriginals.isEmpty();
}
}
private void removeProgress(InlineProgressIndicator progress) {
synchronized (myOriginals) {
if (!myInline2Original.containsKey(progress)) return;
@@ -233,6 +240,10 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
}
runQuery();
if (last) {
myInfoPanel.restoreLogIfNeeded();
}
}
}
@@ -254,7 +265,7 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
private void openProcessPopup(boolean requestFocus) {
synchronized (myOriginals) {
if (myPopup.isShowing()) return;
if (!myOriginals.isEmpty()) {
if (hasProgressIndicators()) {
myShouldClosePopupAndOnProcessFinish = true;
buildInProcessCount();
}
@@ -273,7 +284,7 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
if (myOriginals.size() == 1) {
buildInInlineIndicator(createInlineDelegate(myInfos.get(0), myOriginals.get(0), true));
}
else if (myOriginals.isEmpty()) {
else if (!hasProgressIndicators()) {
restoreEmptyStatus();
}
else {
@@ -351,8 +362,9 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
return Pair.create(myInfoPanel.getText(), myCurrentRequestor);
}
myInfoPanel.setText(text);
myCurrentRequestor = requestor;
final boolean logMode = StringUtil.isEmpty(text) && !hasProgressIndicators();
myInfoPanel.updateText(logMode, text);
myCurrentRequestor = logMode ? requestor : null;
return Pair.create(text, requestor);
}
@@ -410,6 +422,10 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
};
}
public void setLogMessage(String text) {
myInfoPanel.setLogMessage(text);
}
private static class InlineLayout extends AbstractLayoutManager {
public Dimension preferredLayoutSize(final Container parent) {
@@ -0,0 +1,73 @@
/*
* 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.openapi.wm.impl.status;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Alarm;
import com.intellij.util.text.DateFormatUtil;
import org.jetbrains.annotations.Nullable;
import java.util.Date;
/**
* @author peter
*/
class StatusPanel extends TextPanel {
private boolean myLogMode;
private String myLogMessage;
private Date myLogTime;
private final Alarm myLogAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
public void setLogMessage(String text) {
myLogMessage = text;
myLogTime = new Date();
}
public void updateText(boolean logMode, @Nullable String nonLogText) {
myLogMode = logMode;
if (logMode) {
new Runnable() {
@Override
public void run() {
setText(myLogMessage + " (" + StringUtil.decapitalize(DateFormatUtil.formatPrettyDateTime(myLogTime)) + ")");
myLogAlarm.addRequest(this, 30000);
}
}.run();
} else {
setText(nonLogText);
myLogAlarm.cancelAllRequests();
}
}
public void hideLog() {
if (myLogMode) {
updateText(false, "");
}
}
public void restoreLogIfNeeded() {
myLogAlarm.addRequest(new Runnable() {
@Override
public void run() {
if (StringUtil.isEmpty(getText())) {
updateText(true, "");
}
}
}, 500);
}
}