Skip to content

Commit

Permalink
Only show the advanced new constraint dialog on Shift-Enter.
Browse files Browse the repository at this point in the history
Upon reflection it is a bit too scary to be always shown.
  • Loading branch information
angavrilov committed Nov 29, 2012
1 parent 94e6690 commit 5ea26d9
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 15 deletions.
6 changes: 6 additions & 0 deletions Lua API.html
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,9 @@ <h3><a class="toc-backref" href="#id50">List class</a></h3>
<tr class="field"><th class="field-name">on_submit:</th><td class="field-body">Enter key callback; if specified, the list reacts to the key
and calls it as <tt class="docutils literal">on_submit(index,choice)</tt>.</td>
</tr>
<tr class="field"><th class="field-name">on_submit2:</th><td class="field-body">Shift-Enter key callback; if specified, the list reacts to the key
and calls it as <tt class="docutils literal">on_submit2(index,choice)</tt>.</td>
</tr>
<tr class="field"><th class="field-name">row_height:</th><td class="field-body">Height of every row in text lines.</td>
</tr>
<tr class="field"><th class="field-name">icon_width:</th><td class="field-body">If not <em>nil</em>, the specified number of character columns
Expand Down Expand Up @@ -2908,6 +2911,9 @@ <h3><a class="toc-backref" href="#id50">List class</a></h3>
<li><p class="first"><tt class="docutils literal">list:submit()</tt></p>
<p>Call the <tt class="docutils literal">on_submit</tt> callback, as if the Enter key was handled.</p>
</li>
<li><p class="first"><tt class="docutils literal">list:submit2()</tt></p>
<p>Call the <tt class="docutils literal">on_submit2</tt> callback, as if the Shift-Enter key was handled.</p>
</li>
</ul>
</div>
<div class="section" id="filteredlist-class">
Expand Down
6 changes: 6 additions & 0 deletions Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2777,6 +2777,8 @@ It has the following attributes:
:on_select: Selection change callback; called as ``on_select(index,choice)``.
:on_submit: Enter key callback; if specified, the list reacts to the key
and calls it as ``on_submit(index,choice)``.
:on_submit2: Shift-Enter key callback; if specified, the list reacts to the key
and calls it as ``on_submit2(index,choice)``.
:row_height: Height of every row in text lines.
:icon_width: If not *nil*, the specified number of character columns
are reserved to the left of the list item for the icons.
Expand Down Expand Up @@ -2826,6 +2828,10 @@ The list supports the following methods:

Call the ``on_submit`` callback, as if the Enter key was handled.

* ``list:submit2()``

Call the ``on_submit2`` callback, as if the Shift-Enter key was handled.

FilteredList class
------------------

Expand Down
4 changes: 2 additions & 2 deletions Readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -3045,11 +3045,11 @@ <h2><a class="toc-backref" href="#id145">gui/workflow</a></h2>
as described in <tt class="docutils literal">workflow</tt> documentation above. In this manner, this feature
can be used for troubleshooting jobs that don't match the right constraints.</p>
<img alt="images/workflow-new1.png" src="images/workflow-new1.png" />
<p>After selecting one of the presented outputs, the interface proceeds to the
<p>If you select one of the outputs with Enter, the matching constraint is simply
added to the list. If you use Shift-Enter, the interface proceeds to the
next dialog, which allows you to edit the suggested constraint parameters to
suit your need, and set the item count range.</p>
<img alt="images/workflow-new2.png" src="images/workflow-new2.png" />
<p>If you don't need advanced settings, you can just press 'y' to confirm creation.</p>
</div>
<div class="section" id="gui-assign-rack">
<h2><a class="toc-backref" href="#id146">gui/assign-rack</a></h2>
Expand Down
6 changes: 2 additions & 4 deletions Readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2309,15 +2309,13 @@ can be used for troubleshooting jobs that don't match the right constraints.

.. image:: images/workflow-new1.png

After selecting one of the presented outputs, the interface proceeds to the
If you select one of the outputs with Enter, the matching constraint is simply
added to the list. If you use Shift-Enter, the interface proceeds to the
next dialog, which allows you to edit the suggested constraint parameters to
suit your need, and set the item count range.

