Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Comment thread
jguegel marked this conversation as resolved.
## [1.2.3] - 2025-09-15
### Fixed
- Fixed folders showing up incorrectly as files in some cases ([#80])
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ->
Expand All @@ -182,6 +187,7 @@ class ReadTextActivity : SimpleActivity() {
} else {
SELECT_SAVE_FILE_INTENT
}
@Suppress("DEPRECATION")
startActivityForResult(this, requestCode)
}
}
Expand All @@ -200,6 +206,21 @@ class ReadTextActivity : SimpleActivity() {
}
}

private fun saveText(shouldExitAfterSaving: Boolean = false) {
updateFilePath()

Comment thread
jguegel marked this conversation as resolved.
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()
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/menu/menu_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading