File: php_editor_context_menu.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 (131 lines) | stat: -rw-r--r-- 4,810 bytes parent folder | download | duplicates (6)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// Copyright            : (C) 2015 Eran Ifrah
// File name            : php_editor_context_menu.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 PHPEDITORCONTEXTMENU_H
#define PHPEDITORCONTEXTMENU_H

#include <ieditor.h>
#include <wx/event.h>
#include "cl_command_event.h"

enum PhpEditorEventIds {
    wxID_OPEN_PHP_FILE = 10105,
    wxID_GOTO_DEFINITION = 10108,
    wxID_FIND_REFERENCES = 10109,
    wxID_ADD_DOXY_COMMENT = 10110,
    wxID_GENERATE_GETTERS_SETTERS = 10111,
};

// Check values macros
#define SET_CARET_POS(caret_pos)                 \
    {                                            \
        sci->SetSelection(caret_pos, caret_pos); \
        sci->ChooseCaretX();                     \
    }

class IManager;
class PhpPlugin;
class PHPEditorContextMenu : public wxEvtHandler
{
    friend class PhpPlugin;
    static PHPEditorContextMenu* ms_instance;
    wxString m_selectedWord;
    IManager* m_manager;
    wxString m_comment_line_1;
    wxString m_comment_line_2;
    wxString m_start_comment;
    wxString m_close_comment;

protected:
    // Helpers
    void DoContextMenu(IEditor* editor, wxCommandEvent& e);
    wxStyledTextCtrl* DoGetActiveScintila();

protected:
    // Event handlers
    void OnContextMenu(clContextMenuEvent& e);
    void OnMarginContextMenu(clContextMenuEvent& e);
    void OnContextOpenDocument(wxCommandEvent& event);
    void OnPopupClicked(wxCommandEvent& event);

    // Helpers
    void DoOpenPHPFile();
    void DoGotoBeginningOfScope();
    void DoGotoEndOfScope();
    void DoGotoDefinition();
    void OnInsertDoxyComment(wxCommandEvent& e);
    void OnGenerateSettersGetters(wxCommandEvent& e);

public:
    static PHPEditorContextMenu* Instance();
    static void Release();
    void ConnectEvents();

    void SetManager(IManager* manager) { this->m_manager = manager; }

    bool IsPHPSection(int styleAtPos) const;
    bool IsPHPCommentOrString(int styleAtPos) const;

private:
    PHPEditorContextMenu();
    virtual ~PHPEditorContextMenu();
    
    void OnCommentSelection(wxCommandEvent &event);
    void OnCommentLine(wxCommandEvent &event);
    
    void DoBuildMenu(wxMenu* menu, IEditor* editor);
    bool IsIncludeOrRequireStatement(wxString& includeWhat);
    bool GetIncludeOrRequireFileName(wxString& fn);
    bool IsLineMarked(); // does a bookmark exist in the current lines
    int
    RemoveComment(wxStyledTextCtrl* sci, int posFrom, const wxString& value); // return the number of characters removed
    void CommentSingleLine(wxStyledTextCtrl* sci, int style, int line_number, int& caret_pos);
    bool RemoveSingleLineComment(wxStyledTextCtrl* sci, int& caret_pos);
    bool RemoveTokenFirstIteration(wxStyledTextCtrl* sci, const wxString& token, bool direction, int& caret_pos);
    int GetTokenPosInScope(wxStyledTextCtrl* sci,
                           const wxString& token,
                           int start_pos,
                           int end_pos,
                           bool direction,
                           const wxArrayString& tokensBlackList);
    bool IsTokenInBlackList(wxStyledTextCtrl* sci,
                            const wxString& token,
                            int token_pos,
                            const wxArrayString& tokensBlackList);
};

#define GET_EDITOR_SCI_BOOL()                       \
    IEditor* editor = m_manager->GetActiveEditor(); \
    if(!editor) return false;                       \
    wxStyledTextCtrl* sci = editor->GetCtrl();       \
    if(!sci) return false;

#define GET_EDITOR_SCI_VOID()                       \
    IEditor* editor = m_manager->GetActiveEditor(); \
    if(!editor) return;                             \
    wxStyledTextCtrl* sci = editor->GetCtrl();       \
    if(!sci) return;

#endif // PHPEDITORCONTEXTMENU_H