Search in sources :

Example 1 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project xtext-eclipse by eclipse.

the class AdvancedTemplatesPreferencePage method updateViewerInput.

@Override
protected void updateViewerInput() {
    IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
    if (selection.size() == 1) {
        TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
        Template template = data.getTemplate();
        String name = template.getName();
        TemplateContextType contextType = getContextTypeRegistry().getContextType(template.getContextTypeId());
        if (contextType != null) {
            String prefix = "templates for " + grammarAccess.getGrammar().getName() + "'" + name + "'" + " for " + getContextTypeForGrammar(contextType) + ">>";
            String editablePart = template.getPattern();
            String suffix = "";
            partialEditor.updateModel(prefix, editablePart, suffix);
        } else {
            partialEditor.updateModel("", template.getPattern(), "");
        }
    } else {
        partialEditor.updateModel("", "", "");
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) Template(org.eclipse.jface.text.templates.Template)

Example 2 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.

the class ContributionTemplateStore method loadContributedTemplates.

/**
 * Loads the templates contributed via the templates extension point.
 *
 * @throws IOException {@inheritDoc}
 */
@Override
protected void loadContributedTemplates() throws IOException {
    IConfigurationElement[] extensions = getTemplateExtensions();
    Collection<TemplatePersistenceData> contributed = readContributedTemplates(extensions);
    for (Iterator<TemplatePersistenceData> it = contributed.iterator(); it.hasNext(); ) {
        TemplatePersistenceData data = it.next();
        internalAdd(data);
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 3 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.

the class ContributionTemplateStore method createTemplate.

private void createTemplate(Collection<TemplatePersistenceData> map, IConfigurationElement element) {
    String contextTypeId = element.getAttribute(CONTEXT_TYPE_ID);
    // log failures since extension point id and name are mandatory
    if (contextExists(contextTypeId)) {
        String id = element.getAttribute(ID);
        if (isValidTemplateId(id)) {
            String name = element.getAttribute(NAME);
            if (name != null) {
                String pattern = element.getChildren(PATTERN)[0].getValue();
                if (pattern != null) {
                    String desc = element.getAttribute(DESCRIPTION);
                    if (desc == null)
                        // $NON-NLS-1$
                        desc = "";
                    String autoInsert = element.getAttribute(AUTO_INSERT);
                    boolean bAutoInsert;
                    if (autoInsert == null)
                        bAutoInsert = true;
                    else
                        bAutoInsert = Boolean.valueOf(autoInsert).booleanValue();
                    Template template = new Template(name, desc, contextTypeId, pattern, bAutoInsert);
                    TemplatePersistenceData data = new TemplatePersistenceData(template, true, id);
                    if (validateTemplate(template))
                        map.add(data);
                }
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) Template(org.eclipse.jface.text.templates.Template)

Example 4 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.

the class AbstractTemplatesPage method addTemplate.

/**
 * Add a template. The dialog is filled with the values from the given template.
 *
 * @param template the template
 */
private void addTemplate(Template template) {
    Template newTemplate;
    newTemplate = editTemplate(template, false, true);
    if (newTemplate != null) {
        TemplatePersistenceData data = new TemplatePersistenceData(newTemplate, true);
        getTemplateStore().add(data);
        saveTemplateStore();
        refresh();
        fTreeViewer.setSelection(new StructuredSelection(data), true);
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Template(org.eclipse.jface.text.templates.Template)

Example 5 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.

the class AbstractTemplatesPage method createActions.

/**
 * Create all the actions
 */
private void createActions() {
    fInsertAction = new Action(TemplatesMessages.TemplatesPage_insert) {

        @Override
        public void run() {
            TemplatePersistenceData[] selectedTemplates = getSelectedTemplates();
            insertTemplate(selectedTemplates[0].getTemplate());
        }
    };
    fInsertAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_INSERT));
    fInsertAction.setDisabledImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_INSERT));
    fInsertAction.setToolTipText(TemplatesMessages.TemplatesPage_insert_tooltip);
    fAddAction = new Action(TemplatesMessages.TemplatesPage_new) {

        @Override
        public void run() {
            addTemplate();
        }
    };
    fAddAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_NEW));
    fAddAction.setToolTipText(TemplatesMessages.TemplatesPage_new_tooltip);
    fEditAction = new Action(TemplatesMessages.TemplatesPage_edit) {

        @Override
        public void run() {
            editTemplate();
        }
    };
    fEditAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_EDIT));
    fEditAction.setDisabledImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_EDIT));
    fEditAction.setToolTipText(TemplatesMessages.TemplatesPage_edit_tooltip);
    fRemoveAction = new Action(TemplatesMessages.TemplatesPage_remove) {

        @Override
        public void run() {
            removeTemplates();
        }
    };
    fRemoveAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_DELETE));
    fRemoveAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_DELETE));
    fRemoveAction.setToolTipText(TemplatesMessages.TemplatesPage_remove_tooltip);
    fLinkWithEditorAction = new Action(TemplatesMessages.TemplatesPage_link_to_editor, IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            fPreferenceStore.setValue(LINK_ACTION_PREF_ID, fLinkWithEditorAction.isChecked());
            refresh();
        }
    };
    fLinkWithEditorAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_LINK));
    fLinkWithEditorAction.setChecked(fPreferenceStore.getBoolean(LINK_ACTION_PREF_ID));
    fLinkWithEditorAction.setToolTipText(TemplatesMessages.TemplatesPage_link_to_editor_tooltip);
    fCollapseAllAction = new Action(TemplatesMessages.TemplatesPage_collapse_all) {

        @Override
        public void run() {
            fTreeViewer.collapseAll();
        }
    };
    fCollapseAllAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_COLLAPSE_ALL));
    fCollapseAllAction.setToolTipText(TemplatesMessages.TemplatesPage_collapse_all_tooltip);
    if (getPreferencePageId() != null) {
        fPreferencePageAction = new Action(TemplatesMessages.TemplatesPage_preference_page) {

            @Override
            public void run() {
                showPreferencePage();
            }
        };
        fPreferencePageAction.setToolTipText(TemplatesMessages.TemplatesPage_preference_page_tooltip);
    }
    fPasteAction = new Action() {

        @Override
        public void run() {
            Clipboard clipboard = new Clipboard(getShell().getDisplay());
            try {
                String pattern = ((String) clipboard.getContents(TextTransfer.getInstance()));
                if (pattern != null) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    final Template template = new Template(createTemplateName(), TemplatesMessages.TemplatesPage_paste_description, getContextTypeId(), pattern.replaceAll("\\$", "\\$\\$"), true);
                    getShell().getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            addTemplate(template);
                        }
                    });
                    return;
                }
                TemplatePersistenceData[] templates = (TemplatePersistenceData[]) clipboard.getContents(TemplatesTransfer.getInstance());
                if (templates != null)
                    copyTemplates(templates, getContextTypeId());
            } finally {
                clipboard.dispose();
            }
        }
    };
    fCopyAction = new Action() {

        @Override
        public void run() {
            Clipboard clipboard = new Clipboard(getShell().getDisplay());
            try {
                clipboard.setContents(new Object[] { getSelectedTemplates() }, new Transfer[] { TemplatesTransfer.getInstance() });
            } finally {
                clipboard.dispose();
            }
        }
    };
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) Template(org.eclipse.jface.text.templates.Template)

Aggregations

TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)36 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)17 Template (org.eclipse.jface.text.templates.Template)13 TemplateReaderWriter (org.eclipse.jface.text.templates.persistence.TemplateReaderWriter)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 InputStream (java.io.InputStream)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 URL (java.net.URL)4 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)4 BufferedInputStream (java.io.BufferedInputStream)3 PropertyResourceBundle (java.util.PropertyResourceBundle)3 ResourceBundle (java.util.ResourceBundle)3 Point (org.eclipse.swt.graphics.Point)3 Bundle (org.osgi.framework.Bundle)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Action (org.eclipse.jface.action.Action)2 IAction (org.eclipse.jface.action.IAction)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2