--- auto_nodetitle.module.orig	2008-12-09 12:10:51.000000000 -0200
+++ auto_nodetitle.module	2008-12-09 12:10:14.000000000 -0200
@@ -10,6 +10,9 @@ define('AUTO_NODETITLE_DISABLED', 0);
 define('AUTO_NODETITLE_ENABLED', 1);
 define('AUTO_NODETITLE_OPTIONAL', 2);
 
+define('AUTO_NODETITLE_PRESERVE_TITLE_DISABLED', 0);
+define('AUTO_NODETITLE_PRESERVE_TITLE_ENABLED', 1);
+
 /**
  * Implementation of hook_perm()
  */
@@ -29,9 +32,14 @@ function auto_nodetitle_form_alter($form
     //this is a node form    
     if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_ENABLED) {
       // we will autogenerate the title later, just hide the title field in the meanwhile
-      $form['title']['#value'] = 'ant';
+      $preserve_title = auto_nodetitle_get_preserve_setting($form['#node']->type);
+      if (!isset($form['#node']->nid) || ($form['#node']->nid && $preserve_title == AUTO_NODETITLE_PRESERVE_TITLE_DISABLED)) {
+        $form['title']['#value'] = 'ant';
+      }  
+        
       $form['title']['#type'] = 'value';
       $form['title']['#required'] = FALSE;
+      
     }
     else if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_OPTIONAL) {
       // we will make the title optional
@@ -45,17 +53,22 @@ function auto_nodetitle_form_alter($form
  */
 function auto_nodetitle_nodeapi(&$node, $op, $form = NULL, $a4 = NULL) {
   if ($op == 'validate') {
-    if ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_ENABLED) || ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_OPTIONAL) && empty($node->title))) {
-      /*
-       * Sets the node title.
-       * We need to do this on validation because of two points: 
-       *     It's early engouh to have node previews working and 
-       *     it's late enough as CCK has already gone through the 'process form values' step 
-       * 
-       * As changes to $node are not persistent during validation, we use form_set_value()!
-       */
-      auto_nodetitle_set_title($node);
-      form_set_value($form['title'], $node->title);
+    if (auto_nodetitle_get_preserve_setting($node->type) == AUTO_NODETITLE_PRESERVE_TITLE_ENABLED && !empty($node->title) && $node->title != 'ant') {
+      // Preserve node title
+    }
+    else {
+      if ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_ENABLED) || ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_OPTIONAL) && empty($node->title))) {
+          /*
+           * Sets the node title.
+           * We need to do this on validation because of two points: 
+           *     It's early engouh to have node previews working and 
+           *     it's late enough as CCK has already gone through the 'process form values' step 
+           * 
+           * As changes to $node are not persistent during validation, we use form_set_value()!
+           */
+          auto_nodetitle_set_title($node);
+          form_set_value($form['title'], $node->title);
+      }
     }
   }
 }
@@ -126,7 +139,18 @@ function auto_nodetitle_node_settings_fo
       t('Automatically generate the title if the title field is left empty'),
     )
   );
-
+  $form['auto_nodetitle']['preserve'] = array(
+    '#type' => 'radios',
+    '#default_value' => auto_nodetitle_get_preserve_setting($form['#node_type']->type),
+    '#title' => t('Preserve title'),
+    '#options' => array(
+      t('No'),
+      t('Yes'),
+    ),
+    '#description' => t('Prevent title from changing when the node is edited'),
+  );
+  
+  
   if (module_exists('token') || user_access('use PHP for title patterns')) {
     
     $description = t('Leave blank for using the per default generated title. Otherwise this string will be used as title.');
@@ -176,3 +200,10 @@ function auto_nodetitle_node_settings_fo
 function auto_nodetitle_get_setting($type) {
   return variable_get('ant_'. $type, AUTO_NODETITLE_DISABLED);
 }
+
+/**
+ * Gets the auto node title overwrite setting associated with the given content type. 
+ */ 
+function auto_nodetitle_get_preserve_setting($type) {
+  return variable_get('preserve_'. $type, AUTO_NODETITLE_PRESERVE_TITLE_DISABLED);
+}
\ No newline at end of file
