ecode: Quick Fix icon is now clickable. Minor fixes with incorrect usage of setCursor.

This commit is contained in:
Martín Lucas Golini
2024-06-23 22:05:04 -03:00
parent aad3b189d3
commit 4ec00ee02d
6 changed files with 155 additions and 29 deletions

View File

@@ -720,6 +720,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
void setFoldsRefreshTime( const Time& foldsRefreshTime );
void updateMouseCursor( const Vector2f& position );
protected:
struct LastXOffset {
TextPosition position{ 0, 0 };
@@ -1035,8 +1037,6 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
void findRegionsDelayed();
void refreshTag();
void updateMouseCursor( const Vector2f& position );
};
}} // namespace EE::UI

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 13.0.2, 2024-06-13T02:20:10. -->
<!-- Written by QtCreator 13.0.2, 2024-06-23T19:12:47. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@@ -116,7 +116,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{388e5431-b31b-42b3-b9ad-9002d279d75d}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">10</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">8</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">19</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">../../make/linux</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
@@ -235,7 +235,7 @@
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Arguments">--with-debug-symbols gmake</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Arguments">--with-debug-symbols --with-text-shaper gmake</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Command">premake4</value>
<value type="QString" key="ProjectExplorer.ProcessStep.WorkingDirectory">%{buildDir}../../../</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.ProcessStep</value>
@@ -1564,9 +1564,98 @@
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">29</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.1</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Python 2.7.18</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Python 2.7.18</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{2a67c17f-0b20-4f13-b20e-78e54b4ce738}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/programming/eepp/projects/linux</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CycleDetection">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.ShortenTemplates">false</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">false</value>
<value type="QString" key="Analyzer.Valgrind.KCachegrindExecutable">/usr/bin/kcachegrind</value>
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">2</value>
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">2</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.ShowReachable">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">/usr/bin/valgrind</value>
<value type="QList&lt;int&gt;" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="qlonglong">1</value>
<value type="qlonglong">2</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>

View File

@@ -4808,9 +4808,12 @@ void UICodeEditor::refreshTag() {
}
void UICodeEditor::updateMouseCursor( const Vector2f& position ) {
bool overGutter = convertToNodeSpace( position ).x < getGutterWidth();
getUISceneNode()->setCursor(
mHandShown ? Cursor::Hand : ( !overGutter && !mLocked ? Cursor::IBeam : Cursor::Arrow ) );
if ( getScreenBounds().contains( position ) ) {
bool overGutter = convertToNodeSpace( position ).x < getGutterWidth();
getUISceneNode()->setCursor(
mHandShown ? Cursor::Hand
: ( !overGutter && !mLocked ? Cursor::IBeam : Cursor::Arrow ) );
}
}
}} // namespace EE::UI

View File

