Skip to content

Commit

Permalink
Merge pull request #119 from thomthom/master
Browse files Browse the repository at this point in the history
Final fixes and preparations for version 2.1 release.
  • Loading branch information
thomthom committed Feb 25, 2014
2 parents 251efb1 + ad595e1 commit f4ddfe8
Show file tree
Hide file tree
Showing 33 changed files with 483 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sublime-workspace
23 changes: 23 additions & 0 deletions SketchUp STL.sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"folders":
[
{
"follow_symlinks": true,
"path": "."
}
],
"settings":
{
"default_encoding": "UTF-8",
"ensure_newline_at_eof_on_save": true,
"rulers":
[
80
],
"show_encoding": true,
"show_line_endings": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
}
}
23 changes: 12 additions & 11 deletions src/sketchup-stl.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2012 Trimble Navigation Ltd.
# Copyright 2012-2014 Trimble Navigation Ltd.
#
# License: Apache License, Version 2.0
#
Expand All @@ -10,42 +10,43 @@

module CommunityExtensions
module STL

PLUGIN_ROOT_PATH = File.dirname(__FILE__)
PLUGIN_PATH = File.join(PLUGIN_ROOT_PATH, 'sketchup-stl')
PLUGIN_STRINGS_PATH = File.join(PLUGIN_PATH, 'strings')

Sketchup::require File.join(PLUGIN_PATH, 'translator')
options = {
:custom_path => PLUGIN_STRINGS_PATH,
:debug => false
}
@translator = Translator.new('STL.strings', options)

# Method for easy access to the translator instance to anything within this
# project.
#
#
# @example
# STL.translate('Hello World')
def self.translate(string)
@translator.get(string)
end

extension = SketchupExtension.new(
STL.translate('STL Import & Export'),
File.join(PLUGIN_PATH, 'loader.rb')
)

extension.description = STL.translate(
'Adds STL file format import and export. ' <<
'This is an open source project sponsored by the SketchUp team. More ' <<
'info and updates at https://github.com/SketchUp/sketchup-stl'
)
extension.version = '2.0.3'
extension.copyright = '2012 Trimble Navigation, released under Apache 2.0'
extension.version = '2.1.0'
extension.copyright = '2012-2014 Trimble Navigation, ' <<
'released under Apache 2.0'
extension.creator = 'J. Foltz, N. Bromham, K. Shroeder, SketchUp Team'

Sketchup.register_extension(extension, true)

end # module STL
end # module CommunityExtensions
2 changes: 1 addition & 1 deletion src/sketchup-stl/SKUI/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def object_id_hex
# Call this method whenever a control property changes, spesifying which
# properties changed. This is sent to the WebDialog for syncing.
#
# @param [Symbol] *properties
# @param [Symbol] properties
#
# @return [Boolean]
# @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion src/sketchup-stl/SKUI/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize( window, webdialog )
# return_value = window.bridge.call('alert', 'Hello World')
#
# @param [String] function Name of JavaScript function to call.
# @param [Mixed] *args List of arguments for the function call.
# @param [Mixed] args List of arguments for the function call.
#
# @return [Mixed]
# @since 1.0.0
Expand Down
20 changes: 10 additions & 10 deletions src/sketchup-stl/SKUI/checkbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class Checkbox < Control

# @return [Boolean]
# @since 1.0.0
prop_reader_bool( :checked, &TypeCheck::BOOLEAN )
prop_writer( :checked, &TypeCheck::BOOLEAN )

# @since 1.0.0
define_event( :change )
define_event( :click )

# @param [String] label
# @param [Boolean] checked
#
Expand All @@ -30,26 +30,26 @@ def initialize( label, checked = false )

# @return [Boolean]
# @since 1.0.0
def check!
checked = true
def check
self.checked = true
end

# @return [Boolean]
# @since 1.0.0
def checked?
checked = window.bridge.get_checkbox_state( ui_id )
self.checked = window.bridge.get_checkbox_state( ui_id )
end

# @return [Boolean]
# @since 1.0.0
def toggle!
checked = !checked?
def toggle
self.checked = !checked?
end

# @return [Boolean]
# @since 1.0.0
def uncheck!
checked = false
def uncheck
self.checked = false
end

end # class
Expand Down
4 changes: 4 additions & 0 deletions src/sketchup-stl/SKUI/control_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def add_control( control )
# Add to Webdialog
if self.window && self.window.visible?
self.window.bridge.add_control( control )
if control.is_a?(ControlManager)
self.window.bridge.add_container( control )
end
return true
end
false
Expand All @@ -40,6 +43,7 @@ def add_control( control )
# @return [Control,Nil]
# @since 1.0.0
def find_control_by_ui_id( ui_id )
return self if self.ui_id == ui_id
for control in @controls
return control if control.ui_id == ui_id
if control.is_a?( ControlManager )
Expand Down
7 changes: 3 additions & 4 deletions src/sketchup-stl/SKUI/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

# @since 1.0.0
module SKUI

# @since 1.0.0
VERSION = '0.1.0'.freeze

# @since 1.0.0
PATH = File.dirname( __FILE__ ).freeze
Expand All @@ -17,6 +14,8 @@ module SKUI
PLATFORM_IS_OSX = ( Object::RUBY_PLATFORM =~ /darwin/i ) ? true : false
PLATFORM_IS_WINDOWS = !PLATFORM_IS_OSX

# Version and release information.
require File.join( PATH, 'version.rb' )

# Configure Debug mode.
require File.join( PATH, 'debug.rb' )
Expand Down Expand Up @@ -50,4 +49,4 @@ def self.reload
$VERBOSE = original_verbose
end

