⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pyeditconfiguration.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (reconciler == null) {
            reconciler = new PresentationReconciler();
            reconciler.setDocumentPartitioning(IPythonPartitions.PYTHON_PARTITION_TYPE);

            DefaultDamagerRepairer dr;

            // DefaultDamagerRepairer implements both IPresentationDamager, IPresentationRepairer
            // IPresentationDamager::getDamageRegion does not scan, just
            // returns the intersection of document event, and partition region
            // IPresentationRepairer::createPresentation scans
            // gets each token, and sets text attributes according to token

            // We need to cover all the content types from PyPartitionScanner

            IPreferenceStore preferences = PydevPlugin.getChainedPrefStore();
            // Comments have uniform color
            commentScanner = new PyColoredScanner(colorCache, PydevPrefs.COMMENT_COLOR, preferences.getInt(PydevPrefs.COMMENT_STYLE));
            dr = new DefaultDamagerRepairer(commentScanner);
            reconciler.setDamager(dr, IPythonPartitions.PY_COMMENT);
            reconciler.setRepairer(dr, IPythonPartitions.PY_COMMENT);

            // Backquotes have uniform color
            backquotesScanner = new PyColoredScanner(colorCache, PydevPrefs.BACKQUOTES_COLOR,preferences.getInt(PydevPrefs.BACKQUOTES_STYLE));
            dr = new DefaultDamagerRepairer(backquotesScanner);
            reconciler.setDamager(dr, IPythonPartitions.PY_BACKQUOTES);
            reconciler.setRepairer(dr, IPythonPartitions.PY_BACKQUOTES);
            
            // Strings have uniform color
            stringScanner = new PyColoredScanner(colorCache, PydevPrefs.STRING_COLOR,preferences.getInt(PydevPrefs.STRING_STYLE));
            dr = new DefaultDamagerRepairer(stringScanner);
            reconciler.setDamager(dr, IPythonPartitions.PY_SINGLELINE_STRING1);
            reconciler.setRepairer(dr, IPythonPartitions.PY_SINGLELINE_STRING1);
            reconciler.setDamager(dr, IPythonPartitions.PY_SINGLELINE_STRING2);
            reconciler.setRepairer(dr, IPythonPartitions.PY_SINGLELINE_STRING2);
            reconciler.setDamager(dr, IPythonPartitions.PY_MULTILINE_STRING1);
            reconciler.setRepairer(dr, IPythonPartitions.PY_MULTILINE_STRING1);
            reconciler.setDamager(dr, IPythonPartitions.PY_MULTILINE_STRING2);
            reconciler.setRepairer(dr, IPythonPartitions.PY_MULTILINE_STRING2);

            // Default content is code, we need syntax highlighting
            codeScanner = new PyCodeScanner(colorCache);
            dr = new DefaultDamagerRepairer(codeScanner);
            reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
            reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
        }

        return reconciler;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer)
     */
    public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
		// next create a content assistant processor to populate the completions window
        IContentAssistProcessor processor = new SimpleAssistProcessor(edit, 
        		new PythonCompletionProcessor(edit, pyContentAssistant), pyContentAssistant);
        
        PythonStringCompletionProcessor stringProcessor = new PythonStringCompletionProcessor(edit, pyContentAssistant);

        pyContentAssistant.setRestoreCompletionProposalSize(getSettings("pydev_completion_proposal_size")); 

        // No code completion in comments
        pyContentAssistant.setContentAssistProcessor(stringProcessor, IPythonPartitions.PY_SINGLELINE_STRING1);
        pyContentAssistant.setContentAssistProcessor(stringProcessor, IPythonPartitions.PY_SINGLELINE_STRING2);
        pyContentAssistant.setContentAssistProcessor(stringProcessor, IPythonPartitions.PY_MULTILINE_STRING1);
        pyContentAssistant.setContentAssistProcessor(stringProcessor, IPythonPartitions.PY_MULTILINE_STRING2);
        pyContentAssistant.setContentAssistProcessor(stringProcessor, IPythonPartitions.PY_COMMENT);
        pyContentAssistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
        pyContentAssistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
        pyContentAssistant.enableAutoActivation(true); //always true, but the chars depend on whether it is activated or not in the preferences

        //note: delay and auto activate are set on PyContentAssistant constructor.

        pyContentAssistant.setDocumentPartitioning(IPythonPartitions.PYTHON_PARTITION_TYPE);
        pyContentAssistant.setAutoActivationDelay(PyCodeCompletionPreferencesPage.getAutocompleteDelay());
        try{
        	pyContentAssistant.setRepeatedInvocationMode(true);
        }catch(Exception e){
        	PydevPlugin.log(e);
        }
        
        try {
            pyContentAssistant.setRepeatedInvocationTrigger(KeySequence.getInstance("Ctrl+Space"));
        } catch (ParseException e) {
            PydevPlugin.log(e);
        }
        
        try{
        	pyContentAssistant.setStatusLineVisible(true);
        }catch(Exception e){
        	PydevPlugin.log(e);
        }
        
        return pyContentAssistant;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getQuickAssistAssistant(org.eclipse.jface.text.source.ISourceViewer)
     */
    public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) {
        // create a content assistant:
        PyCorrectionAssistant assistant = new PyCorrectionAssistant();

        // next create a content assistant processor to populate the completions window
        IQuickAssistProcessor processor = new PythonCorrectionProcessor(this.getEdit());

        // Correction assist works on all
        assistant.setQuickAssistProcessor(processor);
        assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));

        //delay and auto activate set on PyContentAssistant constructor.
        
        return assistant;
    }

    
    // The presenter instance for the information window
    private static final DefaultInformationControl.IInformationPresenter presenter = new PyInformationPresenter();

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getInformationControlCreator(org.eclipse.jface.text.source.ISourceViewer)
     */
    public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
        return new IInformationControlCreator() {
            public IInformationControl createInformationControl(Shell parent) {
                return new DefaultInformationControl(parent, presenter);
            }
        };
    }

    /**
     * Returns the settings for the given section.
     *
     * @param sectionName the section name
     * @return the settings
     * @since pydev 1.3.5
     */
    private IDialogSettings getSettings(String sectionName) {
        IDialogSettings settings= PydevPlugin.getDefault().getDialogSettings().getSection(sectionName);
        if (settings == null)
            settings= PydevPlugin.getDefault().getDialogSettings().addNewSection(sectionName);

        return settings;
    }


    /**
     * @param edit The edit to set.
     */
    private void setEdit(PyEdit edit) {
        this.edit = edit;
    }

    /**
     * @return Returns the edit.
     */
    private PyEdit getEdit() {
        return edit;
    }

    //updates the syntax highlighting for the specified preference
    //assumes that that editor colorCache has been updated with the
    //new named color
    public void updateSyntaxColorAndStyle() {
        if (reconciler != null) {
            //always update all (too much work in keeping this synchronized by type)
            codeScanner.updateColors();
            
            IPreferenceStore preferences = PydevPlugin.getChainedPrefStore();
            
            commentScanner.setStyle(preferences.getInt(PydevPrefs.COMMENT_STYLE));
            commentScanner.updateColorAndStyle();

            stringScanner.setStyle(preferences.getInt(PydevPrefs.STRING_STYLE));
            stringScanner.updateColorAndStyle();

            backquotesScanner.setStyle(preferences.getInt(PydevPrefs.BACKQUOTES_STYLE));
            backquotesScanner.updateColorAndStyle();
        }
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -