PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/search/BufferListSet.java

#
Java | 141 lines | 82 code | 19 blank | 40 comment | 32 complexity | cad39c84122ed9f0df4378866cfb0ac7 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * BufferListSet.java - Buffer list matcher
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1999, 2004 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.search;
  23. //{{{ Imports
  24. import java.awt.Component;
  25. import org.gjt.sp.jedit.*;
  26. import org.gjt.sp.jedit.io.*;
  27. //}}}
  28. /**
  29. * A file set for searching a user-specified list of buffers.
  30. * @author Slava Pestov
  31. * @version $Id: BufferListSet.java 5343 2006-02-10 07:52:11Z spestov $
  32. */
  33. public abstract class BufferListSet implements SearchFileSet
  34. {
  35. //{{{ getFirstFile() method
  36. public synchronized String getFirstFile(View view)
  37. {
  38. if(files == null)
  39. files = _getFiles(view);
  40. if(files == null || files.length == 0)
  41. return null;
  42. else
  43. return files[0];
  44. } //}}}
  45. //{{{ getNextFile() method
  46. public synchronized String getNextFile(View view, String file)
  47. {
  48. if(files == null)
  49. files = _getFiles(view);
  50. if(files == null || files.length == 0)
  51. return null;
  52. if(file == null)
  53. {
  54. file = view.getBuffer().getSymlinkPath();
  55. VFS vfs = VFSManager.getVFSForPath(file);
  56. boolean ignoreCase = ((vfs.getCapabilities()
  57. & VFS.CASE_INSENSITIVE_CAP) != 0);
  58. for(int i = 0; i < files.length; i++)
  59. {
  60. if(MiscUtilities.compareStrings(
  61. files[i],file,ignoreCase) == 0)
  62. {
  63. return file;
  64. }
  65. }
  66. return getFirstFile(view);
  67. }
  68. else
  69. {
  70. // -1 so that the last isn't checked
  71. VFS vfs = VFSManager.getVFSForPath(file);
  72. boolean ignoreCase = ((vfs.getCapabilities()
  73. & VFS.CASE_INSENSITIVE_CAP) != 0);
  74. for(int i = 0; i < files.length - 1; i++)
  75. {
  76. if(MiscUtilities.compareStrings(
  77. files[i],file,ignoreCase) == 0)
  78. {
  79. return files[i+1];
  80. }
  81. }
  82. return null;
  83. }
  84. } //}}}
  85. //{{{ getFiles() method
  86. public synchronized String[] getFiles(View view)
  87. {
  88. if(files == null)
  89. files = _getFiles(view);
  90. if(files == null || files.length == 0)
  91. return null;
  92. else
  93. return files;
  94. } //}}}
  95. //{{{ getFileCount() method
  96. public synchronized int getFileCount(View view)
  97. {
  98. if(files == null)
  99. files = _getFiles(view);
  100. if(files == null)
  101. return 0;
  102. else
  103. return files.length;
  104. } //}}}
  105. //{{{ getCode() method
  106. public String getCode()
  107. {
  108. // not supported for arbitriary filesets
  109. return null;
  110. } //}}}
  111. //{{{ invalidateCachedList() method
  112. public void invalidateCachedList()
  113. {
  114. files = null;
  115. } //}}}
  116. /**
  117. * Note that the paths in the returned list must be
  118. * fully canonicalized.
  119. */
  120. protected abstract String[] _getFiles(Component comp);
  121. private String[] files;
  122. }