EditorManager.h 4.5 KB

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