2006-05-19 17:18:06 +00:00
/*
* keybindings . c - this file is part of Geany , a fast and lightweight IDE
*
2008-01-06 18:11:57 +00:00
* Copyright 2006 - 2008 Enrico Tröger < enrico ( dot ) troeger ( at ) uvena ( dot ) de >
* Copyright 2006 - 2008 Nick Treleaven < nick ( dot ) treleaven ( at ) btinternet ( dot ) com >
2006-05-19 17:18:06 +00:00
*
* 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 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 . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
* $ Id $
*/
2007-02-24 11:41:56 +00:00
/*
* Configurable keyboard shortcuts .
*/
2006-05-19 17:18:06 +00:00
# include <gdk/gdkkeysyms.h>
# include "geany.h"
# include "keybindings.h"
# include "support.h"
# include "utils.h"
2006-09-05 14:24:47 +00:00
# include "ui_utils.h"
2006-05-19 17:18:06 +00:00
# include "document.h"
2007-08-15 15:37:21 +00:00
# include "filetypes.h"
2006-05-19 17:18:06 +00:00
# include "callbacks.h"
2006-07-11 14:15:56 +00:00
# include "prefs.h"
2006-05-19 17:18:06 +00:00
# include "msgwindow.h"
2007-05-28 16:07:30 +00:00
# include "editor.h"
2006-05-19 17:18:06 +00:00
# include "sciwrappers.h"
2006-10-18 19:35:42 +00:00
# include "build.h"
2007-02-25 14:26:55 +00:00
# include "tools.h"
2007-06-03 16:03:46 +00:00
# include "navqueue.h"
2007-09-25 12:39:41 +00:00
# include "symbols.h"
2007-09-26 16:22:20 +00:00
# include "vte.h"
2006-05-19 17:18:06 +00:00
2008-02-20 11:24:23 +00:00
KeyBinding * keys [ GEANY_MAX_KEYS ] ;
2007-09-27 11:13:59 +00:00
static const gboolean swap_alt_tab_order = FALSE ;
2006-11-23 12:23:36 +00:00
2006-05-19 17:18:06 +00:00
/* simple convenience function to allocate and fill the struct */
2008-01-29 16:11:18 +00:00
static KeyBinding * fill ( KBCallback func , guint key , GdkModifierType mod , const gchar * name ,
2006-10-26 15:22:27 +00:00
const gchar * label ) ;
2007-05-03 15:38:02 +00:00
static void cb_func_file_action ( guint key_id ) ;
2007-05-03 16:13:30 +00:00
static void cb_func_menu_print ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
static void cb_func_menu_undo ( guint key_id ) ;
static void cb_func_menu_redo ( guint key_id ) ;
2007-12-25 14:00:18 +00:00
static void cb_func_clipboard ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
static void cb_func_menu_selectall ( guint key_id ) ;
2007-07-04 14:41:58 +00:00
static void cb_func_menu_help ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
static void cb_func_menu_preferences ( guint key_id ) ;
static void cb_func_menu_insert_date ( guint key_id ) ;
2007-05-03 16:13:30 +00:00
2007-09-13 16:40:19 +00:00
static void cb_func_menu_search ( guint key_id ) ;
2007-05-03 16:13:30 +00:00
2007-05-06 14:49:51 +00:00
static void cb_func_menu_toggle_all ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
static void cb_func_menu_fullscreen ( guint key_id ) ;
static void cb_func_menu_messagewindow ( guint key_id ) ;
static void cb_func_menu_zoomin ( guint key_id ) ;
static void cb_func_menu_zoomout ( guint key_id ) ;
2007-05-03 16:13:30 +00:00
2006-10-26 15:22:27 +00:00
static void cb_func_menu_replacetabs ( guint key_id ) ;
static void cb_func_menu_foldall ( guint key_id ) ;
static void cb_func_menu_unfoldall ( guint key_id ) ;
2007-05-03 16:13:30 +00:00
static void cb_func_reloadtaglist ( guint key_id ) ;
static void cb_func_menu_opencolorchooser ( guint key_id ) ;
2006-12-13 00:46:14 +00:00
static void cb_func_menu_insert_specialchars ( guint key_id ) ;
2007-05-03 16:13:30 +00:00
2006-11-29 10:29:34 +00:00
static void cb_func_build_action ( guint key_id ) ;
2007-05-03 16:13:30 +00:00
2006-10-26 15:22:27 +00:00
static void cb_func_switch_editor ( guint key_id ) ;
static void cb_func_switch_scribble ( guint key_id ) ;
static void cb_func_switch_vte ( guint key_id ) ;
2007-03-30 10:38:13 +00:00
static void cb_func_switch_search_bar ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
static void cb_func_switch_tableft ( guint key_id ) ;
static void cb_func_switch_tabright ( guint key_id ) ;
2007-03-13 17:00:12 +00:00
static void cb_func_switch_tablastused ( guint key_id ) ;
2007-09-07 12:34:57 +00:00
static void cb_func_move_tab ( guint key_id ) ;
2007-06-03 16:03:46 +00:00
static void cb_func_nav_back ( guint key_id ) ;
static void cb_func_nav_forward ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
static void cb_func_toggle_sidebar ( guint key_id ) ;
// common function for editing keybindings, only valid when scintilla has focus.
static void cb_func_edit ( guint key_id ) ;
2007-05-05 16:35:59 +00:00
// common function for global editing keybindings.
static void cb_func_edit_global ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
// common function for keybindings using current word
static void cb_func_current_word ( guint key_id ) ;
2008-02-20 11:24:23 +00:00
static void add_menu_accels ( void ) ;
2006-05-19 17:18:06 +00:00
2006-05-24 13:18:42 +00:00
2008-02-20 11:24:23 +00:00
static void init_default_kb ( void )
2006-05-19 17:18:06 +00:00
{
// init all fields of keys with default values
2007-05-03 16:13:30 +00:00
keys [ GEANY_KEYS_MENU_NEW ] = fill ( cb_func_file_action ,
2006-06-18 17:14:32 +00:00
GDK_n , GDK_CONTROL_MASK , " menu_new " , _ ( " New " ) ) ;
2007-05-03 16:13:30 +00:00
keys [ GEANY_KEYS_MENU_OPEN ] = fill ( cb_func_file_action ,
2006-06-18 17:14:32 +00:00
GDK_o , GDK_CONTROL_MASK , " menu_open " , _ ( " Open " ) ) ;
2007-05-03 16:13:30 +00:00
keys [ GEANY_KEYS_MENU_OPENSELECTED ] = fill ( cb_func_file_action ,
2007-01-24 19:20:12 +00:00
GDK_o , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " menu_open_selected " , _ ( " Open selected file " ) ) ;
2007-05-03 16:13:30 +00:00
keys [ GEANY_KEYS_MENU_SAVE ] = fill ( cb_func_file_action ,
2006-06-18 17:14:32 +00:00
GDK_s , GDK_CONTROL_MASK , " menu_save " , _ ( " Save " ) ) ;
2007-05-03 16:13:30 +00:00
keys [ GEANY_KEYS_MENU_SAVEAS ] = fill ( cb_func_file_action ,
2007-01-08 18:15:06 +00:00
0 , 0 , " menu_saveas " , _ ( " Save as " ) ) ;
2007-05-03 16:13:30 +00:00
keys [ GEANY_KEYS_MENU_SAVEALL ] = fill ( cb_func_file_action ,
2006-06-18 17:14:32 +00:00
GDK_S , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " menu_saveall " , _ ( " Save all " ) ) ;
2006-06-29 17:14:52 +00:00
keys [ GEANY_KEYS_MENU_PRINT ] = fill ( cb_func_menu_print ,
2006-11-01 16:03:41 +00:00
GDK_p , GDK_CONTROL_MASK , " menu_print " , _ ( " Print " ) ) ;
2007-05-03 16:13:30 +00:00
keys [ GEANY_KEYS_MENU_CLOSE ] = fill ( cb_func_file_action ,
2006-06-21 18:54:07 +00:00
GDK_w , GDK_CONTROL_MASK , " menu_close " , _ ( " Close " ) ) ;
2007-05-03 16:13:30 +00:00
keys [ GEANY_KEYS_MENU_CLOSEALL ] = fill ( cb_func_file_action ,
2007-01-18 11:31:37 +00:00
GDK_w , GDK_CONTROL_MASK | GDK_SHIFT_MASK , " menu_closeall " , _ ( " Close all " ) ) ;
2007-05-03 16:13:30 +00:00
keys [ GEANY_KEYS_MENU_RELOADFILE ] = fill ( cb_func_file_action ,
2006-06-18 17:14:32 +00:00
GDK_r , GDK_CONTROL_MASK , " menu_reloadfile " , _ ( " Reload file " ) ) ;
2007-05-03 15:38:02 +00:00
keys [ GEANY_KEYS_MENU_PROJECTPROPERTIES ] = fill ( cb_func_file_action ,
0 , 0 , " project_properties " , _ ( " Project properties " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_MENU_UNDO ] = fill ( cb_func_menu_undo ,
GDK_z , GDK_CONTROL_MASK , " menu_undo " , _ ( " Undo " ) ) ;
keys [ GEANY_KEYS_MENU_REDO ] = fill ( cb_func_menu_redo ,
GDK_y , GDK_CONTROL_MASK , " menu_redo " , _ ( " Redo " ) ) ;
2007-12-25 14:00:18 +00:00
keys [ GEANY_KEYS_MENU_CUT ] = fill ( cb_func_clipboard ,
GDK_x , GDK_CONTROL_MASK , " menu_cut " , _ ( " Cut " ) ) ;
keys [ GEANY_KEYS_MENU_COPY ] = fill ( cb_func_clipboard ,
GDK_c , GDK_CONTROL_MASK , " menu_copy " , _ ( " Copy " ) ) ;
keys [ GEANY_KEYS_MENU_PASTE ] = fill ( cb_func_clipboard ,
GDK_v , GDK_CONTROL_MASK , " menu_paste " , _ ( " Paste " ) ) ;
2006-07-01 14:12:05 +00:00
keys [ GEANY_KEYS_MENU_SELECTALL ] = fill ( cb_func_menu_selectall ,
GDK_a , GDK_CONTROL_MASK , " menu_selectall " , _ ( " Select All " ) ) ;
2006-08-19 12:56:30 +00:00
keys [ GEANY_KEYS_MENU_INSERTDATE ] = fill ( cb_func_menu_insert_date ,
GDK_d , GDK_SHIFT_MASK | GDK_MOD1_MASK , " menu_insert_date " , _ ( " Insert date " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_MENU_PREFERENCES ] = fill ( cb_func_menu_preferences ,
2007-11-08 16:39:34 +00:00
GDK_p , GDK_CONTROL_MASK | GDK_MOD1_MASK , " menu_preferences " , _ ( " Preferences " ) ) ;
2007-05-03 15:38:02 +00:00
2007-09-13 16:40:19 +00:00
// search
keys [ GEANY_KEYS_MENU_FIND ] = fill ( cb_func_menu_search ,
GDK_f , GDK_CONTROL_MASK , " menu_find " , _ ( " Find " ) ) ;
keys [ GEANY_KEYS_MENU_FINDNEXT ] = fill ( cb_func_menu_search ,
2007-07-07 15:24:17 +00:00
GDK_g , GDK_CONTROL_MASK , " menu_findnext " , _ ( " Find Next " ) ) ;
2007-09-13 16:40:19 +00:00
keys [ GEANY_KEYS_MENU_FINDPREVIOUS ] = fill ( cb_func_menu_search ,
2007-07-07 15:24:17 +00:00
GDK_g , GDK_CONTROL_MASK | GDK_SHIFT_MASK , " menu_findprevious " , _ ( " Find Previous " ) ) ;
2007-09-13 16:40:19 +00:00
keys [ GEANY_KEYS_MENU_FINDNEXTSEL ] = fill ( cb_func_menu_search ,
2007-01-23 17:51:30 +00:00
0 , 0 , " menu_findnextsel " , _ ( " Find Next Selection " ) ) ;
2007-09-13 16:40:19 +00:00
keys [ GEANY_KEYS_MENU_FINDPREVSEL ] = fill ( cb_func_menu_search ,
2007-01-23 17:51:30 +00:00
0 , 0 , " menu_findprevsel " , _ ( " Find Previous Selection " ) ) ;
2007-09-13 16:40:19 +00:00
keys [ GEANY_KEYS_MENU_REPLACE ] = fill ( cb_func_menu_search ,
2007-07-04 14:41:58 +00:00
GDK_h , GDK_CONTROL_MASK , " menu_replace " , _ ( " Replace " ) ) ;
2007-09-13 16:40:19 +00:00
keys [ GEANY_KEYS_MENU_FINDINFILES ] = fill ( cb_func_menu_search , GDK_f ,
2007-09-13 16:45:46 +00:00
GDK_CONTROL_MASK | GDK_SHIFT_MASK , " menu_findinfiles " , _ ( " Find in Files " ) ) ;
2007-09-13 16:40:19 +00:00
keys [ GEANY_KEYS_MENU_NEXTMESSAGE ] = fill ( cb_func_menu_search ,
2006-12-09 17:03:03 +00:00
0 , 0 , " menu_nextmessage " , _ ( " Next Message " ) ) ;
2007-09-13 16:40:19 +00:00
keys [ GEANY_KEYS_MENU_GOTOLINE ] = fill ( cb_func_menu_search ,
2007-09-13 16:45:46 +00:00
GDK_l , GDK_CONTROL_MASK , " menu_gotoline " , _ ( " Go to Line " ) ) ;
2007-05-03 15:38:02 +00:00
2007-05-06 14:49:51 +00:00
keys [ GEANY_KEYS_MENU_TOGGLEALL ] = fill ( cb_func_menu_toggle_all ,
2007-11-08 16:39:34 +00:00
0 , 0 , " menu_toggleall " , _ ( " Toggle All Additional Widgets " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_MENU_FULLSCREEN ] = fill ( cb_func_menu_fullscreen ,
GDK_F11 , 0 , " menu_fullscreen " , _ ( " Fullscreen " ) ) ;
keys [ GEANY_KEYS_MENU_MESSAGEWINDOW ] = fill ( cb_func_menu_messagewindow ,
0 , 0 , " menu_messagewindow " , _ ( " Toggle Messages Window " ) ) ;
keys [ GEANY_KEYS_MENU_SIDEBAR ] = fill ( cb_func_toggle_sidebar ,
0 , 0 , " toggle_sidebar " , _ ( " Toggle Sidebar " ) ) ;
keys [ GEANY_KEYS_MENU_ZOOMIN ] = fill ( cb_func_menu_zoomin ,
GDK_plus , GDK_CONTROL_MASK , " menu_zoomin " , _ ( " Zoom In " ) ) ;
keys [ GEANY_KEYS_MENU_ZOOMOUT ] = fill ( cb_func_menu_zoomout ,
GDK_minus , GDK_CONTROL_MASK , " menu_zoomout " , _ ( " Zoom Out " ) ) ;
2007-05-03 15:38:02 +00:00
keys [ GEANY_KEYS_MENU_OPENCOLORCHOOSER ] = fill ( cb_func_menu_opencolorchooser ,
2007-07-27 11:56:50 +00:00
0 , 0 , " menu_opencolorchooser " , _ ( " Show Color Chooser " ) ) ;
2007-05-03 15:38:02 +00:00
keys [ GEANY_KEYS_MENU_INSERTSPECIALCHARS ] = fill ( cb_func_menu_insert_specialchars ,
0 , 0 , " menu_insert_specialchars " , _ ( " Insert Special HTML Characters " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_MENU_REPLACETABS ] = fill ( cb_func_menu_replacetabs ,
0 , 0 , " menu_replacetabs " , _ ( " Replace tabs by space " ) ) ;
keys [ GEANY_KEYS_MENU_FOLDALL ] = fill ( cb_func_menu_foldall ,
0 , 0 , " menu_foldall " , _ ( " Fold all " ) ) ;
keys [ GEANY_KEYS_MENU_UNFOLDALL ] = fill ( cb_func_menu_unfoldall ,
0 , 0 , " menu_unfoldall " , _ ( " Unfold all " ) ) ;
2007-05-03 15:38:02 +00:00
keys [ GEANY_KEYS_RELOADTAGLIST ] = fill ( cb_func_reloadtaglist ,
GDK_r , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " reloadtaglist " , _ ( " Reload symbol list " ) ) ;
2006-11-29 10:29:34 +00:00
keys [ GEANY_KEYS_BUILD_COMPILE ] = fill ( cb_func_build_action ,
2006-06-18 17:14:32 +00:00
GDK_F8 , 0 , " build_compile " , _ ( " Compile " ) ) ;
2006-11-29 10:29:34 +00:00
keys [ GEANY_KEYS_BUILD_LINK ] = fill ( cb_func_build_action ,
2006-06-18 17:14:32 +00:00
GDK_F9 , 0 , " build_link " , _ ( " Build " ) ) ;
2006-11-29 10:29:34 +00:00
keys [ GEANY_KEYS_BUILD_MAKE ] = fill ( cb_func_build_action ,
2006-07-06 09:43:10 +00:00
GDK_F9 , GDK_SHIFT_MASK , " build_make " , _ ( " Make all " ) ) ;
2006-11-29 10:29:34 +00:00
keys [ GEANY_KEYS_BUILD_MAKEOWNTARGET ] = fill ( cb_func_build_action ,
2006-07-06 09:43:10 +00:00
GDK_F9 , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " build_makeowntarget " ,
_ ( " Make custom target " ) ) ;
2006-11-29 10:29:34 +00:00
keys [ GEANY_KEYS_BUILD_MAKEOBJECT ] = fill ( cb_func_build_action ,
2006-07-06 09:43:10 +00:00
0 , 0 , " build_makeobject " , _ ( " Make object " ) ) ;
2006-12-09 17:03:03 +00:00
keys [ GEANY_KEYS_BUILD_NEXTERROR ] = fill ( cb_func_build_action ,
0 , 0 , " build_nexterror " , _ ( " Next error " ) ) ;
2006-11-29 10:29:34 +00:00
keys [ GEANY_KEYS_BUILD_RUN ] = fill ( cb_func_build_action ,
2006-06-18 17:14:32 +00:00
GDK_F5 , 0 , " build_run " , _ ( " Run " ) ) ;
2006-11-29 10:29:34 +00:00
keys [ GEANY_KEYS_BUILD_RUN2 ] = fill ( cb_func_build_action ,
2006-06-18 17:14:32 +00:00
0 , 0 , " build_run2 " , _ ( " Run (alternative command) " ) ) ;
2006-11-30 15:42:52 +00:00
keys [ GEANY_KEYS_BUILD_OPTIONS ] = fill ( cb_func_build_action ,
2006-06-18 17:14:32 +00:00
0 , 0 , " build_options " , _ ( " Build options " ) ) ;
2007-05-03 15:38:02 +00:00
2007-07-04 14:41:58 +00:00
keys [ GEANY_KEYS_MENU_HELP ] = fill ( cb_func_menu_help ,
GDK_F1 , 0 , " menu_help " , _ ( " Help " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_SWITCH_EDITOR ] = fill ( cb_func_switch_editor ,
GDK_F2 , 0 , " switch_editor " , _ ( " Switch to Editor " ) ) ;
keys [ GEANY_KEYS_SWITCH_SCRIBBLE ] = fill ( cb_func_switch_scribble ,
GDK_F6 , 0 , " switch_scribble " , _ ( " Switch to Scribble " ) ) ;
keys [ GEANY_KEYS_SWITCH_VTE ] = fill ( cb_func_switch_vte ,
GDK_F4 , 0 , " switch_vte " , _ ( " Switch to VTE " ) ) ;
2007-03-30 10:38:13 +00:00
keys [ GEANY_KEYS_SWITCH_SEARCH_BAR ] = fill ( cb_func_switch_search_bar ,
GDK_F7 , 0 , " switch_search_bar " , _ ( " Switch to Search Bar " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_SWITCH_TABLEFT ] = fill ( cb_func_switch_tableft ,
GDK_Page_Up , GDK_CONTROL_MASK , " switch_tableft " , _ ( " Switch to left document " ) ) ;
keys [ GEANY_KEYS_SWITCH_TABRIGHT ] = fill ( cb_func_switch_tabright ,
GDK_Page_Down , GDK_CONTROL_MASK , " switch_tabright " , _ ( " Switch to right document " ) ) ;
2007-03-13 17:00:12 +00:00
keys [ GEANY_KEYS_SWITCH_TABLASTUSED ] = fill ( cb_func_switch_tablastused ,
GDK_Tab , GDK_CONTROL_MASK , " switch_tablastused " , _ ( " Switch to last used document " ) ) ;
2007-09-07 12:34:57 +00:00
keys [ GEANY_KEYS_MOVE_TABLEFT ] = fill ( cb_func_move_tab ,
GDK_Page_Up , GDK_MOD1_MASK , " move_tableft " , _ ( " Move document left " ) ) ;
keys [ GEANY_KEYS_MOVE_TABRIGHT ] = fill ( cb_func_move_tab ,
GDK_Page_Down , GDK_MOD1_MASK , " move_tabright " , _ ( " Move document right " ) ) ;
2007-12-16 16:54:47 +00:00
keys [ GEANY_KEYS_MOVE_TABFIRST ] = fill ( cb_func_move_tab ,
0 , 0 , " move_tabfirst " , _ ( " Move document first " ) ) ;
keys [ GEANY_KEYS_MOVE_TABLAST ] = fill ( cb_func_move_tab ,
0 , 0 , " move_tablast " , _ ( " Move document last " ) ) ;
2007-06-03 16:03:46 +00:00
keys [ GEANY_KEYS_NAV_BACK ] = fill ( cb_func_nav_back ,
0 , 0 , " nav_back " , _ ( " Navigate back a location " ) ) ;
keys [ GEANY_KEYS_NAV_FORWARD ] = fill ( cb_func_nav_forward ,
0 , 0 , " nav_forward " , _ ( " Navigate forward a location " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_DUPLICATELINE ] = fill ( cb_func_edit ,
2007-03-26 12:13:04 +00:00
GDK_d , GDK_CONTROL_MASK , " edit_duplicateline " , _ ( " Duplicate line or selection " ) ) ;
2007-07-07 15:12:13 +00:00
keys [ GEANY_KEYS_EDIT_DELETELINE ] = fill ( cb_func_edit ,
2007-08-10 11:29:37 +00:00
GDK_k , GDK_CONTROL_MASK , " edit_deleteline " , _ ( " Delete current line(s) " ) ) ;
2007-07-07 15:12:13 +00:00
keys [ GEANY_KEYS_EDIT_COPYLINE ] = fill ( cb_func_edit ,
2007-09-03 12:17:58 +00:00
GDK_c , GDK_CONTROL_MASK | GDK_SHIFT_MASK , " edit_copyline " , _ ( " Copy current line(s) " ) ) ;
2007-07-07 15:12:13 +00:00
keys [ GEANY_KEYS_EDIT_CUTLINE ] = fill ( cb_func_edit ,
2007-09-03 12:17:58 +00:00
GDK_x , GDK_CONTROL_MASK | GDK_SHIFT_MASK , " edit_cutline " , _ ( " Cut current line(s) " ) ) ;
2007-07-07 15:12:13 +00:00
keys [ GEANY_KEYS_EDIT_TRANSPOSELINE ] = fill ( cb_func_edit ,
GDK_t , GDK_CONTROL_MASK , " edit_transposeline " , _ ( " Transpose current line " ) ) ;
2007-09-07 19:01:55 +00:00
keys [ GEANY_KEYS_EDIT_TOGGLECASE ] = fill ( cb_func_edit ,
GDK_u , GDK_CONTROL_MASK | GDK_MOD1_MASK , " edit_togglecase " , _ ( " Toggle Case of Selection " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_COMMENTLINETOGGLE ] = fill ( cb_func_edit ,
2007-07-05 18:19:56 +00:00
GDK_e , GDK_CONTROL_MASK , " edit_commentlinetoggle " , _ ( " Toggle line commentation " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_COMMENTLINE ] = fill ( cb_func_edit ,
2007-07-05 18:19:56 +00:00
0 , 0 , " edit_commentline " , _ ( " Comment line(s) " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_UNCOMMENTLINE ] = fill ( cb_func_edit ,
2007-07-09 15:35:25 +00:00
0 , 0 , " edit_uncommentline " , _ ( " Uncomment line(s) " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_INCREASEINDENT ] = fill ( cb_func_edit ,
2006-08-01 10:35:32 +00:00
GDK_i , GDK_CONTROL_MASK , " edit_increaseindent " , _ ( " Increase indent " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_DECREASEINDENT ] = fill ( cb_func_edit ,
2007-11-08 16:39:34 +00:00
GDK_u , GDK_CONTROL_MASK , " edit_decreaseindent " , _ ( " Decrease indent " ) ) ;
2007-07-16 15:42:12 +00:00
keys [ GEANY_KEYS_EDIT_INCREASEINDENTBYSPACE ] = fill ( cb_func_edit ,
0 , 0 , " edit_increaseindentbyspace " , _ ( " Increase indent by one space " ) ) ;
keys [ GEANY_KEYS_EDIT_DECREASEINDENTBYSPACE ] = fill ( cb_func_edit ,
0 , 0 , " edit_decreaseindentbyspace " , _ ( " Decrease indent by one space " ) ) ;
keys [ GEANY_KEYS_EDIT_AUTOINDENT ] = fill ( cb_func_edit ,
0 , 0 , " edit_autoindent " , _ ( " Smart line indent " ) ) ;
2007-02-25 14:26:55 +00:00
keys [ GEANY_KEYS_EDIT_SENDTOCMD1 ] = fill ( cb_func_edit ,
2007-03-29 14:39:04 +00:00
GDK_1 , GDK_CONTROL_MASK , " edit_sendtocmd1 " , _ ( " Send to Custom Command 1 " ) ) ;
2007-02-25 14:26:55 +00:00
keys [ GEANY_KEYS_EDIT_SENDTOCMD2 ] = fill ( cb_func_edit ,
2007-03-29 14:39:04 +00:00
GDK_2 , GDK_CONTROL_MASK , " edit_sendtocmd2 " , _ ( " Send to Custom Command 2 " ) ) ;
2007-02-25 14:26:55 +00:00
keys [ GEANY_KEYS_EDIT_SENDTOCMD3 ] = fill ( cb_func_edit ,
2007-03-29 14:39:04 +00:00
GDK_3 , GDK_CONTROL_MASK , " edit_sendtocmd3 " , _ ( " Send to Custom Command 3 " ) ) ;
2007-05-05 16:35:59 +00:00
keys [ GEANY_KEYS_EDIT_GOTOMATCHINGBRACE ] = fill ( cb_func_edit_global ,
2007-07-09 13:53:27 +00:00
GDK_b , GDK_CONTROL_MASK , " edit_gotomatchingbrace " ,
2007-08-30 10:04:39 +00:00
_ ( " Go to matching brace " ) ) ;
2007-05-05 16:35:59 +00:00
keys [ GEANY_KEYS_EDIT_TOGGLEMARKER ] = fill ( cb_func_edit_global ,
2007-03-15 13:14:04 +00:00
GDK_m , GDK_CONTROL_MASK , " edit_togglemarker " ,
_ ( " Toggle marker " ) ) ;
2007-05-05 16:35:59 +00:00
keys [ GEANY_KEYS_EDIT_GOTONEXTMARKER ] = fill ( cb_func_edit_global ,
2007-03-15 12:52:16 +00:00
GDK_period , GDK_CONTROL_MASK , " edit_gotonextmarker " ,
2007-08-30 10:04:39 +00:00
_ ( " Go to next marker " ) ) ;
2007-05-05 16:35:59 +00:00
keys [ GEANY_KEYS_EDIT_GOTOPREVIOUSMARKER ] = fill ( cb_func_edit_global ,
2007-03-15 12:52:16 +00:00
GDK_comma , GDK_CONTROL_MASK , " edit_gotopreviousmarker " ,
2007-08-30 10:04:39 +00:00
_ ( " Go to previous marker " ) ) ;
2007-05-03 15:38:02 +00:00
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_AUTOCOMPLETE ] = fill ( cb_func_edit ,
2006-06-18 17:14:32 +00:00
GDK_space , GDK_CONTROL_MASK , " edit_autocomplete " , _ ( " Complete word " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_CALLTIP ] = fill ( cb_func_edit ,
2006-07-26 14:28:20 +00:00
GDK_space , GDK_CONTROL_MASK | GDK_SHIFT_MASK , " edit_calltip " , _ ( " Show calltip " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_MACROLIST ] = fill ( cb_func_edit ,
2006-06-18 17:14:32 +00:00
GDK_Return , GDK_CONTROL_MASK , " edit_macrolist " , _ ( " Show macro list " ) ) ;
2007-11-12 09:27:43 +00:00
keys [ GEANY_KEYS_EDIT_COMPLETESNIPPET ] = fill ( NULL , // has special callback
GDK_Tab , 0 , " edit_completesnippet " , _ ( " Complete snippet " ) ) ;
keys [ GEANY_KEYS_EDIT_SUPPRESSSNIPPETCOMPLETION ] = fill ( cb_func_edit ,
0 , 0 , " edit_suppresssnippetcompletion " , _ ( " Suppress snippet completion " ) ) ;
2006-10-26 15:22:27 +00:00
2007-03-22 15:51:39 +00:00
keys [ GEANY_KEYS_EDIT_SELECTWORD ] = fill ( cb_func_edit ,
2007-07-06 10:16:51 +00:00
GDK_w , GDK_SHIFT_MASK | GDK_MOD1_MASK , " edit_selectword " , _ ( " Select current word " ) ) ;
2007-07-07 15:12:13 +00:00
keys [ GEANY_KEYS_EDIT_SELECTLINE ] = fill ( cb_func_edit ,
2007-08-10 11:29:37 +00:00
GDK_l , GDK_SHIFT_MASK | GDK_MOD1_MASK , " edit_selectline " , _ ( " Select current line(s) " ) ) ;
2007-07-06 10:16:51 +00:00
keys [ GEANY_KEYS_EDIT_SELECTPARAGRAPH ] = fill ( cb_func_edit ,
GDK_p , GDK_SHIFT_MASK | GDK_MOD1_MASK , " edit_selectparagraph " , _ ( " Select current paragraph " ) ) ;
2007-07-17 16:27:49 +00:00
keys [ GEANY_KEYS_EDIT_SCROLLTOLINE ] = fill ( cb_func_edit ,
GDK_l , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " edit_scrolltoline " , _ ( " Scroll to current line " ) ) ;
2007-09-05 18:55:51 +00:00
keys [ GEANY_KEYS_EDIT_SCROLLLINEUP ] = fill ( cb_func_edit ,
2007-09-13 12:38:14 +00:00
GDK_Up , GDK_MOD1_MASK , " edit_scrolllineup " , _ ( " Scroll up the view by one line " ) ) ;
2007-09-05 18:55:51 +00:00
keys [ GEANY_KEYS_EDIT_SCROLLLINEDOWN ] = fill ( cb_func_edit ,
2007-09-13 12:38:14 +00:00
GDK_Down , GDK_MOD1_MASK , " edit_scrolllinedown " , _ ( " Scroll down the view by one line " ) ) ;
2007-03-22 15:51:39 +00:00
2007-03-25 20:51:45 +00:00
keys [ GEANY_KEYS_EDIT_INSERTALTWHITESPACE ] = fill ( cb_func_edit ,
0 , 0 , " edit_insertwhitespace " , _ ( " Insert alternative whitespace " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_POPUP_FINDUSAGE ] = fill ( cb_func_current_word ,
2006-06-17 21:08:47 +00:00
0 , 0 , " popup_findusage " , _ ( " Find Usage " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_POPUP_GOTOTAGDEFINITION ] = fill ( cb_func_current_word ,
2007-09-13 16:45:46 +00:00
0 , 0 , " popup_gototagdefinition " , _ ( " Go to Tag Definition " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_POPUP_GOTOTAGDECLARATION ] = fill ( cb_func_current_word ,
2007-09-13 16:45:46 +00:00
0 , 0 , " popup_gototagdeclaration " , _ ( " Go to Tag Declaration " ) ) ;
2007-04-15 18:09:59 +00:00
keys [ GEANY_KEYS_POPUP_CONTEXTACTION ] = fill ( cb_func_current_word ,
0 , 0 , " popup_contextaction " , _ ( " Context Action " ) ) ;
2007-09-27 11:13:59 +00:00
}
2008-02-20 11:24:23 +00:00
static void load_user_kb ( void )
2007-09-27 11:13:59 +00:00
{
gchar * configfile = g_strconcat ( app - > configdir , G_DIR_SEPARATOR_S , " keybindings.conf " , NULL ) ;
gchar * val ;
guint i ;
guint key ;
GdkModifierType mods ;
GKeyFile * config = g_key_file_new ( ) ;
2006-05-19 17:18:06 +00:00
// now load user defined keys
if ( g_key_file_load_from_file ( config , configfile , G_KEY_FILE_KEEP_COMMENTS , NULL ) )
{
for ( i = 0 ; i < GEANY_MAX_KEYS ; i + + )
{
val = g_key_file_get_string ( config , " Bindings " , keys [ i ] - > name , NULL ) ;
if ( val ! = NULL )
{
gtk_accelerator_parse ( val , & key , & mods ) ;
keys [ i ] - > key = key ;
keys [ i ] - > mods = mods ;
}
g_free ( val ) ;
}
}
2007-09-27 11:13:59 +00:00
g_free ( configfile ) ;
g_key_file_free ( config ) ;
}
void keybindings_init ( void )
{
init_default_kb ( ) ;
load_user_kb ( ) ;
2006-05-19 17:18:06 +00:00
2007-07-09 13:48:41 +00:00
// set section name
2007-11-06 16:59:01 +00:00
keys [ GEANY_KEYS_GROUP_FILE ] - > section = _ ( " File menu " ) ;
keys [ GEANY_KEYS_GROUP_EDIT ] - > section = _ ( " Edit menu " ) ;
keys [ GEANY_KEYS_GROUP_SEARCH ] - > section = _ ( " Search menu " ) ;
keys [ GEANY_KEYS_GROUP_VIEW ] - > section = _ ( " View menu " ) ;
keys [ GEANY_KEYS_GROUP_DOCUMENT ] - > section = _ ( " Document menu " ) ;
keys [ GEANY_KEYS_GROUP_BUILD ] - > section = _ ( " Build menu " ) ;
keys [ GEANY_KEYS_GROUP_TOOLS ] - > section = _ ( " Tools menu " ) ;
keys [ GEANY_KEYS_GROUP_HELP ] - > section = _ ( " Help menu " ) ;
keys [ GEANY_KEYS_GROUP_FOCUS ] - > section = _ ( " Focus commands " ) ;
keys [ GEANY_KEYS_GROUP_TABS ] - > section = _ ( " Notebook tab commands " ) ;
keys [ GEANY_KEYS_GROUP_EDITING ] - > section = _ ( " Editing commands " ) ;
keys [ GEANY_KEYS_GROUP_TAGS ] - > section = _ ( " Tag commands " ) ;
keys [ GEANY_KEYS_GROUP_OTHER ] - > section = _ ( " Other commands " ) ;
2007-07-09 13:48:41 +00:00
2007-09-28 16:32:28 +00:00
add_menu_accels ( ) ;
2006-05-24 16:56:14 +00:00
}
# define GEANY_ADD_ACCEL(gkey, wid) \
if ( keys [ ( gkey ) ] - > key ! = 0 ) \
gtk_widget_add_accelerator ( \
lookup_widget ( app - > window , G_STRINGIFY ( wid ) ) , \
" activate " , accel_group , keys [ ( gkey ) ] - > key , keys [ ( gkey ) ] - > mods , \
2006-05-30 15:28:13 +00:00
GTK_ACCEL_VISIBLE )
2006-05-24 16:56:14 +00:00
2006-06-17 21:08:47 +00:00
# define GEANY_ADD_POPUP_ACCEL(gkey, wid) \
if ( keys [ ( gkey ) ] - > key ! = 0 ) \
gtk_widget_add_accelerator ( \
lookup_widget ( app - > popup_menu , G_STRINGIFY ( wid ) ) , \
" activate " , accel_group , keys [ ( gkey ) ] - > key , keys [ ( gkey ) ] - > mods , \
GTK_ACCEL_VISIBLE )
2007-09-28 16:32:28 +00:00
static void add_menu_accels ( )
2006-05-24 16:56:14 +00:00
{
GtkAccelGroup * accel_group = gtk_accel_group_new ( ) ;
2006-05-19 17:18:06 +00:00
// apply the settings
2007-05-03 15:38:02 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_OPENSELECTED , menu_open_selected_file1 ) ;
2006-05-30 15:28:13 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_SAVEALL , menu_save_all1 ) ;
2007-01-08 18:15:06 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_SAVEAS , menu_save_as1 ) ;
2006-06-29 17:14:52 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_PRINT , print1 ) ;
2006-06-21 18:54:07 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_CLOSE , menu_close1 ) ;
2006-05-30 15:28:13 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_CLOSEALL , menu_close_all1 ) ;
2006-07-22 02:06:30 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_RELOADFILE , menu_reload1 ) ;
2006-06-18 17:05:09 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_UNDO , menu_undo2 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_REDO , menu_redo2 ) ;
2006-07-01 14:12:05 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_SELECTALL , menu_select_all1 ) ;
2006-08-19 12:56:30 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_INSERTDATE , insert_date_custom1 ) ;
2006-05-30 15:28:13 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_PREFERENCES , preferences1 ) ;
2007-07-04 14:41:58 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_HELP , help1 ) ;
2007-09-13 16:40:19 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_FIND , find1 ) ;
2006-07-15 11:17:23 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_FINDNEXT , find_next1 ) ;
2006-05-30 15:28:13 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_FINDPREVIOUS , find_previous1 ) ;
2007-01-23 17:51:30 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_FINDNEXTSEL , find_nextsel1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_FINDPREVSEL , find_prevsel1 ) ;
2006-05-30 15:28:13 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_REPLACE , replace1 ) ;
2006-07-15 11:17:23 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_FINDINFILES , find_in_files1 ) ;
2006-12-09 17:03:03 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_NEXTMESSAGE , next_message1 ) ;
2006-05-30 15:28:13 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_GOTOLINE , go_to_line1 ) ;
2007-09-13 16:40:19 +00:00
2007-05-06 14:49:51 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_TOGGLEALL , menu_toggle_all_additional_widgets1 ) ;
2006-05-30 15:28:13 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_FULLSCREEN , menu_fullscreen1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_MESSAGEWINDOW , menu_show_messages_window1 ) ;
2007-05-06 14:49:51 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_SIDEBAR , menu_show_sidebar1 ) ;
2006-05-30 15:28:13 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_ZOOMIN , menu_zoom_in1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_ZOOMOUT , menu_zoom_out1 ) ;
2007-09-28 16:32:28 +00:00
2006-05-30 15:28:13 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_REPLACETABS , menu_replace_tabs ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_FOLDALL , menu_fold_all1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_UNFOLDALL , menu_unfold_all1 ) ;
2007-09-28 16:32:28 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_PROJECTPROPERTIES , project_properties1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_OPENCOLORCHOOSER , menu_choose_color1 ) ;
2007-07-23 15:41:08 +00:00
//~ GEANY_ADD_ACCEL(GEANY_KEYS_MENU_INSERTSPECIALCHARS, menu_insert_special_chars1);
2007-09-28 16:32:28 +00:00
2007-09-07 19:01:55 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_EDIT_TOGGLECASE , menu_toggle_case2 ) ;
2006-08-01 10:35:32 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_EDIT_COMMENTLINE , menu_comment_line1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_EDIT_UNCOMMENTLINE , menu_uncomment_line1 ) ;
2006-09-12 08:32:52 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_EDIT_COMMENTLINETOGGLE , menu_toggle_line_commentation1 ) ;
2006-08-01 10:35:32 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_EDIT_DUPLICATELINE , menu_duplicate_line1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_EDIT_INCREASEINDENT , menu_increase_indent1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_EDIT_DECREASEINDENT , menu_decrease_indent1 ) ;
2006-05-19 17:18:06 +00:00
2006-06-18 17:05:09 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_MENU_UNDO , undo1 ) ;
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_MENU_REDO , redo1 ) ;
2006-07-01 14:12:05 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_MENU_SELECTALL , menu_select_all2 ) ;
2006-08-19 12:56:30 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_MENU_INSERTDATE , insert_date_custom2 ) ;
2007-05-03 15:38:02 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_MENU_OPENSELECTED , menu_open_selected_file2 ) ;
2006-06-17 21:08:47 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_POPUP_FINDUSAGE , find_usage1 ) ;
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_POPUP_GOTOTAGDEFINITION , goto_tag_definition1 ) ;
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_POPUP_GOTOTAGDECLARATION , goto_tag_declaration1 ) ;
2007-04-15 18:09:59 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_POPUP_CONTEXTACTION , context_action1 ) ;
2006-06-18 17:05:09 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_MENU_GOTOLINE , go_to_line ) ;
2007-09-07 19:01:55 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_EDIT_TOGGLECASE , toggle_case1 ) ;
2006-08-01 10:35:32 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_EDIT_COMMENTLINE , menu_comment_line2 ) ;
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_EDIT_UNCOMMENTLINE , menu_uncomment_line2 ) ;
2006-09-12 08:32:52 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_EDIT_COMMENTLINETOGGLE , menu_toggle_line_commentation2 ) ;
2006-08-01 10:35:32 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_EDIT_DUPLICATELINE , menu_duplicate_line2 ) ;
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_EDIT_INCREASEINDENT , menu_increase_indent2 ) ;
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_EDIT_DECREASEINDENT , menu_decrease_indent2 ) ;
2006-06-17 21:08:47 +00:00
2006-05-19 17:18:06 +00:00
// the build menu items are set if the build menus are created
gtk_window_add_accel_group ( GTK_WINDOW ( app - > window ) , accel_group ) ;
}
/* just write the content of the keys array to the config file */
void keybindings_write_to_file ( void )
{
gchar * configfile = g_strconcat ( app - > configdir , G_DIR_SEPARATOR_S , " keybindings.conf " , NULL ) ;
gchar * val , * data ;
guint i ;
GKeyFile * config = g_key_file_new ( ) ;
2007-08-28 10:50:18 +00:00
// add comment if the file is newly created
2006-05-19 17:18:06 +00:00
if ( ! g_key_file_load_from_file ( config , configfile , G_KEY_FILE_KEEP_COMMENTS , NULL ) )
{
g_key_file_set_comment ( config , NULL , NULL , " Keybindings for Geany \n The format looks like \" <Control>a \" or \" <Shift><Alt>F1 \" . \n But you can also change the keys in Geany's preferences dialog. " , NULL ) ;
}
for ( i = 0 ; i < GEANY_MAX_KEYS ; i + + )
{
val = gtk_accelerator_name ( keys [ i ] - > key , keys [ i ] - > mods ) ;
g_key_file_set_string ( config , " Bindings " , keys [ i ] - > name , val ) ;
g_free ( val ) ;
}
// write the file
data = g_key_file_to_data ( config , NULL , NULL ) ;
utils_write_file ( configfile , data ) ;
g_free ( data ) ;
g_free ( configfile ) ;
g_key_file_free ( config ) ;
}
void keybindings_free ( void )
{
guint i ;
for ( i = 0 ; i < GEANY_MAX_KEYS ; i + + )
{
g_free ( keys [ i ] ) ;
}
}
2007-03-29 14:39:04 +00:00
static void get_shortcut_labels_text ( GString * * text_names_str , GString * * text_keys_str )
2007-03-23 16:34:54 +00:00
{
2007-03-29 14:39:04 +00:00
guint i ;
2007-03-23 16:34:54 +00:00
GString * text_names = g_string_sized_new ( 600 ) ;
GString * text_keys = g_string_sized_new ( 600 ) ;
2007-03-29 14:39:04 +00:00
* text_names_str = text_names ;
* text_keys_str = text_keys ;
for ( i = 0 ; i < GEANY_MAX_KEYS ; i + + )
{
gchar * shortcut ;
2007-07-09 13:48:41 +00:00
if ( keys [ i ] - > section ! = NULL )
2007-03-29 14:39:04 +00:00
{
2007-07-09 13:48:41 +00:00
if ( i = = GEANY_KEYS_MENU_NEW )
{
g_string_append_printf ( text_names , " <b>%s</b> \n " , keys [ i ] - > section ) ;
2007-03-29 14:39:04 +00:00
g_string_append ( text_keys , " \n " ) ;
2007-07-09 13:48:41 +00:00
}
else
{
g_string_append_printf ( text_names , " \n <b>%s</b> \n " , keys [ i ] - > section ) ;
2007-03-29 14:39:04 +00:00
g_string_append ( text_keys , " \n \n " ) ;
2007-07-09 13:48:41 +00:00
}
2007-03-29 14:39:04 +00:00
}
shortcut = gtk_accelerator_get_label ( keys [ i ] - > key , keys [ i ] - > mods ) ;
g_string_append ( text_names , keys [ i ] - > label ) ;
g_string_append ( text_names , " \n " ) ;
g_string_append ( text_keys , shortcut ) ;
g_string_append ( text_keys , " \n " ) ;
g_free ( shortcut ) ;
}
}
void keybindings_show_shortcuts ( )
{
GtkWidget * dialog , * hbox , * label1 , * label2 , * label3 , * swin , * vbox ;
GString * text_names ;
GString * text_keys ;
2007-03-23 16:34:54 +00:00
gint height , response ;
2007-07-12 11:59:13 +00:00
dialog = gtk_dialog_new_with_buttons ( _ ( " Keyboard Shortcuts " ) , GTK_WINDOW ( app - > window ) ,
2007-03-23 16:34:54 +00:00
GTK_DIALOG_DESTROY_WITH_PARENT ,
GTK_STOCK_EDIT , GTK_RESPONSE_APPLY ,
GTK_STOCK_CLOSE , GTK_RESPONSE_CANCEL , NULL ) ;
vbox = ui_dialog_vbox_new ( GTK_DIALOG ( dialog ) ) ;
gtk_box_set_spacing ( GTK_BOX ( vbox ) , 6 ) ;
2007-05-15 15:16:16 +00:00
gtk_widget_set_name ( dialog , " GeanyDialog " ) ;
2007-03-23 16:34:54 +00:00
height = GEANY_WINDOW_MINIMAL_HEIGHT ;
2008-02-20 11:24:23 +00:00
gtk_window_set_default_size ( GTK_WINDOW ( dialog ) , height * 8 / 10 , height ) ;
2007-03-23 16:34:54 +00:00
gtk_dialog_set_default_response ( GTK_DIALOG ( dialog ) , GTK_RESPONSE_CANCEL ) ;
2007-09-04 15:39:17 +00:00
label3 = gtk_label_new ( _ ( " The following keyboard shortcuts are configurable: " ) ) ;
2007-03-23 16:34:54 +00:00
gtk_misc_set_alignment ( GTK_MISC ( label3 ) , 0 , 0.5 ) ;
hbox = gtk_hbox_new ( FALSE , 6 ) ;
label1 = gtk_label_new ( NULL ) ;
label2 = gtk_label_new ( NULL ) ;
2007-03-29 14:39:04 +00:00
get_shortcut_labels_text ( & text_names , & text_keys ) ;
2007-03-23 16:34:54 +00:00
2007-03-29 14:39:04 +00:00
gtk_label_set_markup ( GTK_LABEL ( label1 ) , text_names - > str ) ;
2007-03-23 16:34:54 +00:00
gtk_label_set_text ( GTK_LABEL ( label2 ) , text_keys - > str ) ;
2007-03-29 14:39:04 +00:00
g_string_free ( text_names , TRUE ) ;
g_string_free ( text_keys , TRUE ) ;
2007-03-23 16:34:54 +00:00
gtk_container_add ( GTK_CONTAINER ( hbox ) , label1 ) ;
gtk_container_add ( GTK_CONTAINER ( hbox ) , label2 ) ;
swin = gtk_scrolled_window_new ( NULL , NULL ) ;
gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( swin ) , GTK_POLICY_AUTOMATIC ,
GTK_POLICY_AUTOMATIC ) ;
gtk_scrolled_window_add_with_viewport ( GTK_SCROLLED_WINDOW ( swin ) , hbox ) ;
gtk_box_pack_start ( GTK_BOX ( vbox ) , label3 , FALSE , FALSE , 6 ) ;
gtk_box_pack_start ( GTK_BOX ( vbox ) , swin , TRUE , TRUE , 0 ) ;
gtk_widget_show_all ( dialog ) ;
response = gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
if ( response = = GTK_RESPONSE_APPLY )
{
GtkWidget * wid ;
2007-03-23 16:47:27 +00:00
prefs_show_dialog ( ) ;
2007-03-23 16:34:54 +00:00
// select the KB page
2007-08-23 11:34:06 +00:00
wid = lookup_widget ( ui_widgets . prefs_dialog , " frame22 " ) ;
2007-03-23 16:34:54 +00:00
if ( wid ! = NULL )
{
2007-08-23 11:34:06 +00:00
GtkNotebook * nb = GTK_NOTEBOOK ( lookup_widget ( ui_widgets . prefs_dialog , " notebook2 " ) ) ;
2007-03-23 16:34:54 +00:00
if ( nb ! = NULL )
gtk_notebook_set_current_page ( nb , gtk_notebook_page_num ( nb , wid ) ) ;
}
}
gtk_widget_destroy ( dialog ) ;
}
2008-02-12 15:49:54 +00:00
static gboolean check_fixed_kb ( guint keyval , guint state )
2006-11-23 12:23:36 +00:00
{
// check alt-0 to alt-9 for setting current notebook page
2008-02-12 15:49:54 +00:00
if ( state & GDK_MOD1_MASK & & keyval > = GDK_0 & & keyval < = GDK_9 )
2006-11-23 12:23:36 +00:00
{
2008-02-12 15:49:54 +00:00
gint page = keyval - GDK_0 - 1 ;
2006-11-23 12:23:36 +00:00
gint npages = gtk_notebook_get_n_pages ( GTK_NOTEBOOK ( app - > notebook ) ) ;
// alt-0 is for the rightmost tab
2008-02-12 15:49:54 +00:00
if ( keyval = = GDK_0 )
2006-11-23 12:23:36 +00:00
page = npages - 1 ;
// invert the order if tabs are added on the other side
2007-08-23 11:34:06 +00:00
if ( swap_alt_tab_order & & ! prefs . tab_order_ltr )
2006-11-23 12:23:36 +00:00
page = ( npages - 1 ) - page ;
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( app - > notebook ) , page ) ;
return TRUE ;
}
2008-02-12 15:49:54 +00:00
if ( keyval = = GDK_Page_Up | | keyval = = GDK_Page_Down )
2007-09-07 12:34:57 +00:00
{
// switch to first or last document
2008-02-12 15:49:54 +00:00
if ( state = = ( GDK_CONTROL_MASK | GDK_SHIFT_MASK ) )
2007-09-07 12:34:57 +00:00
{
2008-02-12 15:49:54 +00:00
if ( keyval = = GDK_Page_Up )
2007-09-07 12:34:57 +00:00
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( app - > notebook ) , 0 ) ;
2008-02-12 15:49:54 +00:00
if ( keyval = = GDK_Page_Down )
2007-09-07 12:34:57 +00:00
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( app - > notebook ) ,
gtk_notebook_get_n_pages ( GTK_NOTEBOOK ( app - > notebook ) ) - 1 ) ;
return TRUE ;
}
}
2006-11-23 12:23:36 +00:00
return FALSE ;
}
2007-11-12 09:27:43 +00:00
/* We have a special case for GEANY_KEYS_EDIT_COMPLETESNIPPET, because we need to
2007-03-27 15:48:16 +00:00
* return FALSE if no completion occurs , so the tab or space is handled normally . */
2008-02-12 15:49:54 +00:00
static gboolean check_snippet_completion ( guint keyval , guint state )
2007-03-27 15:48:16 +00:00
{
2007-11-12 09:27:43 +00:00
const guint i = GEANY_KEYS_EDIT_COMPLETESNIPPET ;
2007-03-27 15:48:16 +00:00
2008-02-12 15:49:54 +00:00
if ( keys [ i ] - > key = = keyval & & keys [ i ] - > mods = = state )
2007-03-27 15:48:16 +00:00
{
gint idx = document_get_cur_idx ( ) ;
2007-04-05 11:53:52 +00:00
GtkWidget * focusw = gtk_window_get_focus ( GTK_WINDOW ( app - > window ) ) ;
2007-03-27 15:48:16 +00:00
2007-04-05 11:53:52 +00:00
// keybinding only valid when scintilla widget has focus
if ( DOC_IDX_VALID ( idx ) & & focusw = = GTK_WIDGET ( doc_list [ idx ] . sci ) )
2007-03-27 15:48:16 +00:00
{
ScintillaObject * sci = doc_list [ idx ] . sci ;
gint pos = sci_get_current_position ( sci ) ;
2007-11-12 09:27:43 +00:00
if ( editor_prefs . complete_snippets )
return editor_complete_snippet ( idx , pos ) ;
2007-03-27 15:48:16 +00:00
}
}
return FALSE ;
}
2007-11-29 18:21:12 +00:00
# ifdef HAVE_VTE
2007-09-26 16:22:20 +00:00
static gboolean set_sensitive ( gpointer widget )
{
gtk_widget_set_sensitive ( GTK_WIDGET ( widget ) , TRUE ) ;
return FALSE ;
}
2007-11-08 16:58:20 +00:00
static gboolean check_vte ( GdkModifierType state , guint keyval )
2007-09-26 16:22:20 +00:00
{
2007-11-06 16:59:01 +00:00
guint i ;
2007-09-28 10:54:56 +00:00
GtkWidget * widget ;
2007-09-26 16:22:20 +00:00
2007-10-02 16:20:44 +00:00
if ( ! vc - > enable_bash_keys )
2007-09-26 16:22:20 +00:00
return FALSE ;
if ( gtk_window_get_focus ( GTK_WINDOW ( app - > window ) ) ! = vc - > vte )
return FALSE ;
2007-12-18 13:35:51 +00:00
// prevent menubar flickering:
if ( state = = GDK_SHIFT_MASK & & ( keyval > = GDK_a & & keyval < = GDK_z ) )
return FALSE ;
if ( state = = 0 & & ( keyval < GDK_F1 | | keyval > GDK_F35 ) ) // e.g. backspace
return FALSE ;
2007-09-26 16:22:20 +00:00
2007-11-06 16:59:01 +00:00
// make focus commands override any bash commands
for ( i = GEANY_KEYS_GROUP_FOCUS ; i < GEANY_KEYS_GROUP_TABS ; i + + )
2007-09-26 16:22:20 +00:00
{
2007-11-08 16:58:20 +00:00
if ( state = = keys [ i ] - > mods & & keyval = = keys [ i ] - > key )
2007-09-26 16:22:20 +00:00
return FALSE ;
}
2007-09-28 10:54:56 +00:00
/* Temporarily disable the menus to prevent conflicting menu accelerators
* from overriding the VTE bash shortcuts .
2007-09-26 16:22:20 +00:00
* Ideally we would just somehow disable the menubar without redrawing it ,
* but maybe that ' s not possible . */
2007-09-28 10:54:56 +00:00
widget = lookup_widget ( app - > window , " menubar1 " ) ;
gtk_widget_set_sensitive ( widget , FALSE ) ;
g_idle_add ( & set_sensitive , ( gpointer ) widget ) ;
widget = app - > popup_menu ;
gtk_widget_set_sensitive ( widget , FALSE ) ;
g_idle_add ( & set_sensitive , ( gpointer ) widget ) ;
2007-09-26 16:22:20 +00:00
return TRUE ;
}
2007-10-02 16:20:44 +00:00
# endif
2007-09-26 16:22:20 +00:00
2006-05-19 17:18:06 +00:00
/* central keypress event handler, almost all keypress events go to this function */
2008-02-12 15:49:54 +00:00
gboolean keybindings_got_event ( GtkWidget * widget , GdkEventKey * ev , gpointer user_data )
2006-05-19 17:18:06 +00:00
{
2008-02-12 15:49:54 +00:00
guint i , state , keyval ;
2006-05-19 17:18:06 +00:00
2008-02-13 16:08:47 +00:00
if ( ev - > keyval = = 0 )
2007-08-28 10:50:18 +00:00
return FALSE ;
2008-02-12 15:49:54 +00:00
keyval = ev - > keyval ;
state = ev - > state & GEANY_KEYS_MODIFIER_MASK ;
2007-08-30 14:07:49 +00:00
// hack to get around that CTRL+Shift+r results in GDK_R not GDK_r
2008-02-12 15:49:54 +00:00
if ( state & GDK_SHIFT_MASK )
2007-08-30 14:07:49 +00:00
if ( keyval > = GDK_A & & keyval < = GDK_Z )
keyval + = GDK_a - GDK_A ;
2007-03-24 16:10:20 +00:00
2007-09-26 16:22:20 +00:00
// special cases
2007-10-02 16:20:44 +00:00
# ifdef HAVE_VTE
2008-02-12 15:49:54 +00:00
if ( vte_info . have_vte & & check_vte ( state , keyval ) )
2007-09-26 16:22:20 +00:00
return FALSE ;
2007-10-02 16:20:44 +00:00
# endif
2008-02-12 15:49:54 +00:00
if ( check_snippet_completion ( keyval , state ) )
2007-08-28 10:50:18 +00:00
return TRUE ;
2006-11-23 12:23:36 +00:00
2006-05-19 17:18:06 +00:00
for ( i = 0 ; i < GEANY_MAX_KEYS ; i + + )
{
2008-02-12 15:49:54 +00:00
if ( keyval = = keys [ i ] - > key & & state = = keys [ i ] - > mods )
2006-05-19 17:18:06 +00:00
{
2007-03-27 15:48:16 +00:00
if ( keys [ i ] - > cb_func = = NULL )
return FALSE ; // ignore the keybinding
2006-05-19 17:18:06 +00:00
// call the corresponding callback function for this shortcut
2007-03-27 15:48:16 +00:00
keys [ i ] - > cb_func ( i ) ;
2006-05-19 17:18:06 +00:00
return TRUE ;
}
}
2007-09-07 12:34:57 +00:00
// fixed keybindings can be overridden by user bindings
2008-02-12 15:49:54 +00:00
if ( check_fixed_kb ( keyval , state ) )
2007-09-07 12:34:57 +00:00
return TRUE ;
2006-05-19 17:18:06 +00:00
return FALSE ;
}
/* simple convenience function to allocate and fill the struct */
2008-01-29 16:11:18 +00:00
static KeyBinding * fill ( KBCallback func , guint key , GdkModifierType mod , const gchar * name ,
2006-10-26 15:22:27 +00:00
const gchar * label )
2006-05-19 17:18:06 +00:00
{
2008-01-29 16:11:18 +00:00
KeyBinding * result ;
2006-05-19 17:18:06 +00:00
2008-01-29 16:11:18 +00:00
result = g_new0 ( KeyBinding , 1 ) ;
2006-05-19 17:18:06 +00:00
result - > name = name ;
2006-06-08 15:12:55 +00:00
result - > label = label ;
2006-05-19 17:18:06 +00:00
result - > key = key ;
result - > mods = mod ;
result - > cb_func = func ;
2007-07-09 13:48:41 +00:00
result - > section = NULL ;
2006-05-19 17:18:06 +00:00
return result ;
}
2007-07-18 15:35:52 +00:00
/* Mimic a keybinding action */
void keybindings_cmd ( GeanyKeyCommand cmd_id )
{
keys [ cmd_id ] - > cb_func ( cmd_id ) ;
}
2007-05-03 15:38:02 +00:00
/* These are the callback functions, either each group or each shortcut has it's
* own function . */
static void cb_func_file_action ( guint key_id )
{
switch ( key_id )
{
2007-05-03 16:13:30 +00:00
case GEANY_KEYS_MENU_NEW :
2007-09-03 16:09:53 +00:00
document_new_file ( NULL , NULL , NULL ) ;
2007-05-03 16:13:30 +00:00
break ;
case GEANY_KEYS_MENU_OPEN :
on_open1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_MENU_OPENSELECTED :
on_menu_open_selected_file1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_MENU_SAVE :
on_save1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_MENU_SAVEAS :
on_save_as1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_MENU_SAVEALL :
on_save_all1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_MENU_CLOSE :
on_close1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_MENU_CLOSEALL :
on_close_all1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_MENU_RELOADFILE :
on_toolbutton23_clicked ( NULL , NULL ) ;
break ;
2007-05-03 15:38:02 +00:00
case GEANY_KEYS_MENU_PROJECTPROPERTIES :
if ( app - > project )
on_project_properties1_activate ( NULL , NULL ) ;
break ;
}
}
2007-05-03 16:13:30 +00:00
static void cb_func_menu_print ( G_GNUC_UNUSED guint key_id )
{
2007-11-12 09:27:43 +00:00
on_print1_activate ( NULL , NULL ) ;
2007-05-03 16:13:30 +00:00
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_undo ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
on_undo1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_redo ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
on_redo1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_selectall ( G_GNUC_UNUSED guint key_id )
2006-07-01 14:12:05 +00:00
{
on_menu_select_all1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_preferences ( G_GNUC_UNUSED guint key_id )
2006-05-24 13:18:42 +00:00
{
2006-08-11 21:12:49 +00:00
on_preferences1_activate ( NULL , NULL ) ;
2006-05-24 13:18:42 +00:00
}
2007-07-04 14:41:58 +00:00
static void cb_func_menu_help ( G_GNUC_UNUSED guint key_id )
{
on_help1_activate ( NULL , NULL ) ;
}
2007-09-13 16:40:19 +00:00
static void cb_func_menu_search ( guint key_id )
2006-12-09 17:03:03 +00:00
{
2007-09-13 16:40:19 +00:00
switch ( key_id )
{
case GEANY_KEYS_MENU_FIND :
on_find1_activate ( NULL , NULL ) ; break ;
case GEANY_KEYS_MENU_FINDNEXT :
on_find_next1_activate ( NULL , NULL ) ; break ;
case GEANY_KEYS_MENU_FINDPREVIOUS :
on_find_previous1_activate ( NULL , NULL ) ; break ;
case GEANY_KEYS_MENU_FINDPREVSEL :
on_find_prevsel1_activate ( NULL , NULL ) ; break ;
case GEANY_KEYS_MENU_FINDNEXTSEL :
on_find_nextsel1_activate ( NULL , NULL ) ; break ;
case GEANY_KEYS_MENU_REPLACE :
on_replace1_activate ( NULL , NULL ) ; break ;
case GEANY_KEYS_MENU_FINDINFILES :
on_find_in_files1_activate ( NULL , NULL ) ; break ;
case GEANY_KEYS_MENU_NEXTMESSAGE :
on_next_message1_activate ( NULL , NULL ) ; break ;
case GEANY_KEYS_MENU_GOTOLINE :
on_go_to_line1_activate ( NULL , NULL ) ; break ;
}
2006-05-19 17:18:06 +00:00
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_opencolorchooser ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
2006-07-27 20:57:13 +00:00
on_show_color_chooser1_activate ( NULL , NULL ) ;
2006-05-19 17:18:06 +00:00
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_fullscreen ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
GtkCheckMenuItem * c = GTK_CHECK_MENU_ITEM ( lookup_widget ( app - > window , " menu_fullscreen1 " ) ) ;
gtk_check_menu_item_set_active ( c , ! gtk_check_menu_item_get_active ( c ) ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_messagewindow ( G_GNUC_UNUSED guint key_id )
2006-05-21 14:02:55 +00:00
{
GtkCheckMenuItem * c = GTK_CHECK_MENU_ITEM ( lookup_widget ( app - > window , " menu_show_messages_window1 " ) ) ;
gtk_check_menu_item_set_active ( c , ! gtk_check_menu_item_get_active ( c ) ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_zoomin ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
on_zoom_in1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_zoomout ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
on_zoom_out1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_foldall ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
gint idx = document_get_cur_idx ( ) ;
2006-06-29 17:14:52 +00:00
if ( idx = = - 1 | | ! doc_list [ idx ] . is_valid ) return ;
2006-05-19 17:18:06 +00:00
document_fold_all ( idx ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_unfoldall ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
gint idx = document_get_cur_idx ( ) ;
2006-06-29 17:14:52 +00:00
if ( idx = = - 1 | | ! doc_list [ idx ] . is_valid ) return ;
2006-05-19 17:18:06 +00:00
document_unfold_all ( idx ) ;
}
2006-11-29 10:29:34 +00:00
static void cb_func_build_action ( guint key_id )
2006-05-19 17:18:06 +00:00
{
gint idx = document_get_cur_idx ( ) ;
2006-11-29 10:29:34 +00:00
GtkWidget * item ;
filetype * ft ;
2006-11-30 15:42:52 +00:00
BuildMenuItems * menu_items ;
2006-05-19 17:18:06 +00:00
2006-11-29 10:29:34 +00:00
if ( ! DOC_IDX_VALID ( idx ) ) return ;
2006-05-19 17:18:06 +00:00
2006-11-29 10:29:34 +00:00
ft = doc_list [ idx ] . file_type ;
2006-11-30 15:42:52 +00:00
if ( ! ft ) return ;
2006-12-08 15:50:10 +00:00
menu_items = build_get_menu_items ( ft - > id ) ;
2006-05-19 17:18:06 +00:00
2006-11-29 10:29:34 +00:00
switch ( key_id )
{
case GEANY_KEYS_BUILD_COMPILE :
2007-05-05 16:35:59 +00:00
item = menu_items - > item_compile ;
break ;
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_LINK :
2007-05-05 16:35:59 +00:00
item = menu_items - > item_link ;
break ;
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_MAKE :
2007-05-05 16:35:59 +00:00
item = menu_items - > item_make_all ;
break ;
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_MAKEOWNTARGET :
2007-05-05 16:35:59 +00:00
item = menu_items - > item_make_custom ;
break ;
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_MAKEOBJECT :
2007-05-05 16:35:59 +00:00
item = menu_items - > item_make_object ;
break ;
2006-12-09 17:03:03 +00:00
case GEANY_KEYS_BUILD_NEXTERROR :
2007-05-05 16:35:59 +00:00
item = menu_items - > item_next_error ;
break ;
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_RUN :
2007-05-05 16:35:59 +00:00
item = menu_items - > item_exec ;
break ;
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_RUN2 :
2007-05-05 16:35:59 +00:00
item = menu_items - > item_exec2 ;
break ;
2006-11-30 15:42:52 +00:00
case GEANY_KEYS_BUILD_OPTIONS :
2007-05-05 16:35:59 +00:00
item = menu_items - > item_set_args ;
break ;
2006-11-29 10:29:34 +00:00
default :
2007-05-05 16:35:59 +00:00
item = NULL ;
2006-11-29 10:29:34 +00:00
}
2008-01-10 13:41:58 +00:00
/* Note: For Build menu items it's OK (at the moment) to assume they are in the correct
* sensitive state , but some other menus don ' t update the sensitive status until
* they are redrawn . */
2006-11-29 10:29:34 +00:00
if ( item & & GTK_WIDGET_IS_SENSITIVE ( item ) )
gtk_menu_item_activate ( GTK_MENU_ITEM ( item ) ) ;
2006-05-19 17:18:06 +00:00
}
2006-10-26 15:22:27 +00:00
static void cb_func_reloadtaglist ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
gint idx = document_get_cur_idx ( ) ;
2006-06-29 17:14:52 +00:00
if ( idx = = - 1 | | ! doc_list [ idx ] . is_valid ) return ;
2006-05-19 17:18:06 +00:00
document_update_tag_list ( idx , TRUE ) ;
}
2006-06-17 21:08:47 +00:00
2006-10-26 15:22:27 +00:00
// common function for keybindings using current word
static void cb_func_current_word ( guint key_id )
2006-06-17 21:08:47 +00:00
{
gint idx = document_get_cur_idx ( ) ;
2006-06-18 17:14:32 +00:00
gint pos ;
2006-06-17 21:08:47 +00:00
2006-06-18 17:14:32 +00:00
if ( idx = = - 1 | | ! doc_list [ idx ] . is_valid ) return ;
2006-06-29 17:14:52 +00:00
2006-06-18 17:14:32 +00:00
pos = sci_get_current_position ( doc_list [ idx ] . sci ) ;
2007-05-28 16:07:30 +00:00
editor_find_current_word ( doc_list [ idx ] . sci , pos ,
2007-01-24 19:20:12 +00:00
editor_info . current_word , GEANY_MAX_WORD_LENGTH , NULL ) ;
2006-06-17 21:08:47 +00:00
2006-09-04 15:57:46 +00:00
if ( * editor_info . current_word = = 0 )
2006-06-17 21:08:47 +00:00
utils_beep ( ) ;
else
2006-10-26 15:22:27 +00:00
switch ( key_id )
2006-06-17 21:08:47 +00:00
{
case GEANY_KEYS_POPUP_FINDUSAGE :
2007-05-05 16:35:59 +00:00
on_find_usage1_activate ( NULL , NULL ) ;
break ;
2006-06-17 21:08:47 +00:00
case GEANY_KEYS_POPUP_GOTOTAGDEFINITION :
2007-09-25 12:39:41 +00:00
symbols_goto_tag ( editor_info . current_word , TRUE ) ;
2007-05-05 16:35:59 +00:00
break ;
2006-06-17 21:08:47 +00:00
case GEANY_KEYS_POPUP_GOTOTAGDECLARATION :
2007-09-25 12:39:41 +00:00
symbols_goto_tag ( editor_info . current_word , FALSE ) ;
2007-05-05 16:35:59 +00:00
break ;
2007-04-15 18:09:59 +00:00
case GEANY_KEYS_POPUP_CONTEXTACTION :
2007-05-05 16:35:59 +00:00
on_context_action1_activate ( GTK_MENU_ITEM ( lookup_widget ( app - > popup_menu ,
" context_action1 " ) ) , NULL ) ;
break ;
2006-06-17 21:08:47 +00:00
}
}
2006-10-26 15:22:27 +00:00
static void cb_func_switch_editor ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
gint idx = document_get_cur_idx ( ) ;
2006-06-29 17:14:52 +00:00
if ( idx = = - 1 | | ! doc_list [ idx ] . is_valid ) return ;
2006-05-19 17:18:06 +00:00
gtk_widget_grab_focus ( GTK_WIDGET ( doc_list [ idx ] . sci ) ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_switch_scribble ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
2007-09-24 16:07:44 +00:00
msgwin_switch_tab ( MSG_SCRATCH , TRUE ) ;
2006-05-19 17:18:06 +00:00
}
2007-03-30 10:38:13 +00:00
static void cb_func_switch_search_bar ( G_GNUC_UNUSED guint key_id )
{
2007-08-23 11:34:06 +00:00
if ( prefs . toolbar_visible & & prefs . toolbar_show_search )
2007-03-30 10:38:13 +00:00
gtk_widget_grab_focus ( lookup_widget ( app - > window , " entry1 " ) ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_switch_vte ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
2007-09-24 16:07:44 +00:00
msgwin_switch_tab ( MSG_VTE , TRUE ) ;
2006-05-19 17:18:06 +00:00
}
2006-10-26 15:22:27 +00:00
static void cb_func_switch_tableft ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
utils_switch_document ( LEFT ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_switch_tabright ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
utils_switch_document ( RIGHT ) ;
}
2007-03-13 17:00:12 +00:00
static void cb_func_switch_tablastused ( G_GNUC_UNUSED guint key_id )
{
gint last_doc_idx = callbacks_data . last_doc_idx ;
if ( DOC_IDX_VALID ( last_doc_idx ) )
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( app - > notebook ) ,
document_get_notebook_page ( last_doc_idx ) ) ;
}
2007-12-16 16:54:47 +00:00
// move document left/right/first/last
2007-09-07 12:34:57 +00:00
static void cb_func_move_tab ( guint key_id )
{
gint idx = document_get_cur_idx ( ) ;
GtkWidget * sci = GTK_WIDGET ( doc_list [ idx ] . sci ) ;
GtkNotebook * nb = GTK_NOTEBOOK ( app - > notebook ) ;
gint cur_page = gtk_notebook_get_current_page ( nb ) ;
if ( ! DOC_IDX_VALID ( idx ) )
return ;
if ( key_id = = GEANY_KEYS_MOVE_TABLEFT )
{
gtk_notebook_reorder_child ( nb , sci , cur_page - 1 ) ; // notebook wraps around by default
}
else if ( key_id = = GEANY_KEYS_MOVE_TABRIGHT )
{
gint npage = cur_page + 1 ;
if ( npage = = gtk_notebook_get_n_pages ( nb ) )
npage = 0 ; // wraparound
gtk_notebook_reorder_child ( nb , sci , npage ) ;
}
2007-12-16 16:54:47 +00:00
else if ( key_id = = GEANY_KEYS_MOVE_TABFIRST )
{
2007-12-23 15:19:42 +00:00
gtk_notebook_reorder_child ( nb , sci , ( prefs . tab_order_ltr ) ? 0 : - 1 ) ;
2007-12-16 16:54:47 +00:00
}
else if ( key_id = = GEANY_KEYS_MOVE_TABLAST )
{
2007-12-23 15:19:42 +00:00
gtk_notebook_reorder_child ( nb , sci , ( prefs . tab_order_ltr ) ? - 1 : 0 ) ;
2007-12-16 16:54:47 +00:00
}
2007-09-07 12:34:57 +00:00
return ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_toggle_sidebar ( G_GNUC_UNUSED guint key_id )
2006-05-21 14:02:55 +00:00
{
2007-05-06 14:49:51 +00:00
on_menu_show_sidebar1_toggled ( NULL , NULL ) ;
2006-05-21 14:02:55 +00:00
}
2006-08-01 10:35:32 +00:00
2007-05-06 14:49:51 +00:00
static void cb_func_menu_toggle_all ( G_GNUC_UNUSED guint key_id )
2007-05-04 16:59:00 +00:00
{
2007-05-06 14:49:51 +00:00
on_menu_toggle_all_additional_widgets1_activate ( NULL , NULL ) ;
2007-05-04 16:59:00 +00:00
}
2006-10-26 15:22:27 +00:00
static void goto_matching_brace ( gint idx )
2006-10-11 22:01:26 +00:00
{
gint pos , new_pos ;
if ( ! DOC_IDX_VALID ( idx ) ) return ;
pos = sci_get_current_position ( doc_list [ idx ] . sci ) ;
2007-08-23 11:34:06 +00:00
if ( ! utils_isbrace ( sci_get_char_at ( doc_list [ idx ] . sci , pos ) , TRUE ) )
2006-10-11 22:01:26 +00:00
pos - - ; // set pos to the brace
new_pos = sci_find_bracematch ( doc_list [ idx ] . sci , pos ) ;
if ( new_pos ! = - 1 )
{
2008-02-22 17:29:45 +00:00
sci_set_current_position ( doc_list [ idx ] . sci , new_pos , FALSE ) ; // set the cursor at the brace
editor_display_current_line ( idx , 0.5F ) ;
2006-10-11 22:01:26 +00:00
}
}
2006-10-26 15:22:27 +00:00
2007-12-25 14:00:18 +00:00
static void cb_func_clipboard ( guint key_id )
{
switch ( key_id )
{
case GEANY_KEYS_MENU_CUT :
2008-01-10 13:27:26 +00:00
on_cut1_activate ( NULL , NULL ) ;
2007-12-25 14:00:18 +00:00
break ;
case GEANY_KEYS_MENU_COPY :
2008-01-10 13:27:26 +00:00
on_copy1_activate ( NULL , NULL ) ;
2007-12-25 14:00:18 +00:00
break ;
case GEANY_KEYS_MENU_PASTE :
2008-01-10 13:27:26 +00:00
on_paste1_activate ( NULL , NULL ) ;
2007-12-25 14:00:18 +00:00
break ;
}
}
2007-05-05 16:35:59 +00:00
/* Common function for editing keybindings that don't change any text, and are
* useful even when sci doesn ' t have focus . */
static void cb_func_edit_global ( guint key_id )
{
gint idx = document_get_cur_idx ( ) ;
gint cur_line ;
if ( ! DOC_IDX_VALID ( idx ) ) return ;
2007-09-25 16:44:33 +00:00
cur_line = sci_get_current_line ( doc_list [ idx ] . sci ) ;
2007-05-05 16:35:59 +00:00
switch ( key_id )
{
case GEANY_KEYS_EDIT_GOTOMATCHINGBRACE :
goto_matching_brace ( idx ) ;
break ;
case GEANY_KEYS_EDIT_TOGGLEMARKER :
{
gboolean set = sci_is_marker_set_at_line ( doc_list [ idx ] . sci , cur_line , 1 ) ;
sci_set_marker_at_line ( doc_list [ idx ] . sci , cur_line , ! set , 1 ) ;
break ;
}
case GEANY_KEYS_EDIT_GOTONEXTMARKER :
{
gint mline = sci_marker_next ( doc_list [ idx ] . sci , cur_line + 1 , 1 < < 1 , TRUE ) ;
if ( mline ! = - 1 )
{
2008-02-22 17:29:45 +00:00
sci_set_current_line ( doc_list [ idx ] . sci , mline ) ;
editor_display_current_line ( idx , 0.5F ) ;
2007-05-05 16:35:59 +00:00
}
break ;
}
case GEANY_KEYS_EDIT_GOTOPREVIOUSMARKER :
{
gint mline = sci_marker_previous ( doc_list [ idx ] . sci , cur_line - 1 , 1 < < 1 , TRUE ) ;
if ( mline ! = - 1 )
{
2008-02-22 17:29:45 +00:00
sci_set_current_line ( doc_list [ idx ] . sci , mline ) ;
editor_display_current_line ( idx , 0.5F ) ;
2007-05-05 16:35:59 +00:00
}
break ;
}
}
}
2007-09-22 11:11:24 +00:00
static void duplicate_lines ( ScintillaObject * sci )
2007-09-21 16:39:21 +00:00
{
if ( sci_get_lines_selected ( sci ) > 1 )
{
2007-09-24 11:25:41 +00:00
editor_select_lines ( sci , FALSE ) ; // ignore extra_line because of selecting lines from the line number column
2007-09-21 16:39:21 +00:00
sci_selection_duplicate ( sci ) ;
}
else if ( sci_can_copy ( sci ) )
sci_selection_duplicate ( sci ) ;
else
sci_line_duplicate ( sci ) ;
}
2007-09-22 11:11:24 +00:00
static void delete_lines ( ScintillaObject * sci )
{
2007-09-24 11:25:41 +00:00
editor_select_lines ( sci , TRUE ) ; // include last line (like cut lines, copy lines do)
sci_clear ( sci ) ; // (SCI_LINEDELETE only does 1 line)
2007-09-22 11:11:24 +00:00
}
2006-10-26 15:22:27 +00:00
// common function for editing keybindings, only valid when scintilla has focus.
static void cb_func_edit ( guint key_id )
2006-09-12 08:32:52 +00:00
{
2006-10-26 15:22:27 +00:00
gint idx = document_get_cur_idx ( ) ;
GtkWidget * focusw = gtk_window_get_focus ( GTK_WINDOW ( app - > window ) ) ;
// edit keybindings only valid when scintilla widget has focus
if ( ! DOC_IDX_VALID ( idx ) | | focusw ! = GTK_WIDGET ( doc_list [ idx ] . sci ) ) return ;
switch ( key_id )
{
2007-07-17 16:27:49 +00:00
case GEANY_KEYS_EDIT_SCROLLTOLINE :
editor_scroll_to_line ( doc_list [ idx ] . sci , - 1 , 0.5F ) ;
break ;
2007-09-05 18:55:51 +00:00
case GEANY_KEYS_EDIT_SCROLLLINEUP :
sci_cmd ( doc_list [ idx ] . sci , SCI_LINESCROLLUP ) ;
break ;
case GEANY_KEYS_EDIT_SCROLLLINEDOWN :
sci_cmd ( doc_list [ idx ] . sci , SCI_LINESCROLLDOWN ) ;
break ;
2006-10-26 15:22:27 +00:00
case GEANY_KEYS_EDIT_DUPLICATELINE :
2007-09-22 11:11:24 +00:00
duplicate_lines ( doc_list [ idx ] . sci ) ;
2006-10-26 15:22:27 +00:00
break ;
2007-07-07 15:12:13 +00:00
case GEANY_KEYS_EDIT_DELETELINE :
2007-09-22 11:11:24 +00:00
delete_lines ( doc_list [ idx ] . sci ) ;
2007-08-10 11:29:37 +00:00
break ;
case GEANY_KEYS_EDIT_COPYLINE :
sci_cmd ( doc_list [ idx ] . sci , SCI_LINECOPY ) ;
2007-07-07 15:12:13 +00:00
break ;
case GEANY_KEYS_EDIT_CUTLINE :
sci_cmd ( doc_list [ idx ] . sci , SCI_LINECUT ) ;
break ;
case GEANY_KEYS_EDIT_TRANSPOSELINE :
sci_cmd ( doc_list [ idx ] . sci , SCI_LINETRANSPOSE ) ;
break ;
2006-10-26 15:22:27 +00:00
case GEANY_KEYS_EDIT_COMMENTLINETOGGLE :
on_menu_toggle_line_commentation1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_EDIT_COMMENTLINE :
on_menu_comment_line1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_EDIT_UNCOMMENTLINE :
on_menu_uncomment_line1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_EDIT_AUTOCOMPLETE :
2007-05-28 16:07:30 +00:00
editor_start_auto_complete ( idx , sci_get_current_position ( doc_list [ idx ] . sci ) , TRUE ) ;
2006-10-26 15:22:27 +00:00
break ;
case GEANY_KEYS_EDIT_CALLTIP :
2007-05-28 16:07:30 +00:00
editor_show_calltip ( idx , - 1 ) ;
2006-10-26 15:22:27 +00:00
break ;
case GEANY_KEYS_EDIT_MACROLIST :
2007-05-28 16:07:30 +00:00
editor_show_macro_list ( doc_list [ idx ] . sci ) ;
2006-10-26 15:22:27 +00:00
break ;
2007-03-27 15:48:16 +00:00
2007-11-12 09:27:43 +00:00
case GEANY_KEYS_EDIT_SUPPRESSSNIPPETCOMPLETION :
switch ( keys [ GEANY_KEYS_EDIT_COMPLETESNIPPET ] - > key )
2007-03-27 15:48:16 +00:00
{
case GDK_space :
sci_add_text ( doc_list [ idx ] . sci , " " ) ;
break ;
case GDK_Tab :
2007-10-09 11:49:42 +00:00
sci_cmd ( doc_list [ idx ] . sci , SCI_TAB ) ;
2007-03-27 15:48:16 +00:00
break ;
default :
break ;
}
2006-10-26 15:22:27 +00:00
break ;
2007-03-27 15:48:16 +00:00
2007-03-22 15:51:39 +00:00
case GEANY_KEYS_EDIT_SELECTWORD :
2007-05-28 16:07:30 +00:00
editor_select_word ( doc_list [ idx ] . sci ) ;
2007-03-22 15:51:39 +00:00
break ;
2007-07-07 15:12:13 +00:00
case GEANY_KEYS_EDIT_SELECTLINE :
2007-09-24 11:25:41 +00:00
editor_select_lines ( doc_list [ idx ] . sci , FALSE ) ;
2007-07-07 15:12:13 +00:00
break ;
2007-07-06 10:16:51 +00:00
case GEANY_KEYS_EDIT_SELECTPARAGRAPH :
editor_select_paragraph ( doc_list [ idx ] . sci ) ;
break ;
2007-03-25 20:51:45 +00:00
case GEANY_KEYS_EDIT_INSERTALTWHITESPACE :
2007-10-17 12:27:07 +00:00
editor_insert_alternative_whitespace ( idx ) ;
2007-03-25 20:51:45 +00:00
break ;
2006-10-26 15:22:27 +00:00
case GEANY_KEYS_EDIT_INCREASEINDENT :
on_menu_increase_indent1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_EDIT_DECREASEINDENT :
on_menu_decrease_indent1_activate ( NULL , NULL ) ;
break ;
2007-07-16 15:42:12 +00:00
case GEANY_KEYS_EDIT_INCREASEINDENTBYSPACE :
editor_indentation_by_one_space ( idx , - 1 , FALSE ) ;
break ;
case GEANY_KEYS_EDIT_DECREASEINDENTBYSPACE :
editor_indentation_by_one_space ( idx , - 1 , TRUE ) ;
break ;
case GEANY_KEYS_EDIT_AUTOINDENT :
editor_auto_line_indentation ( idx , - 1 ) ;
break ;
2007-09-07 19:01:55 +00:00
case GEANY_KEYS_EDIT_TOGGLECASE :
on_toggle_case1_activate ( NULL , NULL ) ;
2006-10-26 15:22:27 +00:00
break ;
2007-02-25 14:26:55 +00:00
case GEANY_KEYS_EDIT_SENDTOCMD1 :
2007-08-23 11:34:06 +00:00
if ( ui_prefs . custom_commands & & g_strv_length ( ui_prefs . custom_commands ) > 0 )
tools_execute_custom_command ( idx , ui_prefs . custom_commands [ 0 ] ) ;
2007-02-25 14:26:55 +00:00
break ;
case GEANY_KEYS_EDIT_SENDTOCMD2 :
2007-08-23 11:34:06 +00:00
if ( ui_prefs . custom_commands & & g_strv_length ( ui_prefs . custom_commands ) > 1 )
tools_execute_custom_command ( idx , ui_prefs . custom_commands [ 1 ] ) ;
2007-02-25 14:26:55 +00:00
break ;
case GEANY_KEYS_EDIT_SENDTOCMD3 :
2007-08-23 11:34:06 +00:00
if ( ui_prefs . custom_commands & & g_strv_length ( ui_prefs . custom_commands ) > 2 )
tools_execute_custom_command ( idx , ui_prefs . custom_commands [ 2 ] ) ;
2007-02-25 14:26:55 +00:00
break ;
2006-10-26 15:22:27 +00:00
}
2006-09-12 08:32:52 +00:00
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_replacetabs ( G_GNUC_UNUSED guint key_id )
2006-09-12 08:32:52 +00:00
{
2006-10-26 15:22:27 +00:00
on_replace_tabs_activate ( NULL , NULL ) ;
}
static void cb_func_menu_insert_date ( G_GNUC_UNUSED guint key_id )
2006-08-19 12:56:30 +00:00
{
2007-10-08 12:10:03 +00:00
gtk_menu_item_activate ( GTK_MENU_ITEM ( lookup_widget ( app - > window , " insert_date_custom1 " ) ) ) ;
2006-08-19 12:56:30 +00:00
}
2006-12-13 00:46:14 +00:00
static void cb_func_menu_insert_specialchars ( G_GNUC_UNUSED guint key_id )
{
2007-07-23 15:41:08 +00:00
// TODO: add plugin keybinding support
//~ on_menu_insert_special_chars1_activate(NULL, NULL);
2006-12-13 00:46:14 +00:00
}
2007-03-23 16:34:54 +00:00
2007-06-03 16:03:46 +00:00
static void cb_func_nav_back ( G_GNUC_UNUSED guint key_id )
{
navqueue_go_back ( ) ;
}
static void cb_func_nav_forward ( G_GNUC_UNUSED guint key_id )
{
navqueue_go_forward ( ) ;
}
2007-07-18 15:35:52 +00:00