# Copyright 2005, @Last Software, Inc.

# Permission to use, copy, modify, and distribute this software for 
# any purpose and without fee is hereby granted, provided that the above
# copyright notice appear in all copies.

# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#-----------------------------------------------------------------------------
# Name        :   Self Paced Tutorials Loader
# Description :   Adds menu items that allow the user to load installed
#                 SketchUp tutorial files.
# Menu Item   :   Help > Self Paced Tutorials > <filename>
# Context Menu:   N/A
# Usage       :   Select the file from the menu and that file is opened.
# Date        :   05/02/2002
# Type        :   Command
#-----------------------------------------------------------------------------
require 'sketchup.rb'

#load the script that hadlers the localaization methods
require 'LangHandler.rb'



if( not $self_paced_tutorials )
    $gsStrings = LanguageHandler.new("GettingStarted",true)

    mydir = File.dirname(__FILE__)

    tutorial_files = nil
    
	help_contents_dir = LanguageHandler::GetHelpContentDir() + "/SelfPacedTutorials";
    #tutorial_files = Sketchup.find_support_files("skp", help_contents_dir + "/SelfPacedTutorials");
    tutorial_entries = Dir.entries(help_contents_dir).sort;
	
	# remove those entries that aren't skp files
	tutorial_files = []
	tutorial_entries.each {|i| tutorial_files.push(i) if !File.stat(help_contents_dir + "/" + i).directory?}
    if(tutorial_files.length > 0)
        help_menu = UI.menu("Help")
        
        tutorials_menu = help_menu.add_submenu($gsStrings.GetString("Self-Paced Tutorials"))

        tutorial_files.each do | filename |
		    strDisplay = File.split(filename)[1]
		    
		    # strip out ugly parts of the file name
		    strDisplay = strDisplay.gsub("GoogleSketchUpSPT_", "")	  
		    strDisplay.gsub!(".skp", "")	  
		    
	        tutorials_menu.add_item(strDisplay) { 
				Sketchup.open_file(help_contents_dir + "/" + filename);
			}
        end
        
        tutorials_menu.add_separator
        
        tutorials_menu.add_item( $gsStrings.GetString("Get more tutorials") ) { UI::openURL($gsStrings.GetString("http://sketchup.google.com/gsu6/tutorials/sptutorials.html")) }
    
    end

    $self_paced_tutorials = true;
end    
