1 package com
.intellij
.openapi
.wm
.impl
.status
;
3 import com
.intellij
.ide
.DataManager
;
4 import com
.intellij
.ide
.util
.GotoLineNumberDialog
;
5 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
6 import com
.intellij
.openapi
.command
.CommandProcessor
;
7 import com
.intellij
.openapi
.editor
.Editor
;
8 import com
.intellij
.openapi
.editor
.LogicalPosition
;
9 import com
.intellij
.openapi
.editor
.SelectionModel
;
10 import com
.intellij
.openapi
.fileEditor
.FileEditorManager
;
11 import com
.intellij
.openapi
.fileEditor
.ex
.IdeDocumentHistory
;
12 import com
.intellij
.openapi
.project
.Project
;
13 import com
.intellij
.openapi
.wm
.StatusBar
;
14 import com
.intellij
.ui
.UIBundle
;
17 import java
.awt
.event
.MouseAdapter
;
18 import java
.awt
.event
.MouseEvent
;
20 class PositionPanel
extends TextPanel
implements StatusBarPatch
{
21 public PositionPanel(StatusBar statusBar
) {
22 super(false, "#############");
24 addMouseListener(new MouseAdapter() {
25 public void mouseClicked(final MouseEvent e
) {
26 if (e
.getClickCount() == 2) {
27 final Project project
= getProject();
28 if (project
== null) return;
29 final Editor editor
= getEditor(project
);
30 if (editor
== null) return;
31 final CommandProcessor processor
= CommandProcessor
.getInstance();
32 processor
.executeCommand(
33 project
, new Runnable(){
35 final GotoLineNumberDialog dialog
= new GotoLineNumberDialog(project
, editor
);
37 IdeDocumentHistory
.getInstance(project
).includeCurrentCommandAsNavigation();
40 UIBundle
.message("go.to.line.command.name"),
47 StatusBarTooltipper
.install(this, statusBar
);
50 public JComponent
getComponent() {
54 public String
updateStatusBar(final Editor editor
, final JComponent componentSelected
) {
56 SwingUtilities
.invokeLater(new Runnable() {
58 if (!editor
.isDisposed()) {
59 StringBuilder message
= new StringBuilder();
61 SelectionModel selectionModel
= editor
.getSelectionModel();
62 if (selectionModel
.hasBlockSelection()) {
63 LogicalPosition start
= selectionModel
.getBlockStart();
64 LogicalPosition end
= selectionModel
.getBlockEnd();
65 appendLogicalPosition(start
, message
);
67 appendLogicalPosition(new LogicalPosition(Math
.abs(end
.column
- start
.column
) - 1, Math
.abs(end
.line
- start
.line
)), message
);
70 LogicalPosition caret
= editor
.getCaretModel().getLogicalPosition();
72 appendLogicalPosition(caret
, message
);
73 if (selectionModel
.hasSelection()) {
74 int len
= Math
.abs(selectionModel
.getSelectionStart() - selectionModel
.getSelectionEnd());
80 setText(message
.toString());
84 return UIBundle
.message("go.to.line.command.double.click");
90 private static void appendLogicalPosition(LogicalPosition caret
, StringBuilder message
) {
91 message
.append(caret
.line
+ 1);
93 message
.append(caret
.column
+ 1);
100 private static Editor
getEditor(final Project project
) {
101 return FileEditorManager
.getInstance(project
).getSelectedTextEditor();
104 private Project
getProject() {
105 return PlatformDataKeys
.PROJECT
.getData(DataManager
.getInstance().getDataContext(this));