From 71ec806b514de4f436135730323c329c6ac8f8cf Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 21 Nov 2017 13:42:13 +0100 Subject: [PATCH] add delete button --- src/lib/cfa/chrony_conf.rb | 11 +++++++++++ src/lib/y2ntp_client/dialog/main.rb | 4 ++++ src/lib/y2ntp_client/widgets.rb | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/lib/cfa/chrony_conf.rb b/src/lib/cfa/chrony_conf.rb index 1cd4e2db..7f1c3c42 100644 --- a/src/lib/cfa/chrony_conf.rb +++ b/src/lib/cfa/chrony_conf.rb @@ -64,6 +64,17 @@ def modify_pool(original_address, new_address, options) data.add(key, value, placer) end + def delete_pool(address) + key = "pool[]" + matcher = Matcher.new do |k, v| + k == key && + v == address || + ( v.respond_to?(:value) && v.value = address ) + end + + data.delete(matcher) + end + def default_pool_options { "iburst" => nil } end diff --git a/src/lib/y2ntp_client/dialog/main.rb b/src/lib/y2ntp_client/dialog/main.rb index 2e4ca1f0..fb04345e 100644 --- a/src/lib/y2ntp_client/dialog/main.rb +++ b/src/lib/y2ntp_client/dialog/main.rb @@ -36,8 +36,12 @@ def contents table, HSpacing(0.2), VBox( + VSpacing(), Y2NtpClient::AddPoolButton.new, + VSpacing(), Y2NtpClient::EditPoolButton.new(table), + VSpacing(), + Y2NtpClient::DeletePoolButton.new(table), VStretch() ) ) diff --git a/src/lib/y2ntp_client/widgets.rb b/src/lib/y2ntp_client/widgets.rb index 47ad6f12..b5a09331 100644 --- a/src/lib/y2ntp_client/widgets.rb +++ b/src/lib/y2ntp_client/widgets.rb @@ -262,4 +262,26 @@ def handle @table.handle end end + + class DeletePoolButton < CWM::PushButton + def initialize(table) + textdomain "ntp-client" + + @table = table + end + + def label + _("&Delete") + end + + def handle + address = @table.value + if address + Yast::Popup.Error(_("No table item is selected")) + return nil + end + + Yast::NtpClient.ntp_conf.delete_pool(address) + end + end end