diff --git a/NEWS.md b/NEWS.md index a8173f59..f241cd3a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,5 @@ Version 0.2 + - enhancement: class browser syntax colors and icons - enhancement: function tips - enhancement: project support - enhancement: paint color editor use system palette's disabled group color diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index bfcec8e7..af2ef766 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -460,7 +460,7 @@ void Editor::focusOutEvent(QFocusEvent *event) this, &SynEdit::invalidate); } - pMainWindow->updateClassBrowserForEditor(nullptr); + //pMainWindow->updateClassBrowserForEditor(nullptr); pMainWindow->updateEditorActions(); pMainWindow->updateStatusbarForLineCol(); pMainWindow->updateForStatusbarModeInfo(); diff --git a/RedPandaIDE/icons.qrc b/RedPandaIDE/icons.qrc index 1ec686ec..7cfe07e6 100644 --- a/RedPandaIDE/icons.qrc +++ b/RedPandaIDE/icons.qrc @@ -467,5 +467,24 @@ images/associations/obj.ico images/associations/rc.ico images/associations/template.ico + images/classparser/class.ico + images/classparser/define.ico + images/classparser/enum.ico + images/classparser/global.ico + images/classparser/global_method.ico + images/classparser/method_inherited.ico + images/classparser/method_inherited_protected.ico + images/classparser/method_private.ico + images/classparser/method_protected.ico + images/classparser/method_public.ico + images/classparser/namespace.ico + images/classparser/static_method.ico + images/classparser/static_var.ico + images/classparser/type.ico + images/classparser/var_inherited.ico + images/classparser/var_inherited_protected.ico + images/classparser/var_private.ico + images/classparser/var_protected.ico + images/classparser/var_public.ico diff --git a/RedPandaIDE/images/classparser/class.ico b/RedPandaIDE/images/classparser/class.ico new file mode 100644 index 00000000..80330bc5 Binary files /dev/null and b/RedPandaIDE/images/classparser/class.ico differ diff --git a/RedPandaIDE/images/classparser/define.ico b/RedPandaIDE/images/classparser/define.ico new file mode 100644 index 00000000..c2cb1a39 Binary files /dev/null and b/RedPandaIDE/images/classparser/define.ico differ diff --git a/RedPandaIDE/images/classparser/enum.ico b/RedPandaIDE/images/classparser/enum.ico new file mode 100644 index 00000000..787304a2 Binary files /dev/null and b/RedPandaIDE/images/classparser/enum.ico differ diff --git a/RedPandaIDE/images/classparser/global.ico b/RedPandaIDE/images/classparser/global.ico new file mode 100644 index 00000000..a022a8b1 Binary files /dev/null and b/RedPandaIDE/images/classparser/global.ico differ diff --git a/RedPandaIDE/images/classparser/global_method.ico b/RedPandaIDE/images/classparser/global_method.ico new file mode 100644 index 00000000..2e0c9810 Binary files /dev/null and b/RedPandaIDE/images/classparser/global_method.ico differ diff --git a/RedPandaIDE/images/classparser/method_inherited.ico b/RedPandaIDE/images/classparser/method_inherited.ico new file mode 100644 index 00000000..4b66e7e8 Binary files /dev/null and b/RedPandaIDE/images/classparser/method_inherited.ico differ diff --git a/RedPandaIDE/images/classparser/method_inherited_protected.ico b/RedPandaIDE/images/classparser/method_inherited_protected.ico new file mode 100644 index 00000000..0f13e596 Binary files /dev/null and b/RedPandaIDE/images/classparser/method_inherited_protected.ico differ diff --git a/RedPandaIDE/images/classparser/method_private.ico b/RedPandaIDE/images/classparser/method_private.ico new file mode 100644 index 00000000..2ad4e68e Binary files /dev/null and b/RedPandaIDE/images/classparser/method_private.ico differ diff --git a/RedPandaIDE/images/classparser/method_protected.ico b/RedPandaIDE/images/classparser/method_protected.ico new file mode 100644 index 00000000..99b41501 Binary files /dev/null and b/RedPandaIDE/images/classparser/method_protected.ico differ diff --git a/RedPandaIDE/images/classparser/method_public.ico b/RedPandaIDE/images/classparser/method_public.ico new file mode 100644 index 00000000..ec1abece Binary files /dev/null and b/RedPandaIDE/images/classparser/method_public.ico differ diff --git a/RedPandaIDE/images/classparser/namespace.ico b/RedPandaIDE/images/classparser/namespace.ico new file mode 100644 index 00000000..d9871377 Binary files /dev/null and b/RedPandaIDE/images/classparser/namespace.ico differ diff --git a/RedPandaIDE/images/classparser/static_method.ico b/RedPandaIDE/images/classparser/static_method.ico new file mode 100644 index 00000000..424120c1 Binary files /dev/null and b/RedPandaIDE/images/classparser/static_method.ico differ diff --git a/RedPandaIDE/images/classparser/static_var.ico b/RedPandaIDE/images/classparser/static_var.ico new file mode 100644 index 00000000..7abb3aa0 Binary files /dev/null and b/RedPandaIDE/images/classparser/static_var.ico differ diff --git a/RedPandaIDE/images/classparser/type.ico b/RedPandaIDE/images/classparser/type.ico new file mode 100644 index 00000000..196a4683 Binary files /dev/null and b/RedPandaIDE/images/classparser/type.ico differ diff --git a/RedPandaIDE/images/classparser/var_inherited.ico b/RedPandaIDE/images/classparser/var_inherited.ico new file mode 100644 index 00000000..f26e5f21 Binary files /dev/null and b/RedPandaIDE/images/classparser/var_inherited.ico differ diff --git a/RedPandaIDE/images/classparser/var_inherited_protected.ico b/RedPandaIDE/images/classparser/var_inherited_protected.ico new file mode 100644 index 00000000..c152ff31 Binary files /dev/null and b/RedPandaIDE/images/classparser/var_inherited_protected.ico differ diff --git a/RedPandaIDE/images/classparser/var_private.ico b/RedPandaIDE/images/classparser/var_private.ico new file mode 100644 index 00000000..99822feb Binary files /dev/null and b/RedPandaIDE/images/classparser/var_private.ico differ diff --git a/RedPandaIDE/images/classparser/var_protected.ico b/RedPandaIDE/images/classparser/var_protected.ico new file mode 100644 index 00000000..180aefdf Binary files /dev/null and b/RedPandaIDE/images/classparser/var_protected.ico differ diff --git a/RedPandaIDE/images/classparser/var_public.ico b/RedPandaIDE/images/classparser/var_public.ico new file mode 100644 index 00000000..ea8e157d Binary files /dev/null and b/RedPandaIDE/images/classparser/var_public.ico differ diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 7cb66e67..d81036a4 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1628,6 +1628,19 @@ void MainWindow::buildContextMenus() mProject->removeFolder(folderNode); mProject->saveOptions(); }); + + //context menu signal for class browser + ui->classBrowser->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->classBrowser,&QWidget::customContextMenuRequested, + this, &MainWindow::onClassBrowserContextMenu); + mClassBrowser_Sort_By_Type = createActionFor( + tr("Sort By Type"), + ui->classBrowser); + mClassBrowser_Sort_By_Type->setIcon(QIcon(":/icons/images/newlook24/077-sort-type.png")); + QAction * mClassBrowser_Sort_By_Name; + QAction * mClassBrowser_Show_Inheritance; + QAction * mClassBrowser_goto_declaration; + QAction * mClassBrowser_goto_definition; } void MainWindow::maximizeEditor() @@ -3433,3 +3446,9 @@ const std::shared_ptr > &MainWindow::statementColor return mStatementColors; } + +void MainWindow::on_classBrowser_doubleClicked(const QModelIndex &index) +{ + +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index d11c6e77..440624b9 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -339,6 +339,8 @@ private slots: void on_actionProject_Open_In_Terminal_triggered(); + void on_classBrowser_doubleClicked(const QModelIndex &index); + private: Ui::MainWindow *ui; EditorList *mEditorList; @@ -409,6 +411,12 @@ private: QAction * mProject_Rename_Folder; QAction * mProject_Remove_Folder; + //actions for class browser + QAction * mClassBrowser_Sort_By_Type; + QAction * mClassBrowser_Sort_By_Name; + QAction * mClassBrowser_Show_Inheritance; + QAction * mClassBrowser_goto_declaration; + QAction * mClassBrowser_goto_definition; // QWidget interface protected: diff --git a/RedPandaIDE/widgets/classbrowser.cpp b/RedPandaIDE/widgets/classbrowser.cpp index 654445b7..0f04d286 100644 --- a/RedPandaIDE/widgets/classbrowser.cpp +++ b/RedPandaIDE/widgets/classbrowser.cpp @@ -10,7 +10,7 @@ ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent) mRoot = new ClassBrowserNode(); mRoot->parent = nullptr; mRoot->statement = PStatement(); - mRoot->childrenFetched = true; +// mRoot->childrenFetched = true; mUpdating = false; mUpdateCount = 0; mShowInheritedMembers = false; @@ -54,14 +54,14 @@ bool ClassBrowserModel::hasChildren(const QModelIndex &parent) const { ClassBrowserNode *parentNode; if (!parent.isValid()) { // top level - return mRoot->children.count(); + return mRoot->children.count()>0; } else { parentNode = static_cast(parent.internalPointer()); - if (parentNode->childrenFetched) - return parentNode->children.count(); - if (parentNode->statement) - return !parentNode->statement->children.isEmpty(); - return false; +// if (parentNode->childrenFetched) + return parentNode->children.count()>0; +// if (parentNode->statement) +// return !parentNode->statement->children.isEmpty(); +// return false; } } @@ -81,37 +81,37 @@ int ClassBrowserModel::columnCount(const QModelIndex&) const return 1; } -void ClassBrowserModel::fetchMore(const QModelIndex &parent) -{ - if (!parent.isValid()) { // top level - return; - } +//void ClassBrowserModel::fetchMore(const QModelIndex &parent) +//{ +// if (!parent.isValid()) { // top level +// return; +// } - ClassBrowserNode *parentNode = static_cast(parent.internalPointer()); - if (!parentNode->childrenFetched) { - parentNode->childrenFetched = true; - if (parentNode->statement && !parentNode->statement->children.isEmpty()) { - filterChildren(parentNode, parentNode->statement->children); - beginInsertRows(parent,0,parentNode->children.count()); - endInsertRows(); - } - } -} +// ClassBrowserNode *parentNode = static_cast(parent.internalPointer()); +// if (!parentNode->childrenFetched) { +// parentNode->childrenFetched = true; +// if (parentNode->statement && !parentNode->statement->children.isEmpty()) { +// filterChildren(parentNode, parentNode->statement->children); +// beginInsertRows(parent,0,parentNode->children.count()); +// endInsertRows(); +// } +// } +//} -bool ClassBrowserModel::canFetchMore(const QModelIndex &parent) const -{ - if (!parent.isValid()) { // top level - return false; - } - ClassBrowserNode *parentNode = static_cast(parent.internalPointer()); - if (!parentNode->childrenFetched) { - if (parentNode->statement && !parentNode->statement->children.isEmpty()) - return true; - else - parentNode->childrenFetched = true; - } - return false; -} +//bool ClassBrowserModel::canFetchMore(const QModelIndex &parent) const +//{ +// if (!parent.isValid()) { // top level +// return false; +// } +// ClassBrowserNode *parentNode = static_cast(parent.internalPointer()); +// if (!parentNode->childrenFetched) { +// if (parentNode->statement && !parentNode->statement->children.isEmpty()) +// return true; +// else +// parentNode->childrenFetched = true; +// } +// return false; +//} QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const { @@ -123,7 +123,7 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const return QVariant(); if (role == Qt::DisplayRole) { if (node->statement) { - return node->statement->command; + return node->statement->command + node->statement->args; } } else if (role == Qt::ForegroundRole) { if (node->statement) { @@ -136,6 +136,70 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const } return mColors->value(kind,pMainWindow->palette().color(QPalette::Text)); } + } else if (role == Qt::DecorationRole) { + if (node->statement) { + PStatement statement = (node->statement); + StatementKind kind; + if (mParser) { + kind = mParser->getKindOfStatement(statement); + } else { + kind = statement->kind; + } + switch (kind) { + case StatementKind::skTypedef: + return QIcon(":/icons/images/classparser/type.ico"); + case StatementKind::skClass: + case StatementKind::skEnumClassType: + case StatementKind::skEnumType: + return QIcon(":/icons/images/classparser/class.ico"); + case StatementKind::skNamespace: + case StatementKind::skNamespaceAlias: + return QIcon(":/icons/images/classparser/namespace.ico"); + case StatementKind::skPreprocessor: + return QIcon(":/icons/images/classparser/define.ico"); + case StatementKind::skEnum: + return QIcon(":/icons/images/classparser/enum.ico"); + case StatementKind::skFunction: + case StatementKind::skConstructor: + case StatementKind::skDestructor: + if (statement->scope == StatementScope::ssGlobal) + return QIcon(":/icons/images/classparser/global_method.ico"); + if (statement->isInherited) { + if (statement->classScope == StatementClassScope::scsProtected) { + return QIcon(":/icons/images/classparser/method_inherited_protected.ico"); + } else if (statement->classScope == StatementClassScope::scsPublic) { + return QIcon(":/icons/images/classparser/method_inherited.ico"); + } + } else { + if (statement->classScope == StatementClassScope::scsProtected) { + return QIcon(":/icons/images/classparser/method_protected.ico"); + } else if (statement->classScope == StatementClassScope::scsPublic) { + return QIcon(":/icons/images/classparser/method_public.ico"); + } else { + return QIcon(":/icons/images/classparser/method_private.ico"); + } + } + case StatementKind::skVariable: + if (statement->scope == StatementScope::ssGlobal) + return QIcon(":/icons/images/classparser/global.ico"); + if (statement->isInherited) { + if (statement->classScope == StatementClassScope::scsProtected) { + return QIcon(":/icons/images/classparser/var_inherited_protected.ico"); + } else if (statement->classScope == StatementClassScope::scsPublic) { + return QIcon(":/icons/images/classparser/var_inherited.ico"); + } + } else { + if (statement->classScope == StatementClassScope::scsProtected) { + return QIcon(":/icons/images/classparser/var_protected.ico"); + } else if (statement->classScope == StatementClassScope::scsPublic) { + return QIcon(":/icons/images/classparser/var_public.ico"); + } else { + return QIcon(":/icons/images/classparser/var_private.ico"); + } + } + } + } + } return QVariant(); } @@ -215,9 +279,10 @@ void ClassBrowserModel::addChild(ClassBrowserNode *node, PStatement statement) PClassBrowserNode newNode = std::make_shared(); newNode->parent = node; newNode->statement = statement; - newNode->childrenFetched = false; +// newNode->childrenFetched = false; node->children.append(newNode.get()); mNodes.append(newNode); + filterChildren(newNode.get(), statement->children); } void ClassBrowserModel::addMembers(const QSet &includedFiles) diff --git a/RedPandaIDE/widgets/classbrowser.h b/RedPandaIDE/widgets/classbrowser.h index 1cd294e7..334b19f0 100644 --- a/RedPandaIDE/widgets/classbrowser.h +++ b/RedPandaIDE/widgets/classbrowser.h @@ -8,7 +8,7 @@ struct ClassBrowserNode { ClassBrowserNode* parent; PStatement statement; QVector children; - bool childrenFetched; +// bool childrenFetched; }; using PClassBrowserNode = std::shared_ptr; @@ -26,8 +26,8 @@ public: bool hasChildren(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override; - void fetchMore(const QModelIndex &parent) override; - bool canFetchMore(const QModelIndex &parent) const override; +// void fetchMore(const QModelIndex &parent) override; +// bool canFetchMore(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; const PCppParser &parser() const; void setParser(const PCppParser &newCppParser); @@ -59,6 +59,7 @@ private: QString mCurrentFile; bool mShowInheritedMembers; std::shared_ptr> mColors; + }; #endif // CLASSBROWSER_H