? 940336.patch
Index: plugins/sweaver_plugin_editor/sweaver_plugin_editor.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sweaver/plugins/sweaver_plugin_editor/sweaver_plugin_editor.js,v
retrieving revision 1.1.2.54
diff -u -p -r1.1.2.54 sweaver_plugin_editor.js
--- plugins/sweaver_plugin_editor/sweaver_plugin_editor.js	14 Oct 2010 08:05:58 -0000	1.1.2.54
+++ plugins/sweaver_plugin_editor/sweaver_plugin_editor.js	14 Oct 2010 15:27:36 -0000
@@ -335,7 +335,7 @@ Drupal.Sweaver.bindClicks = function() {
 
   // When an element is hovered, add a class 'sweaver-hovered'.
   if (Drupal.settings.sweaver['preview_selector']) {
-    /*tempSelectors
+    tempSelectors
     .bind('mouseenter', function(event){
       // Only do something when the content area is visible.
       if (Drupal.Sweaver.visible()) {
@@ -378,7 +378,7 @@ Drupal.Sweaver.bindClicks = function() {
           tempObject.addClass('sweaver-hovered');
         }
       }
-    });*/
+    });
   }
 
   // When an element is clicked, add a class and build the entire path.
@@ -407,7 +407,7 @@ Drupal.Sweaver.bindClicks = function() {
        // If the clicked object is a button prevent default behavior.
        if(object.tag == 'input' || object.tag == 'label') {
          event.preventDefault();
-       }    
+       }
 
       // Don't do anything if the clicked object is the 'follow-link' link.
       if (object.id != 'follow-link') {
@@ -808,12 +808,12 @@ Drupal.Sweaver.objectToReadable = functi
   var id_translation = new Array();
   var class_translation = new Array();
   var tag_translation = new Array();
-  
-  var css = new Array();  
+
+  var css = new Array();
   var id_css = new Array();
   var class_css = new Array();
   var tag_css = new Array();
-    
+
   var selector = '';
   var description = '';
   var tempSelectors = new Array();
@@ -831,7 +831,7 @@ Drupal.Sweaver.objectToReadable = functi
         id_translation[i] = 'the ' + object.id + ' region';
         id_css[i] = '#' + object.id;
         tempSelectors.push('#' + object.id);
-        i++;          
+        i++;
       }
     }
     else if (name == 'allclasses') {
@@ -841,7 +841,7 @@ Drupal.Sweaver.objectToReadable = functi
             class_translation[i] = 'all ' + tempClass;
             class_css[i] = '.' + tempClass;
             tempSelectors.push('.' + tempClass);
-            i++;            
+            i++;
           }
         });
       }
@@ -850,26 +850,26 @@ Drupal.Sweaver.objectToReadable = functi
       tag_translation[i] = object.tag;
       tag_css[i] = object.tag;
       tempSelectors.push(object.tag);
-      i++;      
+      i++;
     }
     else {
       if (selector == '#' + object.id && $.inArray('#' + object.id, tempSelectors) < 0) {
         id_translation[i] = description;
         id_css[i] = '#' + object.id;
         tempSelectors.push('#' + object.id);
-        i++;        
+        i++;
       } else if (selector == object.tag && $.inArray(object.tag, tempSelectors) < 0) {
         tag_translation[i] = description;
         tag_css[i] = object.tag;
         tempSelectors.push(object.tag);
-        i++;        
+        i++;
       } else {
         $.each(object.classes, function(index, tempClass) {
           if (selector == '.' + tempClass  && $.inArray(tempClass, Drupal.Sweaver.excludeClasses) < 0 && $.inArray('.' + tempClass, tempSelectors) < 0) {
             class_translation[i] = description;
             class_css[i] = '.' + tempClass;
             tempSelectors.push('.' + tempClass);
-            i++;            
+            i++;
           }
         });
       }
@@ -886,7 +886,7 @@ Drupal.Sweaver.objectToReadable = functi
   for (var j = 0; j < i; j++) {
     var k = id_css[j] ? id_css[j] : class_css[j] ? class_css[j] : tag_css[j];
     css[j] = k;
-  } 
+  }
 
   if (Drupal.settings.sweaver['combined_selectors']) {
 	  // Add combinations of classes, ids and tags.
@@ -904,11 +904,11 @@ Drupal.Sweaver.objectToReadable = functi
 		      $.each(class_translation, function(index, trans) {
 		        if (trans) {
 		          translation[t] = tag + ' + ' + trans;
-              css[t] = tag + class_css[index];		          
+              css[t] = tag + class_css[index];
 		          t++;
 		        }
-		      });	 
-		    }   
+		      });
+		    }
 		  });
 	  }
   }
Index: plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sweaver/plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc,v
retrieving revision 1.1.2.60
diff -u -p -r1.1.2.60 sweaver_plugin_styles.inc
--- plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc	12 Oct 2010 12:42:22 -0000	1.1.2.60
+++ plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc	14 Oct 2010 15:27:36 -0000
@@ -478,8 +478,12 @@ class sweaver_plugin_styles extends swea
 
     // Remove files tied to theme.
     $dir = file_directory_path() .'/sweaver';
