[gparted] Move code visually re-applying create operation into parent class (#755214)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Move code visually re-applying create operation into parent class (#755214)
- Date: Tue, 29 Sep 2015 18:43:19 +0000 (UTC)
commit dc6ffc6a872c2aae80b14cae19ecc5d3513bda35
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sun Sep 27 08:17:15 2015 +0100
Move code visually re-applying create operation into parent class (#755214)
Move the code from OperationCreate::apply_to_visual() into new method
Operation::insert_new() in the parent class. This is in preparation for
the following commit.
Bug 755214 - Refactor operation merging
include/Operation.h | 1 +
src/Operation.cc | 42 ++++++++++++++++++++++++++++++++++++++++++
src/OperationCreate.cc | 41 +----------------------------------------
3 files changed, 44 insertions(+), 40 deletions(-)
---
diff --git a/include/Operation.h b/include/Operation.h
index 26ae43d..7d06893 100644
--- a/include/Operation.h
+++ b/include/Operation.h
@@ -64,6 +64,7 @@ protected:
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 );
+ void insert_new( std::vector<Partition> & partitions );
int index ;
int index_extended ;
diff --git a/src/Operation.cc b/src/Operation.cc
index e55dab5..1f963a8 100644
--- a/src/Operation.cc
+++ b/src/Operation.cc
@@ -128,4 +128,46 @@ void Operation::substitute_new( std::vector<Partition> & partitions )
}
}
+// Visually re-apply this operation, for operations which create new partitions.
+void Operation::insert_new( std::vector<Partition> & partitions )
+{
+ // Create operations are unique in that they apply to unallocated space. It only
+ // matters that the new partition being created fits in an unallocated space when
+ // visually re-applying this operation to the disk graphic. Hence the use of,
+ // find_index_new() here.
+ //
+ // All other operation types apply to existing partitions which do or will exist
+ // on disk. Therefore they match the original partition when visually re-applying
+ // their operations to the disk graphic. Hence their use of,
+ // find_index_original().
+ if ( partition_new.inside_extended )
+ {
+ index_extended = find_index_extended( partitions );
+ if ( index_extended >= 0 )
+ {
+ index = find_index_new( partitions[index_extended].logicals );
+ if ( index >= 0 )
+ {
+ partitions[index_extended].logicals[index] = partition_new;
+
+ insert_unallocated( partitions[index_extended].logicals,
+ partitions[index_extended].sector_start,
+ partitions[index_extended].sector_end,
+ device.sector_size,
+ true );
+ }
+ }
+ }
+ else
+ {
+ index = find_index_new( partitions );
+ if ( index >= 0 )
+ {
+ partitions[index] = partition_new;
+
+ insert_unallocated( partitions, 0, device.length-1, device.sector_size, false );
+ }
+ }
+}
+
} //GParted
diff --git a/src/OperationCreate.cc b/src/OperationCreate.cc
index af5dfa1..abe5b6f 100644
--- a/src/OperationCreate.cc
+++ b/src/OperationCreate.cc
@@ -33,46 +33,7 @@ OperationCreate::OperationCreate( const Device & device,
void OperationCreate::apply_to_visual( std::vector<Partition> & partitions )
{
- // Create operations are unique in that they apply to unallocated space. It only
- // matters that the new partition being created fits in an unallocated space when
- // visually re-applying this operation to the disk graphic. Hence the use of,
- // find_index_new() below.
- //
- // All other operation types apply to existing partitions which do or will exist
- // on disk. Therefore they match the original partition when visually re-applying
- // their operations to the disk graphic. Hence their use of,
- // find_index_original().
- index = index_extended = -1 ;
-
- if ( partition_new.inside_extended )
- {
- index_extended = find_index_extended( partitions ) ;
-
- if ( index_extended >= 0 )
- index = find_index_new( partitions[index_extended].logicals );
-
- if ( index >= 0 )
- {
- partitions[ index_extended ] .logicals[ index ] = partition_new ;
-
- insert_unallocated( partitions[ index_extended ] .logicals,
- partitions[ index_extended ] .sector_start,
- partitions[ index_extended ] .sector_end,
- device .sector_size,
- true ) ;
- }
- }
- else
- {
- index = find_index_new( partitions );
-
- if ( index >= 0 )
- {
- partitions[ index ] = partition_new ;
-
- insert_unallocated( partitions, 0, device .length -1, device .sector_size, false ) ;
- }
- }
+ insert_new( partitions );
}
void OperationCreate::create_description()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]