@@ -7,6 +7,7 @@
#include <eepp/system/luapattern.hpp>
#include <eepp/system/scopedop.hpp>
#include <eepp/ui/doc/syntaxdefinitionmanager.hpp>
#include <eepp/ui/uieventdispatcher.hpp>
#include <eepp/ui/uiscenenode.hpp>
#include <nlohmann/json.hpp>
using namespace EE::Graphics;
@@ -1209,8 +1210,11 @@ void AutoCompletePlugin::resetSuggestions( UICodeEditor* editor ) {
mSuggestionsEditor = nullptr;
}
mSuggestions.clear();
if ( editor && editor->hasFocus() )
editor->getUISceneNode()->setCursor( !editor->isLocked() ? Cursor::IBeam : Cursor::Arrow );
if ( editor && editor->hasFocus() ) {
auto mousePos( editor->getUISceneNode()->getUIEventDispatcher()->getMousePosf() );
if ( editor->getScreenRect().contains( mousePos ) )
editor->updateMouseCursor( mousePos );
}
}
void AutoCompletePlugin::resetSignatureHelp() {

View File

@@ -998,6 +998,11 @@ SyntaxStyleType LinterPlugin::getMatchString( const LinterType& type ) {
return "error"_sst;
}
void LinterPlugin::preDraw( UICodeEditor*, const Vector2f& /*startScroll*/,
const Float& /*lineHeight*/, const TextPosition& /*cursor*/ ) {
mQuickFixRect = {};
}
void LinterPlugin::drawAfterLineText( UICodeEditor* editor, const Int64& index, Vector2f position,
const Float& /*fontSize*/, const Float& lineHeight ) {
Lock l( mMatchesMutex );
@@ -1057,24 +1062,30 @@ void LinterPlugin::drawAfterLineText( UICodeEditor* editor, const Int64& index,
Float rLineWidth = 0;
if ( !quickFixRendered && doc->getSelection().start().line() == index &&
!match.diagnostic.codeActions.empty() ) {
rLineWidth = editor->getLineWidth( index ) + editor->getGlyphWidth();
Color wcolor( editor->getColorScheme().getEditorSyntaxStyle( "warning"_sst ).color );
if ( nullptr == mLightbulbIcon ) {
mLightbulbIcon = editor->getUISceneNode()->getUIIconThemeManager()->findIcon(
"lightbulb-autofix" );
}
if ( nullptr != mLightbulbIcon ) {
Drawable* drawable = mLightbulbIcon->getSize( (int)eefloor( lineHeight ) );
if ( drawable == nullptr )
return;
if ( !quickFixRendered && doc->getSelection().start().line() == index ) {
if ( !match.diagnostic.codeActions.empty() ) {
rLineWidth = editor->getLineWidth( index ) + editor->getGlyphWidth();
Color wcolor(
editor->getColorScheme().getEditorSyntaxStyle( "warning"_sst ).color );
if ( nullptr == mLightbulbIcon ) {
mLightbulbIcon = editor->getUISceneNode()->getUIIconThemeManager()->findIcon(
"lightbulb-autofix" );
}
if ( nullptr != mLightbulbIcon ) {
Drawable* drawable = mLightbulbIcon->getSize( (int)eefloor( lineHeight ) );
if ( drawable == nullptr )
return;
Color oldColor( drawable->getColor() );
drawable->setColor( wcolor );
drawable->draw( { position.x + rLineWidth, position.y } );
drawable->setColor( oldColor );
quickFixRendered = true;
Color oldColor( drawable->getColor() );
drawable->setColor( wcolor );
Vector2f pos = { position.x + rLineWidth, position.y };
drawable->draw( pos );
mQuickFixRect = { pos, drawable->getPixelsSize() };
drawable->setColor( oldColor );
quickFixRendered = true;
}
} else {
mQuickFixRect = {};
}
}
@@ -1251,7 +1262,21 @@ void LinterPlugin::goToPrevError( UICodeEditor* editor ) {
}
}
bool LinterPlugin::onMouseClick( UICodeEditor* editor, const Vector2i& pos, const Uint32& flags ) {
if ( ( flags & EE_BUTTON_LMASK ) && mQuickFixRect.Right != 0 && mQuickFixRect.Bottom != 0 &&
mQuickFixRect.contains( pos.asFloat() ) ) {
editor->getDocument().execute( "lsp-symbol-code-action", editor );
return true;
}
return false;
}
bool LinterPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& pos, const Uint32& flags ) {
if ( mQuickFixRect.Right != 0 && mQuickFixRect.Bottom != 0 &&
mQuickFixRect.contains( pos.asFloat() ) ) {
editor->getUISceneNode()->setCursor( Cursor::Hand );
return true;
}
if ( flags != 0 ) {
tryHideHoveringMatch( editor );
return false;

View File

@@ -96,6 +96,8 @@ class LinterPlugin : public Plugin {
bool onMouseLeave( UICodeEditor*, const Vector2i&, const Uint32& );
bool onMouseClick( UICodeEditor*, const Vector2i&, const Uint32& flags );
const Time& getDelayTime() const;
void setDelayTime( const Time& delayTime );
@@ -121,10 +123,12 @@ class LinterPlugin : public Plugin {
void unregisterNativeLinter( const std::string& cmd );
void preDraw( UICodeEditor*, const Vector2f&, const Float&, const TextPosition& );
protected:
std::vector<Linter> mLinters;
std::unordered_map<UICodeEditor*, std::vector<Uint32>> mEditors;
std::set<TextDocument*> mDocs;
std::unordered_set<TextDocument*> mDocs;
std::unordered_map<UICodeEditor*, TextDocument*> mEditorDocs;
std::unordered_map<TextDocument*, std::unique_ptr<Clock>> mDirtyDoc;
std::unordered_map<TextDocument*, std::map<Int64, std::vector<LinterMatch>>> mMatches;
@@ -150,6 +154,7 @@ class LinterPlugin : public Plugin {
String::HashType mConfigHash{ 0 };
UIIcon* mLightbulbIcon{ nullptr };
std::string mErrorMsg;
Rectf mQuickFixRect;
LinterPlugin( PluginManager* pluginManager, bool sync );