replaced hardcoded menu and toolbar indices with variables. This is far

* include/Win_GParted.h,
  src/Win_GParted.cc: replaced hardcoded menu and toolbar indices with
  variables. This is far more flexible and reliable.
This commit is contained in:
Bart Hakvoort 2006-08-20 16:51:18 +00:00
parent 649f26be9f
commit ab8e1b586d
3 changed files with 122 additions and 55 deletions

View File

@ -1,3 +1,9 @@
2006-08-20 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/Win_GParted.h,
src/Win_GParted.cc: replaced hardcoded menu and toolbar indices with
variables. This is far more flexible and reliable.
2006-08-20 Bart Hakvoort <hakvoort@cvs.gnome.org> 2006-08-20 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/GParted_Core.h, * include/GParted_Core.h,

View File

@ -69,47 +69,51 @@ private:
void set_valid_operations() ; void set_valid_operations() ;
//convenience functions //convenience functions
void allow_new( bool b ) { void toggle_item( bool state, int menu_item, int toolbar_item = -1 )
menu_partition .items()[ 0 ] .set_sensitive( b ); {
toolbar_main .get_nth_item( 0 ) ->set_sensitive( b ); } if ( menu_item >= 0 && menu_item < static_cast<int>( menu_partition .items() .size() ) )
menu_partition .items()[ menu_item ] .set_sensitive( state ) ;
void allow_delete( bool b ) { if ( toolbar_item >= 0 && toolbar_item < toolbar_main .get_n_items() )
menu_partition .items()[ 1 ] .set_sensitive( b ); toolbar_main .get_nth_item( toolbar_item ) ->set_sensitive( state ) ;
toolbar_main .get_nth_item( 1 ) ->set_sensitive( b ); } }
void allow_resize( bool b ) { void allow_new( bool state ) {
menu_partition .items()[ 3 ] .set_sensitive( b ); toggle_item( state, MENU_NEW, TOOLBAR_NEW ) ; }
toolbar_main .get_nth_item( 3 ) ->set_sensitive( b ); }
void allow_copy( bool b ) { void allow_delete( bool state ) {
menu_partition .items()[ 5 ] .set_sensitive( b ); toggle_item( state, MENU_DEL, TOOLBAR_DEL ) ; }
toolbar_main .get_nth_item( 5 ) ->set_sensitive( b ); }
void allow_paste( bool b ) { void allow_resize( bool state ) {
menu_partition .items()[ 6 ] .set_sensitive( b ); toggle_item( state, MENU_RESIZE_MOVE, TOOLBAR_RESIZE_MOVE ) ; }
toolbar_main .get_nth_item( 6 ) ->set_sensitive( b ); }
void allow_format( bool b ) { void allow_copy( bool state ) {
menu_partition .items()[ 8 ] .set_sensitive( b ); } toggle_item( state, MENU_COPY, TOOLBAR_COPY ) ; }
void allow_toggle_swap_mount_state( bool b ) { void allow_paste( bool state ) {
menu_partition .items()[ 10 ] .set_sensitive( b ); } toggle_item( state, MENU_PASTE, TOOLBAR_PASTE ) ; }
void allow_manage_flags( bool b ) { void allow_format( bool state ) {
menu_partition .items()[ 13 ] .set_sensitive( b ) ; } toggle_item( state, MENU_FORMAT ) ; }
void allow_info( bool b ) { void allow_toggle_swap_mount_state( bool state ) {
menu_partition .items()[ 15 ] .set_sensitive( b ); } toggle_item( state, MENU_TOGGLE_MOUNT_SWAP ) ; }
void allow_undo( bool b ) { void allow_manage_flags( bool state ) {
toolbar_main .get_nth_item( 8 ) ->set_sensitive( b ); toggle_item( state, MENU_FLAGS ) ; }
void allow_info( bool state ) {
toggle_item( state, MENU_INFO ) ; }
void allow_undo( bool state ) {
toggle_item( state, -1, TOOLBAR_UNDO ) ;
static_cast<Gtk::CheckMenuItem *>( & menubar_main .items()[ 1 ] .get_submenu() ->items()[ 0 ] ) static_cast<Gtk::CheckMenuItem *>( & menubar_main .items()[ 1 ] .get_submenu() ->items()[ 0 ] )
->set_sensitive( b ) ; } ->set_sensitive( state ) ; }
void allow_apply( bool b ) { void allow_apply( bool state ) {
toolbar_main .get_nth_item( 9 ) ->set_sensitive( b ); toggle_item( state, -1, TOOLBAR_APPLY ) ;
static_cast<Gtk::CheckMenuItem *>( & menubar_main .items()[ 1 ] .get_submenu() ->items()[ 1 ] ) static_cast<Gtk::CheckMenuItem *>( & menubar_main .items()[ 1 ] .get_submenu() ->items()[ 1 ] )
->set_sensitive( b ) ; } ->set_sensitive( state ) ; }
//threads.. //threads..
void thread_refresh_devices() ; void thread_refresh_devices() ;
@ -221,6 +225,21 @@ private:
}; };
treeview_operations_Columns treeview_operations_columns; treeview_operations_Columns treeview_operations_columns;
//indices for partitionmenu and toolbar
int
MENU_NEW, TOOLBAR_NEW,
MENU_DEL, TOOLBAR_DEL,
MENU_RESIZE_MOVE, TOOLBAR_RESIZE_MOVE,
MENU_COPY, TOOLBAR_COPY,
MENU_PASTE, TOOLBAR_PASTE,
MENU_FORMAT,
MENU_TOGGLE_MOUNT_SWAP,
MENU_MOUNT,
MENU_FLAGS,
MENU_INFO,
TOOLBAR_UNDO,
TOOLBAR_APPLY ;
//usefull variables which are used by many different functions... //usefull variables which are used by many different functions...
int index_extended ; //position of the extended partition (-1 means there isn't one) int index_extended ; //position of the extended partition (-1 means there isn't one)
unsigned short primary_count ;//primary_count checks for max. of 4 pimary partitions unsigned short primary_count ;//primary_count checks for max. of 4 pimary partitions

