diff --git a/prefs.js b/prefs.js index d8d61eb..d03c644 100644 --- a/prefs.js +++ b/prefs.js @@ -169,12 +169,10 @@ function buildPrefsWidget() { let accountsChooserContainer = new Gtk.Box( { orientation: Gtk.Orientation.VERTICAL, homogeneous: false, } ); - monitoLog ( 'Box ' + this._accountsWidgetContainer ); - monitoLog ( 'Func ' + this._accountsWidgetContainer.pack_start ); if ( this.gtkVersion == 4 ) this._accountsWidgetContainer.append(accountsChooserContainer, true, true, 0); else - this._accountsWidgetContainer.add(accountsChooserContainer, true, true, 0); + this._accountsWidgetContainer.add(accountsChooserContainer); this.accountsChooser = new Gtk.ListBox ( { valign: Gtk.Align.FILL, hexpand: true, @@ -182,7 +180,7 @@ function buildPrefsWidget() { if ( this.gtkVersion == 4 ) accountsChooserContainer.append(this.accountsChooser, true, true, 0); else - accountsChooserContainer.add(this.accountsChooser, true, true, 0); + accountsChooserContainer.add(this.accountsChooser); // Account list for ( var server_id of this.getServersList ( ) ) @@ -194,7 +192,7 @@ function buildPrefsWidget() { if ( this.gtkVersion == 4 ) accountsChooserContainer.append(accountsChooserActionBar, true, true, 0); else - accountsChooserContainer.add(accountsChooserActionBar, true, true, 0); + accountsChooserContainer.add(accountsChooserActionBar); let accountCreateButton = Gtk.Button.new_from_icon_name ( 'list-add', Gtk.IconSize.BUTTON ); @@ -367,19 +365,21 @@ function createColumnsPrefTab ( noteBook, type, isActive ) grid.margin = 18; noteBook.append_page ( grid, new Gtk.Label ( { label: _(type), } ) ); - let _treeView = new Gtk.TreeView ( { headers_visible: true, + this.treeView = new Gtk.TreeView ( { headers_visible: true, reorderable: true, hexpand: true, vexpand: true }); let columnNumbers = new Gtk.TreeViewColumn ( { title: _("Column") } ); - let rendererNumbers = new Gtk.CellRendererText ( { editable: true } ); + let rendererNumbers = new Gtk.CellRendererCombo ( { editable: true } ); + rendererNumbers.col = 0; if ( this.gtkVersion == 4 ) columnNumbers.append(rendererNumbers, true); else columnNumbers.pack_start(rendererNumbers, true); columnNumbers.add_attribute(rendererNumbers, 'text', 0); - _treeView.append_column(columnNumbers); + this.treeView.append_column(columnNumbers); + rendererNumbers.connect('edited', Lang.bind ( this, this.editColumn ) ); let _colSize = new Gtk.TreeViewColumn ( { title: _("Size") } ); let _colRenderer = new Gtk.CellRendererText ( { editable: true } ); @@ -388,11 +388,13 @@ function createColumnsPrefTab ( noteBook, type, isActive ) else _colSize.pack_start(_colRenderer, true); _colSize.add_attribute(_colRenderer, 'text', 1); - _treeView.append_column(_colSize); + this.treeView.append_column(_colSize); + _colRenderer.col = 1; + _colRenderer.connect('edited', Lang.bind ( this, this.editColumn ) ); // _treeView.connect('row-activated', this._editPath.bind(this)); - grid.attach ( _treeView, 0, 1, 1, 1 ); + grid.attach ( this.treeView, 0, 1, 1, 1 ); // Action Bar let rowsChooserActionBar = new Gtk.ActionBar ( { valign: Gtk.Align.END } ); @@ -407,7 +409,7 @@ function createColumnsPrefTab ( noteBook, type, isActive ) rowsChooserActionBar.add ( rowRemoveButton ); rowRemoveButton.connect ( 'clicked', Lang.bind ( this, this.removeColumnRow ) ); - grid.attach ( columnsChooserActionBar, 0, 2, 1, 1 ); + grid.attach ( rowsChooserActionBar, 0, 2, 1, 1 ); } @@ -418,6 +420,11 @@ function activateAccountRow ( ) { this._accountsWidget.destroy ( ); this.createAccountWidgets ( true ); + this.store = new Gtk.ListStore(); + this.store.set_column_types([GObject.TYPE_STRING, GObject.TYPE_INT]); + this.store.filter_new(null); + this.treeView.model = this.store; + let _row = this.accountsChooser.get_selected_row(); monitoLog('Active:' + _row.server); let _account_settings = getAccountSettings ( _row.server ); @@ -541,15 +548,30 @@ function setColor ( color ) function createColumnRow ( ) { monitoLog ( '> Create column row' ); - _item = _store.append(null); - _store.set_value(_item, 0, 'bar' ); - _store.set_value(_item, 1, 1 ); - + let _item = this.store.append(null); + this.store.set_value(_item, 0, 'bar' ); + this.store.set_value(_item, 1, 1 ); } -function removeColumnRow ( ) { +function removeColumnRow ( widget ) { monitoLog ( '> Remove column row' ); + let [any, model, _iter] = this.treeView.get_selection().get_selected ( ); + this.store.remove ( _iter ); +} + + +function editColumn ( widget, path, text ) +{ + monitoLog ( '> Edit column row ' + widget.col + ', ' + path + ', ' + text ) + let _iter = this.store.get_iter ( Gtk.TreePath.new_from_string ( path ) ); + monitoLog ( '> Iter ' + _iter[1] ); + if ( widget.col == 1 ) + this.store.set_value(_iter[1], widget.col, parseInt(text) ); + else + this.store.set_value(_iter[1], widget.col, text ); + + return true; }