Exemplo n.º 1
0
  /**
   * Updates the references and project data based on the data in the parsed document.
   *
   * @param monitor Progress monitor
   */
  private void updateReferences(IProgressMonitor monitor) {
    this.updateLabels(parser.getLabels());
    this.updateCommands(parser.getCommands());
    IProject project = getCurrentProject();
    if (project == null) return;
    IFile cFile = ((FileEditorInput) editor.getEditorInput()).getFile();
    boolean isMainFile = cFile.equals(TexlipseProperties.getProjectSourceFile(project));

    pollCancel(monitor);

    // After here we just store those fun properties...
    if (parser.isLocalBib()) {
      TexlipseProperties.setSessionProperty(
          project, TexlipseProperties.SESSION_BIBLATEXLOCALBIB_PROPERTY, new Boolean(true));
    } else {
      TexlipseProperties.setSessionProperty(
          project, TexlipseProperties.SESSION_BIBLATEXLOCALBIB_PROPERTY, null);
    }

    // Only update Preamble, Bibstyle if main Document
    if (isMainFile) {
      boolean biblatexMode = parser.isBiblatexMode();
      updateBiblatex(project, biblatexMode, parser.getBiblatexBackend(), false);

      String[] bibs = parser.getBibs();
      this.updateBibs(bibs, biblatexMode, cFile);

      pollCancel(monitor);

      String preamble = parser.getPreamble();
      if (preamble != null) {
        TexlipseProperties.setSessionProperty(
            project, TexlipseProperties.PREAMBLE_PROPERTY, preamble);
      }
      if (!biblatexMode) {
        String bibstyle = parser.getBibstyle();
        if (bibstyle != null) {
          String oldStyle =
              (String)
                  TexlipseProperties.getSessionProperty(
                      project, TexlipseProperties.BIBSTYLE_PROPERTY);

          if (oldStyle == null || !bibstyle.equals(oldStyle)) {
            TexlipseProperties.setSessionProperty(
                project, TexlipseProperties.BIBSTYLE_PROPERTY, bibstyle);

            // schedule running bibtex on the next build
            TexlipseProperties.setSessionProperty(
                project, TexlipseProperties.BIBFILES_CHANGED, new Boolean(true));
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  /** Creates the reference containers. */
  private void createReferenceContainers() {
    boolean parseAll = false;
    IProject project = getCurrentProject();
    if (project == null) {
      if (bibContainer == null) bibContainer = new ReferenceContainer();
      if (labelContainer == null) labelContainer = new ReferenceContainer();
      if (commandContainer == null) commandContainer = new TexCommandContainer();
      return;
    }
    ReferenceContainer bibCon =
        (ReferenceContainer)
            TexlipseProperties.getSessionProperty(
                project, TexlipseProperties.BIBCONTAINER_PROPERTY);
    if (bibCon == null) {
      bibContainer = new ReferenceContainer();
      TexlipseProperties.setSessionProperty(
          project, TexlipseProperties.BIBCONTAINER_PROPERTY, bibContainer);
      parseAll = true;
    } else {
      bibContainer = bibCon;
    }
    ReferenceContainer labCon =
        (ReferenceContainer)
            TexlipseProperties.getSessionProperty(
                project, TexlipseProperties.LABELCONTAINER_PROPERTY);
    if (labCon == null) {
      labelContainer = new ReferenceContainer();
      TexlipseProperties.setSessionProperty(
          project, TexlipseProperties.LABELCONTAINER_PROPERTY, labelContainer);
      parseAll = true;
    } else {
      labelContainer = labCon;
    }
    TexCommandContainer comCon =
        (TexCommandContainer)
            TexlipseProperties.getSessionProperty(
                project, TexlipseProperties.COMCONTAINER_PROPERTY);
    if (comCon == null) {
      commandContainer = new TexCommandContainer();
      TexlipseProperties.setSessionProperty(
          project, TexlipseProperties.COMCONTAINER_PROPERTY, commandContainer);
      parseAll = true;
    } else {
      commandContainer = comCon;
    }

    if (parseAll) {
      createProjectDatastructs(project);
    }
  }
Exemplo n.º 3
0
 /**
  * Updates the settings for the BibLaTeX package. If this is not the initial run, checks if
  * settings have changed from previous parse job and, if applicable, sets a notification flag for
  * the builder that something has changed.
  *
  * @param project the current project
  * @param biblatexMode true, if biblatex package was found by parser
  * @param biblatexBackend database backend detected by parser, or null
  * @param init whether this is the initial run
  */
 private void updateBiblatex(
     IProject project, boolean biblatexMode, String biblatexBackend, boolean init) {
   if (!init) {
     Boolean oldBLMode =
         (Boolean)
             TexlipseProperties.getSessionProperty(
                 project, TexlipseProperties.SESSION_BIBLATEXMODE_PROPERTY);
     String oldBackend =
         (String)
             TexlipseProperties.getSessionProperty(
                 project, TexlipseProperties.SESSION_BIBLATEXBACKEND_PROPERTY);
     boolean bibChanged;
     if (biblatexMode) {
       if (oldBLMode != null) {
         if (biblatexBackend != null) {
           bibChanged = !biblatexBackend.equals(oldBackend);
         } else {
           bibChanged = oldBLMode == null;
         }
       } else {
         bibChanged = true;
       }
     } else {
       bibChanged = oldBLMode != null;
     }
     if (bibChanged) {
       TexlipseProperties.setSessionProperty(
           project, TexlipseProperties.SESSION_BIBTEX_RERUN, new String("true"));
     }
   }
   if (biblatexMode) {
     TexlipseProperties.setSessionProperty(
         project, TexlipseProperties.SESSION_BIBLATEXMODE_PROPERTY, new Boolean(true));
   } else {
     TexlipseProperties.setSessionProperty(
         project, TexlipseProperties.SESSION_BIBLATEXMODE_PROPERTY, null);
   }
   TexlipseProperties.setSessionProperty(
       project, TexlipseProperties.SESSION_BIBLATEXBACKEND_PROPERTY, biblatexBackend);
 }
Exemplo n.º 4
0
 /** Creates if not exist the ProjectOutline */
 private void createProjectOutline() {
   IProject project = getCurrentProject();
   if (project == null) return;
   Object projectSessionOutLine =
       TexlipseProperties.getSessionProperty(
           project, TexlipseProperties.SESSION_PROJECT_FULLOUTLINE);
   if (projectSessionOutLine != null) projectOutline = (TexProjectOutline) projectSessionOutLine;
   else {
     projectOutline = new TexProjectOutline(getCurrentProject());
     TexlipseProperties.setSessionProperty(
         project, TexlipseProperties.SESSION_PROJECT_FULLOUTLINE, projectOutline);
   }
 }
Exemplo n.º 5
0
  /**
   * Creates all the project data structures. These include the reference completions (BibTeX and
   * label), command completions, the preamble, the BibTeX style.
   *
   * @param project The current project
   */
  private void createProjectDatastructs(IProject project) {
    // IResource resource = ((FileEditorInput)editor.getEditorInput()).getFile();

    IResource[] files = TexlipseProperties.getAllProjectFiles(project);

    if (files != null) {
      IFile mainFile = TexlipseProperties.getProjectSourceFile(project);

      for (int i = 0; i < files.length; i++) {
        // IPath path = files[i].getFullPath();
        String ext = files[i].getFileExtension();
        // here are the file types we want to parse
        if ("tex".equals(ext) || "ltx".equals(ext) || "sty".equals(ext)) {
          try {
            String input = TexlipseProperties.getFileContents(files[i]);
            LatexRefExtractingParser lrep = new LatexRefExtractingParser();
            lrep.parse(input);
            if (lrep.isFatalErrors()) {
              MarkerHandler marker = MarkerHandler.getInstance();
              marker.addFatalError(
                  editor,
                  "The file "
                      + files[i].getFullPath()
                      + " contains fatal errors, parsing aborted.");
              continue;
            }
            List<ReferenceEntry> labels = lrep.getLabels();
            if (labels.size() > 0) {
              labelContainer.addRefSource(files[i].getProjectRelativePath().toString(), labels);
            }
            List<TexCommandEntry> commands = lrep.getCommands();
            if (commands.size() > 0) {
              commandContainer.addRefSource(files[i].getProjectRelativePath().toString(), commands);
            }
            // Only update Preamble, Bibstyle if main Document
            if (files[i].equals(mainFile)) {
              String[] bibs = lrep.getBibs();
              boolean biblatexMode = lrep.isBiblatexMode();
              String biblatexBackend = lrep.getBiblatexBackend();
              this.updateBiblatex(project, biblatexMode, biblatexBackend, true);
              this.updateBibs(bibs, biblatexMode, files[i]);

              String preamble = lrep.getPreamble();
              if (preamble != null) {
                TexlipseProperties.setSessionProperty(
                    project, TexlipseProperties.PREAMBLE_PROPERTY, preamble);
              }

              String bibstyle = lrep.getBibstyle();
              if (bibstyle != null)
                TexlipseProperties.setSessionProperty(
                    project, TexlipseProperties.BIBSTYLE_PROPERTY, bibstyle);
            }
          } catch (IOException ioe) {
            TexlipsePlugin.log(
                "Unable to open file " + files[i].getFullPath() + " for parsing", ioe);
          }
        }
      }
      // save time by doing this last
      labelContainer.organize();
      commandContainer.organize();
    }
  }
Exemplo n.º 6
0
  /**
   * Updates completions for the BibTeX -data
   *
   * @param bibNames Names of the BibTeX -files that the document uses
   * @param resource The resource of the document
   */
  private void updateBibs(String[] bibNames, boolean biblatexMode, IResource resource) {
    IProject project = getCurrentProject();
    if (project == null) return;

    if (!biblatexMode) {
      for (int i = 0; i < bibNames.length; i++) {
        if (!bibNames[i].endsWith(".bib")) {
          bibNames[i] += ".bib";
        }
      }
    }

    if (bibContainer.checkFreshness(bibNames)) {
      return;
    }

    TexlipseProperties.setSessionProperty(project, TexlipseProperties.BIBFILE_PROPERTY, bibNames);

    List<String> newBibs = bibContainer.updateBibHash(bibNames);

    IPath path = resource.getFullPath().removeFirstSegments(1).removeLastSegments(1);
    if (!path.isEmpty()) path = path.addTrailingSeparator();

    KpsewhichRunner filesearch = new KpsewhichRunner();

    for (Iterator<String> iter = newBibs.iterator(); iter.hasNext(); ) {
      String name = iter.next();
      try {
        String filepath = "";
        // First try local search
        IResource res = project.findMember(path + name);
        // Try searching relative to main file
        if (res == null) {
          IContainer sourceDir = TexlipseProperties.getProjectSourceDir(project);
          res = sourceDir.findMember(name);
        }

        if (res != null) {
          filepath = res.getLocation().toOSString();
        }
        if (res == null) {
          // Try Kpsewhich
          filepath = filesearch.getFile(resource, name, "bibtex");
          if (filepath.length() > 0 && !(new File(filepath).isAbsolute())) {
            // filepath is a local path
            res = project.findMember(path + filepath);
            if (res != null) {
              filepath = res.getLocation().toOSString();
            } else {
              filepath = "";
            }
          } else if (filepath.length() > 0) {
            // Create a link to resource
            IPath p = new Path(filepath);
            if (name.indexOf('/') >= 0) {
              // Remove path from name
              name = name.substring(name.lastIndexOf('/') + 1);
            }
            IFile f = project.getFile(path + name);
            if (f != null && !f.exists()) {
              f.createLink(p, IResource.NONE, null);
            }
          }
        }

        if (filepath.length() > 0) {
          BibParser parser = new BibParser(filepath);
          try {
            List<ReferenceEntry> bibEntriesList = parser.getEntries();
            if (bibEntriesList != null && bibEntriesList.size() > 0) {
              bibContainer.addRefSource(path + name, bibEntriesList);
            } else if (bibEntriesList == null) {
              MarkerHandler marker = MarkerHandler.getInstance();
              marker.addFatalError(
                  editor,
                  "The BibTeX file " + filepath + " contains fatal errors, parsing aborted.");
              continue;
            }
          } catch (IOException ioe) {
            TexlipsePlugin.log("Can't read BibTeX file " + filepath, ioe);
          }
        } else {
          MarkerHandler marker = MarkerHandler.getInstance();
          marker.addFatalError(editor, "The BibTeX file " + name + " not found.");
        }

      } catch (CoreException ce) {
        TexlipsePlugin.log("Can't run Kpathsea", ce);
      }
    }
    bibContainer.organize();
  }