diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ab1b2e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.sublime-workspace diff --git a/SketchUp STL.sublime-project b/SketchUp STL.sublime-project new file mode 100644 index 0000000..e8859a2 --- /dev/null +++ b/SketchUp STL.sublime-project @@ -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 + } +} diff --git a/src/sketchup-stl.rb b/src/sketchup-stl.rb index 362b3ed..0aa9a29 100644 --- a/src/sketchup-stl.rb +++ b/src/sketchup-stl.rb @@ -1,4 +1,4 @@ -# Copyright 2012 Trimble Navigation Ltd. +# Copyright 2012-2014 Trimble Navigation Ltd. # # License: Apache License, Version 2.0 # @@ -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 diff --git a/src/sketchup-stl/SKUI/base.rb b/src/sketchup-stl/SKUI/base.rb index 8268e7e..e8b28e2 100644 --- a/src/sketchup-stl/SKUI/base.rb +++ b/src/sketchup-stl/SKUI/base.rb @@ -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 diff --git a/src/sketchup-stl/SKUI/bridge.rb b/src/sketchup-stl/SKUI/bridge.rb index 3c702f9..4c23f0a 100644 --- a/src/sketchup-stl/SKUI/bridge.rb +++ b/src/sketchup-stl/SKUI/bridge.rb @@ -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 diff --git a/src/sketchup-stl/SKUI/checkbox.rb b/src/sketchup-stl/SKUI/checkbox.rb index e197373..8305e38 100644 --- a/src/sketchup-stl/SKUI/checkbox.rb +++ b/src/sketchup-stl/SKUI/checkbox.rb @@ -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 # @@ -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 diff --git a/src/sketchup-stl/SKUI/control_manager.rb b/src/sketchup-stl/SKUI/control_manager.rb index 9cb0cfe..e7eb39b 100644 --- a/src/sketchup-stl/SKUI/control_manager.rb +++ b/src/sketchup-stl/SKUI/control_manager.rb @@ -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 @@ -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 ) diff --git a/src/sketchup-stl/SKUI/core.rb b/src/sketchup-stl/SKUI/core.rb index 541376d..66f8759 100644 --- a/src/sketchup-stl/SKUI/core.rb +++ b/src/sketchup-stl/SKUI/core.rb @@ -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 @@ -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' ) @@ -50,4 +49,4 @@ def self.reload $VERBOSE = original_verbose end -end # module +end # module \ No newline at end of file diff --git a/src/sketchup-stl/SKUI/css/core.css b/src/sketchup-stl/SKUI/css/core.css index 15ca732..02f9cfa 100644 --- a/src/sketchup-stl/SKUI/css/core.css +++ b/src/sketchup-stl/SKUI/css/core.css @@ -7,7 +7,7 @@ * { - cursor: default; + cursor: inherit; box-sizing: border-box; } @@ -27,6 +27,7 @@ html, body border: 0; padding: 0; margin: 0; + cursor: default; } html @@ -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; +} + /******************************************************************************* * @@ -128,6 +143,21 @@ body.platform-windows } +/******************************************************************************* + * + * $LABEL + * + ******************************************************************************/ + + +.control-label a +{ + display: inline-block; + width: 100%; + height: 100%; +} + + /******************************************************************************* * * $LISTBOX diff --git a/src/sketchup-stl/SKUI/font.rb b/src/sketchup-stl/SKUI/font.rb index 7f3b590..e78e6ac 100644 --- a/src/sketchup-stl/SKUI/font.rb +++ b/src/sketchup-stl/SKUI/font.rb @@ -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 ) diff --git a/src/sketchup-stl/SKUI/js/bridge.js b/src/sketchup-stl/SKUI/js/bridge.js index dda6be3..06d9fc7 100644 --- a/src/sketchup-stl/SKUI/js/bridge.js +++ b/src/sketchup-stl/SKUI/js/bridge.js @@ -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 { diff --git a/src/sketchup-stl/SKUI/js/string.js b/src/sketchup-stl/SKUI/js/string.js index 135850c..95b8b7a 100644 --- a/src/sketchup-stl/SKUI/js/string.js +++ b/src/sketchup-stl/SKUI/js/string.js @@ -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; } diff --git a/src/sketchup-stl/SKUI/js/ui.js b/src/sketchup-stl/SKUI/js/ui.js index 0304d6e..32559aa 100644 --- a/src/sketchup-stl/SKUI/js/ui.js +++ b/src/sketchup-stl/SKUI/js/ui.js @@ -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; }, diff --git a/src/sketchup-stl/SKUI/js/ui.label.js b/src/sketchup-stl/SKUI/js/ui.label.js index 61c6919..b5fe831 100644 --- a/src/sketchup-stl/SKUI/js/ui.label.js +++ b/src/sketchup-stl/SKUI/js/ui.label.js @@ -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 ); diff --git a/src/sketchup-stl/SKUI/js/ui.window.js b/src/sketchup-stl/SKUI/js/ui.window.js index e2796bf..d72c650 100644 --- a/src/sketchup-stl/SKUI/js/ui.window.js +++ b/src/sketchup-stl/SKUI/js/ui.window.js @@ -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; @@ -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; } diff --git a/src/sketchup-stl/SKUI/js/utilities.js b/src/sketchup-stl/SKUI/js/utilities.js index b7a7652..91bc5d0 100644 --- a/src/sketchup-stl/SKUI/js/utilities.js +++ b/src/sketchup-stl/SKUI/js/utilities.js @@ -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; } diff --git a/src/sketchup-stl/SKUI/js/webdialog.js b/src/sketchup-stl/SKUI/js/webdialog.js index d919aa7..6402460 100644 --- a/src/sketchup-stl/SKUI/js/webdialog.js +++ b/src/sketchup-stl/SKUI/js/webdialog.js @@ -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 \ No newline at end of file +}(); // WebDialog diff --git a/src/sketchup-stl/SKUI/label.rb b/src/sketchup-stl/SKUI/label.rb index 759ef78..57ff144 100644 --- a/src/sketchup-stl/SKUI/label.rb +++ b/src/sketchup-stl/SKUI/label.rb @@ -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 ) @@ -28,6 +32,7 @@ class Label < Control def initialize( caption, control = nil ) super() + @properties[ :align ] = :left @properties[ :caption ] = caption @properties[ :control ] = control diff --git a/src/sketchup-stl/SKUI/listbox.rb b/src/sketchup-stl/SKUI/listbox.rb index 5f69b2a..9e6cc21 100644 --- a/src/sketchup-stl/SKUI/listbox.rb +++ b/src/sketchup-stl/SKUI/listbox.rb @@ -9,10 +9,10 @@ class Listbox < Control # @return [Array] # @since 1.0.0 prop_reader( :items ) - + # @return [Boolean] # @since 1.0.0 - prop_bool( :multiple, &TypeCheck::BOOLEAN ) + prop_reader_bool( :multiple, &TypeCheck::BOOLEAN ) # @return [Integer] # @since 1.0.0 @@ -20,9 +20,8 @@ class Listbox < Control # @since 1.0.0 define_event( :change ) - + # @param [Array] list - # @param [Proc] on_click # # @since 1.0.0 def initialize( list = [] ) @@ -32,8 +31,9 @@ def initialize( list = [] ) # (?) Check for String content? Convert to strings? Accept #to_a objects? super() # (?) Should the :items list be a Hash instead? To allow key/value pairs. - @properties[ :items ] = list - @properties[ :multiple ] = false + @properties[ :items ] = list.dup + @properties[ :multiple ] = false # Select multiple. + @properties[ :size ] = 1 # Makes no sense! end # @overload add_item(string, ...) @@ -108,6 +108,21 @@ def move_selected_down true end + # @param [Boolean] value + # + # @return [Boolean] + # @since 1.0.0 + def multiple=( value ) + value = TypeCheck::BOOLEAN.call( value ) + if value && self.size < 2 + raise( ArgumentError, + 'Can only select multiple when size is greater than 1.' ) + end + @properties[ :multiple ] = value + update_properties( :multiple ) + value + end + # @overload remove_item(string) # @param [String] string # @@ -122,8 +137,10 @@ def remove_item( arg ) unless index raise( ArgumentError, 'Invalid item.' ) end - else + elsif arg.is_a?( Integer ) index = arg + else + raise( ArgumentError, 'Invalid argument.' ) end if index < 0 || index >= @properties[ :items ].length raise( ArgumentError, 'Index out of range.' ) @@ -133,6 +150,23 @@ def remove_item( arg ) nil end + # @param [Integer] value + # + # @return [Integer] + # @since 1.0.0 + def size=( value ) + value = TypeCheck::INTEGER.call( value ) + if value < 2 + @properties[ :size ] = value + @properties[ :multiple ] = false + update_properties( :size, :multiple ) + else + @properties[ :size ] = value + update_properties( :size ) + end + value + end + # @return [String] # @since 1.0.0 def value @@ -140,19 +174,43 @@ def value @properties[ :value ] = data data end - - # @param [String] string + + # @overload value=(string) + # @param [String] string + # @return [String] # - # @return [String] + # @overload value=(string,...) + # @param [String] string + # @return [Array] + # + # @overload value=(strings) + # @param [Array] strings + # @return [Array] # @since 1.0.0 - def value=( string ) - unless @properties[ :items ].include?( string ) - raise( ArgumentError, "'#{string}' not a valid value in list." ) + def value=( *args ) + if args.size == 1 && args[0].is_a?( Array ) + #return self.value=( *args[0] ) + return send( :value=, *args[0] ) end - @properties[ :value ] = string + + unless args.all? { |item| item.is_a?( String ) } + raise( ArgumentError, 'Arguments must be strings.' ) + end + + if !self.multiple? && args.size > 1 + raise( ArgumentError, 'Not configured to select multiple items.' ) + end + + items = @properties[ :items ] + unless (items | args).length == items.length + not_in_list = (args - items).join(', ') + raise( ArgumentError, "'#{not_in_list}' not valid values in list." ) + end + + @properties[ :value ] = args.dup update_properties( :value ) - string + args end end # class -end # module \ No newline at end of file +end # module diff --git a/src/sketchup-stl/SKUI/properties.rb b/src/sketchup-stl/SKUI/properties.rb index cf81463..8e27d64 100644 --- a/src/sketchup-stl/SKUI/properties.rb +++ b/src/sketchup-stl/SKUI/properties.rb @@ -2,15 +2,12 @@ module SKUI # Mix-in module for the Control class. Simplifies the definition of properties # with getter and setter methods that access the +@properties+ stack. # - # @todo Make YARD document there properties: - # http://yardoc.org/guides/extending-yard/writing-handlers.html#Creating_a_Simple_DSL_Handler - # # @since 1.0.0 module Properties private - # @param [Symbol] *symbols + # @param [Symbol] symbols # # @return [Nil] # @since 1.0.0 @@ -21,7 +18,7 @@ def prop( *symbols, &block ) end alias :prop_accessor :prop - # @param [Symbol] *symbols + # @param [Symbol] symbols # # @return [Nil] # @since 1.0.0 @@ -31,7 +28,7 @@ def prop_bool( *symbols ) nil end - # @param [Symbol] *symbols + # @param [Symbol] symbols # # @return [Nil] # @since 1.0.0 @@ -50,7 +47,7 @@ def prop_reader( *symbols ) nil end - # @param [Symbol] *symbols + # @param [Symbol] symbols # # @return [Nil] # @since 1.0.0 @@ -70,7 +67,7 @@ def prop_reader_bool( *symbols ) # block is given one argument, the new value of the property. Use this to # add argument validation to the property. # - # @param [Symbol] *symbols + # @param [Symbol] symbols # # @return [Nil] # @since 1.0.0 diff --git a/src/sketchup-stl/SKUI/typecheck.rb b/src/sketchup-stl/SKUI/typecheck.rb index 75f61d2..d08e74d 100644 --- a/src/sketchup-stl/SKUI/typecheck.rb +++ b/src/sketchup-stl/SKUI/typecheck.rb @@ -69,11 +69,19 @@ module TypeCheck # @since 1.0.0 INTEGER = Proc.new { |value| unless value.respond_to?( :to_i ) - raise( ArgumentError, 'Not an valid Integer value.' ) + raise( ArgumentError, 'Not a valid Integer value.' ) end value.to_i } + # @since 1.0.0 + TEXTALIGN = Proc.new { |value| + unless [:left, :center, :right].include?( value ) + raise( ArgumentError, 'Not a valid alignment value.' ) + end + value + } + # @since 1.0.0 STRING = Proc.new { |value| unless value.respond_to?( :to_s ) diff --git a/src/sketchup-stl/SKUI/version.rb b/src/sketchup-stl/SKUI/version.rb new file mode 100644 index 0000000..f71cd10 --- /dev/null +++ b/src/sketchup-stl/SKUI/version.rb @@ -0,0 +1,6 @@ +module SKUI + + # @since 1.0.0 + VERSION = '0.1.0'.freeze + +end \ No newline at end of file diff --git a/src/sketchup-stl/SKUI/window.rb b/src/sketchup-stl/SKUI/window.rb index 7790025..6c8b2c9 100644 --- a/src/sketchup-stl/SKUI/window.rb +++ b/src/sketchup-stl/SKUI/window.rb @@ -28,6 +28,15 @@ class Window < Base # @since 1.0.0 define_event( :ready ) + # @since 1.0.0 + define_event( :close ) + + # @since 1.0.0 + define_event( :focus, :blur ) + + # @since 1.0.0 + define_event( :scripts_loaded ) + # @since 1.0.0 THEME_DEFAULT = nil THEME_GRAPHITE = File.join( PATH_CSS, 'theme_graphite.css' ).freeze @@ -69,6 +78,9 @@ def initialize( options = {} ) @properties[:theme] = @options[:theme] + @scripts = [] + @loaded_scripts = [] + # Create a dummy WebDialog here in order for the Bridge to respond in a # more sensible manner other than being `nil`. The WebDialog is recreated # right before the window is displayed due to a SketchUp bug. @@ -77,12 +89,25 @@ def initialize( options = {} ) @bridge = Bridge.new( self, @webdialog ) end + # Adds the given JavaScript. This allow custom solutions outside of SKUI's + # Ruby class wrappers. + # + # @return [Nil] + # @since 1.0.0 + def add_script(script_file) + unless File.exist?(script_file) + raise ArgumentError, "File not found: #{script_file}" + end + @scripts << script_file + nil + end + # Returns an array with the width and height of the client area. # # @return [Array(Integer,Integer)] # @since 1.0.0 def client_size - @bridge.call( 'Webdialog.get_client_size' ) + @bridge.call( 'WebDialog.get_client_size' ) end # Adjusts the window so the client area fits the given +width+ and +height+. @@ -99,7 +124,7 @@ def client_size=( value ) end # (!) Cache size difference. @webdialog.set_size( width, height ) - client_width, client_height = get_client_size() + client_width, client_height = client_size() adjust_width = width - client_width adjust_height = height - client_height unless adjust_width == 0 && adjust_height == 0 @@ -187,6 +212,16 @@ def title @options[:title].dup end + # @return [Nil] + # @since 1.0.0 + def toggle + if visible? + close() + else + show() + end + end + # @return [Boolean] # @since 1.0.0 def visible? @@ -276,6 +311,8 @@ def callback_handler( webdialog, params ) event_open_url( arguments[0] ) when 'SKUI::Window.on_ready' event_window_ready( webdialog ) + when 'SKUI::Window.on_script_loaded' + event_script_loaded( arguments[0] ) end ensure # Inform the Webdialog the message was received so it can process any @@ -293,6 +330,10 @@ def callback_handler( webdialog, params ) def event_window_ready( webdialog ) Debug.puts( '>> Dialog Ready' ) @bridge.call( 'Bridge.set_window_id', ui_id ) + unless @scripts.empty? + @loaded_scripts.clear + @bridge.call( 'WebDialog.add_scripts', @scripts ) + end update_properties( *@properties.keys ) @bridge.add_container( self ) trigger_event( :ready ) @@ -327,6 +368,20 @@ def event_open_url( url ) nil end + + # @param [String] script + # + # @return [Nil] + # @since 1.0.0 + def event_script_loaded( script ) + #Debug.puts( "SKUI::Window.event_script_loaded(#{script})" ) + @loaded_scripts << script + if @loaded_scripts.sort == @scripts.sort + trigger_event( :scripts_loaded ) + end + nil + end + # @â—‹param [Hash] options Same as #initialize # # @return [UI::WebDialog] @@ -355,6 +410,28 @@ def init_webdialog( options ) # Ensure the size for fixed windows is set - otherwise SketchUp will use # the last saved properties. unless options[:resizable] + # OSX has a bug where it ignores the resize flag and let the user resize + # the window. Setting the min and max values for width and height works + # around this issue. + # + # To make things worse, OSX sets the client size with the min/max + # methods - causing the window to grow if you set the min size to the + # desired target size. To account for this we set the min sizes to be + # a little less that the desired width. The size should be larger than + # the titlebar height. + # + # All this has to be done before we set the size in order to restore the + # desired size because the min/max methods will transpose the external + # size to content size. + # + # The result is that the height is adjustable a little bit, but at least + # it's restrained to be close to the desired size. Lesser evil until + # this is fixed in SketchUp. + webdialog.min_width = options[:width] + webdialog.max_width = options[:width] + webdialog.min_height = options[:height] - 30 + webdialog.max_height = options[:height] + webdialog.set_size( options[:width], options[:height] ) end # Limit the size of the window. The limits can be either an Integer for @@ -385,6 +462,10 @@ def init_webdialog( options ) # then the WebDialog instance will not GC. Call a wrapper that # prevents this. add_callback( webdialog, 'SKUI_Callback', :callback_handler ) + # Hook up events to capture when the window closes. + webdialog.set_on_close { + trigger_event( :close ) + } # (i) There appear to be differences between OS when the HTML content # is prepared. OSX loads HTML on #set_file? Inspect this. html_file = File.join( PATH_HTML, 'window.html' ) @@ -393,4 +474,4 @@ def init_webdialog( options ) end end # class -end # module \ No newline at end of file +end # module diff --git a/src/sketchup-stl/css/base.css b/src/sketchup-stl/css/base.css index f67f96d..f6af146 100644 --- a/src/sketchup-stl/css/base.css +++ b/src/sketchup-stl/css/base.css @@ -19,6 +19,7 @@ body { */ html, input, textarea, select, button { font: caption; /* Use native UI fonts */ + font-size: 9pt; } @@ -36,4 +37,4 @@ html { button { width: 80px; height: 25px; -} \ No newline at end of file +} diff --git a/src/sketchup-stl/exporter.rb b/src/sketchup-stl/exporter.rb index 8186175..903f0b6 100644 --- a/src/sketchup-stl/exporter.rb +++ b/src/sketchup-stl/exporter.rb @@ -44,7 +44,7 @@ def self.select_export_file end def self.export(path, options = OPTIONS) - file = File.new(path , 'w') + file = File.new(path , 'w') if options['stl_format'] == STL_BINARY file.binmode @write_face = method(:write_face_binary) @@ -66,7 +66,7 @@ def self.find_faces(file, entities, scale, tform) face_count = 0 entities.each do |entity| if entity.is_a?(Sketchup::Face) - write_face(file, entity, scale, tform) + write_face(file, entity, scale, tform) face_count += 1 elsif entity.is_a?(Sketchup::Group) || entity.is_a?(Sketchup::ComponentInstance) diff --git a/src/sketchup-stl/html/importer.html b/src/sketchup-stl/html/importer.html index 8834f47..4d53ba4 100644 --- a/src/sketchup-stl/html/importer.html +++ b/src/sketchup-stl/html/importer.html @@ -2,7 +2,7 @@ Import STL Options - + @@ -18,7 +18,7 @@
Geometry - +