Skip to content

Commit

Permalink
More Git plugin WIP. Added commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Jan 23, 2024
1 parent a11b6ef commit bdd018f
Show file tree
Hide file tree
Showing 14 changed files with 348 additions and 126 deletions.
26 changes: 15 additions & 11 deletions include/eepp/ui/uimessagebox.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#ifndef EE_UICUIMESSAGEBOX_HPP
#define EE_UICUIMESSAGEBOX_HPP

#include <eepp/ui/uilayout.hpp>
#include <eepp/ui/uipushbutton.hpp>
#include <eepp/ui/uitextinput.hpp>
#include <eepp/ui/uitextview.hpp>
#include <eepp/ui/uiwindow.hpp>

namespace EE { namespace UI {

class UITextEdit;
class UITextInput;
class UILayout;
class UIPushButton;

#define UI_MESSAGE_BOX_DEFAULT_FLAGS \
UI_WIN_CLOSE_BUTTON | UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS | UI_WIN_MODAL | \
UI_WIN_SHARE_ALPHA_WITH_CHILDS

class EE_API UIMessageBox : public UIWindow {
public:
enum Type { OK_CANCEL, YES_NO, RETRY_CANCEL, OK, INPUT };
enum Type { OK_CANCEL, YES_NO, RETRY_CANCEL, OK, INPUT, TEXT_EDIT };

static UIMessageBox* New( const Type& type, const String& message,
const Uint32& windowFlags = UI_MESSAGE_BOX_DEFAULT_FLAGS );
Expand Down Expand Up @@ -43,16 +44,19 @@ class EE_API UIMessageBox : public UIWindow {

UITextInput* getTextInput() const;

UITextEdit* getTextEdit() const;

UILayout* getLayoutCont() const;

protected:
protected:
Type mMsgBoxType;
UITextView* mTextBox;
UIPushButton* mButtonOK;
UIPushButton* mButtonCancel;
UITextInput* mTextInput;
UITextView* mTextBox{ nullptr };
UIPushButton* mButtonOK{ nullptr };
UIPushButton* mButtonCancel{ nullptr };
UITextInput* mTextInput{ nullptr };
UITextEdit* mTextEdit{ nullptr };
KeyBindings::Shortcut mCloseShortcut;
UILayout* mLayoutCont;
UILayout* mLayoutCont{ nullptr };

virtual void onWindowReady();

Expand Down
3 changes: 1 addition & 2 deletions include/eepp/ui/uiwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#define EE_UICUIWINDOW_HPP

#include <eepp/ui/keyboardshortcut.hpp>
#include <eepp/ui/uipushbutton.hpp>
#include <eepp/ui/uitextview.hpp>
#include <eepp/ui/uiwidget.hpp>

namespace EE { namespace Graphics {
Expand All @@ -12,6 +10,7 @@ class FrameBuffer;

namespace EE { namespace UI {

class UITextView;
class UISceneNode;

enum UIWindowFlags {
Expand Down
32 changes: 17 additions & 15 deletions src/eepp/ui/doc/syntaxdefinitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,21 +1124,23 @@ static void addCMake() {
for ( const auto& keyword : cmake_literals )
cmake_symbols[keyword] = "literal";

SyntaxDefinitionManager::instance()->add( { "CMake",
{ "%.cmake$", "CMakeLists.txt$" },
{
{ { "#", "[^\\]\n" }, "comment" },
{ { "\"", "\"", "\\" }, "string" },
{ { "'", "'", "\\" }, "string" },
{ { "[%a_][%w_]*%s?%f[(]" }, "function" },
{ { "CMAKE_[%w%d_]+" }, "keyword" },
{ { "CTEST_[%w%d_]+" }, "keyword" },
{ { "%u[%u%d_]*_[%u%d_]+" }, "keyword" },
{ { "%${[%a_][%w_]*%}" }, "keyword2" },
{ { "[%a_][%w_]*" }, "symbol" },
},
std::move( cmake_symbols ),
"//" } );
SyntaxDefinitionManager::instance()->add(
{ "CMake",
{ "%.cmake$", "CMakeLists.txt$" },
{
{ { "#", "[^\\]\n" }, "comment" },
{ { "\"", "\"", "\\" }, "string" },
{ { "'", "'", "\\" }, "string" },
{ { "[%a_][%w_]*%s?%f[(]" }, "function" },
{ { "CMAKE_[%w%d_]+" }, "keyword" },
{ { "CTEST_[%w%d_]+" }, "keyword" },
{ { "%u[%u%d_]*_[%u%d_]+" }, "keyword" },
{ { "%${[%a_][%w_]*%}" }, "keyword2" },
{ { "[%a_][%w_]*" }, "symbol" },
},
std::move( cmake_symbols ),
"//",
{ "^cmake_minimum_required.*%c" } } );
}

static void addJSX() {
Expand Down
18 changes: 17 additions & 1 deletion src/eepp/ui/uimessagebox.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#include <eepp/ui/uilayout.hpp>
#include <eepp/ui/uilinearlayout.hpp>
#include <eepp/ui/uimessagebox.hpp>
#include <eepp/ui/uipushbutton.hpp>
#include <eepp/ui/uiscenenode.hpp>
#include <eepp/ui/uistyle.hpp>
#include <eepp/ui/uitextedit.hpp>
#include <eepp/ui/uitextinput.hpp>
#include <eepp/ui/uitextview.hpp>
#include <eepp/ui/uitheme.hpp>

namespace EE { namespace UI {
Expand All @@ -12,7 +17,7 @@ UIMessageBox* UIMessageBox::New( const Type& type, const String& message,
}

UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint32& windowFlags ) :
UIWindow(), mMsgBoxType( type ), mTextInput( NULL ), mCloseShortcut( KEY_UNKNOWN ) {
UIWindow(), mMsgBoxType( type ), mCloseShortcut( KEY_UNKNOWN ) {
mVisible = false;

mStyleConfig.WinFlags = windowFlags;
Expand Down Expand Up @@ -41,6 +46,12 @@ UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint3
->setParent( vlay )
->addEventListener( Event::OnPressEnter,
[this]( const Event* ) { sendCommonEvent( Event::OnConfirm ); } );
} else if ( mMsgBoxType == TEXT_EDIT ) {
mTextEdit = UITextEdit::New();
mTextEdit->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed )
->setLayoutMargin( Rectf( 0, 4, 0, 4 ) )
->setSize( PixelDensity::dpToPx( Vector2f{ 400, 100 } ) )
->setParent( vlay );
}

UILinearLayout* hlay = UILinearLayout::NewHorizontal();
Expand All @@ -58,6 +69,7 @@ UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint3

switch ( mMsgBoxType ) {
case UIMessageBox::INPUT:
case UIMessageBox::TEXT_EDIT:
case UIMessageBox::OK_CANCEL: {
mButtonOK->setText( getTranslatorString( "@string/msg_box_ok", "Ok" ) );
mButtonCancel->setText( getTranslatorString( "@string/msg_box_cancel", "Cancel" ) );
Expand Down Expand Up @@ -180,6 +192,10 @@ UITextInput* UIMessageBox::getTextInput() const {
return mTextInput;
}

UITextEdit* UIMessageBox::getTextEdit() const {
return mTextEdit;
}

UILayout* UIMessageBox::getLayoutCont() const {
return mLayoutCont;
}
Expand Down
1 change: 1 addition & 0 deletions src/eepp/ui/uiscenenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <eepp/core/string.hpp>
#include <eepp/graphics/fontmanager.hpp>
#include <eepp/graphics/fonttruetype.hpp>
#include <eepp/graphics/text.hpp>
#include <eepp/network/http.hpp>
#include <eepp/network/uri.hpp>
#include <eepp/scene/scenemanager.hpp>
Expand Down
3 changes: 3 additions & 0 deletions src/eepp/ui/uiwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
#include <eepp/scene/scenenode.hpp>
#include <eepp/ui/css/propertydefinition.hpp>
#include <eepp/ui/uilinearlayout.hpp>
#include <eepp/ui/uipushbutton.hpp>
#include <eepp/ui/uirelativelayout.hpp>
#include <eepp/ui/uiscenenode.hpp>
#include <eepp/ui/uistyle.hpp>
#include <eepp/ui/uitextview.hpp>
#include <eepp/ui/uithememanager.hpp>
#include <eepp/ui/uiwindow.hpp>

#define PUGIXML_HEADER_ONLY
#include <pugixml/pugixml.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <eepp/maps/mapeditor/tilemapproperties.hpp>
#include <eepp/scene/scenemanager.hpp>
#include <eepp/ui/uipushbutton.hpp>
#include <eepp/ui/uiscenenode.hpp>
#include <eepp/ui/uithememanager.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/modules/maps/src/eepp/maps/mapeditor/uigotypenew.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <eepp/maps/mapeditor/uigotypenew.hpp>
#include <eepp/scene/scenemanager.hpp>
#include <eepp/ui/uipushbutton.hpp>
#include <eepp/ui/uiscenenode.hpp>
#include <eepp/ui/uithememanager.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/modules/maps/src/eepp/maps/mapeditor/uimaplayernew.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <eepp/maps/mapeditor/uimaplayernew.hpp>
#include <eepp/scene/scenemanager.hpp>
#include <eepp/ui/uipushbutton.hpp>
#include <eepp/ui/uiscenenode.hpp>
#include <eepp/ui/uithememanager.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/tools/ecode/iconmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ void IconManager::init( UISceneNode* sceneNode, FontTrueType* iconFont, FontTrue
{ "repo", 0xea62 },
{ "repo-pull", 0xeb40 },
{ "repo-push", 0xeb41 },
{ "repo-forked", 0xea63 },
{ "tag", 0xea66 } };

for ( const auto& icon : codIcons )
Expand Down
54 changes: 40 additions & 14 deletions src/tools/ecode/plugins/git/git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,30 @@ Git::CheckoutResult Git::checkoutAndCreateLocalBranch( const std::string& remote
return checkout( newBranchName, projectDir );
}

Git::Result Git::add( const std::string& file, const std::string& projectDir ) {
return gitSimple( String::format( "add --force -- \"%s\"", file ), projectDir );
static std::string asList( std::vector<std::string>& files ) {
for ( auto& file : files )
file = "\"" + file + "\"";
return String::join( files );
}

Git::Result Git::add( std::vector<std::string> files, const std::string& projectDir ) {
return gitSimple( String::format( "add --force -- %s", asList( files ) ), projectDir );
}

Git::Result Git::restore( const std::string& file, const std::string& projectDir ) {
return gitSimple( String::format( "restore \"%s\"", file ), projectDir );
}

Git::Result Git::reset( const std::string& file, const std::string& projectDir ) {
return gitSimple( String::format( "reset -q HEAD -- \"%s\"", file ), projectDir );
Git::Result Git::reset( std::vector<std::string> files, const std::string& projectDir ) {
return gitSimple( String::format( "reset -q HEAD -- %s", asList( files ) ), projectDir );
}

Git::Result Git::createBranch( const std::string& branchName, bool _checkout,
const std::string& projectDir ) {
auto res = gitSimple( String::format( "branch --no-track %s", branchName ), projectDir );
if ( _checkout )
checkout( branchName );
return res;
}

Git::Result Git::renameBranch( const std::string& branch, const std::string& newName,
Expand Down Expand Up @@ -230,6 +244,12 @@ Git::Result Git::fastForwardMerge( const std::string& projectDir ) {
return gitSimple( "merge --no-commit --ff --ff-only", projectDir );
}

Git::Result Git::updateRef( const std::string& headBranch, const std::string& toCommit,
const std::string& projectDir ) {
return gitSimple( String::format( "update-ref refs/heads/%s %s", headBranch, toCommit ),
projectDir );
}

Git::CountResult Git::branchHistoryPosition( const std::string& localBranch,
const std::string& remoteBranch,
const std::string& projectDir ) {
Expand Down Expand Up @@ -345,16 +365,22 @@ static Git::Branch parseTag( std::string_view raw ) {
return newBranch;
}

std::vector<Git::Branch> Git::getAllBranchesAndTags( RefType ref, const std::string& projectDir ) {
std::vector<Git::Branch> Git::getAllBranchesAndTags( RefType ref, std::string_view filterBranch,
const std::string& projectDir ) {
// clang-format off
std::string args( "for-each-ref --format '%(refname) %(refname:short) %(upstream:short) %(objectname) %(upstream:track,nobracket)' --sort=v:refname" );
// clang-format on
if ( ref & RefType::Head )
args.append( " refs/heads" );
if ( ref & RefType::Remote )
args.append( " refs/remotes" );
if ( ref & RefType::Tag )
args.append( " refs/tags" );

if ( filterBranch.empty() ) {
if ( ref & RefType::Head )
args.append( " refs/heads" );
if ( ref & RefType::Remote )
args.append( " refs/remotes" );
if ( ref & RefType::Tag )
args.append( " refs/tags" );
} else {
args.append( " " + filterBranch );
}

std::vector<Branch> branches;
std::string buf;
Expand Down Expand Up @@ -406,7 +432,7 @@ bool Git::hasSubmodules( const std::string& projectDir ) {
( !mProjectPath.empty() && FileSystem::fileExists( mProjectPath + ".gitmodules" ) );
}

std::string Git::inSubModule( const std::string& file, const std::string& projectDir ) {
std::string Git::repoName( const std::string& file, const std::string& projectDir ) {
for ( const auto& subRepo : mSubModules ) {
if ( String::startsWith( file, subRepo ) && file.size() != subRepo.size() )
return subRepo;
Expand Down Expand Up @@ -454,7 +480,7 @@ Git::Status Git::status( bool recurseSubmodules, const std::string& projectDir )
if ( String::fromString( inserts, inserted ) &&
String::fromString( deletes, deleted ) && ( inserts || deletes ) ) {
auto filePath = subModulePath + file;
auto repo = inSubModule( filePath, projectDir );
auto repo = repoName( filePath, projectDir );
auto repoIt = s.files.find( repo );
if ( repoIt != s.files.end() ) {
bool found = false;
Expand Down Expand Up @@ -660,7 +686,7 @@ Git::Status Git::status( bool recurseSubmodules, const std::string& projectDir )
modifiedSubmodule = true;
else {
auto filePath = subModulePath + file;
auto repo = inSubModule( filePath, projectDir );
auto repo = repoName( filePath, projectDir );
auto repoIt = s.files.find( repo );
if ( repoIt != s.files.end() ) {
bool found = false;
Expand Down
23 changes: 15 additions & 8 deletions src/tools/ecode/plugins/git/git.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,14 @@ class Git {

Status status( bool recurseSubmodules, const std::string& projectDir = "" );

Result add( const std::string& file, const std::string& projectDir = "" );
Result add( std::vector<std::string> files, const std::string& projectDir = "" );

Result restore( const std::string& file, const std::string& projectDir = "" );

Result reset( const std::string& file, const std::string& projectDir = "" );
Result reset( std::vector<std::string> files, const std::string& projectDir = "" );

Result createBranch( const std::string& branchName, bool checkout = false,
const std::string& projectDir = "" );

Result renameBranch( const std::string& branch, const std::string& newName,
const std::string& projectDir = "" );
Expand All @@ -218,6 +221,9 @@ class Git {

Result fastForwardMerge( const std::string& projectDir = "" );

Result updateRef( const std::string& headBranch, const std::string& toCommit,
const std::string& projectDir = "" );

CountResult branchHistoryPosition( const std::string& localBranch,
const std::string& remoteBranch,
const std::string& projectDir = "" );
Expand Down Expand Up @@ -256,25 +262,26 @@ class Git {
* @brief get all local and remote branches + tags
*/
std::vector<Branch> getAllBranchesAndTags( RefType ref = RefType::All,
std::string_view filterBranch = {},
const std::string& projectDir = "" );

std::vector<std::string> fetchSubModules( const std::string& projectDir );

std::vector<std::string> getSubModules( const std::string& projectDir = "" );

std::string repoName( const std::string& file, const std::string& projectDir = "" );

bool hasSubmodules( const std::string& projectDir );

Result gitSimple( const std::string& cmd, const std::string& projectDir );

protected:
std::string mGitPath;
std::string mProjectPath;
std::string mGitFolder;
std::string mLastProjectPath;
std::vector<std::string> mSubModules;
bool mSubModulesUpdated{ false };

bool hasSubmodules( const std::string& projectDir );

std::string inSubModule( const std::string& file, const std::string& projectDir );

Result gitSimple( const std::string& cmd, const std::string& projectDir );
};

} // namespace ecode
Loading

0 comments on commit bdd018f

Please sign in to comment.