@@ -123,18 +123,20 @@ class PaneHeader(Gtk.Box):
123123
124124 def __init__ (self ) -> None :
125125 Gtk .Box .__init__ (self , orientation = Gtk .Orientation .HORIZONTAL , spacing = 0 )
126- _append_buttons ( self , Gtk . IconSize . MENU , [
126+ button_specs = [
127127 [Gtk .STOCK_OPEN , self .button_cb , 'open' , _ ('Open File...' )],
128128 [Gtk .STOCK_REFRESH , self .button_cb , 'reload' , _ ('Reload File' )],
129129 [Gtk .STOCK_SAVE , self .button_cb , 'save' , _ ('Save File' )],
130- [Gtk .STOCK_SAVE_AS , self .button_cb , 'save_as' , _ ('Save File As...' )]])
130+ [Gtk .STOCK_SAVE_AS , self .button_cb , 'save_as' , _ ('Save File As...' )]
131+ ]
132+ _append_buttons (self , Gtk .IconSize .MENU , button_specs )
131133
132- self .label = label = Gtk .Label ()
133- label .set_selectable (True )
134- label .set_ellipsize (Pango .EllipsizeMode .START )
135- label .set_max_width_chars (1 )
134+ self .label = Gtk .Label ()
135+ self . label .set_selectable (True )
136+ self . label .set_ellipsize (Pango .EllipsizeMode .START )
137+ self . label .set_max_width_chars (1 )
136138
137- self .pack_start (label , True , True , 0 )
139+ self .pack_start (self . label , True , True , 0 )
138140
139141 # file's name and information about how to retrieve it from a
140142 # VCS
@@ -774,8 +776,8 @@ def __init__(self, rc_dir, **kwargs):
774776 # make the icons available for use
775777 factory .add_default ()
776778
777- menuspecs = []
778- menuspecs .append ([_ ('_File' ), [
779+ menu_specs = []
780+ menu_specs .append ([_ ('_File' ), [
779781 [
780782 [_ ('_Open File...' ), self .open_file_cb , None , 'open_file' ],
781783 [_ ('Open File In New _Tab...' ), self .open_file_in_new_tab_cb , None , 'open_file_in_new_tab' ], # noqa: E501
@@ -797,18 +799,18 @@ def __init__(self, rc_dir, **kwargs):
797799 ]
798800 ]])
799801
800- menuspecs .append ([_ ('_Edit' ), [
802+ menu_specs .append ([_ ('_Edit' ), [
801803 [
802- [_ ('_Undo' ), self .button_cb , 'undo' , 'undo' ],
803- [_ ('_Redo' ), self .button_cb , 'redo' , 'redo' ],
804+ [_ ('_Undo' ), self .menuitem_cb , 'undo' , 'undo' ],
805+ [_ ('_Redo' ), self .menuitem_cb , 'redo' , 'redo' ],
804806 ], [
805- [_ ('Cu_t' ), self .button_cb , 'cut' , 'cut' ],
806- [_ ('_Copy' ), self .button_cb , 'copy' , 'copy' ],
807- [_ ('_Paste' ), self .button_cb , 'paste' , 'paste' ],
807+ [_ ('Cu_t' ), self .menuitem_cb , 'cut' , 'cut' ],
808+ [_ ('_Copy' ), self .menuitem_cb , 'copy' , 'copy' ],
809+ [_ ('_Paste' ), self .menuitem_cb , 'paste' , 'paste' ],
808810 ], [
809- [_ ('Select _All' ), self .button_cb , 'select_all' , 'select_all' ],
810- [_ ('C_lear Edits' ), self .button_cb , 'clear_edits' , 'clear_edits' ],
811- [_ ('_Dismiss All Edits' ), self .button_cb , 'dismiss_all_edits' , 'dismiss_all_edits' ],
811+ [_ ('Select _All' ), self .menuitem_cb , 'select_all' , 'select_all' ],
812+ [_ ('C_lear Edits' ), self .menuitem_cb , 'clear_edits' , 'clear_edits' ],
813+ [_ ('_Dismiss All Edits' ), self .menuitem_cb , 'dismiss_all_edits' , 'dismiss_all_edits' ], # noqa: E501
812814 ], [
813815 [_ ('_Find...' ), self .find_cb , None , 'find' ],
814816 [_ ('Find _Next' ), self .find_next_cb , None , 'find_next' ],
@@ -841,62 +843,62 @@ def __init__(self, rc_dir, **kwargs):
841843 )
842844 syntax_menu .append (syntax_section )
843845
844- menuspecs .append ([_ ('_View' ), [
846+ menu_specs .append ([_ ('_View' ), [
845847 [
846848 [_ ('_Syntax Highlighting' ), None , None , None , syntax_menu ]
847849 ], [
848- [_ ('Re_align All' ), self .button_cb , 'realign_all' , 'realign_all' ],
849- [_ ('_Isolate' ), self .button_cb , 'isolate' , 'isolate' ],
850+ [_ ('Re_align All' ), self .menuitem_cb , 'realign_all' , 'realign_all' ],
851+ [_ ('_Isolate' ), self .menuitem_cb , 'isolate' , 'isolate' ],
850852 ], [
851- [_ ('_First Difference' ), self .button_cb , 'first_difference' , 'first_difference' ],
852- [_ ('_Previous Difference' ), self .button_cb , 'previous_difference' , 'previous_difference' ], # noqa: E501
853- [_ ('_Next Difference' ), self .button_cb , 'next_difference' , 'next_difference' ],
854- [_ ('_Last Difference' ), self .button_cb , 'last_difference' , 'last_difference' ],
853+ [_ ('_First Difference' ), self .menuitem_cb , 'first_difference' , 'first_difference' ],
854+ [_ ('_Previous Difference' ), self .menuitem_cb , 'previous_difference' , 'previous_difference' ], # noqa: E501
855+ [_ ('_Next Difference' ), self .menuitem_cb , 'next_difference' , 'next_difference' ],
856+ [_ ('_Last Difference' ), self .menuitem_cb , 'last_difference' , 'last_difference' ],
855857 ], [
856858 [_ ('Fir_st Tab' ), self .first_tab_cb , None , 'first_tab' ],
857859 [_ ('Pre_vious Tab' ), self .previous_tab_cb , None , 'previous_tab' ],
858860 [_ ('Next _Tab' ), self .next_tab_cb , None , 'next_tab' ],
859861 [_ ('Las_t Tab' ), self .last_tab_cb , None , 'last_tab' ],
860862 ], [
861- [_ ('Shift Pane _Right' ), self .button_cb , 'shift_pane_right' , 'shift_pane_right' ],
862- [_ ('Shift Pane _Left' ), self .button_cb , 'shift_pane_left' , 'shift_pane_left' ]
863+ [_ ('Shift Pane _Right' ), self .menuitem_cb , 'shift_pane_right' , 'shift_pane_right' ],
864+ [_ ('Shift Pane _Left' ), self .menuitem_cb , 'shift_pane_left' , 'shift_pane_left' ]
863865 ]
864866 ]])
865867
866- menuspecs .append ([_ ('F_ormat' ), [
868+ menu_specs .append ([_ ('F_ormat' ), [
867869 [
868- [_ ('Convert To _Upper Case' ), self .button_cb , 'convert_to_upper_case' , 'convert_to_upper_case' ], # noqa: E501
869- [_ ('Convert To _Lower Case' ), self .button_cb , 'convert_to_lower_case' , 'convert_to_lower_case' ], # noqa: E501
870+ [_ ('Convert To _Upper Case' ), self .menuitem_cb , 'convert_to_upper_case' , 'convert_to_upper_case' ], # noqa: E501
871+ [_ ('Convert To _Lower Case' ), self .menuitem_cb , 'convert_to_lower_case' , 'convert_to_lower_case' ], # noqa: E501
870872 ], [
871- [_ ('Sort Lines In _Ascending Order' ), self .button_cb , 'sort_lines_in_ascending_order' , 'sort_lines_in_ascending_order' ], # noqa: E501
872- [_ ('Sort Lines In D_escending Order' ), self .button_cb , 'sort_lines_in_descending_order' , 'sort_lines_in_descending_order' ], # noqa: E501
873+ [_ ('Sort Lines In _Ascending Order' ), self .menuitem_cb , 'sort_lines_in_ascending_order' , 'sort_lines_in_ascending_order' ], # noqa: E501
874+ [_ ('Sort Lines In D_escending Order' ), self .menuitem_cb , 'sort_lines_in_descending_order' , 'sort_lines_in_descending_order' ], # noqa: E501
873875 ], [
874- [_ ('Remove Trailing _White Space' ), self .button_cb , 'remove_trailing_white_space' , 'remove_trailing_white_space' ], # noqa: E501
875- [_ ('Convert Tabs To _Spaces' ), self .button_cb , 'convert_tabs_to_spaces' , 'convert_tabs_to_spaces' ], # noqa: E501
876- [_ ('Convert Leading Spaces To _Tabs' ), self .button_cb , 'convert_leading_spaces_to_tabs' , 'convert_leading_spaces_to_tabs' ], # noqa: E501
876+ [_ ('Remove Trailing _White Space' ), self .menuitem_cb , 'remove_trailing_white_space' , 'remove_trailing_white_space' ], # noqa: E501
877+ [_ ('Convert Tabs To _Spaces' ), self .menuitem_cb , 'convert_tabs_to_spaces' , 'convert_tabs_to_spaces' ], # noqa: E501
878+ [_ ('Convert Leading Spaces To _Tabs' ), self .menuitem_cb , 'convert_leading_spaces_to_tabs' , 'convert_leading_spaces_to_tabs' ], # noqa: E501
877879 ], [
878- [_ ('_Increase Indenting' ), self .button_cb , 'increase_indenting' , 'increase_indenting' ], # noqa: E501
879- [_ ('De_crease Indenting' ), self .button_cb , 'decrease_indenting' , 'decrease_indenting' ], # noqa: E501
880+ [_ ('_Increase Indenting' ), self .menuitem_cb , 'increase_indenting' , 'increase_indenting' ], # noqa: E501
881+ [_ ('De_crease Indenting' ), self .menuitem_cb , 'decrease_indenting' , 'decrease_indenting' ], # noqa: E501
880882 ], [
881- [_ ('Convert To _DOS Format' ), self .button_cb , 'convert_to_dos' , 'convert_to_dos' ],
882- [_ ('Convert To _Mac Format' ), self .button_cb , 'convert_to_mac' , 'convert_to_mac' ],
883- [_ ('Convert To Uni_x Format' ), self .button_cb , 'convert_to_unix' , 'convert_to_unix' ]
883+ [_ ('Convert To _DOS Format' ), self .menuitem_cb , 'convert_to_dos' , 'convert_to_dos' ],
884+ [_ ('Convert To _Mac Format' ), self .menuitem_cb , 'convert_to_mac' , 'convert_to_mac' ],
885+ [_ ('Convert To Uni_x Format' ), self .menuitem_cb , 'convert_to_unix' , 'convert_to_unix' ] # noqa: E501
884886 ]
885887 ]])
886888
887- menuspecs .append ([_ ('_Merge' ), [
889+ menu_specs .append ([_ ('_Merge' ), [
888890 [
889- [_ ('Copy Selection _Right' ), self .button_cb , 'copy_selection_right' , 'copy_selection_right' ], # noqa: E501
890- [_ ('Copy Selection _Left' ), self .button_cb , 'copy_selection_left' , 'copy_selection_left' ], # noqa: E501
891+ [_ ('Copy Selection _Right' ), self .menuitem_cb , 'copy_selection_right' , 'copy_selection_right' ], # noqa: E501
892+ [_ ('Copy Selection _Left' ), self .menuitem_cb , 'copy_selection_left' , 'copy_selection_left' ], # noqa: E501
891893 ], [
892- [_ ('Copy Left _Into Selection' ), self .button_cb , 'copy_left_into_selection' , 'copy_left_into_selection' ], # noqa: E501
893- [_ ('Copy Right I_nto Selection' ), self .button_cb , 'copy_right_into_selection' , 'copy_right_into_selection' ], # noqa: E501
894- [_ ('_Merge From Left Then Right' ), self .button_cb , 'merge_from_left_then_right' , 'merge_from_left_then_right' ], # noqa: E501
895- [_ ('M_erge From Right Then Left' ), self .button_cb , 'merge_from_right_then_left' , 'merge_from_right_then_left' ] # noqa: E501
894+ [_ ('Copy Left _Into Selection' ), self .menuitem_cb , 'copy_left_into_selection' , 'copy_left_into_selection' ], # noqa: E501
895+ [_ ('Copy Right I_nto Selection' ), self .menuitem_cb , 'copy_right_into_selection' , 'copy_right_into_selection' ], # noqa: E501
896+ [_ ('_Merge From Left Then Right' ), self .menuitem_cb , 'merge_from_left_then_right' , 'merge_from_left_then_right' ], # noqa: E501
897+ [_ ('M_erge From Right Then Left' ), self .menuitem_cb , 'merge_from_right_then_left' , 'merge_from_right_then_left' ] # noqa: E501
896898 ]
897899 ]])
898900
899- menuspecs .append ([_ ('_Help' ), [
901+ menu_specs .append ([_ ('_Help' ), [
900902 [
901903 [_ ('_Help Contents...' ), self .help_contents_cb , None , 'help_contents' ],
902904 ], [
@@ -908,13 +910,13 @@ def __init__(self, rc_dir, **kwargs):
908910 self .menu_update_depth = 0
909911
910912 menubar = Gio .Menu ()
911- for label , sections in menuspecs :
913+ for label , sections in menu_specs :
912914 menubar .append_submenu (label , self ._create_menu (sections ))
913915 self .get_application ().set_menubar (menubar )
914916
915- # create button bar
917+ # create toolbar
916918 hbox = Gtk .Box (orientation = Gtk .Orientation .HORIZONTAL , spacing = 0 )
917- _append_buttons ( hbox , Gtk . IconSize . LARGE_TOOLBAR , [
919+ button_specs = [
918920 [DIFFUSE_STOCK_NEW_2WAY_MERGE , self .new_2_way_file_merge_cb , None , _ ('New 2-Way File Merge' )], # noqa: E501
919921 [DIFFUSE_STOCK_NEW_3WAY_MERGE , self .new_3_way_file_merge_cb , None , _ ('New 3-Way File Merge' )], # noqa: E501
920922 [],
@@ -937,7 +939,8 @@ def __init__(self, rc_dir, **kwargs):
937939 [Gtk .STOCK_COPY , self .button_cb , 'copy' , _ ('Copy' )],
938940 [Gtk .STOCK_PASTE , self .button_cb , 'paste' , _ ('Paste' )],
939941 [Gtk .STOCK_CLEAR , self .button_cb , 'clear_edits' , _ ('Clear Edits' )]
940- ])
942+ ]
943+ _append_buttons (hbox , Gtk .IconSize .LARGE_TOOLBAR , button_specs )
941944 # avoid the button bar from dictating the minimum window size
942945 hbox .set_size_request (0 , hbox .get_size_request ()[1 ])
943946 vbox .pack_start (hbox , False , False , 0 )
@@ -1700,10 +1703,14 @@ def next_tab_cb(self, widget, data):
17001703 def last_tab_cb (self , widget , data ):
17011704 self .notebook .set_current_page (self .notebook .get_n_pages () - 1 )
17021705
1703- # callback for most menu items and buttons
1704- def button_cb (self , widget , data ) :
1706+ # callback for menu items
1707+ def menuitem_cb (self , widget : Gtk . Widget , data : GLib . Variant ) -> None :
17051708 self .getCurrentViewer ().button_cb (widget , data .get_string ())
17061709
1710+ # callback for buttons
1711+ def button_cb (self , widget : Gtk .Widget , data : str ) -> None :
1712+ self .getCurrentViewer ().button_cb (widget , data )
1713+
17071714 # display help documentation
17081715 def help_contents_cb (self , widget , data ):
17091716 help_url = None
@@ -1793,17 +1800,16 @@ def _append_buttons(box, size, specs):
17931800 """Convenience method for packing buttons into a container."""
17941801 for spec in specs :
17951802 if len (spec ) > 0 :
1803+ (stock_id , cb , cb_data , label ) = spec
17961804 button = Gtk .Button ()
17971805 button .set_relief (Gtk .ReliefStyle .NONE )
17981806 button .set_can_focus (False )
17991807 image = Gtk .Image ()
1800- image .set_from_stock (spec [ 0 ] , size )
1808+ image .set_from_stock (stock_id , size )
18011809 button .add (image )
18021810 image .show ()
1803- if len (spec ) > 2 :
1804- button .connect ('clicked' , spec [1 ], spec [2 ])
1805- if len (spec ) > 3 :
1806- button .set_tooltip_text (spec [3 ])
1811+ button .connect ('clicked' , cb , cb_data )
1812+ button .set_tooltip_text (label )
18071813 box .pack_start (button , False , False , 0 )
18081814 button .show ()
18091815 else :
0 commit comments