Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Items in Table Widgets #55

Merged
merged 13 commits into from
Oct 9, 2020
Merged

Nested Items in Table Widgets #55

merged 13 commits into from
Oct 9, 2020

Conversation

shundhammer
Copy link
Contributor

@shundhammer shundhammer commented Sep 10, 2020

Master PR

libyui/libyui-old#171 Edit 2021-08-10: Link updated

This is the UI interpreter part.

Problem

We need nested (tree-like) items in the Table widget.

storage-nested-1

New UI Syntax

      Table(Id(:mytable),
        Header("Device", "Size", "Type", "Mount Point"),
        [
          Item(Id(:sda), "/dev/sda", "931.5G", sda_items, :open),
          Item(Id(:sdb), "/dev/sdb", "931.5G", sdb_items, :closed),
          Item(Id(:sdc), "/dev/sdc", "232.9G", sdc_items, :open)
        ]
      )
    ...
    ...
    def sda_items
      [
        Item(Id(:sda1), "/dev/sda1",  "97.7G", "ntfs", "/win/boot" ),
        Item(Id(:sda2), "/dev/sda2", "833.9G", "ntfs", "/win/app"  )
      ]
    end

:open and :closed are special symbols to make a clear difference between an item's boolean selected status (which of course is still there) and the branch open/closed status.

Full Ruby UI Example

See examples/Table-nested-items.rb :

(Click the arrow to open)

# encoding: utf-8

# Example for table with nested items

module Yast
  class TableNestedItems < Client
    Yast.import "UI"

    def main
      UI.OpenDialog(main_dialog)
      handle_events
      UI.CloseDialog
    end

    def main_dialog
      MinSize(
        74, 17,
        MarginBox(
          1, 0.4,
          VBox(
            Left(
              Heading("Storage Overview")
            ),
            VSpacing(0.2),
            table,
            VSpacing(0.2),
            Left(Label("Selected:")),
            Label(Id(:selected), Opt(:outputField, :hstretch), ""),
            VSpacing(0.5),
            Right(
              PushButton(Id(:close), "&Close")
            )
          )
        )
      )
    end

    def table
      Table(
        Id(:table),
        Opt(:notify, :immediate),
        Header("Device", "Size", "Type", "Mount Point"),
        disk_items
      )
    end

    def disk_items
      [
        Item(Id(:sda), "/dev/sda", "931.5G", sda_items, :open),
        Item(Id(:sdb), "/dev/sdb", "931.5G", sdb_items, :closed),
        Item(Id(:sdc), "/dev/sdc", "232.9G", sdc_items, :open)
      ]
    end

    def sda_items
      [
        Item(Id(:sda1), "/dev/sda1",  "97.7G", "ntfs", "/win/boot" ),
        Item(Id(:sda2), "/dev/sda2", "833.9G", "ntfs", "/win/app"  )
      ]
    end

    def sdb_items
      [
        Item(Id(:sdb1), "/dev/sdb1",   "2.0G", "swap" ),
        Item(Id(:sdb2), "/dev/sdb2",  "29.4G", "ext4", "/hd-root-leap-42"   ),
        Item(Id(:sdb3), "/dev/sdb3",  "29.4G", "ext4", "/hd-root-leap-15-0" ),
        Item(Id(:sdb4), "/dev/sdb4", "855.8G", "xfs",  "/work" )
      ]
    end

    def sdc_items
      [
        Item(Id(:sdc1), "/dev/sdc1",   "2.0G", "swap", "[swap]" ),
        Item(Id(:sdc2), "/dev/sdc2",  "29.4G", "ext4", "/ssd-root-leap-15-1" ),
        Item(Id(:sdc3), "/dev/sdc3",  "29.4G", "ext4", "/" ),
        Item(Id(:sdc4), "/dev/sdc4", "167.2G", "ext4", "/ssd-work" )
      ]
    end

    def handle_events
      while true
        id = UI.UserInput
        case id

        when :close, :cancel # :cancel is WM_CLOSE
          break # leave event loop
        when :table
          update_selected(current_table_item)
        end
        id
      end
    end

    def current_table_item
      UI.QueryWidget(Id(:table), :CurrentItem)
    end

    def update_selected(id)
      id ||= "<nil>"
      UI.ChangeWidget(Id(:selected), :Value, id.to_s)
    end
  end
end

Yast::TableNestedItems.new.main

@joseivanlopez joseivanlopez changed the title WIP: Nested Items in Table Widgets Nested Items in Table Widgets Oct 9, 2020
@joseivanlopez joseivanlopez merged commit 2634113 into yast:master Oct 9, 2020
@yast-bot
Copy link
Contributor

yast-bot commented Oct 9, 2020

✔️ Public Jenkins job #23 successfully finished
✔️ Created OBS submit request #840449

@yast-bot
Copy link
Contributor

yast-bot commented Oct 9, 2020

✔️ Internal Jenkins job #23 successfully finished
✔️ Created IBS submit request #228255

@shundhammer shundhammer deleted the huha-tree-table-01 branch August 10, 2021 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants