package org.python.pydev.compare;

import java.util.List;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.IViewerCreator;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.python.pydev.plugin.preferences.PydevPrefs;


/**
 * Required when creating a PyMergeViewer from the plugin.xml file.
 */
public class PyContentViewerCreator implements IViewerCreator {

	public Viewer createViewer(Composite parent, CompareConfiguration mp) {
		return new PyMergeViewer(parent, SWT.NULL, updatePreferenceStore(mp));
	}

	/**
	 * Creates a new configuration with the pydev preference store so that the colors appear correctly when using
	 * Aptana themes.
	 */
    private CompareConfiguration updatePreferenceStore(CompareConfiguration mp) {
        List<IPreferenceStore> stores = PydevPrefs.getDefaultStores(false);
        IPreferenceStore prefs = mp.getPreferenceStore();
        if(prefs != null){
            //Note, we could use the CompareUIPlugin.getDefault().getPreferenceStore() directly, but it's access
            //is restricted, so, we go to the preferences of the previously created compare configuration.
            stores.add(prefs);
        }
        return new CompareConfiguration(new ChainedPreferenceStore(stores.toArray(new IPreferenceStore[stores.size()])));
    }
}

@@ -682,37 +682,45 @@
 T.NULL, 
-updatePreferenceStore
+createNewCompareConfiguration
 (mp));%0A%09
@@ -864,30 +864,72 @@
 %0A%09 *
-/%0A    private C
+ %0A%09 * Also copies the available data from the original c
 ompare
-C
+ c
 onfi
@@ -941,29 +941,100 @@
 ion 
-updatePreferenceStore
+to the new coniguration.%0A%09 */%0A    private CompareConfiguration createNewCompareConfiguration
 (Com
@@ -1487,22 +1487,59 @@
         
-return
+%0A        %0A        CompareConfiguration cc =
  new Com
@@ -1638,16 +1638,539 @@
 ()%5D)));%0A
+        cc.setAncestorImage(mp.getAncestorImage(null));%0A        cc.setAncestorLabel(mp.getAncestorLabel(null));%0A        %0A        cc.setLeftImage(mp.getLeftImage(null));%0A        cc.setLeftLabel(mp.getLeftLabel(null));%0A        cc.setLeftEditable(mp.isLeftEditable());%0A        %0A        cc.setRightImage(mp.getRightImage(null));%0A        cc.setRightLabel(mp.getRightLabel(null));%0A        cc.setRightEditable(mp.isRightEditable());%0A        %0A        cc.setContainer(mp.getContainer());%0A        %0A        %0A        return cc;       %0A
     %7D%0A%7D%0A

Patch from frigo7: properly show the revision information in the compare editor / fix broken shortcuts (e.g.: ctrl+z) in compare editor.