Changeset 1370


Ignore:
Timestamp:
Oct 29, 2011, 3:58:20 PM (6 years ago)
Author:
joerg
Message:
 
Location:
trunk
Files:
3 added
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/de/endrullis/utils/ProgramUpdater.java

    r1344 r1370  
    195195    for (String filename : files2download) {
    196196      File outFile = new File(updateDir, filename);
     197      outFile.deleteOnExit();
     198
    197199      outFile.getParentFile().mkdirs();
    198200      out = new FileOutputStream(outFile);
     
    243245    if (!updateDir.isDirectory()) return false;
    244246
    245     File destinationDir = new File(System.getProperty("user.dir"));
     247    File destinationDir = new File(System.getProperty("userû.dir"));
    246248
    247249    // test for writing rights
     
    258260    if(SystemUtils.isLinuxOS() || SystemUtils.isMacOS()) {
    259261      try {
    260         ProcessUtil.exec(new String[] {"chmod", "+x", new File(updateDir, "jlatexeditor").getAbsolutePath()}, null);
     262        ProcessUtil.exec(new String[] {"chmod", "uog+x", new File(updateDir, "jlatexeditor").getAbsolutePath()}, null);
    261263      } catch(Throwable ignored) { }
    262264    }
     265
     266    System.err.println(updateDir);
    263267
    264268    // move files in update dir to .
     
    339343    File file = File.createTempFile(prefix, Long.toString(System.nanoTime()));
    340344    File dir = new File(file.getAbsolutePath() + ".d");
     345    dir.deleteOnExit();
    341346    file.delete();
    342347
  • trunk/src/jlatexeditor/JLatexEditorJFrame.java

    r1346 r1370  
    343343    createPaneShortcut(SCEPaneUI.Actions.REMOVE_WORD_BEHIND_CARET, false);
    344344    createPaneShortcut(SCEPaneUI.Actions.COMPLETE, false);
     345
     346    createPaneShortcut(SCEPaneUI.Actions.BIBTEX_MOVE, false);
    345347
    346348    createPaneShortcut(SCEPaneUI.Actions.UNDO, false);
  • trunk/src/jlatexeditor/SCEManager.java

    r1334 r1370  
    190190
    191191    try {
     192      codeAssistant.addAssistant(new ScriptingSupport());
    192193      codeAssistant.addAssistant(new FileCreationSuggester());
    193194      codeAssistant.addAssistant(new PackageImportSuggester(instance));
  • trunk/src/jlatexeditor/codehelper/ScriptingSupport.java

    r1363 r1370  
    55import sce.codehelper.SCEPopup;
    66import sce.codehelper.WordWithPos;
    7 import sce.component.SCEDocument;
    8 import sce.component.SCEPane;
     7import sce.component.*;
    98import util.SpellChecker;
    109
     10import java.io.File;
    1111import java.io.IOException;
    1212import java.util.ArrayList;
     
    1414
    1515/**
    16  * Spell checker for the SourceCodeEditor.
    17  *
    18  * @author Stefan Endrullis
     16 * Scripting support.
    1917 */
    20 public class SpellCheckSuggester implements CodeAssistant, SCEPopup.ItemHandler {
    21   public static final PatternPair wordPattern = new PatternPair("(\\p{L}*)", "(\\p{L}*)");
     18public class ScriptingSupport implements CodeAssistant {
     19  private String genericBegin = "%!begin{";
     20  private String[] languages = new String [] {"haskell"};
    2221
    23   static final Action addToDictionary = new Action("<add to dictionary>");
    24   static final Action removeFromDictionary = new Action("<remove from dictionary>");
    25 
    26   /** Spell checker. */
    27   private SpellChecker spellChecker = null;
    28 
    29   /** Last misspelled word ant its position in the document. */
    30   private WordWithPos wordUnderCaret = null;
    31   private SCEDocument document = null;
    32 
    33   public SpellCheckSuggester(SpellChecker spellChecker) {
    34     this.spellChecker = spellChecker;
     22  public ScriptingSupport() {
    3523  }
    3624
    3725  public boolean assistAt(SCEPane pane) {
    38     document = pane.getDocument();
     26    SCEDocument document = pane.getDocument();
    3927
    40     // get the word under the caret
    41     List<WordWithPos> wordList = wordPattern.find(pane);
     28    SCEDocumentRows rows = document.getRowsModel();
     29    synchronized (rows) {
     30      int rowNr = pane.getCaret().getRow();
     31      while(rowNr >= 0) {
     32        String row = rows.getRowAsString(rowNr).trim();
    4233
    43     if (wordList == null) return false;
     34        if(!row.startsWith("%")) return false;
    4435
    45     wordUnderCaret = wordList.get(0);
    46     if(wordUnderCaret.word.length() == 0) return false;
    47     if(!Character.isLetter(wordUnderCaret.word.charAt(0))) return false;
    48 
    49     try {
    50       SpellChecker.Result spellCheckResult = spellChecker.check(wordUnderCaret.word);
    51 
    52       if (spellCheckResult.isCorrect()) {
    53         if (spellChecker.getPersonalWords().contains(wordUnderCaret.word)) {
    54           List<Object> list = new ArrayList<Object>();
    55           list.add(removeFromDictionary);
    56 
    57           pane.getPopup().openPopup(list, this);
    58           return true;
    59         }
    60       } else {
    61         List<Object> list = new ArrayList<Object>();
    62         list.add(addToDictionary);
    63         for (String suggestion : spellCheckResult.getSuggestions()) {
    64           list.add(new Suggestion(suggestion));
     36        if(row.startsWith(genericBegin)) {
     37          for(String language : languages) {
     38            if(row.startsWith(getBegin(language))) {
     39              execute(language, rows, rowNr, pane);
     40              return true;
     41            }
     42          }
    6543        }
    6644
    67         pane.getPopup().openPopup(list, this);
    68         return true;
     45        rowNr--;
    6946      }
    70     } catch (IOException e) {
    71       e.printStackTrace();
    72       return true;
    7347    }
    7448
     
    7650  }
    7751
    78   public void perform(Object item) {
    79     if (item instanceof Action) {
    80       if (item == addToDictionary) {
    81         try {
    82           spellChecker.addToPersonalDict(wordUnderCaret.word);
    83         } catch (IOException e) {
    84           e.printStackTrace();
    85         }
    86         // replace the word for reparsing
    87         document.replace(wordUnderCaret.getStartPos(), wordUnderCaret.getEndPos(), wordUnderCaret.word);
    88       }
    89       if (item == removeFromDictionary) {
    90         try {
    91           spellChecker.removeFromPersonalDict(wordUnderCaret.word);
    92         } catch (IOException e) {
    93           e.printStackTrace();
    94         }
    95         // replace the word for reparsing
    96         document.replace(wordUnderCaret.getStartPos(), wordUnderCaret.getEndPos(), wordUnderCaret.word);
    97       }
    98     } else if (item instanceof Suggestion) {
    99       Suggestion suggestion = (Suggestion) item;
    100       document.replace(wordUnderCaret.getStartPos(), wordUnderCaret.getEndPos(), suggestion.word);
    101     }
     52  public String getBegin(String language) {
     53    return genericBegin + language + "}";
    10254  }
    10355
    10456
    105 // inner classes
     57  public String getEnd(String language, String magic) {
     58    return "%!end{" + language + "}" + magic;
     59  }
    10660
    107   static class Action {
    108     String name;
     61  public void execute(String language, SCEDocumentRows rows, int startRow, SCEPane pane) {
     62    SCECaret caret = pane.getCaret();
     63    SCEDocumentPosition caretPos = new SCEDocumentPosition(caret.getRow(), caret.getColumn());
    10964
    110     Action(String name) {
    111       this.name = name;
     65    String row = rows.getRowAsString(startRow);
     66    String rowTrimmed = row.trim();
     67    String begin = getBegin(language);
     68    String magic = rowTrimmed.substring(begin.length());
     69
     70    int commentIndex = row.indexOf('%');
     71    String indentation = row.substring(0, commentIndex);
     72
     73    if(magic.trim().equals("")) {
     74      magic = ("{magic:" + Math.random() + "}").replaceAll("[,\\.]","");
     75
     76      caret.moveTo(startRow, row.length(), false);
     77      pane.insert(magic + "\n" + indentation + "% \n" + indentation + getEnd(language, magic));
     78      caret.moveTo(startRow + 1, indentation.length() + 2, false);
     79      return;
    11280    }
    11381
    114     @Override
    115     public String toString() {
    116       return name;
     82    String end = getEnd(language, magic);
     83
     84    // find end of code
     85    int codeEnd = startRow+1;
     86    while(codeEnd < rows.getRowsCount()) {
     87      String line = rows.getRowAsString(codeEnd).trim();
     88
     89      if(!line.startsWith("%")) break;
     90      if(line.startsWith(end)) break;
     91
     92      codeEnd++;
    11793    }
    118   }
     94    codeEnd--;
    11995
    120   class Suggestion {
    121     String word;
     96    // find end of generated code
     97    int endRow = codeEnd+1;
     98    boolean endFound = false;
     99    while(endRow < rows.getRowsCount()) {
     100      String line = rows.getRowAsString(endRow).trim();
    122101
    123     Suggestion(String word) {
    124       this.word = word;
     102      if(line.startsWith(end)) { endFound = true; break; }
     103
     104      endRow++;
    125105    }
    126106
    127     @Override
    128     public String toString() {
    129       return word;
     107    // no end marker found?
     108    if(!endFound) {
     109      caret.moveTo(codeEnd, rows.getRow(codeEnd).length, false);
     110      pane.insert("\n" + indentation + getEnd(language, magic));
     111      caret.moveTo(caretPos, false);
     112
     113      endRow = codeEnd+1;
     114    }
     115
     116    File[] files = new File("./scripting/" + language).listFiles();
     117    for(File file : files) {
     118      if(file.getName().startsWith(".")) continue;
     119      System.err.println(file);
    130120    }
    131121  }
  • trunk/src/jlatexeditor/gproperties/GProperties.java

    r1349 r1370  
    226226    properties.addEntry(new Def("shortcut.complete", SHORTCUT, "control SPACE"));
    227227
     228    properties.addEntry(new Def("shortcut.bibtex.move", SHORTCUT, "alt X"));
     229
    228230    properties.addEntry(new Comment(" Focus Traversal"));
    229231    properties.addEntry(new Def("shortcut.focus traversal forward", SHORTCUT, "TAB"));
  • trunk/src/sce/component/SCEPane.java

    r1300 r1370  
    362362   */
    363363  public void paste() {
     364    String string = getClipboardData();
     365    if(string == null) return;
     366    insert(string.replaceAll("\t", "  "));
     367  }
     368
     369  public String getClipboardData() {
    364370    Transferable content = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    365371    try {
    366       String string = (String) content.getTransferData(DataFlavor.stringFlavor);
    367       insert(string.replaceAll("\t", "  "));
     372      return (String) content.getTransferData(DataFlavor.stringFlavor);
    368373    } catch (Exception ignored) {
    369374    }
     375    return null;
    370376  }
    371377
  • trunk/src/sce/component/SCEPaneUI.java

    r1346 r1370  
    2323import java.util.HashMap;
    2424import java.util.Map;
     25import java.util.regex.Matcher;
     26import java.util.regex.Pattern;
    2527
    2628/**
     
    459461    public static final String COMPLETE                 = "complete";
    460462
     463    public static final String BIBTEX_MOVE              = "bibtex.move";
     464
    461465    public static final String UNDO                     = "undo";
    462466    public static final String REDO                     = "redo";
     
    521525        ui.complete();
    522526      } else
     527      if (key.equals(BIBTEX_MOVE)) {
     528        Pattern pattern = Pattern.compile("@(\\w+) *\\{ *([^ ,]+) *,");
     529
     530        String item = pane.getDocument().getSelectedText();
     531        if(item == null) return;
     532
     533        Matcher matcher = pattern.matcher(item);
     534        if(!matcher.find()) return;
     535        String itemName = matcher.group(2);
     536
     537        pane.cut();
     538
     539        SCEDocument document = pane.getDocument();
     540        SCEDocumentRow[] rows = document.getRowsModel().getRows();
     541        for(SCEDocumentRow row : rows) {
     542          matcher = pattern.matcher(row.toString());
     543          if(matcher.find()) {
     544            String type = matcher.group(1);
     545            String name = matcher.group(2);
     546
     547            if(type.toLowerCase().trim().equals("string")) continue;
     548
     549            if(name.compareTo(itemName) > 0) {
     550              pane.getCaret().moveTo(row.row_nr, 0, false);
     551              break;
     552            }
     553          }
     554        }
     555
     556        pane.paste();
     557      } else
    523558      if (key.equals(UNDO)) {
    524559        pane.getUndoManager().undo(false);
     
    591626        REMOVE_LINE, REMOVE_LINE_BEFORE_CARET, REMOVE_LINE_BEHIND_CARET, REMOVE_WORD_BEFORE_CARET, REMOVE_WORD_BEHIND_CARET,
    592627        COMPLETE,
     628              BIBTEX_MOVE,
    593629        UNDO, REDO, FIND, REPLACE, FIND_NEXT, FIND_PREVIOUS, CUT, COPY, PASTE, SELECT_ALL, SELECT_NONE, COMMENT, UNCOMMENT);
    594630      return am;
  • trunk/src/sce/component/SCESearch.java

    r1340 r1370  
    544544
    545545  public void setProperties(SCESearch lastSearch) {
    546     input.setText(lastSearch.input.getText());
    547     replace.setText(lastSearch.replace.getText());
    548     caseSensitive.setSelected(lastSearch.caseSensitive.isSelected());
    549     regExp.setSelected(lastSearch.regExp.isSelected());
    550     setShowReplace(lastSearch.isShowReplace());
     546    if(lastSearch == null) return;
     547
     548    input.setText(lastSearch.input.getText());
     549    replace.setText(lastSearch.replace.getText());
     550    caseSensitive.setSelected(lastSearch.caseSensitive.isSelected());
     551    regExp.setSelected(lastSearch.regExp.isSelected());
     552    setShowReplace(lastSearch.isShowReplace());
    551553  }
    552554
Note: See TracChangeset for help on using the changeset viewer.