PrefAliases.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is Vision.
  13. *
  14. * The Initial Developer of the Original Code is The Vision Team.
  15. * Portions created by The Vision Team are
  16. * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
  17. * Reserved.
  18. *
  19. * Contributor(s): Rene Gollent
  20. */
  21. #include "ColumnTypes.h"
  22. #include "ColumnListView.h"
  23. #include "PrefAliases.h"
  24. #include "Vision.h"
  25. #include "VisionStrings.h"
  26. #include <Button.h>
  27. const uint32 M_ALIAS_SELECTION_CHANGED = 'mASC';
  28. const uint32 M_ALIAS_ADD = 'mADD';
  29. const uint32 M_ALIAS_REMOVE = 'MARE';
  30. AliasesPrefsView::AliasesPrefsView (BRect frame)
  31. : BView(frame, "Alias Prefs", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
  32. fAliasView(NULL),
  33. fAddButton(NULL),
  34. fRemoveButton(NULL)
  35. {
  36. SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
  37. }
  38. AliasesPrefsView::~AliasesPrefsView (void)
  39. {
  40. }
  41. void
  42. AliasesPrefsView::MessageReceived (BMessage *msg)
  43. {
  44. switch (msg->what)
  45. {
  46. case M_ALIAS_SELECTION_CHANGED:
  47. {
  48. if (msg->FindInt32("index") >= 0)
  49. {
  50. fRemoveButton->SetEnabled(true);
  51. }
  52. else
  53. {
  54. fRemoveButton->SetEnabled(false);
  55. }
  56. }
  57. break;
  58. case M_ALIAS_REMOVE:
  59. {
  60. BRow *row (fAliasView->CurrentSelection());
  61. if (row != NULL)
  62. {
  63. fAliasView->RemoveRow(row);
  64. vision_app->RemoveAlias(dynamic_cast<BStringField *>(row->GetField(0))->String());
  65. fRemoveButton->SetEnabled(false);
  66. delete row;
  67. }
  68. }
  69. break;
  70. default:
  71. {
  72. BView::MessageReceived(msg);
  73. }
  74. break;
  75. }
  76. }
  77. void
  78. AliasesPrefsView::AttachedToWindow (void)
  79. {
  80. BView::AttachedToWindow();
  81. BRect bounds (Bounds());
  82. bounds.InsetBySelf(10, 10);
  83. bounds.bottom -= 50;
  84. fAliasView = new BColumnListView(bounds, "clv", B_FOLLOW_ALL_SIDES, B_WILL_DRAW, B_FANCY_BORDER);
  85. AddChild(fAliasView);
  86. fAliasView->SetSelectionMessage(new BMessage(M_ALIAS_SELECTION_CHANGED));
  87. fAliasView->AddColumn(new BStringColumn(S_PREFALIAS_COLUMN_NAME, StringWidth(S_PREFALIAS_COLUMN_NAME) * 2.0,
  88. 0, bounds.Width(), 0), 0);
  89. fAliasView->AddColumn(new BStringColumn(S_PREFALIAS_COLUMN_ALIAS, StringWidth(S_PREFALIAS_COLUMN_ALIAS) * 6.0,
  90. 0, bounds.Width(), 0), 1);
  91. fAddButton = new BButton(BRect(0,0,0,0), "alAdd", S_PREFALIAS_ADD, new BMessage(M_ALIAS_ADD), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
  92. AddChild(fAddButton);
  93. fAddButton->ResizeToPreferred();
  94. fRemoveButton = new BButton(BRect(0,0,0,0), "alRemove", S_PREFALIAS_REMOVE, new BMessage(M_ALIAS_REMOVE), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
  95. AddChild(fRemoveButton);
  96. fRemoveButton->ResizeToPreferred();
  97. fRemoveButton->MoveTo(fAliasView->Frame().right - fRemoveButton->Bounds().Width(),
  98. fAliasView->Frame().bottom + 10.0);
  99. fAddButton->MoveTo(fRemoveButton->Frame().left - (fAddButton->Frame().Width() + 5.0), fRemoveButton->Frame().top);
  100. fRemoveButton->SetEnabled(false);
  101. BuildAliasList();
  102. }
  103. void
  104. AliasesPrefsView::AllAttached (void)
  105. {
  106. BView::AllAttached();
  107. fAliasView->SetTarget(this);
  108. fAddButton->SetTarget(this);
  109. fRemoveButton->SetTarget(this);
  110. }
  111. void
  112. AliasesPrefsView::BuildAliasList(void)
  113. {
  114. void *cookie (NULL);
  115. BString name, value;
  116. while (vision_app->GetNextAlias(&cookie, name, value))
  117. {
  118. BRow *row (new BRow());
  119. row->SetField(new BStringField(name.String()), 0);
  120. row->SetField(new BStringField(value.String()), 1);
  121. fAliasView->AddRow(row);
  122. }
  123. }