From 39133dbef7bc25728e1194f2a22ebb88407b5c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 1 Jun 2022 23:34:41 -0300 Subject: [PATCH] SyntaxDefinitionManager: Improved JSON patterns. UIAbstractTableView: Fixed a minor bug. WidgetTreeModel: Added ID column. ecode: Added debug node tree view. --- include/eepp/ui/models/widgettreemodel.hpp | 8 ++++ .../eepp/ui/tools/uicodeeditorsplitter.hpp | 3 ++ src/eepp/ui/abstract/uiabstracttableview.cpp | 44 ++++++++++--------- src/eepp/ui/doc/syntaxdefinitionmanager.cpp | 3 +- src/eepp/ui/models/widgettreemodel.cpp | 36 +++++++++++---- src/eepp/ui/tools/uicodeeditorsplitter.cpp | 6 +++ src/tools/ecode/ecode.cpp | 30 ++++++++++--- src/tools/ecode/ecode.hpp | 2 + 8 files changed, 96 insertions(+), 36 deletions(-) diff --git a/include/eepp/ui/models/widgettreemodel.hpp b/include/eepp/ui/models/widgettreemodel.hpp index 53fe932a5..044595997 100644 --- a/include/eepp/ui/models/widgettreemodel.hpp +++ b/include/eepp/ui/models/widgettreemodel.hpp @@ -11,12 +11,20 @@ namespace EE { namespace UI { namespace Models { class EE_API WidgetTreeModel : public Model { public: + enum Column { + Type = 0, + ID, + Count, + }; + static std::shared_ptr New( Node* node ); virtual size_t rowCount( const ModelIndex& = ModelIndex() ) const override; virtual size_t columnCount( const ModelIndex& = ModelIndex() ) const override; + virtual std::string columnName( const size_t& /*column*/ ) const override; + virtual Variant data( const ModelIndex&, ModelRole role = ModelRole::Display ) const override; virtual ModelIndex index( int row, int column, diff --git a/include/eepp/ui/tools/uicodeeditorsplitter.hpp b/include/eepp/ui/tools/uicodeeditorsplitter.hpp index 08056c039..7d2f1b680 100644 --- a/include/eepp/ui/tools/uicodeeditorsplitter.hpp +++ b/include/eepp/ui/tools/uicodeeditorsplitter.hpp @@ -141,12 +141,15 @@ class EE_API UICodeEditorSplitter { const std::vector& getTabWidgets() const; + Node* getBaseLayout() const; + protected: UISceneNode* mUISceneNode{ nullptr }; UICodeEditor* mCurEditor{ nullptr }; std::map mColorSchemes; std::string mCurrentColorScheme; std::vector mTabWidgets; + Node* mBaseLayout{ nullptr }; Client* mClient; bool mHideTabBarOnSingleTab{ true }; diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index d2519ddf1..9405b9271 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -95,27 +95,6 @@ void UIAbstractTableView::createOrUpdateColumns() { auto visibleColCount = visibleColumnCount(); - if ( mAutoColumnsWidth && visibleColCount > 1 && getModel()->rowCount() > 0 ) { - Float contentWidth = getContentSpaceWidth(); - bool shouldVScrollBeVisible = shouldVerticalScrollBeVisible(); - if ( !mVScroll->isVisible() && shouldVScrollBeVisible ) - contentWidth -= getVerticalScrollBar()->getPixelsSize().getWidth(); - else if ( mVScroll->isVisible() && !shouldVScrollBeVisible ) - contentWidth += getVerticalScrollBar()->getPixelsSize().getWidth(); - Float usedWidth = 0; - for ( size_t col = 0; col < count; col++ ) { - if ( col != mMainColumn && !isColumnHidden( col ) ) { - Float colWidth = getMaxColumnContentWidth( col, true ); - usedWidth += colWidth; - columnData( col ).width = colWidth; - } - } - Float mainColMaxWidth = getMaxColumnContentWidth( mMainColumn, true ); - columnData( mMainColumn ).width = contentWidth - usedWidth >= mainColMaxWidth - ? contentWidth - usedWidth - : mainColMaxWidth; - } - for ( size_t i = 0; i < count; i++ ) { ColumnData& col = columnData( i ); if ( !col.widget ) { @@ -140,6 +119,29 @@ void UIAbstractTableView::createOrUpdateColumns() { col.widget->setPixelsSize( col.width, getHeaderHeight() ); } + if ( mAutoColumnsWidth && visibleColCount > 1 && getModel()->rowCount() > 0 ) { + Float contentWidth = getContentSpaceWidth(); + bool shouldVScrollBeVisible = shouldVerticalScrollBeVisible(); + if ( !mVScroll->isVisible() && shouldVScrollBeVisible ) + contentWidth -= getVerticalScrollBar()->getPixelsSize().getWidth(); + else if ( mVScroll->isVisible() && !shouldVScrollBeVisible ) + contentWidth += getVerticalScrollBar()->getPixelsSize().getWidth(); + Float usedWidth = 0; + for ( size_t col = 0; col < count; col++ ) { + if ( col != mMainColumn && !isColumnHidden( col ) ) { + Float colWidth = getMaxColumnContentWidth( col, true ); + if ( colWidth == 0 ) + colWidth = columnData( col ).widget->getPixelsSize().getWidth(); + usedWidth += colWidth; + columnData( col ).width = colWidth; + } + } + Float mainColMaxWidth = getMaxColumnContentWidth( mMainColumn, true ); + columnData( mMainColumn ).width = contentWidth - usedWidth >= mainColMaxWidth + ? contentWidth - usedWidth + : mainColMaxWidth; + } + mHeaderHeight = 0; for ( size_t i = 0; i < count; i++ ) { ColumnData& col = columnData( i ); diff --git a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp index c4a751801..786f20f00 100644 --- a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp +++ b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp @@ -109,6 +109,7 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { { { "```[Cc]", "```" }, "function", "C" }, { { "```[Dd]", "```" }, "function", "D" }, { { "```[Ll]ua", "```" }, "function", "Lua" }, + { { "```[Jj][Ss][Oo][Nn]", "```" }, "function", "JSON" }, { { "```[Ja]va[Ss]cript", "```" }, "function", "JavaScript" }, { { "```[Tt]ype[Ss]cript", "```" }, "function", "TypeScript" }, { { "```[Pp]ython", "```" }, "function", "Python" }, @@ -266,7 +267,7 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { add( { "JSON", { "%.json$", "%.cson$" }, { - { { "(\".-\")(:)" }, { "normal", "keyword", "operator" } }, + { { "(%b\"\")(:)" }, { "normal", "keyword", "operator" } }, { { "\"", "\"", "\\" }, "string" }, { { "'", "'", "\\" }, "string" }, { { "`", "`", "\\" }, "string" }, diff --git a/src/eepp/ui/models/widgettreemodel.cpp b/src/eepp/ui/models/widgettreemodel.cpp index 3bcc2a756..cd7991cc2 100644 --- a/src/eepp/ui/models/widgettreemodel.cpp +++ b/src/eepp/ui/models/widgettreemodel.cpp @@ -19,23 +19,41 @@ size_t WidgetTreeModel::rowCount( const ModelIndex& index ) const { } size_t WidgetTreeModel::columnCount( const ModelIndex& ) const { - return 1; + return 2; +} + +std::string WidgetTreeModel::columnName( const size_t& col ) const { + switch ( col ) { + case Column::Type: + return "Type"; + case Column::ID: + return "ID"; + } + return ""; } Variant WidgetTreeModel::data( const ModelIndex& index, ModelRole role ) const { const char* EMPTY = ""; Node* node = static_cast( index.internalData() ); + if ( role == ModelRole::Display ) { - if ( node->isWidget() ) { - return Variant( node->asType()->getElementTag().c_str() ); - } else if ( node->isUISceneNode() ) { - return Variant( "UISceneNode" ); - } else if ( node->isSceneNode() ) { - return Variant( "SceneNode" ); - } else { - return Variant( node->getId().empty() ? "Node" : node->getId() ); + switch ( index.column() ) { + case Column::Type: { + if ( node->isWidget() ) { + return Variant( node->asType()->getElementTag().c_str() ); + } else if ( node->isUISceneNode() ) { + return Variant( "UISceneNode" ); + } else if ( node->isSceneNode() ) { + return Variant( "SceneNode" ); + } else { + return Variant( node->getId().empty() ? "Node" : node->getId() ); + } + } + case Column::ID: + return Variant( node->getId() ); } } + return Variant( EMPTY ); } diff --git a/src/eepp/ui/tools/uicodeeditorsplitter.cpp b/src/eepp/ui/tools/uicodeeditorsplitter.cpp index f297a6e0d..cf1822413 100644 --- a/src/eepp/ui/tools/uicodeeditorsplitter.cpp +++ b/src/eepp/ui/tools/uicodeeditorsplitter.cpp @@ -409,6 +409,8 @@ void UICodeEditorSplitter::removeUnusedTab( UITabWidget* tabWidget ) { } UITabWidget* UICodeEditorSplitter::createEditorWithTabWidget( Node* parent ) { + if ( nullptr == mBaseLayout ) + mBaseLayout = parent; UICodeEditor* prevCurEditor = mCurEditor; UITabWidget* tabWidget = UITabWidget::New(); tabWidget->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); @@ -526,6 +528,10 @@ const std::vector& UICodeEditorSplitter::getTabWidgets() const { return mTabWidgets; } +Node* UICodeEditorSplitter::getBaseLayout() const { + return mBaseLayout; +} + std::vector UICodeEditorSplitter::getAllEditors() { std::vector editors; forEachEditor( [&]( UICodeEditor* editor ) { editors.push_back( editor ); } ); diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 74c9cc3d1..b721243d1 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -448,6 +448,21 @@ App::~App() { eeSAFE_DELETE( mConsole ); } +void App::createWidgetTreeView() { + UIWindow* uiWin = UIWindow::NewOpt( UIWindow::LINEAR_LAYOUT ); + uiWin->setMinWindowSize( 600, 400 ); + uiWin->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); + UITreeView* widgetTree = UITreeView::New(); + widgetTree->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); + widgetTree->setParent( uiWin ); + widgetTree->setHeadersVisible( true ); + widgetTree->setAutoExpandOnSingleColumn( true ); + widgetTree->setExpanderIconSize( mMenuIconSize ); + widgetTree->setAutoColumnsWidth( true ); + widgetTree->setModel( WidgetTreeModel::New( mUISceneNode ) ); + uiWin->center(); +} + void App::updateRecentFiles() { UINode* node = nullptr; if ( mSettingsMenu && ( node = mSettingsMenu->getItem( "Recent Files" ) ) ) { @@ -1689,6 +1704,7 @@ std::map App::getLocalKeybindings() { { { KEY_F6, KEYMOD_NONE }, "debug-draw-highlight-toggle" }, { { KEY_F7, KEYMOD_NONE }, "debug-draw-boxes-toggle" }, { { KEY_F8, KEYMOD_NONE }, "debug-draw-debug-data" }, + { { KEY_F11, KEYMOD_NONE }, "debug-widget-tree-view" }, { { KEY_K, KeyMod::getDefaultModifier() }, "open-locatebar" }, { { KEY_F, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-global-search" }, { { KEY_L, KeyMod::getDefaultModifier() }, "go-to-line" }, @@ -1949,6 +1965,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { } ); doc.setCommand( "debug-draw-debug-data", [&] { mUISceneNode->setDrawDebugData( !mUISceneNode->getDrawDebugData() ); } ); + doc.setCommand( "debug-widget-tree-view", [&] { createWidgetTreeView(); } ); doc.setCommand( "go-to-line", [&] { mFileLocator->goToLine(); } ); doc.setCommand( "load-current-dir", [&] { loadCurrentDirectory(); } ); doc.setCommand( "menu-toggle", [&] { toggleSettingsMenu(); } ); @@ -3012,14 +3029,15 @@ void App::init( std::string file, const Float& pidelDensity, const std::string& - + - + + - + @@ -3068,8 +3086,8 @@ void App::init( std::string file, const Float& pidelDensity, const std::string& { "zoom-reset", 0xeb47 }, { "fullscreen", 0xed9c }, { "keybindings", 0xee75 }, - { "tree-expanded", 0xea50 }, - { "tree-contracted", 0xea54 }, + // { "tree-expanded", 0xea50 }, + // { "tree-contracted", 0xea54 }, { "search", 0xf0d1 }, { "go-up", 0xea78 }, { "ok", 0xeb7a }, @@ -3151,6 +3169,8 @@ void App::init( std::string file, const Float& pidelDensity, const std::string& { "file", 61766 }, { "folder", 0xF23B }, { "folder-open", 0xF23C }, + { "tree-expanded", 0xF11E }, + { "tree-contracted", 0xF120 }, }; for ( const auto& icon : mimeIcons ) iconTheme->add( UIGlyphIcon::New( icon.first, mimeIconFont, icon.second ) ); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 562105adc..22c314dd7 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -24,6 +24,8 @@ class App : public UICodeEditorSplitter::Client { ~App(); + void createWidgetTreeView(); + void init( std::string file, const Float& pidelDensity, const std::string& colorScheme ); void setAppTitle( const std::string& title );