[meld/ui-next] filediff: Move from GtkFileChooserButton to manual open button + label
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/ui-next] filediff: Move from GtkFileChooserButton to manual open button + label
- Date: Sat, 23 Mar 2019 02:04:04 +0000 (UTC)
commit dd309b29bb8e136dab93a55e1e8a0d6d1ee687db
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Mar 10 07:02:30 2019 +1000
filediff: Move from GtkFileChooserButton to manual open button + label
While this path display isn't ideal (and isn't finished) it's arguably
less visually disturbing than the existing full-width
GtkFileChooserButton, which has always looked wrong.
As a minor bonus here, we're now also using our custom file chooser
dialog with support for specifying the encoding.
meld/filediff.py | 55 +++++++++++++++-------------
meld/resources/ui/filediff.ui | 85 ++++++++++++++-----------------------------
2 files changed, 57 insertions(+), 83 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 3f5e22cf..a03dbe89 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -45,6 +45,7 @@ from meld.settings import bind_settings, meldsettings
from meld.sourceview import (
get_custom_encoding_candidates, LanguageManager, TextviewLineAnimationType)
from meld.ui._gtktemplate import Template
+from meld.ui.filechooser import MeldFileChooserDialog
from meld.ui.findbar import FindBar
from meld.ui.util import (
make_multiobject_property_action, map_widgets_into_lists)
@@ -133,12 +134,9 @@ class FileDiff(Gtk.VBox, MeldDoc):
dummy_toolbar_linkmap0 = Template.Child()
dummy_toolbar_linkmap1 = Template.Child()
dummy_toolbar_sourcemap = Template.Child()
- fileentry0 = Template.Child()
- fileentry1 = Template.Child()
- fileentry2 = Template.Child()
- fileentry_toolitem0 = Template.Child()
- fileentry_toolitem1 = Template.Child()
- fileentry_toolitem2 = Template.Child()
+ file_open_button0 = Template.Child()
+ file_open_button1 = Template.Child()
+ file_open_button2 = Template.Child()
file_save_button0 = Template.Child()
file_save_button1 = Template.Child()
file_save_button2 = Template.Child()
@@ -224,11 +222,11 @@ class FileDiff(Gtk.VBox, MeldDoc):
bind_settings(self)
widget_lists = [
- "sourcemap", "file_save_button", "file_toolbar", "fileentry",
+ "sourcemap", "file_save_button", "file_toolbar",
"linkmap", "msgarea_mgr", "readonlytoggle",
"scrolledwindow", "textview", "vbox",
"dummy_toolbar_linkmap", "filelabel_toolitem", "filelabel",
- "fileentry_toolitem", "statusbar",
+ "file_open_button", "statusbar",
"actiongutter", "dummy_toolbar_actiongutter",
]
map_widgets_into_lists(self, widget_lists)
@@ -1217,7 +1215,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
buf.data.savefile = gfile
buf.data.label = gfile.get_path()
self.update_buffer_writable(buf)
- self.fileentry[1].set_file(gfile)
+ self.filelabel[1].set_text(buf.data.savefile)
self.recompute_label()
def _set_save_action_sensitivity(self):
@@ -1308,13 +1306,13 @@ class FileDiff(Gtk.VBox, MeldDoc):
duplicate handlers, etc. if you don't do this thing.
"""
- self.fileentry[pane].set_file(gfile)
-
self.msgarea_mgr[pane].clear()
buf = self.textbuffer[pane]
buf.data.reset(gfile)
+ self.filelabel[pane].set_text(self.textbuffer[pane].data.label)
+
if buf.data.is_special:
loader = GtkSource.FileLoader.new_from_stream(
buf, buf.data.sourcefile, buf.data.gfile.read())
@@ -1448,8 +1446,6 @@ class FileDiff(Gtk.VBox, MeldDoc):
for i, l in enumerate(labels):
if l:
self.filelabel[i].set_text(l)
- self.filelabel_toolitem[i].set_visible(True)
- self.fileentry_toolitem[i].set_visible(False)
def notify_file_changed(self, data):
try:
@@ -1731,9 +1727,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
bufdata.label = gfile.get_path()
bufdata.gfile = gfile
bufdata.savefile = None
- self.fileentry[pane].set_file(gfile)
- self.filelabel_toolitem[pane].set_visible(False)
- self.fileentry_toolitem[pane].set_visible(True)
+ self.filelabel[pane].set_text(bufdata.label)
if not force_overwrite and not bufdata.current_on_disk():
primary = (
@@ -1850,15 +1844,26 @@ class FileDiff(Gtk.VBox, MeldDoc):
self.save_file(idx)
@Template.Callback()
- def on_fileentry_file_set(self, entry):
- pane = self.fileentry[:self.num_panes].index(entry)
- buffer = self.textbuffer[pane]
- if self.check_unsaved_changes():
- # TODO: Use encoding file selectors in FileDiff
- self.set_file(pane, entry.get_file())
- else:
- entry.set_file(buffer.data.gfile)
- return True
+ def on_file_open_button_clicked(self, button):
+ pane = self.file_open_button.index(button)
+
+ dialog = MeldFileChooserDialog(
+ title=_("Open File"),
+ transient_for=self.get_toplevel(),
+ )
+ dialog.set_file(self.textbuffer[pane].data.gfile)
+ response = dialog.run()
+ gfile = dialog.get_file()
+ encoding = dialog.get_encoding()
+ dialog.destroy()
+
+ if response != Gtk.ResponseType.ACCEPT:
+ return
+
+ if not self.check_unsaved_changes():
+ return
+
+ self.set_file(pane, gfile, encoding)
def _get_focused_pane(self):
for i in range(self.num_panes):
diff --git a/meld/resources/ui/filediff.ui b/meld/resources/ui/filediff.ui
index 293148b1..a0febbf4 100644
--- a/meld/resources/ui/filediff.ui
+++ b/meld/resources/ui/filediff.ui
@@ -181,6 +181,14 @@
<property name="homogeneous">True</property>
</packing>
</child>
+ <child>
+ <object class="GtkToolButton" id="file_open_button2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">document-open-symbolic</property>
+ <signal name="clicked" handler="on_file_open_button_clicked" swapped="no"/>
+ </object>
+ </child>
<child>
<object class="GtkToolButton" id="file_save_button2">
<property name="visible">True</property>
@@ -193,26 +201,9 @@
<property name="homogeneous">True</property>
</packing>
</child>
- <child>
- <object class="GtkToolItem" id="fileentry_toolitem2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <child>
- <object class="GtkFileChooserButton" id="fileentry2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="local_only">False</property>
- <signal name="file-set" handler="on_fileentry_file_set" swapped="no"/>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="homogeneous">False</property>
- </packing>
- </child>
<child>
<object class="GtkToolItem" id="filelabel_toolitem2">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">12</property>
<child>
@@ -256,6 +247,14 @@
<property name="homogeneous">True</property>
</packing>
</child>
+ <child>
+ <object class="GtkToolButton" id="file_open_button1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">document-open-symbolic</property>
+ <signal name="clicked" handler="on_file_open_button_clicked" swapped="no"/>
+ </object>
+ </child>
<child>
<object class="GtkToolButton" id="file_save_button1">
<property name="visible">True</property>
@@ -268,26 +267,9 @@
<property name="homogeneous">True</property>
</packing>
</child>
- <child>
- <object class="GtkToolItem" id="fileentry_toolitem1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <child>
- <object class="GtkFileChooserButton" id="fileentry1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="local_only">False</property>
- <signal name="file-set" handler="on_fileentry_file_set" swapped="no"/>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="homogeneous">False</property>
- </packing>
- </child>
<child>
<object class="GtkToolItem" id="filelabel_toolitem1">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">12</property>
<child>
@@ -332,37 +314,24 @@
</packing>
</child>
<child>
- <object class="GtkToolButton" id="file_save_button0">
+ <object class="GtkToolButton" id="file_open_button0">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="icon_name">document-save-symbolic</property>
- <signal name="clicked" handler="on_file_save_button_clicked" swapped="no"/>
+ <property name="can_focus">False</property>
+ <property name="icon_name">document-open-symbolic</property>
+ <signal name="clicked" handler="on_file_open_button_clicked" swapped="no"/>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="homogeneous">True</property>
- </packing>
</child>
<child>
- <object class="GtkToolItem" id="fileentry_toolitem0">
+ <object class="GtkToolButton" id="file_save_button0">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <child>
- <object class="GtkFileChooserButton" id="fileentry0">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="local_only">False</property>
- <signal name="file-set" handler="on_fileentry_file_set" swapped="no"/>
- </object>
- </child>
+ <property name="can_focus">True</property>
+ <property name="icon_name">document-save-symbolic</property>
+ <signal name="clicked" handler="on_file_save_button_clicked" swapped="no"/>
</object>
- <packing>
- <property name="expand">True</property>
- <property name="homogeneous">False</property>
- </packing>
</child>
<child>
<object class="GtkToolItem" id="filelabel_toolitem0">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">12</property>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]