mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-31 10:36:30 +03:00
ecode: Syntax highlighting in project search.
This commit is contained in:
@@ -101,7 +101,9 @@ class EE_API UICodeEditorSplitter {
|
||||
|
||||
UICodeEditor* getCurEditor() const;
|
||||
|
||||
const std::string& getCurrentColorScheme() const;
|
||||
const SyntaxColorScheme& getCurrentColorScheme() const;
|
||||
|
||||
const std::string& getCurrentColorSchemeName() const;
|
||||
|
||||
void setColorScheme( const std::string& name );
|
||||
|
||||
|
||||
@@ -88,6 +88,8 @@ class EE_API UITextView : public UIWidget {
|
||||
|
||||
void setTextAlign( const Uint32& align );
|
||||
|
||||
UITextView* setFontFillColor( const Color& color, Uint32 from, Uint32 to );
|
||||
|
||||
protected:
|
||||
Text* mTextCache;
|
||||
String mString;
|
||||
|
||||
@@ -13,6 +13,72 @@ namespace EE { namespace UI {
|
||||
|
||||
class UITableRow;
|
||||
|
||||
class EE_API UITreeViewCell : public UITableCell {
|
||||
public:
|
||||
static UITreeViewCell* New() { return eeNew( UITreeViewCell, () ); }
|
||||
|
||||
Uint32 getType() const { return UI_TYPE_TREEVIEW_CELL; }
|
||||
|
||||
bool isType( const Uint32& type ) const {
|
||||
return UITreeViewCell::getType() == type ? true : UITableCell::isType( type );
|
||||
}
|
||||
|
||||
UIImage* getImage() const { return mImage; }
|
||||
|
||||
Rectf calculatePadding() const {
|
||||
Sizef size;
|
||||
Rectf autoPadding;
|
||||
if ( mFlags & UI_AUTO_PADDING ) {
|
||||
autoPadding = makePadding( true, true, true, true );
|
||||
if ( autoPadding != Rectf() )
|
||||
autoPadding = PixelDensity::dpToPx( autoPadding );
|
||||
}
|
||||
if ( mPaddingPx.Top > autoPadding.Top )
|
||||
autoPadding.Top = mPaddingPx.Top;
|
||||
if ( mPaddingPx.Bottom > autoPadding.Bottom )
|
||||
autoPadding.Bottom = mPaddingPx.Bottom;
|
||||
if ( mPaddingPx.Left > autoPadding.Left )
|
||||
autoPadding.Left = mPaddingPx.Left;
|
||||
if ( mPaddingPx.Right > autoPadding.Right )
|
||||
autoPadding.Right = mPaddingPx.Right;
|
||||
autoPadding.Left += mIndent;
|
||||
return autoPadding;
|
||||
}
|
||||
|
||||
void setIndentation( const Float& indent ) {
|
||||
if ( mIndent != indent ) {
|
||||
mIndent = indent;
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
const Float& getIndentation() const { return mIndent; }
|
||||
|
||||
protected:
|
||||
mutable UIImage* mImage{nullptr};
|
||||
Float mIndent{0};
|
||||
|
||||
UITreeViewCell() : UITableCell( "treeview::cell" ) {
|
||||
mTextBox->setElementTag( mTag + "::text" );
|
||||
mIcon->setElementTag( mTag + "::icon" );
|
||||
mInnerWidgetOrientation = InnerWidgetOrientation::Left;
|
||||
auto cb = [&]( const Event* ) { updateLayout(); };
|
||||
mImage = UIImage::NewWithTag( mTag + "::expander" );
|
||||
mImage->setScaleType( UIScaleType::FitInside )
|
||||
->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed )
|
||||
->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER )
|
||||
->setParent( const_cast<UITreeViewCell*>( this ) )
|
||||
->setVisible( false )
|
||||
->setEnabled( false );
|
||||
mImage->addEventListener( Event::OnPaddingChange, cb );
|
||||
mImage->addEventListener( Event::OnMarginChange, cb );
|
||||
mImage->addEventListener( Event::OnSizeChange, cb );
|
||||
mImage->addEventListener( Event::OnVisibleChange, cb );
|
||||
}
|
||||
|
||||
virtual UIWidget* getExtraInnerWidget() const { return mImage; }
|
||||
};
|
||||
|
||||
class EE_API UITreeView : public UIAbstractTableView {
|
||||
public:
|
||||
static UITreeView* New();
|
||||
@@ -59,8 +125,7 @@ class EE_API UITreeView : public UIAbstractTableView {
|
||||
|
||||
void setExpanderIconSize( const size_t& expanderSize );
|
||||
|
||||
virtual ModelIndex findRowWithText( const std::string& text,
|
||||
const bool& caseSensitive = false,
|
||||
virtual ModelIndex findRowWithText( const std::string& text, const bool& caseSensitive = false,
|
||||
const bool& exactMatch = false );
|
||||
|
||||
protected:
|
||||
@@ -109,6 +174,9 @@ class EE_API UITreeView : public UIAbstractTableView {
|
||||
void updateContentSize();
|
||||
|
||||
void setAllExpanded( const ModelIndex& index = {}, bool expanded = true );
|
||||
|
||||
virtual UIWidget* setupCell( UITableCell* widget, UIWidget* rowWidget,
|
||||
const ModelIndex& index );
|
||||
};
|
||||
|
||||
}} // namespace EE::UI
|
||||
|
||||
@@ -262,10 +262,14 @@ UICodeEditor* UICodeEditorSplitter::createCodeEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
const std::string& UICodeEditorSplitter::getCurrentColorScheme() const {
|
||||
const std::string& UICodeEditorSplitter::getCurrentColorSchemeName() const {
|
||||
return mCurrentColorScheme;
|
||||
}
|
||||
|
||||
const SyntaxColorScheme& UICodeEditorSplitter::getCurrentColorScheme() const {
|
||||
return mColorSchemes.at( mCurrentColorScheme );
|
||||
}
|
||||
|
||||
void UICodeEditorSplitter::setColorScheme( const std::string& name ) {
|
||||
if ( name != mCurrentColorScheme ) {
|
||||
mCurrentColorScheme = name;
|
||||
|
||||
@@ -216,6 +216,13 @@ UITextView* UITextView::setFontColor( const Color& color ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
UITextView* UITextView::setFontFillColor( const Color& color, Uint32 from, Uint32 to ) {
|
||||
Color newColor( color.r, color.g, color.b, color.a * mAlpha / 255.f );
|
||||
mTextCache->setFillColor( newColor, from, to );
|
||||
invalidateDraw();
|
||||
return this;
|
||||
}
|
||||
|
||||
const Color& UITextView::getFontShadowColor() const {
|
||||
return mFontStyleConfig.ShadowColor;
|
||||
}
|
||||
|
||||
@@ -108,75 +108,8 @@ void UITreeView::updateContentSize() {
|
||||
onContentSizeChange();
|
||||
}
|
||||
|
||||
class UITreeViewCell : public UITableCell {
|
||||
public:
|
||||
static UITreeViewCell* New() { return eeNew( UITreeViewCell, () ); }
|
||||
|
||||
Uint32 getType() const { return UI_TYPE_TREEVIEW_CELL; }
|
||||
|
||||
bool isType( const Uint32& type ) const {
|
||||
return UITreeViewCell::getType() == type ? true : UITableCell::isType( type );
|
||||
}
|
||||
|
||||
UIImage* getImage() const { return mImage; }
|
||||
|
||||
Rectf calculatePadding() const {
|
||||
Sizef size;
|
||||
Rectf autoPadding;
|
||||
if ( mFlags & UI_AUTO_PADDING ) {
|
||||
autoPadding = makePadding( true, true, true, true );
|
||||
if ( autoPadding != Rectf() )
|
||||
autoPadding = PixelDensity::dpToPx( autoPadding );
|
||||
}
|
||||
if ( mPaddingPx.Top > autoPadding.Top )
|
||||
autoPadding.Top = mPaddingPx.Top;
|
||||
if ( mPaddingPx.Bottom > autoPadding.Bottom )
|
||||
autoPadding.Bottom = mPaddingPx.Bottom;
|
||||
if ( mPaddingPx.Left > autoPadding.Left )
|
||||
autoPadding.Left = mPaddingPx.Left;
|
||||
if ( mPaddingPx.Right > autoPadding.Right )
|
||||
autoPadding.Right = mPaddingPx.Right;
|
||||
autoPadding.Left += mIndent;
|
||||
return autoPadding;
|
||||
}
|
||||
|
||||
void setIndentation( const Float& indent ) {
|
||||
if ( mIndent != indent ) {
|
||||
mIndent = indent;
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
const Float& getIndentation() const { return mIndent; }
|
||||
|
||||
protected:
|
||||
mutable UIImage* mImage{nullptr};
|
||||
Float mIndent{0};
|
||||
|
||||
UITreeViewCell() : UITableCell( "treeview::cell" ) {
|
||||
mTextBox->setElementTag( mTag + "::text" );
|
||||
mIcon->setElementTag( mTag + "::icon" );
|
||||
mInnerWidgetOrientation = InnerWidgetOrientation::Left;
|
||||
auto cb = [&]( const Event* ) { updateLayout(); };
|
||||
mImage = UIImage::NewWithTag( mTag + "::expander" );
|
||||
mImage->setScaleType( UIScaleType::FitInside )
|
||||
->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed )
|
||||
->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER )
|
||||
->setParent( const_cast<UITreeViewCell*>( this ) )
|
||||
->setVisible( false )
|
||||
->setEnabled( false );
|
||||
mImage->addEventListener( Event::OnPaddingChange, cb );
|
||||
mImage->addEventListener( Event::OnMarginChange, cb );
|
||||
mImage->addEventListener( Event::OnSizeChange, cb );
|
||||
mImage->addEventListener( Event::OnVisibleChange, cb );
|
||||
}
|
||||
|
||||
virtual UIWidget* getExtraInnerWidget() const { return mImage; }
|
||||
};
|
||||
|
||||
UIWidget* UITreeView::createCell( UIWidget* rowWidget, const ModelIndex& index ) {
|
||||
UITableCell* widget = index.column() == (Int64)getModel()->treeColumn() ? UITreeViewCell::New()
|
||||
: UITableCell::New();
|
||||
UIWidget* UITreeView::setupCell( UITableCell* widget, UIWidget* rowWidget,
|
||||
const ModelIndex& index ) {
|
||||
widget->setParent( rowWidget );
|
||||
widget->unsetFlags( UI_AUTO_SIZE );
|
||||
widget->clipEnable();
|
||||
@@ -219,6 +152,12 @@ UIWidget* UITreeView::createCell( UIWidget* rowWidget, const ModelIndex& index )
|
||||
return widget;
|
||||
}
|
||||
|
||||
UIWidget* UITreeView::createCell( UIWidget* rowWidget, const ModelIndex& index ) {
|
||||
UITableCell* widget = index.column() == (Int64)getModel()->treeColumn() ? UITreeViewCell::New()
|
||||
: UITableCell::New();
|
||||
return setupCell( widget, rowWidget, index );
|
||||
}
|
||||
|
||||
UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index,
|
||||
const size_t& indentLevel, const Float& yOffset ) {
|
||||
if ( rowIndex >= (int)mWidgets.size() )
|
||||
|
||||
@@ -359,7 +359,7 @@ void App::loadConfig() {
|
||||
}
|
||||
|
||||
void App::saveConfig() {
|
||||
mConfig.editor.colorScheme = mEditorSplitter->getCurrentColorScheme();
|
||||
mConfig.editor.colorScheme = mEditorSplitter->getCurrentColorSchemeName();
|
||||
mConfig.window.size = mWindow->getLastWindowedSize();
|
||||
mConfig.window.maximized = mWindow->isMaximized();
|
||||
mIni.setValue( "editor", "colorscheme", mConfig.editor.colorScheme );
|
||||
@@ -683,6 +683,83 @@ void App::hideGlobalSearchBar() {
|
||||
mGlobalSearchTree->setVisible( false );
|
||||
}
|
||||
|
||||
class UITreeViewCellGlobalSearch : public UITreeViewCell {
|
||||
public:
|
||||
static UITreeViewCellGlobalSearch* New() { return eeNew( UITreeViewCellGlobalSearch, () ); }
|
||||
|
||||
UITreeViewCellGlobalSearch() : UITreeViewCell() {}
|
||||
|
||||
UIPushButton* setText( const String& text );
|
||||
|
||||
UIPushButton* updateText( const String& text );
|
||||
};
|
||||
|
||||
class UITreeViewGlobalSearch : public UITreeView {
|
||||
public:
|
||||
static UITreeViewGlobalSearch* New( const SyntaxColorScheme& colorScheme ) {
|
||||
return eeNew( UITreeViewGlobalSearch, ( colorScheme ) );
|
||||
}
|
||||
|
||||
UITreeViewGlobalSearch( const SyntaxColorScheme& colorScheme ) :
|
||||
UITreeView(), mColorScheme( colorScheme ) {
|
||||
mLineNumColor = Color::fromString(
|
||||
mUISceneNode->getRoot()->getUIStyle()->getVariable( "--font-hint" ).getValue() );
|
||||
}
|
||||
|
||||
UIWidget* createCell( UIWidget* rowWidget, const ModelIndex& index ) {
|
||||
UITableCell* widget = index.column() == (Int64)getModel()->treeColumn()
|
||||
? UITreeViewCellGlobalSearch::New()
|
||||
: UITableCell::New();
|
||||
return setupCell( widget, rowWidget, index );
|
||||
}
|
||||
|
||||
const SyntaxColorScheme& getColorScheme() const { return mColorScheme; }
|
||||
|
||||
const Color& getLineNumColor() const { return mLineNumColor; }
|
||||
|
||||
void updateColorScheme( const SyntaxColorScheme& colorScheme ) { mColorScheme = colorScheme; }
|
||||
|
||||
protected:
|
||||
Color mLineNumColor;
|
||||
SyntaxColorScheme mColorScheme;
|
||||
};
|
||||
|
||||
UIPushButton* UITreeViewCellGlobalSearch::updateText( const String& text ) {
|
||||
if ( getCurIndex().internalId() != -1 ) {
|
||||
UITreeViewGlobalSearch* pp = getParent()->getParent()->asType<UITreeViewGlobalSearch>();
|
||||
|
||||
ProjectSearch::ResultData* res = (ProjectSearch::ResultData*)getCurIndex().parent().data();
|
||||
|
||||
auto styleDef = SyntaxDefinitionManager::instance()->getStyleByExtension( res->file );
|
||||
|
||||
auto tokens =
|
||||
SyntaxTokenizer::tokenize( styleDef, text, SYNTAX_TOKENIZER_STATE_NONE ).first;
|
||||
|
||||
size_t start = 0;
|
||||
for ( auto& token : tokens ) {
|
||||
mTextBox->setFontFillColor( pp->getColorScheme().getSyntaxStyle( token.type ).color,
|
||||
start, start + token.text.size() );
|
||||
start += token.text.size();
|
||||
}
|
||||
|
||||
Uint32 from = text.find_first_not_of( ' ' );
|
||||
if ( from != String::InvalidPos )
|
||||
mTextBox->setFontFillColor( pp->getLineNumColor(), from,
|
||||
text.find_first_of( ' ', from ) );
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
UIPushButton* UITreeViewCellGlobalSearch::setText( const String& text ) {
|
||||
if ( text != mTextBox->getText() ) {
|
||||
mTextBox->setVisible( !text.empty() );
|
||||
mTextBox->setText( text );
|
||||
updateText( text );
|
||||
updateLayout();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void App::initGlobalSearchBar() {
|
||||
auto addClickListener = [&]( UIWidget* widget, std::string cmd ) {
|
||||
widget->addEventListener( Event::MouseClick, [this, cmd]( const Event* event ) {
|
||||
@@ -758,7 +835,7 @@ void App::initGlobalSearchBar() {
|
||||
} );
|
||||
addClickListener( searchButton, "search-in-files" );
|
||||
addClickListener( searchBarClose, "close-global-searchbar" );
|
||||
mGlobalSearchTree = UITreeView::New();
|
||||
mGlobalSearchTree = UITreeViewGlobalSearch::New( mEditorSplitter->getCurrentColorScheme() );
|
||||
mGlobalSearchTree->setId( "search_tree" );
|
||||
mGlobalSearchTree->setParent( mUISceneNode->getRoot() );
|
||||
mGlobalSearchTree->setExpanderIconSize( PixelDensity::dpToPx( 20 ) );
|
||||
@@ -1558,6 +1635,9 @@ void App::onCodeEditorFocusChange( UICodeEditor* editor ) {
|
||||
|
||||
void App::onColorSchemeChanged( const std::string& ) {
|
||||
updateColorSchemeMenu();
|
||||
|
||||
mGlobalSearchTree->asType<UITreeViewGlobalSearch>()->updateColorScheme(
|
||||
mEditorSplitter->getCurrentColorScheme() );
|
||||
}
|
||||
|
||||
void App::onDocumentLoaded( UICodeEditor* codeEditor, const std::string& path ) {
|
||||
@@ -1617,8 +1697,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) {
|
||||
const CodeEditorConfig& config = mConfig.editor;
|
||||
editor->setFontSize( config.fontSize.asDp( 0, Sizef(), mUISceneNode->getDPI() ) );
|
||||
editor->setEnableColorPickerOnSelection( true );
|
||||
editor->setColorScheme(
|
||||
mEditorSplitter->getColorSchemes().at( mEditorSplitter->getCurrentColorScheme() ) );
|
||||
editor->setColorScheme( mEditorSplitter->getCurrentColorScheme() );
|
||||
editor->setShowLineNumber( config.showLineNumbers );
|
||||
editor->setShowWhitespaces( config.showWhiteSpaces );
|
||||
editor->setHighlightMatchingBracket( config.highlightMatchingBracket );
|
||||
@@ -1838,7 +1917,7 @@ void App::createSettingsMenu() {
|
||||
void App::updateColorSchemeMenu() {
|
||||
for ( size_t i = 0; i < mColorSchemeMenu->getCount(); i++ ) {
|
||||
UIMenuRadioButton* menuItem = mColorSchemeMenu->getItem( i )->asType<UIMenuRadioButton>();
|
||||
menuItem->setActive( mEditorSplitter->getCurrentColorScheme() == menuItem->getText() );
|
||||
menuItem->setActive( mEditorSplitter->getCurrentColorSchemeName() == menuItem->getText() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1846,7 +1925,7 @@ UIMenu* App::createColorSchemeMenu() {
|
||||
mColorSchemeMenu = UIPopUpMenu::New();
|
||||
for ( auto& colorScheme : mEditorSplitter->getColorSchemes() ) {
|
||||
mColorSchemeMenu->addRadioButton(
|
||||
colorScheme.first, mEditorSplitter->getCurrentColorScheme() == colorScheme.first );
|
||||
colorScheme.first, mEditorSplitter->getCurrentColorSchemeName() == colorScheme.first );
|
||||
}
|
||||
mColorSchemeMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) {
|
||||
UIMenuItem* item = event->getNode()->asType<UIMenuItem>();
|
||||
|
||||
Reference in New Issue
Block a user