mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-02 11:36:30 +03:00
Git Plugin more WIP.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "gitplugin.hpp"
|
||||
#include "eepp/ui/uistyle.hpp"
|
||||
#include <eepp/graphics/primitives.hpp>
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
#include <eepp/system/scopedop.hpp>
|
||||
@@ -40,6 +41,8 @@ GitPlugin::GitPlugin( PluginManager* pluginManager, bool sync ) : PluginBase( pl
|
||||
|
||||
GitPlugin::~GitPlugin() {
|
||||
mShuttingDown = true;
|
||||
if ( mStatusButton )
|
||||
mStatusButton->close();
|
||||
}
|
||||
|
||||
void GitPlugin::load( PluginManager* pluginManager ) {
|
||||
@@ -75,6 +78,13 @@ void GitPlugin::load( PluginManager* pluginManager ) {
|
||||
if ( j.contains( "config" ) ) {
|
||||
auto& config = j["config"];
|
||||
|
||||
if ( config.contains( "ui_refresh_frequency" ) )
|
||||
mRefreshFreq = Time::fromString( config.value( "ui_refresh_frequency", "5s" ) );
|
||||
else {
|
||||
config["ui_refresh_frequency"] = mRefreshFreq.toString();
|
||||
updateConfigFile = true;
|
||||
}
|
||||
|
||||
if ( config.contains( "statusbar_display_branch" ) )
|
||||
mStatusBarDisplayBranch = config.value( "statusbar_display_branch", true );
|
||||
else {
|
||||
@@ -117,24 +127,85 @@ void GitPlugin::load( PluginManager* pluginManager ) {
|
||||
}
|
||||
}
|
||||
|
||||
mGit = std::make_unique<Git>( "", pluginManager->getWorkspaceFolder() );
|
||||
mGit = std::make_unique<Git>( pluginManager->getWorkspaceFolder() );
|
||||
mGitFound = !mGit->getGitPath().empty();
|
||||
|
||||
if ( getUISceneNode() )
|
||||
updateStatusBar();
|
||||
|
||||
subscribeFileSystemListener();
|
||||
mReady = true;
|
||||
fireReadyCbs();
|
||||
setReady();
|
||||
}
|
||||
|
||||
void GitPlugin::updateUINow() {
|
||||
if ( !mGit || !getUISceneNode() )
|
||||
return;
|
||||
|
||||
updateStatusBar();
|
||||
}
|
||||
|
||||
void GitPlugin::updateUI() {
|
||||
if ( !mGit || !getUISceneNode() )
|
||||
return;
|
||||
|
||||
getUISceneNode()->debounce( [this] { updateUINow(); }, mRefreshFreq,
|
||||
String::hash( "git::status-update" ) );
|
||||
}
|
||||
|
||||
void GitPlugin::updateStatusBar() {
|
||||
if ( !mGit || !mStatusBarDisplayBranch )
|
||||
return;
|
||||
mThreadPool->run( [this] {
|
||||
if ( !mGit )
|
||||
return;
|
||||
mGitBranch = mGit->branch();
|
||||
mGitStatus = mGit->status();
|
||||
getUISceneNode()->runOnMainThread( [this] {
|
||||
if ( !mStatusBar )
|
||||
getUISceneNode()->bind( "status_bar", mStatusBar );
|
||||
if ( !mStatusBar )
|
||||
return;
|
||||
|
||||
if ( !mStatusButton ) {
|
||||
mStatusButton = UIPushButton::New();
|
||||
mStatusButton->setLayoutSizePolicy( SizePolicy::WrapContent,
|
||||
SizePolicy::MatchParent );
|
||||
mStatusButton->setId( "status_git" );
|
||||
mStatusButton->setClass( "status_but" );
|
||||
mStatusButton->setIcon( getManager()
|
||||
->getUISceneNode()
|
||||
->findIcon( "source-control" )
|
||||
->getSize( PixelDensity::dpToPxI( 12 ) ) );
|
||||
mStatusButton->setParent( mStatusBar );
|
||||
auto childCount = mStatusBar->getChildCount();
|
||||
if ( childCount > 2 )
|
||||
mStatusButton->toPosition( mStatusBar->getChildCount() - 2 );
|
||||
}
|
||||
|
||||
std::string text( mStatusBarDisplayModifications
|
||||
? String::format( "%s (+%d / -%d)", mGitBranch.c_str(),
|
||||
mGitStatus.totalInserts,
|
||||
mGitStatus.totalDeletions )
|
||||
: mGitBranch );
|
||||
|
||||
mStatusButton->setText( text );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
PluginRequestHandle GitPlugin::processMessage( const PluginMessage& msg ) {
|
||||
switch ( msg.type ) {
|
||||
case PluginMessageType::WorkspaceFolderChanged: {
|
||||
if ( !mGit )
|
||||
mGit = std::make_unique<Git>( "", msg.asJSON()["folder"] );
|
||||
else
|
||||
if ( mGit )
|
||||
mGit->setProjectPath( msg.asJSON()["folder"] );
|
||||
break;
|
||||
}
|
||||
case ecode::PluginMessageType::UIReady: {
|
||||
updateStatusBar();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -146,10 +217,23 @@ void GitPlugin::onFileSystemEvent( const FileEvent& ev, const FileInfo& file ) {
|
||||
|
||||
if ( mShuttingDown || isLoading() )
|
||||
return;
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
void GitPlugin::displayTooltip( UICodeEditor* editor, const Git::Blame& blame,
|
||||
const Vector2f& position ) {
|
||||
static std::vector<SyntaxPattern> patterns;
|
||||
|
||||
if ( patterns.empty() ) {
|
||||
patterns.emplace_back( SyntaxPattern( { "([%w:]+)%s(%x+)%s%((%x+)%)" },
|
||||
{ "normal", "keyword", "number", "number" } ) );
|
||||
patterns.emplace_back( SyntaxPattern( { "([%w:]+)%s(.*)%(([%w%.-]+@[%w-]+%.%w+)%)" },
|
||||
{ "normal", "keyword", "function", "link" } ) );
|
||||
patterns.emplace_back( SyntaxPattern( { "([%w:]+)%s(%d%d%d%d%-%d%d%-%d%d[%s%d%-+:]+)" },
|
||||
{ "normal", "keyword", "warning" } ) );
|
||||
}
|
||||
|
||||
// HACK: Gets the old font style to restore it when the tooltip is hidden
|
||||
UITooltip* tooltip = editor->createTooltip();
|
||||
if ( tooltip == nullptr )
|
||||
@@ -181,15 +265,10 @@ void GitPlugin::displayTooltip( UICodeEditor* editor, const Git::Blame& blame,
|
||||
tooltip->setDontAutoHideOnMouseMove( true );
|
||||
tooltip->setUsingCustomStyling( true );
|
||||
tooltip->setData( String::hash( "git" ) );
|
||||
tooltip->setBackgroundColor( editor->getColorScheme().getEditorColor( "background"_sst ) );
|
||||
|
||||
std::vector<SyntaxPattern> patterns;
|
||||
patterns.emplace_back( SyntaxPattern( { "([%w:]+)%s(%x+)%s%((%x+)%)" },
|
||||
{ "normal", "keyword", "number", "number" } ) );
|
||||
patterns.emplace_back( SyntaxPattern( { "([%w:]+)%s(.*)%(([%w%.-]+@[%w-]+%.%w+)%)" },
|
||||
{ "normal", "keyword", "function", "link" } ) );
|
||||
patterns.emplace_back( SyntaxPattern( { "([%w:]+)%s(%d%d%d%d%-%d%d%-%d%d[%s%d%-:]+)" },
|
||||
{ "normal", "keyword", "warning" } ) );
|
||||
tooltip->getUIStyle()->setStyleSheetProperty( StyleSheetProperty(
|
||||
"background-color",
|
||||
editor->getColorScheme().getEditorColor( "background"_sst ).toRgbaString(), true,
|
||||
StyleSheetSelectorRule::SpecificityImportant ) );
|
||||
|
||||
SyntaxDefinition syntaxDef( "custom_build", {}, std::move( patterns ) );
|
||||
|
||||
@@ -251,7 +330,7 @@ void GitPlugin::blame( UICodeEditor* editor ) {
|
||||
}
|
||||
mThreadPool->run( [this, editor]() {
|
||||
auto blame = mGit->blame( editor->getDocument().getFilePath(),
|
||||
editor->getDocument().getSelection().start().line() );
|
||||
editor->getDocument().getSelection().start().line() + 1 );
|
||||
editor->runOnMainThread( [this, editor, blame] {
|
||||
displayTooltip(
|
||||
editor, blame,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../plugin.hpp"
|
||||
#include "../pluginmanager.hpp"
|
||||
#include "git.hpp"
|
||||
#include <eepp/ui/uilinearlayout.hpp>
|
||||
|
||||
namespace ecode {
|
||||
|
||||
@@ -42,6 +43,11 @@ class GitPlugin : public PluginBase {
|
||||
|
||||
protected:
|
||||
std::unique_ptr<Git> mGit;
|
||||
std::string mGitBranch;
|
||||
Git::Status mGitStatus;
|
||||
UILinearLayout* mStatusBar{ nullptr };
|
||||
UIPushButton* mStatusButton{ nullptr };
|
||||
Time mRefreshFreq{ Seconds( 5 ) };
|
||||
|
||||
GitPlugin( PluginManager* pluginManager, bool sync );
|
||||
|
||||
@@ -49,8 +55,7 @@ class GitPlugin : public PluginBase {
|
||||
|
||||
PluginRequestHandle processMessage( const PluginMessage& msg );
|
||||
|
||||
void displayTooltip( UICodeEditor* editor, const Git::Blame& blame,
|
||||
const Vector2f& position );
|
||||
void displayTooltip( UICodeEditor* editor, const Git::Blame& blame, const Vector2f& position );
|
||||
|
||||
void hideTooltip( UICodeEditor* editor );
|
||||
|
||||
@@ -71,6 +76,12 @@ class GitPlugin : public PluginBase {
|
||||
Color mOldBackgroundColor;
|
||||
|
||||
void blame( UICodeEditor* editor );
|
||||
|
||||
void updateStatusBar();
|
||||
|
||||
void updateUI();
|
||||
|
||||
void updateUINow();
|
||||
};
|
||||
|
||||
} // namespace ecode
|
||||
|
||||
Reference in New Issue
Block a user