bindings.cc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but 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. bool
  37. keybindings::bind(int key, const char *action)
  38. {
  39. if (key == -1)
  40. return false;
  41. const interpretation *interp = interps;
  42. while (interp->action && strcmp(interp->action, action))
  43. interp++;
  44. if (!interp->action)
  45. return false;
  46. const description *desc = descriptions;
  47. while (desc->action && strcmp(desc->action, action))
  48. desc++;
  49. binding *b = bindings;
  50. while (b && b->key != key)
  51. b = b->next;
  52. if (!b) {
  53. b = new binding;
  54. b->key = key;
  55. b->next = bindings;
  56. bindings = b;
  57. }
  58. b->interp = interp;
  59. b->desc = desc ? desc->desc : 0;
  60. return true;
  61. }
  62. const char *keybindings::find(const char *action) {
  63. binding *b = bindings;
  64. while (b && strcmp(action, b->interp->action))
  65. b = b->next;
  66. if (!b) return _("[not bound]");
  67. const char *n= key2name(b->key);
  68. if (n) return n;
  69. static char buf[50];
  70. sprintf(buf,_("[unk: %d]"),b->key);
  71. return buf;
  72. }
  73. const keybindings::interpretation *keybindings::operator()(int key) {
  74. binding *b = bindings;
  75. while (b && b->key != key)
  76. b = b->next;
  77. if (!b) return 0;
  78. return b->interp;
  79. }
  80. const char **keybindings::describenext() {
  81. binding *search;
  82. int count;
  83. for (;;) {
  84. if (!iterate->action) return 0;
  85. for (count=0, search=bindings; search; search=search->next)
  86. if (strcmp(search->interp->action, iterate->action) == 0)
  87. count++;
  88. if (count) break;
  89. iterate++;
  90. }
  91. const char **retarray= new const char *[count+2];
  92. retarray[0]= iterate->desc;
  93. for (count=1, search=bindings; search; search=search->next)
  94. if (strcmp(search->interp->action, iterate->action) == 0)
  95. retarray[count++]= key2name(search->key);
  96. retarray[count]= 0;
  97. iterate++;
  98. return retarray;
  99. }
  100. const char *keybindings::key2name(int key) {
  101. const keyname *search = keynames;
  102. while (search->key != -1 && search->key != key)
  103. search++;
  104. return search->kname;
  105. }
  106. int keybindings::name2key(const char *name) {
  107. const keyname *search = keynames;
  108. while (search->kname && strcasecmp(search->kname, name))
  109. search++;
  110. return search->key;
  111. }
  112. keybindings::~keybindings() {
  113. binding *search, *next;
  114. for (search=bindings; search; search=next) {
  115. next= search->next;
  116. delete search;
  117. }
  118. }
  119. const keybindings::description keybindings::descriptions[]= {
  120. // Actions which apply to both types of list.
  121. { "iscrollon", N_("Scroll onwards through help/information") },
  122. { "iscrollback", N_("Scroll backwards through help/information") },
  123. { "up", N_("Move up") },
  124. { "down", N_("Move down") },
  125. { "top", N_("Go to top of list") },
  126. { "bottom", N_("Go to end of list") },
  127. { "help", N_("Request help (cycle through help screens)") },
  128. { "info", N_("Cycle through information displays") },
  129. { "redraw", N_("Redraw display") },
  130. { "scrollon1", N_("Scroll onwards through list by 1 line") },
  131. { "scrollback1", N_("Scroll backwards through list by 1 line") },
  132. { "iscrollon1", N_("Scroll onwards through help/information by 1 line") },
  133. { "iscrollback1", N_("Scroll backwards through help/information by 1 line") },
  134. { "scrollon", N_("Scroll onwards through list") },
  135. { "scrollback", N_("Scroll backwards through list") },
  136. // Actions which apply only to lists of packages.
  137. { "install", N_("Mark package(s) for installation") },
  138. { "remove", N_("Mark package(s) for deinstallation") },
  139. { "purge", N_("Mark package(s) for deinstall and purge") },
  140. { "morespecific", N_("Make highlight more specific") },
  141. { "lessspecific", N_("Make highlight less specific") },
  142. { "search", N_("Search for a package whose name contains a string") },
  143. { "searchagain", N_("Repeat last search") },
  144. { "swaporder", N_("Swap sort order priority/section") },
  145. { "quitcheck", N_("Quit, confirming, and checking dependencies") },
  146. { "quitnocheck", N_("Quit, confirming without check") },
  147. { "quitrejectsug", N_("Quit, rejecting conflict/dependency suggestions") },
  148. { "abortnocheck", N_("Abort - quit without making changes") },
  149. { "revert", N_("Revert to old state for all packages") },
  150. { "revertsuggest", N_("Revert to suggested state for all packages") },
  151. { "revertdirect", N_("Revert to directly requested state for all packages") },
  152. { "revertinstalled", N_("Revert to currently installed state for all packages") },
  153. // Actions which apply only to lists of methods.
  154. { "select-and-quit", N_("Select currently-highlighted access method") },
  155. { "abort", N_("Quit without changing selected access method") },
  156. { 0, 0 }
  157. };