@ -55,7 +55,7 @@ end
ItemSelection = defclass ( ItemSelection , widgets.Window )
ItemSelection = defclass ( ItemSelection , widgets.Window )
ItemSelection.ATTRS {
ItemSelection.ATTRS {
frame_title = ' Choose items ' ,
frame_title = ' Choose items ' ,
frame = { w = 56 , h = 2 0, l = 4 , t = 8 } ,
frame = { w = 56 , h = 2 4, l = 4 , t = 7 } ,
resizable = true ,
resizable = true ,
index = DEFAULT_NIL ,
index = DEFAULT_NIL ,
desc = DEFAULT_NIL ,
desc = DEFAULT_NIL ,
@ -81,107 +81,144 @@ function ItemSelection:init()
end
end
self : addviews {
self : addviews {
widgets.Label {
widgets.Panel {
frame = { t = 0 , l = 0 , r = 16 } ,
view_id = ' header ' ,
text = {
frame = { t = 0 , h = 3 } ,
self.desc , plural , NEWLINE ,
subviews = {
( ' Select up to %d item%s ( ' ) : format ( self.quantity , plural ) ,
widgets.Label {
{ text = function ( ) return self.num_selected end } ,
frame = { t = 0 , l = 0 , r = 16 } ,
' selected) ' ,
text = {
} ,
self.desc , plural , NEWLINE ,
} ,
( ' Select up to %d item%s ( ' ) : format ( self.quantity , plural ) ,
widgets.Label {
{ text = function ( ) return self.num_selected end } ,
frame = { r = 0 , w = 15 , t = 0 , h = 3 } ,
' selected) ' ,
text_pen = BUILD_TEXT_PEN ,
} ,
text_hpen = BUILD_TEXT_HPEN ,
} ,
text = {
widgets.Label {
' Use filter ' , NEWLINE ,
frame = { r = 0 , w = 15 , t = 0 , h = 3 } ,
' for remaining ' , NEWLINE ,
text_pen = BUILD_TEXT_PEN ,
' items ' ,
text_hpen = BUILD_TEXT_HPEN ,
text = {
' Use filter ' , NEWLINE ,
' for remaining ' , NEWLINE ,
' items ' ,
} ,
on_click = self : callback ( ' submit ' ) ,
visible = function ( ) return self.num_selected < self.quantity end ,
} ,
widgets.Label {
frame = { r = 0 , w = 15 , t = 0 , h = 3 } ,
text_pen = BUILD_TEXT_PEN ,
text_hpen = BUILD_TEXT_HPEN ,
text = {
' ' , NEWLINE ,
' Continue ' , NEWLINE ,
' ' ,
} ,
on_click = self : callback ( ' submit ' ) ,
visible = function ( ) return self.num_selected >= self.quantity end ,
} ,
} ,
} ,
on_click = self : callback ( ' submit ' ) ,
visible = function ( ) return self.num_selected < self.quantity end ,
} ,
} ,
widgets.Label {
}
frame = { r = 0 , w = 15 , t = 0 , h = 3 } ,
text_pen = BUILD_TEXT_PEN ,
self : addviews {
text_hpen = BUILD_TEXT_HPEN ,
widgets.Panel {
text = {
view_id = ' body ' ,
' ' , NEWLINE ,
frame = { t = self.subviews . header.frame . h , b = 4 } ,
' Continue ' , NEWLINE ,
subviews = {
' ' ,
widgets.EditField {
view_id = ' search ' ,
frame = { l = 1 , t = 0 } ,
label_text = ' Search: ' ,
on_char = function ( ch ) return ch : match ( ' [%l -] ' ) end ,
} ,
widgets.CycleHotkeyLabel {
frame = { l = 1 , t = 2 } ,
key = ' CUSTOM_SHIFT_R ' ,
label = ' Sort by: ' ,
options = {
{ label = ' Recently used ' , value = sort_by_recency } ,
{ label = ' Name ' , value = sort_by_name } ,
{ label = ' Amount ' , value = sort_by_quantity } ,
} ,
on_change = self : callback ( ' on_sort ' ) ,
} ,
widgets.Panel {
frame = { l = 0 , t = 3 , r = 0 , b = 0 } ,
frame_style = gui.INTERIOR_FRAME ,
subviews = {
widgets.FilteredList {
view_id = ' flist ' ,
frame = { t = 0 , b = 0 } ,
case_sensitive = false ,
choices = choices ,
icon_width = 2 ,
on_submit = self : callback ( ' toggle_group ' ) ,
} ,
} ,
} ,
} ,
} ,
on_click = self : callback ( ' submit ' ) ,
visible = function ( ) return self.num_selected >= self.quantity end ,
} ,
} ,
widgets.FilteredList {
widgets.Panel {
view_id = ' flist ' ,
view_id = ' footer ' ,
frame = { t = 3 , l = 0 , r = 0 , b = 4 } ,
frame = { l = 1 , r = 1 , b = 0 , h = 3 } ,
case_sensitive = false ,
subviews = {
choices = choices ,
widgets.HotkeyLabel {
icon_width = 2 ,
frame = { l = 0 , h = 1 , t = 0 } ,
on_submit = self : callback ( ' toggle_group ' ) ,
key = ' KEYBOARD_CURSOR_RIGHT_FAST ' ,
edit_on_char = function ( ch ) return ch : match ( ' [%l -] ' ) end ,
key_sep = ' ----: ' , -- these hypens function as "padding" to be overwritten by the next Label
} ,
label = ' Use one ' ,
widgets.CycleHotkeyLabel {
auto_width = true ,
frame = { l = 0 , b = 2 } ,
on_activate = function ( ) self : increment_group ( self.subviews . flist.list : getSelected ( ) ) end ,
key = ' CUSTOM_SHIFT_R ' ,
} ,
label = ' Sort by: ' ,
widgets.Label {
options = {
frame = { l = 6 , w = 5 , t = 0 } ,
{ label = ' Recently used ' , value = sort_by_recency } ,
text_pen = COLOR_LIGHTGREEN ,
{ label = ' Name ' , value = sort_by_name } ,
text = ' Right ' , -- this overrides the "6----" characters from the previous HotkeyLabel
{ label = ' Amount ' , value = sort_by_quantity } ,
} ,
widgets.HotkeyLabel {
frame = { l = 1 , h = 1 , t = 1 } ,
key = ' KEYBOARD_CURSOR_LEFT_FAST ' ,
key_sep = ' ---: ' , -- these hypens function as "padding" to be overwritten by the next Label
label = ' Use one fewer ' ,
auto_width = true ,
on_activate = function ( ) self : decrement_group ( self.subviews . flist.list : getSelected ( ) ) end ,
} ,
widgets.Label {
frame = { l = 7 , w = 4 , t = 1 } ,
text_pen = COLOR_LIGHTGREEN ,
text = ' Left ' , -- this overrides the "4---" characters from the previous HotkeyLabel
} ,
widgets.HotkeyLabel {
frame = { l = 6 , t = 2 , h = 2 } ,
key = ' SELECT ' ,
label = ' Use all/none ' ,
auto_width = true ,
on_activate = function ( ) self : toggle_group ( self.subviews . flist.list : getSelected ( ) ) end ,
} ,
widgets.HotkeyLabel {
frame = { r = 5 , t = 0 } ,
key = ' LEAVESCREEN ' ,
label = ' Go back ' ,
auto_width = true ,
on_activate = self : callback ( ' on_cancel ' ) ,
} ,
widgets.HotkeyLabel {
frame = { r = 4 , t = 2 } ,
key = ' CUSTOM_SHIFT_C ' ,
label = ' Continue ' ,
auto_width = true ,
on_activate = self : callback ( ' submit ' ) ,
} ,
} ,
} ,
on_change = self : callback ( ' on_sort ' ) ,
} ,
widgets.HotkeyLabel {
frame = { l = 0 , b = 1 } ,
key = ' SELECT ' ,
label = ' Use all/none ' ,
auto_width = true ,
on_activate = function ( ) self : toggle_group ( self.subviews . flist.list : getSelected ( ) ) end ,
} ,
widgets.HotkeyLabel {
frame = { l = 22 , b = 1 } ,
key = ' CUSTOM_SHIFT_C ' ,
label = ' Continue ' ,
auto_width = true ,
on_activate = self : callback ( ' submit ' ) ,
} ,
widgets.HotkeyLabel {
frame = { l = 38 , b = 1 } ,
key = ' LEAVESCREEN ' ,
label = ' Go back ' ,
auto_width = true ,
on_activate = self : callback ( ' on_cancel ' ) ,
} ,
widgets.HotkeyLabel {
frame = { l = 0 , b = 0 } ,
key = ' KEYBOARD_CURSOR_RIGHT_FAST ' ,
key_sep = ' : ' ,
label = ' Use one ' ,
auto_width = true ,
on_activate = function ( ) self : increment_group ( self.subviews . flist.list : getSelected ( ) ) end ,
} ,
widgets.Label {
frame = { l = 6 , b = 0 , w = 5 } ,
text_pen = COLOR_LIGHTGREEN ,
text = ' Right ' ,
} ,
widgets.HotkeyLabel {
frame = { l = 23 , b = 0 } ,
key = ' KEYBOARD_CURSOR_LEFT_FAST ' ,
key_sep = ' : ' ,
label = ' Use one fewer ' ,
auto_width = true ,
on_activate = function ( ) self : decrement_group ( self.subviews . flist.list : getSelected ( ) ) end ,
} ,
widgets.Label {
frame = { l = 29 , b = 0 , w = 4 } ,
text_pen = COLOR_LIGHTGREEN ,
text = ' Left ' ,
} ,
} ,
}
}
self.subviews . flist.list . frame.t = 0
self.subviews . flist.edit . visible = false
self.subviews . flist.edit = self.subviews . search
self.subviews . search.on_change = self.subviews . flist : callback ( ' onFilterChange ' )
end
end
-- resort and restore selection
-- resort and restore selection
@ -234,7 +271,7 @@ function ItemSelection:get_choices(sort_fn)
for desc , choice in pairs ( buckets ) do
for desc , choice in pairs ( buckets ) do
local data = choice.data
local data = choice.data
choice.text = {
choice.text = {
{ width = 10 , text = function ( ) return ( ' [ %d/%d] ' ) : format ( data.selected , data.quantity ) end } ,
{ width = 10 , text = function ( ) return ( ' %d/%d' ) : format ( data.selected , data.quantity ) end } ,
{ gap = 2 , text = desc } ,
{ gap = 2 , text = desc } ,
}
}
table.insert ( choices , choice )
table.insert ( choices , choice )