WSF
AutoCompletePopup.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef AUTOCOMPLETEPOPUP_HPP
13#define AUTOCOMPLETEPOPUP_HPP
14
15#include <string>
16#include <vector>
17
18#include <QListWidget>
19#include <QTimer>
20#include <QWidget>
21
22#include "UtCallback.hpp"
23#include "UtCallbackHolder.hpp"
24#include "UtTextDocument.hpp"
25#include "WsfScriptLookup.hpp"
26class WsfParseNode;
27class WsfParseCommandReader;
29class WsfParseRule;
30class UsSymbol;
31class QListWidget;
32class QKeyEvent;
33class UtTextDocumentRange;
34class QLabel;
35
36namespace wizard
37{
38class BrowserWidget;
39class TextSource;
40class WsfEditor;
41class WsfScriptLookup;
42class WsfTextPreview;
43
45class AutoCompletePopup : public QWidget
46{
47 Q_OBJECT
48
49public:
50 class SuggestionList : public QListWidget
51 {
52 public:
53 explicit SuggestionList(AutoCompletePopup* aParentPtr)
54 : QListWidget(aParentPtr)
55 , mParentPtr(aParentPtr)
56 {
57 QObject::connect(this, &SuggestionList::itemDoubleClicked, this, &SuggestionList::OnItemDoubleClick);
58 }
59 void keyPressEvent(QKeyEvent* event) override;
60 bool InterceptKeyDown(QKeyEvent* aEventPtr);
61 void SetCurrentRow(int aRow, int aSearchDiration);
62 void OnItemDoubleClick(QListWidgetItem* aItem);
64 };
65 friend class SuggestionList;
66 AutoCompletePopup(QWidget* aParentPtr, WsfEditor* aEditControlPtr);
67 ~AutoCompletePopup() override;
68
69 void CursorMove(int aX, int aY, int aLineHeight);
70 void UpdateAutocomplete(size_t aCursorLine, size_t aCursorColumn);
71
72 bool InterceptKeyDown(QKeyEvent* aEventPtr);
73 bool HasFocus();
75
76protected:
77 void paintEvent(QPaintEvent*) override;
78
79private:
80 void DocLinkClicked(const QUrl& aUrl);
81 void LinkActivated(const QString& link);
82
83 bool UpdateScriptSymbols();
84 WsfTextPreview* GetPreview();
85 BrowserWidget* GetDocumentationView();
86 void ClearDocumentationView();
87 enum ContextType
88 {
89 cNONE,
90 cWSF,
91 cWSF_SCRIPT
92 };
93 void ItemClicked(QListWidgetItem* aItemPtr);
94 std::string GetLineText(UtTextDocumentRange& aRange);
95 bool InsertSelection(QListWidgetItem* aItemPtr = nullptr);
96 void UpdateAutocompleteWSF();
97
98 bool UpdateAutocompleteScript();
99
100 void UpdateSize();
101 bool FilterAutoCompleteList();
102
103 void CurrentSuggestionChanged(QListWidgetItem* current, QListWidgetItem* previous);
104 void SelectedItem(QListWidgetItem* aItemPtr);
105 bool ScriptMode() { return mContextType == cWSF_SCRIPT; }
106
107 bool CharCompare(char a, char b) const;
108 int GetSymbolMatchScore(const std::string& aInput, const std::string& aSymbol) const;
109
110 ContextType mContextType;
111 bool mNeedsUpdated;
112 size_t mCursorLine;
113 size_t mCursorColumn;
114 UtTextDocumentRange mReplaceRange;
115 WsfEditor* mEditControlPtr;
116 UtCallbackHolder mCallbacks;
117 SuggestionList* mSuggestionListPtr;
118
119 QWidget* mDetailPane;
120 QLabel* mDetailHeader;
121 BrowserWidget* mDetailDocumentation;
122 WsfTextPreview* mDetailPreview;
123 QLabel* mDetailFooter;
124
125 size_t mInsertPosition;
126 size_t mReplaceCharacters;
127 bool mSuggestionIsLastToken;
128 bool mSuggestionIsPartialToken;
129
130 int mCursorX;
131 int mCursorY;
132 int mLineHeight;
133 QSize mCurrentSize;
134
135 size_t mPreviousCommandPosition;
136 bool mNeedsNewSuggestionList;
137 std::vector<std::string> mCurrentSuggestions;
138 UtCallbackN<void()>* mUpdateCallbackPtr;
139
140 WsfScriptLookup* mScriptLookupPtr;
141 WsfScriptLookup::SymbolMap mScriptSymbols;
142 bool mShowScriptTypes;
143};
144} // namespace wizard
145#endif
Definition UsSymbolTable.hpp:281
Definition WsfParseAlternate.hpp:22
Definition WsfParseNode.hpp:61
Definition WsfParseRule.hpp:131
Definition AutoCompletePopup.hpp:51
SuggestionList(AutoCompletePopup *aParentPtr)
Definition AutoCompletePopup.hpp:53
AutoCompletePopup * mParentPtr
Definition AutoCompletePopup.hpp:63
bool InterceptKeyDown(QKeyEvent *aEventPtr)
Definition AutoCompletePopup.cpp:331
void OnItemDoubleClick(QListWidgetItem *aItem)
Definition AutoCompletePopup.cpp:504
void SetCurrentRow(int aRow, int aSearchDiration)
Definition AutoCompletePopup.cpp:472
void keyPressEvent(QKeyEvent *event) override
Definition AutoCompletePopup.cpp:460
bool InterceptKeyDown(QKeyEvent *aEventPtr)
Definition AutoCompletePopup.cpp:326
AutoCompletePopup(QWidget *aParentPtr, WsfEditor *aEditControlPtr)
Definition AutoCompletePopup.cpp:52
bool HasFocus()
Definition AutoCompletePopup.cpp:588
void UpdateAutocomplete(size_t aCursorLine, size_t aCursorColumn)
Definition AutoCompletePopup.cpp:164
void CursorMove(int aX, int aY, int aLineHeight)
Definition AutoCompletePopup.cpp:116
~AutoCompletePopup() override
Definition AutoCompletePopup.cpp:110
friend class SuggestionList
Definition AutoCompletePopup.hpp:65
void UpdateWindowPosition()
Definition AutoCompletePopup.cpp:133
void paintEvent(QPaintEvent *) override
Definition AutoCompletePopup.cpp:617
Definition BrowserWidget.hpp:26
Definition TextSource.hpp:48
Definition WsfEditor.hpp:32
Definition WsfScriptLookup.hpp:28
std::map< std::string, UsValRef > SymbolMap
Definition WsfScriptLookup.hpp:65
Displays a syntax-highlighted snippet of an WSF file.
Definition WsfTextPreview.hpp:28
Definition Runner.hpp:22
Copyrights Multiple, All Rights Reserved