bindings.cc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * bindings.cc - keybinding manager object definitions and default bindings
  4. *
  5. * Copyright © 1995 Ian Jackson <ijackson@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 <https://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 = nullptr;
  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;
  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)
  78. return nullptr;
  79. return b->interp;
  80. }
  81. const char **keybindings::describenext() {
  82. binding *search;
  83. int count;
  84. for (;;) {
  85. if (!iterate->action)
  86. return nullptr;
  87. for (count=0, search=bindings; search; search=search->next)
  88. if (strcmp(search->interp->action, iterate->action) == 0)
  89. count++;
  90. if (count) break;
  91. iterate++;
  92. }
  93. const char **retarray= new const char *[count+2];
  94. retarray[0]= iterate->desc;
  95. for (count=1, search=bindings; search; search=search->next)
  96. if (strcmp(search->interp->action, iterate->action) == 0)
  97. retarray[count++]= key2name(search->key);
  98. retarray[count] = nullptr;
  99. iterate++;
  100. return retarray;
  101. }
  102. const char *keybindings::key2name(int key) {
  103. const keyname *search = keynames;
  104. while (search->key != -1 && search->key != key)
  105. search++;
  106. return search->kname;
  107. }
  108. int keybindings::name2key(const char *name) {
  109. const keyname *search = keynames;
  110. while (search->kname && strcasecmp(search->kname, name))
  111. search++;
  112. return search->key;
  113. }
  114. keybindings::~keybindings() {
  115. binding *search, *next;
  116. for (search=bindings; search; search=next) {
  117. next= search->next;
  118. delete search;
  119. }
  120. }
  121. const keybindings::description keybindings::descriptions[]= {
  122. // Actions which apply to both types of list.
  123. { "iscrollon", N_("Scroll onwards through help/information") },
  124. { "iscrollback", N_("Scroll backwards through help/information") },
  125. { "up", N_("Move up") },
  126. { "down", N_("Move down") },
  127. { "top", N_("Go to top of list") },
  128. { "bottom", N_("Go to end of list") },
  129. { "help", N_("Request help (cycle through help screens)") },
  130. { "info", N_("Cycle through information displays") },
  131. { "redraw", N_("Redraw display") },
  132. { "scrollon1", N_("Scroll onwards through list by 1 line") },
  133. { "scrollback1", N_("Scroll backwards through list by 1 line") },
  134. { "iscrollon1", N_("Scroll onwards through help/information by 1 line") },
  135. { "iscrollback1", N_("Scroll backwards through help/information by 1 line") },
  136. { "scrollon", N_("Scroll onwards through list") },
  137. { "scrollback", N_("Scroll backwards through list") },
  138. // Actions which apply only to lists of packages.
  139. { "install", N_("Mark package(s) for installation") },
  140. { "remove", N_("Mark package(s) for deinstallation") },
  141. { "purge", N_("Mark package(s) for deinstall and purge") },
  142. { "morespecific", N_("Make highlight more specific") },
  143. { "lessspecific", N_("Make highlight less specific") },
  144. { "search", N_("Search for a package whose name contains a string") },
  145. { "searchagain", N_("Repeat last search") },
  146. { "swaporder", N_("Swap sort order priority/section") },
  147. { "quitcheck", N_("Quit, confirming, and checking dependencies") },
  148. { "quitnocheck", N_("Quit, confirming without check") },
  149. { "quitrejectsug", N_("Quit, rejecting conflict/dependency suggestions") },
  150. { "abortnocheck", N_("Abort - quit without making changes") },
  151. { "revert", N_("Revert to old state for all packages") },
  152. { "revertsuggest", N_("Revert to suggested state for all packages") },
  153. { "revertdirect", N_("Revert to directly requested state for all packages") },
  154. { "revertinstalled", N_("Revert to currently installed state for all packages") },
  155. // Actions which apply only to lists of methods.
  156. { "select-and-quit", N_("Select currently-highlighted access method") },
  157. { "abort", N_("Quit without changing selected access method") },
  158. { nullptr, nullptr }
  159. };