Skip to content

Commit

Permalink
Merge pull request #769 from timja/update-theme-api
Browse files Browse the repository at this point in the history
Support system themes for Pipeline editor
  • Loading branch information
jglick authored Sep 26, 2023
2 parents ac0338e + 4d73ccb commit 65dec41
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 63 deletions.
2 changes: 1 addition & 1 deletion plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"dev": "webpack --config webpack.dev.js",
"prod": "webpack --config webpack.prod.js",
"start": "yarn dev -- --watch",
"start": "yarn dev --watch",
"lint:js": "eslint src/main/js --ext js",
"mvnbuild": "yarn prod",
"mvntest": "yarn lint:js"
Expand Down
11 changes: 0 additions & 11 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>theme-manager</artifactId>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>io.jenkins.blueocean</groupId>
<artifactId>blueocean-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,16 @@
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.workflow.cps.persistence.PersistIn;
import org.jenkinsci.plugins.workflow.cps.replay.ReplayAction;
import org.jenkinsci.plugins.workflow.cps.view.ThemeUtil;
import org.jenkinsci.plugins.workflow.flow.DurabilityHintProvider;
import org.jenkinsci.plugins.workflow.flow.FlowDefinition;
import org.jenkinsci.plugins.workflow.flow.FlowDefinitionDescriptor;
import org.jenkinsci.plugins.workflow.flow.FlowDurabilityHint;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;
import org.jenkinsci.plugins.workflow.flow.GlobalDefaultFlowDurabilityLevel;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import net.sf.json.JSON;
Expand Down Expand Up @@ -184,10 +179,4 @@ public JSON doCheckScriptCompile(@AncestorInPath Item job, @QueryParameter Strin
}

}

/** @see ReplayAction#getTheme */
@Restricted(DoNotUse.class)
/* accessible to Jelly */ public String getTheme() {
return ThemeUtil.getTheme();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import org.acegisecurity.AccessDeniedException;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.cps.view.ThemeUtil;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;
import org.kohsuke.accmod.Restricted;
Expand Down Expand Up @@ -200,12 +199,6 @@ private ReplayAction(Run run) {
return run;
}

/** @see CpsFlowDefinition#getTheme */
@Restricted(DoNotUse.class)
/* accessible to Jelly */ public String getTheme() {
return ThemeUtil.getTheme();
}

@Restricted(DoNotUse.class)
@RequirePOST
public void doRun(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
Expand Down

This file was deleted.

18 changes: 15 additions & 3 deletions plugin/src/main/js/workflow-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import "./snippets/workflow";

var editorIdCounter = 0;

function setTheme(editor) {
const theme = window.getThemeManagerProperty('ace-editor', 'theme') || 'tomorrow'
editor.setTheme("ace/theme/" + theme);
}

$(function() {
$('.workflow-editor-wrapper').each(function() {
initEditor($(this));
Expand Down Expand Up @@ -44,10 +49,17 @@ $(function() {
var snippetContent = ace.require('ace/snippets/groovy').snippetText;
var snippets = snippetManager.parseSnippetFile(snippetContent);
snippetManager.register(snippets, 'groovy');

editor.session.setMode("ace/mode/groovy");
var theme = aceContainer.attr("theme") === "tomorrow_night" ? "tomorrow_night" : "tomorrow";
editor.setTheme("ace/theme/" + theme);
if (window.getThemeManagerProperty) {
setTheme(editor);

if (window.isSystemRespectingTheme) {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
setTheme(editor)
});
}

}
editor.setAutoScrollEditorIntoView(true);
editor.setOption("minLines", 20);
// enable autocompletion and snippets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler" xmlns:wfe="/org/jenkinsci/plugins/workflow/editor">
<input type="hidden" name="oldScript" value="${instance.script}"/>
<f:entry title="${%Script}" field="script">
<wfe:workflow-editor theme="${instance.theme}" />
<wfe:workflow-editor />
</f:entry>
<f:entry field="sandbox">
<f:checkbox title="${%Use Groovy Sandbox}" default="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<st:attribute name="script">
The script.
</st:attribute>
<st:attribute name="theme">
The ACE editor theme.
</st:attribute>
</st:documentation>
<j:choose>
<j:when test="${h.isUnitTest}">
Expand All @@ -17,7 +14,7 @@
<j:otherwise>
<div class="workflow-editor-wrapper" style="display: none; position: relative">
<f:textarea value="${script}" checkMethod="post" checkUrl="${attrs.checkUrl}" checkDependsOn="${attrs.checkDependsOn}"/>
<div class="pane-frame editor" style="height: 250px;" samplesUrl="${rootURL}/workflow-cps-samples/" theme="${theme ?: 'tomorrow'}"/>
<div class="pane-frame editor" style="height: 250px;" samplesUrl="${rootURL}/workflow-cps-samples/" />
</div>
<st:adjunct includes="org.jenkinsci.plugins.workflow.cps.workflow-editor"/>
</j:otherwise>
Expand Down

0 comments on commit 65dec41

Please sign in to comment.