From 0693e7996f501ed9b19ca19c58bc0fb4eb00b367 Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Sun, 17 Sep 2006 13:23:47 +0000 Subject: [PATCH] added popupmenu to operationslist and did some (higrelated) cleanups * added popupmenu to operationslist and did some (higrelated) cleanups --- ChangeLog | 4 ++ include/HBoxOperations.h | 74 ++++++++++++++++++++ include/Makefile.am | 1 + include/Win_GParted.h | 28 +------- src/DrawingAreaVisualDisk.cc | 2 +- src/HBoxOperations.cc | 128 +++++++++++++++++++++++++++++++++++ src/Makefile.am | 1 + src/Win_GParted.cc | 100 +++++++++++++-------------- 8 files changed, 259 insertions(+), 79 deletions(-) create mode 100644 include/HBoxOperations.h create mode 100644 src/HBoxOperations.cc diff --git a/ChangeLog b/ChangeLog index bae911de..f7102a5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-09-17 Bart Hakvoort + + * added popupmenu to operationslist and did some (higrelated) cleanups + 2006-09-16 Bart Hakvoort * include/TreeView_Detail.h, diff --git a/include/HBoxOperations.h b/include/HBoxOperations.h new file mode 100644 index 00000000..e6241732 --- /dev/null +++ b/include/HBoxOperations.h @@ -0,0 +1,74 @@ +/* Copyright (C) 2004-2006 Bart 'plors' Hakvoort + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef HBOX_OPERATIONS +#define HBOX_OPERATIONS + +#include "../include/Operation.h" + +#include +#include +#include +#include +#include + +namespace GParted +{ + +class HBoxOperations : public Gtk::HBox +{ +public: + HBoxOperations() ; + ~HBoxOperations() ; + + void load_operations( const std::vector operations ) ; + void clear() ; + + sigc::signal< void > signal_undo ; + sigc::signal< void > signal_clear ; + sigc::signal< void > signal_apply ; + sigc::signal< void > signal_close ; + +private: + bool on_signal_button_press_event( GdkEventButton * event ) ; + void on_undo() ; + void on_clear() ; + void on_apply() ; + void on_close() ; + + Gtk::Menu menu_popup ; + Gtk::ScrolledWindow scrollwindow ; + Gtk::TreeView treeview_operations ; + Glib::RefPtr liststore_operations ; + + struct treeview_operations_Columns : public Gtk::TreeModelColumnRecord + { + Gtk::TreeModelColumn operation_description; + Gtk::TreeModelColumn< Glib::RefPtr > operation_icon; + + treeview_operations_Columns() + { + add( operation_description ); + add( operation_icon ); + } + }; + treeview_operations_Columns treeview_operations_columns; +}; + +} //GParted + +#endif //HBOX_OPERATIONS diff --git a/include/Makefile.am b/include/Makefile.am index 4818032c..47750c67 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -16,6 +16,7 @@ EXTRA_DIST = \ Frame_Resizer_Base.h \ Frame_Resizer_Extended.h \ GParted_Core.h \ + HBoxOperations.h \ Operation.h \ OperationCopy.h \ OperationCreate.h \ diff --git a/include/Win_GParted.h b/include/Win_GParted.h index 7a950430..94ea8cfa 100644 --- a/include/Win_GParted.h +++ b/include/Win_GParted.h @@ -22,8 +22,8 @@ #include "../include/DrawingAreaVisualDisk.h" #include "../include/Partition.h" #include "../include/TreeView_Detail.h" -#include "../include/Operation.h" #include "../include/GParted_Core.h" +#include "../include/HBoxOperations.h" #include #include @@ -31,15 +31,11 @@ #include #include #include -#include #include #include -#include #include #include -#include //should be included by gtkmm headers. but decided to include it anyway after getting some bugreports.. - namespace GParted { @@ -54,7 +50,6 @@ private: void init_partition_menu() ; Gtk::Menu * create_format_menu() ; void init_device_info() ; - void init_operationslist() ; void init_hpaned_main() ; void refresh_combo_devices() ; @@ -174,7 +169,7 @@ private: Gtk::HPaned hpaned_main; Gtk::VPaned vpaned_main; Gtk::VBox vbox_main,vbox_info ; - Gtk::HBox hbox_toolbar, hbox_operations, *hbox; + Gtk::HBox hbox_toolbar, *hbox; Gtk::Toolbar toolbar_main; Gtk::MenuBar menubar_main; Gtk::ComboBox combo_devices ; @@ -192,6 +187,7 @@ private: DrawingAreaVisualDisk drawingarea_visualdisk ; TreeView_Detail treeview_detail; + HBoxOperations hbox_operations ; //device combo Glib::RefPtr liststore_devices ; @@ -211,23 +207,6 @@ private: }; treeview_devices_Columns treeview_devices_columns ; - //operations list - Gtk::TreeView treeview_operations; - Glib::RefPtr liststore_operations; - - struct treeview_operations_Columns : public Gtk::TreeModelColumnRecord - { - Gtk::TreeModelColumn operation_description; - Gtk::TreeModelColumn< Glib::RefPtr > operation_icon; - - treeview_operations_Columns() - { - add( operation_description ); - add( operation_icon ); - } - }; - treeview_operations_Columns treeview_operations_columns; - //indices for partitionmenu and toolbar int MENU_NEW, TOOLBAR_NEW, @@ -251,7 +230,6 @@ private: bool OPERATIONSLIST_OPEN ; GParted_Core gparted_core ; - GParted::Device *temp_device ; std::vector device_info ; //stuff for progress overview and pulsebar diff --git a/src/DrawingAreaVisualDisk.cc b/src/DrawingAreaVisualDisk.cc index 24a6b076..915f0076 100644 --- a/src/DrawingAreaVisualDisk.cc +++ b/src/DrawingAreaVisualDisk.cc @@ -39,7 +39,7 @@ DrawingAreaVisualDisk::DrawingAreaVisualDisk() color_text .set( "black" ); get_colormap() ->alloc_color( color_text ) ; - set_events( Gdk::BUTTON_PRESS_MASK ); + add_events( Gdk::BUTTON_PRESS_MASK ); set_size_request( -1, HEIGHT ) ; } diff --git a/src/HBoxOperations.cc b/src/HBoxOperations.cc new file mode 100644 index 00000000..f325dd0a --- /dev/null +++ b/src/HBoxOperations.cc @@ -0,0 +1,128 @@ +/* Copyright (C) 2004-2006 Bart 'plors' Hakvoort + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "../include/HBoxOperations.h" + +#include + +namespace GParted +{ + +HBoxOperations::HBoxOperations() +{ + //create listview for pending operations + liststore_operations = Gtk::ListStore::create( treeview_operations_columns ); + treeview_operations .set_model( liststore_operations ); + treeview_operations .set_headers_visible( false ); + treeview_operations .append_column( "", treeview_operations_columns .operation_icon ); + treeview_operations .append_column( "", treeview_operations_columns .operation_description ); + treeview_operations .get_selection() ->set_mode( Gtk::SELECTION_NONE ) ; + treeview_operations .signal_button_press_event() .connect( + sigc::mem_fun( *this, &HBoxOperations::on_signal_button_press_event ), false ) ; + + //init scrollwindow_operations + scrollwindow .set_shadow_type( Gtk::SHADOW_ETCHED_IN ); + scrollwindow .set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC ); + scrollwindow .add ( treeview_operations ) ; + pack_start( scrollwindow, Gtk::PACK_EXPAND_WIDGET ); + + //create popupmenu + menu_popup .items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( + _("_Undo Last Operation"), + * manage( new Gtk::Image( Gtk::Stock::UNDO, Gtk::ICON_SIZE_MENU ) ), + sigc::mem_fun(*this, &HBoxOperations::on_undo) ) ); + + menu_popup .items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( + _("_Clear All Operations"), + * manage( new Gtk::Image( Gtk::Stock::CLEAR, Gtk::ICON_SIZE_MENU ) ), + sigc::mem_fun(*this, &HBoxOperations::on_clear) ) ); + + menu_popup .items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( + _("_Apply All Operations"), + * manage( new Gtk::Image( Gtk::Stock::APPLY, Gtk::ICON_SIZE_MENU ) ), + sigc::mem_fun(*this, &HBoxOperations::on_apply) ) ); + + menu_popup .items() .push_back( Gtk::Menu_Helpers::SeparatorElem() ); + menu_popup .items() .push_back( Gtk::Menu_Helpers::StockMenuElem( + Gtk::Stock::CLOSE, sigc::mem_fun(*this, &HBoxOperations::on_close) ) ); +} + +void HBoxOperations::load_operations( const std::vector operations ) +{ + liststore_operations ->clear(); + + Gtk::TreeRow treerow ; + for ( unsigned int t = 0 ; t < operations .size(); t++ ) + { + treerow = *( liststore_operations ->append() ); + treerow[ treeview_operations_columns .operation_description ] = operations[ t ] ->description ; + treerow[ treeview_operations_columns .operation_icon ] = operations[ t ] ->icon ; + } + + //make scrollwindow focus on the last operation in the list + if ( liststore_operations ->children() .size() > 0 ) + treeview_operations .set_cursor( static_cast( static_cast( + *(--liststore_operations ->children() .end()) ) ) ) ; +} + +void HBoxOperations::clear() +{ + liststore_operations ->clear(); +} + +bool HBoxOperations::on_signal_button_press_event( GdkEventButton * event ) +{ + //right-click + if ( event ->button == 3 ) + { + menu_popup .items()[0] .set_sensitive( liststore_operations ->children() .size() > 0 ) ; + menu_popup .items()[1] .set_sensitive( liststore_operations ->children() .size() > 0 ) ; + menu_popup .items()[2] .set_sensitive( liststore_operations ->children() .size() > 0 ) ; + + menu_popup .popup( event ->button, event ->time ) ; + } + + return true ; +} + +void HBoxOperations::on_undo() +{ + signal_undo .emit() ; +} + +void HBoxOperations::on_clear() +{ + signal_clear .emit() ; +} + +void HBoxOperations::on_apply() +{ + signal_apply .emit() ; +} + +void HBoxOperations::on_close() +{ + signal_close .emit() ; +} + +HBoxOperations::~HBoxOperations() +{ +} + +} //GParted + + diff --git a/src/Makefile.am b/src/Makefile.am index 5777b08c..a433e3e6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,6 +25,7 @@ gparted_SOURCES = \ Frame_Resizer_Base.cc \ Frame_Resizer_Extended.cc \ GParted_Core.cc \ + HBoxOperations.cc \ Operation.cc \ OperationCopy.cc \ OperationCreate.cc \ diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index df8ea9ab..539e39af 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -105,9 +105,12 @@ Win_GParted::Win_GParted( const std::vector & user_devices ) init_device_info() ; //operationslist... - init_operationslist() ; + hbox_operations .signal_undo .connect( sigc::mem_fun( this, &Win_GParted::activate_undo ) ) ; + hbox_operations .signal_clear .connect( sigc::mem_fun( this, &Win_GParted::clear_operationslist ) ) ; + hbox_operations .signal_apply .connect( sigc::mem_fun( this, &Win_GParted::activate_apply ) ) ; + hbox_operations .signal_close .connect( sigc::mem_fun( this, &Win_GParted::close_operationslist ) ) ; vpaned_main .pack2( hbox_operations, true, true ) ; - + //statusbar... pulsebar .set_pulse_step( 0.01 ); statusbar .add( pulsebar ); @@ -125,30 +128,48 @@ void Win_GParted::init_menubar() //gparted menu = manage( new Gtk::Menu() ) ; image = manage( new Gtk::Image( Gtk::Stock::REFRESH, Gtk::ICON_SIZE_MENU ) ); - menu ->items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( _("_Refresh Devices"), Gtk::AccelKey("r"), *image, sigc::mem_fun(*this, &Win_GParted::menu_gparted_refresh_devices) ) ); + menu ->items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( + _("_Refresh Devices"), + Gtk::AccelKey("r"), + *image, + sigc::mem_fun(*this, &Win_GParted::menu_gparted_refresh_devices) ) ); image = manage( new Gtk::Image( Gtk::Stock::HARDDISK, Gtk::ICON_SIZE_MENU ) ); menu ->items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( _("_Devices"), *image ) ) ; menu ->items() .push_back( Gtk::Menu_Helpers::SeparatorElem( ) ); - menu ->items() .push_back( Gtk::Menu_Helpers::MenuElem( _("_Show Features"), sigc::mem_fun( *this, &Win_GParted::menu_gparted_features ) ) ); + menu ->items() .push_back( Gtk::Menu_Helpers::MenuElem( + _("_Show Features"), sigc::mem_fun( *this, &Win_GParted::menu_gparted_features ) ) ); menu ->items() .push_back( Gtk::Menu_Helpers::SeparatorElem( ) ); - menu ->items() .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::QUIT, sigc::mem_fun(*this, &Win_GParted::menu_gparted_quit) ) ); + menu ->items() .push_back( Gtk::Menu_Helpers::StockMenuElem( + Gtk::Stock::QUIT, sigc::mem_fun(*this, &Win_GParted::menu_gparted_quit) ) ); menubar_main .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("_GParted"), *menu ) ); //edit menu = manage( new Gtk::Menu() ) ; - menu ->items() .push_back( Gtk::Menu_Helpers::StockMenuElem( - Gtk::Stock::UNDO, Gtk::AccelKey("z"), sigc::mem_fun(*this, &Win_GParted::activate_undo) ) ); - menu ->items() .push_back( Gtk::Menu_Helpers::StockMenuElem( - Gtk::Stock::CLEAR, sigc::mem_fun(*this, &Win_GParted::clear_operationslist) ) ); - menu ->items() .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::APPLY, sigc::mem_fun(*this, &Win_GParted::activate_apply) ) ); + menu ->items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( + _("_Undo Last Operation"), + Gtk::AccelKey("z"), + * manage( new Gtk::Image( Gtk::Stock::UNDO, Gtk::ICON_SIZE_MENU ) ), + sigc::mem_fun(*this, &Win_GParted::activate_undo) ) ); + + menu ->items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( + _("_Clear All Operations"), + * manage( new Gtk::Image( Gtk::Stock::CLEAR, Gtk::ICON_SIZE_MENU ) ), + sigc::mem_fun(*this, &Win_GParted::clear_operationslist) ) ); + + menu ->items() .push_back( Gtk::Menu_Helpers::ImageMenuElem( + _("_Apply All Operations"), + * manage( new Gtk::Image( Gtk::Stock::APPLY, Gtk::ICON_SIZE_MENU ) ), + sigc::mem_fun(*this, &Win_GParted::activate_apply) ) ); menubar_main .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("_Edit"), *menu ) ); //view menu = manage( new Gtk::Menu() ) ; - menu ->items() .push_back( Gtk::Menu_Helpers::CheckMenuElem( _("Device _Information"), sigc::mem_fun(*this, &Win_GParted::menu_view_harddisk_info) ) ); - menu ->items() .push_back( Gtk::Menu_Helpers::CheckMenuElem( _("Pending _Operations"), sigc::mem_fun(*this, &Win_GParted::menu_view_operations) ) ); + menu ->items() .push_back( Gtk::Menu_Helpers::CheckMenuElem( + _("Device _Information"), sigc::mem_fun(*this, &Win_GParted::menu_view_harddisk_info) ) ); + menu ->items() .push_back( Gtk::Menu_Helpers::CheckMenuElem( + _("Pending _Operations"), sigc::mem_fun(*this, &Win_GParted::menu_view_operations) ) ); menubar_main .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("_View"), *menu ) ); //device @@ -163,8 +184,10 @@ void Win_GParted::init_menubar() //help menu = manage( new Gtk::Menu() ) ; - menu ->items() .push_back(Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::HELP, sigc::mem_fun(*this, &Win_GParted::menu_help_contents) ) ); - menu ->items( ) .push_back( Gtk::Menu_Helpers::StockMenuElem( Gtk::Stock::ABOUT, sigc::mem_fun(*this, &Win_GParted::menu_help_about) ) ); + menu ->items() .push_back(Gtk::Menu_Helpers::StockMenuElem( + Gtk::Stock::HELP, sigc::mem_fun(*this, &Win_GParted::menu_help_contents) ) ); + menu ->items() .push_back( Gtk::Menu_Helpers::StockMenuElem( + Gtk::Stock::ABOUT, sigc::mem_fun(*this, &Win_GParted::menu_help_about) ) ); menubar_main.items() .push_back( Gtk::Menu_Helpers::MenuElem(_("_Help"), *menu ) ); } @@ -219,14 +242,14 @@ void Win_GParted::init_toolbar() toolbar_main.append(*toolbutton); TOOLBAR_UNDO = index++ ; toolbutton ->set_sensitive( false ); - toolbutton ->set_tooltip(tooltips, _("Undo last operation") ); + toolbutton ->set_tooltip(tooltips, _("Undo Last Operation") ); toolbutton = Gtk::manage(new Gtk::ToolButton(Gtk::Stock::APPLY)); toolbutton ->signal_clicked().connect( sigc::mem_fun(*this, &Win_GParted::activate_apply) ); toolbar_main.append(*toolbutton); TOOLBAR_APPLY = index++ ; toolbutton ->set_sensitive( false ); - toolbutton ->set_tooltip(tooltips, _("Apply all operations") ); + toolbutton ->set_tooltip(tooltips, _("Apply All Operations") ); //initialize and pack combo_devices liststore_devices = Gtk::ListStore::create( treeview_devices_columns ) ; @@ -448,37 +471,18 @@ void Win_GParted::init_device_info() vbox_info .pack_start( *table, Gtk::PACK_SHRINK ); } -void Win_GParted::init_operationslist() -{ - //create listview for pending operations - liststore_operations = Gtk::ListStore::create( treeview_operations_columns ); - treeview_operations .set_model( liststore_operations ); - treeview_operations .set_headers_visible( false ); - treeview_operations .append_column( "", treeview_operations_columns .operation_icon ); - treeview_operations .append_column( "", treeview_operations_columns .operation_description ); - treeview_operations .get_selection() ->set_mode( Gtk::SELECTION_NONE ); - - //init scrollwindow_operations - scrollwindow = manage( new Gtk::ScrolledWindow( ) ) ; - scrollwindow ->set_shadow_type( Gtk::SHADOW_ETCHED_IN ); - scrollwindow ->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC ); - scrollwindow ->add ( treeview_operations ) ; - - hbox_operations .pack_start( *scrollwindow, Gtk::PACK_EXPAND_WIDGET ); -} - void Win_GParted::init_hpaned_main() { //left scrollwindow (holds device info) - scrollwindow = manage( new Gtk::ScrolledWindow( ) ) ; + scrollwindow = manage( new Gtk::ScrolledWindow() ) ; scrollwindow ->set_shadow_type( Gtk::SHADOW_ETCHED_IN ); scrollwindow ->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC ); - hpaned_main.pack1( *scrollwindow, true, true ); + hpaned_main .pack1( *scrollwindow, true, true ); scrollwindow ->add( vbox_info ); //right scrollwindow (holds treeview with partitions) - scrollwindow = manage( new Gtk::ScrolledWindow( ) ) ; + scrollwindow = manage( new Gtk::ScrolledWindow() ) ; scrollwindow ->set_shadow_type( Gtk::SHADOW_ETCHED_IN ); scrollwindow ->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC ); @@ -487,7 +491,7 @@ void Win_GParted::init_hpaned_main() treeview_detail .signal_partition_activated .connect( sigc::mem_fun( this, &Win_GParted::on_partition_activated ) ); treeview_detail .signal_popup_menu .connect( sigc::mem_fun( this, &Win_GParted::on_partition_popup_menu ) ); scrollwindow ->add( treeview_detail ); - hpaned_main.pack2( *scrollwindow, true, true ); + hpaned_main .pack2( *scrollwindow, true, true ); } void Win_GParted::refresh_combo_devices() @@ -618,11 +622,6 @@ void Win_GParted::Add_Operation( Operation * operation, int index ) if ( operations .size() == 1 ) //first operation, open operationslist open_operationslist() ; - - //make scrollwindow focus on the last operation in the list - treeview_operations .set_cursor( - static_cast( static_cast( - *(--liststore_operations ->children() .end()) ) ) ) ; } else { @@ -642,19 +641,14 @@ void Win_GParted::Add_Operation( Operation * operation, int index ) void Win_GParted::Refresh_Visual() { std::vector partitions = devices[ current_device ] .partitions ; - liststore_operations ->clear(); //make all operations visible for ( unsigned int t = 0 ; t < operations .size(); t++ ) - { if ( operations[ t ] ->device == devices[ current_device ] ) operations[ t ] ->apply_to_visual( partitions ) ; - treerow = *( liststore_operations ->append() ); - treerow[ treeview_operations_columns .operation_description ] = operations[ t ] ->description ; - treerow[ treeview_operations_columns .operation_icon ] = operations[ t ] ->icon ; - } - + hbox_operations .load_operations( operations ) ; + //set new statusbartext statusbar .pop() ; if ( operations .size() != 1 ) @@ -1020,7 +1014,7 @@ void Win_GParted::menu_gparted_refresh_devices() treeview_detail .clear() ; //hmzz, this is really paranoid, but i think it's the right thing to do ;) - liststore_operations ->clear() ; + hbox_operations .clear() ; close_operationslist() ; remove_operation( -1, true ) ; @@ -1825,7 +1819,7 @@ void Win_GParted::activate_apply() //wipe operations... remove_operation( -1, true ) ; - liststore_operations ->clear() ; + hbox_operations .clear() ; close_operationslist() ; //reset new_count to 1