View File

@ -48,6 +48,19 @@ Win_GParted::Win_GParted( const std::vector<Glib::ustring> & user_devices )
OPERATIONSLIST_OPEN = true ; OPERATIONSLIST_OPEN = true ;
gparted_core .set_user_devices( user_devices ) ; gparted_core .set_user_devices( user_devices ) ;
MENU_NEW = TOOLBAR_NEW =
MENU_DEL = TOOLBAR_DEL =
MENU_RESIZE_MOVE = TOOLBAR_RESIZE_MOVE =
MENU_COPY = TOOLBAR_COPY =
MENU_PASTE = TOOLBAR_PASTE =
MENU_FORMAT =
MENU_TOGGLE_MOUNT_SWAP =
MENU_MOUNT =
MENU_FLAGS =
MENU_INFO =
TOOLBAR_UNDO =
TOOLBAR_APPLY = -1 ;
//==== GUI ========================= //==== GUI =========================
this ->set_title( _("GParted") ); this ->set_title( _("GParted") );
this ->set_default_size( 775, 500 ); this ->set_default_size( 775, 500 );
@ -108,8 +121,6 @@ Win_GParted::Win_GParted( const std::vector<Glib::ustring> & user_devices )
void Win_GParted::init_menubar() void Win_GParted::init_menubar()
{ {
//FIXME: store menuindex in variables, so we don't have to use these numbers everywhere
//see my local version of the installerpatch for details.
//fill menubar_main and connect callbacks //fill menubar_main and connect callbacks
//gparted //gparted
menu = manage( new Gtk::Menu() ) ; menu = manage( new Gtk::Menu() ) ;
@ -156,49 +167,60 @@ void Win_GParted::init_menubar()
void Win_GParted::init_toolbar() void Win_GParted::init_toolbar()
{ {
int index = 0 ;
//initialize and pack toolbar_main //initialize and pack toolbar_main
hbox_toolbar.pack_start( toolbar_main ); hbox_toolbar.pack_start( toolbar_main );
//NEW and DELETE //NEW and DELETE
toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::NEW)); toolbutton = Gtk::manage( new Gtk::ToolButton( Gtk::Stock::NEW ) );
toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_new) ); toolbutton ->signal_clicked() .connect( sigc::mem_fun( *this, &Win_GParted::activate_new ) );
toolbar_main.append(*toolbutton); toolbar_main .append( *toolbutton );
TOOLBAR_NEW = index++ ;
toolbutton ->set_tooltip(tooltips, _("Create a new partition in the selected unallocated space") ); toolbutton ->set_tooltip(tooltips, _("Create a new partition in the selected unallocated space") );
toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::DELETE)); toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::DELETE));
toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_delete) ); toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_delete) );
toolbar_main.append(*toolbutton); toolbar_main.append(*toolbutton);
TOOLBAR_DEL = index++ ;
toolbutton ->set_tooltip(tooltips, _("Delete the selected partition") ); toolbutton ->set_tooltip(tooltips, _("Delete the selected partition") );
toolbar_main.append( *(Gtk::manage(new Gtk::SeparatorToolItem)) ); toolbar_main.append( *(Gtk::manage(new Gtk::SeparatorToolItem)) );
index++ ;
//RESIZE/MOVE //RESIZE/MOVE
image = manage( new Gtk::Image( Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_BUTTON ) ); image = manage( new Gtk::Image( Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_BUTTON ) );
toolbutton = Gtk::manage(new Gtk::ToolButton( *image, _("Resize/Move") )); toolbutton = Gtk::manage(new Gtk::ToolButton( *image, _("Resize/Move") ));
toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_resize) ); toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_resize) );
toolbar_main.append(*toolbutton); toolbar_main.append(*toolbutton);
TOOLBAR_RESIZE_MOVE = index++ ;
toolbutton ->set_tooltip(tooltips, _("Resize/Move the selected partition") ); toolbutton ->set_tooltip(tooltips, _("Resize/Move the selected partition") );
toolbar_main.append( *(Gtk::manage(new Gtk::SeparatorToolItem)) ); toolbar_main.append( *(Gtk::manage(new Gtk::SeparatorToolItem)) );
index++ ;
//COPY and PASTE //COPY and PASTE
toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::COPY)); toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::COPY));
toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_copy) ); toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_copy) );
toolbar_main.append(*toolbutton); toolbar_main.append(*toolbutton);
TOOLBAR_COPY = index++ ;
toolbutton ->set_tooltip(tooltips, _("Copy the selected partition to the clipboard") ); toolbutton ->set_tooltip(tooltips, _("Copy the selected partition to the clipboard") );
toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::PASTE)); toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::PASTE));
toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_paste) ); toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_paste) );
toolbar_main.append(*toolbutton); toolbar_main.append(*toolbutton);
TOOLBAR_PASTE = index++ ;
toolbutton ->set_tooltip(tooltips, _("Paste the partition from the clipboard") ); toolbutton ->set_tooltip(tooltips, _("Paste the partition from the clipboard") );
toolbar_main.append( *(Gtk::manage(new Gtk::SeparatorToolItem)) ); toolbar_main.append( *(Gtk::manage(new Gtk::SeparatorToolItem)) );
index++ ;
//UNDO and APPLY //UNDO and APPLY
toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::UNDO)); toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::UNDO));
toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_undo) ); toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_undo) );
toolbar_main.append(*toolbutton); toolbar_main.append(*toolbutton);
TOOLBAR_UNDO = index++ ;
toolbutton ->set_sensitive( false ); toolbutton ->set_sensitive( false );
toolbutton ->set_tooltip(tooltips, _("Undo last operation") ); toolbutton ->set_tooltip(tooltips, _("Undo last operation") );
toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::APPLY)); toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::APPLY));
toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_apply) ); toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_apply) );
toolbar_main.append(*toolbutton); toolbar_main.append(*toolbutton);
TOOLBAR_APPLY = index++ ;
toolbutton ->set_sensitive( false ); toolbutton ->set_sensitive( false );
toolbutton ->set_tooltip(tooltips, _("Apply all operations") ); toolbutton ->set_tooltip(tooltips, _("Apply all operations") );
@ -217,34 +239,44 @@ void Win_GParted::init_toolbar()
void Win_GParted::init_partition_menu() void Win_GParted::init_partition_menu()
{ {
int index = 0 ;
//fill menu_partition //fill menu_partition
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::NEW, Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::NEW,
sigc::mem_fun(*this, &Win_GParted::activate_new) ) ); sigc::mem_fun(*this, &Win_GParted::activate_new) ) );
MENU_NEW = index++ ;
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::DELETE, Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::DELETE,
Gtk::AccelKey( GDK_Delete, Gdk::BUTTON1_MASK ), Gtk::AccelKey( GDK_Delete, Gdk::BUTTON1_MASK ),
sigc::mem_fun(*this, &Win_GParted::activate_delete) ) ); sigc::mem_fun(*this, &Win_GParted::activate_delete) ) );
MENU_DEL = index++ ;
menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ); menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() );
index++ ;
image = manage( new Gtk::Image( Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_MENU ) ); image = manage( new Gtk::Image( Gtk::Stock::GOTO_LAST, Gtk::ICON_SIZE_MENU ) );
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::ImageMenuElem( _("_Resize/Move"), Gtk::Menu_Helpers::ImageMenuElem( _("_Resize/Move"),
*image, *image,
sigc::mem_fun(*this, &Win_GParted::activate_resize) ) ); sigc::mem_fun(*this, &Win_GParted::activate_resize) ) );
MENU_RESIZE_MOVE = index++ ;
menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ); menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() );
index++ ;
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::COPY, Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::COPY,
sigc::mem_fun(*this, &Win_GParted::activate_copy) ) ); sigc::mem_fun(*this, &Win_GParted::activate_copy) ) );
MENU_COPY = index++ ;
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::PASTE, Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::PASTE,
sigc::mem_fun(*this, &Win_GParted::activate_paste) ) ); sigc::mem_fun(*this, &Win_GParted::activate_paste) ) );
MENU_PASTE = index++ ;
menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ); menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() );
index++ ;
image = manage( new Gtk::Image( Gtk::Stock::CONVERT, Gtk::ICON_SIZE_MENU ) ); image = manage( new Gtk::Image( Gtk::Stock::CONVERT, Gtk::ICON_SIZE_MENU ) );
/*TO TRANSLATORS: menuitem which holds a submenu with filesystems.. */ /*TO TRANSLATORS: menuitem which holds a submenu with filesystems.. */
@ -252,28 +284,36 @@ void Win_GParted::init_partition_menu()
Gtk::Menu_Helpers::ImageMenuElem( _("_Format to"), Gtk::Menu_Helpers::ImageMenuElem( _("_Format to"),
*image, *image,
* create_format_menu() ) ) ; * create_format_menu() ) ) ;
MENU_FORMAT = index++ ;
menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ); menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ) ;
index++ ;
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::MenuElem( _("unmount"), Gtk::Menu_Helpers::MenuElem( _("unmount"),
sigc::mem_fun( *this, &Win_GParted::toggle_swap_mount_state ) ) ); sigc::mem_fun( *this, &Win_GParted::toggle_swap_mount_state ) ) );
MENU_TOGGLE_MOUNT_SWAP = index++ ;
/*TO TRANSLATORS: menuitem which holds a submenu with mountpoints.. */ /*TO TRANSLATORS: menuitem which holds a submenu with mountpoints.. */
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::MenuElem( _("mount on"), * manage( new Gtk::Menu() ) ) ) ; Gtk::Menu_Helpers::MenuElem( _("mount on"), * manage( new Gtk::Menu() ) ) ) ;
MENU_MOUNT = index++ ;
menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ) ; menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ) ;
index++ ;
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::MenuElem( _("manage flags"), Gtk::Menu_Helpers::MenuElem( _("manage flags"),
sigc::mem_fun( *this, &Win_GParted::activate_manage_flags ) ) ); sigc::mem_fun( *this, &Win_GParted::activate_manage_flags ) ) );
MENU_FLAGS = index++ ;
menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ) ; menu_partition .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ) ;
index++ ;
menu_partition .items() .push_back( menu_partition .items() .push_back(
Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::DIALOG_INFO, Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::DIALOG_INFO,
sigc::mem_fun(*this, &Win_GParted::activate_info) ) ); sigc::mem_fun(*this, &Win_GParted::activate_info) ) );
MENU_INFO = index++ ;
menu_partition .accelerate( *this ) ; menu_partition .accelerate( *this ) ;
} }
@ -719,9 +759,11 @@ void Win_GParted::set_valid_operations()
allow_paste( false ); allow_format( false ); allow_toggle_swap_mount_state( false ) ; allow_paste( false ); allow_format( false ); allow_toggle_swap_mount_state( false ) ;
allow_manage_flags( false ) ; allow_info( false ) ; allow_manage_flags( false ) ; allow_info( false ) ;
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 10 ] .get_child() ) ->set_label( _("unmount") ) ; dynamic_cast<Gtk::Label*>( menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() )
menu_partition .items()[ 10 ] .show() ; ->set_label( _("unmount") ) ;
menu_partition .items()[ 11 ] .hide() ;
menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .show() ;
menu_partition .items()[ MENU_MOUNT ] .hide() ;
//no partition selected... //no partition selected...
if ( ! selected_partition .get_paths() .size() ) if ( ! selected_partition .get_paths() .size() )
@ -742,13 +784,13 @@ void Win_GParted::set_valid_operations()
if ( selected_partition .busy ) if ( selected_partition .busy )
{ {
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 10 ] .get_child() ) dynamic_cast<Gtk::Label*>(menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() )
->set_label( _("swapoff") ) ; ->set_label( _("swapoff") ) ;
return ; return ;
} }
else else
dynamic_cast<Gtk::Label*>(menu_partition .items()[ 10 ] .get_child() ) dynamic_cast<Gtk::Label*>(menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() )
->set_label( _("swapon") ) ; ->set_label( _("swapon") ) ;
} }
@ -816,7 +858,7 @@ void Win_GParted::set_valid_operations()
{ {
allow_toggle_swap_mount_state( true ) ; allow_toggle_swap_mount_state( true ) ;
menu = menu_partition .items()[ 11 ] .get_submenu() ; menu = menu_partition .items()[ MENU_MOUNT ] .get_submenu() ;
menu ->items() .clear() ; menu ->items() .clear() ;
for ( unsigned int t = 0 ; t < selected_partition .get_mountpoints() .size() ; t++ ) for ( unsigned int t = 0 ; t < selected_partition .get_mountpoints() .size() ; t++ )
{ {
@ -828,8 +870,8 @@ void Win_GParted::set_valid_operations()
dynamic_cast<Gtk::Label*>( menu ->items() .back() .get_child() ) ->set_use_underline( false ) ; dynamic_cast<Gtk::Label*>( menu ->items() .back() .get_child() ) ->set_use_underline( false ) ;
} }
menu_partition .items()[ 10 ] .hide() ; menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .hide() ;
menu_partition .items()[ 11 ] .show() ; menu_partition .items()[ MENU_MOUNT ] .show() ;
} }
//see if there is an copied partition and if it passes all tests //see if there is an copied partition and if it passes all tests
@ -1037,8 +1079,8 @@ void Win_GParted::menu_gparted_features()
dialog .load_filesystems( gparted_core .get_filesystems() ) ; dialog .load_filesystems( gparted_core .get_filesystems() ) ;
//recreate format menu... //recreate format menu...
menu_partition .items()[ 8 ] .remove_submenu() ; menu_partition .items()[ MENU_FORMAT ] .remove_submenu() ;
menu_partition .items()[ 8 ] .set_submenu( * create_format_menu() ) ; menu_partition .items()[ MENU_FORMAT ] .set_submenu( * create_format_menu() ) ;
menu_partition .show_all_children() ; menu_partition .show_all_children() ;
} }
} }