[meld] Add and use New Comparison tab, replacing the existing New dialog



commit 59355129e52f08073b29bf3065934560a6b2b2bc
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Dec 3 14:23:19 2011 +1000

    Add and use New Comparison tab, replacing the existing New dialog
    
    The New Comparison tab provides a clear workflow that users can follow
    to start a comparison, hopefully without too much friction for power
    users.
    
    The more permissive approach of just providing three filechoosers and
    working things out from there might be preferrable, but shortcomings
    with GtkFileChooser (i.e., you can't select both files and directories
    from the same chooser) mean that it's not feasible.
    
    This implementation avoids one of the pitfalls of the existing dialog
    by requiring the user to click on file/folder/vc before browsing for
    files. While this does add an extra click in the file comparison case,
    it avoids having the user start to browse for a folder in a file
    selection dialog.
    
    In order to help users who just want a blank comparison, there is a
    button that opens a new tab of the selected type with no
    files/folders/etc. selected. Note that this currently doesn't work as
    intended for VC and directory comparisons.
    
    In addition, if we're not given anything to compare on startup, a
    New Comparison tab is now opened.
    
    Closes bgo#342701, bgo#349926, bgo#448658, and bgo#518179.

 data/ui/meldapp.ui      |  373 -----------------------------------
 data/ui/new-dialog.ui   |  498 +++++++++++++++++++++++++++++++++++++++++++++++
 meld/meldwindow.py      |  114 ++++-------
 meld/new_diff_dialog.py |  113 +++++++++++
 4 files changed, 653 insertions(+), 445 deletions(-)
---
diff --git a/data/ui/meldapp.ui b/data/ui/meldapp.ui
index e22856e..4972059 100644
--- a/data/ui/meldapp.ui
+++ b/data/ui/meldapp.ui
@@ -66,377 +66,4 @@ Josef VybÃral</property>
     <property name="translator-credits" translatable="yes">translator-credits</property>
     <property name="wrap_license">True</property>
   </object>
