Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 13 2016 03:24
    @PeterWAWood banned @Vexercizer
luce80
@luce80
@GiuseppeChillemi here is a reacting version: https://gist.github.com/luce80/e34516e5248b629badfd4016dda6cbb8
Rebol2Red
@Rebol2Red

@luce80

*** Script Error: n1 has no value
*** Where: get
*** Stack: view layout react

What are the values for n1 and n2?

Rebol2Red
@Rebol2Red

My previous post did not work after copying and pasting into the console so i deleted it. This version does.

After selecting an item from a text-list i want to delete it from the list.

thedata: ["a" "b" "c"]
selecteditems: copy []
view [
    te: text-list data thedata [
        t: thedata/(te/selected)
        if not(none? t) [
            append selecteditems t
            thedata/(te/selected): copy ""
        ]
        l: 0
        foreach item thedata [
            if item <> "" [
                l: l + 1
            ]
        ]
        if 0 = l [unview]
    ] 
]
print selecteditems ; this order is not important

This code works but there must be a nicer better way to do this.
Note: The selected items can be chosen random.

Nenad Rakocevic
@dockimbel
@Rebol2Red Here is a simplified version:
list: ["a" "b" "c"]
collected: []

view [
    text-list data list on-down [
        append collected take at face/data face/selected
        if empty? face/data [?? collected unview]
    ]
]
Rebol2Red
@Rebol2Red
@dockimbel Much better. Thank you.
Nenad Rakocevic
@dockimbel
Some comments about your code:
  • if not(none? t) [ is equivalent to if t [ in this case.
  • thedata/(te/selected) is a bit harder to read than pick thedata te/selected or at thedata te/selected.
  • Use shorter words, use hyphen (-) when putting multiple words together as a variable name. Invest into better names, make your code read well enough in English, it will be easier to understand/maintain.
  • Avoid using I, l or O as variable names, as they can often be confused with 1 and 0.
  • Red has a rich API, most of simple actions you need on built-in datatypes are probably covered already. Take some time to study the existing functions (use what from the console and the Rebol/Core manual).
Rebol2Red
@Rebol2Red
@dockimbel Thanks for your comments. I appreciate this a lot! I did study the functions but i do'nt have taken the Red pill after many years of programming in c, basic and many other languages.
Nenad Rakocevic
@dockimbel
@Rebol2Red In such case, I really recommend you reading the Rebol/Core manual, from cover to cover, with a Rebol console opened to copy/paste and play with the examples. That's the best way, for now, to dive into those concepts.
Here is an even more concise version:
list: ["a" "b" "c"]

probe collect [
    view [
        text-list data list on-down [
            keep take at face/data face/selected
            if empty? face/data [unview]
        ]
    ]
]
Rebol2Red
@Rebol2Red
@dockimbel Maybe i am good at providing poor code to learn others and myself to learn how to do it the right way. I have a lot of it :)
Nenad Rakocevic
@dockimbel
Submitting code for improvement by the community is a good way to learn. Though, it should not replace reading in depth the existing docs. Also, asking the community questions about some language concepts or constructs is also very useful. Back in the early days in the Rebol community, we only had the mailing-list for that, and it was very helpful for everyone to ask questions and submit code. Nowadays, we have sophisticated realtime chats and online collaborative tools, so don't be shy. ;-)
Rebol2Red
@Rebol2Red
@dockimbel So expect a lot from me. I'm just kidding. Back to programming :)
Rebol2Red
@Rebol2Red
One more question. How do i get the selected item? Looks simple but
not to me.
list: ["a" "b" "c"]
print collect [
    view [
        text-list data list on-down [

            ; I need the selected item to 
            ; store it into another text-list

            keep take at face/data face/selected
            if empty? face/data [unview]
        ]
    ]
]
Rebol2Red
@Rebol2Red

Wrong:

list: ["a" "b" "c"]
selected: copy []
print collect [
    view [
        text-list data list on-down [
            append selected keep take at face/data face/selected
        ]
        text-list data selected
    ]
]

If i click on "b" i get "a" into the other text-list

Rebol2Red
@Rebol2Red
@dockimbel Also on the concise code you gave me this happens.
For example if i click on "b" it removes "a"
Nenad Rakocevic
@dockimbel
@Rebol2Red Right, I should have used event/picked rather than face/selected. Though, the mouse events seem to not fill event/picked, so that we need to change the event type and add some extra code to ensure that the text-list's selection does not interfere:
list: ["a" "b" "c"]

probe collect [
    view [
        text-list data list 
            on-change [face/selected: none]
            on-select [
                keep take at face/data probe event/picked
                if empty? face/data [unview]

        ]
    ]
]
Rebol2Red
@Rebol2Red
@dockimbel Thanks, now i have a nice way to select items!
Nenad Rakocevic
@dockimbel
@Rebol2Red Selecting items is much simpler than that. The above code is for selecting, removing selected items , and storing them in another list.
I've opened a ticket for the mouse events on text-list, to see if we can improve it.
luce80
@luce80
@Rebol2Red About n1 and n2 of my code: did you just copy-pasted only the piece of code shown by gitter ? If so try to go to the link and copy-paste all the text.
Rebol2Red
@Rebol2Red
@luce80 Yes, i did only copy-pasted. I now have all the text. Thanks.
Rebol2Red
@Rebol2Red
@dockimbel Now i have to find a way to keep the second text-list sorted. A pity "text-list data sort selected" does not work. Any suggestion?
Why did you use probe event/picked not leaving probe out?
Gregg Irwin
@greggirwin
@Rebol2Red, probably Doc is showing how to collect data and return it. If you need to act, i.e. sort, on each selection, you'll need to use the append approach, not collect.
Then you can sort as each item is selected.
Nenad Rakocevic
@dockimbel

@Rebol2Red

view [
    tl: text-list data ["b" "d" "a" "c"]
    button "sort" [sort tl/data show tl]
]

show should not be needed, seems an object event handler for sort action is missing.

Nenad Rakocevic
@dockimbel
Fix for sort on text-list pushed.
GiuseppeChillemi
@GiuseppeChillemi
It would be good to reference those script as expample in the proper documentation section
Jose Luis
@planetsizecpu
+1 to scroller face type (sorry for delay)
Jose Luis
@planetsizecpu
polo1.jpg
Taking advantage of my holidays I acquired this new T-Shirt at the corner's shop, I'm so proud of wear it this summer :smile:
Gregg Irwin
@greggirwin
@planetsizecpu, nice!
Fyodor Shchukin
@honix
gradient-bug.PNG
Looks like a bug. Code
Boleslav Březovský
@rebolek
@honix definetely a bug, I can confirm it it on Vbox W10. Please fill an issue for it.
Fyodor Shchukin
@honix
done!
Gregg Irwin
@greggirwin
:point_up: August 7, 2017 1:07 PM How best to access old and new selection in a text-list.
Henrik Mikael Kristensen
@henrikmk
the way I see it is to first store SELECTION in LAST-SELECTION or OLD-SELECTION before changing SELECTION in ON-CHANGE.
Gregg Irwin
@greggirwin
In face/state?
Henrik Mikael Kristensen
@henrikmk
where SELECTION is
Gregg Irwin
@greggirwin
Would need a new facet then, pretty sure.
Henrik Mikael Kristensen
@henrikmk
is there an extensible facet? one that stores an object?
Gregg Irwin
@greggirwin
state and options are blocks, AFAIK, so need to check and append, or designate a fixed slot. Haven't dug in myself yet.
Henrik Mikael Kristensen
@henrikmk
ok. what are the prospects for face accessor functions like GET-FACE and SET-FACE? they could help solve this issue in a more "official" way.
Gregg Irwin
@greggirwin
I'm sure there will be more accessor ideas. do-event was added recently, but I don't know if they'll be wrappers or built into styles. Could be done either way.
Petr Krenzelok
@pekr
IIRC Doc studied available Rebol GUIs, it would be probably best to ask him about those design questions?
Nenad Rakocevic
@dockimbel
@henrikmk :point_up: August 8, 2017 11:40 AM There is no need to store the old selection, both old and new values are available during select event.
Nenad Rakocevic
@dockimbel
@planetsizecpu Great! :clap: :-)
Boleslav Březovský
@rebolek

@GiuseppeChillemi @pekr some improvements:
http://i.imgur.com/LZm7Vas.png

  • columns can be reordered
  • long text is automatically truncated
  • text can be aligned to left or right
  • active cell or row can be highlighted
  • header
  • and probably some others I forgot.

Next is keyboard navigation and editing (probably using fieldstyle, I will see).

Petr Krenzelok
@pekr
Just some input - when you reorder column - do you physically move the data? I hope it is just virtual?
Boleslav Březovský
@rebolek
Virtual, moving all data would be too much work ;)