EditorManager.h 3.9 KB

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