<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>src/Contents/Resources/TEAGenericAction.py</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -26,6 +26,7 @@ THE SOFTWARE.
 '''
 
 # Import our main action classes so that Espresso can find them
+import TEAGenericAction
 import TEAforEspresso
 import TEALoader
 import TEASpacesToTabs</diff>
      <filename>main.py</filename>
    </modified>
    <modified>
      <diff>@@ -10,21 +10,20 @@ import os
 from Foundation import *
 import objc
 
+from TEAGenericAction import TEAGenericAction
 import tea_actions as tea
-from espresso import *
 
-# This really shouldn't be necessary thanks to the Foundation import
-# but for some reason the plugin dies without it
-NSObject = objc.lookUpClass('NSObject')
-
-class TEALoader(NSObject):
+class TEALoader(TEAGenericAction):
     '''
     Determines what info is necessary and feeds it to external scripts,
     then inserts their return value into the Espresso document
     '''
     def initWithDictionary_bundlePath_(self, dictionary, bundlePath):
         '''Required by Espresso; initializes the plugin settings'''
-        self = super(TEALoader, self).init()
+        # Call the generic action's init method
+        self = super(TEALoader, self).initWithDictionary_bundlePath_(
+            dictionary, bundlePath
+        )
         if self is None: return None
         
         # Set object's internal variables
@@ -34,32 +33,8 @@ class TEALoader(NSObject):
         self.output = dictionary['output'] if 'output' in dictionary else None
         self.undo = dictionary['undo_name'] if 'undo_name' in dictionary else None
         
-        # Set the syntax context
-        self.syntax_context = dictionary['syntax-context'] \
-                              if 'syntax-context' in dictionary else None
-        
-        # By looking up the bundle, third party sugars can call
-        # TEA for Espresso actions or include their own custom actions
-        self.bundle_path = bundlePath
-        
         return self
     
-    # Signature is necessary for Objective-C to be able to find the method
-    @objc.signature('B@:@')
-    def canPerformActionWithContext_(self, context):
-        '''Returns bool; can the action be performed in the given context'''
-        if self.syntax_context is not None:
-            ranges = context.selectedRanges()
-            range = ranges[0].rangeValue()
-            selectors = SXSelectorGroup.selectorGroupWithString_(self.syntax_context)
-            zone = context.syntaxTree().rootZone().zoneAtCharacterIndex_(range.location)
-            if selectors.matches_(zone):
-                return True
-            else:
-                return False
-        else:
-            return True
-    
     @objc.signature('B@:@@')
     def performActionWithContext_error_(self, context, error):
         '''
@@ -203,7 +178,7 @@ class TEALoader(NSObject):
                     )
             # Log errors
             if error:
-                tea.log(str(error))
+                tea.log(error)
             # Process the output
             output = output.decode('utf-8')
             if self.output == 'document' or \</diff>
      <filename>src/Contents/Resources/TEALoader.py</filename>
    </modified>
    <modified>
      <diff>@@ -6,10 +6,10 @@ actions that use the TEA act() method
 from Foundation import *
 import objc
 
+from TEAGenericAction import TEAGenericAction
 from tea_utils import *
-from espresso import *
 
-class TEAforEspresso(NSObject):
+class TEAforEspresso(TEAGenericAction):
     '''
     Performs initialization and is responsible for loading and calling
     the various external actions when the plugin is invoked
@@ -19,7 +19,10 @@ class TEAforEspresso(NSObject):
     
     def initWithDictionary_bundlePath_(self, dictionary, bundlePath):
         '''Required by Espresso; initializes the plugin settings'''
-        self = super(TEAforEspresso, self).init()
+        # Call the generic action's init method
+        self = super(TEAforEspresso, self).initWithDictionary_bundlePath_(
+            dictionary, bundlePath
+        )
         if self is None: return None
         
         # Set object's internal variables
@@ -28,41 +31,26 @@ class TEAforEspresso(NSObject):
             # backwards compatible fix
             self.action = dictionary['target_action']
         else:
-            self.action = dictionary[&quot;action&quot;]
+            self.action = dictionary['action'] if 'action' in dictionary else \
+                          None
         
         # options is an optional dictionary with named extra arguments
         # for the act() call
         if 'arguments' in dictionary:
             # backwards compatible fix
             dictionary['options'] = dictionary['arguments']
-        if &quot;options&quot; in dictionary:
+        if 'options' in dictionary:
             # In order to pass dictionary as keyword arguments it has to:
             # 1) be a Python dictionary
             # 2) have the key encoded as a string
             # This dictionary comprehension takes care of both issues
             self.options = dict(
                 [str(arg), value] \
-                for arg, value in dictionary[&quot;options&quot;].iteritems()
+                for arg, value in dictionary['options'].iteritems()
             )
         else:
             self.options = None
         
-        # Set the syntax context
-        if 'syntax-context' in dictionary:
-            self.syntax_context = dictionary['syntax-context']
-        else:
-            self.syntax_context = None
-        
-        # By looking up the bundle, third party sugars can call
-        # TEA for Espresso actions or include their own custom actions
-        self.bundle_path = bundlePath
-        self.tea_bundle = NSBundle.bundleWithIdentifier_('com.onecrayon.tea.espresso').\
-                          bundlePath()
-        if self.bundle_path == self.tea_bundle:
-            self.search_paths = [self.bundle_path]
-        else:
-            self.search_paths = [self.bundle_path, self.tea_bundle]
-        
         # Run one-time initialization items
         if not TEAforEspresso.initialized:
             TEAforEspresso.initialized = True
@@ -72,37 +60,13 @@ class TEAforEspresso(NSObject):
             defaults.registerDefaults_(NSDictionary.dictionaryWithContentsOfFile_(
                 bundle.pathForResource_ofType_('Defaults', 'plist')
             ))
-            refresh_symlinks(self.tea_bundle)
+            refresh_symlinks(self.tea_path)
         return self
     
-    # Signature is necessary for Objective-C to be able to find the method
-    @objc.signature('B@:@')
-    def canPerformActionWithContext_(self, context):
-        '''Returns bool; can the action be performed in the given context'''
-        # Possible for context to be empty if it's partially initialized
-        if context.string() is None:
-            return False
-        if self.syntax_context is not None:
-            ranges = context.selectedRanges()
-            range = ranges[0].rangeValue()
-            selectors = SXSelectorGroup.selectorGroupWithString_(self.syntax_context)
-            if context.string().length() == range.location:
-                zone = context.syntaxTree().rootZone()
-            else:
-                zone = context.syntaxTree().rootZone().zoneAtCharacterIndex_(
-                    range.location
-                )
-            if selectors.matches_(zone):
-                return True
-            else:
-                return False
-        else:
-            return True
-    
     @objc.signature('B@:@@')
     def performActionWithContext_error_(self, context, error):
         '''Imports and calls the action's act() method'''
