Skip to content

Commit 8647071

Browse files
authored
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 <[email protected]> * fix icon of new menuItem to ic_save_vector Signed-off-by: Jan Guegel <[email protected]> * apply CodeReview input getFilePath to updateFilePath menuItem SaveAs never displayed with icon backButtonPressed now uses Save without confirmation Signed-off-by: Jan Guegel <[email protected]> * fix catch filePath.isEmpty() by opening SaveAs Dialog Signed-off-by: Jan Guegel <[email protected]> --------- Signed-off-by: Jan Guegel <[email protected]> Co-authored-by: Jan Guegel <[email protected]> Refs: #224
1 parent 630d7b2 commit 8647071

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Fixed missing permission prompt on initial "Save as" launch ([#85])
1212
- Fixed printing text files containing a "#" ([#104])
1313

14+
### Added
15+
- Added a separate "Save as" option in the text editor ([#224])
16+
17+
### Changed
18+
- Save button now overwrites files directly in the text editor ([#224])
19+
1420
## [1.2.3] - 2025-09-15
1521
### Fixed
1622
- 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
8086
[#250]: https://github.com/FossifyOrg/File-Manager/issues/250
8187
[#85]: https://github.com/FossifyOrg/File-Manager/issues/85
8288
[#104]: https://github.com/FossifyOrg/File-Manager/issues/104
89+
[#224]: https://github.com/FossifyOrg/File-Manager/issues/224
8390

8491
[Unreleased]: https://github.com/FossifyOrg/File-Manager/compare/1.2.3...HEAD
8592
[1.2.3]: https://github.com/FossifyOrg/File-Manager/compare/1.2.2...1.2.3

app/src/main/kotlin/org/fossify/filemanager/activities/ReadTextActivity.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class ReadTextActivity : SimpleActivity() {
144144
when (menuItem.itemId) {
145145
R.id.menu_search -> openSearch()
146146
R.id.menu_save -> saveText()
147+
R.id.menu_save_as -> saveAsText()
147148
R.id.menu_open_with -> openPath(intent.dataString!!, true)
148149
R.id.menu_print -> printText()
149150
else -> return@setOnMenuItemClickListener false
@@ -165,10 +166,14 @@ class ReadTextActivity : SimpleActivity() {
165166
}, 250)
166167
}
167168

168-
private fun saveText(shouldExitAfterSaving: Boolean = false) {
169+
private fun updateFilePath() {
169170
if (filePath.isEmpty()) {
170171
filePath = getRealPathFromURI(intent.data!!) ?: ""
171172
}
173+
}
174+
175+
private fun saveAsText(shouldExitAfterSaving: Boolean = false) {
176+
updateFilePath()
172177

173178
if (filePath.isEmpty()) {
174179
SaveAsDialog(this, filePath, true) { _, filename ->
@@ -182,6 +187,7 @@ class ReadTextActivity : SimpleActivity() {
182187
} else {
183188
SELECT_SAVE_FILE_INTENT
184189
}
190+
@Suppress("DEPRECATION")
185191
startActivityForResult(this, requestCode)
186192
}
187193
}
@@ -200,6 +206,21 @@ class ReadTextActivity : SimpleActivity() {
200206
}
201207
}
202208

209+
private fun saveText(shouldExitAfterSaving: Boolean = false) {
210+
updateFilePath()
211+
212+
if (filePath.isEmpty()) {
213+
saveAsText(shouldExitAfterSaving)
214+
} else if (hasStoragePermission()) {
215+
val file = File(filePath)
216+
getFileOutputStream(file.toFileDirItem(this), true) {
217+
saveTextContent(it, shouldExitAfterSaving, true)
218+
}
219+
} else {
220+
toast(R.string.no_storage_permissions)
221+
}
222+
}
223+
203224
private fun saveTextContent(outputStream: OutputStream?, shouldExitAfterSaving: Boolean, shouldOverwriteOriginalText: Boolean) {
204225
if (outputStream != null) {
205226
val currentText = binding.readTextView.text.toString()

app/src/main/res/menu/menu_editor.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
<item
1212
android:id="@+id/menu_save"
1313
android:icon="@drawable/ic_save_vector"
14-
android:title="@string/save_as"
14+
android:title="@string/save"
1515
app:showAsAction="always" />
16+
<item
17+
android:id="@+id/menu_save_as"
18+
android:showAsAction="never"
19+
android:title="@string/save_as"
20+
app:showAsAction="never" />
1621
<item
1722
android:id="@+id/menu_print"
1823
android:icon="@drawable/ic_print_vector"

0 commit comments

Comments
 (0)