.. image:: images/workflow-new2.png

If you don't need advanced settings, you can just press 'y' to confirm creation.



gui/assign-rack
===============
Expand Down
Binary file modified images/workflow-new1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion library/lua/gui/dialogs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ ListBox.ATTRS{
with_filter = false,
cursor_pen = DEFAULT_NIL,
select_pen = DEFAULT_NIL,
on_select = DEFAULT_NIL
on_select = DEFAULT_NIL,
on_select2 = DEFAULT_NIL,
select2_hint = DEFAULT_NIL,
}

function ListBox:preinit(info)
Expand All @@ -168,6 +170,16 @@ function ListBox:init(info)
list_widget = widgets.FilteredList
end

local on_submit2
if self.select2_hint or self.on_select2 then
on_submit2 = function(sel, obj)
self:dismiss()
if self.on_select2 then self.on_select2(sel, obj) end
local cb = obj.on_select2
if cb then cb(obj, sel) end
end
end

self:addviews{
list_widget{
view_id = 'list',
Expand All @@ -182,11 +194,19 @@ function ListBox:init(info)
local cb = obj.on_select or obj[2]
if cb then cb(obj, sel) end
end,
on_submit2 = on_submit2,
frame = { l = 0, r = 0 },
}
}
end

function ListBox:onRenderFrame(dc,rect)
ListBox.super.onRenderFrame(self,dc,rect)
if self.select2_hint then
dc:seek(rect.x1+2,rect.y2):key('SEC_SELECT'):string(': '..self.select2_hint,COLOR_DARKGREY)
end
end

function ListBox:getWantedFrameSize()
local mw, mh = InputBox.super.getWantedFrameSize(self)
local list = self.subviews.list
Expand Down
19 changes: 19 additions & 0 deletions library/lua/gui/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ List.ATTRS{
inactive_pen = DEFAULT_NIL,
on_select = DEFAULT_NIL,
on_submit = DEFAULT_NIL,
on_submit2 = DEFAULT_NIL,
row_height = 1,
scroll_keys = STANDARDSCROLL,
icon_width = DEFAULT_NIL,
Expand Down Expand Up @@ -542,10 +543,19 @@ function List:submit()
end
end

function List:submit2()
if self.on_submit2 and #self.choices > 0 then
self.on_submit2(self:getSelected())
end
end

function List:onInput(keys)
if self.on_submit and keys.SELECT then
self:submit()
return true
elseif self.on_submit2 and keys.SEC_SELECT then
self:submit2()
return true
else
for k,v in pairs(self.scroll_keys) do
if keys[k] then
Expand Down Expand Up @@ -608,6 +618,11 @@ function FilteredList:init(info)
return info.on_submit(self:getSelected())
end
end
if info.on_submit2 then
self.list.on_submit2 = function()
return info.on_submit2(self:getSelected())
end
end
self.not_found = Label{
visible = false,
text = info.not_found_label or 'No matches',
Expand All @@ -634,6 +649,10 @@ function FilteredList:submit()
return self.list:submit()
end

function FilteredList:submit2()
return self.list:submit2()
end

function FilteredList:canSubmit()
return not self.not_found.visible
end
Expand Down
20 changes: 12 additions & 8 deletions scripts/gui/workflow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -552,18 +552,22 @@ function JobConstraints:onNewConstraint()
table.insert(choices, { text = itemstr..' of '..matstr, obj = cons })
end

dlg.showListPrompt(
'New limit',
'Select one of the possible outputs:',
COLOR_WHITE,
choices,
function(idx,item)
dlg.ListBox{
frame_title = 'New limit',
text = 'Select one of the possible outputs:',
text_pen = COLOR_WHITE,
choices = choices,
on_select = function(idx,item)
self:saveConstraint(item.obj)
end,
select2_hint = 'Advanced',
on_select2 = function(idx,item)
NewConstraint{
constraint = item.obj,
on_submit = self:callback('saveConstraint')
}:show()
end
)
end,
}:show()
end

function JobConstraints:onDeleteConstraint()
Expand Down

0 comments on commit 5ea26d9

Please sign in to comment.