Changeset 958

Show
Ignore:
Timestamp:
01/14/11 23:59:28 (2 years ago)
Author:
stefan
Message:

mark invalid files after \bibliography red + enable quick jump to bib entries

Location:
trunk
Files:
7 modified
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/data/codehelper/commands.xml

    r904 r958  
    136136 
    137137  <command name="\bibliography" usage="\bibliography{@file@}" hint="set bibliography file"> 
    138     <argument name="file" value="" completion="true" hint="filename of the bibliography file"/> 
     138    <argument name="file" type="file" value="" completion="true" hint="filename of the bibliography file"/> 
    139139  </command> 
    140140 
  • trunk/src/jlatexeditor/codehelper/BackgroundParser.java

    r943 r958  
    2727 
    2828  private long bibModified = 0; 
    29   private ArrayList<BibEntry> bibEntries = new ArrayList<BibEntry>(); 
     29  private ArrayList<FilePos<BibEntry>> bibEntries = new ArrayList<FilePos<BibEntry>>(); 
    3030 
    3131  private HashSet<File> files = new HashSet<File>(); 
     
    3535  private Trie<FilePos> labelDefs = new Trie<FilePos>(); 
    3636  private Trie<FilePos> labelRefs = new Trie<FilePos>(); 
    37   private Trie<BibEntry> cites = new Trie<BibEntry>(); 
     37  private Trie<FilePos<BibEntry>> cites = new Trie<FilePos<BibEntry>>(); 
    3838 
    3939  private DefaultTreeModel structure = new DefaultTreeModel(new DefaultMutableTreeNode()); 
     
    4747  } 
    4848 
    49   public ArrayList<BibEntry> getBibEntries() { 
     49  public ArrayList<FilePos<BibEntry>> getBibEntries() { 
    5050    return bibEntries; 
    5151  } 
     
    7171  } 
    7272 
    73   public Trie<BibEntry> getCites() { 
     73  public Trie<FilePos<BibEntry>> getCites() { 
    7474    return cites; 
    7575  } 
     
    279279 
    280280    bibEntries = BibParser.parseBib(bibFile); 
    281     cites = new Trie<BibEntry>(); 
    282     for (BibEntry bibEntry : bibEntries) { 
    283       cites.add(bibEntry.getEntryName(), bibEntry); 
     281    cites = new Trie<FilePos<BibEntry>>(); 
     282    for (FilePos<BibEntry> bibEntry : bibEntries) { 
     283      cites.add(bibEntry.getName(), bibEntry); 
    284284    } 
    285285  } 
     
    289289    ArrayList<BibEntry> entries = new ArrayList<BibEntry>(); 
    290290 
    291     for (BibEntry entry : bibEntries) { 
     291    for (FilePos<BibEntry> entry : bibEntries) { 
    292292      boolean all = true; 
    293293      for (String key : keys) { 
    294         if (entry.getText().toLowerCase().indexOf(key) == -1) { 
     294        if (entry.getElement().getText().toLowerCase().indexOf(key) == -1) { 
    295295          all = false; 
    296296          break; 
    297297        } 
    298298      } 
    299       if (all) entries.add(entry); 
     299      if (all) entries.add(entry.getElement()); 
    300300    } 
    301301 
     
    329329  } 
    330330 
    331   public static class FilePos extends DefaultMutableTreeNode { 
     331  public static class FilePos<E> extends DefaultMutableTreeNode { 
    332332    private String name; 
    333333 
    334334    private String file; 
    335335    private int lineNr; 
     336 
     337    private E element; 
    336338 
    337339    public FilePos(String name, String file, int lineNr) { 
     
    341343    } 
    342344 
     345    public FilePos(String name, String file, int lineNr, E element) { 
     346      super(element); 
     347      this.name = name; 
     348      this.file = file; 
     349      this.lineNr = lineNr; 
     350      this.element = element; 
     351    } 
     352 
    343353    public String getName() { 
    344354      return name; 
     
    351361    public int getLineNr() { 
    352362      return lineNr; 
     363    } 
     364 
     365    public E getElement() { 
     366      return element; 
    353367    } 
    354368 
  • trunk/src/jlatexeditor/codehelper/BibParser.java

    r744 r958  
    1212 */ 
    1313public class BibParser { 
    14   public static ArrayList<BibEntry> parseBib(File file) { 
    15     ArrayList<BibEntry> results = new ArrayList<BibEntry>(); 
     14  public static ArrayList<BackgroundParser.FilePos<BibEntry>> parseBib(File file) { 
     15    ArrayList<BackgroundParser.FilePos<BibEntry>> results = new ArrayList<BackgroundParser.FilePos<BibEntry>>(); 
    1616 
    1717    String bib; 
     
    2222    } 
    2323 
     24    int lineNr = 0; 
     25    int lastAt = 0; 
    2426    int at = -1; 
    2527    while ((at = bib.indexOf("@", at + 1)) != -1) { 
     28      lineNr += countNewLinesBetween(bib, lastAt, at); 
     29 
    2630      int openBracket = bib.indexOf('{', at); 
    2731      if (openBracket == -1) break; 
     
    3640 
    3741      BibEntry entry = new BibEntry(); 
     42      BackgroundParser.FilePos<BibEntry> filePos = new BackgroundParser.FilePos<BibEntry>(name, file.getAbsolutePath(), lineNr, entry); 
    3843 
    3944      int index = comma + 1; 
     
    6065                      entry.getYear() 
    6166      ); 
    62       results.add(entry); 
     67      results.add(filePos); 
     68 
     69      lastAt = at; 
    6370    } 
    6471 
     
    6673  } 
    6774 
    68   private static String removeBraces(String string) { 
     75  private static int countNewLinesBetween(String bib, int start, int end) { 
     76    int count = 0; 
     77    for (int i = start; i < end; i++) { 
     78      if (bib.charAt(i) == '\n') count++; 
     79    } 
     80    return count; 
     81  } 
     82 
     83  private static String removeBraces(String string) { 
    6984    if (string.startsWith("{") || string.startsWith("\"")) string = string.substring(1); 
    7085    if (string.endsWith("}") || string.endsWith("\"")) string = string.substring(0, string.length() - 1); 
  • trunk/src/jlatexeditor/codehelper/JumpTo.java

    r898 r958  
    8686            return; 
    8787          } 
     88        } else 
     89        if (command.equals("cite")) { 
     90          BackgroundParser.FilePos filePos = backgroundParser.getCites().get(word.word); 
     91          if (filePos != null) { 
     92            jLatexEditorJFrame.open(new FileDoc(new File(filePos.getFile())), filePos.getLineNr()); 
     93            return; 
     94          } 
    8895        } 
    8996      } 
  • trunk/src/jlatexeditor/JLatexEditorJFrame.java

    r955 r958  
    12131213              ""); 
    12141214      if (message != null) { 
    1215         Pair<Boolean, String> result = null; 
     1215        Tuple<Boolean, String> result = null; 
    12161216        try { 
    12171217          result = SVN.getInstance().commit(getMainEditor().getFile().getParentFile(), message); 
  • trunk/src/jlatexeditor/tools/SVN.java

    r835 r958  
    11package jlatexeditor.tools; 
    22 
    3 import util.Pair; 
     3import util.Tuple; 
    44import util.ProcessUtil; 
    55import util.StreamUtils; 
     
    6262  } 
    6363 
    64   public synchronized Pair<Boolean, String> commit(File dir, String message) throws Exception { 
     64  public synchronized Tuple<Boolean, String> commit(File dir, String message) throws Exception { 
    6565    message = message.replace('"', ' '); 
    6666    message = message.replace('\\', ' '); 
     
    9292    checkProcessResult(svn, "SVN update"); 
    9393 
    94     return new Pair<Boolean, String>(success, builder.toString()); 
     94    return new Tuple<Boolean, String>(success, builder.toString()); 
    9595  } 
    9696 
  • trunk/src/sce/codehelper/CodeHelperPane.java

    r941 r958  
    22 
    33import sce.component.*; 
    4 import util.Pair; 
     4import util.Tuple; 
    55 
    66import javax.swing.*; 
     
    224224 
    225225    // set the caret position and remove it from template 
    226     Pair<String, SCEDocumentPosition> pair = getTransformedTemplate(templateWithAt, arguments, row, column); 
     226    Tuple<String, SCEDocumentPosition> pair = getTransformedTemplate(templateWithAt, arguments, row, column); 
    227227    templateWithAt = pair.first; 
    228228 
     
    303303  } 
    304304 
    305   private Pair<String, SCEDocumentPosition> getTransformedTemplate(String templateWithAt, ArrayList<CHCommandArgument> arguments, int row, int column) { 
     305  private Tuple<String, SCEDocumentPosition> getTransformedTemplate(String templateWithAt, ArrayList<CHCommandArgument> arguments, int row, int column) { 
    306306    int cursorIndex = templateWithAt.lastIndexOf("@|@"); 
    307307    if (cursorIndex != -1) { 
     
    324324    } 
    325325 
    326     return new Pair<String,SCEDocumentPosition>(templateWithAt, document.createDocumentPosition(caret_row, caret_column)); 
     326    return new Tuple<String,SCEDocumentPosition>(templateWithAt, document.createDocumentPosition(caret_row, caret_column)); 
    327327  } 
    328328 
  • trunk/src/util/Tuple.java

    r744 r958  
    11package util; 
    22 
    3 public class Pair<S, T> { 
     3public class Tuple<S, T> { 
    44  public S first; 
    55  public T second; 
    66 
    7   public Pair(S first, T second) { 
     7  public Tuple(S first, T second) { 
    88    this.first = first; 
    99    this.second = second;