[plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013
-
Hi All,
Please see my other forum post for details and all updates:
http://sketchucation.com/forums/viewtopic.php?f=323&t=25800
Cheers,
Alex -
tried to leave this at your site,but not sure it worked??
Hi Alex,
I've been using v1 quite a lot , teaching myself ruby on a Mac and I put together a list of slight oddities to post, however I'll now check them against the new version before bothering you, keep up the good work, every bit helps, even the oddities...
john
-
Hi Alex,
possibly a quick fix required,
I always get the open link format on restart even after setting options
WebConsole show's _modal on the Mac, this doesn't ... (or whatever I should call not vanishing behind SU)
I may have modified WC, can't remember, I'll reload a clean one and check...
I can't see where I might modify this or the last version
john
-
@driven said:
I always get the open link format on restart even after setting options
Not sure what you mean by this. I have to admit that I haven't tried either version on a mac yet. I'll do that soon but in the meantime keep any bugs coming my way...
Cheers,
Alex -
I have to right click to get to the drop down box, then click load link
I always get this page on when selecting RCE
-
@driven said:
I have to right click to get to the drop down box, then click load link
Yuck! That is indeed a glitch. It is only happening in Safari/Chrome. So for now that's a problem only for mac users. I'll fix that later today. Thanks for letting me know.
Cheers,
Alex -
Dang... Alex we are supposed to use the same original thread, and post the plugin in the first message. Then when updated, you replace the file attachment there in the first message.
(But in your case, you'd update the link to the download.. same difference.)As the thread 'starter' you can can change the Topic to reflect '[UPDATE]' and release version. etc.
That way..
(1) there is not a separate thread for each new release.
(2) Since I posted in the original thread, I expected (when an update came,) to see the thread pop to the top of the 'Your Posts' page (which is kind of my 'homepage' at SCF, how I enter the site.){Maybe ThomThom can stitch the 2 threads together if you agree.]
-
@Dan: I can do that the next time. I did put a note on the last thread mentioning that there is an update available at the same address. And the last thread went a little off-topic after a while, so I thought this would keep things clean.
The main download location is still my website, so at least there are no old versions floating around.
Cheers, Alex
P.S. WebKit doesn't seem to want to save cookies from a local page somehow, so I might have to do a local preference storage (as suggested before) after all...
-
@alexschreyer said:
@Dan: I can do that the next time.
OK. no problem... I've posted here so this thread popped to the top, when you posted.
@alexschreyer said:
WebKit doesn't seem to want to save cookies from a local page somehow, so I might have to do a local preference storage (as suggested before) after all...
Well I've already done the work.. let me have a look at as_rubyeditor.rb, and I'll get back to ya' today or tomarrow.
-
as ruby code editor ver 1.1
MSIEver 7.0.5730.11Errors:
(1) ui.html - Line 113 - invalid argument
%(#804000)[<a] %(#40BFBF)[class]=%(#FF8040)["button"] %(#40BFBF)[onClick]=%(#FF8040)["u();"] ... %(#804000)[>]
removed ";" and error went away
%(#804000)[<a] %(#40BFBF)[class]=%(#FF8040)["button"] %(#40BFBF)[onClick]=%(#FF8040)["u()"] ... %(#804000)[>]
.. but then (after reloading page,)
(2) ui.js - Line 165 - Char 3 - Object doesn't support this property or method
[seems that line wants to load stylesheet(s)]... the page looks exactly like driven posted for the Mac. (but with MS fonts)
-
Just a quick update:
-
I fixed the cookie issue. Apparently I needed a path to save the cookies. Although Chrome won't save local file cookies, Safari will do that. So we're okay with all preferences and saving them locally.
-
I fixed the reference browser back button issue. Now in Safari only the iframe gets navigated.
I'll upload a new version with those fixes later today.
The remaining issue is that the function that inserts text at the cursor (tab key and snippets) works fine in IE but not in FF/Safari. I'll look into that. Then I'll also finally try this out on a mac.
Cheers,
Alex -
-
Excellent ....
-
@alexschreyer said:
The remaining issue is ...
Actually I see a few (in as_rubyeditor.rb)
(1) You removed the module wrapper around the dialog class !!!
This is a no-no. ONLY Ruby Baseclasses (like Integer, String, Module, Class .. etc.,) should be defined at the TOP_LEVEL, in the Objectspace. The lightweight version I'm working on (update to Jim's) will be double wrapped, something like:
SUutil::Ruby::WebConsole(2) down ~line 181
# Callback to undo the last code execution
add_action_callback("undo") do |d, p|
(a) Just want to stress (seeing your code comment,) that Undo is a Sketchup function, not a Ruby function. It only undoes changes to the model. It does not undo ruby statements. For instance, if you define a method, run it, and click undo; The method is still defined in Ruby (whether right or wrong.) The same holds true for variables, constants, object instances, etc.
(b) I consider using 'p' as a varname dangerous because of method Object.p (and try to avoid single char varnames; usually put a number like t1, t2 for time vars, or x1,y1 for coords, etc.
Jim had a weird bug in a previous version that had to do with the use of 'd' as a varname, see:Sketchup Developer's Google Group post: "What is so special about d?"
***** For WebDialog callbacks I've settled on a personal standard |dlg,arg|(3) Instancing.
(a) The way it's written now (ie the way Jim had it,) the object constructor is within the menu item block, and creates a new instance each time the menu (or toolbar button,) is clicked.
When the .close method is called, it's only the OS window object (and it's instances of the webpage, CSS and Js that are destroyed,) along with any text in the HTML controls.
But the Ruby UI::WebDialog instance object still exists, and can be reshown. When this happens, Sketchup Ruby reloads the webpage assigned to it. Anyway think about that for a future revision.
(b) I think I will limit my version to two (2) instances and greyout the "new" menu item after that. (A user can only 'cut & paste' between two windows at a time.) I'm also going to dynamically add links to the menu as the instances are created, so those instances can be reused, rather than waste memory.
(c) This brings up the problem of Preference control. Which window will be (or should be,) allowed to update the settings? It takes a bit of thought, as I wish to have each instance save it's own size and position, and likely for the Mac, whether individually they will be 'always on top' or can go behind other windows, including SU.
_ -
Hi Dan, Thanks for those points. My comments:
-
I believe I kept that as it was but I'll add that.
-
I see this code editor more for people that use it for geometry creation in SU rather than for the Ruby programmer (although they should find it useful, too). So the undo option is meant for undoing the SU action. Also, if you compare my code to Jim's, you see that I like verbose and commented code - I find it helpful for myself and for whoever uses it next. So I also prefer longer variable names.
-
Until there is a multi-file version of the editor, the multi-instance option is actually useful. Question: On close, can I destroy an instance like "UI::WebDialog = nil". Good point about the instance preferences. Haven't thought about that yet.
I am still fighting with Browser issues. I thought using jQuery would eliminate those. So cookies that save in Safari don't do so in IE.
Cheers,
Alex -
-
I just uploaded a newer version (1.1.1) that should fix some of the Safari issues. Now the page should at least load without complaint and the editor is usable. Some of the quirks I found:
-
It doesn't seem to be possible to access an iframe's browser history in Safari. Therefore I had to remove the Back/Forward buttons when the editor gets used on a mac.
-
Cookies are handled differently in all browsers. So preference storing works fine in Windows, but may not work on the mac. Next step is to use a local storage for that.
-
I couldn't get caret positioning working 100% in Safari. Text and tab insertion works fine but the caret jumps around afterwards.
Everything should work as expected in Windows, though. I can't believe that this time IE works fine and Safari is acting up.
Cheers,
Alex -
-
@alexschreyer said:
- ... So the undo option is meant for undoing the SU action. ...
OK just so you know, and hopefully the users will also.
I thought of a scenario: What if a user wishes to actually experient themselves with the undo API feature, writing the .start_operation, .commit_operation calls into the snippet editor? What would happen in ruby with double nested operations? Perhaps a checkbox next to the UNDO button to turn on|off the editor's Undo calls, ie(as_rubyeditor.rb):
line 74:Sketchup.active_model.start_operation "RubyEditor" **if @undo_is_on**
line 82:Sketchup.active_model.abort_operation **if @undo_is_on**
line 84:Sketchup.active_model.commit_operation **if @undo_is_on**
@alexschreyer said:
- Until there is a multi-file version of the editor, the multi-instance option is actually useful. Question: On close, can I destroy an instance like "UI::WebDialog = nil".
Agreed, and actually even with a multi-file version (if you don't have a split screen feature,) then allowing two instances can satisfy those who'd want a split screen feature, (ie: 'cut & pasting' between two windows.) But we need to control instancing, and limit it (with a default limit, which might be overridden by the user.) I'm using a class variable: @@max_num
Garbage Collection. You would not set the class to nil. You are suppossed to be able to set the instance to nil and then call GC.start, but I've never witnessed GC disposing of the instance variable. It just sits around with a nil value (at least it's not taking up much space.) So ..
dlg=Namespace::RubyEditor.new( *arglist* ) #.. set it up.. show it .. use it .. close it dlg=nil GC.start
Anyway... in this case: we first must use a symbol to hold a reference to each instance. In editor code (line 205) in the add menu item command block you have (as Jim did,): "RubyEditor.new" which is not storing a reference to the instance, even though the object.new method always returns a reference to the newly created instance of the object class (which is the third main task of the new method in ruby.)
I'm using an Array class variable: @@instances=[]
and when I construct the instance, I push it's reference into the array:
if @@instances.size < @@max_num %(#F0F0F0)[__]num = @@instances.size+1 %(#F0F0F0)[__]if dlgi = WebConsole.new(num) # non-nil if success %(#F0F0F0)[____]@@instances.push( dlgi ) %(#F0F0F0)[____]# add menu link for instance %(#F0F0F0)[__]end end
The num var is used both to insert into instance menu text (similar to an editor's untitled(1), untitled(2) captions,) and is passed to new, so the instance itself can know which one it is (it's position in the class array var @@instances,) and to append as text onto the instance's Preferences Key suffix.
All that if block, above is wrapped within a UI::Commandclass instance @@cmd
__
- ... So the undo option is meant for undoing the SU action. ...
-
BY the way... you announced a ver 1.1.1, but...
The Revision block at the top of as_rubyeditor.rb says version: 1.2
(The extension registration/loader script says version: 1.1.1)The thread topic (title of the first post,) still says version 1.1
-
@dan rathbun said:
The Revision block at the top of as_rubyeditor.rb says version: 1.2
I keep missing those little details... Thanks!
@dan rathbun said:
Perhaps a checkbox next to the UNDO button
Great idea. I'll put this into the preferences section, though.
@dan rathbun said:
Garbage Collection
Thanks for the detailed explanation. I'll look at it.
But zooming out a little: It seems to me that we could maybe work more effectively on this if it were a collaborative project. I haven't worked with Github or similar systems before, but from what I understand it is made for stuff like this. Would you (and anyone else interested, of course) want to move this to a collaborative project?
Cheers,
Alex -
Wow -- very nice and helpful plugin! I almost wish I could run it outside of SketchUp
Have you thought about adding syntax highlighting? Something to pop out basic Ruby keywords and SketchUp-specific keywords?
-
@alz said:
Have you thought about adding syntax highlighting?
I actually had it in there at the beginning. Unfortunately (since it uses Javascript), I found that it would get very slow with moderately sized files. But I agree it would be nice.
Cheers,
Alex
Advertisement