This commit is contained in:
Olesya Smirnova
2005-01-18 15:38:51 +03:00
parent 983be7df48
commit 23b57cdaa3
5 changed files with 123 additions and 59 deletions

View File

@@ -35,6 +35,7 @@ import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.editor.markup.TextAttributes;
public abstract class ProjectLevelVcsManager {
public static final String FILE_VIEW_TOOL_WINDOW_ID = "File View";
@@ -62,4 +63,6 @@ public abstract class ProjectLevelVcsManager {
public abstract AbstractVcs[] getAllActiveVcss();
public abstract void addMessageToConsoleWindow(String message, TextAttributes attributes);
}

View File

@@ -1,4 +1,4 @@
package com.intellij.cvsSupport2.consoleView;
package com.intellij.util.ui;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
@@ -17,10 +17,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* author: lesya
*/
class Line {
private final String myValue;
private final TextAttributes myTextAttributes;
@@ -41,7 +37,7 @@ class Line {
public class EditorAdapter {
private static final Logger LOG = Logger.getInstance("#com.intellij.cvsSupport2.consoleView.EditorAdapter");
private static final Logger LOG = Logger.getInstance("#com.intellij.util.ui.EditorAdapter");
private final Editor myEditor;

View File

@@ -1,12 +1,13 @@
package com.intellij.cvsSupport2.cvshandlers;
import com.intellij.cvsSupport2.consoleView.EditorAdapter;
import com.intellij.util.ui.EditorAdapter;
import com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsMessagesAdapter;
import com.intellij.cvsSupport2.cvsoperations.cvsMessages.MessageEvent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.markup.EffectType;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.project.Project;
import com.intellij.util.ui.EditorAdapter;
import java.awt.*;
@@ -16,9 +17,9 @@ import java.awt.*;
public class CvsMessagesConsole extends CvsMessagesAdapter {
private EditorAdapter myOutput;
private static final TextAttributes USER_MESSAGES_ATTRIBUTES = new TextAttributes(null, null, null, EffectType.LINE_UNDERSCORE, Font.PLAIN);
private static final TextAttributes PROGRESS_MESSAGES_ATTRIBUTES = new TextAttributes(null, null, null, EffectType.LINE_UNDERSCORE, Font.ITALIC);
private static final TextAttributes COMMAND = new TextAttributes(null, null, null, EffectType.LINE_UNDERSCORE, Font.BOLD);
public static final TextAttributes USER_MESSAGES_ATTRIBUTES = new TextAttributes(null, null, null, EffectType.LINE_UNDERSCORE, Font.PLAIN);
public static final TextAttributes PROGRESS_MESSAGES_ATTRIBUTES = new TextAttributes(null, null, null, EffectType.LINE_UNDERSCORE, Font.ITALIC);
public static final TextAttributes COMMAND = new TextAttributes(null, null, null, EffectType.LINE_UNDERSCORE, Font.BOLD);
public void connectToOutputView(Editor editor, Project project) {
myOutput = new EditorAdapter(editor, project);

View File

@@ -33,13 +33,16 @@ package com.intellij.openapi.vcs.impl;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.EditorSettings;
import com.intellij.openapi.editor.event.EditorFactoryAdapter;
import com.intellij.openapi.editor.event.EditorFactoryEvent;
import com.intellij.openapi.editor.event.EditorFactoryListener;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.localVcs.LocalVcs;
@@ -62,13 +65,17 @@ import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.peer.PeerFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
import com.intellij.ui.content.ContentManagerAdapter;
import com.intellij.ui.content.ContentManagerEvent;
import com.intellij.util.ui.EditorAdapter;
import javax.swing.*;
import java.io.File;
import java.util.*;
public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx implements ProjectComponent {
private List<AbstractVcs> myVcss = new ArrayList<AbstractVcs>();
private final Project myProject;
private final Map<AbstractVcs, Boolean> myVcsToStatus = new HashMap<AbstractVcs, Boolean>();
@@ -80,7 +87,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
private final MyFileStatusListener myFileStatusListener = new MyFileStatusListener();
private final MyVirtualFileListener myVirtualFileListener = new MyVirtualFileListener();
private ContentManager myContentManager;
private EditorAdapter myEditorAdapter;
public ProjectLevelVcsManagerImpl(Project project) {
myProject = project;
@@ -136,16 +143,19 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
VirtualFileManager.getInstance().addVirtualFileListener(myVirtualFileListener);
StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() {
public void run() {
ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
if (toolWindowManager != null) { // Can be null in tests
ToolWindow toolWindow = toolWindowManager.registerToolWindow(ToolWindowId.VCS, myContentManager.getComponent(),
ToolWindowAnchor.BOTTOM);
toolWindow.setIcon(IconLoader.getIcon("/_cvs/cvs.png"));
toolWindow.installWatcher(myContentManager);
}
}
});
public void run() {
ToolWindowManager toolWindowManager =
ToolWindowManager.getInstance(myProject);
if (toolWindowManager != null) { // Can be null in tests
ToolWindow toolWindow =
toolWindowManager.registerToolWindow(ToolWindowId.VCS,
myContentManager.getComponent(),
ToolWindowAnchor.BOTTOM);
toolWindow.setIcon(IconLoader.getIcon("/_cvs/cvs.png"));
toolWindow.installWatcher(myContentManager);
}
}
});
}
public void projectClosed() {
@@ -272,27 +282,27 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
public synchronized void resetTracker(final LineStatusTracker tracker) {
if (tracker != null) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
if (myIsDisposed) return;
if (releaseTracker(tracker.getDocument())) {
installTracker(tracker.getVirtualFile(), tracker.getDocument());
}
}
});
public void run() {
if (myIsDisposed) return;
if (releaseTracker(tracker.getDocument())) {
installTracker(tracker.getVirtualFile(), tracker.getDocument());
}
}
});
}
}
private class MyFileStatusListener implements FileStatusListener {
public void fileStatusesChanged() {
if (myIsDisposed) return;
synchronized (this) {
List<LineStatusTracker> trackers = new ArrayList<LineStatusTracker>(myLineStatusTrackers.values());
for (Iterator<LineStatusTracker> i = trackers.iterator(); i.hasNext();) {
LineStatusTracker tracker = i.next();
resetTracker(tracker);
}
if (myIsDisposed) return;
synchronized (this) {
List<LineStatusTracker> trackers = new ArrayList<LineStatusTracker>(myLineStatusTrackers.values());
for (Iterator<LineStatusTracker> i = trackers.iterator(); i.hasNext();) {
LineStatusTracker tracker = i.next();
resetTracker(tracker);
}
}
}
public void fileStatusChanged(VirtualFile virtualFile) {
resetTracker(virtualFile);
@@ -356,25 +366,27 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
public String getPresentableRelativePathFor(final VirtualFile file) {
if (file == null) return "";
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
public String compute() {
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
Module module = fileIndex.getModuleForFile(file);
VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
if (module == null) return file.getPresentableUrl();
StringBuffer result = new StringBuffer();
result.append("<");
result.append(module.getName());
result.append(">");
result.append(File.separatorChar);
result.append(contentRoot.getName());
String relativePath = VfsUtil.getRelativePath(file, contentRoot, File.separatorChar);
if (relativePath.length() > 0) {
result.append(File.separatorChar);
result.append(relativePath);
}
return result.toString();
}
});
public String compute() {
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject)
.getFileIndex();
Module module = fileIndex.getModuleForFile(file);
VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
if (module == null) return file.getPresentableUrl();
StringBuffer result = new StringBuffer();
result.append("<");
result.append(module.getName());
result.append(">");
result.append(File.separatorChar);
result.append(contentRoot.getName());
String relativePath =
VfsUtil.getRelativePath(file, contentRoot, File.separatorChar);
if (relativePath.length() > 0) {
result.append(File.separatorChar);
result.append(relativePath);
}
return result.toString();
}
});
}
public DataProvider createVirtualAndPsiFileDataProvider(VirtualFile[] virtualFileArray, VirtualFile selectedFile) {
@@ -407,4 +419,48 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
}
public void addMessageToConsoleWindow(String message, TextAttributes attributes) {
if (ApplicationManager.getApplication().isDispatchThread()) {
getOrCreateConsoleContent(getContentManager());
}
else {
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
public void run() {
getOrCreateConsoleContent(getContentManager());
}
}, ModalityState.defaultModalityState());
}
myEditorAdapter.appendString(message, attributes);
}
private Content getOrCreateConsoleContent(final ContentManager contentManager) {
final String displayName = "Console";
Content content = contentManager.findContent(displayName);
if (content == null) {
final EditorFactory editorFactory = EditorFactory.getInstance();
final Editor editor = editorFactory.createViewer(editorFactory.createDocument(""));
EditorSettings editorSettings = editor.getSettings();
editorSettings.setLineMarkerAreaShown(false);
editorSettings.setLineNumbersShown(false);
editorSettings.setFoldingOutlineShown(false);
myEditorAdapter = new EditorAdapter(editor, myProject);
final JComponent panel = editor.getComponent();
content = PeerFactory.getInstance().getContentFactory().createContent(panel, displayName, true);
contentManager.addContent(content);
contentManager.addContentManagerListener(new ContentManagerAdapter() {
public void contentRemoved(ContentManagerEvent event) {
if (event.getContent().getComponent() == panel) {
editorFactory.releaseEditor(editor);
contentManager.removeContentManagerListener(this);
}
}
});
}
return content;
}
}

View File

@@ -417,10 +417,18 @@ public class CodeEditUtil {
final int startOffset = first.getStartOffset();
final int endOffset = second.getStartOffset();
final PseudoText pseudoText = pseudoTextBuilder.build(project,
settings,
file);
final boolean oldValue = settings.XML_KEEP_LINE_BREAKS;
settings.XML_KEEP_LINE_BREAKS = false;
return GeneralCodeFormatter.getWhiteSpaceBetweenTokens(pseudoText, settings, fileType, startOffset, endOffset);
try {
final PseudoText pseudoText = pseudoTextBuilder.build(project,
settings,
file);
return GeneralCodeFormatter.getWhiteSpaceBetweenTokens(pseudoText, settings, fileType, startOffset, endOffset);
}
finally {
settings.XML_KEEP_LINE_BREAKS = oldValue;
}
}
}