bindings.cc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * bindings.cc - keybinding manager object definitions and default bindings
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.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 License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include <compat.h>
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include <dpkg/i18n.h>
  25. #include <dpkg/dpkg.h>
  26. #include <dpkg/dpkg-db.h>
  27. #include "dselect.h"
  28. #include "bindings.h"
  29. keybindings::keybindings(const interpretation *ints, const orgbinding *orgbindings) {
  30. interps= ints;
  31. bindings=0;
  32. const orgbinding *b= orgbindings;
  33. while (b->action) { bind(b->key,b->action); b++; }
  34. describestart();
  35. }
  36. int keybindings::bind(int key, const char *action) {
  37. if (key == -1) return 0;
  38. const interpretation *interp = interps;
  39. while (interp->action && strcmp(interp->action, action))
  40. interp++;
  41. if (!interp->action) return 0;
  42. const description *desc = descriptions;
  43. while (desc->action && strcmp(desc->action, action))
  44. desc++;
  45. binding *bind = bindings;
  46. while (bind && bind->key != key)
  47. bind = bind->next;
  48. if (!bind) {
  49. bind= new binding;
  50. bind->key= key;
  51. bind->next= bindings;
  52. bindings= bind;
  53. }
  54. bind->interp= interp;
  55. bind->desc= desc ? desc->desc : 0;
  56. return 1;
  57. }
  58. const char *keybindings::find(const char *action) {
  59. binding *b = bindings;
  60. while (b && strcmp(action, b->interp->action))
  61. b = b->next;
  62. if (!b) return _("[not bound]");
  63. const char *n= key2name(b->key);
  64. if (n) return n;
  65. static char buf[50];
  66. sprintf(buf,_("[unk: %d]"),b->key);
  67. return buf;
  68. }
  69. const keybindings::interpretation *keybindings::operator()(int key) {
  70. binding *b = bindings;
  71. while (b && b->key != key)
  72. b = b->next;
  73. if (!b) return 0;
  74. return b->interp;
  75. }
  76. const char **keybindings::describenext() {
  77. binding *search;
  78. int count;
  79. for (;;) {
  80. if (!iterate->action) return 0;
  81. for (count=0, search=bindings; search; search=search->next)
  82. if (!strcmp(search->interp->action,iterate->action))
  83. count++;
  84. if (count) break;
  85. iterate++;
  86. }
  87. const char **retarray= new const char *[count+2];
  88. retarray[0]= iterate->desc;
  89. for (count=1, search=bindings; search; search=search->next)
  90. if (!strcmp(search->interp->action,iterate->action))
  91. retarray[count++]= key2name(search->key);
  92. retarray[count]= 0;
  93. iterate++;
  94. return retarray;
  95. }
  96. const char *keybindings::key2name(int key) {
  97. const keyname *search = keynames;
  98. while (search->key != -1 && search->key != key)
  99. search++;
  100. return search->kname;
  101. }
  102. int keybindings::name2key(const char *name) {
  103. const keyname *search = keynames;
  104. while (search->kname && strcasecmp(search->kname, name))
  105. search++;
  106. return search->key;
  107. }
  108. keybindings::~keybindings() {
  109. binding *search, *next;
  110. for (search=bindings; search; search=next) {
  111. next= search->next;
  112. delete search;
  113. }
  114. }
  115. const keybindings::description keybindings::descriptions[]= {
  116. // Actions which apply to both types of list.
  117. { "iscrollon", N_("Scroll onwards through help/information") },
  118. { "iscrollback", N_("Scroll backwards through help/information") },
  119. { "up", N_("Move up") },
  120. { "down", N_("Move down") },
  121. { "top", N_("Go to top of list") },
  122. { "bottom", N_("Go to end of list") },
  123. { "help", N_("Request help (cycle through help screens)") },
  124. { "info", N_("Cycle through information displays") },
  125. { "redraw", N_("Redraw display") },
  126. { "scrollon1", N_("Scroll onwards through list by 1 line") },
  127. { "scrollback1", N_("Scroll backwards through list by 1 line") },
  128. { "iscrollon1", N_("Scroll onwards through help/information by 1 line") },
  129. { "iscrollback1", N_("Scroll backwards through help/information by 1 line") },
  130. { "scrollon", N_("Scroll onwards through list") },
  131. { "scrollback", N_("Scroll backwards through list") },
  132. // Actions which apply only to lists of packages.
  133. { "install", N_("Mark package(s) for installation") },
  134. { "remove", N_("Mark package(s) for deinstallation") },
  135. { "purge", N_("Mark package(s) for deinstall and purge") },
  136. { "morespecific", N_("Make highlight more specific") },
  137. { "lessspecific", N_("Make highlight less specific") },
  138. { "search", N_("Search for a package whose name contains a string") },
  139. { "searchagain", N_("Repeat last search.") },
  140. { "swaporder", N_("Swap sort order priority/section") },
  141. { "quitcheck", N_("Quit, confirming, and checking dependencies") },
  142. { "quitnocheck", N_("Quit, confirming without check") },
  143. { "quitrejectsug", N_("Quit, rejecting conflict/dependency suggestions") },
  144. { "abortnocheck", N_("Abort - quit without making changes") },
  145. { "revert", N_("Revert to old state for all packages") },
  146. { "revertsuggest", N_("Revert to suggested state for all packages") },
  147. { "revertdirect", N_("Revert to directly requested state for all packages") },
  148. { "revertinstalled", N_("Revert to currently installed state for all packages") },
  149. // Actions which apply only to lists of methods.
  150. { "select-and-quit", N_("Select currently-highlighted access method") },
  151. { "abort", N_("Quit without changing selected access method") },
  152. { 0, 0 }
  153. };