More git plugin fixes.

UITabWidget minor fix.
This commit is contained in:
Martín Lucas Golini
2024-01-25 23:35:47 -03:00
parent fdd8df9123
commit 80b6a4ea82
9 changed files with 117 additions and 60 deletions
+9
View File
@@ -1612,6 +1612,14 @@ void TextDocument::deleteToNextWord() {
mergeSelection();
}
void TextDocument::deleteWord() {
for ( size_t i = 0; i < mSelection.size(); ++i ) {
moveTo( i, previousWordBoundary( getSelectionIndex( i ).start() ) );
deleteTo( i, nextWordBoundary( getSelectionIndex( i ).start() ) );
}
mergeSelection();
}
void TextDocument::deleteCurrentLine() {
BoolScopedOpOptional op( !mDoingTextInput, mDoingTextInput, true );
for ( size_t i = 0; i < mSelection.size(); ++i ) {
@@ -2923,6 +2931,7 @@ void TextDocument::initializeCommands() {
mCommands["delete-to-next-char"] = [this] { deleteToNextChar(); };
mCommands["delete-current-line"] = [this] { deleteCurrentLine(); };
mCommands["delete-selection"] = [this] { deleteSelection(); };
mCommands["delete-word"] = [this] { deleteWord(); };
mCommands["move-to-previous-char"] = [this] { moveToPreviousChar(); };
mCommands["move-to-previous-word"] = [this] { moveToPreviousWord(); };
mCommands["move-to-next-char"] = [this] { moveToNextChar(); };
+8
View File
@@ -139,6 +139,14 @@ void UIConsole::setMenuIconSize( size_t menuIconSize ) {
mMenuIconSize = menuIconSize;
}
KeyBindings& UIConsole::getKeyBindings() {
return mKeyBindings;
}
TextDocument& UIConsole::getDoc() {
return mDoc;
}
Font* UIConsole::getFont() const {
return mFontStyleConfig.Font;
}
+25 -22
View File
@@ -123,7 +123,7 @@ void UITabWidget::setContainerSize() {
Float totalSize = totalTabsWidth > mSize.getWidth() ? totalTabsWidth : mSize.getWidth();
mTabBar->setPixelsSize( totalSize - mPaddingPx.Left - mPaddingPx.Right,
PixelDensity::dpToPx( mStyleConfig.TabHeight ) );
mTabBar->setPosition( mPadding.Left, mPadding.Top );
mTabBar->setPixelsPosition( mPaddingPx.Left, mPaddingPx.Top );
mNodeContainer->setPosition( mPadding.Left, mPadding.Top + mStyleConfig.TabHeight );
Sizef s( mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right,
mSize.getHeight() - PixelDensity::dpToPx( mStyleConfig.TabHeight ) -
@@ -472,6 +472,8 @@ void UITabWidget::orderTabs() {
posTabs();
updateScroll( true );
invalidateDraw();
}
@@ -1065,31 +1067,32 @@ void UITabWidget::updateScrollBar() {
}
void UITabWidget::updateScroll( bool updateFocus ) {
if ( mTabScroll->isVisible() ) {
mTabBar->setPixelsPosition(
{ mPaddingPx.Left - mTabScroll->getValue(), mTabBar->getPixelsPosition().y } );
mTabScroll->setPixelsPosition(
{ -mTabBar->getPixelsPosition().x, mTabScroll->getPixelsPosition().y } );
if ( !mTabScroll->isVisible() )
return;
if ( updateFocus && mTabSelected ) {
Rectf r = mTabScroll->getRectBox();
Rectf r2 = mTabSelected->getRectBox();
mTabBar->setPixelsPosition( mPaddingPx.Left - mTabScroll->getValue(),
mTabBar->getPixelsPosition().y );
mTabScroll->setPixelsPosition( -mTabBar->getPixelsPosition().x,
mTabScroll->getPixelsPosition().y );
if ( !( r.Left <= r2.Left && r.Right >= r2.Right ) ) {
size_t pIndex = mFocusHistory.size() >= 2
? getTabIndex( mFocusHistory.at( mFocusHistory.size() - 2 ) )
: getTabIndex( mFocusHistory.back() );
if ( updateFocus && mTabSelected ) {
Rectf r = mTabScroll->getRectBox();
Rectf r2 = mTabSelected->getRectBox();
Float x = mTabSelectedIndex > pIndex
? eeclamp( mTabSelected->getPixelsPosition().x +
mTabSelected->getPixelsSize().getWidth() -
mTabScroll->getPixelsSize().getWidth(),
0.f, mTabScroll->getMaxValue() )
: eeclamp( mTabSelected->getPixelsPosition().x, 0.f,
mTabScroll->getMaxValue() );
if ( !( r.Left <= r2.Left && r.Right >= r2.Right ) ) {
size_t pIndex = mFocusHistory.size() >= 2
? getTabIndex( mFocusHistory.at( mFocusHistory.size() - 2 ) )
: getTabIndex( mFocusHistory.back() );
mTabScroll->setValue( x );
}
Float x = mTabSelectedIndex > pIndex
? eeclamp( mTabSelected->getPixelsPosition().x +
mTabSelected->getPixelsSize().getWidth() -
mTabScroll->getPixelsSize().getWidth(),
0.f, mTabScroll->getMaxValue() )
: eeclamp( mTabSelected->getPixelsPosition().x, 0.f,
mTabScroll->getMaxValue() );
mTabScroll->setValue( x );
}
}
}
+1 -4
View File
@@ -67,7 +67,7 @@ int Git::git( const std::string& args, const std::string& projectDir, std::strin
p.readAllStdOut( buf );
int retCode;
p.join( &retCode );
Log::debug( "GitPlugin run: %s %s", mGitPath, args );
Log::info( "GitPlugin run: %s %s", mGitPath, args );
return retCode;
}
@@ -86,9 +86,6 @@ bool Git::isGitRepo( const std::string& projectDir ) {
std::string Git::branch( const std::string& projectDir ) {
std::string buf;
if ( EXIT_SUCCESS == git( "symbolic-ref --short HEAD", projectDir, buf ) )
return String::rTrim( buf, '\n' );
if ( EXIT_SUCCESS == git( "rev-parse --abbrev-ref HEAD", projectDir, buf ) )
return String::rTrim( buf, '\n' );
+65 -33
View File
@@ -1,6 +1,7 @@
#include "gitplugin.hpp"
#include <eepp/graphics/primitives.hpp>
#include <eepp/system/filesystem.hpp>
#include <eepp/system/luapattern.hpp>
#include <eepp/system/scopedop.hpp>
#include <eepp/ui/doc/syntaxdefinitionmanager.hpp>
#include <eepp/ui/uidropdownlist.hpp>
@@ -628,11 +629,16 @@ void GitPlugin::updateStatusBarSync() {
->setEnabled( !mGitContentView->isEnabled() );
if ( !mGit->getGitFolder().empty() ) {
Lock l( mGitStatusMutex );
mStatusTree->setModel( GitStatusModel::asModel( mGitStatus.files, this ) );
{
Lock l( mGitStatusMutex );
mStatusTree->setModel( GitStatusModel::asModel( mGitStatus.files, this ) );
}
mStatusTree->expandAll();
}
if ( !mStatusBarDisplayBranch )
return;
if ( !mStatusBar )
getUISceneNode()->bind( "status_bar", mStatusBar );
if ( !mStatusBar )
@@ -702,34 +708,32 @@ void GitPlugin::updateStatusBarSync() {
}
void GitPlugin::updateStatus( bool force ) {
if ( !mGit || !mGitFound || !mStatusBarDisplayBranch || mRunningUpdateStatus )
if ( !mGit || !mGitFound || mRunningUpdateStatus )
return;
mRunningUpdateStatus++;
mThreadPool->run(
[this, force] {
if ( !mGit )
if ( !mGit || mGit->getGitFolder().empty() )
return;
if ( !mGit->getGitFolder().empty() ) {
auto prevBranch = mGitBranches;
{
Lock l( mGitBranchMutex );
mGitBranches = mGit->branches( repos() );
}
Git::Status prevGitStatus;
{
Lock l( mGitStatusMutex );
prevGitStatus = mGitStatus;
}
Git::Status newGitStatus = mGit->status( mStatusRecurseSubmodules );
{
Lock l( mGitStatusMutex );
mGitStatus = std::move( newGitStatus );
if ( !force && mGitBranches == prevBranch && mGitStatus == prevGitStatus )
return;
}
} else if ( !mStatusButton ) {
return;
decltype( mGitBranches ) prevBranch;
{
auto branches = mGit->branches( repos() );
Lock l( mGitBranchMutex );
prevBranch = mGitBranches;
mGitBranches = std::move( branches );
}
Git::Status prevGitStatus;
{
Lock l( mGitStatusMutex );
prevGitStatus = mGitStatus;
}
Git::Status newGitStatus = mGit->status( mStatusRecurseSubmodules );
{
Lock l( mGitStatusMutex );
mGitStatus = std::move( newGitStatus );
if ( !force && mGitBranches == prevBranch && mGitStatus == prevGitStatus )
return;
}
getUISceneNode()->runOnMainThread( [this] { updateStatusBarSync(); } );
@@ -1004,7 +1008,7 @@ void GitPlugin::branchDelete( Git::Branch branch ) {
}
void GitPlugin::pull() {
runAsync( [this]() { return mGit->pull( repoSelected() ); }, true, true );
runAsync( [this]() { return mGit->pull( repoSelected() ); }, true, true, true );
}
void GitPlugin::push() {
@@ -1023,7 +1027,7 @@ void GitPlugin::push() {
}
void GitPlugin::fetch() {
runAsync( [this]() { return mGit->fetch( repoSelected() ); }, true, true );
runAsync( [this]() { return mGit->fetch( repoSelected() ); }, true, true, true );
}
void GitPlugin::branchCreate() {
@@ -1079,18 +1083,45 @@ void GitPlugin::fastForwardMerge( Git::Branch branch ) {
// Branch operations
// File operations
static bool isPath( const std::string& file ) {
bool ret = !file.empty() && file[0] == '/';
#if EE_PLATFORM == EE_PLATFORM_WIN
if ( !ret )
ret = LuaPattern::matches( file, "%w:[\\/][\\/]" );
#endif
return ret;
}
std::vector<std::string> GitPlugin::fixFilePaths( const std::vector<std::string>& files ) {
std::vector<std::string> paths;
paths.reserve( files.size() );
for ( const auto& file : files ) {
if ( !isPath( file ) ) {
paths.push_back( mProjectPath + file );
} else {
paths.push_back( file );
}
}
return paths;
}
void GitPlugin::stage( const std::vector<std::string>& files ) {
if ( files.empty() )
return;
runAsync( [this, files]() { return mGit->add( files, mGit->repoPath( files[0] ) ); }, true,
false );
runAsync(
[this, files]() { return mGit->add( fixFilePaths( files ), mGit->repoPath( files[0] ) ); },
true, false );
}
void GitPlugin::unstage( const std::vector<std::string>& files ) {
if ( files.empty() )
return;
runAsync( [this, files]() { return mGit->reset( files, mGit->repoPath( files[0] ) ); }, true,
false );
runAsync(
[this, files]() {
return mGit->reset( fixFilePaths( files ), mGit->repoPath( files[0] ) );
},
true, false );
}
// File operations
@@ -1197,14 +1228,15 @@ void GitPlugin::updateBranches( bool force ) {
if ( !mGit || mGit->getGitFolder().empty() )
return;
auto prevBranch = mGitBranches;
mGit->getSubModules();
decltype( mGitBranches ) prevBranch;
{
Lock l( mGitBranchMutex );
prevBranch = mGitBranches;
mGitBranches = mGit->branches( repos() );
}
mGit->getSubModules();
auto branches = mGit->getAllBranchesAndTags( Git::RefType::All, {}, repoSelected() );
auto hash = hashBranches( branches );
auto model = GitBranchModel::asModel( std::move( branches ), hash, this );
@@ -179,6 +179,8 @@ class GitPlugin : public PluginBase {
const std::string& icon = "" );
std::string repoSelected();
std::vector<std::string> fixFilePaths( const std::vector<std::string>& files );
};
} // namespace ecode