views:

206

answers:

1

The code below has (at least) two problems: the Copy button doesn't update the clipboard, and the edit_box doesn't show a vertical scroll bar when it should.

Shoes.app (:title => "Test", :width => 1000, :height => 600) do
  background "#DFA"
  stack :margin => 30 do
    flow do
      button "Paste" do
        @sql.text = clipboard
      end
      button "Copy", :margin_left => 15 do
        clipboard = @sql.text
        alert(@sql.text.length.to_s + " characters copied to clipboard.")
      end
    end
    stack :margin_top => 10, :width => "100%", :height => 500, :scroll => true do
      @sql = edit_box :width => "100%", :height => "100%"
    end
  end
end

The Paste button correctly pastes the clipboard contents into the edit_box. If you make changes, then click Copy, the alert message displays the correct number of characters. If you then click Paste again, the original clipboard contents are pasted. The Copy button never correctly updates the clipboard.

Also, if you generate more lines than fit the edit_box, either by editing or pasting, no scroll bar ever appears.

Any help on these two issues will be much appreciated. My environment is Windows XP if that helps.

UPDATE WITH ANSWERS: Thanks to @Pesto for answering the clipboard question. It turns out that qualifying clipboard with either app. or self. works as expected in both the Paste and Copy buttons.

After digging deeper into the scrollbar issue, I think I understand why the edit_box doesn't show a scrollbar. The scrollbar in Shoes applies only to slots (stack and flow), and not to individual elements like edit_box. The edit_box height is specified in such a way as to always fit within the enclosing stack, so the stack never needs a scrollbar. This led me to a work-around that is not ideal, but is acceptable for my application. Simply change the edit_box height to a larger-than-necessary value such as "10000px" and the scrollbar appears. Unfortunately, it's there whether needed or not, but that's better than no scrollbar. I'm sure that some additional tinkering can dynamically change the edit_box height to exactly fit the contents, so that the scrollbar will appear only when needed.

+1  A: 

First of all, the easy one: change the line in the Copy button to app.clipboard = @sql.text.

Second, as far as the scrollbar goes, this is a known issue on Windows XP. I don't see it listed in the bug reports on github, but the latest version (r1229) still doesn't have a scrollbar.

Pesto
Many thanks. The app.clipboard fix works perfectly. Why is this not required in the Paste function?
Ken Paul
For the simple reason that without using "app", the interpreter doesn't know that you're looking for the clipboard= method instead of just assigning a local variable named clipboard. It's not a shoes thing, it's a Ruby thing.
Pesto

related questions