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 RemoteDirectory;
  13. bool ForceText;
  14. TTerminal * Terminal;
  15. TTerminalQueue * Queue;
  16. AnsiString SessionName;
  17. AnsiString OriginalFileName;
  18. AnsiString Command;
  19. };
  20. //---------------------------------------------------------------------------
  21. typedef void __fastcall (__closure * TEditedFileChangedEvent)
  22. (const AnsiString FileName, const TEditedFileData & Data, HANDLE CompleteEvent);
  23. typedef void __fastcall (__closure * TEditedFileReloadEvent)
  24. (const AnsiString FileName, const TEditedFileData & Data);
  25. typedef void __fastcall (__closure * TEditedFileEarlyClosedEvent)
  26. (const TEditedFileData & Data, bool * CloseFlag, bool & KeepOpen);
  27. //---------------------------------------------------------------------------
  28. typedef void __fastcall (__closure * TEditedFileProcessEvent)
  29. (const AnsiString FileName, TEditedFileData & Data, TObject * Token, void * Arg);
  30. //---------------------------------------------------------------------------
  31. class TEditorManager
  32. {
  33. public:
  34. __fastcall TEditorManager();
  35. __fastcall ~TEditorManager();
  36. bool __fastcall Empty(bool IgnoreClosed);
  37. bool __fastcall CanAddFile(const AnsiString RemoteDirectory,
  38. const AnsiString OriginalFileName, const AnsiString SessionName,
  39. TObject *& Token,AnsiString & ExistingLocalDirectory);
  40. bool __fastcall CloseInternalEditors(TNotifyEvent CloseCallback);
  41. bool __fastcall CloseExternalFilesWithoutProcess();
  42. void __fastcall AddFileInternal(const AnsiString FileName,
  43. const TEditedFileData & Data, bool * CloseFlag, TObject * Token);
  44. void __fastcall AddFileExternal(const AnsiString FileName,
  45. const TEditedFileData & Data, bool * CloseFlag, HANDLE Process);
  46. void __fastcall Check();
  47. void __fastcall FileChanged(TObject * Token);
  48. void __fastcall FileReload(TObject * Token);
  49. void __fastcall FileClosed(TObject * Token);
  50. void __fastcall ProcessFiles(TEditedFileProcessEvent Callback, void * Arg);
  51. __property TEditedFileChangedEvent OnFileChange = { read = FOnFileChange, write = FOnFileChange };
  52. __property TEditedFileReloadEvent OnFileReload = { read = FOnFileReload, write = FOnFileReload };
  53. __property TEditedFileEarlyClosedEvent OnFileEarlyClosed = { read = FOnFileEarlyClosed, write = FOnFileEarlyClosed };
  54. private:
  55. struct TFileData
  56. {
  57. AnsiString FileName;
  58. AnsiString LocalDirectory;
  59. HANDLE Monitor;
  60. bool External;
  61. HANDLE Process;
  62. TObject * Token;
  63. int Timestamp;
  64. TEditedFileData Data;
  65. bool Closed;
  66. HANDLE UploadCompleteEvent;
  67. bool * CloseFlag;
  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