Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support system themes for Pipeline editor #769

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecation warning in my build console that yarn hasn't needed this since yarn v1.0

"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 @@ -191,17 +191,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>theme-manager</artifactId>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only needed as a JavaScript API now so not needed to be in pom. We could leave it in bumping the version to ensure that the plugins work together but I don't think needed

<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