mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Added 'Format code' action in editor's text actions
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.actions.file
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.itsaky.androidide.R
|
||||
import com.itsaky.androidide.actions.ActionData
|
||||
import com.itsaky.androidide.actions.ActionItem
|
||||
import com.itsaky.androidide.actions.EditorRelatedAction
|
||||
|
||||
/**
|
||||
* Action that formats the code in the editor.
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
class FormatCodeAction() : EditorRelatedAction() {
|
||||
override val id: String = "editor_file_formatCode"
|
||||
override var location: ActionItem.Location = ActionItem.Location.EDITOR_TEXT_ACTIONS
|
||||
|
||||
constructor(context: Context) : this() {
|
||||
label = context.getString(R.string.title_format_code)
|
||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_format_code)
|
||||
}
|
||||
|
||||
override fun execAction(data: ActionData): Any {
|
||||
val editor = getEditor(data)!!
|
||||
editor.formatCodeAsync()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ import com.itsaky.androidide.actions.etc.DaemonStatusAction
|
||||
import com.itsaky.androidide.actions.etc.FileTreeAction
|
||||
import com.itsaky.androidide.actions.etc.FindActionMenu
|
||||
import com.itsaky.androidide.actions.etc.PreviewLayoutAction
|
||||
import com.itsaky.androidide.actions.file.FormatCodeAction
|
||||
import com.itsaky.androidide.actions.file.SaveFileAction
|
||||
import com.itsaky.androidide.actions.text.RedoAction
|
||||
import com.itsaky.androidide.actions.text.UndoAction
|
||||
@@ -80,6 +81,7 @@ class EditorActivityActions {
|
||||
registry.registerAction(CutAction(context))
|
||||
registry.registerAction(CopyAction(context))
|
||||
registry.registerAction(PasteAction(context))
|
||||
registry.registerAction(FormatCodeAction(context))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
Reference in New Issue
Block a user