Class: Yast::TablePopupClass
- Inherits:
-
Module
- Object
- Module
- Yast::TablePopupClass
- Defined in:
- ../../src/modules/TablePopup.rb
Instance Method Summary (collapse)
-
- (String) askForNewOption(possible, editable, descr)
Displaye popup for option to edit choosing.
-
- (Hash) CreateTableDescr(attrib, widget_descr)
Get the map with the table widget.
-
- (Boolean) deleteTableItem(opt_id, descr)
Delete an item from the table Just a wrapper for module-specific function.
-
- (Object) DisableTable(descr)
Disable whole table.
-
- (Object) EnableTable(descr)
Enable whole table (except buttons that should be grayed according to currently selected table row.
-
- (Array) getIdList(descr)
Get list of IDs of entries of the table.
-
- (String) id2key(descr, opt_id)
Get option key from the option id global only because of testsuites.
-
- (Hash) key2descr(descr, opt_key)
Get option description map from the key global only because of testsuites.
- - (Object) main
-
- (Object) moveTableItem(opt_id, descr, dir)
Move table item up or down Just a wrapper for module-specific function.
-
- (Symbol) singleOptionEditPopup(option)
Display and handle the popup for option.
-
- (Boolean) tableEntryChanged(opt_id, opt_descr)
Realize if table entry was changed.
-
- (String) tableEntryKey(opt_id, opt_descr)
Get the left column of the table.
-
- (String) tableEntryValue(opt_id, opt_descr)
Get value to the table entry.
-
- (Symbol) TableHandle(descr, key, event_descr)
Handle the event that happened on the table.
-
- (Symbol) TableHandleWrapper(key, event_descr)
Wrapper for TableHandle using CWM::GetProcessedWidget () for getting widget description map.
-
- (Object) TableInit(descr, key)
Initialize the displayed table.
-
- (Object) TableInitWrapper(key)
Wrapper for TableInit using CWM::GetProcessedWidget () for getting widget description map.
-
- (Object) TableRedraw(descr, update_buttons)
Redraw completely the table.
-
- (Object) updateButtons(descr, opt_descr)
Enable or disable the Delete and up/down buttons.
-
- (Hash) updateOptionMap(opt_descr, fallbacks)
Update the option description map in order to contain handlers of all needed functions global only because of testsuites.
-
- (Boolean) ValidateTableAttr(attr)
Validate table options specifyign attributesA.
-
- (Boolean) ValidateTableDescr(key, descr)
Validate the table description.
-
- (Boolean) ValidateValueType(key, value, widget, popup)
Validate type of entry of the option description map Also checks option description maps if present.
Instance Method Details
- (String) askForNewOption(possible, editable, descr)
Displaye popup for option to edit choosing
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
# File '../../src/modules/TablePopup.rb', line 460 def askForNewOption(possible, editable, descr) possible = deep_copy(possible) descr = deep_copy(descr) do_sort = !Ops.get_boolean(descr, "add_items_keep_order", false) possible = Builtins.sort(possible) if do_sort val2key = {} known_keys = {} possible = Builtins.maplist(possible) do |p| next if !Ops.is_string?(p) opt_descr = key2descr(descr, Convert.to_string(p)) label = Ops.get_string( opt_descr, ["table", "label"], Builtins.sformat("%1", p) ) Ops.set(known_keys, Convert.to_string(p), true) Ops.set(val2key, label, Convert.to_string(p)) Item(Id(p), label) end = HBox( HSpacing(1), VBox( VSpacing(1), ComboBox( Id(:optname), editable ? Opt(:editable) : Opt(), # combobox header _("&Selected Option"), possible ), VSpacing(1), HBox( HStretch(), PushButton(Id(:_tp_ok), Opt(:key_F10, :default), Label.OKButton), HSpacing(1), PushButton(Id(:_tp_cancel), Opt(:key_F9), Label.CancelButton), HStretch() ), VSpacing(1) ), HSpacing(1) ) UI.OpenDialog() begin UI.SetFocus(Id(:optname)) ret = nil option = nil while ret != :_tp_ok && ret != :_tp_cancel ret = UI.UserInput if ret == :_tp_ok option = Convert.to_string(UI.QueryWidget(Id(:optname), :Value)) end end ensure UI.CloseDialog end return nil if ret == :_tp_cancel return option if Ops.get(known_keys, option, false) Ops.get(val2key, option, option) end |
- (Hash) CreateTableDescr(attrib, widget_descr)
Get the map with the table widget
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 |
# File '../../src/modules/TablePopup.rb', line 860 def CreateTableDescr(attrib, ) attrib = deep_copy(attrib) = deep_copy() ValidateTableAttr(attrib) = if Ops.get_boolean(attrib, "add_delete_buttons", true) PushButton(Id(:_tp_add), Opt(:key_F3), Label.AddButton) else HSpacing(0) end = if Ops.get_boolean(attrib, "edit_button", true) PushButton(Id(:_tp_edit), Opt(:key_F4), Label.EditButton) else HSpacing(0) end = if Ops.get_boolean(attrib, "add_delete_buttons", true) PushButton(Id(:_tp_delete), Opt(:key_F5), Label.DeleteButton) else HSpacing(0) end table_header = if Ops.get_boolean(attrib, "changed_column", false) Header( # table header, shortcut for changed, keep very short _("Ch."), # table header _("Option"), # table header _("Value") ) else Header( # table header _("Option"), # table header _("Value") ) end replace_point = ReplacePoint(Id(:_tp_table_repl), HSpacing(0)) # help 1/4 help = _( "<p><b><big>Editing the Settings</big></b><br>\n" \ "To edit the settings, choose the appropriate\n" \ "entry of the table then click <b>Edit</b>.</p>" ) if Ops.get_boolean(attrib, "add_delete_buttons", true) # help 2/4, optional help = Ops.add( help, _( "<p>To add a new option, click <b>Add</b>. To remove\nan option, select it and click <b>Delete</b>.</p>" ) ) end if Ops.get_boolean(attrib, "changed_column", false) # help 3/4, optional help = Ops.add( help, _( "<P>The <B>Ch.</B> column of the table shows \nwhether the option was changed.</P>" ) ) end if Ops.get_boolean(attrib, "up_down_buttons", false) # help 4/4, optional help = Ops.add( help, _( "<p>To reorder the options, select an option\n" \ "and use <b>Up</b> and <b>Down</b> to move it up or down\n" \ "in the list.</p>" ) ) end up_down = if Ops.get_boolean(attrib, "up_down_buttons", false) VBox( VStretch(), # push button PushButton(Id(:_tp_up), _("&Up")), # push button PushButton(Id(:_tp_down), _("&Down")), VStretch() ) else HSpacing(0) end ret = Convert.convert( Builtins.union( { "custom_widget" => HBox( HSpacing(2), VBox( HBox( Table( Id(:_tp_table), Opt(:immediate, :notify, :keepSorting), table_header, [] ), up_down ), HBox( , , , HStretch(), replace_point ) ), HSpacing(2) ), "_cwm_attrib" => attrib, "widget" => :custom, "help" => help, "_cwm_do_validate" => fun_ref( method(:ValidateTableDescr), "boolean (string, map <string, any>)" ) }, ), from: "map", to: "map <string, any>" ) if !Builtins.haskey(ret, "init") Ops.set( ret, "init", fun_ref(method(:TableInitWrapper), "void (string)") ) end if !Builtins.haskey(ret, "handle") Ops.set( ret, "handle", fun_ref(method(:TableHandleWrapper), "symbol (string, map)") ) end deep_copy(ret) end |
- (Boolean) deleteTableItem(opt_id, descr)
Delete an item from the table Just a wrapper for module-specific function
341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File '../../src/modules/TablePopup.rb', line 341 def deleteTableItem(opt_id, descr) opt_id = deep_copy(opt_id) descr = deep_copy(descr) toEval = Convert.convert( Ops.get(descr, "option_delete"), from: "any", to: "boolean (any, string)" ) if nil != toEval opt_key = id2key(descr, opt_id) return toEval.call(opt_id, opt_key) end false end |
- (Object) DisableTable(descr)
Disable whole table
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
# File '../../src/modules/TablePopup.rb', line 623 def DisableTable(descr) descr = deep_copy(descr) UI.ChangeWidget(Id(:_tp_table), :Enabled, false) if Ops.get_boolean(descr, ["_cwm_attrib", "edit_button"], true) UI.ChangeWidget(Id(:_tp_edit), :Enabled, false) end if Ops.get_boolean(descr, ["_cwm_attrib", "add_delete_buttons"], true) UI.ChangeWidget(Id(:_tp_delete), :Enabled, false) UI.ChangeWidget(Id(:_tp_add), :Enabled, false) end if Ops.get_boolean(descr, ["_cwm_attrib", "up_down_buttons"], false) UI.ChangeWidget(Id(:_tp_up), :Enabled, false) UI.ChangeWidget(Id(:_tp_down), :Enabled, false) end nil end |
- (Object) EnableTable(descr)
Enable whole table (except buttons that should be grayed according to currently selected table row
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
# File '../../src/modules/TablePopup.rb', line 644 def EnableTable(descr) descr = deep_copy(descr) UI.ChangeWidget(Id(:_tp_table), :Enabled, true) if Ops.get_boolean(descr, ["_cwm_attrib", "edit_button"], true) UI.ChangeWidget(Id(:_tp_edit), :Enabled, true) end if Ops.get_boolean(descr, ["_cwm_attrib", "add_delete_buttons"], true) UI.ChangeWidget(Id(:_tp_add), :Enabled, false) end opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) opt_key = id2key(descr, opt_id) option_map = key2descr(descr, opt_key) updateButtons(descr, option_map) nil end |
- (Array) getIdList(descr)
Get list of IDs of entries of the table
58 59 60 61 62 63 64 65 66 67 |
# File '../../src/modules/TablePopup.rb', line 58 def getIdList(descr) descr = deep_copy(descr) toEval = Convert.convert( Ops.get(descr, "ids"), from: "any", to: "list (map)" ) return toEval.call(descr) if !toEval.nil? [] end |
- (String) id2key(descr, opt_id)
Get option key from the option id global only because of testsuites
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File '../../src/modules/TablePopup.rb', line 185 def id2key(descr, opt_id) descr = deep_copy(descr) opt_id = deep_copy(opt_id) if !opt_id.nil? && Ops.is_string?(opt_id) && Ops.greater_or_equal(Builtins.size(Convert.to_string(opt_id)), 7) && Builtins.substring(Convert.to_string(opt_id), 0, 7) == "____sep" return "____sep" end toEval = Convert.convert( Ops.get(descr, "id2key"), from: "any", to: "string (map, any)" ) if !toEval.nil? return toEval.call(descr, opt_id) else return Convert.to_string(opt_id) end end |
- (Hash) key2descr(descr, opt_key)
Get option description map from the key global only because of testsuites
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File '../../src/modules/TablePopup.rb', line 210 def key2descr(descr, opt_key) descr = deep_copy(descr) = Ops.get_map(descr, "options", {}) opt_descr = Ops.get_map(, opt_key, {}) # a copy wanted here opt_descr = Builtins.add(opt_descr, "_cwm_key", opt_key) # a deep copy Ops.set( opt_descr, "table", Builtins.add(Ops.get_map(opt_descr, "table", {}), "_cwm_key", opt_key) ) Ops.set( opt_descr, "popup", Builtins.add(Ops.get_map(opt_descr, "popup", {}), "_cwm_key", opt_key) ) if Ops.get(opt_descr, ["popup", "label"]).nil? Ops.set( opt_descr, ["popup", "label"], Ops.get_string(opt_descr, ["table", "label"], opt_key) ) end deep_copy(opt_descr) end |
- (Object) main
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File '../../src/modules/TablePopup.rb', line 35 def main Yast.import "UI" textdomain "base" Yast.import "CWM" Yast.import "Label" Yast.import "Mode" Yast.import "Report" # variables # Item, that is the last selected # Used to decide if selected item should be moved up or down if separator # clicked # Loss of contents is no problem @previous_selected_item = nil end |
- (Object) moveTableItem(opt_id, descr, dir)
Move table item up or down Just a wrapper for module-specific function
398 399 400 401 402 403 404 405 406 407 408 |
# File '../../src/modules/TablePopup.rb', line 398 def moveTableItem(opt_id, descr, dir) opt_id = deep_copy(opt_id) descr = deep_copy(descr) toEval = Convert.convert( Ops.get(descr, "option_move"), from: "any", to: "any (any, string, symbol)" ) return toEval.call(opt_id, id2key(descr, opt_id), dir) if nil != toEval nil end |
- (Symbol) singleOptionEditPopup(option)
Display and handle the popup for option
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File '../../src/modules/TablePopup.rb', line 525 def singleOptionEditPopup(option) option = deep_copy(option) opt_key = Ops.get_string(option, "_cwm_key", "") opt_id = Ops.get(option, "_cwm_id") label = Builtins.sformat( "%1", Ops.get_string(option, ["table", "label"], opt_key) ) header = HBox( # heading / label Heading(_("Current Option: ")), Label(label), HStretch() ) popup_descr = CWM.prepareWidget(Ops.get_map(option, "popup", {})) = Ops.get_term(popup_descr, "widget", VBox()) help = Ops.get_string(popup_descr, "help", "") help = "" if help.nil? contents = HBox( HSpacing(1), VBox( VSpacing(1), Left(header), VSpacing(1), help == "" ? VSpacing(0) : Left(Label(help)), VSpacing(help == "" ? 0 : 1), Left(ReplacePoint(Id(:value_rp), )), VSpacing(1), HBox( HStretch(), PushButton(Id(:_tp_ok), Opt(:key_F10, :default), Label.OKButton), HSpacing(1), PushButton(Id(:_tp_cancel), Opt(:key_F9), Label.CancelButton), HStretch() ), VSpacing(1) ), HSpacing(1) ) UI.OpenDialog(contents) begin if Ops.get(popup_descr, "init") toEval = Convert.convert( Ops.get(popup_descr, "init"), from: "any", to: "void (any, string)" ) toEval.call(opt_id, opt_key) end ret = nil while ret != :_tp_ok && ret != :_tp_cancel event_descr2 = UI.WaitForEvent event_descr2 = { "ID" => :_tp_ok } if Mode.test ret = Ops.get(event_descr2, "ID") if Ops.get(popup_descr, "handle") toEval = Convert.convert( Ops.get(popup_descr, "handle"), from: "any", to: "void (any, string, map)" ) toEval.call(opt_id, opt_key, event_descr2) end next if ret != :_tp_ok val_type = Ops.get_symbol(popup_descr, "validate_type") if val_type == :function toEval = Convert.convert( Ops.get(popup_descr, "validate_function"), from: "any", to: "boolean (any, string, map)" ) if !toEval.nil? ret = nil if !toEval.call(opt_id, opt_key, event_descr2) end elsif !CWM.validateWidget(popup_descr, event_descr2, opt_key) ret = nil end end if ret == :_tp_ok && Ops.get(popup_descr, "store") toEval = Convert.convert( Ops.get(popup_descr, "store"), from: "any", to: "void (any, string)" ) toEval.call(opt_id, opt_key) end ensure UI.CloseDialog end Convert.to_symbol(ret) end |
- (Boolean) tableEntryChanged(opt_id, opt_descr)
Realize if table entry was changed
323 324 325 326 327 328 329 330 331 332 333 334 |
# File '../../src/modules/TablePopup.rb', line 323 def tableEntryChanged(opt_id, opt_descr) opt_id = deep_copy(opt_id) opt_descr = deep_copy(opt_descr) opt_key = Ops.get_string(opt_descr, "_cwm_key", "") toEval = Convert.convert( Ops.get(opt_descr, ["table", "changed"]), from: "any", to: "boolean (any, string)" ) return toEval.call(opt_id, opt_key) if !toEval.nil? false end |
- (String) tableEntryKey(opt_id, opt_descr)
Get the left column of the table
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File '../../src/modules/TablePopup.rb', line 282 def tableEntryKey(opt_id, opt_descr) opt_id = deep_copy(opt_id) opt_descr = deep_copy(opt_descr) opt_key = Ops.get_string(opt_descr, "_cwm_key", "") label = Ops.get_string( opt_descr, ["table", "label"], Builtins.sformat("%1", opt_key) ) if Builtins.haskey(Ops.get_map(opt_descr, "table", {}), "label_func") label_func = Convert.convert( Ops.get(opt_descr, ["table", "label_func"]), from: "any", to: "string (any, string)" ) label = label_func.call(opt_id, opt_key) end label end |
- (String) tableEntryValue(opt_id, opt_descr)
Get value to the table entry
306 307 308 309 310 311 312 313 314 315 316 317 |
# File '../../src/modules/TablePopup.rb', line 306 def tableEntryValue(opt_id, opt_descr) opt_id = deep_copy(opt_id) opt_descr = deep_copy(opt_descr) opt_key = Ops.get_string(opt_descr, "_cwm_key", "") toEval = Convert.convert( Ops.get(opt_descr, ["table", "summary"]), from: "any", to: "string (any, string)" ) return toEval.call(opt_id, opt_key) if !toEval.nil? "" end |
- (Symbol) TableHandle(descr, key, event_descr)
Handle the event that happened on the table
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
# File '../../src/modules/TablePopup.rb', line 679 def TableHandle(descr, key, event_descr) descr = deep_copy(descr) event_descr = deep_copy(event_descr) event_id = Ops.get(event_descr, "ID") UI.SetFocus(Id(:_tp_table)) if event_id == :_tp_table if Ops.get_string(event_descr, "EventReason", "") == "Activated" && Ops.get_string(event_descr, "EventType", "") == "WidgetEvent" && UI.WidgetExists(Id(:_tp_edit)) event_id = :_tp_edit end end if event_id == :_tp_edit || event_id == :_tp_add opt_key = nil opt_id = nil if event_id == :_tp_add add_unlisted = Ops.get_boolean(descr, "add_unlisted", true) if !add_unlisted && Builtins.size(Ops.get_list(descr, "add_items", [])) == 1 opt_key = Ops.get_string(descr, ["add_items", 0], "") else add_opts = Ops.get_list(descr, "add_items", []) ids = getIdList(descr) present = Builtins.maplist(ids) { |i| id2key(descr, i) } if !Ops.get_boolean(descr, ["_cwm_attrib", "unique_keys"], false) present = Builtins.filter(present) do |i| opt_descr = key2descr(descr, i) !Ops.get_boolean(opt_descr, ["table", "optional"], true) end end add_opts = Builtins.filter(add_opts) do |o| !Builtins.contains(present, o) end selected = false until selected opt_key = askForNewOption(add_opts, add_unlisted, descr) return nil if opt_key.nil? if Builtins.contains(present, opt_key) Report.Error( # error report _("The selected option is already present.") ) else selected = true end end end return nil if opt_key.nil? elsif event_id == :_tp_edit opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) opt_key = id2key(descr, opt_id) end option_map = key2descr(descr, opt_key) toEval = Ops.get(option_map, ["table", "handle"]) if !toEval.nil? # if (is (toEval, symbol)) if !Ops.is(toEval, "symbol (any, string, map)") ret2 = Convert.to_symbol(toEval) return ret2 else toEval_c = Convert.convert( Ops.get(option_map, ["table", "handle"]), from: "any", to: "symbol (any, string, map)" ) ret2 = toEval_c.call(opt_id, opt_key, event_descr) return ret2 if ret2 != :_tp_normal end end Ops.set(option_map, "_cwm_id", opt_id) Ops.set(option_map, "_cwm_key", opt_key) # add generic handlers if needed option_map = updateOptionMap( option_map, Ops.get_map(descr, "fallback", {}) ) ret = singleOptionEditPopup(option_map) if ret == :_tp_ok if event_id == :_tp_add TableInit(descr, key) elsif event_id == :_tp_edit column = descr.fetch("_cwm_attrib", {}).fetch("changed_column", false) ? 2 : 1 UI.ChangeWidget( Id(:_tp_table), term(:Item, opt_id, column), tableEntryValue(opt_id, option_map) ) # also redraw the key field as it can be changed column = Ops.subtract(column, 1) UI.ChangeWidget( Id(:_tp_table), term(:Item, opt_id, column), tableEntryKey(opt_id, option_map) ) if Ops.get_boolean(descr, ["_cwm_attrib", "changed_column"], false) UI.ChangeWidget( Id(:_tp_table), term(:Item, opt_id, 0), tableEntryChanged(opt_id, option_map) ? "*" : "" ) end end end elsif event_id == :_tp_delete opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) TableInit(descr, key) if deleteTableItem(opt_id, descr) elsif event_id == :_tp_table opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) key2 = id2key(descr, opt_id) if key2 == "____sep" id_list = getIdList(descr) previous_index = 0 if !@previous_selected_item.nil? previous_index = -1 Builtins.find(id_list) do |e| previous_index = Ops.add(previous_index, 1) e == @previous_selected_item end end current_index = -1 Builtins.find(id_list) do |e| current_index = Ops.add(current_index, 1) e == opt_id end step = 0 if current_index == 0 step = 1 elsif Ops.add(current_index, 1) == Builtins.size(id_list) step = -1 elsif Ops.greater_or_equal(current_index, previous_index) step = 1 else step = -1 end new_index = Ops.add(current_index, step) opt_id = Ops.get(id_list, new_index) UI.ChangeWidget(Id(:_tp_table), :CurrentItem, opt_id) end @previous_selected_item = deep_copy(opt_id) opt_descr = key2descr(descr, id2key(descr, opt_id)) updateButtons(descr, opt_descr) elsif event_id == :_tp_up || event_id == :_tp_down opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) opt_id = moveTableItem(opt_id, descr, event_id == :_tp_up ? :up : :down) if nil != opt_id TableRedraw(descr, false) UI.ChangeWidget(Id(:_tp_table), :CurrentItem, opt_id) opt_descr = key2descr(descr, id2key(descr, opt_id)) updateButtons(descr, opt_descr) end end nil end |
- (Symbol) TableHandleWrapper(key, event_descr)
Wrapper for TableHandle using CWM::GetProcessedWidget () for getting widget description map
850 851 852 853 |
# File '../../src/modules/TablePopup.rb', line 850 def TableHandleWrapper(key, event_descr) event_descr = deep_copy(event_descr) TableHandle(CWM.GetProcessedWidget, key, event_descr) end |
- (Object) TableInit(descr, key)
Initialize the displayed table
665 666 667 668 669 670 671 672 |
# File '../../src/modules/TablePopup.rb', line 665 def TableInit(descr, key) descr = deep_copy(descr) @previous_selected_item = nil Ops.set(descr, "_cwm_key", key) TableRedraw(descr, true) nil end |
- (Object) TableInitWrapper(key)
Wrapper for TableInit using CWM::GetProcessedWidget () for getting widget description map
839 840 841 842 843 |
# File '../../src/modules/TablePopup.rb', line 839 def TableInitWrapper(key) TableInit(CWM.GetProcessedWidget, key) nil end |
- (Object) TableRedraw(descr, update_buttons)
Redraw completely the table
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File '../../src/modules/TablePopup.rb', line 414 def TableRedraw(descr, ) descr = deep_copy(descr) id_list = getIdList(descr) if @previous_selected_item.nil? @previous_selected_item = Ops.get(id_list, 0) end entries = Builtins.maplist(id_list) do |opt_id| opt_val = "" opt_changed = false opt_key = id2key(descr, opt_id) opt_descr = key2descr(descr, opt_key) opt_descr = updateOptionMap( opt_descr, Ops.get_map(descr, "fallback", {}) ) label = tableEntryKey(opt_id, opt_descr) if opt_key != "____sep" opt_val = tableEntryValue(opt_id, opt_descr) opt_changed = tableEntryChanged(opt_id, opt_descr) end if && opt_id == @previous_selected_item updateButtons(descr, opt_descr) end if Ops.get_boolean(descr, ["_cwm_attrib", "changed_column"], false) next Item( Id(opt_id), opt_changed ? "*" : "", label, Builtins.sformat("%1", opt_val) ) end Item(Id(opt_id), label, Builtins.sformat("%1", opt_val)) end UI.ChangeWidget(Id(:_tp_table), :Items, entries) UI.SetFocus(Id(:_tp_table)) nil end |
- (Object) updateButtons(descr, opt_descr)
Enable or disable the Delete and up/down buttons
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File '../../src/modules/TablePopup.rb', line 359 def updateButtons(descr, opt_descr) descr = deep_copy(descr) opt_descr = deep_copy(opt_descr) if Ops.get_boolean(descr, ["_cwm_attrib", "add_delete_buttons"], true) UI.ChangeWidget( Id(:_tp_delete), :Enabled, Ops.get_boolean(opt_descr, ["table", "optional"], true) ) end if Ops.get_boolean(descr, ["_cwm_attrib", "edit_button"], true) UI.ChangeWidget( Id(:_tp_edit), :Enabled, !Ops.get_boolean(opt_descr, ["table", "immutable"], false) ) end if Ops.get_boolean(descr, ["_cwm_attrib", "up_down_buttons"], false) UI.ChangeWidget( Id(:_tp_up), :Enabled, Ops.get_boolean(opt_descr, ["table", "ordering"], true) ) UI.ChangeWidget( Id(:_tp_down), :Enabled, Ops.get_boolean(opt_descr, ["table", "ordering"], true) ) end nil end |
- (Hash) updateOptionMap(opt_descr, fallbacks)
Update the option description map in order to contain handlers of all needed functions global only because of testsuites
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File '../../src/modules/TablePopup.rb', line 243 def updateOptionMap(opt_descr, fallbacks) opt_descr = deep_copy(opt_descr) fallbacks = deep_copy(fallbacks) # ensure that the submaps exist Ops.set(opt_descr, "table", Ops.get_map(opt_descr, "table", {})) Ops.set(opt_descr, "popup", Ops.get_map(opt_descr, "popup", {})) Builtins.foreach(["init", "store"]) do |k| if !Builtins.haskey(Ops.get_map(opt_descr, "popup", {}), k) && Builtins.haskey(fallbacks, k) Ops.set(opt_descr, ["popup", k], Ops.get(fallbacks, k)) end end if !Builtins.haskey(Ops.get_map(opt_descr, "table", {}), "summary") && Builtins.haskey(fallbacks, "summary") Ops.set(opt_descr, ["table", "summary"], Ops.get(fallbacks, "summary")) end if !Builtins.haskey(Ops.get_map(opt_descr, "table", {}), "label_func") && Builtins.haskey(fallbacks, "label_func") Ops.set( opt_descr, ["table", "label_func"], Ops.get(fallbacks, "label_func") ) end if !Builtins.haskey(Ops.get_map(opt_descr, "table", {}), "changed") && Builtins.haskey(fallbacks, "changed") Ops.set(opt_descr, ["table", "changed"], Ops.get(fallbacks, "changed")) end if Ops.get_string(opt_descr, "_cwm_key", "") == "____sep" && Ops.get_string(opt_descr, ["table", "label"], "") == "" Ops.set(opt_descr, ["table", "label"], "--------------------") end deep_copy(opt_descr) end |
- (Boolean) ValidateTableAttr(attr)
Validate table options specifyign attributesA
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File '../../src/modules/TablePopup.rb', line 72 def ValidateTableAttr(attr) attr = deep_copy(attr) types = { "add_delete_buttons" => "boolean", "edit_button" => "boolean", "changed_column" => "boolean", "up_down_buttons" => "boolean", "unique_keys" => "boolean" } ret = true Builtins.foreach(attr) do |k, v| type = Ops.get(types, k) if type.nil? Builtins.y2error("Unknown attribute %1", k) ret = false else ret = CWM.ValidateBasicType(v, type) && ret end end ret end |
- (Boolean) ValidateTableDescr(key, descr)
Validate the table description
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File '../../src/modules/TablePopup.rb', line 155 def ValidateTableDescr(key, descr) descr = deep_copy(descr) ret = true Builtins.foreach(descr) do |k, v| ret = ValidateValueType(k, v, key, false) && ret end = Ops.get_map(descr, "options", {}) Builtins.foreach() do |w_key, v| des = Convert.convert( v, from: "any", to: "map <string, map <string, any>>" ) Builtins.foreach(des) do |group, d| if group != "table" && group != "popup" Builtins.y2error("Unknown entry in option %1: %2", w_key, group) end Builtins.foreach(d) do |key2, value| ValidateValueType(key2, value, w_key, true) end end end ret end |
- (Boolean) ValidateValueType(key, value, widget, popup)
Validate type of entry of the option description map Also checks option description maps if present
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File '../../src/modules/TablePopup.rb', line 101 def ValidateValueType(key, value, , popup) value = deep_copy(value) success = true if popup if key == "init" success = Ops.is(value, "void (any, string)") elsif key == "handle" success = Ops.is(value, "void (any, string, map)") || Ops.is_symbol?(value) elsif key == "store" success = Ops.is(value, "void (any, string)") elsif key == "cleanup" success = Ops.is(value, "void (any, string)") elsif key == "validate_function" success = Ops.is(value, "boolean (any, string, map)") elsif key == "optional" success = Ops.is_boolean?(value) elsif key == "label_func" success = Ops.is(value, "string (any, string)") else return CWM.ValidateValueType(key, value, ) end elsif key == "id2key" success = Ops.is(value, "string (map, any)") elsif key == "ids" success = Ops.is(value, "list (map)") elsif key == "option_delete" success = Ops.is(value, "boolean (any, string)") elsif key == "summary" success = Ops.is(value, "string (any, string)") elsif key == "label_func" success = Ops.is(value, "string (any, string)") elsif key == "option_move" success = Ops.is(value, "any (any, string, symbol)") elsif key == "options" success = Ops.is(value, "map <string, any>") elsif key == "add_items" success = Ops.is_list?(value) end if !success Builtins.y2error( "Wrong type of option %1 in description map of %2", key, ) end nil end |