-  <object class="GtkDialog" id="newdialog">
-    <property name="visible">True</property>
-    <property name="title" translatable="yes">Choose Files</property>
-    <property name="default_width">600</property>
-    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
-    <signal handler="on_response" name="response"/>
-    <child internal-child="vbox">
-      <object class="GtkVBox" id="vbox">
-        <property name="visible">True</property>
-        <child>
-          <object class="GtkNotebook" id="type_notebook">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <child>
-              <object class="GtkTable" id="table1">
-                <property name="visible">True</property>
-                <property name="border_width">10</property>
-                <property name="n_rows">3</property>
-                <property name="n_columns">3</property>
-                <property name="column_spacing">10</property>
-                <property name="row_spacing">10</property>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <object class="GtkCheckButton" id="three_way_compare0">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="label" translatable="yes">_Three Way Compare</property>
-                    <property name="use_underline">True</property>
-                    <property name="draw_indicator">True</property>
-                    <signal handler="on_three_way_toggled" name="toggled"/>
-                  </object>
-                  <packing>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="HistoryFileEntry" id="fileentry2">
-                    <property name="visible">True</property>
-                    <property name="history-id">fileentry</property>
-                    <property name="directory-entry">False</property>
-                    <signal handler="on_entry_activate" name="activate"/>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="HistoryFileEntry" id="fileentry1">
-                    <property name="visible">True</property>
-                    <property name="history-id">fileentry</property>
-                    <property name="directory-entry">False</property>
-                    <signal handler="on_entry_activate" name="activate"/>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="HistoryFileEntry" id="fileentry0">
-                    <property name="visible">True</property>
-                    <property name="sensitive">False</property>
-                    <property name="history-id">fileentry</property>
-                    <property name="directory-entry">False</property>
-                    <signal handler="on_entry_activate" name="activate"/>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="label77">
-                    <property name="visible">True</property>
-                    <property name="xalign">1</property>
-                    <property name="xpad">5</property>
-                    <property name="ypad">5</property>
-                    <property name="label" translatable="yes" comments="Refers to version of the file being compared">Mine</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="label76">
-                    <property name="visible">True</property>
-                    <property name="xalign">1</property>
-                    <property name="xpad">5</property>
-                    <property name="ypad">5</property>
-                    <property name="label" translatable="yes" comments="Refers to version of the file being compared">Original</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="label75">
-                    <property name="visible">True</property>
-                    <property name="xalign">1</property>
-                    <property name="xpad">5</property>
-                    <property name="ypad">5</property>
-                    <property name="label" translatable="yes" comments="Refers to version of the file being compared">Other</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-              </object>
-            </child>
-            <child type="tab">
-              <object class="GtkLabel" id="tablabel0">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_File Comparison</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="tab_fill">False</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkTable" id="table2">
-                <property name="visible">True</property>
-                <property name="border_width">10</property>
-                <property name="n_rows">3</property>
-                <property name="n_columns">3</property>
-                <property name="column_spacing">10</property>
-                <property name="row_spacing">10</property>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <object class="GtkCheckButton" id="three_way_compare1">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="label" translatable="yes">_Three Way Compare</property>
-                    <property name="use_underline">True</property>
-                    <property name="draw_indicator">True</property>
-                    <signal handler="on_three_way_toggled" name="toggled"/>
-                  </object>
-                  <packing>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="HistoryFileEntry" id="direntry2">
-                    <property name="visible">True</property>
-                    <property name="history-id">direntry</property>
-                    <property name="directory-entry">True</property>
-                    <signal handler="on_entry_activate" name="activate"/>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="HistoryFileEntry" id="direntry1">
-                    <property name="visible">True</property>
-                    <property name="history-id">direntry</property>
-                    <property name="directory-entry">True</property>
-                    <signal handler="on_entry_activate" name="activate"/>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="HistoryFileEntry" id="direntry0">
-                    <property name="visible">True</property>
-                    <property name="sensitive">False</property>
-                    <property name="history-id">direntry</property>
-                    <property name="directory-entry">True</property>
-                    <signal handler="on_entry_activate" name="activate"/>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="label80">
-                    <property name="visible">True</property>
-                    <property name="xalign">1</property>
-                    <property name="xpad">5</property>
-                    <property name="ypad">5</property>
-                    <property name="label" translatable="yes" comments="Refers to version of the file being compared">Mine</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="label79">
-                    <property name="visible">True</property>
-                    <property name="xalign">1</property>
-                    <property name="xpad">5</property>
-                    <property name="ypad">5</property>
-                    <property name="label" translatable="yes" comments="Refers to version of the file being compared">Original</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="label78">
-                    <property name="visible">True</property>
-                    <property name="xalign">1</property>
-                    <property name="xpad">5</property>
-                    <property name="ypad">5</property>
-                    <property name="label" translatable="yes" comments="Refers to version of the file being compared">Other</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-              </object>
-            </child>
-            <child type="tab">
-              <object class="GtkLabel" id="tablabel1">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_Directory Comparison</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="position">1</property>
-                <property name="tab_fill">False</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkTable" id="table3">
-                <property name="visible">True</property>
-                <property name="border_width">10</property>
-                <property name="n_rows">1</property>
-                <property name="n_columns">2</property>
-                <property name="column_spacing">10</property>
-                <property name="row_spacing">10</property>
-                <child>
-                  <object class="HistoryFileEntry" id="vcentry0">
-                    <property name="visible">True</property>
-                    <property name="history-id">vc_directory</property>
-                    <property name="dialog-title" translatable="yes">Select VC Directory</property>
-                    <property name="directory-entry">True</property>
-                    <signal handler="on_entry_activate" name="activate"/>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="label81">
-                    <property name="visible">True</property>
-                    <property name="xalign">1</property>
-                    <property name="xpad">5</property>
-                    <property name="ypad">5</property>
-                    <property name="label" translatable="yes">Directory</property>
-                  </object>
-                  <packing>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"/>
-                  </packing>
-                </child>
-              </object>
-            </child>
-            <child type="tab">
-              <object class="GtkLabel" id="tablabel2">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_Version Control Browser</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="position">2</property>
-                <property name="tab_fill">False</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="position">2</property>
-          </packing>
-        </child>
-        <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="hbuttonbox1">
-            <property name="visible">True</property>
-            <property name="layout_style">GTK_BUTTONBOX_END</property>
-            <child>
-              <object class="GtkButton" id="button_cancel">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="label">gtk-cancel</property>
-                <property name="use_stock">True</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkButton" id="button_ok">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="has_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="label">gtk-ok</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">GTK_PACK_END</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-    <action-widgets>
-      <action-widget response="-6">button_cancel</action-widget>
-      <action-widget response="-5">button_ok</action-widget>
-    </action-widgets>
-  </object>
 </interface>
