File: codeformatter.h

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (113 lines) | stat: -rw-r--r-- 4,681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : codeformatter.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifndef CODEFORMATTER_H
#define CODEFORMATTER_H

#include "cl_command_event.h"
#include "fileextmanager.h"
#include "formatoptions.h"
#include "plugin.h"

enum FormatterEngine {
    kFormatEngineNone,
    kFormatEngineAStyle,
    kFormatEngineClangFormat,
    kFormatEngineBuildInPhp,
    kFormatEnginePhpCsFixer,
    kFormatEnginePhpcbf,
    kFormatEngineWxXmlDocument,
};

class CodeFormatter : public IPlugin
{
    static FormatOptions m_options;
    PhpOptions m_optionsPhp;

protected:
    wxString m_selectedFolder;

    int DoGetGlobalEOL() const;
    wxString DoGetGlobalEOLString() const;

private:
    void DoFormatFile(const wxFileName& fileName, const FormatterEngine& engine);
    void DoFormatFileAsString(const wxFileName& fileName, const FormatterEngine& engine);
    void DoFormatString(wxString& content, const wxFileName& fileName, const FormatterEngine& engine,
                        int& cursorPosition);
    void DoFormatSelection(IEditor* editor, wxString& content, const FormatterEngine& engine, int& cursorPosition,
                           const int& selStart, const int& selEnd);
    void DoFormatEditor(IEditor* editor, int selStart = wxNOT_FOUND, int selEnd = wxNOT_FOUND);
    void DoFormatWithTempFile(const wxFileName& fileName, wxString& content, const FormatterEngine& engine);
    void OverwriteEditorText(IEditor*& editor, const wxString& content, const int& cursorPosition = 0,
                             const int& selStart = wxNOT_FOUND, const int& selEnd = wxNOT_FOUND);
    static FormatterEngine FindFormatter(const wxFileName& fileName);
    bool CanFormatSelection(const FormatterEngine& engine);
    bool CanFormatString(const FormatterEngine& engine);
    bool CanFormatFile(const FormatterEngine& engine);

    void DoFormatWithPhpcbf(const wxFileName& fileName);
    void DoFormatWithBuildInPhp(wxString& content);
    void DoFormatWithPhpCsFixer(const wxFileName& fileName);
    void DoFormatWithClang(const wxFileName& fileName);
    void DoFormatWithClang(wxString& content, const wxFileName& fileName, int& cursorPosition,
                           const int& selStart = wxNOT_FOUND, const int& selEnd = wxNOT_FOUND);
    void DoFormatWithAstyle(wxString& content, const bool& appendEOL = true);
    void DoFormatWithWxXmlDocument(const wxFileName& fileName);

    void OnPhpSettingsChanged(clCommandEvent& event);
    void OnScanFilesCompleted(const std::vector<wxFileName>& files);

public:
    wxString RunCommand(const wxString& command);

    /**
     * @brief format list of files
     */
    void BatchFormat(const std::vector<wxFileName>& files, bool silent = true);
    void OnContextMenu(clContextMenuEvent& event);

    CodeFormatter(IManager* manager);
    virtual ~CodeFormatter();
    virtual void CreateToolBar(clToolBar* toolbar);
    virtual void CreatePluginMenu(wxMenu* pluginsMenu);
    virtual void HookPopupMenu(wxMenu* menu, MenuType type);
    virtual void UnPlug();

    IManager* GetManager();
    // event handlers
    void OnFormat(wxCommandEvent& e);
    void OnFormatOptions(wxCommandEvent& e);
    void OnFormatUI(wxUpdateUIEvent& e);
    void OnFormatOptionsUI(wxUpdateUIEvent& e);
    void DoFormatPreview(wxString& content, const wxString& ext, const FormatterEngine& engine);

    void OnFormatString(clSourceFormatEvent& e);
    void OnFormatFile(clSourceFormatEvent& e);
    void OnFormatFiles(wxCommandEvent& e);
    void OnFormatProject(wxCommandEvent& e);
    void OnBeforeFileSave(clCommandEvent& e);
};

#endif // CODEFORMATTER_H