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-62 IJ: Action to start/stop breaks (#105)
- Loading branch information
Showing
21 changed files
with
729 additions
and
164 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package co.makerflow.client.models | ||
|
||
|
||
/** | ||
* Reason for a break during the workday. | ||
* | ||
* Can be one of the following: | ||
* - coffee | ||
* - tea | ||
* - beverage | ||
* - walk | ||
* - lunch | ||
* - running | ||
* - workout | ||
* - doctor | ||
* - child | ||
* - other | ||
*/ | ||
enum class BreakReason { | ||
COFFEE, TEA, BEVERAGE, WALK, LUNCH, RUNNING, WORKOUT, DOCTOR, CHILD, OTHER; | ||
} |
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
69 changes: 69 additions & 0 deletions
69
src/main/kotlin/co/makerflow/intellijplugin/actions/ToggleWorkBreakAction.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 | ||
|
||
import co.makerflow.intellijplugin.dialogs.StartWorkBreakDialog | ||
import co.makerflow.intellijplugin.services.WorkBreakService | ||
import co.makerflow.intellijplugin.state.FlowState | ||
import co.makerflow.intellijplugin.state.WorkBreakState | ||
import co.makerflow.intellijplugin.state.WorkBreakStateChangeNotifier | ||
import com.intellij.icons.AllIcons | ||
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.application.ApplicationManager | ||
import com.intellij.openapi.components.service | ||
import com.intellij.util.ui.UIUtil | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* Action to toggle work break | ||
*/ | ||
class ToggleWorkBreakAction : AnAction("Begin Break", "Take a break from work", AllIcons.Actions.Pause) { | ||
|
||
init { | ||
ApplicationManager.getApplication().messageBus.connect() | ||
.subscribe( | ||
WorkBreakStateChangeNotifier.WORK_BREAK_STATE_CHANGE_TOPIC, | ||
WorkBreakStateChangeNotifier { _, _ -> | ||
UIUtil.invokeLaterIfNeeded { | ||
update(AnActionEvent.createFromAnAction( | ||
this, | ||
null, | ||
"", | ||
DataContext.EMPTY_CONTEXT | ||
)) | ||
} | ||
}) | ||
} | ||
override fun update(e: AnActionEvent) { | ||
if (WorkBreakState.isOngoing().not()) { | ||
e.presentation.text = "Begin Break" | ||
e.presentation.description = "Take a break from work." | ||
} else { | ||
e.presentation.text = "Stop Break" | ||
e.presentation.description = "Stop the ongoing break session." | ||
} | ||
} | ||
|
||
override fun getActionUpdateThread(): ActionUpdateThread { | ||
return ActionUpdateThread.EDT | ||
} | ||
|
||
private val stopWorkBreakCoroutineScope = CoroutineScope(Dispatchers.IO) | ||
|
||
override fun actionPerformed(e: AnActionEvent) { | ||
if (WorkBreakState.isOngoing().not()) { | ||
StartWorkBreakDialog().show() | ||
} else { | ||
stopWorkBreakCoroutineScope.launch { | ||
WorkBreakState.instance.processing = true | ||
service<WorkBreakService>().stopWorkBreak().let { | ||
WorkBreakState.instance.currentBreak = null | ||
} | ||
WorkBreakState.instance.processing = false | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.