diff --git a/data/ui/new-dialog.ui b/data/ui/new-dialog.ui
new file mode 100644
index 0000000..8a3fcf5
--- /dev/null
+++ b/data/ui/new-dialog.ui
@@ -0,0 +1,498 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.18"/>
+  <!-- interface-naming-policy toplevel-contextual -->
+  <object class="GtkWindow" id="window">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkAlignment" id="new_comparison_tab">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="yalign">0.25</property>
+        <property name="xscale">0</property>
+        <property name="yscale">0</property>
+        <child>
+          <object class="GtkVBox" id="vbox6">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">12</property>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">New comparison</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkAlignment" id="alignment2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="GtkVBox" id="vbox7">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">12</property>
+                    <child>
+                      <object class="GtkHBox" id="hbox1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="spacing">12</property>
+                        <property name="homogeneous">True</property>
+                        <child>
+                          <object class="GtkToggleButton" id="button_type_file">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="use_action_appearance">False</property>
+                            <signal name="toggled" handler="on_button_type_toggled" swapped="no"/>
+                            <child>
+                              <object class="GtkVBox" id="vbox1">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">6</property>
+                                <child>
+                                  <object class="GtkImage" id="image1">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="stock">gtk-new</property>
+                                    <property name="icon-size">6</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label5">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">File comparison</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkToggleButton" id="button_type_dir">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="use_action_appearance">False</property>
+                            <signal name="toggled" handler="on_button_type_toggled" swapped="no"/>
+                            <child>
+                              <object class="GtkVBox" id="vbox2">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">6</property>
+                                <child>
+                                  <object class="GtkImage" id="image2">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="stock">gtk-directory</property>
+                                    <property name="icon-size">6</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label6">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">Directory comparison</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkToggleButton" id="button_type_vc">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="use_action_appearance">False</property>
+                            <signal name="toggled" handler="on_button_type_toggled" swapped="no"/>
+                            <child>
+                              <object class="GtkVBox" id="vbox3">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">6</property>
+                                <child>
+                                  <object class="GtkImage" id="image3">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="icon_name">vc-icon</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label7">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">Version control view</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkNotebook" id="choosers_notebook">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="show_tabs">False</property>
+                        <property name="show_border">False</property>
+                        <child>
+                          <object class="GtkHBox" id="hbox2">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="spacing">12</property>
+                            <property name="homogeneous">True</property>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="tab_fill">False</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <object class="GtkTable" id="table1">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="n_rows">2</property>
+                            <property name="n_columns">3</property>
+                            <property name="column_spacing">12</property>
+                            <property name="row_spacing">6</property>
+                            <property name="homogeneous">True</property>
+                            <child>
+                              <object class="GtkCheckButton" id="file_three_way_checkbutton">
+                                <property name="label" translatable="yes">_3-way comparison</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_action_appearance">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                                <signal name="toggled" handler="on_three_way_checkbutton_toggled" swapped="no"/>
+                              </object>
+                              <packing>
+                                <property name="left_attach">2</property>
+                                <property name="right_attach">3</property>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkFileChooserButton" id="file_chooser2">
+                                <property name="visible">True</property>
+                                <property name="sensitive">False</property>
+                                <property name="can_focus">False</property>
+                                <property name="create_folders">False</property>
+                                <property name="title" translatable="yes">Select Third File</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">2</property>
+                                <property name="right_attach">3</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkFileChooserButton" id="file_chooser1">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="create_folders">False</property>
+                                <property name="title" translatable="yes">Select Second File</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkFileChooserButton" id="file_chooser0">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="create_folders">False</property>
+                                <property name="title" translatable="yes">Select First File</property>
+                              </object>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <object class="GtkTable" id="table2">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="n_rows">2</property>
+                            <property name="n_columns">3</property>
+                            <property name="column_spacing">12</property>
+                            <property name="row_spacing">6</property>
+                            <child>
+                              <object class="GtkFileChooserButton" id="dir_chooser0">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="action">select-folder</property>
+                                <property name="create_folders">False</property>
+                                <property name="title" translatable="yes">Select First Folder</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="GtkFileChooserButton" id="dir_chooser1">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="action">select-folder</property>
+                                <property name="create_folders">False</property>
+                                <property name="title" translatable="yes">Select Second Folder</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkFileChooserButton" id="dir_chooser2">
+                                <property name="visible">True</property>
+                                <property name="sensitive">False</property>
+                                <property name="can_focus">False</property>
+                                <property name="action">select-folder</property>
+                                <property name="create_folders">False</property>
+                                <property name="title" translatable="yes">Select Third Folder</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">2</property>
+                                <property name="right_attach">3</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkCheckButton" id="dir_three_way_checkbutton">
+                                <property name="label" translatable="yes">_3-way comparison</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_action_appearance">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                                <signal name="toggled" handler="on_three_way_checkbutton_toggled" swapped="no"/>
+                              </object>
+                              <packing>
+                                <property name="left_attach">2</property>
+                                <property name="right_attach">3</property>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <object class="GtkHBox" id="hbox6">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="spacing">12</property>
+                            <property name="homogeneous">True</property>
+                            <child>
+                              <object class="GtkFileChooserButton" id="vc_chooser0">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="action">select-folder</property>
+                                <property name="create_folders">False</property>
+                                <property name="title" translatable="yes">Select A Version-Controlled Folder</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">3</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child type="tab">
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child type="tab">
+                          <placeholder/>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkHButtonBox" id="hbuttonbox2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="spacing">6</property>
+                <property name="layout_style">end</property>
+                <child>
+                  <object class="GtkButton" id="button_help">
+                    <property name="label">gtk-help</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="use_stock">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                    <property name="secondary">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button_new_blank">
+                    <property name="label" translatable="yes">_Blank comparison</property>
+                    <property name="visible">True</property>
+                    <property name="sensitive">False</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="use_underline">True</property>
+                    <signal name="clicked" handler="on_button_new_blank_clicked" swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button_compare">
+                    <property name="label" translatable="yes">C_ompare</property>
+                    <property name="visible">True</property>
+                    <property name="sensitive">False</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="use_underline">True</property>
+                    <signal name="clicked" handler="on_button_compare_clicked" swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index 9c27207..32e1639 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -26,7 +26,9 @@ import gobject
 from . import dirdiff
 from . import filediff
 from . import filemerge
