Changeset 918


Ignore:
Timestamp:
Nov 4, 2010, 11:55:46 PM (7 years ago)
Author:
stefan
Message:

towards feature #122: implement inverse search

Location:
trunk/src/jlatexeditor
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/JLatexEditorJFrame.java

    r917 r918  
    1919import jlatexeditor.gui.*;
    2020import jlatexeditor.quickhelp.LatexQuickHelp;
     21import jlatexeditor.remote.NetworkNode;
    2122import jlatexeditor.syntaxhighlighting.LatexStyles;
    2223import jlatexeditor.syntaxhighlighting.LatexSyntaxHighlighting;
     
    350351
    351352    // inverse search
    352     new Seek(GProperties.getInt("inverse search.port")).start();
     353    //new Seek(GProperties.getInt("inverse search.port")).start();
     354    new NetworkNode(this).start();
    353355  }
    354356
     
    715717  public SourceCodeEditor<Doc> open(Doc doc, int lineNr) {
    716718    SourceCodeEditor<Doc> editor = open(doc);
    717     editor.getTextPane().getCaret().moveTo(lineNr, 0);
     719    if (lineNr > 0) {
     720      editor.getTextPane().getCaret().moveTo(lineNr, 0);
     721    }
    718722
    719723    return editor;
     
    892896  private void closeTab(int tab) {
    893897    SourceCodeEditor<Doc> editor = getEditor(tab);
    894     if (tabbedPane.getTabCount() > 1) {
     898    docMap.remove(editor.getResource().getUri());
     899    if (tabbedPane.getTabCount() > 1) {
    895900      tabbedPane.removeTabAt(tab);
    896901    } else {
     
    904909  }
    905910
    906   // ActionListener methods
     911  public boolean isOpen(File file) {
     912    return docMap.containsKey(file.toURI());
     913  }
     914
     915  /**
     916   * Returns true if this JLE instance is responsible for the given file.
     917   *
     918   * @param file file
     919   * @return true if this JLE instance is responsible for the given file
     920   */
     921  public boolean isResponsibleFor(File file) {
     922    // did we open the file already?                  or is file referenced by the main document?
     923    return isOpen(file) || backgroundParser.isResponsibleFor(file);
     924  }
     925
     926  @Override
     927  public void requestFocus() {
     928    super.requestFocus();
     929    getActiveEditor().getFocusedPane().requestFocus();
     930  }
     931
     932  // ActionListener methods
    907933
    908934  public void actionPerformed(ActionEvent e) {
     
    13991425  }
    14001426
    1401   private class ShutdownHook extends Thread {
     1427  private class ShutdownHook extends Thread {
    14021428    private JLatexEditorJFrame mainWindow;
    14031429
  • trunk/src/jlatexeditor/codehelper/BackgroundParser.java

    r898 r918  
    2929  private ArrayList<BibEntry> bibEntries = new ArrayList<BibEntry>();
    3030
     31  private HashSet<File> files = new HashSet<File>();
    3132  private Trie<? extends Object> words = new Trie<Object>();
    3233  private Trie<FilePos> commandNames = new Trie<FilePos>();
     
    4041  private ArrayList<TODO> todos = new ArrayList<TODO>();
    4142
    42   public BackgroundParser(JLatexEditorJFrame jle) {
     43  public BackgroundParser(JLatexEditorJFrame jle) {
    4344    super("BackgroundParser");
    4445    this.jle = jle;
     
    9394      File directory = file.getParentFile();
    9495
     96      HashSet<File> files = new HashSet<File>();
    9597      Trie words = new Trie();
    9698      Trie<FilePos> commandNames = new Trie<FilePos>();
     
    102104      structureStack.add(new StructureEntry("Project", 0, resource.getName(), 0));
    103105
    104       parseTex(directory, file.getName(), words, commandNames, commands, labelDefs, labelRefs, structureStack, new HashSet<String>());
    105 
     106      parseTex(directory, file.getName(), files, words, commandNames, commands, labelDefs, labelRefs, structureStack, new HashSet<String>());
     107
     108      this.files = files;
    106109      this.words = words;
    107110      this.commandNames = commandNames;
     
    124127  }
    125128
    126   private void parseTex(File directory, String fileName, Trie words, Trie<FilePos> commandNames, Trie<Command> commands,
     129  private void parseTex(File directory, String fileName, HashSet<File> files, Trie words, Trie<FilePos> commandNames, Trie<Command> commands,
    127130                        Trie<FilePos> labelDefs, Trie<FilePos> labelRefs, ArrayList<StructureEntry> structure, HashSet<String> done) {
    128131    if (done.contains(fileName)) return;
     
    132135    if (!file.exists()) file = new File(directory, fileName + ".tex");
    133136    if (!file.exists()) return;
     137
     138    files.add(file);
    134139
    135140    String tex;
     
    225230          parseBib(directory, Command.unfoldRecursive(argument, commands, 10));
    226231        } else {
    227           parseTex(directory, Command.unfoldRecursive(argument, commands, 10), words, commandNames, commands, labelDefs, labelRefs, structure, done);
     232          parseTex(directory, Command.unfoldRecursive(argument, commands, 10), files, words, commandNames, commands, labelDefs, labelRefs, structure, done);
    228233        }
    229234      // sections
     
    294299  }
    295300
    296   public static class TODO {
     301  /**
     302   * Returns true if the file is referenced by the master document.
     303   *
     304   * @param file file
     305   * @return true if the file is referenced by the master document
     306   */
     307  public boolean isResponsibleFor(File file) {
     308    return files.contains(file);
     309  }
     310
     311  public static class TODO {
    297312    private String msg;
    298313    private File file;
  • trunk/src/jlatexeditor/gproperties/GProperties.java

    r917 r918  
    193193    properties.addEntry(new Comment(" forward search"));
    194194    properties.addEntry(new Def("forward search.viewer", STRING, ""));
    195     properties.addEntry(new Def("inverse search.port", INT, "7001"));
     195    properties.addEntry(new Def("inverse search.port", INT_GT_0, "13231"));
    196196
    197197    load();
Note: See TracChangeset for help on using the changeset viewer.