Search in sources :

Example 1 with SnippetData

use of org.rstudio.studio.client.workbench.snippets.model.SnippetData in project rstudio by rstudio.

the class SnippetHelper method onSnippetsChanged.

public static void onSnippetsChanged(SnippetsChangedEvent event) {
    SnippetManager manager = getSnippetManager();
    JsArray<SnippetData> data = event.getData();
    for (int i = 0; i < data.length(); i++) {
        SnippetData snippetData = data.get(i);
        loadSnippetsForMode(snippetData.getMode(), snippetData.getContents(), manager);
    }
}
Also used : SnippetData(org.rstudio.studio.client.workbench.snippets.model.SnippetData)

Example 2 with SnippetData

use of org.rstudio.studio.client.workbench.snippets.model.SnippetData in project rstudio by rstudio.

the class EditSnippetsDialog method attemptSaveAndClose.

private void attemptSaveAndClose() {
    // record pending edits
    recordEditorState();
    // check for edits we need to save
    JsArray<SnippetData> changedSnippets = JsArray.createArray().cast();
    for (int i = 0; i < snippetTypes_.getItemCount(); i++) {
        EditableSnippets snippets = snippetTypes_.getItemAtIdx(i);
        String edits = snippets.getPendingEdits();
        if (edits != null) {
            String mode = snippets.getEditorMode();
            JavaScriptException ex = SnippetHelper.loadSnippetsForMode(mode, edits);
            if (ex != null) {
                snippetTypes_.setSelectedIndex(i);
                globalDisplay_.showErrorMessage("Error Applying Snippets (" + snippets.getFileTypeLabel() + ")", ex.getDescription());
                // early return (don't close dialog)
                return;
            }
            changedSnippets.push(SnippetData.create(mode, edits));
        }
    }
    // perform the save then close the dialog
    if (changedSnippets.length() > 0) {
        server_.saveSnippets(changedSnippets, new VoidServerRequestCallback() {

            @Override
            protected void onSuccess() {
                closeDialog();
            }
        });
    } else {
        closeDialog();
    }
}
Also used : SnippetData(org.rstudio.studio.client.workbench.snippets.model.SnippetData) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) JavaScriptException(com.google.gwt.core.client.JavaScriptException)

Aggregations

SnippetData (org.rstudio.studio.client.workbench.snippets.model.SnippetData)2 JavaScriptException (com.google.gwt.core.client.JavaScriptException)1 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)1