bindings.cc 6.3 KB

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