1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
5 #include <CrySystem/File/IFileChangeMonitor.h>
6 #include <CryMono/IMonoRuntime.h>
7 #include <CrySchematyc/CoreAPI.h>
8 #include <CryCore/Containers/CryListenerSet.h>
13 struct ICSharpMessageListener
15 virtual ~ICSharpMessageListener() {}
17 virtual void OnMessagesUpdated(string messages
) = 0;
20 typedef CListenerSet
<ICSharpMessageListener
*> CSharpMessageListeners
;
22 class CCSharpEditorPlugin final
24 public Schematyc::IEnvRegistryListener
,
25 public IFileChangeListener
,
26 public IMonoCompileListener
,
27 public ISystemEventListener
,
28 public IAutoEditorNotifyListener
32 int32
GetPluginVersion() override
{ return 1; }
33 const char* GetPluginName() override
{ return "CSharp Editor"; }
34 const char* GetPluginDescription() override
{ return "CSharp Editor plugin"; }
37 CCSharpEditorPlugin();
38 virtual ~CCSharpEditorPlugin();
40 virtual void RegisterMessageListener(ICSharpMessageListener
* pListener
) { m_messageListeners
.Add(pListener
); }
41 virtual void UnregisterMessageListener(ICSharpMessageListener
* pListener
) { m_messageListeners
.Remove(pListener
); }
42 virtual string
GetCompileMessage() { return m_compileMessage
; }
44 // Returns the path to the C# solution file.
45 const char* GetCSharpSolutionPath() const { return m_csharpSolutionPath
; };
47 // Opens the specified file in the editor that's set in the preferences.
48 bool OpenCSharpFile(const string
& filePath
);
49 // Opens the specified file at the specified line in the editor that's set in the preferences.
50 bool OpenCSharpFile(const string
& filePath
, const int line
);
52 // Opens the CompiledMonoLibrary solution in the text editor specified in the File Preferences. Returns false if the file couldn't be opened.
53 bool OpenCSharpSolution();
55 // IFileChangeListener
56 virtual void OnFileChange(const char* sFilename
, EChangeType eType
) override
;
57 // ~IFileChangeListener
59 // IMonoCompileListener
60 virtual void OnCompileFinished(const char* szCompileMessage
) override
;
61 // ~IMonoCompileListener
63 // Schematyc::IEnvRegistryListener
64 virtual void OnEnvElementAdd(Schematyc::IEnvElementPtr pElement
) override
;
65 virtual void OnEnvElementDelete(Schematyc::IEnvElementPtr pElement
) override
;
66 // ~Schematyc::IEnvRegistryListener
68 // ISystemEventListener
69 virtual void OnSystemEvent(ESystemEvent event
, UINT_PTR wparam
, UINT_PTR lparam
) override
;
70 // ~ISystemEventListener
72 // IAutoEditorNotifyListener
73 virtual void OnEditorNotifyEvent(EEditorNotifyEvent aEventId
) override
;
74 // ~IAutoEditorNotifyListener
76 static CCSharpEditorPlugin
* GetInstance() { return s_pInstance
; }
79 bool m_initialized
= false;
80 HANDLE m_textEditorHandle
;
81 string m_createdTextEditor
;
82 std::vector
<string
> m_changedFiles
;
83 bool m_reloadPlugins
= false;
84 bool m_isSandboxInFocus
= true;
85 string m_compileMessage
;
86 CSharpMessageListeners m_messageListeners
;
87 string m_csharpSolutionPath
;
89 // Checks the machine for an installation of VS2017+, and sets this as the default text editor.
90 void SetDefaultTextEditor();
91 // Updates the plugins and solutions if required.
92 void UpdatePluginsAndSolution();
93 // Reloads the managed plugings.
94 void ReloadPlugins() const;
95 // Regenerates the .sln and .csproj files of the Sandbox C# files.
96 void RegenerateSolution() const;
97 // Find files with a specific extension in a folder recursively.
98 void FindSourceFilesInDirectoryRecursive(const char* szDirectory
, const char* szExtension
, std::vector
<string
>& sourceFiles
) const;
99 // Checks if m_textEditorHandle refers to a valid application, and focuses the window if it does.
100 bool HasExistingTextEditor() const;
101 // Opens the specified file in the C# solution based. Returns false if the file couldn't be opened.
102 bool OpenFileInSolution(const string
& filePath
);
103 // Opens the specified file on a specific line in the C# solution. Returns false if the file couldn't be opened.
104 bool OpenFileInSolution(const string
& filePath
, const int line
);
105 // Opens the specified file in the text editor specified in the File Preferences. Returns false if the file couldn't be opened.
106 bool OpenFileInTextEditor(const string
& filePath
) const;
107 // Opens the specified file on a specific line in the text editor specified in the File Preferences. Returns false if the file couldn't be opened.
108 bool OpenFileInTextEditor(const string
& filePath
, const int line
) const;
109 // Opens the specified file by Windows association. If that fails it will try to open it in Notepad instead.
110 bool OpenCSharpFileSafe(const string
& filePath
) const;
113 static CCSharpEditorPlugin
* s_pInstance
;