+from . import melddoc
 from . import misc
+from . import new_diff_dialog
 from . import paths
 from . import preferences
 from . import recent
@@ -39,62 +41,6 @@ from .util.compat import string_types
 from .util.sourceviewer import srcviewer
 from .meldapp import app
 
-################################################################################
-#
-# NewDocDialog
-#
-################################################################################
-
-class NewDocDialog(gnomeglade.Component):
-    def __init__(self, parentapp):
-        gnomeglade.Component.__init__(self, paths.ui_dir("meldapp.ui"), "newdialog")
-        self.map_widgets_into_lists(["fileentry", "direntry", "vcentry", "three_way_compare"])
-        self.entrylists = self.fileentry, self.direntry, self.vcentry
-        self.widget.set_transient_for(parentapp.widget)
-        self.fileentry[0].set_sensitive(self.three_way_compare[0].get_active())
-        self.direntry[0].set_sensitive(self.three_way_compare[1].get_active())
-        self.diff_methods = (parentapp.append_filediff,
-                             parentapp.append_dirdiff,
-                             parentapp.append_vcview)
-        self.parentapp = parentapp
-        self.widget.show_all()
-
-    def on_entry_activate(self, entry):
-        for el in self.entrylists:
-            if entry in el:
-                i = el.index(entry)
-                if i == len(el) - 1:
-                    self.button_ok.grab_focus()
-                else:
-                    el[i+1].focus_entry()
-
-    def on_three_way_toggled(self, button):
-        page = self.three_way_compare.index(button)
-        self.entrylists[page][0].set_sensitive( button.get_active() )
-        self.entrylists[page][not button.get_active()].focus_entry()
-
-    def on_response(self, dialog, arg):
-        if arg == gtk.RESPONSE_OK:
-            page = self.type_notebook.get_current_page()
-            paths = [e.get_full_path() or "" for e in self.entrylists[page]]
-            if page < 2 and not self.three_way_compare[page].get_active():
-                paths.pop(0)
-            for path in paths:
-                self.entrylists[page][0].prepend_history(path)
-            if page == 2:
-                new_tab = self.diff_methods[page](paths[0])
-            else:
-                new_tab = self.diff_methods[page](paths)
-
-            # We just opened a new comparison, transfer focus to it
-            new_tab_idx = self.parentapp.notebook.page_num(new_tab.widget)
-            self.parentapp.notebook.set_current_page(new_tab_idx)
-
-            diff_type = recent.COMPARISON_TYPES[page]
-            app.recent_comparisons.add(new_tab)
-
-        self.widget.destroy()
-
 
 ################################################################################
 #
