ComboInput.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Dialogs.hpp>
  5. //---------------------------------------------------------------------
  6. #include <Common.h>
  7. #include <TextsWin.h>
  8. #include <HelpWin.h>
  9. #include <WinInterface.h>
  10. #include <VCLCommon.h>
  11. #include <ScpMain.h>
  12. #include "ComboInput.h"
  13. //---------------------------------------------------------------------
  14. #pragma resource "*.dfm"
  15. //---------------------------------------------------------------------
  16. bool __fastcall DoComboInputDialog(
  17. const AnsiString Caption, const AnsiString Prompt,
  18. AnsiString & Text, TStrings * Items, TCloseQueryEvent OnCloseQuery,
  19. bool AllowEmpty, const AnsiString HelpKeyword)
  20. {
  21. bool Result;
  22. TComboInputDialog * ComboInputDialog = new TComboInputDialog(Application);
  23. try
  24. {
  25. ComboInputDialog->Caption = Caption;
  26. ComboInputDialog->Prompt = Prompt;
  27. ComboInputDialog->Text = Text;
  28. ComboInputDialog->Items = Items;
  29. ComboInputDialog->AllowEmpty = AllowEmpty;
  30. ComboInputDialog->OnCloseQuery = OnCloseQuery;
  31. ComboInputDialog->HelpKeyword = HelpKeyword;
  32. Result = (ComboInputDialog->ShowModal() == mrOk);
  33. if (Result)
  34. {
  35. Text = ComboInputDialog->Text;
  36. }
  37. }
  38. __finally
  39. {
  40. delete ComboInputDialog;
  41. }
  42. return Result;
  43. }
  44. //---------------------------------------------------------------------
  45. AnsiString __fastcall DoSaveSessionDialog(
  46. TStoredSessionList * ASessionList, const AnsiString DefaultName)
  47. {
  48. // SessionList is no longer passed to TComboInputDialog, it uses global variable
  49. assert(ASessionList == StoredSessions);
  50. AnsiString Result;
  51. TComboInputDialog * SaveSessionDialog = NULL;
  52. TStrings * Items = NULL;
  53. try
  54. {
  55. Items = new TStringList();
  56. for (int Index = 0; Index < ASessionList->Count; Index++)
  57. {
  58. TSessionData * Data = ASessionList->Sessions[Index];
  59. if (!Data->Special)
  60. {
  61. Items->Add(Data->Name);
  62. }
  63. }
  64. SaveSessionDialog = new TComboInputDialog(Application);
  65. SaveSessionDialog->Items = Items;
  66. SaveSessionDialog->Text = DefaultName;
  67. SaveSessionDialog->Caption = LoadStr(SAVE_SESSION_CAPTION);
  68. SaveSessionDialog->Prompt = LoadStr(SAVE_SESSION_PROMPT);
  69. SaveSessionDialog->OnCloseQuery = SaveSessionDialog->StoredSessionsCloseQuery;
  70. SaveSessionDialog->HelpKeyword = HELP_SESSION_SAVE;
  71. if (SaveSessionDialog->ShowModal() == mrOk)
  72. {
  73. Result = SaveSessionDialog->Text;
  74. }
  75. }
  76. __finally
  77. {
  78. delete SaveSessionDialog;
  79. delete Items;
  80. }
  81. return Result;
  82. }
  83. //---------------------------------------------------------------------
  84. __fastcall TComboInputDialog::TComboInputDialog(TComponent* AOwner)
  85. : TForm(AOwner)
  86. {
  87. FAllowEmpty = false;
  88. UseSystemSettings(this);
  89. }
  90. //---------------------------------------------------------------------
  91. void __fastcall TComboInputDialog::SetItems(TStrings * value)
  92. {
  93. InputCombo->Items = value;
  94. UpdateControls();
  95. }
  96. //---------------------------------------------------------------------
  97. TStrings * __fastcall TComboInputDialog::GetItems()
  98. {
  99. return InputCombo->Items;
  100. }
  101. //---------------------------------------------------------------------
  102. void __fastcall TComboInputDialog::SetText(AnsiString value)
  103. {
  104. InputCombo->Text = value;
  105. UpdateControls();
  106. }
  107. //---------------------------------------------------------------------
  108. AnsiString __fastcall TComboInputDialog::GetText()
  109. {
  110. return InputCombo->Text;
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TComboInputDialog::SetPrompt(AnsiString value)
  114. {
  115. InputLabel->Caption = value;
  116. }
  117. //---------------------------------------------------------------------------
  118. AnsiString __fastcall TComboInputDialog::GetPrompt()
  119. {
  120. return InputLabel->Caption;
  121. }
  122. //---------------------------------------------------------------------------
  123. void __fastcall TComboInputDialog::InputComboChange(TObject * /*Sender*/)
  124. {
  125. UpdateControls();
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TComboInputDialog::UpdateControls()
  129. {
  130. EnableControl(OKButton, !Text.IsEmpty() || FAllowEmpty);
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TComboInputDialog::StoredSessionsCloseQuery(TObject * /*Sender*/,
  134. bool & CanClose)
  135. {
  136. CanClose = true;
  137. if (ModalResult == mrOk)
  138. {
  139. TSessionData::ValidateName(Text);
  140. assert(StoredSessions);
  141. TSessionData * Data = (TSessionData *)StoredSessions->FindByName(Text);
  142. if (Data && Data->Special)
  143. {
  144. MessageDialog(FMTLOAD(CANNOT_OVERWRITE_SPECIAL_SESSION, (Text)),
  145. qtError, qaOK, HELP_NONE);
  146. CanClose = false;
  147. }
  148. else if (Data &&
  149. MessageDialog(FMTLOAD(CONFIRM_OVERWRITE_SESSION, (Text)),
  150. qtConfirmation, qaYes | qaNo, HELP_SESSION_SAVE_OVERWRITE) != qaYes)
  151. {
  152. CanClose = false;
  153. }
  154. }
  155. }
  156. //---------------------------------------------------------------------------
  157. void __fastcall TComboInputDialog::FormShow(TObject * /*Sender*/)
  158. {
  159. TBorderIcons BI = BorderIcons;
  160. if (HelpKeyword.IsEmpty())
  161. {
  162. BI >> biHelp;
  163. OKButton->Left = CancelButton->Left;
  164. CancelButton->Left = HelpButton->Left;
  165. HelpButton->Visible = false;
  166. }
  167. else
  168. {
  169. BI << biHelp;
  170. }
  171. BorderIcons = BI;
  172. }
  173. //---------------------------------------------------------------------------
  174. void __fastcall TComboInputDialog::HelpButtonClick(TObject * /*Sender*/)
  175. {
  176. FormHelp(this);
  177. }
  178. //---------------------------------------------------------------------------