[119] | 1 | /* $Id: kkeys.e 2407 2010-06-10 12:52:02Z bird $ */
|
---|
| 2 | /** @file
|
---|
[1590] | 3 | * Bird's key additions to Visual Slickedit.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[2243] | 7 | * Copyright (c) 2004-2009 knut st. osmundsen <bird-kBuild-spamix@anduin.net>
|
---|
[119] | 8 | *
|
---|
| 9 | * This file is part of kBuild.
|
---|
| 10 | *
|
---|
| 11 | * kBuild is free software; you can redistribute it and/or modify
|
---|
| 12 | * it under the terms of the GNU General Public License as published by
|
---|
[2019] | 13 | * the Free Software Foundation; either version 3 of the License, or
|
---|
[119] | 14 | * (at your option) any later version.
|
---|
| 15 | *
|
---|
| 16 | * kBuild is distributed in the hope that it will be useful,
|
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | * GNU General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
[2019] | 22 | * along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
---|
[119] | 23 | *
|
---|
| 24 | */
|
---|
| 25 |
|
---|
[2400] | 26 | /*******************************************************************************
|
---|
| 27 | * Header Files *
|
---|
| 28 | *******************************************************************************/
|
---|
| 29 | #include 'slick.sh'
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | /*******************************************************************************
|
---|
| 33 | * Global Variables *
|
---|
| 34 | *******************************************************************************/
|
---|
[114] | 35 | defeventtab default_keys
|
---|
| 36 | def 'A-UP' = find_prev
|
---|
| 37 | def 'A-DOWN' = find_next
|
---|
[134] | 38 | def 'A-PGUP' = prev_proc
|
---|
| 39 | def 'A-PGDN' = next_proc
|
---|
[116] | 40 | def 'A-d' = delete_line
|
---|
[114] | 41 | def 'A-o' = kkeys_duplicate_line
|
---|
| 42 | def 'A-s' = kkeys_switch_lines
|
---|
| 43 | def 'A-u' = undo_cursor /* will cursor movement in one undo step. */
|
---|
[118] | 44 | def 'A-g' = goto_line
|
---|
[252] | 45 | def 'A-z' = kkeys_fullscreen
|
---|
[114] | 46 | def 'INS' = boxer_paste
|
---|
| 47 | def 'S-INS' = insert_toggle
|
---|
| 48 | def 'C-UP' = kkeys_scroll_down
|
---|
| 49 | def 'C-DOWN' = kkeys_scroll_up
|
---|
[134] | 50 | def 'C-PGUP' = prev_window
|
---|
| 51 | def 'C-PGDN' = next_window
|
---|
[118] | 52 | def 'C-DEL' = kkeys_delete_right
|
---|
[2353] | 53 | #if __VERSION__ >= 14.0
|
---|
[2407] | 54 | def 'C-/' = kkeys_push_ref
|
---|
| 55 | def 'S-C-/' = push_ref
|
---|
[2353] | 56 | def 'S-A-]' = next_buff_tab
|
---|
| 57 | def 'S-A-[' = prev_buff_tab
|
---|
[2388] | 58 | def 'S-A-U' = kkeys_gen_uuid
|
---|
[2353] | 59 | #endif
|
---|
[1590] | 60 | /* For the mac (A/M mix, all except A-z): */
|
---|
| 61 | def 'M-UP' = find_prev
|
---|
| 62 | def 'M-DOWN' = find_next
|
---|
| 63 | def 'M-PGUP' = prev_proc
|
---|
| 64 | def 'M-PGDN' = next_proc
|
---|
| 65 | def 'M-d' = delete_line
|
---|
[2400] | 66 | def 'M-f' = kkeys_open_file_menu
|
---|
| 67 | def 'M-e' = kkeys_open_edit_menu
|
---|
[1590] | 68 | def 'M-o' = kkeys_duplicate_line
|
---|
| 69 | def 'M-s' = kkeys_switch_lines
|
---|
[2400] | 70 | def 'M-t' = kkeys_open_tools_menu
|
---|
[1590] | 71 | def 'M-u' = undo_cursor
|
---|
| 72 | def 'M-g' = goto_line
|
---|
[2353] | 73 | #if __VERSION__ >= 14.0
|
---|
| 74 | def 'S-M-]' = next_buff_tab
|
---|
| 75 | def 'S-M-[' = prev_buff_tab
|
---|
[2388] | 76 | def 'S-M-U' = kkeys_gen_uuid
|
---|
[2353] | 77 | #endif
|
---|
[1590] | 78 | /* Fixing brainfucked slickedit silliness: */
|
---|
| 79 | def 'M-v' = paste
|
---|
[114] | 80 |
|
---|
[2388] | 81 |
|
---|
| 82 | /** Saves the cursor position. */
|
---|
| 83 | static long kkeys_save_cur_pos()
|
---|
| 84 | {
|
---|
| 85 | long offset = _QROffset();
|
---|
| 86 | message(offset);
|
---|
| 87 | return offset;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | /** Restores a saved cursor position. */
|
---|
| 91 | static void kkeys_restore_cur_pos(long lSavedCurPos)
|
---|
| 92 | {
|
---|
| 93 | _GoToROffset(lSavedCurPos);
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 |
|
---|
[561] | 97 | _command kkeys_switch_lines()
|
---|
[114] | 98 | {
|
---|
| 99 | /* Allocate a selection for copying the current line. */
|
---|
| 100 | cursor_down();
|
---|
| 101 | mark_id= _alloc_selection();
|
---|
| 102 | if (mark_id>=0)
|
---|
| 103 | {
|
---|
| 104 | _select_line(mark_id);
|
---|
| 105 | cursor_up();
|
---|
| 106 | cursor_up();
|
---|
| 107 | _move_to_cursor(mark_id);
|
---|
| 108 | cursor_down();
|
---|
| 109 | _free_selection(mark_id);
|
---|
| 110 | // This selection can be freed because it is not the active selection.
|
---|
| 111 | }
|
---|
| 112 | else
|
---|
| 113 | message(get_message(mark_id));
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[561] | 116 | _command kkeys_duplicate_line()
|
---|
[114] | 117 | {
|
---|
| 118 | /* Allocate a selection for copying the current line. */
|
---|
| 119 | mark_id= _alloc_selection();
|
---|
| 120 | if (mark_id>=0)
|
---|
| 121 | {
|
---|
| 122 | _select_line(mark_id);
|
---|
| 123 | _copy_to_cursor(mark_id);
|
---|
| 124 | // This selection can be freed because it is not the active selection.
|
---|
| 125 | _free_selection(mark_id);
|
---|
| 126 | cursor_down();
|
---|
| 127 | }
|
---|
| 128 | else
|
---|
| 129 | message(get_message(mark_id));
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[561] | 132 | _command kkeys_delete_right()
|
---|
[114] | 133 | {
|
---|
| 134 | col=p_col
|
---|
| 135 | search('[ \t]#|?|$|^','r+');
|
---|
| 136 | if ( match_length()&& get_text(1,match_length('s'))=='' )
|
---|
| 137 | {
|
---|
| 138 | _nrseek(match_length('s'));
|
---|
| 139 | _delete_text(match_length());
|
---|
| 140 | }
|
---|
| 141 | else
|
---|
| 142 | delete_word();
|
---|
| 143 | p_col=col
|
---|
| 144 | //retrieve_command_results()
|
---|
| 145 |
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[561] | 148 | _command kkeys_delete_left()
|
---|
[114] | 149 | {
|
---|
| 150 | //denne virker ikkje som den skal!!!
|
---|
| 151 | message "not implemented"
|
---|
[561] | 152 | /*
|
---|
[114] | 153 | return;
|
---|
| 154 | col=p_col
|
---|
| 155 | search('[ \t]#|?|$|^','r-');
|
---|
| 156 | if ( match_length()&& get_text(1,match_length('s'))=='' )
|
---|
| 157 | {
|
---|
| 158 | _nrseek(match_length('s'));
|
---|
| 159 | _delete_text(match_length());
|
---|
| 160 | }
|
---|
| 161 | else
|
---|
| 162 | delete_word();
|
---|
| 163 | p_col=col
|
---|
[561] | 164 | */
|
---|
[114] | 165 | }
|
---|
| 166 |
|
---|
[561] | 167 | _command kkeys_scroll_up()
|
---|
[114] | 168 | {
|
---|
| 169 | if (p_cursor_y == 0)
|
---|
| 170 | down();
|
---|
| 171 | set_scroll_pos(p_left_edge, p_cursor_y-1);
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[561] | 174 | _command kkeys_scroll_down()
|
---|
[114] | 175 | {
|
---|
| 176 | if (p_cursor_y intdiv p_font_height == p_char_height-1)
|
---|
| 177 | up()
|
---|
| 178 | set_scroll_pos(p_left_edge, p_cursor_y+p_font_height);
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[566] | 181 | _command boxer_paste()
|
---|
[114] | 182 | {
|
---|
[2388] | 183 | long lSavedCurPos = kkeys_save_cur_pos()
|
---|
| 184 | paste();
|
---|
| 185 | kkeys_restore_cur_pos(lSavedCurPos);
|
---|
[114] | 186 | }
|
---|
| 187 |
|
---|
[252] | 188 | _command kkeys_fullscreen()
|
---|
| 189 | {
|
---|
| 190 | fullscreen();
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | /* for later, not used yet. */
|
---|
| 195 |
|
---|
[114] | 196 | _command boxer_select()
|
---|
| 197 | {
|
---|
| 198 | if (command_state())
|
---|
| 199 | fSelected = (p_sel_length != 0);
|
---|
| 200 | else
|
---|
| 201 | fSelected = select_active();
|
---|
| 202 |
|
---|
| 203 | key = last_event();
|
---|
| 204 | if (key :== name2event('s-down'))
|
---|
| 205 | {
|
---|
| 206 | if (!fSelected)
|
---|
| 207 | select_line();
|
---|
| 208 | else
|
---|
| 209 | cursor_down();
|
---|
| 210 | }
|
---|
| 211 | else if (key :== name2event('s-up'))
|
---|
| 212 | {
|
---|
| 213 | if (!fSelected)
|
---|
| 214 | select_line();
|
---|
| 215 | else
|
---|
| 216 | cursor_up();
|
---|
| 217 | }
|
---|
| 218 | else if (key :== name2event('s-left'))
|
---|
| 219 | {
|
---|
| 220 | if (!fSelected)
|
---|
| 221 | select_char();
|
---|
| 222 | else
|
---|
| 223 | cursor_left();
|
---|
| 224 | }
|
---|
| 225 | else if (key :== name2event('s-right'))
|
---|
| 226 | {
|
---|
| 227 | if (!fSelected)
|
---|
| 228 | select_char();
|
---|
| 229 | else
|
---|
| 230 | cursor_right();
|
---|
| 231 | }
|
---|
| 232 | else if (key :== name2event('s-home'))
|
---|
| 233 | {
|
---|
| 234 | if (!fSelected) select_char();
|
---|
| 235 | begin_line_text_toggle();
|
---|
| 236 | }
|
---|
| 237 | else if (key :== name2event('s-end'))
|
---|
| 238 | {
|
---|
| 239 | if (!fSelected) select_char();
|
---|
| 240 | end_line();
|
---|
| 241 | if (p_col > 0) //this is not identical with boxer...
|
---|
| 242 | cursor_left();
|
---|
| 243 | }
|
---|
| 244 | else if (key :== name2event('c-s-home'))
|
---|
| 245 | {
|
---|
| 246 | if (!fSelected) select_char();
|
---|
| 247 | top_of_buffer();
|
---|
| 248 | }
|
---|
| 249 | else if (key :== name2event('c-s-end'))
|
---|
| 250 | {
|
---|
| 251 | if (!fSelected) select_char();
|
---|
| 252 | bottom_of_buffer();
|
---|
| 253 | }
|
---|
| 254 | else if (key :== name2event('c-s-left'))
|
---|
| 255 | {
|
---|
| 256 | if (!fSelected)
|
---|
| 257 | {
|
---|
| 258 | cursor_left();
|
---|
| 259 | select_char(); /* start this selection non-inclusive */
|
---|
| 260 | }
|
---|
| 261 | prev_word();
|
---|
| 262 | }
|
---|
| 263 | else if (key :== name2event('c-s-right'))
|
---|
| 264 | {
|
---|
| 265 | if (!fSelected)
|
---|
| 266 | {
|
---|
| 267 | select_char(); /* start this selection non-inclusive */
|
---|
| 268 | }
|
---|
| 269 | /* temporary hack */
|
---|
| 270 | prevpos = p_col;
|
---|
| 271 | prevline = p_line;
|
---|
| 272 | p_col++;
|
---|
| 273 | next_word();
|
---|
| 274 | if ((p_line == prevline && p_col > prevpos + 1) || (p_line != prevline && p_col > 0))
|
---|
| 275 | p_col--;
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 |
|
---|
[2407] | 279 | #if __VERSION__ >= 14.0
|
---|
[114] | 280 |
|
---|
[2407] | 281 | /**
|
---|
| 282 | * Search for references only in the current workspace.
|
---|
| 283 | */
|
---|
| 284 | _command kkeys_push_ref()
|
---|
| 285 | {
|
---|
| 286 | if (_isEditorCtl())
|
---|
| 287 | {
|
---|
| 288 | sProjTagFile = project_tags_filename();
|
---|
| 289 | sLangId = p_LangId;
|
---|
| 290 | if (sProjTagFile != '')
|
---|
| 291 | {
|
---|
| 292 |
|
---|
| 293 | /* HACK ALERT: Make sure gtag_filelist_last_ext has the right value. */
|
---|
| 294 | _update_tag_filelist_ext(sLangId);
|
---|
| 295 |
|
---|
| 296 | /* save */
|
---|
| 297 | boolean saved_gtag_filelist_cache_updated = gtag_filelist_cache_updated;
|
---|
| 298 | _str saved_gtag_filelist_ext[] = gtag_filelist_ext;
|
---|
| 299 |
|
---|
| 300 | /* HACK ALERT: Replace the tag file list for this language. */
|
---|
| 301 | gtag_filelist_ext._makeempty();
|
---|
| 302 | gtag_filelist_ext[0] = sProjTagFile;
|
---|
| 303 | saved_gtag_filelist_cache_updated = true;
|
---|
| 304 |
|
---|
| 305 | /* Do the reference searching. */
|
---|
| 306 | push_ref('-e ' :+ sLangId);
|
---|
| 307 |
|
---|
| 308 | /* restore*/
|
---|
| 309 | gtag_filelist_cache_updated = saved_gtag_filelist_cache_updated;
|
---|
| 310 | gtag_filelist_ext = saved_gtag_filelist_ext;
|
---|
| 311 | }
|
---|
| 312 | else
|
---|
| 313 | push_ref();
|
---|
| 314 | }
|
---|
| 315 | else
|
---|
| 316 | push_ref();
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 |
|
---|
[2388] | 320 | _command kkeys_gen_uuid()
|
---|
| 321 | {
|
---|
| 322 | _str uuid = guid_create_string('G');
|
---|
| 323 | uuid = lowcase(uuid);
|
---|
| 324 |
|
---|
| 325 | long lSavedCurPos = kkeys_save_cur_pos();
|
---|
| 326 | _insert_text(uuid);
|
---|
| 327 | kkeys_restore_cur_pos(lSavedCurPos);
|
---|
| 328 | }
|
---|
| 329 |
|
---|
[2407] | 330 | #endif /* >= 14.0 */
|
---|
| 331 |
|
---|
[2400] | 332 | /** @name Mac OS X Hacks: Alt+[fet] -> drop down menu
|
---|
| 333 | *
|
---|
| 334 | * This only works when the alt menu hotkeys are enabled in the
|
---|
| 335 | * settings. Al
|
---|
| 336 | *
|
---|
| 337 | * @{
|
---|
| 338 | */
|
---|
| 339 | _command void kkeys_open_file_menu()
|
---|
| 340 | {
|
---|
| 341 | call_key(A_F)
|
---|
| 342 | }
|
---|
[2388] | 343 |
|
---|
[2400] | 344 | _command void kkeys_open_edit_menu()
|
---|
| 345 | {
|
---|
| 346 | call_key(A_E)
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | _command void kkeys_open_tools_menu()
|
---|
| 350 | {
|
---|
| 351 | call_key(A_T)
|
---|
| 352 | }
|
---|
| 353 | /** @} */
|
---|
| 354 |
|
---|
[114] | 355 | void nop()
|
---|
| 356 | {
|
---|
| 357 |
|
---|
| 358 | }
|
---|
| 359 |
|
---|