bindings.cc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * dselect - Debian GNU/Linux package maintenance user interface
  3. * bindings.cc - keybinding manager object definitions and default bindings
  4. *
  5. * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with this; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <assert.h>
  24. extern "C" {
  25. #include <config.h>
  26. #include <dpkg.h>
  27. #include <dpkg-db.h>
  28. }
  29. #include "dselect.h"
  30. #include "bindings.h"
  31. keybindings::keybindings(const interpretation *ints, const orgbinding *orgbindings) {
  32. interps= ints;
  33. bindings=0;
  34. const orgbinding *b= orgbindings;
  35. while (b->action) { bind(b->key,b->action); b++; }
  36. describestart();
  37. }
  38. int keybindings::bind(int key, const char *action) {
  39. if (key == -1) return 0;
  40. const interpretation *interp;
  41. for (interp=interps; interp->action && strcmp(interp->action,action); interp++);
  42. if (!interp->action) return 0;
  43. const description *desc;
  44. for (desc=descriptions; desc->action && strcmp(desc->action,action); desc++);
  45. binding *bind;
  46. for (bind=bindings; bind && bind->key != key; bind=bind->next);
  47. if (!bind) {
  48. bind= new binding;
  49. bind->key= key;
  50. bind->next= bindings;
  51. bindings= bind;
  52. }
  53. bind->interp= interp;
  54. bind->desc= desc ? desc->desc : 0;
  55. return 1;
  56. }
  57. const char *keybindings::find(const char *action) {
  58. binding *b;
  59. for (b=bindings; b && strcmp(action,b->interp->action); b=b->next);
  60. if (!b) return _("[not bound]");
  61. const char *n= key2name(b->key);
  62. if (n) return n;
  63. static char buf[50];
  64. sprintf(buf,_("[unk: %d]"),b->key);
  65. return buf;
  66. }
  67. const keybindings::interpretation *keybindings::operator()(int key) {
  68. binding *b;
  69. for (b=bindings; b && b->key != key; b=b->next);
  70. if (!b) return 0;
  71. return b->interp;
  72. }
  73. const char **keybindings::describenext() {
  74. binding *search;
  75. int count;
  76. for (;;) {
  77. if (!iterate->action) return 0;
  78. for (count=0, search=bindings; search; search=search->next)
  79. if (!strcmp(search->interp->action,iterate->action))
  80. count++;
  81. if (count) break;
  82. iterate++;
  83. }
  84. const char **retarray= new const char *[count+2];
  85. retarray[0]= iterate->desc;
  86. for (count=1, search=bindings; search; search=search->next)
  87. if (!strcmp(search->interp->action,iterate->action))
  88. retarray[count++]= key2name(search->key);
  89. retarray[count]= 0;
  90. iterate++;
  91. return retarray;
  92. }
  93. const char *keybindings::key2name(int key) {
  94. const keyname *search;
  95. for (search=keynames; search->key != -1 && search->key != key; search++);
  96. return search->kname;
  97. }
  98. int keybindings::name2key(const char *name) {
  99. const keyname *search;
  100. for (search=keynames; search->kname && strcasecmp(search->kname,name); search++);
  101. return search->key;
  102. }
  103. keybindings::~keybindings() {
  104. binding *search, *next;
  105. for (search=bindings; search; search=next) {
  106. next= search->next;
  107. delete search;
  108. }
  109. }
  110. const keybindings::description keybindings::descriptions[]= {
  111. // Actions which apply to both types of list.
  112. { "iscrollon", N_("Scroll onwards through help/information") },
  113. { "iscrollback", N_("Scroll backwards through help/information") },
  114. { "up", N_("Move up") },
  115. { "down", N_("Move down") },
  116. { "top", N_("Go to top of list") },
  117. { "bottom", N_("Go to end of list") },
  118. { "help", N_("Request help (cycle through help screens)") },
  119. { "info", N_("Cycle through information displays") },
  120. { "redraw", N_("Redraw display") },
  121. { "scrollon1", N_("Scroll onwards through list by 1 line") },
  122. { "scrollback1", N_("Scroll backwards through list by 1 line") },
  123. { "iscrollon1", N_("Scroll onwards through help/information by 1 line") },
  124. { "iscrollback1", N_("Scroll backwards through help/information by 1 line") },
  125. { "scrollon", N_("Scroll onwards through list") },
  126. { "scrollback", N_("Scroll backwards through list") },
  127. // Actions which apply only to lists of packages.
  128. { "install", N_("Mark package(s) for installation") },
  129. { "remove", N_("Mark package(s) for deinstallation") },
  130. { "purge", N_("Mark package(s) for deinstall and purge") },
  131. { "morespecific", N_("Make highlight more specific") },
  132. { "lessspecific", N_("Make highlight less specific") },
  133. { "search", N_("Search for a package whose name contains a string") },
  134. { "searchagain", N_("Repeat last search.") },
  135. { "swaporder", N_("Swap sort order priority/section") },
  136. { "quitcheck", N_("Quit, confirming, and checking dependencies") },
  137. { "quitnocheck", N_("Quit, confirming without check") },
  138. { "quitrejectsug", N_("Quit, rejecting conflict/dependency suggestions") },
  139. { "abortnocheck", N_("Abort - quit without making changes") },
  140. { "revert", N_("Revert to old state for all packages") },
  141. { "revertsuggest", N_("Revert to suggested state for all packages") },
  142. { "revertdirect", N_("Revert to directly requested state for all packages") },
  143. // Actions which apply only to lists of methods.
  144. { "select-and-quit", N_("Select currently-highlighted access method") },
  145. { "abort", N_("Quit without changing selected access method") },
  146. { 0, 0 }
  147. };