Changeset 1445


Ignore:
Timestamp:
May 11, 2012, 12:08:19 AM (5 years ago)
Author:
joerg
Message:

improved comment removal, space after % is no longer required for uncomment

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/addon/RenameElement.java

    r1324 r1445  
    145145  }
    146146
    147   private void backgroundParserUpdate(JLatexEditorJFrame jle) {
     147  public static void backgroundParserUpdate(JLatexEditorJFrame jle) {
    148148    // let parser finish current run (user might have changes)
    149149    backgroundParserWaitFor(jle);
     
    153153  }
    154154
    155   private boolean backgroundParserWaitFor(JLatexEditorJFrame jle) {
     155  public static boolean backgroundParserWaitFor(JLatexEditorJFrame jle) {
    156156    // wait for background parser to finish
    157157    try {
     
    164164  }
    165165
    166   private void renameBibRef(JLatexEditorJFrame jle, String oldRef) {
     166  public static void renameBibRef(JLatexEditorJFrame jle, String oldRef) {
    167167      // start background parser to update document states
    168168      backgroundParserUpdate(jle);
     
    184184  }
    185185
    186   private void replaceInAllFiles(JLatexEditorJFrame jle, List<BackgroundParser.FilePos> filePoses, String from, String to, boolean everywhere) {
     186  public static void replaceInAllFiles(JLatexEditorJFrame jle, List<BackgroundParser.FilePos> filePoses, String from, String to, boolean everywhere) {
    187187    HashSet<File> files = new HashSet<File>();
    188188
     
    199199  }
    200200
    201   private void replaceInAllFiles(JLatexEditorJFrame jle, HashSet<File> files, String from, String to, boolean everywhere) {
     201  public static void replaceInAllFiles(JLatexEditorJFrame jle, HashSet<File> files, String from, String to, boolean everywhere) {
    202202    // put them into a set
    203203    HashSet<SourceCodeEditor<Doc>> editors = new HashSet<SourceCodeEditor<Doc>>();
  • trunk/src/jlatexeditor/bib/BibAssistant.java

    r1444 r1445  
    2525 */
    2626public class BibAssistant implements CodeAssistant, SCEPopup.ItemHandler {
    27   PatternPair authorPattern = new PatternPair("(?:^| and )(?:(?! and ) )*((?:(?! and ).)*?)", true, "(.*?)(?:$| and$| and )");
     27  private PatternPair authorPattern = new PatternPair("(?:^| and )(?:(?! and ) )*((?:(?! and ).)*?)", true, "(.*?)(?:$| and$| and )");
     28  private String[] valueOrder = new String[] {
     29          "author", "title",
     30          "booktitle",
     31          "journal", "volume", "number",
     32          "editor",
     33          "pages",
     34          "institution",
     35          "publisher", "series",
     36          "month", "year",
     37          "edition",
     38          "note",
     39          "address",
     40          "isbn","issn","doi","ee"
     41  };
    2842
    2943  public BibAssistant() {
     
    106120    for(BibEntry stringEntry : stringEntries) {
    107121      if(stringEntry.getName().isEmpty()) continue;
    108       String stringValue = stringEntry.getAllParameters().get(stringEntry.getName()).getValuesString();
     122      String stringValue = stringEntry.getAllParameters().get(stringEntry.getName().toLowerCase()).getValuesString();
    109123
    110124      int common = lcs(word.word, stringValue);
     
    120134      if(weightedEntries.isEmpty()) break;
    121135      BibEntry entry = weightedEntries.remove(weightedEntries.size()-1).element;
    122       list.add(new ReplaceByAction(word.word, entry.getName(), entry.getAllParameters().get(entry.getName()).getValuesString(), pane));
     136      list.add(new ReplaceByAction(word.word, entry.getName(), entry.getAllParameters().get(entry.getName().toLowerCase()).getValuesString(), pane));
    123137    }
    124138
  • trunk/src/jlatexeditor/bib/BibEntry.java

    r1444 r1445  
    11package jlatexeditor.bib;
    22
     3import sce.codehelper.WordWithPos;
    34import sce.component.SCEDocumentPosition;
    45
     
    1011
    1112  private String type = null;
    12   private String name = "";
     13  private WordWithPos name = new WordWithPos("", 0,0);
    1314  private HashMap<String,BibKeyValuePair> parameters = new HashMap<String, BibKeyValuePair>();
    1415  private HashMap<String,BibKeyValuePair> allParameters = new HashMap<String, BibKeyValuePair>();
     
    4748
    4849  public String getName() {
     50    return name.word;
     51  }
     52
     53  public WordWithPos getNameWithPos() {
    4954    return name;
    5055  }
    5156
    52   public void setName(String name) {
     57  public void setName(WordWithPos name) {
    5358    this.name = name;
    5459  }
  • trunk/src/jlatexeditor/bib/BibSyntaxHighlighting.java

    r1444 r1445  
    231231          BibKeyValuePair value = state.getValue();
    232232          if(value != null && value.getKey() != null) {
    233             entry.getParameters().put(value.getKey().word, value);
     233            entry.getParameters().put(value.getKey().word.toLowerCase(), value);
    234234          }
    235235
     
    249249        char delimiter[] = COMMA_OR_BRACKET;
    250250        String entryName = LatexSyntaxHighlighting.getUntil(row, char_nr, delimiter);
    251         state.getEntry().setName(entryName);
     251        state.getEntry().setName(new WordWithPos(entryName, new SCEDocumentPosition(sce_char)));
    252252        if(c == ',' || entryName == null) {
    253253          sce_char.style = stateStyles[LatexStyles.TEXT];
     
    294294        BibKeyValuePair value = state.getValue();
    295295        if(value != null && value.getKey() != null) {
    296           state.getEntry().getParameters().put(value.getKey().word, value);
     296          state.getEntry().getParameters().put(value.getKey().word.toLowerCase(), value);
    297297        }
    298298
     
    316316          // non-existing key
    317317          if(!entry.getAll().contains(keyLower)) {
    318             entryStyle = stateStyles[LatexStyles.ERROR];
     318            entryStyle = stateStyles[LatexStyles.COMMENT];
    319319          }
    320320        }
     
    322322        boolean isString = state.getEntry().getType().toLowerCase().equals("string");
    323323        if(isString) {
    324           state.getEntry().setName(key);
     324          state.getEntry().setName(new WordWithPos(key, new SCEDocumentPosition(sce_char)));
    325325
    326326          // check whether entry name is in use
     
    339339        BibKeyValuePair value = new BibKeyValuePair();
    340340        value.setKey(new WordWithPos(key, new SCEDocumentPosition(sce_char)));
    341         state.getEntry().getParameters().put(key, value);
     341        state.getEntry().getParameters().put(keyLower, value);
    342342        state.setValue(value);
    343343
     
    411411
    412412          boolean isString = state.getEntry().getType().toLowerCase().equals("string");
    413           if(isString) state.getEntry().setName(state.getValue().getKey().word);
    414413          state.setState(!isString ? BibParserState.STATE_EXPECT_COMMA : BibParserState.STATE_EXPECT_CLOSE);
    415414        }
     
    445444  }
    446445
    447   private void markError(SCEDocumentRow row, int startColumn, int length) {
     446  private void mark(int style, SCEDocumentRow row, int startColumn, int length) {
    448447    SCEDocumentChar[] chars = row.chars;
    449448    int endColumn = startColumn + length;
  • trunk/src/sce/component/SCEPane.java

    r1414 r1445  
    443443   * @param commentPrefix prefix used to mark a line as lineComment
    444444   */
    445   public void lineUncomment(String commentPrefix) {
     445  public void lineUncomment(String[] commentPrefix) {
    446446    if (!document.hasSelection()) {
    447447      int row = caret.getRow();
    448448      int col = caret.getColumn();
    449       if (removeComment(commentPrefix, caret.getRow())) {
    450         caret.moveTo(row, Math.max(col - commentPrefix.length(), 0), false);
     449      int removed = removeComment(commentPrefix, caret.getRow());
     450      if (removed >= 0) {
     451        caret.moveTo(row, Math.max(col - removed, 0), false);
    451452      }
    452453    } else {
     
    458459      boolean moveCaret = false;
    459460      for (int row = startRow; row <= endRow; row++) {
    460         if (removeComment(commentPrefix, row) && row == caret.getRow()) {
     461        int removed = removeComment(commentPrefix, row);
     462        if (removed >= 0 && row == caret.getRow()) {
    461463          moveCaret = true;
    462464        }
     
    473475  }
    474476
    475   private boolean removeComment(String commentPrefix, int row) {
     477  private int removeComment(String[] commentPrefixes, int row) {
    476478    String rowString = document.getRowsModel().getRowAsString(row);
    477     if (rowString.startsWith(commentPrefix)) {
    478       document.remove(row, 0, row, commentPrefix.length());
    479       return true;
    480     }
    481     return false;
     479    for(String commentPrefix : commentPrefixes) {
     480      if (rowString.startsWith(commentPrefix)) {
     481        document.remove(row, 0, row, commentPrefix.length());
     482        return commentPrefix.length();
     483      }
     484    }
     485    return -1;
    482486  }
    483487
  • trunk/src/sce/component/SCEPaneUI.java

    r1414 r1445  
    611611      if (key.equals(UNCOMMENT)) {
    612612        SourceCodeEditor editor = pane.getSourceCodeEditor();
    613         String lineComment = "//";
     613        String[] lineComment = new String[] {"//"};
    614614        try {
    615           lineComment = ((SourceCodeEditor<? extends Doc>) editor).getResource().getProperty("lineComment");
     615          String lc = ((SourceCodeEditor<? extends Doc>) editor).getResource().getProperty("lineComment");
     616          if(!lc.endsWith(" ")) {
     617            lineComment = new String[] {lc};
     618          } else {
     619            lineComment = new String[] {lc, lc.trim()};
     620          }
    616621        } catch (Throwable _) { /* ignore */ }
    617622        editor.lineUncomment(lineComment);
  • trunk/src/sce/component/SourceCodeEditor.java

    r1409 r1445  
    301301  }
    302302
    303   public void lineUncomment(String commentPrefix) {
     303  public void lineUncomment(String[] commentPrefix) {
    304304    getFocusedPane().lineUncomment(commentPrefix);
    305305  }
Note: See TracChangeset for help on using the changeset viewer.