@@ -322,7 +268,8 @@ class MeldWindow(gnomeglade.Component):
         oldidx = notebook.get_current_page()
         if oldidx >= 0:
             olddoc = notebook.get_nth_page(oldidx).get_data("pyobject")
-            olddoc.disconnect(self.diff_handler)
+            if self.diff_handler is not None:
+                olddoc.disconnect(self.diff_handler)
             olddoc.on_container_switch_out_event(self.ui)
             if self.undo_handlers:
                 undoseq = olddoc.undosequence
@@ -343,13 +290,18 @@ class MeldWindow(gnomeglade.Component):
         self.actiongroup.get_action("Undo").set_sensitive(can_undo)
         self.actiongroup.get_action("Redo").set_sensitive(can_redo)
 
-        nbl = self.notebook.get_tab_label( newdoc.widget )
+        nbl = self.notebook.get_tab_label(newdoc.widget)
         self.widget.set_title(nbl.get_label_text() + " - Meld")
-        self.statusbar.set_info_box(newdoc.get_info_widgets())
-        self.diff_handler = newdoc.connect("next-diff-changed",
-                                           self.on_next_diff_changed)
+        try:
+            self.statusbar.set_info_box(newdoc.get_info_widgets())
+        except AttributeError:
+            pass
         newdoc.on_container_switch_in_event(self.ui)
-        self.scheduler.add_task( newdoc.scheduler )
+        if isinstance(page, melddoc.MeldDoc):
+            self.diff_handler = newdoc.connect("next-diff-changed",
+                                               self.on_next_diff_changed)
+        if hasattr(newdoc, 'scheduler'):
+            self.scheduler.add_task(newdoc.scheduler)
 
     def after_switch_page(self, notebook, page, which):
         self._update_page_action_sensitivity()
@@ -396,7 +348,7 @@ class MeldWindow(gnomeglade.Component):
     # Toolbar and menu items (file)
     #
     def on_menu_file_new_activate(self, menuitem):
