1 /***************************************************************
2  * Name:      fortranproject
3  * Purpose:   Code::Blocks plugin
4  * Author:    Darius Markauskas, darmar.lt@gmail.com (code based on Code-completion plugin)
5  * Created:   2009-07-11
6  * Copyright:
7  * License:   GPL
8  **************************************************************/
9 
10 #ifndef FORTRANPROJECT_H_INCLUDED
11 #define FORTRANPROJECT_H_INCLUDED
12 
13 #include <sdk.h>
14 #ifndef CB_PRECOMP
15     #include <wx/timer.h>
16 
17     #include <cbplugin.h> // for "class cbToolPlugin"
18     #include <loggers.h>
19 #endif
20 #include <list>
21 #include <map>
22 
23 #include "nativeparserf.h"
24 #include "keywordsparserf.h"
25 #include "finfowindow.h"
26 #include "lineaddress.h"
27 #include "autoinsert.h"
28 #include "constrhighlighter.h"
29 #include "calltree.h"
30 
31 enum DocsShowOptions
32 {
33     dsoAlways,
34     dsoOnly,
35     dsoNot
36 };
37 
38 
39 class FortranProject : public cbCodeCompletionPlugin
40 {
41     public:
42 
43         FortranProject();
44         ~FortranProject();
45 
46         virtual void OnAttach();
47         virtual void OnRelease(bool appShutDown);
48 
49         void OnUpdateUI(wxUpdateUIEvent& event);
50         void OnUpdateUICallTree(wxUpdateUIEvent& event);
51         void BuildMenu(wxMenuBar* menuBar);
52         virtual void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0);
53         void OnViewWorkspaceBrowser(wxCommandEvent& event);
54         virtual bool BuildToolBar(wxToolBar* toolBar);
55         void ShowCallTipEvt(CodeBlocksEvent& event);
56         void MakeCompleteCode();
57 
58 
59         void EditorEventHook(cbEditor* editor, wxScintillaEvent& event);
60 
GetConfigurationGroup()61         virtual int GetConfigurationGroup() const { return cgEditor; }
62         void ShowInfoLog(TokensArrayFlat* result, bool isAfterPercent);
63         cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent);
64         cbConfigurationPanel* GetProjectConfigurationPanel(wxWindow* parent, cbProject* project);
65         void OnProjectLoadingHook(cbProject* prj, TiXmlElement* elem, bool loading);
66         void RereadOptions();
67         void CheckEnableToolbar();
68         bool GotoToken(TokenFlat* pToken, cbEditor* cured);
69         void ShowCallTree(bool showCallTree);
70 
71         // override
72         virtual CCProviderStatus GetProviderStatusFor(cbEditor* ed);
73         virtual std::vector<CCToken> GetAutocompList(bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd);
74         virtual void DoAutocomplete(const CCToken& token, cbEditor* ed);
75         virtual wxString GetDocumentation(const CCToken& token);
76         virtual std::vector<CCCallTip> GetCallTips(int pos, int style, cbEditor* ed, int& argsPos);
77         virtual std::vector<CCToken> GetTokenAt(int pos, cbEditor* ed, bool& allowCallTip);
78         virtual wxString OnDocumentationLink(wxHtmlLinkEvent& event, bool& dismissPopup);
79 
80     private:
81 
82         void OnAppDoneStartup(CodeBlocksEvent& event);
83         void OnWorkspaceChanged(CodeBlocksEvent& event);
84         void OnProjectActivated(CodeBlocksEvent& event);
85         void OnProjectClosed(CodeBlocksEvent& event);
86         void OnProjectSaved(CodeBlocksEvent& event);
87         void OnProjectFileAdded(CodeBlocksEvent& event);
88         void OnProjectFileRemoved(CodeBlocksEvent& event);
89         void OnCompilerStarted(CodeBlocksEvent& event);
90         void OnCleanProjectStarted(CodeBlocksEvent& event);
91         void OnCleanWorkspaceStarted(CodeBlocksEvent& event);
92         void OnGotoDeclaration(wxCommandEvent& event);
93         void OnEditorSave(CodeBlocksEvent& event);
94         void OnEditorActivated(CodeBlocksEvent& event);
95         void OnEditorDeactivated(CodeBlocksEvent& event);
96         void OnEditorClose(CodeBlocksEvent& event);
97         void OnReparseEditorTimer(wxTimerEvent& event);
98         void CodeCompletePreprocessor(int tknStart, int tknEnd, cbEditor* ed, std::vector<CCToken>& tokens);
99         void DoCodeComplete(int caretPos, cbEditor* ed, std::vector<CCToken>& tokens);
100         void CodeComplete(const int pos, cbEditor* ed, std::vector<CCToken>& tokens);
101         void OnValueTooltip(CodeBlocksEvent& event);
102         void WriteToLog(const wxString& text);
103         void CreateLogWindow();
104         void RemoveLogWindow(bool appShutDown);
105         void OnJumpBack(wxCommandEvent& event);
106         void OnJumpHome(wxCommandEvent& event);
107         void OnJumpForward(wxCommandEvent& event);
108         void JumpToLine(const LineAddress& adr);
109         wxString GetIncludeFilename(cbStyledTextCtrl* control);
110         void OnMenuEditPaste(wxCommandEvent& event);
111 
112         void OnDebuggerStarted(CodeBlocksEvent& event);
113         void OnDebuggerFinished(CodeBlocksEvent& event);
114         bool m_IsDebugging;
115 
116         void OnGenerateMakefile(wxCommandEvent& event);
117         void OnChangeCase(wxCommandEvent& event);
118         void OnTab2Space(wxCommandEvent& event);
119         void OnBindTo(wxCommandEvent& event);
120         void OnFormatIndent(wxCommandEvent& event);
121         void OnShowCallTreeView(wxCommandEvent& event);
122         void OnShowCallTree(wxCommandEvent& event);
123         void OnShowCalledByTree(wxCommandEvent& event);
124         void LoadFortranKeywordImages();
125         wxBitmap GetFortranKeywordImage(int height);
126 
127         bool m_InitDone;
128 
129         NativeParserF* m_pNativeParser;
130         CallTree* m_pCallTree;
131 
132         int                                m_ProjectLoadingHookID;
133         int                                m_EditorHookId;
134         int                                m_LastPosForCodeCompletion;
135         wxTimer                            m_TimerCodeCompletion;
136         cbEditor*                          m_pCodeCompletionLastEditor;
137         wxMenu*                            m_ViewMenu;
138         wxMenu*                            m_FortranToolsMenu;
139 
140         wxToolBar*                         m_pToolbar;
141 
142         bool                               m_ShowedCallTip;
143 
144         bool                               m_WasCallTipActive;
145 
146         bool                               m_IsAutoPopup;
147         int                                m_ActiveCalltipsNest;
148         int                                m_ActiveCalltipsPosition;
149         int                                m_CurrentLine;
150         bool                               m_LexerKeywordsToInclude[9];
151         bool                               m_UseSmartCC;
152         size_t                             m_MaxMatch;
153 
154         bool                               m_LogUseWindow;
155         bool                               m_LogComAbove;
156         bool                               m_LogComBelow;
157         bool                               m_LogDeclar;
158         bool                               m_LogComVariab;
159         bool                               m_LogOnlyUseAssoc;
160         bool                               m_LogOnlyPublicNames;
161         bool                               m_LogShowTypeVariables;
162 
163         DocsShowOptions                    m_DocsShowOption;
164 
165         bool                               m_AutoInsertEnabled;
166         AutoInsert                         m_AutoInsert;
167 
168         ConstrHighlighter                  m_ConstrHighlighter;
169 
170         FInfoWindow*                       m_pFortranLog;
171 
172         KeywordsParserF*                   m_pKeywordsParser;
173         wxString                           m_LastCallTipName;
174         bool                               m_WasCallTipInfoLog;
175 
176         std::map<wxString,int>             m_IdxCallTipPage;
177         wxTimer                            m_TimerReparseEditor;
178 
179         TokensArrayFlatClass               m_TokensCCList;
180         std::map<int,wxBitmap>             m_FKImages;
181 
182         DECLARE_EVENT_TABLE()
183 };
184 
185 #endif // FORTRANPROJECT_H
186 
187