mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
feat(actions): add API to destroy ActionItem instances
This commit is contained in:
@@ -23,6 +23,7 @@ import android.view.View
|
||||
/**
|
||||
* An action that can be registered using the [ActionsRegistry]
|
||||
* [com.itsaky.androidide.actions.ActionsRegistry]
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
interface ActionItem {
|
||||
@@ -37,6 +38,7 @@ interface ActionItem {
|
||||
|
||||
/**
|
||||
* Prepare the action. Subclasses can modify the visual properties of this action here.
|
||||
*
|
||||
* @param data The data containing various information about the event.
|
||||
*/
|
||||
fun prepare(data: ActionData)
|
||||
@@ -57,6 +59,12 @@ interface ActionItem {
|
||||
*/
|
||||
fun postExec(data: ActionData, result: Any) = Unit
|
||||
|
||||
/**
|
||||
* Called when the action item is to be destroyed. Any resource references must be released if
|
||||
* held.
|
||||
*/
|
||||
fun destroy() = Unit
|
||||
|
||||
/**
|
||||
* Return the show as action flags for the menu item.
|
||||
*
|
||||
|
||||
+9
-1
@@ -66,6 +66,7 @@ class DefaultActionsRegistry : ActionsRegistry() {
|
||||
val actions = getActions(action.location)
|
||||
val older = actions.remove(action.id)
|
||||
if (older != null) {
|
||||
older.destroy()
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -76,6 +77,7 @@ class DefaultActionsRegistry : ActionsRegistry() {
|
||||
for (locations in this.actions.values) {
|
||||
val older = locations.remove(id)
|
||||
if (older != null) {
|
||||
older.destroy()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -86,7 +88,13 @@ class DefaultActionsRegistry : ActionsRegistry() {
|
||||
override fun findAction(location: ActionItem.Location, id: String): ActionItem? =
|
||||
getActions(location)[id]
|
||||
|
||||
override fun clearActions(location: ActionItem.Location) = getActions(location).clear()
|
||||
override fun clearActions(location: ActionItem.Location) {
|
||||
val actions = getActions(location)
|
||||
actions.forEach {
|
||||
it.value.destroy()
|
||||
}
|
||||
actions.clear()
|
||||
}
|
||||
|
||||
override fun registerActionExecListener(listener: ActionExecListener) {
|
||||
listeners.add(listener)
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user