SaveSession.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Dialogs.hpp>
  5. //---------------------------------------------------------------------
  6. #include <Common.h>
  7. #include <HelpWin.h>
  8. #include <WinInterface.h>
  9. #include <VCLCommon.h>
  10. #include <CoreMain.h>
  11. #include <TextsWin.h>
  12. #include "SaveSession.h"
  13. //---------------------------------------------------------------------
  14. #pragma resource "*.dfm"
  15. //---------------------------------------------------------------------------
  16. bool __fastcall DoSaveSessionDialog(AnsiString & SessionName,
  17. bool * SavePassword, TSessionData * OriginalSession)
  18. {
  19. bool Result;
  20. TSaveSessionDialog * Dialog = NULL;
  21. TStrings * Items = NULL;
  22. try
  23. {
  24. Items = new TStringList();
  25. for (int Index = 0; Index < StoredSessions->Count; Index++)
  26. {
  27. TSessionData * Data = StoredSessions->Sessions[Index];
  28. if (!Data->Special)
  29. {
  30. Items->Add(Data->Name);
  31. }
  32. }
  33. Dialog = new TSaveSessionDialog(Application, Items, OriginalSession,
  34. (SavePassword != NULL));
  35. bool ASavePassword = ((SavePassword != NULL) ? *SavePassword : false);
  36. Result = Dialog->Execute(SessionName, ASavePassword);
  37. if (Result)
  38. {
  39. if (SavePassword != NULL)
  40. {
  41. *SavePassword = ASavePassword;
  42. }
  43. }
  44. }
  45. __finally
  46. {
  47. delete Dialog;
  48. delete Items;
  49. }
  50. return Result;
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall SessionNameValidate(const AnsiString & Text,
  54. TSessionData * RenamingSession)
  55. {
  56. TSessionData::ValidatePath(Text);
  57. assert(StoredSessions);
  58. TSessionData * Data = (TSessionData *)StoredSessions->FindByName(Text);
  59. if (Data && Data->Special)
  60. {
  61. MessageDialog(FMTLOAD(CANNOT_OVERWRITE_SPECIAL_SESSION, (Text)),
  62. qtError, qaOK, HELP_NONE);
  63. Abort();
  64. }
  65. else if (Data && (Data != RenamingSession) &&
  66. MessageDialog(FMTLOAD(CONFIRM_OVERWRITE_SESSION, (Text)),
  67. qtConfirmation, qaYes | qaNo, HELP_SESSION_SAVE_OVERWRITE) != qaYes)
  68. {
  69. Abort();
  70. }
  71. }
  72. //---------------------------------------------------------------------
  73. __fastcall TSaveSessionDialog::TSaveSessionDialog(TComponent * AOwner,
  74. TStrings * Items, TSessionData * OriginalSession, bool AllowSavePassword) :
  75. TForm(AOwner),
  76. FOriginalSession(OriginalSession)
  77. {
  78. UseSystemSettings(this);
  79. InstallPathWordBreakProc(InputCombo);
  80. InputCombo->Items = Items;
  81. EnableControl(SavePasswordCheck, AllowSavePassword);
  82. }
  83. //---------------------------------------------------------------------
  84. bool __fastcall TSaveSessionDialog::Execute(AnsiString & SessionName, bool & SavePassword)
  85. {
  86. InputCombo->Text = SessionName;
  87. SavePasswordCheck->Checked = SavePassword;
  88. bool Result = (ShowModal() == mrOk);
  89. if (Result)
  90. {
  91. SessionName = InputCombo->Text;
  92. SavePassword = SavePasswordCheck->Checked;
  93. }
  94. return Result;
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TSaveSessionDialog::InputComboChange(TObject * /*Sender*/)
  98. {
  99. UpdateControls();
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TSaveSessionDialog::UpdateControls()
  103. {
  104. EnableControl(OKButton, !InputCombo->Text.IsEmpty());
  105. }
  106. //---------------------------------------------------------------------------
  107. void __fastcall TSaveSessionDialog::HelpButtonClick(TObject * /*Sender*/)
  108. {
  109. FormHelp(this);
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TSaveSessionDialog::FormCloseQuery(TObject * /*Sender*/,
  113. bool & /*CanClose*/)
  114. {
  115. if (ModalResult == mrOk)
  116. {
  117. SessionNameValidate(InputCombo->Text, FOriginalSession);
  118. }
  119. }
  120. //---------------------------------------------------------------------------
  121. void __fastcall TSaveSessionDialog::FormShow(TObject * /*Sender*/)
  122. {
  123. int P = InputCombo->Text.LastDelimiter("/");
  124. if (P > 0)
  125. {
  126. InputCombo->SetFocus();
  127. InputCombo->SelStart = P;
  128. InputCombo->SelLength = InputCombo->Text.Length() - P;
  129. }
  130. UpdateControls();
  131. }
  132. //---------------------------------------------------------------------------