-        NewDocDialog(self)
+        self.append_new_comparison()
 
     def on_menu_save_activate(self, menuitem):
         self.current_doc().save()
@@ -589,16 +541,19 @@ class MeldWindow(gnomeglade.Component):
         "See if a page will allow itself to be removed"
         response = page.on_delete_event(appquit)
         if response != gtk.RESPONSE_CANCEL:
-            self.scheduler.remove_scheduler(page.scheduler)
+            if hasattr(page, 'scheduler'):
+                self.scheduler.remove_scheduler(page.scheduler)
             page_num = self.notebook.page_num(page.widget)
             assert page_num >= 0
 
             # If the page we're removing is the current page, we need to
             # disconnect and clear undo handlers, and trigger a switch out
             if self.notebook.get_current_page() == page_num:
-                page.disconnect(self.diff_handler)
-                for handler in self.undo_handlers:
-                    page.undosequence.disconnect(handler)
+                if self.diff_handler is not None:
+                    page.disconnect(self.diff_handler)
+                if self.undo_handlers:
+                    for handler in self.undo_handlers:
+                        page.undosequence.disconnect(handler)
                 self.undo_handlers = tuple()
                 page.on_container_switch_out_event(self.ui)
 
@@ -625,14 +580,25 @@ class MeldWindow(gnomeglade.Component):
            isinstance(self.current_doc(), vcview.VcView):
             self.notebook.set_current_page(self.notebook.page_num(page.widget))
 
-        self.scheduler.add_scheduler(page.scheduler)
-        page.connect("label-changed", self.on_notebook_label_changed)
-        page.connect("file-changed", self.on_file_changed)
-        page.connect("create-diff", lambda obj,arg: self.append_diff(arg) )
+        if hasattr(page, 'scheduler'):
+            self.scheduler.add_scheduler(page.scheduler)
+        if isinstance(page, melddoc.MeldDoc):
+            page.connect("label-changed", self.on_notebook_label_changed)
+            page.connect("file-changed", self.on_file_changed)
+            page.connect("create-diff", lambda obj, arg: self.append_diff(arg))
+            page.connect("status-changed",
+                         lambda obj, arg: self.statusbar.set_doc_status(arg))
 
         # Allow reordering of tabs
         self.notebook.set_tab_reorderable(page.widget, True);
 
+    def append_new_comparison(self):
+        doc = new_diff_dialog.NewDiffTab(self)
+        self._append_page(doc, "document-new")
+        self.on_notebook_label_changed(doc, _("New comparison"), None)
+        doc.connect("diff-created", lambda x: self.try_remove_page(doc))
+        return doc
+
     def append_dirdiff(self, dirs, auto_compare=False):
         assert len(dirs) in (1,2,3)
         doc = dirdiff.DirDiff(app.prefs, len(dirs))
@@ -690,6 +656,7 @@ class MeldWindow(gnomeglade.Component):
         doc = vcview.VcView(app.prefs)
         # FIXME: need a good themed VC icon
         self._append_page(doc, "vc-icon")
+        location = location[0] if isinstance(location, list) else location
         doc.set_location(location)
         if auto_compare:
             doc.on_button_diff_clicked(None)
@@ -739,7 +706,10 @@ class MeldWindow(gnomeglade.Component):
         "Get the current doc or a dummy object if there is no current"
         index = self.notebook.get_current_page()
         if index >= 0:
-            return self.notebook.get_nth_page(index).get_data("pyobject")
+            page = self.notebook.get_nth_page(index).get_data("pyobject")
+            if isinstance(page, melddoc.MeldDoc):
+                return page
+
         class DummyDoc(object):
             def __getattr__(self, a): return lambda *x: None
         return DummyDoc()
