generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAK-58 IJ: Start timed flow modes from status bar widget (#102)
- Loading branch information
Showing
17 changed files
with
340 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
src/main/kotlin/co/makerflow/intellijplugin/actions/ToggleFlowModeAction.kt
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
src/main/kotlin/co/makerflow/intellijplugin/actions/flowmode/FiftyMinutesFlowModeAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package co.makerflow.intellijplugin.actions.flowmode | ||
|
||
class FiftyMinutesFlowModeAction : | ||
FlowModeAction("Flow Mode (50 minutes)", "Begin a timed flow mode session for 50 minutes", duration = 50) |
69 changes: 69 additions & 0 deletions
69
src/main/kotlin/co/makerflow/intellijplugin/actions/flowmode/FlowModeAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package co.makerflow.intellijplugin.actions.flowmode | ||
|
||
import co.makerflow.intellijplugin.services.FlowModeService | ||
import co.makerflow.intellijplugin.services.toFlow | ||
import co.makerflow.intellijplugin.state.FlowState | ||
import com.intellij.ide.actions.searcheverywhere.PossibleSlowContributor | ||
import com.intellij.openapi.actionSystem.ActionUpdateThread | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.components.service | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
abstract class FlowModeAction( | ||
text: String, | ||
description: String, | ||
private val duration: Int? = null | ||
) : | ||
AnAction(text, description, null), PossibleSlowContributor { | ||
private val startFlowModeCoroutineScope = CoroutineScope(Dispatchers.IO) | ||
private val stopFlowModeCoroutineScope = CoroutineScope(Dispatchers.IO) | ||
private fun stopFlowMode() { | ||
FlowState.instance.processing = true | ||
val flowModeService = service<FlowModeService>() | ||
ApplicationManager.getApplication().invokeLater { | ||
stopFlowModeCoroutineScope.launch { | ||
flowModeService.stopFlowMode() | ||
FlowState.instance.currentFlow = null | ||
}.invokeOnCompletion { | ||
FlowState.instance.processing = false | ||
} | ||
} | ||
} | ||
|
||
private fun startFlowMode() { | ||
FlowState.instance.processing = true | ||
val flowModeService = service<FlowModeService>() | ||
ApplicationManager.getApplication().invokeLater { | ||
startFlowModeCoroutineScope.launch { | ||
flowModeService.startFlowMode(null, duration)?.let { flowMode -> | ||
FlowState.instance.currentFlow = flowMode.toFlow() | ||
} | ||
}.invokeOnCompletion { | ||
FlowState.instance.processing = false | ||
} | ||
} | ||
} | ||
|
||
override fun actionPerformed(e: AnActionEvent) { | ||
if (FlowState.instance.currentFlow == null) { | ||
startFlowMode() | ||
} else { | ||
stopFlowMode() | ||
} | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
val flowState = FlowState.instance | ||
if (duration != null) { | ||
e.presentation.isEnabled = !flowState.processing && flowState.currentFlow == null | ||
} | ||
} | ||
|
||
override fun getActionUpdateThread(): ActionUpdateThread { | ||
return ActionUpdateThread.BGT | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/main/kotlin/co/makerflow/intellijplugin/actions/flowmode/FlowModeActionGroup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package co.makerflow.intellijplugin.actions.flowmode | ||
|
||
import co.makerflow.intellijplugin.state.Flow | ||
import co.makerflow.intellijplugin.state.FlowState | ||
import co.makerflow.intellijplugin.state.FlowStateChangeNotifier | ||
import com.intellij.ide.actions.searcheverywhere.PossibleSlowContributor | ||
import com.intellij.openapi.actionSystem.ActionManager | ||
import com.intellij.openapi.actionSystem.ActionUpdateThread | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.DataContext | ||
import com.intellij.openapi.actionSystem.DefaultActionGroup | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.util.ui.UIUtil | ||
|
||
const val STOP_FLOW_MODE_DIRECTIVE = "Stop Flow Mode" | ||
|
||
private const val STOP_FLOW_MODE_DESCRIPTION = "Stop the ongoing Flow Mode session" | ||
|
||
class FlowModeActionGroup : DefaultActionGroup(), PossibleSlowContributor { | ||
init { | ||
UIUtil.invokeLaterIfNeeded { | ||
if (FlowState.instance.currentFlow != null) { | ||
updateTemplateForStoppingFlowMode() | ||
} else { | ||
updateTemplateForStartingFlowMode() | ||
} | ||
} | ||
ApplicationManager.getApplication().messageBus.connect() | ||
.subscribe(FlowStateChangeNotifier.FLOW_STATE_CHANGE_TOPIC, object : FlowStateChangeNotifier { | ||
override fun updated(flow: Flow?, processing: Boolean) { | ||
UIUtil.invokeLaterIfNeeded { | ||
if (flow != null) { | ||
updateTemplateForStoppingFlowMode() | ||
updateTimedFlowModeActions() | ||
} else { | ||
updateTemplateForStartingFlowMode() | ||
updateTimedFlowModeActions() | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
if (FlowState.instance.currentFlow != null) { | ||
e.presentation.text = STOP_FLOW_MODE_DIRECTIVE | ||
e.presentation.description = STOP_FLOW_MODE_DESCRIPTION | ||
e.presentation.isEnabled = false | ||
} else { | ||
e.presentation.text = "Choose Flow Mode Session Type" | ||
e.presentation.description = "Choose a Flow Mode type to start a new session" | ||
e.presentation.isEnabled = true | ||
} | ||
} | ||
|
||
override fun getActionUpdateThread(): ActionUpdateThread { | ||
return ActionUpdateThread.BGT | ||
} | ||
|
||
private fun updateTemplateForStoppingFlowMode() { | ||
update(buildActionEvent(this)) | ||
val toggleFlowModeAction = ActionManager.getInstance() | ||
.getAction("co.makerflow.intellijplugin.actions.flowmode.ToggleFlowModeAction") | ||
toggleFlowModeAction.update( | ||
buildActionEvent(toggleFlowModeAction) | ||
) | ||
} | ||
|
||
private fun updateTemplateForStartingFlowMode() { | ||
update(buildActionEvent(this)) | ||
val toggleFlowModeAction = ActionManager.getInstance() | ||
.getAction("co.makerflow.intellijplugin.actions.flowmode.ToggleFlowModeAction") | ||
toggleFlowModeAction.update( | ||
buildActionEvent(toggleFlowModeAction) | ||
) | ||
} | ||
|
||
private fun updateTimedFlowModeActions() { | ||
val twentyFiveMinutesFlowModeAction = ActionManager.getInstance() | ||
.getAction("co.makerflow.intellijplugin.actions.flowmode.TwentyFiveMinutesFlowModeAction") | ||
twentyFiveMinutesFlowModeAction.update( | ||
buildActionEvent(twentyFiveMinutesFlowModeAction) | ||
) | ||
val fiftyMinutesFlowModeAction = ActionManager.getInstance() | ||
.getAction("co.makerflow.intellijplugin.actions.flowmode.FiftyMinutesFlowModeAction") | ||
fiftyMinutesFlowModeAction.update( | ||
buildActionEvent(fiftyMinutesFlowModeAction) | ||
) | ||
val seventyFiveMinutesFlowModeAction = ActionManager.getInstance() | ||
.getAction("co.makerflow.intellijplugin.actions.flowmode.SeventyFiveMinutesFlowModeAction") | ||
seventyFiveMinutesFlowModeAction.update( | ||
buildActionEvent(seventyFiveMinutesFlowModeAction) | ||
) | ||
} | ||
|
||
private fun buildActionEvent(action: AnAction) = | ||
AnActionEvent.createFromAnAction( | ||
action, | ||
null, | ||
"", | ||
DataContext.EMPTY_CONTEXT | ||
) | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...n/kotlin/co/makerflow/intellijplugin/actions/flowmode/SeventyFiveMinutesFlowModeAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package co.makerflow.intellijplugin.actions.flowmode | ||
|
||
class SeventyFiveMinutesFlowModeAction : | ||
FlowModeAction( | ||
"Flow Mode (75 minutes)", | ||
"Begin a timed flow mode session for 75 minutes", | ||
duration = 75 | ||
) |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/co/makerflow/intellijplugin/actions/flowmode/ToggleFlowModeAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package co.makerflow.intellijplugin.actions.flowmode | ||
|
||
import co.makerflow.intellijplugin.state.FlowState | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
|
||
private const val START_FLOW_MODE_DIRECTIVE = "Start Flow Mode (Without Timer)" | ||
private const val START_FLOW_MODE_DESCRIPTION = "Begin an untimed Flow Mode session" | ||
|
||
class ToggleFlowModeAction : | ||
FlowModeAction( | ||
START_FLOW_MODE_DIRECTIVE, | ||
START_FLOW_MODE_DESCRIPTION | ||
) { | ||
override fun update(e: AnActionEvent) { | ||
if (FlowState.instance.currentFlow == null) { | ||
e.presentation.text = START_FLOW_MODE_DIRECTIVE | ||
e.presentation.description = START_FLOW_MODE_DESCRIPTION | ||
} else { | ||
e.presentation.text = STOP_FLOW_MODE_DIRECTIVE | ||
e.presentation.description = "Stop the ongoing Flow Mode session" | ||
} | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...in/kotlin/co/makerflow/intellijplugin/actions/flowmode/TwentyFiveMinutesFlowModeAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package co.makerflow.intellijplugin.actions.flowmode | ||
|
||
class TwentyFiveMinutesFlowModeAction : | ||
FlowModeAction("Flow Mode (25 minutes)", "Begin a timed flow mode session for 25 minutes", duration = 25) |
15 changes: 0 additions & 15 deletions
15
...main/kotlin/co/makerflow/intellijplugin/listeners/FlowModeStatusBarWidgetClickListener.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.