Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Gtk.NodeView(NodeStore) constructor does not work (but NodeStore property does) #242

Open
dafrito opened this issue Nov 17, 2018 · 1 comment

Comments

@dafrito
Copy link

dafrito commented Nov 17, 2018

Steps to Reproduce

Follow the steps in https://www.mono-project.com/docs/gui/gtksharp/widgets/nodeview-tutorial/

Short version:

  1. Create and show a Gtk2 Window that has within it a NodeView.
  2. When creating the NodeView, assign the Store in the constructor or by setting the NodeStore property.
using System;
using Gtk;

namespace NodeViewTutorial {

[Gtk.TreeNode (ListOnly=true)]
class MyTreeNode : Gtk.TreeNode {
    string song_title;

    public MyTreeNode (string artist, string song_title)
    {
            Artist = artist;
            this.song_title = song_title;
    }

    [Gtk.TreeNodeValue (Column=0)]
    public string Artist;

    [Gtk.TreeNodeValue (Column=1)]
    public string SongTitle {get { return song_title; } }
}

public class NodeViewExample : Gtk.Window {
    public NodeViewExample () : base ("NodeView")
    {
        SetSizeRequest (200,150);

        // Create our TreeView and add it as our child widget
        Gtk.NodeView view = new Gtk.NodeView (Store());
        Add (view);

        // Create a column with title Artist and bind its renderer to model column 0
        view.AppendColumn ("Artist", new Gtk.CellRendererText (), "text", 0);

        // Create a column with title 'Song Title' and bind its renderer to model column 1
        view.AppendColumn ("Song Title", new Gtk.CellRendererText (), "text", 1);
        view.ShowAll ();
    }

    protected override bool OnDeleteEvent (Gdk.Event ev)
    {
        Gtk.Application.Quit ();
        return true;
    }

	Gtk.NodeStore store = null;
	private Gtk.NodeStore Store() {
        if (store == null) {
            store = new Gtk.NodeStore (typeof (MyTreeNode));
            store.AddNode (new MyTreeNode ("The Beatles", "Yesterday"));
            store.AddNode (new MyTreeNode ("Peter Gabriel", "In Your Eyes"));
            store.AddNode (new MyTreeNode ("Rush", "Fly By Night"));
        }
        return store;
    }

	public static void Main ()
	{
			Gtk.Application.Init ();
			NodeViewExample win = new NodeViewExample ();
			win.Show ();
			Gtk.Application.Run ();
	}
}
}

Current Behavior

If the constructor is used to set the NodeStore, no values appear.

If the NodeStore property is used to set the NodeStore, the values appear as in the demo.

Expected Behavior

The constructor should behave the same as the NodeStore property.

On which platforms did you notice this

[ ] macOS
[X] Linux
[ ] Windows

Version Used:

Mono JIT compiler version 4.8.0 (Stable 4.8.0.520/8f6d0f6 Thu Jun 7 07:23:56 UTC 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: normal
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen

$ dnf info gtk-sharp2
Last metadata expiration check: 0:00:24 ago on Fri 16 Nov 2018 09:28:43 PM CST.
Installed Packages
Name : gtk-sharp2
Version : 2.12.45
Release : 4.fc28
Arch : x86_64
Size : 2.8 M
Source : gtk-sharp2-2.12.45-4.fc28.src.rpm
Repo : @System
From repo : fedora
Summary : GTK+ and GNOME bindings for Mono
URL : http://www.mono-project.com/GtkSharp
License : LGPLv2+
Description : This package provides a library that allows you to build
: fully native graphical GNOME applications using Mono. Gtk#
: is a binding to GTK+, the cross platform user interface
: toolkit used in GNOME. It includes bindings for Gtk, Atk,
: Pango, Gdk.

Stacktrace

N/A

Please paste the stack trace here if available.
@marek-safar marek-safar transferred this issue from mono/mono Nov 19, 2018
@awittaker
Copy link

I get this error on xubuntu 18.04...
gtk-sharp2: Installed: 2.12.45-0xamarin14+ubuntu1804b1
Mono JIT compiler version 5.18.1.3
Just to spell out the workaround...

            _nodeView = new NodeView();
            _nodeView.NodeStore = nodeStore;

NB: I am also experiencing issue #267 "NodeView.NodeStore setter not changing underlying field"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants