renderer_text == editable



Hello.

I have few problems with a GtkTreeView (file browser). I'd like it to
have to following functionality: 
- double left click opens the file.
- one column should be editable for renaming the file.
- right click should popup a menu.

Selection mode is GTK_SELECTION_MULTIPLE.
Now several questions:
- Is there a way to let gtk handle all the selection stuff before
  my button-press callback is called? g_signal_connect_after() seems
  to skip my function, so i do all the selection stuff in the callback
  manually before creating the popup menu.
- What is the standard way of selecting when right clicking a row?
  Should this row be selected and all others deselected before creating
  the menu? Or should the selection be modified according to the key
  modifiers? What is a good GUI expected to do?
- If i double click a row then i call the open_file() function, but
  unfortunately also the cell is edited by gtk, how to prevent this?

Here's some of my button_press callback code (C++ style):

gboolean on_button_pressed(GtkTreeView *tv, GdkEventButton *event) {
  node_t* node;

  /* dont handle key mods */
  if (event->state) return FALSE;

  if (!gtk_tree_view_get_path_at_pos(tv, event->x, event->y,
                                     &path, NULL, NULL, NULL)) 
    return FALSE;

  GtkTreeModel* model = gtk_tree_view_get_model(tv);
  GtkTreeSelection* select = gtk_tree_view_get_selection (tv);

  // is current row selected? Is there a gtk function to check this?
  gboolean selected = path_selected(select, path);

  gtk_tree_model_get_iter(model, &iter, path);
  gtk_tree_path_free(path);

  // get the data pointer for this row
  gtk_tree_model_get (model, &iter, 0, &node, -1);

  if (event->button == 1) {
    // double left click
    if (event->type == GDK_2BUTTON_PRESS) {
      open_file(node->file->longname);
      return TRUE;
    }
    return FALSE;
  } else if (event->button == 3) {
    /* unselected selection if current node is not selected
       otherwise simply keep the current selection
    if (!selected) {
      gtk_tree_selection_unselect_all(select);
      gtk_tree_selection_select_iter(select, &iter);
    }
    pop = gui_create_popup_menu(...);
    if (pop) {
      gtk_menu_popup(GTK_MENU(pop), NULL, NULL, NULL, NULL,
                     event->button, event->time);
    }
    return TRUE;
  }
  return FALSE
}

Markus.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]