From a11c16445b167df565d673e01a62389cbae2ea6d Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 28 Feb 2021 15:22:25 +0000 Subject: [PATCH] Rename member variable to default_fs ... in class Dialog_Partition_New and slightly refactor the code in build_filesystems_combo() method which sets it. Change the name from first_creatable_fs to default_fs to be more immediately obvious what the variable represents. As default_fs is used to index the items in the combo_filesystem derived ComboBox, make it's type an int to match the type of the parameter passed to Gtk::ComboBox::set_active() [1]. Initialise default_fs to -1 (no selection) in the class constructor [2], which also allows removal of local variable set_first just used to track whether first_creatable_fs had been assigned yet or not. [1] gtkmm: Gtk::ComboBox Class Reference, set_active() https://developer.gnome.org/gtkmm/stable/classGtk_1_1ComboBox.html#a4f23cf08e85733d23f120935b235096d [2] C++ FAQ / Should my constructors use "initialization lists" or "assignment"? https://isocpp.org/wiki/faq/ctors#init-lists --- include/Dialog_Partition_New.h | 3 ++- src/Dialog_Partition_New.cc | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/Dialog_Partition_New.h b/include/Dialog_Partition_New.h index 77c0aed1..4c97a250 100644 --- a/include/Dialog_Partition_New.h +++ b/include/Dialog_Partition_New.h @@ -66,7 +66,8 @@ private: //signal handlers void combobox_changed(bool combo_type_changed); - unsigned short new_count, first_creatable_fs ; + unsigned short new_count; + int default_fs; }; } //GParted diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc index 5e1cfaf4..74644095 100644 --- a/src/Dialog_Partition_New.cc +++ b/src/Dialog_Partition_New.cc @@ -33,7 +33,7 @@ Dialog_Partition_New::Dialog_Partition_New( const Device & device, bool any_extended, unsigned short new_count, const std::vector & FILESYSTEMS ) - : Dialog_Base_Partition(device) + : Dialog_Base_Partition(device), default_fs(-1) { /*TO TRANSLATORS: dialogtitle */ this ->set_title( _("Create new Partition") ) ; @@ -182,7 +182,7 @@ void Dialog_Partition_New::set_data( const Device & device, // (As the change signal for combo_filesystem has already been connected, // combobox_changed(false) is automatically called by setting the active // selection. This is needed to initialise everything correctly). - combo_filesystem.set_active(first_creatable_fs); + combo_filesystem.set_active(default_fs); //set spinbuttons initial values spinbutton_after .set_value( 0 ) ; @@ -344,7 +344,7 @@ void Dialog_Partition_New::combobox_changed(bool combo_type_changed) else if (combo_type.get_active_row_number() != TYPE_EXTENDED && combo_filesystem.items().size() == FILESYSTEMS.size() ) { - combo_filesystem.set_active(first_creatable_fs); + combo_filesystem.set_active(default_fs); combo_filesystem.items().erase(combo_filesystem.items().back()); combo_filesystem.set_sensitive(true); } @@ -407,7 +407,6 @@ void Dialog_Partition_New::build_filesystems_combo(bool only_unformatted) g_assert( new_partition != NULL ); // Bug: Not initialised by constructor calling set_data() combo_filesystem.items().clear(); - bool set_first=false; // Fill the file system combobox for ( unsigned int t = 0 ; t < FILESYSTEMS .size( ) ; t++ ) { @@ -438,18 +437,18 @@ void Dialog_Partition_New::build_filesystems_combo(bool only_unformatted) FILESYSTEMS[t].fstype == FS_EXT4 ) && combo_filesystem.items().back().sensitive() ) { - first_creatable_fs = combo_filesystem.items().size() - 1; - set_first=true; + default_fs = combo_filesystem.items().size() - 1; } } - if(!set_first) + if (default_fs < 0) { - //find and set first enabled file system as last choice default + // Find and set first enabled file system as last choice default. Note + // that unformatted will always be available. for (unsigned int t = 0; t < combo_filesystem.items().size(); t++) if (combo_filesystem.items()[t].sensitive()) { - first_creatable_fs = t ; + default_fs = t; break ; } }