Skip to content

Commit

Permalink
Merge pull request #817 from joseivanlopez/backport_changes
Browse files Browse the repository at this point in the history
Backport changes
  • Loading branch information
joseivanlopez committed Sep 7, 2018
2 parents 6c101da + d9d174c commit f9f98b3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
2 changes: 2 additions & 0 deletions library/cwm/examples/object_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ def run
)

Yast::Wizard.CreateDialog
next_handler = proc { Yast::Popup.YesNo("Really go next?") }
back_handler = proc { Yast::Popup.YesNo("Really go back?") }
abort_handler = proc { Yast::Popup.YesNo("Really abort?") }
CWM.show(contents,
caption: _("Lucky number"),
next_handler: next_handler,
back_handler: back_handler,
abort_handler: abort_handler)
Yast::Wizard.CloseDialog
Expand Down
10 changes: 10 additions & 0 deletions library/cwm/src/lib/cwm/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def disable_buttons
[]
end

# Handler when the next button is used
#
# If returns false, then it does not go next.
#
# @return [Boolean]
def next_handler
true
end

# Handler when the back button is used
#
# If returns false, then it does not go back.
Expand Down Expand Up @@ -116,6 +125,7 @@ def cwm_show
next_button: next_button,
skip_store_for: skip_store_for,
disable_buttons: disable_buttons,
next_handler: proc { next_handler },
back_handler: proc { back_handler },
abort_handler: proc { abort_handler }
)
Expand Down
56 changes: 23 additions & 33 deletions library/cwm/src/modules/CWM.rb
Original file line number Diff line number Diff line change
Expand Up @@ -834,31 +834,16 @@ def Run(widgets, functions, skip_store_for: [])
end
end

ret = :next if ret == :ok
ret = :abort if ret == :cancel
if ret == :abort
if Ops.get(functions, :abort)
toEval = Convert.convert(
Ops.get(functions, :abort),
from: "any",
to: "boolean ()"
)
if !toEval.nil?
eval_ret = toEval.call
ret = eval_ret ? :abort : nil
end
end
elsif ret == :back
if Ops.get(functions, :back)
toEval = Convert.convert(
Ops.get(functions, :back),
from: "any",
to: "boolean ()"
)
if !toEval.nil?
eval_ret = toEval.call
ret = eval_ret ? :back : nil
end
end

if ret == :next && functions[:next]
ret = nil unless functions[:next].call
save = false if ret.nil?
elsif ret == :back && functions[:back]
ret = nil unless functions[:back].call
elsif ret == :abort && functions[:abort]
ret = nil unless functions[:abort].call
end

next if ret.nil?
Expand Down Expand Up @@ -930,27 +915,31 @@ def SetValidationFailedHandler(handler)
end

# Display the dialog and run its event loop using new widget API
# @param [::CWM::WidgetTerm] contents is UI term including instances of {CWM::AbstractWidget}
# @param [String] caption of dialog
# @param [String, nil] back_button label for dialog back button,
# @param contents [::CWM::WidgetTerm] UI term including instances of {CWM::AbstractWidget}
# @param caption [String] caption of dialog
# @param back_button [String, nil] label for dialog back button,
# `nil` to use the default label, `""` to omit the button
# @param [String, nil] next_button label for dialog next button,
# @param next_button [String, nil] label for dialog next button,
# `nil` to use the default label, `""` to omit the button
# @param [String, nil] abort_button label for dialog abort button,
# @param abort_button [String, nil] label for dialog abort button,
# `nil` to use the default label, `""` to omit the button
# @param [Array] skip_store_for list of events for which the value of the widget will not be stored.
# @param skip_store_for [Array] list of events for which the value of the widget will not be stored.
# Useful mainly when some widget returns an event that should not trigger the storing,
# like a reset button or a redrawing. It will skip also validation, because it is not needed
# as nothing is stored.
# @param [Proc] back_handler handler that is called after clicking on back. If it returns false,
# @param next_handler [Proc] handler that is called after clicking on next. If it returns false,
# then it does not go next. If it returns true, then :next symbol is returned. If handler is not
# defined, then it acts like if it returns true.
# @param back_handler [Proc] handler that is called after clicking on back. If it returns false,
# then it does not go back. If it returns true, then :back symbol is returned. If handler is not
# defined, then it acts like if it returns true.
# @param [Proc] abort_handler handler that is called after clicking on abort. If it returns false,
# @param abort_handler [Proc] handler that is called after clicking on abort. If it returns false,
# then it stops abort. If it returns true, then :abort symbol is returned. If handler is not
# defined, then it acts like if it returns true.
#
# @return [Symbol] wizard sequencer symbol
def show(contents, caption: nil, back_button: nil, next_button: nil, abort_button: nil, skip_store_for: [],
disable_buttons: [], back_handler: nil, abort_handler: nil)
disable_buttons: [], next_handler: nil, back_handler: nil, abort_handler: nil)
widgets = widgets_in_contents(contents)
options = {
"contents" => widgets_contents(contents),
Expand All @@ -964,6 +953,7 @@ def show(contents, caption: nil, back_button: nil, next_button: nil, abort_butto
options["skip_store_for"] = skip_store_for
options["disable_buttons"] = disable_buttons
options["fallback_functions"] = {}
options["fallback_functions"][:next] = Yast.fun_ref(next_handler, "boolean ()") if next_handler
options["fallback_functions"][:back] = Yast.fun_ref(back_handler, "boolean ()") if back_handler
options["fallback_functions"][:abort] = Yast.fun_ref(abort_handler, "boolean ()") if abort_handler

Expand Down
10 changes: 10 additions & 0 deletions library/cwm/test/dialog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def contents
expect(subject.class.run).to eq(:launch)
end

it "passes the next handler to CWM#show" do
expect(Yast::CWM).to receive(:show) do |_content, options|
expect(options).to include(:next_handler)
# Checking the default handler is passed (simply returns true)
expect(options[:next_handler].call).to eq(true)
end

subject.class.run
end

it "passes the back handler to CWM#show" do
expect(Yast::CWM).to receive(:show) do |_content, options|
expect(options).to include(:back_handler)
Expand Down
8 changes: 8 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Wed Sep 5 10:19:27 UTC 2018 - jlopez@suse.com

- CWM: allow to define next handler for CWM#show.
- CWM: define default next handler in CWM::Dialog.
- Needed for Expert Partitioner (fate#318196).
- 4.0.87

-------------------------------------------------------------------
Thu Aug 30 11:21:14 UTC 2018 - dgonzalez@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 4.0.86
Version: 4.0.87
Release: 0
Summary: YaST2 - Main Package
License: GPL-2.0-only
Expand Down

0 comments on commit f9f98b3

Please sign in to comment.