gparted/include/TreeView_Detail.h

104 lines
3.6 KiB
C
Raw Normal View History

2004-09-19 14:24:53 -06:00
/* Copyright (C) 2004 Bart
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
2004-09-19 14:24:53 -06:00
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
2004-09-19 14:24:53 -06:00
*/
#ifndef GPARTED_TREEVIEW_DETAIL_H
#define GPARTED_TREEVIEW_DETAIL_H
2004-09-19 14:24:53 -06:00
#include "Partition.h"
#include "PartitionVector.h"
2004-09-19 14:24:53 -06:00
#include <gtkmm/treeview.h>
#include <gtkmm/treestore.h>
#include <gtkmm/entry.h>
#include <gtkmm/stock.h>
#include <gdkmm/pixbuf.h>
#include <vector>
namespace GParted
{
class TreeView_Detail : public Gtk::TreeView
{
public:
TreeView_Detail();
void load_partitions( const PartitionVector & partitions );
void set_selected( const Partition * partition_ptr );
void clear() ;
2004-09-19 14:24:53 -06:00
// Signals for interclass communication
sigc::signal<void, const Partition *, bool> signal_partition_selected;
sigc::signal< void > signal_partition_activated ;
sigc::signal< void, unsigned int, unsigned int > signal_popup_menu ;
2004-09-19 14:24:53 -06:00
private:
void load_partitions( const PartitionVector & partitions,
bool & show_names,
bool & show_mountpoints,
bool & show_labels,
const Gtk::TreeRow & parent_row = Gtk::TreeRow() );
bool set_selected( Gtk::TreeModel::Children rows,
const Partition * partition_ptr, bool inside_extended = false );
void create_row( const Gtk::TreeRow & treerow,
const Partition & partition,
bool & show_names,
bool & show_mountpoints,
bool & show_labels );
2004-09-19 14:24:53 -06:00
//(overridden) signals
bool on_button_press_event( GdkEventButton * event );
void on_row_activated( const Gtk::TreeModel::Path & path, Gtk::TreeViewColumn * column ) ;
void on_selection_changed() ;
2004-09-19 14:24:53 -06:00
Glib::RefPtr<Gtk::TreeStore> treestore_detail;
Glib::RefPtr<Gtk::TreeSelection> treeselection;
bool block ;
2004-09-19 14:24:53 -06:00
//columns for this treeview
struct treeview_detail_Columns : public Gtk::TreeModelColumnRecord
{
Gtk::TreeModelColumn<Glib::ustring> path;
Gtk::TreeModelColumn<Glib::ustring> name;
Gtk::TreeModelColumn<Glib::ustring> filesystem;
Gtk::TreeModelColumn<Glib::ustring> mountpoint;
Gtk::TreeModelColumn<Glib::ustring> label ;
2004-09-19 14:24:53 -06:00
Gtk::TreeModelColumn<Glib::ustring> size;
Gtk::TreeModelColumn<Glib::ustring> used;
Gtk::TreeModelColumn<Glib::ustring> unused;
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > color ;
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > icon1 ;
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > icon2 ;
2004-09-19 14:24:53 -06:00
Gtk::TreeModelColumn<Glib::ustring> flags;
Store pointers to partition objects in TreeView_Details (#750168) This stops copying of each displayed partition object into the TreeView_Details class. It also stops copy constructing lots of partition objects when just clicking on a partition in the disk graphic. The disk graphic needs to inform the main GUI and then the partition list which partition has been selected. The call sequence goes like: DrawingAreaVisualDisk::on_button_press_event(event) Win_GParted::on_partition_selected(partition_ptr, src_is_treeview) TreeView_Detail::set_selected(partition_ptr) TreeView_Detail::set_selected(rows, partition_ptr, inside_extended) Relevant source and highlighted comparison line: 140 bool TreeView_Detail::set_selected( Gtk::TreeModel::Children rows, 141 const Partition * partition_ptr, bool inside_extended ) 142 { 143 for ( unsigned int t = 0 ; t < rows .size() ; t++ ) 144 { >> 145 if ( static_cast<Partition>( rows[t][treeview_detail_columns.partition] ) == *partition_ptr ) 146 { 147 if ( inside_extended ) 148 expand_all() ; 149 150 set_cursor( static_cast<Gtk::TreePath>( rows[ t ] ) ) ; 151 return true ; 152 } 153 154 if ( set_selected( rows[t].children(), partition_ptr, true ) ) 155 return true ; 156 } 157 158 return false ; 159 } Then in this function the partition selected in the disk graphic (partition_ptr parameter) is compared in turn with each partition object stored in the Gtk::TreeView model to find the matching one to mark it as selected. This mere act of accessing the partition object stored in a row of the Gtk::TreeView model causes it to be copy constructed. So clicking on the 5th partition in the disk graphic will copy construct the first 5 partition objects just to do a compare to find the matching one. This is because it is not possible to get a reference from a Gtk:TreeViewProxy in gtkmm. Merely accessing a value in a Gtk::TreeView model takes a copy of that value. Subject: get a reference from a Gtk::TreeValueProxy http://comments.gmane.org/gmane.comp.gnome.gtkmm/2217 http://marc.info/?t=104400417500001&r=1&w=4 Bug 750168 - Reduce the amount of copying of partition objects
2015-05-16 15:36:29 -06:00
Gtk::TreeModelColumn<const Partition *> partition_ptr; // Hidden column. (Alias to element in
// Win_GParted::display_partitions[] vector).
treeview_detail_Columns()
{
add( path ); add( name ); add( filesystem ); add( mountpoint ); add( label );
add( size ); add( used ); add( unused ); add( color );
2016-09-18 14:06:57 -06:00
add( icon1 ); add( icon2 ); add( flags ); add( partition_ptr );
2004-09-19 14:24:53 -06:00
}
};
treeview_detail_Columns treeview_detail_columns;
};
} //GParted
#endif /* GPARTED_TREEVIEW_DETAIL_H */