2006-05-19 17:18:06 +00:00
/*
* keybindings . c - this file is part of Geany , a fast and lightweight IDE
*
2007-01-14 17:36:42 +00:00
* Copyright 2006 - 2007 Enrico Tröger < enrico . troeger @ uvena . de >
* Copyright 2006 - 2007 Nick Treleaven < nick . treleaven @ btinternet . 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 $
*/
# 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"
# 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"
# include "sci_cb.h"
# include "sciwrappers.h"
2006-10-18 19:35:42 +00:00
# include "build.h"
2006-05-19 17:18:06 +00:00
// include vte.h on non-Win32 systems, else define fake vte_init
# ifdef HAVE_VTE
# include "vte.h"
# endif
2006-11-23 12:23:36 +00:00
const gboolean swap_alt_tab_order = FALSE ;
2006-05-19 17:18:06 +00:00
/* simple convenience function to allocate and fill the struct */
2006-10-26 15:22:27 +00:00
static binding * fill ( KBCallback func , guint key , GdkModifierType mod , const gchar * name ,
const gchar * label ) ;
static void cb_func_menu_new ( guint key_id ) ;
static void cb_func_menu_open ( guint key_id ) ;
static void cb_func_menu_save ( guint key_id ) ;
static void cb_func_menu_saveall ( guint key_id ) ;
2007-01-08 18:15:06 +00:00
static void cb_func_menu_saveas ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
static void cb_func_menu_print ( guint key_id ) ;
static void cb_func_menu_close ( guint key_id ) ;
static void cb_func_menu_closeall ( guint key_id ) ;
static void cb_func_menu_reloadfile ( guint key_id ) ;
static void cb_func_menu_undo ( guint key_id ) ;
static void cb_func_menu_redo ( guint key_id ) ;
static void cb_func_menu_selectall ( guint key_id ) ;
static void cb_func_menu_preferences ( guint key_id ) ;
static void cb_func_menu_insert_date ( guint key_id ) ;
static void cb_func_menu_findnext ( guint key_id ) ;
static void cb_func_menu_findprevious ( guint key_id ) ;
static void cb_func_menu_replace ( guint key_id ) ;
static void cb_func_menu_findinfiles ( guint key_id ) ;
2006-12-09 17:03:03 +00:00
static void cb_func_menu_nextmessage ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
static void cb_func_menu_gotoline ( guint key_id ) ;
static void cb_func_menu_opencolorchooser ( guint key_id ) ;
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 ) ;
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 ) ;
2006-12-13 00:46:14 +00:00
static void cb_func_menu_insert_specialchars ( guint key_id ) ;
2006-11-29 10:29:34 +00:00
static void cb_func_build_action ( guint key_id ) ;
2006-10-26 15:22:27 +00:00
static void cb_func_reloadtaglist ( guint key_id ) ;
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 ) ;
static void cb_func_switch_tableft ( guint key_id ) ;
static void cb_func_switch_tabright ( guint key_id ) ;
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 ) ;
// common function for keybindings using current word
static void cb_func_current_word ( guint key_id ) ;
2006-06-18 17:14:32 +00:00
static void keybindings_add_accels ( ) ;
2006-05-19 17:18:06 +00:00
2006-05-24 13:18:42 +00:00
2006-05-19 17:18:06 +00:00
void keybindings_init ( void )
{
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 ( ) ;
// init all fields of keys with default values
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_MENU_NEW ] = fill ( cb_func_menu_new ,
GDK_n , GDK_CONTROL_MASK , " menu_new " , _ ( " New " ) ) ;
keys [ GEANY_KEYS_MENU_OPEN ] = fill ( cb_func_menu_open ,
GDK_o , GDK_CONTROL_MASK , " menu_open " , _ ( " Open " ) ) ;
keys [ GEANY_KEYS_MENU_SAVE ] = fill ( cb_func_menu_save ,
GDK_s , GDK_CONTROL_MASK , " menu_save " , _ ( " Save " ) ) ;
2007-01-08 18:15:06 +00:00
keys [ GEANY_KEYS_MENU_SAVEAS ] = fill ( cb_func_menu_saveas ,
0 , 0 , " menu_saveas " , _ ( " Save as " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_MENU_SAVEALL ] = fill ( cb_func_menu_saveall ,
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 " ) ) ;
2006-06-21 18:54:07 +00:00
keys [ GEANY_KEYS_MENU_CLOSE ] = fill ( cb_func_menu_close ,
GDK_w , GDK_CONTROL_MASK , " menu_close " , _ ( " Close " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_MENU_CLOSEALL ] = fill ( cb_func_menu_closeall ,
2007-01-18 11:31:37 +00:00
GDK_w , GDK_CONTROL_MASK | GDK_SHIFT_MASK , " menu_closeall " , _ ( " Close all " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_MENU_RELOADFILE ] = fill ( cb_func_menu_reloadfile ,
GDK_r , GDK_CONTROL_MASK , " menu_reloadfile " , _ ( " Reload file " ) ) ;
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 " ) ) ;
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-01-18 11:31:37 +00:00
0 , 0 , " menu_preferences " , _ ( " Preferences " ) ) ;
2006-07-15 11:17:23 +00:00
keys [ GEANY_KEYS_MENU_FINDNEXT ] = fill ( cb_func_menu_findnext ,
2006-06-18 17:14:32 +00:00
GDK_F3 , 0 , " menu_findnext " , _ ( " Find Next " ) ) ;
keys [ GEANY_KEYS_MENU_FINDPREVIOUS ] = fill ( cb_func_menu_findprevious ,
GDK_F3 , GDK_SHIFT_MASK , " menu_findprevious " , _ ( " Find Previous " ) ) ;
keys [ GEANY_KEYS_MENU_REPLACE ] = fill ( cb_func_menu_replace ,
GDK_e , GDK_CONTROL_MASK , " menu_replace " , _ ( " Replace " ) ) ;
2006-07-15 11:17:23 +00:00
keys [ GEANY_KEYS_MENU_FINDINFILES ] = fill ( cb_func_menu_findinfiles , GDK_f ,
GDK_CONTROL_MASK | GDK_SHIFT_MASK , " menu_findinfiles " , _ ( " Find in files " ) ) ;
2006-12-09 17:03:03 +00:00
keys [ GEANY_KEYS_MENU_NEXTMESSAGE ] = fill ( cb_func_menu_nextmessage ,
0 , 0 , " menu_nextmessage " , _ ( " Next Message " ) ) ;
2006-06-18 17:14:32 +00:00
keys [ GEANY_KEYS_MENU_GOTOLINE ] = fill ( cb_func_menu_gotoline ,
GDK_l , GDK_CONTROL_MASK , " menu_gotoline " , _ ( " Go to line " ) ) ;
keys [ GEANY_KEYS_MENU_OPENCOLORCHOOSER ] = fill ( cb_func_menu_opencolorchooser ,
0 , 0 , " menu_opencolorchooser " , _ ( " Show Colour Chooser " ) ) ;
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 " ) ) ;
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 " ) ) ;
2006-12-13 00:46:14 +00:00
keys [ GEANY_KEYS_MENU_INSERTSPECIALCHARS ] = fill ( cb_func_menu_insert_specialchars ,
0 , 0 , " menu_insert_specialchars " , _ ( " Insert Special HTML Characters " ) ) ;
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 " ) ) ;
keys [ GEANY_KEYS_RELOADTAGLIST ] = fill ( cb_func_reloadtaglist ,
GDK_r , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " reloadtaglist " , _ ( " Reload symbol list " ) ) ;
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 " ) ) ;
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 " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_DUPLICATELINE ] = fill ( cb_func_edit ,
2006-06-18 17:14:32 +00:00
GDK_g , GDK_CONTROL_MASK , " edit_duplicateline " , _ ( " Duplicate line or selection " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_TOLOWERCASE ] = fill ( cb_func_edit ,
2006-09-12 08:32:52 +00:00
GDK_u , GDK_CONTROL_MASK , " edit_tolowercase " , _ ( " Convert Selection to lower-case " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_TOUPPERCASE ] = fill ( cb_func_edit ,
2006-09-12 08:32:52 +00:00
GDK_u , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " edit_touppercase " , _ ( " Convert Selection to upper-case " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_COMMENTLINETOGGLE ] = fill ( cb_func_edit ,
2006-09-10 11:47:26 +00:00
GDK_b , 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 ,
2006-11-13 22:26:55 +00:00
GDK_d , GDK_CONTROL_MASK , " edit_commentline " , _ ( " Comment line(s) " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_UNCOMMENTLINE ] = fill ( cb_func_edit ,
2006-11-13 22:26:55 +00:00
GDK_d , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " 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 ,
2006-08-01 10:35:32 +00:00
GDK_i , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " edit_decreaseindent " , _ ( " Decrease indent " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_GOTOMATCHINGBRACE ] = fill ( cb_func_edit ,
2006-10-16 14:09:20 +00:00
GDK_less , GDK_SHIFT_MASK | GDK_CONTROL_MASK , " edit_gotomatchingbrace " ,
_ ( " Goto matching brace " ) ) ;
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-07-26 17:02:16 +00:00
# ifdef G_OS_WIN32
2006-07-26 14:28:20 +00:00
// on windows alt-space is taken by the window manager
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 " ) ) ;
# else
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_CALLTIP ] = fill ( cb_func_edit ,
2006-06-18 17:14:32 +00:00
GDK_space , GDK_MOD1_MASK , " edit_calltip " , _ ( " Show calltip " ) ) ;
2006-07-26 14:28:20 +00:00
# endif
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 " ) ) ;
2006-10-26 15:22:27 +00:00
keys [ GEANY_KEYS_EDIT_SUPPRESSCOMPLETION ] = fill ( cb_func_edit ,
2006-06-18 17:14:32 +00:00
GDK_space , GDK_SHIFT_MASK , " edit_suppresscompletion " , _ ( " Suppress auto completion " ) ) ;
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 ,
2006-06-17 21:08:47 +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 ,
2006-06-17 21:08:47 +00:00
0 , 0 , " popup_gototagdeclaration " , _ ( " Go to tag declaration " ) ) ;
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 ) ;
}
}
2006-05-24 16:56:14 +00:00
g_free ( configfile ) ;
g_key_file_free ( config ) ;
keybindings_add_accels ( ) ;
}
# 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 )
2006-06-18 17:14:32 +00:00
static void keybindings_add_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
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 ) ;
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 ) ;
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 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_FULLSCREEN , menu_fullscreen1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_MESSAGEWINDOW , menu_show_messages_window1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_OPENCOLORCHOOSER , menu_choose_color1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_ZOOMIN , menu_zoom_in1 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_ZOOMOUT , menu_zoom_out1 ) ;
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 ) ;
2006-12-13 00:46:14 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_MENU_INSERTSPECIALCHARS , menu_insert_special_chars1 ) ;
2006-09-12 08:32:52 +00:00
GEANY_ADD_ACCEL ( GEANY_KEYS_EDIT_TOLOWERCASE , menu_to_lower_case2 ) ;
GEANY_ADD_ACCEL ( GEANY_KEYS_EDIT_TOUPPERCASE , menu_to_upper_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 ) ;
2006-06-18 17:05:09 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_MENU_ZOOMIN , zoom_in1 ) ;
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_MENU_ZOOMOUT , zoom_out1 ) ;
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 ) ;
2006-06-18 17:05:09 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_MENU_GOTOLINE , go_to_line ) ;
2006-09-12 08:32:52 +00:00
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_EDIT_TOLOWERCASE , to_lower_case1 ) ;
GEANY_ADD_POPUP_ACCEL ( GEANY_KEYS_EDIT_TOUPPERCASE , to_upper_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 ( ) ;
// add comment if the file is newly created
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 ] ) ;
}
}
2006-11-23 12:23:36 +00:00
static gboolean check_fixed_kb ( GdkEventKey * event )
{
// check alt-0 to alt-9 for setting current notebook page
if ( event - > state & GDK_MOD1_MASK & & event - > keyval > = GDK_0 & & event - > keyval < = GDK_9 )
{
gint page = event - > keyval - GDK_0 - 1 ;
gint npages = gtk_notebook_get_n_pages ( GTK_NOTEBOOK ( app - > notebook ) ) ;
// alt-0 is for the rightmost tab
if ( event - > keyval = = GDK_0 )
page = npages - 1 ;
// invert the order if tabs are added on the other side
if ( swap_alt_tab_order & & ! app - > tab_order_ltr )
page = ( npages - 1 ) - page ;
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( app - > notebook ) , page ) ;
return TRUE ;
}
return FALSE ;
}
2006-05-19 17:18:06 +00:00
/* central keypress event handler, almost all keypress events go to this function */
gboolean keybindings_got_event ( GtkWidget * widget , GdkEventKey * event , gpointer user_data )
{
guint i , k ;
2006-11-23 12:23:36 +00:00
if ( check_fixed_kb ( event ) ) return TRUE ;
2006-05-19 17:18:06 +00:00
for ( i = 0 ; i < GEANY_MAX_KEYS ; i + + )
{
// ugly hack to get around that CTRL+Shift+r results in 'R' not 'r'
k = keys [ i ] - > key ;
if ( event - > state & GDK_SHIFT_MASK )
{
// skip entries which don't include SHIFT
if ( ! ( keys [ i ] - > mods & GDK_SHIFT_MASK ) ) continue ;
// raise the keyval
if ( keys [ i ] - > key > = GDK_a & & keys [ i ] - > key < = GDK_z ) k = keys [ i ] - > key - 32 ;
}
// ignore numlock key, not necessary but nice
if ( event - > state & GDK_MOD2_MASK ) event - > state - = GDK_MOD2_MASK ;
if ( event - > keyval = = k & & event - > state = = keys [ i ] - > mods )
{
// call the corresponding callback function for this shortcut
2006-10-26 15:22:27 +00:00
if ( keys [ i ] - > cb_func ! = NULL ) keys [ i ] - > cb_func ( i ) ;
2006-05-19 17:18:06 +00:00
return TRUE ;
}
}
return FALSE ;
}
/* simple convenience function to allocate and fill the struct */
2006-10-26 15:22:27 +00:00
static binding * fill ( KBCallback func , guint key , GdkModifierType mod , const gchar * name ,
const gchar * label )
2006-05-19 17:18:06 +00:00
{
binding * result ;
result = g_new0 ( binding , 1 ) ;
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 ;
return result ;
}
/* these are the callback functions, each shortcut has its own function, this is only for clear code */
2006-10-26 15:22:27 +00:00
static void cb_func_menu_new ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
document_new_file ( NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_open ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
2006-08-11 21:12:49 +00:00
on_open1_activate ( NULL , NULL ) ;
2006-05-19 17:18:06 +00:00
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_save ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
on_save1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_saveall ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
on_save_all1_activate ( NULL , NULL ) ;
}
2007-01-08 18:15:06 +00:00
static void cb_func_menu_saveas ( G_GNUC_UNUSED guint key_id )
{
on_save_as1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_close ( G_GNUC_UNUSED guint key_id )
2006-06-21 18:54:07 +00:00
{
on_close1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_closeall ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
on_close_all1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_reloadfile ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
on_toolbutton23_clicked ( NULL , NULL ) ;
}
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
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_findnext ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
on_find_next1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_findprevious ( G_GNUC_UNUSED guint key_id )
2006-05-24 13:18:42 +00:00
{
on_find_previous1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_replace ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
2006-08-11 21:12:49 +00:00
on_replace1_activate ( NULL , NULL ) ;
2006-05-19 17:18:06 +00:00
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_findinfiles ( G_GNUC_UNUSED guint key_id )
2006-07-15 11:17:23 +00:00
{
2006-08-11 21:12:49 +00:00
on_find_in_files1_activate ( NULL , NULL ) ;
2006-07-15 11:17:23 +00:00
}
2006-12-09 17:03:03 +00:00
static void cb_func_menu_nextmessage ( guint key_id )
{
on_next_message1_activate ( NULL , NULL ) ;
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_gotoline ( G_GNUC_UNUSED guint key_id )
2006-05-19 17:18:06 +00:00
{
2006-05-24 13:18:42 +00:00
on_go_to_line1_activate ( NULL , NULL ) ;
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 :
2006-11-30 15:42:52 +00:00
item = menu_items - > item_compile ;
2006-11-29 10:29:34 +00:00
break ;
2006-05-19 17:18:06 +00:00
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_LINK :
2006-11-30 15:42:52 +00:00
item = menu_items - > item_link ;
2006-11-29 10:29:34 +00:00
break ;
2006-07-06 09:43:10 +00:00
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_MAKE :
2006-11-30 15:42:52 +00:00
item = menu_items - > item_make_all ;
2006-11-29 10:29:34 +00:00
break ;
2006-05-19 17:18:06 +00:00
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_MAKEOWNTARGET :
2006-11-30 15:42:52 +00:00
item = menu_items - > item_make_custom ;
2006-11-29 10:29:34 +00:00
break ;
case GEANY_KEYS_BUILD_MAKEOBJECT :
2006-11-30 15:42:52 +00:00
item = menu_items - > item_make_object ;
2006-11-29 10:29:34 +00:00
break ;
2006-12-09 17:03:03 +00:00
case GEANY_KEYS_BUILD_NEXTERROR :
item = menu_items - > item_next_error ;
break ;
2006-11-29 10:29:34 +00:00
case GEANY_KEYS_BUILD_RUN :
2006-11-30 15:42:52 +00:00
item = menu_items - > item_exec ;
2006-11-29 10:29:34 +00:00
break ;
case GEANY_KEYS_BUILD_RUN2 :
2006-11-30 15:42:52 +00:00
item = menu_items - > item_exec2 ;
break ;
case GEANY_KEYS_BUILD_OPTIONS :
item = menu_items - > item_set_args ;
2006-11-29 10:29:34 +00:00
break ;
default :
item = NULL ;
}
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 ) ;
2006-09-04 15:57:46 +00:00
sci_cb_find_current_word ( doc_list [ idx ] . sci , pos ,
editor_info . current_word , GEANY_MAX_WORD_LENGTH ) ;
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 :
on_find_usage1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_POPUP_GOTOTAGDEFINITION :
on_goto_tag_activate ( GTK_MENU_ITEM ( lookup_widget ( app - > popup_menu ,
" goto_tag_definition1 " ) ) , NULL ) ;
break ;
case GEANY_KEYS_POPUP_GOTOTAGDECLARATION :
on_goto_tag_activate ( GTK_MENU_ITEM ( lookup_widget ( app - > popup_menu ,
" goto_tag_declaration1 " ) ) , NULL ) ;
break ;
}
}
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
{
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( msgwindow . notebook ) , MSG_SCRATCH ) ;
2007-01-06 11:55:01 +00:00
msgwin_show_hide ( TRUE ) ;
2006-05-19 17:18:06 +00:00
gtk_widget_grab_focus ( lookup_widget ( app - > window , " textview_scribble " ) ) ;
}
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
{
# ifdef HAVE_VTE
2007-01-06 11:55:01 +00:00
msgwin_show_hide ( TRUE ) ;
/* the msgwin must be visible before we switch to the VTE page so that
* the font settings are applied on realization */
2006-05-19 17:18:06 +00:00
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( msgwindow . notebook ) , MSG_VTE ) ;
gtk_widget_grab_focus ( vc - > vte ) ;
# endif
}
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 ) ;
}
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
{
2006-06-29 17:14:52 +00:00
static gint active_page = - 1 ;
2006-05-22 13:43:56 +00:00
2006-07-07 14:34:43 +00:00
if ( app - > sidebar_visible )
2006-05-22 13:43:56 +00:00
{
2006-06-25 17:02:27 +00:00
// to remember the active page because GTK (e.g. 2.8.18) doesn't do it and shows always
// the last page (for unknown reason, with GTK 2.6.4 it works)
active_page = gtk_notebook_get_current_page ( GTK_NOTEBOOK ( app - > treeview_notebook ) ) ;
2006-05-22 13:43:56 +00:00
}
2006-07-07 14:34:43 +00:00
app - > sidebar_visible = ! app - > sidebar_visible ;
if ( ( ! app - > sidebar_openfiles_visible & & ! app - > sidebar_symbol_visible ) )
2006-05-22 13:43:56 +00:00
{
2006-07-07 14:34:43 +00:00
app - > sidebar_openfiles_visible = TRUE ;
app - > sidebar_symbol_visible = TRUE ;
2006-05-22 13:43:56 +00:00
}
2006-05-21 14:02:55 +00:00
2006-09-05 14:24:47 +00:00
ui_treeviews_show_hide ( TRUE ) ;
2006-06-25 17:02:27 +00:00
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( app - > treeview_notebook ) , active_page ) ;
2006-05-21 14:02:55 +00:00
}
2006-08-01 10:35:32 +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 ) ;
if ( ! utils_isbrace ( sci_get_char_at ( doc_list [ idx ] . sci , pos ) ) )
pos - - ; // set pos to the brace
new_pos = sci_find_bracematch ( doc_list [ idx ] . sci , pos ) ;
if ( new_pos ! = - 1 )
{
2006-11-03 15:09:13 +00:00
sci_goto_pos ( doc_list [ idx ] . sci , new_pos , TRUE ) ; // set the cursor at the brace
sci_scroll_to_line ( doc_list [ idx ] . sci , - 1 , 0.5 ) ;
2006-10-11 22:01:26 +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 )
{
case GEANY_KEYS_EDIT_DUPLICATELINE :
on_menu_duplicate_line1_activate ( NULL , NULL ) ;
break ;
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 :
sci_cb_start_auto_complete ( idx , sci_get_current_position ( doc_list [ idx ] . sci ) , TRUE ) ;
break ;
case GEANY_KEYS_EDIT_CALLTIP :
sci_cb_show_calltip ( idx , - 1 ) ;
break ;
case GEANY_KEYS_EDIT_MACROLIST :
sci_cb_show_macro_list ( doc_list [ idx ] . sci ) ;
break ;
case GEANY_KEYS_EDIT_SUPPRESSCOMPLETION :
sci_add_text ( doc_list [ idx ] . sci , " " ) ;
break ;
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 ;
case GEANY_KEYS_EDIT_GOTOMATCHINGBRACE :
goto_matching_brace ( idx ) ;
break ;
case GEANY_KEYS_EDIT_TOLOWERCASE :
on_to_lower_case1_activate ( NULL , NULL ) ;
break ;
case GEANY_KEYS_EDIT_TOUPPERCASE :
on_to_upper_case1_activate ( NULL , NULL ) ;
break ;
}
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_print ( G_GNUC_UNUSED guint key_id )
{
gint idx = document_get_cur_idx ( ) ;
if ( idx = = - 1 | | ! doc_list [ idx ] . is_valid ) return ;
document_print ( idx ) ;
2006-09-12 08:32:52 +00:00
}
2006-10-26 15:22:27 +00:00
static void cb_func_menu_insert_date ( G_GNUC_UNUSED guint key_id )
2006-08-19 12:56:30 +00:00
{
gtk_menu_item_activate ( GTK_MENU_ITEM ( lookup_widget ( app - > popup_menu , " insert_date_custom2 " ) ) ) ;
}
2006-12-13 00:46:14 +00:00
static void cb_func_menu_insert_specialchars ( G_GNUC_UNUSED guint key_id )
{
on_menu_insert_special_chars1_activate ( NULL , NULL ) ;
}