+    // Get files with id.
     $mask = '(.*)'. $style->theme .'_'. $style->style_id .'_(.*)';
     $files = file_scan_directory($dir, $mask);
+    // Get temp files.
+    $mask = '(.*)'. $style->theme .'_temp_(.*)';
+    $files += file_scan_directory($dir, $mask);
     foreach ($files as $key => $file) {
       file_delete($file->filename);
     }
@@ -607,6 +611,8 @@ class sweaver_plugin_styles extends swea
     $GLOBALS['conf']['cache'] = FALSE;
     // Prevent Devel from hi-jacking our output in any case.
     $GLOBALS['devel_shutdown'] = FALSE;
+    // Load CTools object cache.
+    ctools_include('object-cache');
 
     // Save current styling.
     $style = new stdClass;
@@ -614,22 +620,16 @@ class sweaver_plugin_styles extends swea
     $style->style = t('Temporary');
     $style->css = $_POST['css'];
     $style->customcss = $_POST['customcss'];
-    $style->themesettings = '';
 
     // Get the themesettings if applicable and overwrite style id & style name.
-    if (sweaver_session(NULL, 'draft_mode')) {
-      $table = (sweaver_session(NULL, 'loaded_table') == 'live') ? 'sweaver_style' : 'sweaver_style_draft';
-      $original = db_fetch_object(db_query("SELECT style_id, style, theme, themesettings FROM {". $table ."} where style_id = %d", sweaver_session(NULL, 'loaded_style')));
-      if (isset($original->style_id)) {
-        $style->style_id = $original->style_id;
-        $style->style = $original->style;
-        $style->theme = $original->theme;
-        $style->themesettings = $style->themesettings;
-      }
+    $sweaver = Sweaver::get_instance();
+    $working_style = $sweaver->get_current_style();
+    if (isset($working_style->themesettings)) {
+      $style->theme = $working_style->theme;
+      $style->themesettings = $working_style->themesettings;
     }
 
     // Save to CTools object cache.
-    ctools_include('object-cache');
     ctools_object_cache_set('sweaver-styling', 'sweaver-styling', $style);
 
     // Set session variable.
Index: plugins/sweaver_plugin_themesettings/sweaver_plugin_themesettings.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sweaver/plugins/sweaver_plugin_themesettings/sweaver_plugin_themesettings.inc,v
retrieving revision 1.1.2.27
diff -u -p -r1.1.2.27 sweaver_plugin_themesettings.inc
--- plugins/sweaver_plugin_themesettings/sweaver_plugin_themesettings.inc	30 Sep 2010 13:54:03 -0000	1.1.2.27
+++ plugins/sweaver_plugin_themesettings/sweaver_plugin_themesettings.inc	14 Oct 2010 15:27:37 -0000
@@ -12,7 +12,7 @@ class sweaver_plugin_themesettings exten
    */
   public function sweaver_init() {
     // Override theme settings in $conf variable when in Draft.
-    if (sweaver_session(NULL, 'draft_mode')) {
+    if (sweaver_session(NULL, 'draft_mode') || sweaver_session(NULL, 'sweaver_temp')) {
       $sweaver = Sweaver::get_instance();
       $sweaver_style = $sweaver->get_current_style();
       if (isset($sweaver_style->themesettings) && !empty($sweaver_style->themesettings)) {
@@ -92,9 +92,13 @@ class sweaver_plugin_themesettings exten
       }
     }
 
-    // Deny access to the buttons for now, theme settings are
-    // now also saved via the save style tab.
+    // Deny access to the buttons and add our own.
     $form['buttons']['#access'] = FALSE;
+    $form['theme_settings_apply'] = array(
+      '#type' => 'submit',
+      '#value' => t('Apply theme settings'),
+      '#prefix' => '<div class="clear-block"></div>',
+    );
 
     return $form;
   }
@@ -109,9 +113,10 @@ class sweaver_plugin_themesettings exten
     $clicked_button = $form_state['clicked_button']['#value'];
 
     // Save style.
-    if (($clicked_button == t('Save and continue') || $clicked_button == t('Save and publish') || $clicked_button == t('Publish style')) && isset($form_state['style_id'])) {
+    if ($clicked_button == t('Save and continue') || $clicked_button == t('Save and publish') || $clicked_button == t('Publish style') || $clicked_button == t('Apply theme settings')) {
 
-      $style_id = $form_state['style_id'];
+      // Style id is not always set.
+      $style_id = isset($form_state['style_id']) ? $form_state['style_id'] : 'temp';
 
       // General theme settings.
       $theme_values = array();
@@ -148,20 +153,32 @@ class sweaver_plugin_themesettings exten
       // Rename logo / favicon when needed.
       foreach (array('logo_path', 'favicon_path') as $file) {
 
+        $type = str_replace('_path', '', $file);
+        $theme_name = $form['#current_theme'];
+
         // Rename when just uploaded.
         if (isset($form['sweaver_plugin_themesettings']['form']['#'. $file])) {
-          $type = str_replace('_path', '', $file);
-          $theme_name = $form['#current_theme'];
           $source_path = file_directory_path() .'/'. $form['sweaver_plugin_themesettings']['form']['#'. $file];
           $dest_draft = 'sweaver/'. $type .'_'. $theme_name .'_'. $style_id .'_draft.'. $form['sweaver_plugin_themesettings']['form']['#'. $file .'_extension'];
           file_move($source_path, $dest_draft, FILE_EXISTS_REPLACE);
           $theme_values[$file] = file_directory_path() .'/'. $dest_draft;
         }
 
+        // Create the default variable for this file.
+        $default = 'default_'. str_replace('_path', '', $file);
+
+        // Move temporary if needed.
+        if ($style_id != 'temp' && !$theme_values[$default] && !empty($theme_values[$file]) && strpos($theme_values[$file], 'temp_draft') !== FALSE) {
+          $parts = pathinfo($theme_values[$file]);
+          $temp_path = $theme_values[$file];
+          $dest_draft = 'sweaver/'. $type .'_'. $theme_name .'_'. $style_id .'_draft.'. $parts['extension'];
+          file_move($temp_path, $dest_draft, FILE_EXISTS_REPLACE);
+          $theme_values[$file] = file_directory_path() .'/'. $dest_draft;
+        }
+
         // Copy to live if save_live is found. Can either be directly after the upload
         // or when setting a style live after the uploads were done already.
-        $default = 'default_'. str_replace('_path', '', $file);
-        if ($form_state['publish'] && !$theme_values[$default] && !empty($theme_values[$file])) {
+        if (isset($form_state['publish']) && $form_state['publish'] && !$theme_values[$default] && !empty($theme_values[$file])) {
           $source_path = $theme_values[$file];
           $dest_live = str_replace('_draft', '_live', $theme_values[$file]);
           file_copy($source_path, $dest_live, FILE_EXISTS_REPLACE);
@@ -169,22 +186,41 @@ class sweaver_plugin_themesettings exten
         }
       }
 
-      // And finally save. Always save the draft version. If the
+      // Save when style_id is found. Always save the draft version. If the
       // save_live key is found also update the live table.
-      $theme_values_serialized = serialize($theme_values);
-      db_query("UPDATE {sweaver_style_draft} set themesettings = '%s' WHERE style_id = %d", $theme_values_serialized, $style_id);
-      if ($form_state['publish']) {
-        variable_set($theme_key, $theme_values);
-        db_query("UPDATE {sweaver_style} set themesettings = '%s' WHERE style_id = %d", $theme_values_serialized, $style_id);
-      }
+      if ($style_id != 'temp') {
+        $theme_values_serialized = serialize($theme_values);
+        db_query("UPDATE {sweaver_style_draft} set themesettings = '%s' WHERE style_id = %d", $theme_values_serialized, $style_id);
+        if ($form_state['publish']) {
+          variable_set($theme_key, $theme_values);
+          db_query("UPDATE {sweaver_style} set themesettings = '%s' WHERE style_id = %d", $theme_values_serialized, $style_id);
+        }
 
-      // Fire other submit functions on the theme settings form.
-      $submit_handlers = isset($form['sweaver_plugin_themesettings']['form']['#submit']) ? $form['sweaver_plugin_themesettings']['form']['#submit'] : array();
-      foreach ($submit_handlers as $key => $function) {
-        if (function_exists($function)) {
-          $function($form['sweaver_plugin_themesettings']['form'], $form_state);
+        // Fire other submit functions on the theme settings form.
+        $submit_handlers = isset($form['sweaver_plugin_themesettings']['form']['#submit']) ? $form['sweaver_plugin_themesettings']['form']['#submit'] : array();
+        foreach ($submit_handlers as $key => $function) {
+          if (function_exists($function)) {
+            $function($form['sweaver_plugin_themesettings']['form'], $form_state);
+          }
         }
       }
+      else {
+        // Save to CTools object cache.
+        $sweaver = Sweaver::get_instance();
+        ctools_include('object-cache');
+        $style = $sweaver->get_current_style();
+        if (!isset($style->style_id)) {
+          $style = new stdClass;
+          $style->style_id = 0;
+          $style->style = t('Temporary');
+          $style->css = '';
+          $style->customcss = '';
+        }
+        $style->themesettings = serialize($theme_values);
+        ctools_object_cache_set('sweaver-styling', 'sweaver-styling', $style);
+        sweaver_session(t('The theme settings have been applied.'));
+        sweaver_session(TRUE, 'sweaver_temp');
+      }
     }
 
     // Delete style.
@@ -195,14 +231,6 @@ class sweaver_plugin_themesettings exten
       if ($form_state['style_active']) {
         variable_del($theme_key);
       }
-
-      // Remove files.
-      $dir = file_directory_path() .'/sweaver';
-      $mask = '(.*)'. $style->theme .'_'. $style->style_id .'_(.*)';
-      $files = file_scan_directory($dir, $mask);
-      foreach ($files as $key => $file) {
-        file_delete($file->filename);
-      }
     }
   }
 
