EditorManager.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //---------------------------------------------------------------------------
  2. #ifndef EditorManagerH
  3. #define EditorManagerH
  4. //---------------------------------------------------------------------------
  5. #include <vector>
  6. //---------------------------------------------------------------------------
  7. class TManagedTerminal;
  8. class TTerminalQueue;
  9. //---------------------------------------------------------------------------
  10. struct TEditedFileData
  11. {
  12. TEditedFileData();
  13. ~TEditedFileData();
  14. UnicodeString LocalRootDirectory;
  15. UnicodeString RemoteDirectory;
  16. bool ForceText;
  17. TManagedTerminal * Terminal;
  18. TSessionData * SessionData;
  19. TTerminalQueue * Queue;
  20. UnicodeString SessionName;
  21. UnicodeString OriginalFileName;
  22. UnicodeString Command;
  23. TDateTime SourceTimestamp;
  24. };
  25. //---------------------------------------------------------------------------
  26. typedef void __fastcall (__closure * TEditedFileChangedEvent)
  27. (const UnicodeString & FileName, TEditedFileData * Data, HANDLE CompleteEvent, bool & Retry);
  28. typedef void __fastcall (__closure * TEditedFileReloadEvent)
  29. (const UnicodeString & FileName, TEditedFileData * Data);
  30. typedef void __fastcall (__closure * TEditedFileEarlyClosedEvent)
  31. (const TEditedFileData * Data, bool & KeepOpen);
  32. typedef void __fastcall (__closure * TEditedFileUploadComplete)
  33. (TEditedFileData * Data, TObject * Token, bool Failed);
  34. //---------------------------------------------------------------------------
  35. typedef void __fastcall (__closure * TEditedFileProcessEvent)
  36. (const UnicodeString FileName, TEditedFileData * Data, TObject * Token, void * Arg);
  37. //---------------------------------------------------------------------------
  38. class TEditorManager
  39. {
  40. public:
  41. __fastcall TEditorManager();
  42. __fastcall ~TEditorManager();
  43. bool __fastcall Empty(bool IgnoreClosed);
  44. bool __fastcall CanAddFile(const UnicodeString RemoteDirectory,
  45. const UnicodeString OriginalFileName, const UnicodeString SessionName,
  46. TObject *& Token, UnicodeString & ExistingLocalRootDirectory,
  47. UnicodeString & ExistingLocalDirectory);
  48. bool __fastcall CloseInternalEditors(TNotifyEvent CloseCallback);
  49. bool __fastcall CloseExternalFilesWithoutProcess();
  50. void __fastcall AddFileInternal(const UnicodeString FileName,
  51. TEditedFileData * Data, TObject * Token);
  52. void __fastcall AddFileExternal(const UnicodeString FileName,
  53. TEditedFileData * Data, HANDLE Process);
  54. void __fastcall Check();
  55. void __fastcall FileChanged(TObject * Token);
  56. void __fastcall FileReload(TObject * Token);
  57. void __fastcall FileClosed(TObject * Token, bool Forced);
  58. void __fastcall ProcessFiles(TEditedFileProcessEvent Callback, void * Arg);
  59. __property TEditedFileChangedEvent OnFileChange = { read = FOnFileChange, write = FOnFileChange };
  60. __property TEditedFileReloadEvent OnFileReload = { read = FOnFileReload, write = FOnFileReload };
  61. __property TEditedFileEarlyClosedEvent OnFileEarlyClosed = { read = FOnFileEarlyClosed, write = FOnFileEarlyClosed };
  62. __property TEditedFileUploadComplete OnFileUploadComplete = { read = FOnFileUploadComplete, write = FOnFileUploadComplete };
  63. private:
  64. struct TFileData
  65. {
  66. UnicodeString FileName;
  67. bool External;
  68. HANDLE Process;
  69. TObject * Token;
  70. TDateTime Timestamp;
  71. TEditedFileData * Data;
  72. bool Closed;
  73. HANDLE UploadCompleteEvent;
  74. TDateTime Opened;
  75. bool Reupload;
  76. bool Reloading;
  77. unsigned int Saves;
  78. };
  79. std::vector<TFileData> FFiles;
  80. std::vector<HANDLE> FProcesses;
  81. std::vector<HANDLE> FUploadCompleteEvents;
  82. TEditedFileChangedEvent FOnFileChange;
  83. TEditedFileReloadEvent FOnFileReload;
  84. TEditedFileEarlyClosedEvent FOnFileEarlyClosed;
  85. TEditedFileUploadComplete FOnFileUploadComplete;
  86. void __fastcall AddFile(TFileData & FileData, TEditedFileData * Data);
  87. void __fastcall UploadComplete(int Index, bool Failed);
  88. bool __fastcall CloseFile(int Index, bool IgnoreErrors, bool Delete);
  89. void __fastcall CloseProcess(int Index);
  90. bool __fastcall EarlyClose(int Index);
  91. bool __fastcall HasFileChanged(int Index, TDateTime & NewTimestamp);
  92. void __fastcall CheckFileChange(int Index, bool Force);
  93. int __fastcall FindFile(const TObject * Token);
  94. void __fastcall ReleaseFile(int Index);
  95. TDateTime NormalizeTimestamp(const TDateTime & Timestamp);
  96. bool GetFileTimestamp(const UnicodeString & FileName, TDateTime & Timestamp);
  97. enum TWaitHandle { PROCESS, EVENT };
  98. int __fastcall WaitFor(unsigned int Count, const HANDLE * Handles,
  99. TWaitHandle WaitFor);
  100. };
  101. //---------------------------------------------------------------------------
  102. #endif