Changeset 917


Ignore:
Timestamp:
Nov 4, 2010, 11:02:23 AM (7 years ago)
Author:
joerg
Message:
 
Location:
trunk/src/jlatexeditor
Files:
2 edited

Legend:

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

    r916 r917  
    4646import java.beans.PropertyChangeListener;
    4747import java.io.*;
     48import java.net.ServerSocket;
     49import java.net.Socket;
    4850import java.net.URI;
    4951import java.util.*;
     
    346348    GProperties.addPropertyChangeListener("editor.font.size", fontChangeListener);
    347349    GProperties.addPropertyChangeListener("editor.font.antialiasing", fontChangeListener);
     350
     351    // inverse search
     352    new Seek(GProperties.getInt("inverse search.port")).start();
    348353  }
    349354
     
    356361      String line;
    357362      while ((line = reader.readLine()) != null) {
    358         int colon = line.lastIndexOf(':');
    359         if (colon == -1) colon = line.length();
    360 
    361         File file = new File(line.substring(0, colon));
    362         int lineNr = colon >= line.length() ? 0 : Integer.parseInt(line.substring(colon + 1));
    363 
    364         if (file.exists() && file.isFile()) {
    365           SourceCodeEditor<Doc> editor = open(new Doc.FileDoc(file));
    366           editor.getTextPane().getCaret().moveTo(lineNr, 0);
    367         }
     363       openSeek(line);
    368364      }
    369365      reader.close();
    370366    } catch (IOException ignored) {
     367    }
     368  }
     369
     370  private void openSeek(String seek) {
     371    int colon = seek.lastIndexOf(':');
     372    if (colon == -1) colon = seek.length();
     373
     374    File file = new File(seek.substring(0, colon));
     375    int lineNr = colon >= seek.length() ? 0 : Integer.parseInt(seek.substring(colon + 1));
     376
     377    if (file.exists() && file.isFile()) {
     378      SourceCodeEditor<Doc> editor = open(new Doc.FileDoc(file));
     379      editor.getTextPane().getCaret().moveTo(lineNr, 0);
    371380    }
    372381  }
     
    10211030    if (action.startsWith("forward search: ")) {
    10221031      String command = action.substring("forward search: ".length());
    1023       GProperties.set("viewer.forward search", command);
     1032      GProperties.set("forward search.viewer", command);
    10241033    } else
    10251034
     
    10321041        String file = mainFile.substring(0, mainFile.lastIndexOf(".tex"));
    10331042
    1034         ArrayList<String> list = StringUtils.tokenize(GProperties.getString("viewer.forward search"));
     1043        ArrayList<String> list = StringUtils.tokenize(GProperties.getString("forward search.viewer"));
    10351044        String[] array = new String[list.size()];
    10361045        list.toArray(array);
     
    15911600
    15921601    // SCEModificationStateListener
    1593 
    15941602    public void modificationStateChanged(boolean modified) {
    15951603      label.setText(modified ? "*" + doc.getName() : doc.getName());
     
    15971605  }
    15981606
     1607  // inverse search
     1608  private class Seek extends Thread {
     1609    private int port;
     1610
     1611    public Seek(int port) {
     1612      this.port = port;
     1613      this.setDaemon(true);
     1614    }
     1615
     1616    public void run() {
     1617      try {
     1618        ServerSocket server = new ServerSocket(port);
     1619
     1620        while(true) {
     1621          Socket socket = server.accept();
     1622          BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
     1623          String seek = reader.readLine();
     1624          System.out.println(seek);
     1625          if(seek != null) openSeek(seek);
     1626          reader.close();
     1627          socket.close();
     1628        }
     1629      } catch (IOException e) {
     1630        e.printStackTrace();
     1631      }
     1632    }
     1633  }
    15991634}
  • trunk/src/jlatexeditor/gproperties/GProperties.java

    r911 r917  
    192192    properties.addEntry(new Def("compiler.latex.parameters", STRING, "--src-specials"));
    193193    properties.addEntry(new Comment(" forward search"));
    194     properties.addEntry(new Def("viewer.forward search", STRING, ""));
     194    properties.addEntry(new Def("forward search.viewer", STRING, ""));
     195    properties.addEntry(new Def("inverse search.port", INT, "7001"));
    195196
    196197    load();
Note: See TracChangeset for help on using the changeset viewer.