 noflo = require 'noflo'
 Gtk = imports.gi.Gtk
 
-exports.getComponentForFile = (file) ->
+exports.getComponentForFile = (file, additionals) ->
 
   (metadata) ->
     c = new noflo.Component
 
+    c.shutdown = () ->
+      @started = false
+
     builder = new Gtk.Builder
-    objects = []
+    objects = {}
     error = null
     try
       Gtk.init null, null
       builder.add_from_file(file.get_path())
-      objects = builder.get_objects()
+      for object in builder.get_objects()
+        try
+          objects[object.get_name()] = object
+        catch e
+      if additionals
+        for objectName in additionals
+          object = builder.get_object(objectName)
+          objects[objectName] = object if object
     catch e
       error = e
 

      datatype: 'object'
      required: no

    for obj in objects
      name = obj.get_name().replace /[^A-Za-z0-9_]/g, ''
      c.outPorts.add name,
        datatype: 'object'
        required: no
      c.outPorts[name].object = obj
    c

      datatype: 'bang'
      process: (event, payload) ->
        return unless event is 'data'
        c.started = true
        if error?
          c.outPorts.error.send error
          c.outPorts.error.disconnect()
        else
          for portName, port  of c.outPorts.ports
            continue if portName is 'error'
            #log "Sending #{port.object} on #{portName}"
            port.send port.object
            port.disconnect()

