[gparted] Don't rely on unformatted being the last file system type



commit a97f1240fb94eabd971d074822ca6ecf24cbdc46
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sun Feb 28 14:51:21 2021 +0000

    Don't rely on unformatted being the last file system type
    
    ... in Dialog_Partition_New::build_filesystems_combo().  set_data()
    populates this->FILESYSTEMS[] vector with supported file systems with
    cleared, unformatted and extended added to the end.  Then
    build_filesystems_combo() adds those items to combo_filesystem, skipping
    extended.  It then makes the last item in the combobox sensitive,
    relying on the fact that it is unformatted.
    
    Refactor the code so build_filesystems_combo() no longer relies on
    unformatted being the last item in combo_filesystem to always enable it.

 src/Dialog_Partition_New.cc | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index 0be9db43..5e1cfaf4 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -408,16 +408,29 @@ void Dialog_Partition_New::build_filesystems_combo(bool only_unformatted)
        combo_filesystem.items().clear();
 
        bool set_first=false;
-       //fill the file system menu with the file systems (except for extended) 
+       // Fill the file system combobox
        for ( unsigned int t = 0 ; t < FILESYSTEMS .size( ) ; t++ ) 
        {
-               //skip extended
+               // Skip extended which is only added by combobox_changed() while partition
+               // type = extended.
                if (FILESYSTEMS[t].fstype == FS_EXTENDED)
                        continue ;
+
                combo_filesystem.items().push_back(Utils::get_filesystem_string(FILESYSTEMS[t].fstype));
-               combo_filesystem.items().back().set_sensitive(
-                       ! only_unformatted && FILESYSTEMS[ t ] .create &&
-                       new_partition->get_byte_length() >= get_filesystem_min_limit(FILESYSTEMS[t].fstype));
+
+               if (FILESYSTEMS[t].fstype == FS_UNFORMATTED)
+               {
+                       // Unformatted is always available
+                       combo_filesystem.items().back().set_sensitive(true);
+               }
+               else
+               {
+                       combo_filesystem.items().back().set_sensitive(
+                               ! only_unformatted                                                            
      &&
+                               FILESYSTEMS[t].create                                                         
      &&
+                               new_partition->get_byte_length() >= 
get_filesystem_min_limit(FILESYSTEMS[t].fstype)   );
+               }
+
                //use ext4/3/2 as first/second/third choice default file system
                //(Depends on ordering in FILESYSTEMS for preference)
                if ((FILESYSTEMS[t].fstype == FS_EXT2 ||
@@ -429,9 +442,6 @@ void Dialog_Partition_New::build_filesystems_combo(bool only_unformatted)
                        set_first=true;
                }
        }
-       
-       //unformatted is always available
-       combo_filesystem.items().back().set_sensitive(true);
 
        if(!set_first)
        {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]