Index: nodetypetheme.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodetypetheme/nodetypetheme.admin.inc,v
retrieving revision 1.1
diff -u -r1.1 nodetypetheme.admin.inc
--- nodetypetheme.admin.inc	5 Jun 2009 14:42:19 -0000	1.1
+++ nodetypetheme.admin.inc	8 Sep 2010 11:20:09 -0000
@@ -9,27 +9,46 @@
 {
   $form = array();
   $themes = array(NODETYPETHEME_DEFAULT => '');
-  $themesinfo = list_themes();
-  $types = node_get_types('names');
-  
-  while($themeinfo = array_shift($themesinfo))
-  {
-  	$themes[$themeinfo->name] = $themeinfo->info['name'];
-  }
-  unset($themesinfo);
+  $themes += nodetypetheme_get_enabled_themes();
   asort($themes);
   $themes[NODETYPETHEME_DEFAULT] = t('System default');
-  
+
+  $types = node_get_types('names');
   foreach($types as $type => $name)
   {
-    $form['nodetypetheme_' . $type] = array(
+    $form['content_type'][$type]['nodetypetheme_' . $type] = array(
       '#title' => $name,
       '#type' => 'select',
       '#default_value' => nodetypetheme_get_theme($type),
       '#options' => $themes,
     );
+    $form['content_type'][$type]['nodetypetheme_use_on_edit_page_' . $type] = array(
+      '#title' => t('!type - use custom theme on edit page', array('!type' => $name)),
+      '#type' => 'checkbox',
+      '#default_value' => variable_get('nodetypetheme_use_on_edit_page_' . $type, FALSE),
+    );
   }
-  
-  return system_settings_form($form);
+
+  $form = system_settings_form($form);
+  unset($form['#theme']);
+
+  return $form;
 }
 
+/**
+ * List the themes which are currently enabled.
+ * 
+ * @return Array
+ * An array of theme names.
+ */
+function nodetypetheme_get_enabled_themes()
+{
+  $enabled_themes = array();
+  $themes = list_themes();
+  foreach($themes as $theme) {
+    if($theme->status) {
+      $enabled_themes[$theme->name] = $theme->info['name'];
+    }
+  }
+  return $enabled_themes;
+}
\ No newline at end of file
Index: nodetypetheme.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodetypetheme/nodetypetheme.module,v
retrieving revision 1.1
diff -u -r1.1 nodetypetheme.module
--- nodetypetheme.module	5 Jun 2009 14:42:19 -0000	1.1
+++ nodetypetheme.module	8 Sep 2010 11:20:10 -0000
@@ -3,6 +3,18 @@
 define('NODETYPETHEME_DEFAULT', 'default');
 
 /**
+ * Implementation of hook_enable
+ */
+function nodetypetheme_enable()
+{
+  // the module should always be weighted heavier than system
+  // (to ensure that system's "Use administration theme for content editing"
+  // setting can be overridden).
+  $system_weight = db_result(db_query("SELECT weight FROM system WHERE name='system' AND type='module'"));
+  db_query("UPDATE {system} SET weight=%d WHERE name='nodetypetheme' AND type='module'", ++$system_weight);
+}
+
+/**
  * Returns the theme specified for a node type, using variable_get().
  *
  * @param $type Node type
@@ -23,6 +35,10 @@
     case "admin/help#nodetypetheme":
       $output .= '<p>' . t("Allows administrators to set themes based on node types.") . '</p>';
       break;
+
+    case 'admin/settings/nodetypetheme':
+      $output .= '<p>' . t('Only themes which are enabled are available to select.  You can enable themes on the !theme_settings.', array('!theme_settings' => l('theme settings page', 'admin/build/themes'))) . '</p>';
+      break;
   }
   return $output;
 }
@@ -32,12 +48,20 @@
  */
 function nodetypetheme_init()
 {
-  if((variable_get('site_offline', 0) == 1 && !user_access('administer site configuration')) || arg(0) != 'node' || !is_numeric($nid = arg(1)) || arg(2)) return;
-  $node = node_load($nid);
-  $theme = nodetypetheme_get_theme($node->type);
-  if($theme == NODETYPETHEME_DEFAULT) return;
-  global $custom_theme;
-  $custom_theme = $theme;
+  if($node = menu_get_object()) {
+    $node_theme = nodetypetheme_get_theme($node->type);
+    if($node_theme != NODETYPETHEME_DEFAULT)
+    {
+      // use the custom theme on all 'view' pages,
+      // use the custom theme on the 'edit' page only if the override-flag is set.
+      $node_edit_page = (arg(2) == 'add' || arg(2) == 'edit');
+      if( (!$node_edit_page) || ($node_edit_page && variable_get('nodetypetheme_use_on_edit_page_' . $node->type, FALSE)))
+      {
+        global $custom_theme;
+        $custom_theme = $node_theme;
+      }
+    }
+  }
 }
 
 /**
@@ -66,3 +90,50 @@
   return array('administer node type theme');
 }
 
+/**
+ * Implementation of hook_theme
+ */
+function nodetypetheme_theme($existing, $type, $theme, $path){
+  if($type == 'module') {
+    return array(
+      'nodetypetheme_form' => array(
+        'arguments' => array('form' => array()),
+      )
+    );
+  }
+}
+
+/**
+ * Theme implementation for the nodetypetheme admin-form.
+ */
+function theme_nodetypetheme_form(&$form) {
+  
+  $headers = array(
+    t('Content-type'),
+    t('Custom theme'),
+    t('Use custom theme for node-edit pages'),
+  );
+
+  $rows = array();
+  foreach(element_children($form['content_type']) as $type)
+  {
+    $fields = $form['content_type'][$type];
+    // Use the table-headers instead of form field-titles.
+    unset($form['content_type'][$type]['nodetypetheme_' . $type]['#title'],
+          $form['content_type'][$type]['nodetypetheme_use_on_edit_page_' . $type]['#title']
+          );
+ 
+    $row = array(
+      $fields['nodetypetheme_' . $type]['#title'],
+      drupal_render($form['content_type'][$type]['nodetypetheme_' . $type]),
+      drupal_render($form['content_type'][$type]['nodetypetheme_use_on_edit_page_' . $type]),
+    );
+    $rows[] = $row;
+  }
+
+  $output = '';
+  $output .= theme('table', $headers, $rows);
+  $output .= drupal_render($form);
+
+  return $output;
+}
