Пример #1
0
void
init_list	(GtkWidget *window)
{

  GtkListStore *model;
  GtkWidget *view;
  GtkTreeViewColumn *column;
  GtkCellRenderer *cell_renderer;



  /* Create a model.  We are using the store model for now, though we
 *    * could use any other GtkTreeModel */
  model = gtk_list_store_new (N_COLUMNS, G_TYPE_POINTER, G_TYPE_INT);
puts("model created");

  /* Create a view */
  view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
puts("view created");

  /* The view now holds a reference.  We can get rid of our own
 *    * reference */
  g_object_unref (G_OBJECT (model));

  /* Create a cell render and arbitrarily make it red for demonstration
 *    * purposes */
  cell_renderer = gtk_cell_renderer_text_new ();
  g_object_set (G_OBJECT (cell_renderer), "foreground", "red", NULL);
puts("cell renderer created");

  /* Create a column, associating the "text" attribute of the
 *    * cell_renderer to the first column of the model */
/*  column = gtk_tree_view_column_new_with_attributes ("title",
						     cell_renderer,
						     "text", COLUMN_ONE,
						     NULL);
*/
  column = gtk_tree_view_column_new_with_attributes ("title", cell_renderer, NULL);
puts("column created");
  gtk_tree_view_column_set_cell_data_func (column, cell_renderer,render_name ,NULL,NULL);
puts("datafunc set");

  /* Add the column to the view. */
  gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
puts("column appended");


  gtk_widget_show (GTK_WIDGET(view));
puts("view shown");
  gtk_container_add (GTK_CONTAINER(window), view);
puts("view inserted");

  /* custom function to fill the model with data */
  populate_tree_model (model);
puts("model populated");

}
Пример #2
0
/* Delete the currently selected file or folder. Folders will only be removed if
 * it does not include any content. */
void 
on_delete_clicked (GtkToolButton *item)
{
  GtkWidget *entry, *treeview, *dialog, *window;
  GtkTreeSelection *selection;
  GtkTreeModel *model;
  GtkTreeIter iter;
  GString *location;
  GList *temp;
  gchar *file;
  
  entry = glade_xml_get_widget (xml, "location");
  treeview = glade_xml_get_widget (xml, "treeview");
  window = glade_xml_get_widget (xml, "window");
  location = g_string_new ("/");
  temp = current_path;
  
  /* Create the current path out of the content of current_path. */
  while (temp != NULL)
  {
    g_string_append_printf (location, "%s/", (gchar*) temp->data);
    temp = temp->next;
  }

  /* If there is a selected file, delete it if the user approves. */
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
  if (gtk_tree_selection_get_selected (selection, &model, &iter))
  {
    gtk_tree_model_get (model, &iter, FILENAME, &file, -1);
    if (g_ascii_strcasecmp (file, "..") == 0)
    {
      file_manager_error ("You cannot remove the '..' directory!");
      return;
    }

    gtk_entry_set_text (GTK_ENTRY (entry), location->str);
    g_string_append (location, file);
    
    /* Ask the user if it is okay to remove the file or folder. */
    dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_MODAL, 
                                     GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
                                     "Do you really want to delete %s?", file);
    
    /* If the user approves, remove the file or report if it can't be done. */
    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
      if (g_remove (location->str) != 0)
        file_manager_error ("The file or folder could not be removed!");
    gtk_widget_destroy (dialog);
    populate_tree_model (NULL);
  }
  
  g_string_free (location, TRUE);
}
Пример #3
0
/* Add the tree store, but the actual content is setup in populate_tree_model(). */
static void
setup_tree_model (GtkWidget *treeview)
{
  GtkListStore *store;
  
  store = gtk_list_store_new (COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING,
                              G_TYPE_STRING, G_TYPE_STRING);
  gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
  g_object_unref (store);
  
  populate_tree_model (treeview);
}
Пример #4
0
/* When a row is activated, either move to the desired location or show
 * more information if the file is not a directory. */
void 
on_row_activated (GtkTreeView *treeview,
                  GtkTreePath *path,
                  GtkTreeViewColumn *column) 
{
  GtkTreeModel *model;
  GtkTreeIter iter;
  gchar *file;

  model = gtk_tree_view_get_model (treeview);
  if (gtk_tree_model_get_iter (model, &iter, path))
  {
    gtk_tree_model_get (model, &iter, FILENAME, &file, -1);
    
    /* Move to the parent directory. */
    if (g_ascii_strcasecmp ("..", file) == 0)
    {
      GList *last = g_list_last (current_path);
      store_history ();
      current_path = g_list_remove_link (current_path, last);
      g_list_free_1 (last);
      populate_tree_model (GTK_WIDGET (treeview));
    }
    /* Move to the chosen directory or show more information about the file. */
    else
    {
      gchar *location = path_to_string ();   

      if (g_file_test (g_strconcat (location, "/", file, NULL), G_FILE_TEST_IS_DIR))
      {
        store_history ();
        current_path = g_list_append (current_path, file);
        populate_tree_model (GTK_WIDGET (treeview));
      }
      else
        on_info_clicked (NULL);  
    }
  }
}
Пример #5
0
/* Visit the next location in the history list. */
void
on_forward_clicked (GtkToolButton *item)
{
  GtkWidget *treeview;
  GString *str;

  if (history_pos + 1 < history->len)
  {
    history_pos++;
    treeview = glade_xml_get_widget (xml, "treeview");
    str = g_string_new ((gchar*) g_ptr_array_index (history, history_pos));
    parse_location (str);
    populate_tree_model (GTK_WIDGET (treeview));
  }
}
Пример #6
0
/* Visit the previous location in the history list. */
void 
on_back_clicked (GtkToolButton *item)
{
  GtkWidget *treeview;

  if (history_pos >= 0)
  {
    /* Store the current location at the end of the list. */
    if (history_pos + 1 == history->len)
      store_history();

    treeview = glade_xml_get_widget (xml, "treeview");
    parse_location (g_string_new ((gchar*) history->pdata[history_pos]));
    populate_tree_model (GTK_WIDGET (treeview));

    if (history_pos > 0)
      history_pos--;
  }
}
Пример #7
0
/* Go to the address bar location when the button is clicked. */
void 
on_go_clicked (GtkButton *button) 
{
  GtkWidget *entry, *treeview;
  GString *location;
  
  entry = glade_xml_get_widget (xml, "location");
  treeview = glade_xml_get_widget (xml, "treeview");
  location = g_string_new (gtk_entry_get_text (GTK_ENTRY (entry)));
  
  /* If the directory exists, visit the entered location. */
  if (g_file_test (location->str, G_FILE_TEST_IS_DIR))
  {
    store_history ();
    parse_location (location);
    populate_tree_model (GTK_WIDGET (treeview));
  }
  else
    file_manager_error ("The location does not exist!");
  
  g_string_free (location, TRUE);
}
Пример #8
0
/* Refresh the content of the current location. */
void 
on_refresh_clicked (GtkToolButton *item)
{
  GtkWidget *treeview = glade_xml_get_widget (xml, "treeview");
  populate_tree_model (treeview);
}