end # module
end # module
32 changes: 31 additions & 1 deletion src/sketchup-stl/SKUI/css/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

*
{
cursor: default;
cursor: inherit;
box-sizing: border-box;
}

Expand All @@ -27,6 +27,7 @@ html, body
border: 0;
padding: 0;
margin: 0;
cursor: default;
}

html
Expand All @@ -48,6 +49,20 @@ body.platform-windows
background: ThreeDFace;
}

/* Windows 8.1 (Or IE11?), or setting text scaling will cause text ir appear
* too big under Windows. Setting explicit size in points appear to make things
* better.
*/
.platform-windows,
.platform-windows input,
.platform-windows select,
.platform-windows textarea,
.platform-windows button,
.platform-windows legend
{
font-size: 9pt;
}


/*******************************************************************************
*
Expand Down Expand Up @@ -128,6 +143,21 @@ body.platform-windows
}


/*******************************************************************************
*
* $LABEL
*
******************************************************************************/


.control-label a
{
display: inline-block;
width: 100%;
height: 100%;
}


/*******************************************************************************
*
* $LISTBOX
Expand Down
6 changes: 4 additions & 2 deletions src/sketchup-stl/SKUI/font.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ class Font

attr_accessor( :name, :size, :bold, :italic )

# @param [String] caption
# @param [Control] control Control which focus of forwarded to.
# @param [String] name
# @param [Integer, Nil] size
# @param [Boolean, Nil] bold
# @param [Boolean, Nil] italic
#
# @since 1.0.0
def initialize( name, size = nil, bold = nil, italic = nil )
Expand Down
2 changes: 1 addition & 1 deletion src/sketchup-stl/SKUI/js/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var Bridge = function() {
message = messages.shift();
if ( message ) {
busy = true;
uri_message = encodeURIComponent( message );
uri_message = encodeURIComponent( message.add_slashes() );
window.location = 'skp:SKUI_Callback@' + uri_message;
return true;
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/sketchup-stl/SKUI/js/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@
******************************************************************************/


String.prototype.add_slashes = function() {
var string = this;
string = string.replace(/\\/g,"\\\\");
string = string.replace(/\'/g,"\\'");
string = string.replace(/\"/g,"\\\"");
return string;
}

//String.prototype.to_css = String.prototype.toString; // Doesn't work.
String.prototype.to_css = function() { return this; }
2 changes: 1 addition & 1 deletion src/sketchup-stl/SKUI/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ var UI = function() {
var control_class_string = $control.data( 'control_class' );
var control_class = eval( control_class_string );
var control = new control_class( $control );
return control
return control;
},


Expand Down
7 changes: 7 additions & 0 deletions src/sketchup-stl/SKUI/js/ui.label.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ Label.add = function( properties ) {
return control;
}

Label.prototype.set_align = function( value ) {
// `value` is a Symbol in Ruby and becomes a string like ":left" in JS.
var css_value = value.substring( 1, value.length );
this.control.css('text-align', css_value);
return value;
};

Label.prototype.set_caption = function( value ) {
$a = this.control.children('a');
$a.text( value );
Expand Down
13 changes: 13 additions & 0 deletions src/sketchup-stl/SKUI/js/ui.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function Window( jquery_element ) {
Control.call( this, jquery_element );
this.cancel_button = null;
this.default_button = null;
this.control.data( 'control_class', this.typename );
}

UI.Window = Window;
Expand All @@ -37,6 +38,18 @@ Window.init = function( properties ) {
break;
}
});
// Catch when the window received and looses focus.
// (i) These events doesn't trigger correctly when Firebug Lite is active
// because it introduces frames that interfere with the focus
// notifications.
$(window).on( 'focus', function( event ) {
control = UI.get_control( 'body' );
control.callback( 'focus' );
});
$(window).on( 'blur', function( event ) {
control = UI.get_control( 'body' );
control.callback( 'blur' );
});
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sketchup-stl/SKUI/js/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Function.prototype.get_typename = function() {
if (Function.prototype.name === undefined) {
var funcNameRegex = /function\s([^(]{1,})\(/;
var results = funcNameRegex.exec( this.toString() );
return (results && results.length > 1) ? results[1].trim() : "";
return (results && results.length > 1) ? $.trim(results[1]) : "";
} else {
return this.name;
}
Expand Down
18 changes: 17 additions & 1 deletion src/sketchup-stl/SKUI/js/webdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,25 @@ var WebDialog = function() {

userAgent : function() {
return navigator.userAgent;
},


add_scripts : function(scripts) {
var $head = $('head');
for (var i = 0; i < scripts.length; ++i)
{
var script = scripts[i];
// Must use a closure to ensure `script` is returned properly.
(function(script) {
jQuery.getScript(script, function() {
Sketchup.callback('SKUI::Window.on_script_loaded', script);
});
})(scripts[i]);
}
return null;
}


};

}(); // WebDialog
}(); // WebDialog
5 changes: 5 additions & 0 deletions src/sketchup-stl/SKUI/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module SKUI
# @since 1.0.0
class Label < Control

# @return [Control]
# @since 1.0.0
prop( :align, &TypeCheck::TEXTALIGN )

# @return [String]
# @since 1.0.0
prop( :caption, &TypeCheck::STRING )
Expand All @@ -28,6 +32,7 @@ class Label < Control
def initialize( caption, control = nil )
super()

@properties[ :align ] = :left
@properties[ :caption ] = caption
@properties[ :control ] = control

Expand Down
Loading

0 comments on commit f4ddfe8

Please sign in to comment.