Implement GTK+3/4 compatibility

This commit is contained in:
Benjamin Drieu 2022-05-30 11:27:11 +02:00 committed by Benjamin Drieu
parent af32fbefd2
commit 4e21919d2e
1 changed files with 50 additions and 11 deletions

View File

@ -83,6 +83,9 @@ const prefs = [
function init() {
monitoLog('initializing ${Me.metadata.name} Preferences');
this.settings = ExtensionUtils.getSettings(SETTINGS_SCHEMA);
this.gtkVersion = Gtk.get_major_version();
}
@ -98,12 +101,14 @@ function buildPrefsWidget() {
let mainWidget = new Gtk.Notebook( { } );
let prefsWidget = new Gtk.Grid({
// margin: 18,
column_spacing: 12,
row_spacing: 12,
column_homogeneous: false,
});
if ( this.gtkVersion < 4 )
prefsWidget.margin = 18;
this.prefWidgets = { };
// Add a simple title and add it to the prefsWidget
@ -165,12 +170,18 @@ function buildPrefsWidget() {
homogeneous: false, } );
monitoLog ( 'Box ' + this._accountsWidgetContainer );
monitoLog ( 'Func ' + this._accountsWidgetContainer.pack_start );
this._accountsWidgetContainer.append(accountsChooserContainer, true, true, 0);
if ( this.gtkVersion == 4 )
this._accountsWidgetContainer.append(accountsChooserContainer, true, true, 0);
else
this._accountsWidgetContainer.add(accountsChooserContainer, true, true, 0);
this.accountsChooser = new Gtk.ListBox ( { valign: Gtk.Align.FILL,
hexpand: true,
vexpand: true } );
accountsChooserContainer.append(this.accountsChooser, true, true, 0);
if ( this.gtkVersion == 4 )
accountsChooserContainer.append(this.accountsChooser, true, true, 0);
else
accountsChooserContainer.add(this.accountsChooser, true, true, 0);
// Account list
for ( var server_id of this.getServersList ( ) )
@ -179,7 +190,10 @@ function buildPrefsWidget() {
// Action Bar
let accountsChooserActionBar = new Gtk.ActionBar ( { valign: Gtk.Align.END } );
accountsChooserContainer.append(accountsChooserActionBar, true, true, 0);
if ( this.gtkVersion == 4 )
accountsChooserContainer.append(accountsChooserActionBar, true, true, 0);
else
accountsChooserContainer.add(accountsChooserActionBar, true, true, 0);
let accountCreateButton = Gtk.Button.new_from_icon_name ( 'list-add',
Gtk.IconSize.BUTTON );
@ -193,7 +207,10 @@ function buildPrefsWidget() {
this.createAccountWidgets ( false ) ;
mainVbox.append(mainWidget, true, true, 0);
if ( this.gtkVersion == 4 )
mainVbox.append(mainWidget, true, true, 0);
else
mainVbox.add(mainWidget);
mainVbox.show_all();
return mainVbox;
@ -245,7 +262,10 @@ function createAccountWidgets ( isActive )
this.prefWidgets = { };
this._accountsWidget = new Gtk.Notebook( { } );
this._accountsWidgetContainer.append(this._accountsWidget, true, true, 0);
if ( this.gtkVersion == 4 )
this._accountsWidgetContainer.append(this._accountsWidget, true, true, 0);
else
this._accountsWidgetContainer.add(this._accountsWidget);
for ( var _tab of [ 'Settings', 'Columns', 'Colors', 'Filters', 'Replacements' ] )
{
@ -276,6 +296,8 @@ function createPrefWidgets ( noteBook, type, isActive )
visible: true,
column_homogeneous: false,
});
if ( this.gtkVersion < 4 )
grid.margin = 18;
noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) );
let y = 0;
@ -340,6 +362,8 @@ function createColumnsPrefTab ( noteBook, type, isActive )
visible: true,
column_homogeneous: false,
});
if ( this.gtkVersion < 4 )
grid.margin = 18;
noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) );
let _store = new Gtk.TreeStore();
@ -354,13 +378,19 @@ function createColumnsPrefTab ( noteBook, type, isActive )
let columnNumbers = new Gtk.TreeViewColumn ( { title: _("Column") } );
let rendererNumbers = new Gtk.CellRendererText ( { editable: true } );
columnNumbers.append(rendererNumbers, true);
if ( this.gtkVersion == 4 )
columnNumbers.append(rendererNumbers, true);
else
columnNumbers.pack_start(rendererNumbers, true);
columnNumbers.add_attribute(rendererNumbers, 'text', 0);
_treeView.append_column(columnNumbers);
let _colSize = new Gtk.TreeViewColumn ( { title: _("Size") } );
let _colRenderer = new Gtk.CellRendererText ( { editable: true } );
_colSize.append(_colRenderer, true);
if ( this.gtkVersion == 4 )
_colSize.append(_colRenderer, true);
else
_colSize.pack_start(_colRenderer, true);
_colSize.add_attribute(_colRenderer, 'text', 1);
_treeView.append_column(_colSize);
@ -446,9 +476,18 @@ function addAccountLine ( server_id )
hexpand: true,
// margin: 5,
halign: Gtk.Align.START } );
row.set_child ( _label );
this.accountsChooser.append ( row );
this.accountsChooser.show_all(); // XXX Does not work in gtk4 ?
if ( this.gtkVersion == 4 )
{
row.set_child ( _label );
this.accountsChooser.append ( row );
}
else
{
_label.margin = 5;
row.add ( _label );
this.accountsChooser.add ( row );
this.accountsChooser.show_all();
}
}