Share duplicate code substituting partitions in multiple operations (#755214)

The apply_to_visual() method for the change UUID, format, label file
system and name partition operations duplicated identical code.  This
code was just substituting the partition in the disk graphic vector with
the new partition recorded in the operation, as none of these operations
change the partition boundaries.  Move this duplicate code into the
parent class in new method Operation::substitute_new().

Bug 755214 - Refactor operation merging
This commit is contained in:
Mike Fleetwood 2015-09-26 14:25:58 +01:00 committed by Curtis Gedak
parent 9b497aae14
commit 27cbe36d0f
6 changed files with 28 additions and 65 deletions

View File

@ -63,6 +63,7 @@ protected:
int find_index_new( const std::vector<Partition> & partitions );
int find_index_extended( const std::vector<Partition> & partitions ) ;
void insert_unallocated( std::vector<Partition> & partitions, Sector start, Sector end, Byte_Value sector_size, bool inside_extended );
void substitute_new( std::vector<Partition> & partitions );
int index ;
int index_extended ;

View File

@ -105,4 +105,27 @@ void Operation::insert_unallocated( std::vector<Partition> & partitions, Sector
}
}
// Visual re-apply this operation, for operations which don't change the partition
// boundaries. Matches this operation's original partition in the vector and substitutes
// it with this operation's new partition.
void Operation::substitute_new( std::vector<Partition> & partitions )
{
if ( partition_original.inside_extended )
{
index_extended = find_index_extended( partitions );
if ( index_extended >= 0 )
{
index = find_index_original( partitions[index_extended].logicals );
if ( index >= 0 )
partitions[index_extended].logicals[index] = partition_new;
}
}
else
{
index = find_index_original( partitions );
if ( index >= 0 )
partitions[index] = partition_new;
}
}
} //GParted

View File

@ -33,23 +33,7 @@ OperationChangeUUID::OperationChangeUUID( const Device & device
void OperationChangeUUID::apply_to_visual( std::vector<Partition> & partitions )
{
if ( partition_original .inside_extended )
{
index_extended = find_index_extended( partitions ) ;
if ( index_extended >= 0 )
index = find_index_original( partitions[ index_extended ] .logicals ) ;
if ( index >= 0 )
partitions[ index_extended ] .logicals[ index ] = partition_new ;
}
else
{
index = find_index_original( partitions ) ;
if ( index >= 0 )
partitions[ index ] = partition_new ;
}
substitute_new( partitions );
}
void OperationChangeUUID::create_description()

View File

@ -47,22 +47,9 @@ void OperationFormat::apply_to_visual( std::vector<Partition> & partitions )
false );
partitions.push_back( temp_partition );
}
else if ( partition_original.inside_extended )
{
index_extended = find_index_extended( partitions ) ;
if ( index_extended >= 0 )
index = find_index_original( partitions[ index_extended ] .logicals ) ;
if ( index >= 0 )
partitions[ index_extended ] .logicals[ index ] = partition_new ;
}
else
{
index = find_index_original( partitions ) ;
if ( index >= 0 )
partitions[ index ] = partition_new ;
substitute_new( partitions );
}
}

View File

@ -32,23 +32,7 @@ OperationLabelFileSystem::OperationLabelFileSystem( const Device & device,
void OperationLabelFileSystem::apply_to_visual( std::vector<Partition> & partitions )
{
if ( partition_original .inside_extended )
{
index_extended = find_index_extended( partitions ) ;
if ( index_extended >= 0 )
index = find_index_original( partitions[ index_extended ] .logicals ) ;
if ( index >= 0 )
partitions[ index_extended ] .logicals[ index ] = partition_new ;
}
else
{
index = find_index_original( partitions ) ;
if ( index >= 0 )
partitions[ index ] = partition_new ;
}
substitute_new( partitions );
}
void OperationLabelFileSystem::create_description()

View File

@ -32,23 +32,7 @@ OperationNamePartition::OperationNamePartition( const Device & device,
void OperationNamePartition::apply_to_visual( std::vector<Partition> & partitions )
{
if ( partition_original.inside_extended )
{
index_extended = find_index_extended( partitions );
if ( index_extended >= 0 )
index = find_index_original( partitions[index_extended].logicals );
if ( index >= 0 )
partitions[index_extended].logicals[index] = partition_new;
}
else
{
index = find_index_original( partitions );
if ( index >= 0 )
partitions[index] = partition_new;
}
substitute_new( partitions );
}
void OperationNamePartition::create_description()