/plugins/Jump/trunk/jump/Jump.java

# · Java · 165 lines · 119 code · 42 blank · 4 comment · 27 complexity · f11164878fc3483cc47b42c64576f6dc MD5 · raw file

  1. package jump;
  2. import java.awt.Point;
  3. import java.io.File;
  4. import javax.swing.SwingUtilities;
  5. import org.gjt.sp.jedit.GUIUtilities;
  6. import org.gjt.sp.jedit.View;
  7. import org.gjt.sp.jedit.jEdit;
  8. import org.gjt.sp.jedit.textarea.JEditTextArea;
  9. import projectviewer.ProjectViewer;
  10. import projectviewer.vpt.VPTProject;
  11. public class Jump {
  12. public Jump() {
  13. String s = System.getProperty("file.separator");
  14. File jumpDir = new File(System.getProperty("user.home") + s + ".jedit" +
  15. s + "jump");
  16. if (!jumpDir.exists()) {
  17. jumpDir.mkdirs();
  18. }
  19. }
  20. public boolean isJumpEnabled() {
  21. if (!jEdit.getBooleanProperty("jump.enable", false)) {
  22. GUIUtilities.message(jEdit.getActiveView(), "JumpPlugin.enable",
  23. null);
  24. return false;
  25. }
  26. return true;
  27. }
  28. // Is any active VTProject loaded?
  29. // TODO: this method must be called just once!!!
  30. public boolean isProjectLoaded() {
  31. return null != ProjectViewer.getActiveProject(jEdit.getActiveView());
  32. }
  33. public void showFilesJump() {
  34. // QUESTION: May be view field must be class-field?
  35. View view = jEdit.getActiveView();
  36. if (!check()) return;
  37. ProjectBuffer pb = getProjectBuffer(view);
  38. if (pb.ctagsBuffer != null) {
  39. JumpPlugin.fja.showList();
  40. }
  41. }
  42. public void showTagsJump() {
  43. View view = jEdit.getActiveView();
  44. if (!check()) return;
  45. ProjectBuffer pb = getProjectBuffer(view);
  46. if (pb.ctagsBuffer != null) {
  47. JumpPlugin.tja.showList();
  48. }
  49. }
  50. public void showProjectJump() {
  51. View view = jEdit.getActiveView();
  52. if (!check()) return;
  53. ProjectBuffer pb = getProjectBuffer(view);
  54. if (pb.ctagsBuffer != null) {
  55. JumpPlugin.pja.JumpToTag();
  56. }
  57. }
  58. public void showFoldJump() {
  59. FoldJumpAction foldja = new FoldJumpAction();
  60. foldja.showFoldsList();
  61. }
  62. public void completeTag(boolean isGlobalSearch) {
  63. View view = jEdit.getActiveView();
  64. if (!check()) return;
  65. ProjectBuffer pb = getProjectBuffer(view);
  66. if (pb.ctagsBuffer != null) {
  67. JumpPlugin.pja.completeTag(isGlobalSearch);
  68. }
  69. }
  70. public void reloadTagsOnProject() {
  71. check();
  72. }
  73. public void historyJump() {
  74. View view = jEdit.getActiveView();
  75. if (!check()) return;
  76. ProjectBuffer pb = getProjectBuffer(view);
  77. if (pb.ctagsBuffer != null) {
  78. JumpPlugin.pja.JumpToPreviousTag();
  79. }
  80. }
  81. public void jumpByInput() {
  82. View view = jEdit.getActiveView();
  83. if (!check()) return;
  84. ProjectBuffer pb = getProjectBuffer(view);
  85. if (pb.ctagsBuffer != null) {
  86. JumpPlugin.pja.JumpToTagByInput();
  87. }
  88. }
  89. public static Point getListLocation() {
  90. JEditTextArea textArea = jEdit.getActiveView().getTextArea();
  91. textArea.scrollToCaret(false);
  92. int caret = textArea.getCaretPosition();
  93. //String sel = textArea.getSelectedText();
  94. Point location = textArea.offsetToXY(caret);
  95. location.y += textArea.getPainter().getFontMetrics().getHeight();
  96. SwingUtilities.convertPointToScreen(location, textArea.getPainter());
  97. return location;
  98. }
  99. private boolean check() {
  100. if (!isJumpEnabled()) {
  101. return false;
  102. }
  103. if (!isProjectLoaded()) {
  104. return false;
  105. }
  106. if (!JumpPlugin.isListenerAdded) {
  107. JumpPlugin.init();
  108. }
  109. return true;
  110. }
  111. private ProjectBuffer getProjectBuffer(View view) {
  112. JumpPlugin.getListener().reloadProjectForced();
  113. if (JumpPlugin.getActiveProjectBuffer() != null) {
  114. return JumpPlugin.getActiveProjectBuffer();
  115. } else {
  116. VPTProject activep = ProjectViewer.getActiveProject(view);
  117. ProjectBuffer b = new ProjectBuffer(activep.getName());
  118. b.init(activep);
  119. JumpPlugin.setActiveProjectBuffer(b);
  120. return b;
  121. }
  122. }
  123. }