[meld: 1/4] Add an option to preferably use native file dialogs
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld: 1/4] Add an option to preferably use native file dialogs
- Date: Sun, 13 Dec 2020 21:35:50 +0000 (UTC)
commit 5f5c44f03617e71ce90f6058295e661eaccc181a
Author: Mario Aichinger <aichingm gmail com>
Date: Sun Nov 15 15:49:41 2020 +0100
Add an option to preferably use native file dialogs
data/org.gnome.meld.gschema.xml | 5 ++
meld/filediff.py | 4 +-
meld/iohelpers.py | 4 +-
meld/newdifftab.py | 51 +++++++++++++++-
meld/preferences.py | 2 +
meld/resources/ui/new-diff-tab.ui | 42 ++++++++++++-
meld/resources/ui/preferences.ui | 121 +++++++++++++++++++++++++++++++++++---
meld/settings.py | 2 +
meld/ui/filechooser.py | 35 +++++++++++
9 files changed, 251 insertions(+), 15 deletions(-)
---
diff --git a/data/org.gnome.meld.gschema.xml b/data/org.gnome.meld.gschema.xml
index d966b43b..63e2118a 100644
--- a/data/org.gnome.meld.gschema.xml
+++ b/data/org.gnome.meld.gschema.xml
@@ -114,6 +114,11 @@
<summary>Use the system default monospace font</summary>
<description>If false, custom-font will be used instead of the system monospace font.</description>
</key>
+ <key name="use-system-file-dialogs" type="b">
+ <default>false</default>
+ <summary>Use the system file dialogs</summary>
+ <description>If false, custom non-native file dialogs will be used.</description>
+ </key>
<key name="custom-font" type="s">
<default>"monospace, 14"</default>
<summary>Custom font</summary>
diff --git a/meld/filediff.py b/meld/filediff.py
index dfaf71a0..356537bb 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -52,7 +52,7 @@ from meld.sourceview import (
TextviewLineAnimationType,
get_custom_encoding_candidates,
)
-from meld.ui.filechooser import MeldFileChooserDialog
+from meld.ui.filechooser import MeldFileChooserDialogFactory
from meld.ui.findbar import FindBar
from meld.ui.util import (
make_multiobject_property_action,
@@ -2042,7 +2042,7 @@ class FileDiff(Gtk.VBox, MeldDoc):
def on_file_open_button_clicked(self, button):
pane = self.file_open_button.index(button)
- dialog = MeldFileChooserDialog(
+ dialog = MeldFileChooserDialogFactory.dialog(
title=_("Open File"),
transient_for=self.get_toplevel(),
)
diff --git a/meld/iohelpers.py b/meld/iohelpers.py
index ffa162e4..614a58a9 100644
--- a/meld/iohelpers.py
+++ b/meld/iohelpers.py
@@ -5,7 +5,7 @@ from gi.repository import Gio, GLib, Gtk
from meld.conf import _
from meld.misc import get_modal_parent, modal_dialog
-from meld.ui.filechooser import MeldFileChooserDialog
+from meld.ui.filechooser import MeldFileChooserDialogFactory
def trash_or_confirm(gfile: Gio.File) -> bool:
@@ -75,7 +75,7 @@ def trash_or_confirm(gfile: Gio.File) -> bool:
def prompt_save_filename(
title: str, parent: Optional[Gtk.Widget] = None) -> Optional[Gio.File]:
- dialog = MeldFileChooserDialog(
+ dialog = MeldFileChooserDialogFactory.dialog(
title,
transient_for=get_modal_parent(parent),
action=Gtk.FileChooserAction.SAVE,
diff --git a/meld/newdifftab.py b/meld/newdifftab.py
index a619013a..06d593b1 100644
--- a/meld/newdifftab.py
+++ b/meld/newdifftab.py
@@ -20,6 +20,7 @@ from gi.repository import Gio, GLib, GObject, Gtk
from meld.conf import _
from meld.melddoc import LabeledObjectMixin, MeldDoc
from meld.recent import recent_comparisons
+from meld.settings import get_meld_settings, settings
from meld.ui.util import map_widgets_into_lists
@@ -61,6 +62,9 @@ class NewDiffTab(Gtk.Alignment, LabeledObjectMixin):
file_chooser0 = Gtk.Template.Child()
file_chooser1 = Gtk.Template.Child()
file_chooser2 = Gtk.Template.Child()
+ file_chooser_native0 = Gtk.Template.Child()
+ file_chooser_native1 = Gtk.Template.Child()
+ file_chooser_native2 = Gtk.Template.Child()
file_three_way_checkbutton = Gtk.Template.Child()
filechooserdialog0 = Gtk.Template.Child()
filechooserdialog1 = Gtk.Template.Child()
@@ -71,7 +75,13 @@ class NewDiffTab(Gtk.Alignment, LabeledObjectMixin):
super().__init__()
map_widgets_into_lists(
self,
- ["file_chooser", "dir_chooser", "vc_chooser", "filechooserdialog"]
+ [
+ "file_chooser",
+ "file_chooser_native",
+ "dir_chooser",
+ "vc_chooser",
+ "filechooserdialog"
+ ]
)
self.button_types = [
self.button_type_file,
@@ -89,7 +99,10 @@ class NewDiffTab(Gtk.Alignment, LabeledObjectMixin):
for chooser in self.file_chooser:
chooser.set_current_folder(default_path)
+ get_meld_settings().connect('changed', self.on_setting_changed)
+
self.show()
+ self.hide_unused_file_chooser_buttons()
@Gtk.Template.Callback()
def on_button_type_toggled(self, button, *args):
@@ -113,6 +126,7 @@ class NewDiffTab(Gtk.Alignment, LabeledObjectMixin):
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())
+ self.file_chooser_native2.set_sensitive(button.get_active())
else: # button is self.dir_three_way_checkbutton
self.dir_chooser2.set_sensitive(button.get_active())
@@ -136,6 +150,23 @@ class NewDiffTab(Gtk.Alignment, LabeledObjectMixin):
# we've got binary files; check for null file selections; sniff text
# encodings; check file permissions.
+ def hide_unused_file_chooser_buttons(self):
+ if settings.get_boolean('use-system-file-dialogs'):
+ choosers_to_hide = self.file_chooser
+ choosers_to_show = self.file_chooser_native
+ else:
+ choosers_to_hide = self.file_chooser_native
+ choosers_to_show = self.file_chooser
+
+ for b in choosers_to_hide:
+ b.hide()
+ for b in choosers_to_show:
+ b.show()
+
+ def on_setting_changed(self, settings, key):
+ if key == 'use-system-file-dialogs':
+ self.hide_unused_file_chooser_buttons()
+
def _get_num_paths(self):
if self.diff_type in (DiffType.File, DiffType.Folder):
three_way_buttons = (
@@ -150,8 +181,22 @@ class NewDiffTab(Gtk.Alignment, LabeledObjectMixin):
@Gtk.Template.Callback()
def on_button_compare_clicked(self, *args):
- type_choosers = (self.file_chooser, self.dir_chooser, self.vc_chooser)
- choosers = type_choosers[self.diff_type][:self._get_num_paths()]
+ type_choosers = (
+ self.file_chooser,
+ self.dir_chooser,
+ self.vc_chooser,
+ self.file_chooser_native
+ )
+
+ if settings.get_boolean('use-system-file-dialogs'):
+ native_offset = 3
+ else:
+ native_offset = 0
+
+ chooser_index = self.diff_type + native_offset
+
+ choosers = type_choosers[chooser_index][:self._get_num_paths()]
+
compare_gfiles = [chooser.get_file() for chooser in choosers]
compare_kwargs = {}
diff --git a/meld/preferences.py b/meld/preferences.py
index cf8b9def..01993dbf 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -254,6 +254,7 @@ class PreferencesDialog(Gtk.Dialog):
checkbutton_break_commit_lines = Gtk.Template.Child()
checkbutton_default_font = Gtk.Template.Child()
+ checkbutton_system_file_dialogs = Gtk.Template.Child()
checkbutton_folder_filter_text = Gtk.Template.Child()
checkbutton_highlight_current_line = Gtk.Template.Child()
checkbutton_ignore_blank_lines = Gtk.Template.Child()
@@ -286,6 +287,7 @@ class PreferencesDialog(Gtk.Dialog):
super().__init__(**kwargs)
bindings = [
+ ('use-system-file-dialogs', self.checkbutton_system_file_dialogs, 'active'), # noqa: E501
('use-system-font', self.checkbutton_default_font, 'active'),
('custom-font', self.fontpicker, 'font'),
('indent-width', self.spinbutton_tabsize, 'value'),
diff --git a/meld/resources/ui/new-diff-tab.ui b/meld/resources/ui/new-diff-tab.ui
index 1a8ea3d6..3b3f1b47 100644
--- a/meld/resources/ui/new-diff-tab.ui
+++ b/meld/resources/ui/new-diff-tab.ui
@@ -342,7 +342,7 @@
</object>
<packing>
<property name="left_attach">2</property>
- <property name="top_attach">1</property>
+ <property name="top_attach">2</property>
</packing>
</child>
<child>
@@ -359,6 +359,19 @@
<property name="top_attach">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkFileChooserButton" id="file_chooser_native0">
+ <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>
+ <signal name="file-set" handler="on_file_set" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
<child>
<object class="GtkFileChooserButton" id="file_chooser1">
<property name="visible">True</property>
@@ -373,6 +386,19 @@
<property name="top_attach">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkFileChooserButton" id="file_chooser_native1">
+ <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>
+ <signal name="file-set" handler="on_file_set" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
<child>
<object class="GtkFileChooserButton" id="file_chooser2">
<property name="visible">True</property>
@@ -388,6 +414,20 @@
<property name="top_attach">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkFileChooserButton" id="file_chooser_native2">
+ <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>
+ <signal name="file-set" handler="on_file_set" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
<child>
<placeholder/>
</child>
diff --git a/meld/resources/ui/preferences.ui b/meld/resources/ui/preferences.ui
index 37dc3055..67f984bf 100644
--- a/meld/resources/ui/preferences.ui
+++ b/meld/resources/ui/preferences.ui
@@ -55,6 +55,112 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_border">False</property>
+ <child>
+ <object class="GtkBox" id="general_tab">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label17">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">File Dialogs</property>
+ <property name="use_markup">True</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="padding">12</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkCheckButton" id="checkbutton_system_file_dialogs">
+ <property name="label" translatable="yes">_Use system file dialogs where
possible</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="general_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">General</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
<child>
<object class="GtkBox" id="editor_tab">
<property name="visible">True</property>
@@ -699,7 +805,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">3</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -711,6 +817,7 @@
<property name="label" translatable="yes">Editor</property>
</object>
<packing>
+ <property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
@@ -1340,7 +1447,7 @@
</child>
</object>
<packing>
- <property name="position">2</property>
+ <property name="position">3</property>
<property name="tab_fill">False</property>
</packing>
</child>
@@ -1351,7 +1458,7 @@
<property name="label" translatable="yes">Version Control</property>
</object>
<packing>
- <property name="position">2</property>
+ <property name="position">3</property>
<property name="tab_fill">False</property>
</packing>
</child>
@@ -1445,7 +1552,7 @@
</child>
</object>
<packing>
- <property name="position">3</property>
+ <property name="position">4</property>
<property name="tab_fill">False</property>
</packing>
</child>
@@ -1456,7 +1563,7 @@
<property name="label" translatable="yes">File Filters</property>
</object>
<packing>
- <property name="position">3</property>
+ <property name="position">4</property>
<property name="tab_fill">False</property>
</packing>
</child>
@@ -1631,7 +1738,7 @@
</child>
</object>
<packing>
- <property name="position">4</property>
+ <property name="position">5</property>
</packing>
</child>
<child type="tab">
@@ -1641,7 +1748,7 @@
<property name="label" translatable="yes">Text Filters</property>
</object>
<packing>
- <property name="position">4</property>
+ <property name="position">5</property>
<property name="tab_fill">False</property>
</packing>
</child>
diff --git a/meld/settings.py b/meld/settings.py
index a240a8e3..c97fb563 100644
--- a/meld/settings.py
+++ b/meld/settings.py
@@ -53,6 +53,8 @@ class MeldSettings(GObject.GObject):
elif key in ('style-scheme'):
self.style_scheme = self._style_scheme_from_gsettings()
self.emit('changed', 'style-scheme')
+ elif key in ('use-system-file-dialogs'):
+ self.emit('changed', 'use-system-file-dialogs')
def _style_scheme_from_gsettings(self):
from meld.style import set_base_style_scheme
diff --git a/meld/ui/filechooser.py b/meld/ui/filechooser.py
index 9616adb9..2cd15888 100644
--- a/meld/ui/filechooser.py
+++ b/meld/ui/filechooser.py
@@ -20,6 +20,7 @@ import sys
from gi.repository import Gtk, GtkSource
from meld.conf import _
+from meld.settings import settings
FILE_ACTIONS = {
Gtk.FileChooserAction.OPEN,
@@ -27,6 +28,20 @@ FILE_ACTIONS = {
}
+class MeldFileChooserDialogNative(Gtk.FileChooserNative):
+
+ __gtype_name__ = 'MeldFileChooserDialogNative'
+
+ def __init__(self, title=None, transient_for=None,
+ action=Gtk.FileChooserAction.OPEN):
+ super().__init__(title=title, transient_for=transient_for,
+ action=action)
+
+ def set_default_response(*_):
+ pass # it is not possible to set this when using the native dialog
+ # The native dialog always returns Gtk.ResponseType.ACCEPT
+
+
class MeldFileChooserDialog(Gtk.FileChooserDialog):
"""A simple GTK+ file chooser dialog with a text encoding combo box."""
@@ -106,3 +121,23 @@ class MeldFileChooserDialog(Gtk.FileChooserDialog):
self.props.extra_widget = self.make_encoding_combo()
else:
self.props.extra_widget = None
+
+
+class MeldFileChooserDialogFactory:
+
+ @staticmethod
+ def dialog(title=None, transient_for=None,
+ action=Gtk.FileChooserAction.OPEN):
+
+ if settings.get_boolean('use-system-file-dialogs'):
+ return MeldFileChooserDialogNative(
+ title,
+ transient_for=transient_for,
+ action=action,
+ )
+ else:
+ return MeldFileChooserDialog(
+ title,
+ transient_for=transient_for,
+ action=action,
+ )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]