Skip to content

Commit

Permalink
Filter titles and descriptions localization.
Browse files Browse the repository at this point in the history
Update issue #2514
  • Loading branch information
dbarashev committed Sep 27, 2024
1 parent 0746b76 commit 29d0875
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ganttproject/src/main/java/biz/ganttproject/app/Menu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fun (GPAction).getGlyphIcon(): Text? =
}
}

fun GPAction.getHelpText(): String? = RootLocalizer.formatTextOrNull("${this.id}.help")
fun GPAction.getHelpText(): String? = this.getValue(GPAction.HELP_TEXT)?.toString() ?: RootLocalizer.formatTextOrNull("${this.id}.help")

private class CheckBoxMenuItemNode(private val action: GPAction, initiallySelected: Boolean): Button() {
private var isSelected: Boolean = initiallySelected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fun showFilterDialog(filterManager: TaskFilterManager, projectDatabase: ProjectD
val dialogPane = ItemListDialogPane<TaskFilter>(
listItems,
editItem,
{ filter -> ShowHideListItem({filter.title}, {filter.isEnabledProperty.value}, {filter.isEnabledProperty.set(!filter.isEnabledProperty.get())}) },
{ filter -> ShowHideListItem({filter.getLocalizedTitle()}, {filter.isEnabledProperty.value}, {filter.isEnabledProperty.set(!filter.isEnabledProperty.get())}) },
dialogModel,
editor,
i18n
Expand Down Expand Up @@ -108,8 +108,8 @@ internal class FilterEditor(
) {
override fun loadData(item: TaskFilter?) {
if (item != null) {
editorModel.nameField.set(item.title)
editorModel.descriptionField.set(item.description)
editorModel.nameField.set(item.getLocalizedTitle())
editorModel.descriptionField.set(item.getLocalizedDescription())
editorModel.expressionField.set(item.expression)
propertySheet.isDisable = item.isBuiltIn
dialogModel.btnDeleteController.isDisabled.set(item.isBuiltIn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ along with GanttProject. If not, see <http://www.gnu.org/licenses/>.
package biz.ganttproject.ganttview

import biz.ganttproject.app.MenuBuilder
import biz.ganttproject.core.option.DefaultBooleanOption
import biz.ganttproject.app.RootLocalizer
import net.sourceforge.ganttproject.action.GPAction
import net.sourceforge.ganttproject.storage.ProjectDatabase
import java.awt.event.ActionEvent
Expand All @@ -28,14 +28,15 @@ import java.awt.event.ActionEvent
* @author [email protected]
*/
class TaskFilterAction(
actionName: String,
private val filterManager: TaskFilterManager,
private val taskFilterOption: DefaultBooleanOption,
private val taskFilter: TaskFilter
) : GPAction(actionName) {
) : GPAction(taskFilter.title) {

init {
putValue(SELECTED_KEY, filterManager.activeFilter == taskFilter)
putValue(NAME, taskFilter.getLocalizedTitle())
putValue(HELP_TEXT, taskFilter.getLocalizedDescription())

filterManager.filterListeners.add { filter ->
if (taskFilter != filter) {
putValue(SELECTED_KEY, false)
Expand All @@ -44,9 +45,9 @@ class TaskFilterAction(

// An option can be saved and changed when a project will be open
// or undo\redo
taskFilterOption.addChangeValueListener { evt ->
(evt.newValue as? Boolean)?.let {
if (evt.newValue != evt.oldValue) {
taskFilter.isEnabledProperty.subscribe { oldValue, newValue ->
newValue?.let {
if (newValue != oldValue) {
setChecked(it)
}
}
Expand All @@ -63,7 +64,7 @@ class TaskFilterAction(
override fun putValue(key: String?, newValue: Any?) {
if (SELECTED_KEY == key) {
if (newValue is Boolean) {
taskFilterOption.value = newValue
taskFilter.isEnabledProperty.value = newValue
super.putValue(key, if (newValue) java.lang.Boolean.TRUE else java.lang.Boolean.FALSE)
}
} else {
Expand All @@ -83,31 +84,31 @@ class TaskFilterAction(
}
}

class TaskFilterActionSet(taskFilterManager: TaskFilterManager, projectDatabase: ProjectDatabase) {
class TaskFilterActionSet(private val taskFilterManager: TaskFilterManager, projectDatabase: ProjectDatabase) {
// Task filters -> actions
private val filterCompletedTasksAction = TaskFilterAction("taskTable.filter.uncompletedTasks",
taskFilterManager, BuiltInFilters.filterCompletedTasksOption, BuiltInFilters.completedTasksFilter)
private val filterDueTodayTasksAction = TaskFilterAction("taskTable.filter.dueTodayTasks",
taskFilterManager, BuiltInFilters.filterDueTodayOption, BuiltInFilters.dueTodayFilter)
private val filterOverdueTasksAction = TaskFilterAction("taskTable.filter.overdueTasks",
taskFilterManager, BuiltInFilters.filterOverdueOption, BuiltInFilters.overdueFilter)
private val filterInProgressTodayTasksAction = TaskFilterAction("taskTable.filter.inProgressTodayTasks",
taskFilterManager, BuiltInFilters.filterInProgressTodayOption, BuiltInFilters.inProgressTodayFilter)
private val filterDialogAction = GPAction.create("taskTable.filterDialog.action") {
showFilterDialog(taskFilterManager, projectDatabase)
}


fun tableFilterActions(builder: MenuBuilder) {
val recentFilters = taskFilterManager.recentFilters.map { filter ->
TaskFilterAction(taskFilterManager, filter)
}
builder.apply {
items(
filterCompletedTasksAction,
filterDueTodayTasksAction,
filterOverdueTasksAction,
filterInProgressTodayTasksAction,
filterDialogAction
)
items(recentFilters + listOf(filterDialogAction))
}
}
}

internal fun TaskFilter.getLocalizedTitle(): String =
if (this.isBuiltIn) {
val suffix = if (this.title == "filter.completedTasks") "filter.uncompletedTasks" else this.title
RootLocalizer.createWithRootKey("taskTable", RootLocalizer).formatText(suffix)
} else this.title

}
internal fun TaskFilter.getLocalizedDescription(): String =
if (this.isBuiltIn) {
val suffix = if (this.title == "filter.completedTasks") "filter.uncompletedTasks" else this.title
RootLocalizer.createWithRootKey("taskTable", RootLocalizer).formatText("$suffix.help")
} else this.description
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import net.sourceforge.ganttproject.undo.GPUndoListener
import javax.swing.event.UndoableEditEvent

/**
*
* Encapsulates the task filter properties.
*/
data class TaskFilter(
override var title: String,
Expand Down Expand Up @@ -140,7 +140,7 @@ class TaskFilterManager(val taskManager: TaskManager, val projectDatabase: Proje
}

val filters get() = BuiltInFilters.allFilters + customFilters

val recentFilters get() = filters
init {
taskManager.addTaskListener(TaskListenerAdapter().also {
it.taskProgressChangedHandler = { _ -> if (activeFilter != VOID_FILTER) sync() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ public String asString() {
private static final String ICON_FILE_DIRECTORY = "/icons";

public static final String HAS_DIALOG_BUTTON = "has_dialog_button";

// ContentDisplay value.
public static final String TEXT_DISPLAY = "text_display";
public static final String IS_SUBMENU = "is_submenu";

public static final String HAS_AUTO_REPEAT = "has_auto_repeat";

// Text that may be shown somewhere close to the task title, explaining the action.
public static final String HELP_TEXT = "help_text";
private boolean iconVisible = true;

private final String myName;
Expand Down

0 comments on commit 29d0875

Please sign in to comment.