mirror of
https://github.com/FossifyOrg/File-Manager.git
synced 2026-03-28 19:31:09 -04:00
feat: add save as in menu in text editor (#277)
* add save as in menu rename saveText to saveAsText() add new save() without confirmation Signed-off-by: Jan Guegel <jan@guegel.eu> * fix icon of new menuItem to ic_save_vector Signed-off-by: Jan Guegel <jan@guegel.eu> * apply CodeReview input getFilePath to updateFilePath menuItem SaveAs never displayed with icon backButtonPressed now uses Save without confirmation Signed-off-by: Jan Guegel <jan@guegel.eu> * fix catch filePath.isEmpty() by opening SaveAs Dialog Signed-off-by: Jan Guegel <jan@guegel.eu> --------- Signed-off-by: Jan Guegel <jan@guegel.eu> Co-authored-by: Jan Guegel <jan@guegel.eu> Refs: https://github.com/FossifyOrg/File-Manager/issues/224
This commit is contained in:
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Fixed missing permission prompt on initial "Save as" launch ([#85])
|
||||
- Fixed printing text files containing a "#" ([#104])
|
||||
|
||||
### Added
|
||||
- Added a separate "Save as" option in the text editor ([#224])
|
||||
|
||||
### Changed
|
||||
- Save button now overwrites files directly in the text editor ([#224])
|
||||
|
||||
## [1.2.3] - 2025-09-15
|
||||
### Fixed
|
||||
- Fixed folders showing up incorrectly as files in some cases ([#80])
|
||||
@@ -80,6 +86,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
[#250]: https://github.com/FossifyOrg/File-Manager/issues/250
|
||||
[#85]: https://github.com/FossifyOrg/File-Manager/issues/85
|
||||
[#104]: https://github.com/FossifyOrg/File-Manager/issues/104
|
||||
[#224]: https://github.com/FossifyOrg/File-Manager/issues/224
|
||||
|
||||
[Unreleased]: https://github.com/FossifyOrg/File-Manager/compare/1.2.3...HEAD
|
||||
[1.2.3]: https://github.com/FossifyOrg/File-Manager/compare/1.2.2...1.2.3
|
||||
|
||||
@@ -144,6 +144,7 @@ class ReadTextActivity : SimpleActivity() {
|
||||
when (menuItem.itemId) {
|
||||
R.id.menu_search -> openSearch()
|
||||
R.id.menu_save -> saveText()
|
||||
R.id.menu_save_as -> saveAsText()
|
||||
R.id.menu_open_with -> openPath(intent.dataString!!, true)
|
||||
R.id.menu_print -> printText()
|
||||
else -> return@setOnMenuItemClickListener false
|
||||
@@ -165,10 +166,14 @@ class ReadTextActivity : SimpleActivity() {
|
||||
}, 250)
|
||||
}
|
||||
|
||||
private fun saveText(shouldExitAfterSaving: Boolean = false) {
|
||||
private fun updateFilePath() {
|
||||
if (filePath.isEmpty()) {
|
||||
filePath = getRealPathFromURI(intent.data!!) ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveAsText(shouldExitAfterSaving: Boolean = false) {
|
||||
updateFilePath()
|
||||
|
||||
if (filePath.isEmpty()) {
|
||||
SaveAsDialog(this, filePath, true) { _, filename ->
|
||||
@@ -182,6 +187,7 @@ class ReadTextActivity : SimpleActivity() {
|
||||
} else {
|
||||
SELECT_SAVE_FILE_INTENT
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
startActivityForResult(this, requestCode)
|
||||
}
|
||||
}
|
||||
@@ -200,6 +206,21 @@ class ReadTextActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveText(shouldExitAfterSaving: Boolean = false) {
|
||||
updateFilePath()
|
||||
|
||||
if (filePath.isEmpty()) {
|
||||
saveAsText(shouldExitAfterSaving)
|
||||
} else if (hasStoragePermission()) {
|
||||
val file = File(filePath)
|
||||
getFileOutputStream(file.toFileDirItem(this), true) {
|
||||
saveTextContent(it, shouldExitAfterSaving, true)
|
||||
}
|
||||
} else {
|
||||
toast(R.string.no_storage_permissions)
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveTextContent(outputStream: OutputStream?, shouldExitAfterSaving: Boolean, shouldOverwriteOriginalText: Boolean) {
|
||||
if (outputStream != null) {
|
||||
val currentText = binding.readTextView.text.toString()
|
||||
|
||||
@@ -11,8 +11,13 @@
|
||||
<item
|
||||
android:id="@+id/menu_save"
|
||||
android:icon="@drawable/ic_save_vector"
|
||||
android:title="@string/save_as"
|
||||
android:title="@string/save"
|
||||
app:showAsAction="always" />
|
||||
<item
|
||||
android:id="@+id/menu_save_as"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/save_as"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/menu_print"
|
||||
android:icon="@drawable/ic_print_vector"
|
||||
|
||||
Reference in New Issue
Block a user