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

Allow toggle between light/dark mode separate from theme #92

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.bric3.excalidraw.actions

import com.github.bric3.excalidraw.SceneModes
import com.github.bric3.excalidraw.findEditor
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.util.ui.UIUtil

class ToggleLightDarkModeAction() : ToggleSceneModeAction() {

override fun setSelected(event: AnActionEvent, state: Boolean) {
val sceneModes = event.getSceneModes() ?: return

toggle(sceneModes, state)

// This SceneMode value gets passed to a different
// method than other scene mode toggles

var mode = "dark";
if(state)
mode = "light"
bric3 marked this conversation as resolved.
Show resolved Hide resolved

event.findEditor()!!.viewController.changeTheme(mode)
}

override fun toggle(sceneModes: SceneModes, state: Boolean) {
sceneModes.lightMode = state
}
bric3 marked this conversation as resolved.
Show resolved Hide resolved

// Default selected state is dervived from the UI theme
// if user has not set a state
override fun isSelected(event: AnActionEvent): Boolean =
event.getSceneModes()?.lightMode ?: !UIUtil.isUnderDarcula()

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class SceneModes(
var gridMode: Boolean? = null,
var zenMode: Boolean? = null,
var readOnlyMode: Boolean? = null,
var lightMode: Boolean? = null, // allow overriding uiTheme for the editor window
) {
companion object {
val SCENE_MODES_KEY: Key<SceneModes> = Key.create(SceneModes::javaClass.name)
Expand Down
6 changes: 6 additions & 0 deletions plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
text="Toggle Zen Mode"
description="Toggle the zen mode"
icon="AllIcons.General.ReaderMode"/>
<action id="excalidraw.ToggleLightDarkMode"
class="com.github.bric3.excalidraw.actions.ToggleLightDarkModeAction"
text="Toggle Light/Dark Mode"
description="Toggle Light/Dark mode"
icon="AllIcons.Actions.IntentionBulb"/>

<!-- AllIcons.Actions.InlayGlobe -->

Expand All @@ -98,6 +103,7 @@
<separator/>
<reference ref="excalidraw.ToggleGridMode" />
<reference ref="excalidraw.ToggleZenMode" />
<reference ref="excalidraw.ToggleLightDarkMode" />
</group>

</actions>
Expand Down