-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GTK: Add reload button to list-view-page, fix layout
- Loading branch information
Showing
3 changed files
with
65 additions
and
46 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
aat-gtk/src/main/kotlin/ch/bailu/aat_gtk/view/solid/SolidDirectoryDropDownView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ch.bailu.aat_gtk.view.solid | ||
|
||
import ch.bailu.aat_lib.app.AppContext | ||
import ch.bailu.aat_lib.logger.AppLog | ||
import ch.bailu.aat_lib.preferences.OnPreferencesChanged | ||
import ch.bailu.aat_lib.preferences.SolidDirectoryQuery | ||
import ch.bailu.aat_lib.preferences.StorageInterface | ||
import ch.bailu.aat_lib.util.fs.AppDirectory | ||
import ch.bailu.gtk.gtk.DropDown | ||
import ch.bailu.gtk.type.Strs | ||
|
||
|
||
class SolidDirectoryDropDownView(appContext: AppContext) | ||
: OnPreferencesChanged { | ||
private val solidDirectoryQuery = SolidDirectoryQuery(appContext.storage, appContext) | ||
private val directories = AppDirectory.getGpxDirectories(appContext) | ||
|
||
val dropDown: DropDown | ||
|
||
init { | ||
val model = ArrayList<String ?>() | ||
|
||
model.addAll(directories.map { | ||
limitWidth(it.name, 30) // TODO width limit should be handled by GTK (but how?) | ||
}) | ||
model.add(null) | ||
dropDown = DropDown.newFromStringsDropDown(Strs(model.toTypedArray())) | ||
|
||
indexFromSolid() | ||
|
||
dropDown.onNotify { | ||
AppLog.d(SolidDirectoryQuery@this, it.name.toString()) | ||
|
||
if ("selected" == it.name.toString()) { // Property "selected" has changed | ||
solidDirectoryQuery.setValue(directories[dropDown.selected].file.path) | ||
} | ||
} | ||
|
||
dropDown.showArrow = false | ||
solidDirectoryQuery.register(this) | ||
} | ||
|
||
override fun onPreferencesChanged(storage: StorageInterface, key: String) { | ||
if (key == solidDirectoryQuery.getKey()) { | ||
indexFromSolid() | ||
} | ||
} | ||
|
||
private fun indexFromSolid() { | ||
directories.forEachIndexed { index, directory -> | ||
if (directory.file == solidDirectoryQuery.getValueAsFile()) { | ||
dropDown.selected = index | ||
} | ||
} | ||
} | ||
|
||
private fun limitWidth(text: String, limit: Int): String { | ||
if (text.length > limit) { | ||
return text.substring(0, limit-2) + "…"; | ||
} | ||
return text | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
aat-gtk/src/main/kotlin/ch/bailu/aat_gtk/view/solid/SolidDirectoryQueryComboView.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters