diff --git a/CHANGELOG.md b/CHANGELOG.md index c8359a95..0b108ff3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/src/main/kotlin/org/fossify/filemanager/activities/ReadTextActivity.kt b/app/src/main/kotlin/org/fossify/filemanager/activities/ReadTextActivity.kt index 4e7678cf..6e7a7294 100644 --- a/app/src/main/kotlin/org/fossify/filemanager/activities/ReadTextActivity.kt +++ b/app/src/main/kotlin/org/fossify/filemanager/activities/ReadTextActivity.kt @@ -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() diff --git a/app/src/main/res/menu/menu_editor.xml b/app/src/main/res/menu/menu_editor.xml index bed84694..7cc37d72 100644 --- a/app/src/main/res/menu/menu_editor.xml +++ b/app/src/main/res/menu/menu_editor.xml @@ -11,8 +11,13 @@ +