Use custom text functions for mount/unmount and swapon/swapoff texts

Part 3 of 4 to provide new UUID support for NTFS.

See Bug #667278 - Add support for setting UUID
This commit is contained in:
Rogier Goossens 2012-01-27 12:41:31 -07:00 committed by Curtis Gedak
parent 8735227dd7
commit 170a79b3a0
5 changed files with 65 additions and 31 deletions

View File

@ -94,6 +94,8 @@ enum SIZE_UNIT
enum CUSTOM_TEXT
{
CTEXT_NONE,
CTEXT_ACTIVATE_FILESYSTEM, // Activate text ('Mount', 'Swapon', ...)
CTEXT_DEACTIVATE_FILESYSTEM, // Deactivate text ('Unmount', 'Swapoff', ...)
} ;
//struct to store file system information

View File

@ -28,6 +28,8 @@ namespace GParted
class linux_swap : public FileSystem
{
public:
virtual const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) ;
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void read_label( Partition & partition ) ;

View File

@ -34,7 +34,18 @@ const Glib::ustring FileSystem::get_custom_text( CUSTOM_TEXT ttype, int index )
const Glib::ustring FileSystem::get_generic_text( CUSTOM_TEXT ttype, int index )
{
/*TO TRANSLATORS: these labels will be used in the partition menu */
static const Glib::ustring activate_text = _( "_Mount" ) ;
static const Glib::ustring deactivate_text = _( "_Unmount" ) ;
switch ( ttype ) {
case CTEXT_ACTIVATE_FILESYSTEM :
return index == 0 ? activate_text : "" ;
case CTEXT_DEACTIVATE_FILESYSTEM :
return index == 0 ? deactivate_text : "" ;
default :
return "" ;
}
}
int FileSystem::execute_command( const Glib::ustring & command, OperationDetail & operationdetail )

View File

@ -303,6 +303,7 @@ void Win_GParted::init_toolbar()
void Win_GParted::init_partition_menu()
{
int index = 0 ;
//fill menu_partition
image = manage( new Gtk::Image( Gtk::Stock::NEW, Gtk::ICON_SIZE_MENU ) );
menu_partition .items() .push_back(
@ -356,7 +357,8 @@ void Win_GParted::init_partition_menu()
index++ ;
menu_partition .items() .push_back(
Gtk::Menu_Helpers::MenuElem( _("Unmount"),
//This is a placeholder text. It will be replaced with some other text before it is used
Gtk::Menu_Helpers::MenuElem( "--placeholder--",
sigc::mem_fun( *this, &Win_GParted::toggle_swap_mount_state ) ) );
MENU_TOGGLE_MOUNT_SWAP = index++ ;
@ -904,7 +906,7 @@ void Win_GParted::set_valid_operations()
allow_change_uuid( false ); allow_info( false ) ;
dynamic_cast<Gtk::Label*>( menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() )
->set_label( _("_Unmount") ) ;
->set_label( FileSystem::get_generic_text ( CTEXT_DEACTIVATE_FILESYSTEM ) ) ;
menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .show() ;
menu_partition .items()[ MENU_MOUNT ] .hide() ;
@ -920,33 +922,36 @@ void Win_GParted::set_valid_operations()
if ( selected_partition .type != GParted::TYPE_UNALLOCATED && selected_partition .status == GParted::STAT_REAL )
allow_manage_flags( true ) ;
//deal with swap...
if ( selected_partition .filesystem == GParted::FS_LINUX_SWAP )
{
if ( selected_partition .status == GParted::STAT_REAL )
allow_toggle_swap_mount_state( true ) ;
if ( selected_partition .busy )
{
dynamic_cast<Gtk::Label*>(menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() )
->set_label( _("_Swapoff") ) ;
return ;
}
//Activate / deactivate
if ( gparted_core .get_filesystem_object ( selected_partition .filesystem ) )
dynamic_cast<Gtk::Label*>( menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() )
->set_label( gparted_core .get_filesystem_object ( selected_partition .filesystem )
->get_custom_text ( selected_partition .busy
? CTEXT_DEACTIVATE_FILESYSTEM
: CTEXT_ACTIVATE_FILESYSTEM
)
) ;
else
dynamic_cast<Gtk::Label*>(menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() )
->set_label( _("_Swapon") ) ;
}
dynamic_cast<Gtk::Label*>( menu_partition .items()[ MENU_TOGGLE_MOUNT_SWAP ] .get_child() )
->set_label( FileSystem::get_generic_text ( selected_partition .busy
? CTEXT_DEACTIVATE_FILESYSTEM
: CTEXT_ACTIVATE_FILESYSTEM )
) ;
//only unmount is allowed (if ! extended)
if ( selected_partition .busy )
{
if ( selected_partition .type != GParted::TYPE_EXTENDED &&
selected_partition .filesystem != GParted::FS_LVM2_PV )
//Only permit mount/unmount, swapon/swapoff, ... if action is available
if ( selected_partition .status == GParted::STAT_REAL
&& selected_partition .type != GParted::TYPE_EXTENDED
&& selected_partition .filesystem != GParted::FS_LVM2_PV
&& ( selected_partition .busy
|| selected_partition .get_mountpoints() .size() /* Have mount point(s) */
|| selected_partition .filesystem == GParted::FS_LINUX_SWAP
)
)
allow_toggle_swap_mount_state( true ) ;
//only unmount/swapoff/... is allowed if busy
if ( selected_partition .busy )
return ;
}
//UNALLOCATED
if ( selected_partition .type == GParted::TYPE_UNALLOCATED )
@ -1050,8 +1055,6 @@ void Win_GParted::set_valid_operations()
&& selected_partition .get_mountpoints() .size()
)
{
allow_toggle_swap_mount_state( true ) ;
menu = menu_partition .items()[ MENU_MOUNT ] .get_submenu() ;
menu ->items() .clear() ;
for ( unsigned int t = 0 ; t < selected_partition .get_mountpoints() .size() ; t++ )

View File

@ -22,6 +22,22 @@
namespace GParted
{
const Glib::ustring linux_swap::get_custom_text( CUSTOM_TEXT ttype, int index )
{
/*TO TRANSLATORS: these labels will be used in the partition menu */
static const Glib::ustring activate_text = _( "_Swapon" ) ;
static const Glib::ustring deactivate_text = _( "_Swapoff" ) ;
switch ( ttype ) {
case CTEXT_ACTIVATE_FILESYSTEM :
return index == 0 ? activate_text : "" ;
case CTEXT_DEACTIVATE_FILESYSTEM :
return index == 0 ? deactivate_text : "" ;
default :
return "" ;
}
}
FS linux_swap::get_filesystem_support()
{
FS fs ;