GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Selecting part of a string in a gtkcellrenderer

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
colossus73
Familiar Face


Joined: 18 Aug 2008
Posts: 13

PostPosted: Fri Aug 22, 2008 11:46 am    Post subject: Selecting part of a string in a gtkcellrenderer Reply with quote

Hi,

I want to select a string in a cell of a treeview. The string contains a dot so I want to select all the characters before the dot. I have this code:

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

void xa_rename_cell_editing_started (GtkCellRenderer *cell,GtkCellEditable *editable,const gchar *path,XArchive *archive)
{
    GtkEntry *gtk_entry;
    gchar *text;
    XEntry *entry;
    glong offset;
    GtkTreeModel *model;
    GtkTreeIter iter;

    if (GTK_IS_ENTRY (editable))
    {
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(archive->treeview));
        gtk_tree_model_get_iter_from_string(model,&iter,path);
        gtk_tree_model_get(model,&iter,archive->nc+1,&entry,-1);
        text = g_utf8_strrchr (entry->filename,-1,'.');
        if (G_LIKELY (text != NULL))
        {
            gtk_entry = GTK_ENTRY (editable);
            gtk_widget_grab_focus (GTK_WIDGET(gtk_entry));
            offset = g_utf8_pointer_to_offset (entry->filename,text);
            if (G_LIKELY (offset > 0))
                gtk_editable_select_region (GTK_EDITABLE(editable),0,offset);
        }
    }
}

offset is > 0 but the cell is selected completely not up to the dot. Where am I wrong?
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 526
Location: Falun, WI USA

PostPosted: Fri Aug 22, 2008 5:51 pm    Post subject: Reply with quote

there's nothing wrong with your code, but I believe that that signal is mostly meant for setting up things like entry completions,
setting the text position doesn't work because I believe that gtk_cell_renderer_text_start_editing is called after your function,
see here:
http://svn.gnome.org/viewvc/gtk%2B/trunk/gtk/gtkcellrenderertext.c?revision=21089&view=markup
Back to top
colossus73
Familiar Face


Joined: 18 Aug 2008
Posts: 13

PostPosted: Sat Aug 23, 2008 6:37 am    Post subject: Reply with quote

dreblen wrote:
there's nothing wrong with your code, but I believe that that signal is mostly meant for setting up things like entry completions,
setting the text position doesn't work because I believe that gtk_cell_renderer_text_start_editing is called after your function,


So there is no chance to intervene before the signal is fired?
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 526
Location: Falun, WI USA

PostPosted: Sat Aug 23, 2008 2:27 pm    Post subject: Reply with quote

you might be able to make your own class deriving from GtkCellRendererText and then change cell_class->start_editing to your own function,
however I don't really know enough about the GtkCellRenderer class to be of much help in doing that
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP