bindings.cc 6.4 KB

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