Here's a version cleaned up and made into a Mixin module.
Added Class Variables declarations:
# CLASS VARIABLES
@@relative_instructor_path = ''
@@temp_instructor_folder = false
@@tool_filepath = '' # must be redefined in the Tool class for rbs files
Added method definitions:
public
def relative_instructor_path
return @@relative_instructor_path
end
def temp_instructor_folder
return @@temp_instructor_folder
end
private
# initialize()
#
# Likely to be redefined in the Tool class definition.
# We define it here just in case the Tool author does not.
#
def initialize
help_setup()
end
# help_setup( instructor_folder=false, temp_folder=false )
#
# Sets up and inits some instance variables used for
# the tool's Instructor help system.
#
# ** Must be called by the Tool's initialize() method. **
#
def help_setup(instructor_folder=false, temp_folder=false)
#
if @@tool_filepath.empty?
if __FILE__ != '(eval)' && File.exist?(File.expand_path(__FILE__))
@@tool_filepath = __FILE__
else
raise(ScriptError,"#{self.class.name}; @@tool_filepath class variable error. @@tool_filepath must be declared for rbs files!")
end
else
unless File.exist?(File.expand_path(@@tool_filepath))
raise(ScriptError,"#{self.class.name}; @@tool_filepath class variable error. File '#{@@tool_filepath}' does not exist!")
end
end
#
if instructor_folder
@instructor_folder = instructor_folder
else
@instructor_folder = getDefaultInstructorFolder()
end
if temp_folder
@temp_folder = temp_folder
elsif RUBY_PLATFORM =~ /darwin/i # on a Mac
@temp_folder = @instructor_folder
else
@temp_folder = getDefaultTempFolder()
end
#
@@relative_instructor_path = returnRelativePath()
#
end #def help_setup()
and:
# getInstructorContentDirectory()
#
# Callback for tool to give Sketchup the relative path
# to the tool's help directory.
#
def getInstructorContentDirectory
unless @@temp_instructor_folder
# copy help files
copyInstructor()
@@temp_instructor_folder = returnTempInstructorFolderName()
end
return @@relative_instructor_path
end #def
I did not make any changes to the "engine" methods, except:
getDefaultInstructorFolder()
changed all __FILE__ to @@tool_filepath
returnTempInstructorFolderName()
inserted a 'short circuit' as the first line, for Macs
return @temp_folder if @temp_folder == @instructor_folder
File Removed - Get the latest version in Niall's [ code ] topic:
[ code ] Load Instructor
I also wonder if there should be an AppObserver instance that deletes the temp/instructor file at the end of the session ??