Changeset 1071


Ignore:
Timestamp:
Jun 20, 2011, 6:32:25 PM (6 years ago)
Author:
joerg
Message:
 
Location:
trunk/src
Files:
5 added
11 edited

Legend:

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

    r1058 r1071  
    99import de.endrullis.utils.StringUtils;
    1010import jlatexeditor.addon.AddOn;
    11 import jlatexeditor.bib.BibCodeHelper;
    12 import jlatexeditor.bib.BibSyntaxHighlighting;
    13 import jlatexeditor.changelog.ChangeLogStyles;
    14 import jlatexeditor.changelog.ChangeLogSyntaxHighlighting;
    15 import jlatexeditor.codehelper.*;
     11import jlatexeditor.codehelper.BackgroundParser;
    1612import jlatexeditor.errorhighlighting.LatexCompiler;
    1713import jlatexeditor.errorhighlighting.LatexErrorHighlighting;
    1814import jlatexeditor.gproperties.GProperties;
    19 import jlatexeditor.gproperties.GPropertiesCodeHelper;
    20 import jlatexeditor.gproperties.GPropertiesStyles;
    21 import jlatexeditor.gproperties.GPropertiesSyntaxHighlighting;
    2215import jlatexeditor.gui.*;
    23 import jlatexeditor.quickhelp.LatexQuickHelp;
    2416import jlatexeditor.remote.FileLineNr;
    2517import jlatexeditor.remote.NetworkNode;
    2618import jlatexeditor.syntaxhighlighting.LatexStyles;
    27 import jlatexeditor.syntaxhighlighting.LatexSyntaxHighlighting;
    2819import jlatexeditor.tools.SVN;
    2920import jlatexeditor.tools.ThreadInfoWindow;
    30 import sce.codehelper.CombinedCodeAssistant;
    31 import sce.codehelper.CombinedCodeHelper;
    32 import sce.codehelper.StaticCommandsCodeHelper;
    33 import sce.codehelper.StaticCommandsReader;
    3421import sce.component.*;
    35 import sce.syntaxhighlighting.SyntaxHighlighting;
    3622import util.*;
    3723import util.diff.Diff;
     
    5844import java.util.logging.Logger;
    5945
    60 public class JLatexEditorJFrame extends JFrame implements ActionListener, WindowListener, ChangeListener, MouseMotionListener, TreeSelectionListener, SearchChangeListener, SCETabbedPane.CloseListener {
     46public class JLatexEditorJFrame extends JFrame implements SCEManagerInteraction, ActionListener, WindowListener, ChangeListener, MouseMotionListener, TreeSelectionListener, SearchChangeListener, SCETabbedPane.CloseListener {
    6147  public static final File FILE_LAST_SESSION = new File(System.getProperty("user.home") + "/.jlatexeditor/last.session");
    6248  public static final File FILE_RECENT = new File(System.getProperty("user.home") + "/.jlatexeditor/recent");
     
    123109  private LinkedHashMap<String,AddOn> addOns = AddOn.getAllAddOnsMap();
    124110
    125   // background parser
    126   private BackgroundParser backgroundParser;
    127111  private HashMap<URI, Doc> docMap = new HashMap<URI, Doc>();
    128112  private File lastDocDir;
    129113  private SCESearch lastSearch;
    130   private StaticCommandsReader latexCommands = new StaticCommandsReader("data/codehelper/commands.xml");
    131   private StaticCommandsReader tabCompletions = new StaticCommandsReader("data/codehelper/tabCompletion.xml");
    132114
    133115  public static void main(String args[]) {
    134     /*
    135     try {
    136       //System.setProperty("swing.aatext", "true");
    137       System.setProperty("Quaqua.tabLayoutPolicy","wrap");
    138       System.setProperty("apple.laf.useScreenMenuBar", "true");
    139       System.setProperty("com.apple.macos.useScreenMenuBar", "true");
    140 
    141       try {
    142         Methods.invokeStatic(JFrame.class, "setDefaultLookAndFeelDecorated", Boolean.TYPE, Boolean.TRUE);
    143         Methods.invokeStatic(JDialog.class, "setDefaultLookAndFeelDecorated", Boolean.TYPE, Boolean.TRUE);
    144       } catch (NoSuchMethodException e) { }
    145 
    146       String lafName = QuaquaManager.getLookAndFeelClassName();
    147       if(!lafName.equals("default")) {
    148         if(lafName.equals("system")) {
    149           lafName = UIManager.getSystemLookAndFeelClassName();
    150         } else if (lafName.equals("crossplatform")) {
    151           lafName = UIManager.getCrossPlatformLookAndFeelClassName();
    152         }
    153 
    154         LookAndFeel laf = (LookAndFeel) Class.forName(lafName).newInstance();
    155         UIManager.setLookAndFeel(laf);
    156       }
    157     } catch (Exception e) { }
    158     */
    159 
    160116    // init logging
    161117    initLogging();
     
    177133    UIManager.put("TabbedPaneUI", "util.gui.SCETabbedPaneUI");
    178134    UIManager.put("List.timeFactor", 200L);
    179     /*
    180     UIManager.put("Menu.background", SCETabbedPaneUI.BLUE);
    181     UIManager.put("Menu.selectionBackground", SCETabbedPaneUI.BLUE);
    182     UIManager.put("MenuBar.gradient", Arrays.asList(1.0f, 0.0f, SCETabbedPaneUI.BLUE, SCETabbedPaneUI.BLUE.brighter(), SCETabbedPaneUI.BLUE.darker()));
    183     */
    184135
    185136    new AboutDialog(null).showAndAutoHideAfter(5000);
     
    208159  public JLatexEditorJFrame(JLatexEditorParams params) {
    209160    super(windowTitleSuffix);
     161    SCEManager.setInstance(this);
    210162
    211163    // set files to open
     
    281233    editMenu.add(createMenuItem("Uncomment", "uncomment", 'u'));
    282234    editMenu.addSeparator();
    283     editMenu.add(createMenuItem("Diff", "diff", 'D'));
     235    editMenu.add(createMenuItem("Compare With... (Diff)", "diff", 'D'));
    284236
    285237    JMenu viewMenu = new JMenu("View");
     
    343295    }};
    344296    settingsMenu.add(forwardSearch);
     297    // settingsMenu.add(createMenuItem("Template Editor", "template editor", 'T'));
     298    settingsMenu.add(createMenuItem("Quick Setup Wizard", "wizard", 'W'));
    345299    settingsMenu.add(createMenuItem("Global Settings", "global settings", 'G'));
    346300
     
    392346
    393347    // background parser
    394     backgroundParser = new BackgroundParser(this);
     348    BackgroundParser backgroundParser = new BackgroundParser(this);
     349    SCEManager.setBackgroundParser(backgroundParser);
    395350    backgroundParser.start();
    396351   
     
    579534    openDialog.addChoosableFileFilter(SCEFileChooser.FILTER_TEX);
    580535  }
    581 
    582   private SourceCodeEditor<Doc> createLatexSourceCodeEditor() {
    583     SourceCodeEditor<Doc> editor = new SourceCodeEditor<Doc>(null);
    584 
    585     SCEPane scePane = editor.getTextPane();
    586     setPaneProperties(scePane);
    587     SCEDocument document = scePane.getDocument();
    588 
    589     // add some styles to the document
    590     LatexStyles.addStyles(document);
    591 
    592     SpellChecker spellChecker = null;
    593     try {
    594       spellChecker = createSpellChecker();
    595     } catch (Exception ignored) {}
    596 
    597     // syntax highlighting
    598     SyntaxHighlighting syntaxHighlighting = new LatexSyntaxHighlighting(scePane, spellChecker, latexCommands.getCommands(), backgroundParser);
    599     syntaxHighlighting.start();
    600 
    601     // code completion and quick help
    602     CombinedCodeHelper codeHelper = new CombinedCodeHelper();
    603     if (backgroundParser != null) {
    604       codeHelper.addPatternHelper(new CiteHelper(backgroundParser));
    605       // add completion for \ref and \eqref
    606       codeHelper.addPatternHelper(new GenericCodeHelper("\\\\(?:ref|eqref)\\{([^{}]*)", new Function0<AbstractTrie<?>>() {
    607         public Trie<?> apply() {
    608           return backgroundParser.getLabelDefs();
    609         }
    610       }));
    611       // add completion for \label
    612       codeHelper.addPatternHelper(new GenericCodeHelper("\\\\label\\{([^{}]*)", new Function0<AbstractTrie<?>>() {
    613         public AbstractTrie<?> apply() {
    614           return backgroundParser.getLabelRefs();
    615         }
    616       }));
    617     }
    618     codeHelper.addPatternHelper(new IncludeCodeHelper());
    619     codeHelper.addPatternHelper(new CommandsCodeHelper(this));
    620     if (backgroundParser != null) {
    621       codeHelper.addPatternHelper(new WordCompletion(backgroundParser));
    622     }
    623     codeHelper.setAutoCompletion(GProperties.getBoolean("editor.auto_completion.activated"));
    624     codeHelper.setAutoCompletionMinLetters(GProperties.getInt("editor.auto_completion.min_number_of_letters"));
    625     codeHelper.setAutoCompletionDelay(GProperties.getInt("editor.auto_completion.delay"));
    626     scePane.setCodeHelper(codeHelper);
    627     scePane.setTabCompletion(new StaticCommandsCodeHelper("(\\p{L}*)", tabCompletions));
    628     scePane.setQuickHelp(new LatexQuickHelp("data/quickhelp/"));
    629 
    630     CombinedCodeAssistant codeAssistant = new CombinedCodeAssistant();
    631     try {
    632       codeAssistant.addAssistant(new FileCreationSuggester(this));
    633       codeAssistant.addAssistant(new SpellCheckSuggester(createSpellChecker()));
    634     } catch (Exception ignored) {
    635     }
    636     scePane.addCodeAssistantListener(codeAssistant);
    637 
    638     new JumpTo(editor, this, backgroundParser);
    639 
    640     return editor;
    641   }
    642 
    643   private SpellChecker createSpellChecker() throws Exception {
    644     String program = GProperties.getString("editor.spell_checker");
    645 
    646     if (program.equals("aspell")) {
    647       // set executables
    648       Aspell.ASPELL_EXECUTABLE = GProperties.getString("aspell.executable");
    649 
    650       SpellChecker spellChecker = Aspell.getInstance(GProperties.getAspellLang());
    651       if (spellChecker == null) throw new Exception("Initialization of the spell checker failed!");
    652       return spellChecker;
    653     } else
    654     if (program.equals("hunspell")) {
    655       // set executables
    656       Hunspell.HUNSPELL_EXECUTABLE = GProperties.getString("hunspell.executable");
    657 
    658       SpellChecker spellChecker = Hunspell.getInstance(GProperties.getString("hunspell.lang"));
    659       if (spellChecker == null) throw new Exception("Initialization of the spell checker failed!");
    660       return spellChecker;
    661     }
    662 
    663     return null;
    664   }
    665 
    666   private SourceCodeEditor<Doc> createBibSourceCodeEditor() {
    667     SourceCodeEditor<Doc> editor = new SourceCodeEditor<Doc>(null);
    668 
    669     SCEPane scePane = editor.getTextPane();
    670     setPaneProperties(scePane);
    671     SCEDocument document = scePane.getDocument();
    672 
    673     // TODO: use other styles
    674     // add some styles to the document
    675     LatexStyles.addStyles(document);
    676 
    677     // syntax highlighting
    678     BibSyntaxHighlighting syntaxHighlighting = new BibSyntaxHighlighting(scePane, backgroundParser);
    679     syntaxHighlighting.start();
    680 
    681     // code completion and quick help
    682     CombinedCodeHelper codeHelper = new CombinedCodeHelper();
    683     if (backgroundParser != null) {
    684       codeHelper.addPatternHelper(new BibCodeHelper());
    685     }
    686     codeHelper.addPatternHelper(new IncludeCodeHelper());
    687     codeHelper.addPatternHelper(new CommandsCodeHelper(this));
    688     if (backgroundParser != null) {
    689       codeHelper.addPatternHelper(new WordCompletion(backgroundParser));
    690     }
    691     codeHelper.setAutoCompletion(GProperties.getBoolean("editor.auto_completion.activated"));
    692     codeHelper.setAutoCompletionMinLetters(GProperties.getInt("editor.auto_completion.min_number_of_letters"));
    693     codeHelper.setAutoCompletionDelay(GProperties.getInt("editor.auto_completion.delay"));
    694     scePane.setCodeHelper(codeHelper);
    695     scePane.setTabCompletion(new StaticCommandsCodeHelper("(\\p{L}*)", tabCompletions));
    696     scePane.setQuickHelp(new LatexQuickHelp("data/quickhelp/"));
    697 
    698     CombinedCodeAssistant codeAssistant = new CombinedCodeAssistant();
    699     try {
    700       codeAssistant.addAssistant(new SpellCheckSuggester(createSpellChecker()));
    701     } catch (Exception ignored) {
    702     }
    703     scePane.addCodeAssistantListener(codeAssistant);
    704 
    705     return editor;
    706   }
    707 
    708   private SourceCodeEditor<Doc> createGPropertiesSourceCodeEditor() {
    709     SourceCodeEditor<Doc> editor = new SourceCodeEditor<Doc>(null);
    710 
    711     SCEPane scePane = editor.getTextPane();
    712     setPaneProperties(scePane);
    713     SCEDocument document = scePane.getDocument();
    714 
    715     // add some styles to the document
    716     GPropertiesStyles.addStyles(document);
    717 
    718     // syntax highlighting
    719     GPropertiesSyntaxHighlighting syntaxHighlighting = new GPropertiesSyntaxHighlighting(scePane);
    720     syntaxHighlighting.start();
    721 
    722     // code completion and quick help
    723     CombinedCodeHelper codeHelper = new CombinedCodeHelper();
    724     codeHelper.addPatternHelper(new GPropertiesCodeHelper());
    725     scePane.setCodeHelper(codeHelper);
    726 
    727     return editor;
    728   }
    729 
    730   private SourceCodeEditor<Doc> createChangeLogSourceCodeEditor() {
    731     SourceCodeEditor<Doc> editor = new SourceCodeEditor<Doc>(null);
    732 
    733     SCEPane scePane = editor.getTextPane();
    734     setPaneProperties(scePane);
    735     SCEDocument document = scePane.getDocument();
    736 
    737     // add some styles to the document
    738     ChangeLogStyles.addStyles(document);
    739 
    740     // syntax highlighting
    741     ChangeLogSyntaxHighlighting syntaxHighlighting = new ChangeLogSyntaxHighlighting(scePane);
    742     syntaxHighlighting.start();
    743 
    744     return editor;
    745   }
    746 
    747   private void setPaneProperties(final SCEPane pane) {
    748     pane.setColumnsPerRow(GProperties.getInt("editor.columns_per_row"));
    749     GProperties.addPropertyChangeListener("editor.columns_per_row", new PropertyChangeListener() {
    750       public void propertyChange(PropertyChangeEvent evt) {
    751         pane.setColumnsPerRow(GProperties.getInt("editor.columns_per_row"));
    752       }
    753     });
    754   }
    755 
    756   public BackgroundParser getBackgroundParser() {
    757     return backgroundParser;
    758   }
    759 
    760   public StaticCommandsReader getLatexCommands() {
    761     return latexCommands;
    762   }
    763 
    764   public StaticCommandsReader getTabCompletions() {
    765     return tabCompletions;
    766   }
    767536
    768537  /**
     
    813582  }
    814583
     584  public int getEditorCount() {
     585    return tabbedPane.getTabCount();
     586  }
     587
    815588  public SourceCodeEditor<Doc> getEditor(int tab) {
    816589    return (SourceCodeEditor<Doc>) tabbedPane.getComponentAt(tab);
     
    846619
    847620    if (doc.getName().endsWith("global.properties")) {
    848       editor = createGPropertiesSourceCodeEditor();
     621      editor = SCEManager.createGPropertiesSourceCodeEditor();
    849622    } else
    850623    if (doc.getName().endsWith("CHANGELOG")) {
    851       editor = createChangeLogSourceCodeEditor();
     624      editor = SCEManager.createChangeLogSourceCodeEditor();
    852625    } else
    853626    if (doc.getName().endsWith(".bib")) {
    854       editor = createBibSourceCodeEditor();
     627      editor = SCEManager.createBibSourceCodeEditor();
    855628    } else {
    856       editor = createLatexSourceCodeEditor();
     629      editor = SCEManager.createLatexSourceCodeEditor();
    857630    }
    858631
     
    970743    }
    971744
    972     backgroundParser.parse();
     745    SCEManager.getBackgroundParser().parse();
    973746    return all;
    974747  }
     
    1164937  public boolean isResponsibleFor(File file) {
    1165938    // did we open the file already?                  or is file referenced by the main document?
    1166     return isOpen(file) || backgroundParser.isResponsibleFor(file);
     939    return isOpen(file) || SCEManager.getBackgroundParser().isResponsibleFor(file);
    1167940  }
    1168941
     
    14681241      SCEFontWindow fontDialog = new SCEFontWindow(GProperties.getEditorFont().getFamily(), GProperties.getEditorFont().getSize(), this);
    14691242      fontDialog.setVisible(true);
     1243    } else if (action.equals("template editor")) {
     1244      TemplateEditor templateEditor = new TemplateEditor(this);
     1245      templateEditor.setVisible(true);
     1246    } else if (action.equals("wizard")) {
     1247      Wizard wizard = new Wizard(this);
     1248      wizard.setVisible(true);
    14701249    } else if (action.equals("font window") || action.equals("font window cancel")) {
    14711250      SCEFontWindow fontDialog = (SCEFontWindow) e.getSource();
     
    14951274
    14961275  private void showTool(int tab) {
    1497     if (toolsTab.isVisible()) {
    1498       if (toolsTab.getSelectedIndex() != tab) {
    1499         toolsTab.setSelectedIndex(tab);
    1500       }
    1501     } else {
    1502       toolsTab.setSelectedIndex(tab);
    1503       toolsTab.setVisible(true);
    1504       textToolsSplit.setResizeWeight(1 - GProperties.getDouble("main_window.tools_panel.height"));
    1505       textToolsSplit.resetToPreferredSizes();
    1506       toolsTab.getSelectedComponent().requestFocus();
    1507     }
     1276    if (!toolsTab.isVisible()) toolsTab.setVisible(true);
     1277
     1278    if (toolsTab.getSelectedIndex() != tab) {
     1279      toolsTab.setSelectedIndex(tab);
     1280    }
     1281
     1282    if (toolsTab.getVisibleRect().getHeight() < 5) {
     1283      textToolsSplit.setResizeWeight(1 - GProperties.getDouble("main_window.tools_panel.height"));
     1284      textToolsSplit.resetToPreferredSizes();
     1285      toolsTab.getSelectedComponent().requestFocus();
     1286    }
    15081287  }
    15091288
     
    16381417    tabbedPane.getTabComponentAt(mainEditorTab).setForeground(Color.RED);
    16391418
    1640     backgroundParser.parse();
     1419    SCEManager.getBackgroundParser().parse();
    16411420    statusBar.checkForUpdates();
    16421421  }
  • trunk/src/jlatexeditor/addon/FileSearch.java

    r1032 r1071  
    33import jlatexeditor.Doc;
    44import jlatexeditor.JLatexEditorJFrame;
     5import jlatexeditor.SCEManager;
    56import sce.codehelper.SCEPopup;
    6 import sce.codehelper.WordWithPos;
    77import sce.component.SCEPane;
    88
     
    2222  @Override
    2323  public void run(JLatexEditorJFrame jle) {
    24     HashSet<File> files = jle.getBackgroundParser().getFiles();
     24    HashSet<File> files = SCEManager.getBackgroundParser().getFiles();
    2525    File[] filesArray = new File[files.size()];
    2626    files.toArray(filesArray);
     
    3737  }
    3838
    39   @Override
    4039  public void perform(Object item) {
    4140    if (item instanceof FileOpenAction) {
  • trunk/src/jlatexeditor/addon/RenameElement.java

    r1014 r1071  
    33import jlatexeditor.Doc;
    44import jlatexeditor.JLatexEditorJFrame;
     5import jlatexeditor.SCEManager;
    56import jlatexeditor.codehelper.BackgroundParser;
    67import jlatexeditor.codehelper.CodePattern;
     
    4849      backgroundParserWaitFor(jle);
    4950
    50       List<String> fileNames = jle.getBackgroundParser().getCommandsAndFiles().getObjects(oldCommandName, 1000);
     51      List<String> fileNames = SCEManager.getBackgroundParser().getCommandsAndFiles().getObjects(oldCommandName, 1000);
    5152      HashSet<File> files = new HashSet<File>();
    5253      if (fileNames != null) {
     
    5960
    6061      // start background parser to update document states
    61       jle.getBackgroundParser().parse();
     62      SCEManager.getBackgroundParser().parse();
    6263
    6364      return;
     
    8889
    8990          // determine all files/editors that contain this label
    90           List<BackgroundParser.FilePos> filePoses = jle.getBackgroundParser().getLabelRefs().getObjects(oldLabel, 1000);
     91          List<BackgroundParser.FilePos> filePoses = SCEManager.getBackgroundParser().getLabelRefs().getObjects(oldLabel, 1000);
    9192          if (filePoses == null) {
    9293            filePoses = new ArrayList<BackgroundParser.FilePos>();
    9394          }
    94           filePoses.add(jle.getBackgroundParser().getLabelDefs().get(oldLabel));
     95          filePoses.add(SCEManager.getBackgroundParser().getLabelDefs().get(oldLabel));
    9596
    9697          replaceInAllFiles(jle, filePoses, "\\\\(label|ref|eqref)\\{" + oldLabel + "\\}", "\\\\$1{" + newLabel + "}", false);
     
    154155
    155156    // start background parser to update document states
    156     jle.getBackgroundParser().parse();
     157    SCEManager.getBackgroundParser().parse();
    157158  }
    158159
     
    160161    // wait for background parser to finish
    161162    try {
    162       jle.getBackgroundParser().waitForParseFinished();
     163      SCEManager.getBackgroundParser().waitForParseFinished();
    163164    } catch (InterruptedException e) {
    164165      return false;
     
    180181
    181182      // determine all files/editors that contain this citation
    182       List<BackgroundParser.FilePos> filePoses = jle.getBackgroundParser().getBibRefs().getObjects(oldRef, 1000);
     183      List<BackgroundParser.FilePos> filePoses = SCEManager.getBackgroundParser().getBibRefs().getObjects(oldRef, 1000);
    183184      if (filePoses == null) {
    184185        filePoses = new ArrayList<BackgroundParser.FilePos>();
    185186      }
    186       filePoses.add(jle.getBackgroundParser().getBibKeys2bibEntries().get(oldRef));
     187      filePoses.add(SCEManager.getBackgroundParser().getBibKeys2bibEntries().get(oldRef));
    187188
    188189      String balanced = "[^\\{\\}]*(?:\\{[^\\{\\}]*\\}[^\\{\\}]*)*";
     
    229230
    230231    // start background parser to update document states
    231     jle.getBackgroundParser().parse();
     232    SCEManager.getBackgroundParser().parse();
    232233  }
    233234}
  • trunk/src/jlatexeditor/codehelper/CommandsCodeHelper.java

    r996 r1071  
    22
    33import de.endrullis.utils.ExtIterator;
    4 import jlatexeditor.JLatexEditorJFrame;
     4import jlatexeditor.SCEManager;
    55import sce.codehelper.CHCommand;
    66import sce.codehelper.StaticCommandsCodeHelper;
     
    1717 */
    1818public class CommandsCodeHelper extends StaticCommandsCodeHelper {
    19   private JLatexEditorJFrame jle;
    20 
    21   public CommandsCodeHelper(JLatexEditorJFrame jle) {
    22     super("(\\\\\\p{L}*)", jle.getLatexCommands());
    23     this.jle = jle;
     19  public CommandsCodeHelper() {
     20    super("(\\\\\\p{L}*)", SCEManager.getLatexCommands());
    2421  }
    2522
     
    2724  public Iterable<? extends CHCommand> getCompletions(String prefix) {
    2825    ArrayList<CHCommand> dynamicCommands = new ArrayList<CHCommand>();
    29     BackgroundParser backgroundParser = jle.getBackgroundParser();
     26    BackgroundParser backgroundParser = SCEManager.getBackgroundParser();
    3027    if (backgroundParser != null) {
    3128      List<String> commandNames = backgroundParser.getCommandNames().getStrings(prefix.substring(1), 10);
     
    9188    }
    9289
    93     BackgroundParser backgroundParser = jle.getBackgroundParser();
     90    BackgroundParser backgroundParser = SCEManager.getBackgroundParser();
    9491    if (backgroundParser != null) {
    9592      String dynMaxCommonPrefix = "\\" + backgroundParser.getCommandNames().getMaxCommonPrefix(prefix.substring(1));
  • trunk/src/jlatexeditor/codehelper/FileCreationSuggester.java

    r821 r1071  
    44import jlatexeditor.Doc;
    55import jlatexeditor.JLatexEditorJFrame;
     6import jlatexeditor.SCEManager;
     7import jlatexeditor.SCEManagerInteraction;
    68import sce.codehelper.CodeAssistant;
    79import sce.codehelper.PatternPair;
     
    2325  private PatternPair parameterPattern = new PatternPair("\\\\(input|include)\\{([^\\{]*)", "([^\\}]*)\\}");
    2426
    25   private JLatexEditorJFrame jle;
    26 
    27   public FileCreationSuggester(JLatexEditorJFrame jle) {
    28     this.jle = jle;
     27  public FileCreationSuggester() {
    2928  }
    3029
    31   @Override
    3230  public boolean assistAt(SCEPane pane) {
    3331    List<WordWithPos> words = parameterPattern.find(pane);
     
    3533      WordWithPos word = words.get(1);
    3634
    37       Doc resource = jle.getMainEditor().getResource();
     35      Doc resource = SCEManager.getInstance().getMainEditor().getResource();
    3836      if (resource instanceof Doc.FileDoc) {
    3937        Doc.FileDoc fileDoc = (Doc.FileDoc) resource;
     
    7876  }
    7977
    80   @Override
    8178  public void perform(Object item) {
    8279    if (item instanceof FileCreationAction) {
     
    8683        File file = action.getFile();
    8784        if (file.createNewFile())
    88           jle.open(new Doc.FileDoc(file));
     85          SCEManager.getInstance().open(new Doc.FileDoc(file));
    8986      } catch (IOException e) {
    9087        e.printStackTrace();
  • trunk/src/jlatexeditor/codehelper/JumpTo.java

    r996 r1071  
    33import jlatexeditor.Doc;
    44import jlatexeditor.Doc.FileDoc;
    5 import jlatexeditor.JLatexEditorJFrame;
     5import jlatexeditor.SCEManager;
    66import sce.codehelper.WordWithPos;
    77import sce.component.SCEDocumentPosition;
     
    2424
    2525  private SourceCodeEditor editor;
    26   private JLatexEditorJFrame jLatexEditorJFrame;
    2726
    28   private BackgroundParser backgroundParser;
    29 
    30   public JumpTo(SourceCodeEditor editor, JLatexEditorJFrame jLatexEditorJFrame, BackgroundParser backgroundParser) {
     27  public JumpTo(SourceCodeEditor editor) {
    3128    this.editor = editor;
    32     this.jLatexEditorJFrame = jLatexEditorJFrame;
    33     this.backgroundParser = backgroundParser;
    3429    editor.getTextPane().addKeyListener(this);
    3530    editor.getTextPane().addMouseListener(this);
     
    5651
    5752      // try to jump to command definition
    58       BackgroundParser.FilePos filePos = backgroundParser.getCommands().get(word.word);
     53      BackgroundParser.FilePos filePos = SCEManager.getBackgroundParser().getCommands().get(word.word);
    5954      if (filePos != null) {
    60         jLatexEditorJFrame.open(new FileDoc(new File(filePos.getFile())), filePos.getLineNr());
     55        SCEManager.getInstance().open(new FileDoc(new File(filePos.getFile())), filePos.getLineNr());
    6156        return;
    6257      }
     
    7671        // if \ref or \eqref -> try to jump to label definition
    7772        if (command.equals("ref") || command.equals("eqref")) {
    78           BackgroundParser.FilePos filePos = backgroundParser.getLabelDefs().get(word.word);
     73          BackgroundParser.FilePos filePos = SCEManager.getBackgroundParser().getLabelDefs().get(word.word);
    7974          if (filePos != null) {
    80             jLatexEditorJFrame.open(new FileDoc(new File(filePos.getFile())), filePos.getLineNr());
     75            SCEManager.getInstance().open(new FileDoc(new File(filePos.getFile())), filePos.getLineNr());
    8176            return;
    8277          }
    8378        } else
    8479        if (command.equals("cite")) {
    85           BackgroundParser.FilePos filePos = backgroundParser.getBibKeys2bibEntries().get(word.word);
     80          BackgroundParser.FilePos filePos = SCEManager.getBackgroundParser().getBibKeys2bibEntries().get(word.word);
    8681          if (filePos != null) {
    87             jLatexEditorJFrame.open(new FileDoc(new File(filePos.getFile())), filePos.getLineNr());
     82            SCEManager.getInstance().open(new FileDoc(new File(filePos.getFile())), filePos.getLineNr());
    8883            return;
    8984          }
     
    10398
    10499          if (fileUnderCaret.exists() && fileUnderCaret.isFile()) {
    105             jLatexEditorJFrame.open(new FileDoc(fileUnderCaret));
     100            SCEManager.getInstance().open(new FileDoc(fileUnderCaret));
    106101            e.consume();
    107102            return;
  • trunk/src/jlatexeditor/gproperties/GProperties.java

    r1059 r1071  
    189189    properties.addEntry(new Def("shortcut.svn commit", SHORTCUT, "alt C"));
    190190    properties.addEntry(new Def("shortcut.font", SHORTCUT, ""));
     191    properties.addEntry(new Def("shortcut.template editor", SHORTCUT, "control T"));
    191192    properties.addEntry(new Def("shortcut.global settings", SHORTCUT, "control alt S"));
    192193    properties.addEntry(new Comment(" Editors/tabs"));
  • trunk/src/jlatexeditor/syntaxhighlighting/LatexSyntaxHighlighting.java

    r1039 r1071  
    278278              if (argumentTypeName.equals("cite_key_list")) {
    279279                matchAndStyle(char_nr + 1, chars, param, LIST_PATTERN, new Function1<String, Byte>(){
    280                   @Override
    281280                  public Byte apply(String a1) {
    282281                    boolean citeExists = backgroundParser.getBibKeys2bibEntries().contains(a1);
  • trunk/src/sce/codehelper/CHCommand.java

    r869 r1071  
    1818  /** Arguments. */
    1919  private ArrayList<CHCommandArgument> arguments = new ArrayList<CHCommandArgument>();
     20
     21  /** User defined? */
     22  private boolean isUserDefined = false;
    2023
    2124  /**
     
    114117  }
    115118
     119  /**
     120   * Returns true if the command is defined or changed by the user.
     121   *
     122   * @return true if user defined
     123   */
     124  public boolean isUserDefined() {
     125    return isUserDefined;
     126  }
     127
     128  /**
     129   * Set whether this command is defined or changed by the user.
     130   *
     131   * @param userDefined true if user defined
     132   */
     133  public void setUserDefined(boolean userDefined) {
     134    isUserDefined = userDefined;
     135  }
     136
    116137  // Comparable methods
    117138
     
    129150    return getName();
    130151  }
     152
     153  public boolean equals(Object obj) {
     154    if(!(obj instanceof CHCommand)) return false;
     155    CHCommand o = (CHCommand) obj;
     156
     157    if(!name.equals(o.name)
     158            || !usage.equals(o.usage)
     159            || !style.equals(o.style)
     160            || !hint.equals(o.hint)) return false;
     161
     162    if(arguments.size() != o.arguments.size()) return false;
     163    /* TODO: comparison of arguments
     164    for(int argNr = 0; argNr < arguments.size(); argNr++) {
     165      if(!arguments.get(argNr).equals(o.arguments.get(argNr))) return false;
     166    }
     167    */
     168
     169    return true;
     170  }
    131171}
  • trunk/src/sce/codehelper/StaticCommandsReader.java

    r960 r1071  
    2020
    2121  public StaticCommandsReader(String filename) {
    22     readCommands(filename);
     22    commands = new Trie<CHCommand>();
     23
     24    readCommands(filename, false);
    2325  }
    2426
     
    2830   * @param filename the filename
    2931   */
    30   public void readCommands(String filename) {
    31     commands = new Trie<CHCommand>();
    32 
     32  public void readCommands(String filename, boolean userDefined) {
    3333    XMLParser xmlParser = new XMLParser();
    3434    XMLDocument commandsDocument;
     
    5353        CHCommand command = getCommand(commandXML);
    5454        if (command == null) continue;
     55
     56        // user defined command?
     57        command.setUserDefined(true);
    5558
    5659        // add the command to the commands list
  • trunk/src/sce/component/SCEDiff.java

    r996 r1071  
    11package sce.component;
    22
     3import jlatexeditor.SCEManager;
    34import util.diff.Diff;
    45import util.diff.levenstein.Modification;
     
    5960    this.left = left;
    6061    this.rightTitle = rightTitle;
    61     this.right = new SCEPane(null);
     62    this.right = new SCEPane(left.getSourceCodeEditor());
     63    SCEManager.setupLatexSCEPane(this.right);
    6264    this.markerBar = markerBar;
    6365
     
    7173    scrollPane = new SCEDiff.SCEDiffScrollPane(splitPane);
    7274    add(scrollPane, BorderLayout.CENTER);
    73     updateLayout();
    7475    addComponentListener(this);
    7576
     
    119120      }
    120121    });
     122
     123    SwingUtilities.invokeLater(new Runnable() {
     124      public void run() {
     125        updateLayout();
     126      }
     127    });
    121128  }
    122129
     
    165172  }
    166173
     174  public void updateLayout() {
     175    final Rectangle visibleRect = scrollPane.getVisibleRect();
     176
     177    SwingUtilities.invokeLater(new Runnable() {
     178      public void run() {
     179        splitPane.setDividerLocation((visibleRect.width - WIDTH) / 2);
     180        splitPane.setDividerSize(WIDTH);
     181      }
     182    });
     183
     184    int visibleWidthLeft = splitPane.getDividerLocation();
     185    int visibleWidthRight = visibleRect.width - visibleWidthLeft - WIDTH;
     186    double overLeft = Math.max(1, left.getPreferredSize().width - visibleWidthLeft) / (double) visibleWidthLeft;
     187    double overRight = Math.max(1, right.getPreferredSize().width - visibleWidthRight) / (double) visibleWidthRight;
     188
     189    preferredWidthFactor = 1 + Math.max(0, Math.max(overLeft, overRight));
     190    preferredSize.width = (int) (visibleRect.width * preferredWidthFactor);
     191    preferredSize.height = preferredLines * left.getLineHeight() + 30;
     192  }
     193
    167194  public void jumpToNextSourceModification() {
    168195    SCECaret caret = right.getCaret();
     
    175202      }
    176203    }
    177   }
    178 
    179   public void updateLayout() {
    180     splitPane.setDividerLocation((scrollPane.getVisibleRect().width - WIDTH) / 2);
    181     splitPane.setDividerSize(WIDTH);
    182 
    183     Rectangle visibleRect = scrollPane.getVisibleRect();
    184     int visibleWidthLeft = splitPane.getDividerLocation();
    185     int visibleWidthRight = visibleRect.width - visibleWidthLeft - WIDTH;
    186     double overLeft = Math.max(1, left.getPreferredSize().width - visibleWidthLeft) / (double) visibleWidthLeft;
    187     double overRight = Math.max(1, right.getPreferredSize().width - visibleWidthRight) / (double) visibleWidthRight;
    188 
    189     preferredWidthFactor = 1 + Math.max(0, Math.max(overLeft, overRight));
    190     preferredSize.width = (int) (visibleRect.width * preferredWidthFactor);
    191     preferredSize.height = preferredLines * left.getLineHeight() + 30;
    192204  }
    193205
     
    541553        if (up) {
    542554          int distance = (int) (visible.getY() - rectangle.getY());
    543           while (line >= 0 && (lineMap[line] - lineMap[nline]) * lineHeight < distance) nline--;
     555          while (nline >= 0 && (lineMap[line] - lineMap[nline]) * lineHeight < distance) nline--;
    544556        } else {
    545557          int distance = (int) (rectangle.getY() + rectangle.getHeight() - visible.getY() - visible.getHeight());
    546           while (line < lineMap.length && (lineMap[nline] - lineMap[line]) * lineHeight < distance) nline++;
     558          while (nline < lineMap.length && (lineMap[nline] - lineMap[line]) * lineHeight < distance) nline++;
    547559        }
    548560        vbar.setValue(vbar.getValue() + (nline - line) * lineHeight);
Note: See TracChangeset for help on using the changeset viewer.