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