-        target_module = load_action(self.action, *self.search_paths)
+        target_module = load_action(self.action, *self.root_paths)
         if target_module is None:
             # Couldn't find the module, log the error
             NSLog('TEA: Could not find the module ' + self.action)</diff>
      <filename>src/Contents/Resources/TEAforEspresso.py</filename>
    </modified>
    <modified>
      <diff>@@ -22,17 +22,15 @@ def load_action(target, *roots):
     
     Usage: wrap_selection_in_tag = load_action('wrap_selection_in_tag')
     '''
-    paths = [
-        os.path.expanduser(
-            '~/Library/Application Support/Espresso/Support/Scripts/'
-        ),
-        os.path.expanduser(
-            '~/Library/Application Support/Espresso/TEA/Scripts/'
-        )
-    ]
-    for root in roots:
+    paths = []
+    for idx, root in enumerate(roots):
         paths.append(os.path.join(root, 'Support', 'Scripts'))
-        paths.append(os.path.join(root, 'TEA'))
+        if idx == 1:
+            # First item is always the user's folder, so for backwards
+            # compatibility we have to append TEA/Scripts
+            paths.append(os.path.join(root, 'TEA', 'Scripts'))
+        else:
+            paths.append(os.path.join(root, 'TEA'))
     try:
         # Is the action already loaded?
         module = sys.modules[target]</diff>
      <filename>src/Contents/Resources/tea_utils.py</filename>
    </modified>
    <modified>
      <diff>@@ -341,6 +341,7 @@
 		&lt;key-equivalent&gt;cmd control W&lt;/key-equivalent&gt;
 		&lt;setup&gt;
 			&lt;action&gt;selected_lines_to_snippets&lt;/action&gt;
+			&lt;selection-context&gt;one&lt;/selection-context&gt;
 			&lt;options&gt;
 				&lt;dict&gt;
 					&lt;key&gt;first_snippet&lt;/key&gt;
@@ -365,6 +366,7 @@
 		&lt;key-equivalent&gt;control L&lt;/key-equivalent&gt;
 		&lt;setup&gt;
 			&lt;action&gt;insert_url_snippet&lt;/action&gt;
+			&lt;selection-context&gt;one&lt;/selection-context&gt;
 			&lt;options&gt;
 				&lt;dict&gt;
 					&lt;key&gt;default&lt;/key&gt;</diff>
      <filename>src/TextActions/Actions.xml</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>50c50118bae28f222ff875d5850809633582c130</id>
    </parent>
  </parents>
  <author>
    <name>Ian Beck</name>
    <email>ian@onecrayon.com</email>
  </author>
  <url>http://github.com/onecrayon/tea-for-espresso/commit/2358de27c94fa2639f5841379160034e97a2a071</url>
  <id>2358de27c94fa2639f5841379160034e97a2a071</id>
  <committed-date>2009-08-24T19:31:13-07:00</committed-date>
  <authored-date>2009-08-24T19:31:13-07:00</authored-date>
  <message>Added selection-context (closes #46) and extracted common portions of TEA actions into a generic action class for subclassing</message>
  <tree>f48d291db3b95a1d1db08fd86353b2f5cafc5328</tree>
  <committer>
    <name>Ian Beck</name>
    <email>ian@onecrayon.com</email>
  </committer>
</commit>