diff --git a/meld/new_diff_dialog.py b/meld/new_diff_dialog.py
new file mode 100644
index 0000000..ab2bd21
--- /dev/null
+++ b/meld/new_diff_dialog.py
@@ -0,0 +1,113 @@
+### Copyright (C) 2011 Kai Willadsen <kai willadsen gmail com>
+
+### This program is free software; you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation; either version 2 of the License, or
+### (at your option) any later version.
+
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+### GNU General Public License for more details.
+
+### You should have received a copy of the GNU General Public License
+### along with this program; if not, write to the Free Software
+### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import os
+
+import gobject
+import gtk
+
+import paths
+from ui import gnomeglade
+
+
+class NewDiffTab(gobject.GObject, gnomeglade.Component):
+
+    __gtype_name__ = "NewDiffTab"
+
+    __gsignals__ = {
+        'diff-created': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()),
+    }
+
+    def __init__(self, parentapp):
+        gobject.GObject.__init__(self)
+        gnomeglade.Component.__init__(self, paths.ui_dir("new-dialog.ui"),
+                                      "new_comparison_tab")
+        self.map_widgets_into_lists(["file_chooser", "dir_chooser",
+                                     "vc_chooser"])
+        self.button_types = [self.button_type_file, self.button_type_dir,
+                             self.button_type_vc]
+        self.diff_methods = (parentapp.append_filediff,
+                             parentapp.append_dirdiff,
+                             parentapp.append_vcview)
+        self.diff_type = -1
+        self.widget.show_all()
+
+    def on_button_type_toggled(self, button, *args):
+        if not button.get_active():
+            if not any([b.get_active() for b in self.button_types]):
+                button.set_active(True)
+            return
+
+        for b in self.button_types:
+            if b is not button:
+                b.set_active(False)
+
+        self.diff_type = self.button_types.index(button)
+        self.choosers_notebook.set_current_page(self.diff_type + 1)
+        self.button_new_blank.set_sensitive(True)
+        self.button_compare.set_sensitive(True)
+
+    def on_three_way_checkbutton_toggled(self, button, *args):
+        if button is self.file_three_way_checkbutton:
+            self.file_chooser2.set_sensitive(button.get_active())
+        else:  # button is self.dir_three_way_checkbutton
+            self.dir_chooser2.set_sensitive(button.get_active())
+
+    # TODO: This is not even hooked up. We could do checks here to prevent
+    # errors: check to see if we've got binary files; check for null file
+    # selections; sniff text encodings; check file permissions.
+    def on_file_set(self, button, *args):
+        filename = button.get_filename()
+        assert os.path.isfile(filename)
+
+    def _get_num_paths(self):
+        if self.diff_type in (0, 1):
+            three_way_buttons = (self.file_three_way_checkbutton,
+                                 self.dir_three_way_checkbutton)
+            three_way = three_way_buttons[self.diff_type].get_active()
+            num_paths = 3 if three_way else 2
+        else:  # self.diff_type == 2
+            num_paths = 1
+        return num_paths
+
+    def on_button_compare_clicked(self, *args):
+        type_choosers = (self.file_chooser, self.dir_chooser, self.vc_chooser)
+
+        compare_paths = []
+        num_paths = self._get_num_paths()
+        for chooser in type_choosers[self.diff_type][:num_paths]:
+            gfile = chooser.get_file()
+            path = gfile.get_path() if gfile else ""
+            compare_paths.append(path)
+
+        self.diff_methods[self.diff_type](compare_paths)
+        self.emit('diff-created')
+
+    def on_button_new_blank_clicked(self, *args):
+        # TODO: This doesn't work the way I'd like for DirDiff and VCView.
+        # It should do something similar to FileDiff; give a tab with empty
+        # file entries and no comparison done.
+        compare_paths = [""] * self._get_num_paths()
+        self.diff_methods[self.diff_type](compare_paths)
+
+    def on_container_switch_in_event(self, *args):
+        pass
+
+    def on_container_switch_out_event(self, *args):
+        pass
+
+    def on_delete_event(self, *args):
+        return gtk.RESPONSE_OK



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]