itom
Loading...
Searching...
No Matches
pyGotoAssignment.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21
22 Further hints:
23 ------------------------
24
25 This file belongs to the code editor of itom. The code editor is
26 in major parts a fork / rewritten version of the python-based source
27 code editor PyQode from Colin Duquesnoy and others
28 (see https://github.com/pyQode). PyQode itself is licensed under
29 the MIT License (MIT).
30
31 Some parts of the code editor of itom are also inspired by the
32 source code editor of the Spyder IDE (https://github.com/spyder-ide),
33 also licensed under the MIT License and developed by the Spyder Project
34 Contributors.
35
36*********************************************************************** */
37
38#ifndef PYGOTOASSIGNMENT_H
39#define PYGOTOASSIGNMENT_H
40
41/*
42Contains the go to assignments mode.
43*/
44
45#include "wordclick.h"
46
47#include "../../python/pythonJedi.h"
48
49namespace ito {
50
51//-----------------------------------------------------------
52/*
53Defines an assignment. Used by :class:`PyGotoAssignmentsMode`.
54*/
56{
57 PyAssignment() :
58 m_line(-1),
59 m_column(-1)
60 {
61 }
62
63 PyAssignment(const QString &path, int line, int column, const QString &fullName) :
64 m_line(line),
65 m_column(column),
66 m_fullName(fullName)
67 {
68 m_modulePath = path;
69 m_modulePath.replace(".pyc", ".py");
70 }
71
72 bool operator==(const PyAssignment &rhs) const
73 {
74 return (m_modulePath == rhs.m_modulePath) && \
75 (m_line == rhs.m_line) && \
76 (m_column == rhs.m_column) && \
77 (m_fullName == rhs.m_fullName);
78 }
79
80 QString m_modulePath; // File path of the module where the assignment can be found
81 int m_line; //line number
82 int m_column; //column number
83 QString m_fullName; //assignment full name
84};
85
86/*
87Goes to the assignments (using jedi.Script.goto_assignments) when the user
88execute the shortcut or click word. If there are more than one assignments,
89an input dialog is used to ask the user to choose the desired assignment.
90
91This mode will emit the :attr:`out_of_doc` signal if the definition can
92not be reached in the current document. IDE will typically connects a slot
93that open a new editor tab and goes to the definition position.
94*/
96{
97 Q_OBJECT
98public:
99 PyGotoAssignmentMode(const QString &description = "", QObject *parent = NULL);
100 virtual ~PyGotoAssignmentMode();
101
102 virtual void onStateChanged(bool state);
103
104 void setDefaultWordClickMode(int mode) { m_defaultMode = mode; }
105 int defaultWordClickMode() const { return m_defaultMode; }
106
107 bool mouseClickEnabled() const { return m_mouseClickEnabled; }
108 void setMouseClickEnabled(bool enabled);
109
110 virtual QList<QAction*> actions() const;
111
112protected:
113 void doGoto(const PyAssignment &assignment);
114 virtual void checkWordCursor(const QTextCursor &cursor);
115 void checkWordCursorWithMode(const QTextCursor &cursor, int mode);
116 QList<PyAssignment> unique(const QList<PyAssignment> &assignments) const;
117 virtual void clearSelection();
118 void performGoto(const QList<PyAssignment> &assignments);
119
120 void timerEvent(QTimerEvent *event) override;
121
122private:
123 QObject *m_pPythonEngine;
124 bool m_gotoRequested;
125 int m_gotoRequestedTimerId;
126 static const int gotoRequestedTimeoutMs = 3000;
127
128 QList<PyAssignment> m_assignments;
129 QAction *m_pActionGotoDefinition;
130 QAction *m_pActionGotoAssignment;
131 QAction *m_pActionGotoAssignmentExtended;
132 int m_defaultMode; //mode, if word is clicked: 0: goto definition, 1: goto assignment (no follow imports), 2: goto assignment (follow imports)
133 bool m_mouseClickEnabled;
134
135private slots:
136 void requestGotoDefinition();
137 void requestGotoAssignment();
138 void requestGotoAssignmentEx();
139 void onJediAssignmentResultsAvailable(QVector<ito::JediAssignment> assignments);
140 void onWordClicked(const QTextCursor &cursor) { performGoto(m_assignments); }
141 void onKeyReleasedGoto(QKeyEvent *e);
142
143
144signals:
145 void outOfDoc(PyAssignment assignment); //Signal emitted when the definition cannot be reached in the current document
146 void noResultsFound(); //Signal emitted when no results could be found.
147
148
149};
150
151} //end namespace ito
152
153#endif
Definition pyGotoAssignment.h:96
Definition wordclick.h:72
Definition apiFunctionsGraph.cpp:40
Definition pyGotoAssignment.h:56