jEdit Community - Resources for users of the jEdit Text Editor
ToggleHeaderSource.bsh 0.4 (Toggle_Header_Source.bsh v0.4 by Alan Ezust)
Submitted by AlanEzust on Wednesday, 9 November, 2005 - 15:09
A jedit beanshell macro that toggles your current buffer between the header file (.h) and the source file (.cpp). Enables you to switch the current text buffer between c++ header and sourcecode file. If the file does not already exist, it opens a buffer of that name for you (!). Version 0.4 also works with other filename extensions (.c, .cxx).

Updated on 11/09/2005 - 15:09
Downloads: 1112

Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
added some stuff
by HolyBastard on Wed, 16/11/2005 - 19:34
I changed the following so it will use the same mecanism to find the header file (some header files are named .hpp. I also adde .C as a source extension
String[] sourceExtensions = new String[]{"C", "cpp", "c", "cxx" };
String[] headerExtensions = new String[]{"h", "hpp"};

String defaultSourceExtension = "C";
String defaultHeaderExtension = "h";

String getSourceFile(String baseName, String[] extensions)
{
  int numExt = extensions.length;
  String tryFile = null;
  for (int i=numExt-1; i>=0; --i)
  {
    String ext = extensions[i];
    String tryFile = baseName + "." + ext;
    File f = new File(tryFile);
    if (f.canRead()) return f.getPath();
  }
  return baseName + "." + defaultSourceExtension;
}

boolean isFileType(String extension, String[] extensions)
{
  for (int i=0; i<extensions.length; ++i) {
    if (extension.equals(extensions[i])) return true;
  }
  return false;
}

void toggleHeaderSource()
{

  String currentFile = buffer.getPath();
  int pos = currentFile.lastIndexOf('.');
  String extension = currentFile.substring(pos+1);
  String baseName = currentFile.substring(0, pos);
  if (isFileType(extension, sourceExtensions))
  {
    String sourceFile = getSourceFile(baseName,headerExtensions);
    jEdit.openFile(view, baseName + ".h");
  }
  else if (isFileType(extension, headerExtensions) ) {

    String sourceFile = getSourceFile(baseName,sourceExtensions);
    jEdit.openFile(view, sourceFile);
  }
}

toggleHeaderSource();
User login
Browse archives
« March 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   82338
Context Free Art (*.cfdg)   0.31   46043
JBuilder scheme   .001   18487
BBEdit scheme   1.0   18108
ColdFusion scheme   1.0   18015
R Edit Mode - extensive version   0.1   17461
Advanced HTML edit mode   1.0   16194
Matlab Edit Mode   1.0   16057
jEdit XP icons   1.0   15220
XP icons for jEdit   1.1   14281