mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-11 17:17:42 +03:00
Added Git data models.
Small base Model clean up.
This commit is contained in:
@@ -49,8 +49,6 @@ class CSSPropertiesModel final : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
CSSPropertiesModel() {}
|
||||
|
||||
explicit CSSPropertiesModel( UIWidget* widget ) { setWidget( widget ); }
|
||||
|
||||
@@ -233,8 +233,6 @@ class EE_API DiskDrivesModel : public Model {
|
||||
|
||||
virtual Variant data( const ModelIndex& index, ModelRole role = ModelRole::Display ) const;
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
private:
|
||||
explicit DiskDrivesModel( const std::vector<std::string>& data ) : mData( data ) {}
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@ template <typename T> class ItemListModel final : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
private:
|
||||
const std::vector<T>& mData;
|
||||
};
|
||||
@@ -84,8 +82,6 @@ template <typename K, typename V> class ItemPairListModel final : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
virtual bool isEditable( const ModelIndex& ) const { return mIsEditable; }
|
||||
|
||||
void setIsEditable( bool isEditable ) { mIsEditable = isEditable; }
|
||||
@@ -135,8 +131,6 @@ template <typename T> class ItemListOwnerModel final : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
virtual bool isEditable( const ModelIndex& ) const { return mIsEditable; }
|
||||
|
||||
void setIsEditable( bool isEditable ) { mIsEditable = isEditable; }
|
||||
@@ -196,8 +190,6 @@ template <typename K, typename V> class ItemPairListOwnerModel final : public Mo
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
virtual bool isEditable( const ModelIndex& ) const { return mIsEditable; }
|
||||
|
||||
void setIsEditable( bool isEditable ) { mIsEditable = isEditable; }
|
||||
@@ -267,8 +259,6 @@ template <typename V> class ItemVectorListOwnerModel final : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
virtual bool isEditable( const ModelIndex& ) const { return mIsEditable; }
|
||||
|
||||
void setIsEditable( bool isEditable ) { mIsEditable = isEditable; }
|
||||
|
||||
@@ -70,7 +70,7 @@ class EE_API Model {
|
||||
|
||||
virtual Variant data( const ModelIndex&, ModelRole = ModelRole::Display ) const = 0;
|
||||
|
||||
virtual void update() = 0;
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
virtual ModelIndex parentIndex( const ModelIndex& ) const { return {}; }
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ class EE_API WidgetTreeModel : public Model {
|
||||
|
||||
virtual ModelIndex parentIndex( const ModelIndex& ) const override;
|
||||
|
||||
virtual void update() override;
|
||||
|
||||
ModelIndex getRoot() const;
|
||||
|
||||
ModelIndex getModelIndex( const Node* node ) const;
|
||||
|
||||
@@ -91,10 +91,6 @@ ModelIndex WidgetTreeModel::parentIndex( const ModelIndex& index ) const {
|
||||
return createIndex( node->getParent()->getNodeIndex(), 0, node->getParent() );
|
||||
}
|
||||
|
||||
void WidgetTreeModel::update() {
|
||||
onModelUpdate();
|
||||
}
|
||||
|
||||
ModelIndex WidgetTreeModel::getRoot() const {
|
||||
return createIndex( 0, 0, mRoot );
|
||||
}
|
||||
|
||||
@@ -332,8 +332,6 @@ class HealthModel : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
virtual bool classModelRoleEnabled() { return true; }
|
||||
|
||||
const FeaturesHealth::LangHealth& getHealthRow( size_t idx ) {
|
||||
|
||||
@@ -23,8 +23,8 @@ class Git {
|
||||
std::size_t line{ 0 };
|
||||
};
|
||||
|
||||
enum class FileStatus {
|
||||
Unknown,
|
||||
enum class FileStatus : char {
|
||||
Unknown = ' ',
|
||||
Modified = 'M',
|
||||
Added = 'A',
|
||||
Renamed = 'R',
|
||||
@@ -34,6 +34,7 @@ class Git {
|
||||
Untracked = '?',
|
||||
ModifiedSubmodule = 'm',
|
||||
};
|
||||
|
||||
struct DiffFile {
|
||||
std::string file;
|
||||
int inserts{ 0 };
|
||||
@@ -45,10 +46,12 @@ class Git {
|
||||
}
|
||||
};
|
||||
|
||||
using FilesStatus = std::map<std::string, DiffFile>;
|
||||
|
||||
struct Status {
|
||||
int totalInserts{ 0 };
|
||||
int totalDeletions{ 0 };
|
||||
std::map<std::string, DiffFile> files;
|
||||
FilesStatus files;
|
||||
|
||||
bool operator==( const Status& other ) const {
|
||||
return totalInserts == other.totalInserts && totalDeletions == other.totalDeletions &&
|
||||
@@ -72,6 +75,23 @@ class Git {
|
||||
All = 0x7,
|
||||
};
|
||||
|
||||
static constexpr const char* HEAD = "head";
|
||||
static constexpr const char* REMOTE = "remote";
|
||||
static constexpr const char* TAG = "tag";
|
||||
static constexpr const char* ALL = "all";
|
||||
|
||||
static const char* refTypeToString( RefType type ) {
|
||||
switch ( type ) {
|
||||
case Head:
|
||||
return HEAD;
|
||||
case Remote:
|
||||
return REMOTE;
|
||||
case Tag:
|
||||
return TAG;
|
||||
case All:
|
||||
return ALL;
|
||||
}
|
||||
}
|
||||
struct Branch {
|
||||
/** Branch name */
|
||||
std::string name;
|
||||
@@ -81,6 +101,8 @@ class Git {
|
||||
RefType type = All;
|
||||
/** last commit on this branch, may be empty **/
|
||||
std::string lastCommit;
|
||||
|
||||
const char* typeStr() const { return refTypeToString( type ); }
|
||||
};
|
||||
|
||||
Git( const std::string& projectDir = "", const std::string& gitPath = "" );
|
||||
|
||||
@@ -4,9 +4,13 @@
|
||||
#include "../plugin.hpp"
|
||||
#include "../pluginmanager.hpp"
|
||||
#include "git.hpp"
|
||||
#include <eepp/ui/models/model.hpp>
|
||||
#include <eepp/ui/uilinearlayout.hpp>
|
||||
#include <optional>
|
||||
|
||||
using namespace EE::UI::Models;
|
||||
using namespace EE::UI;
|
||||
|
||||
namespace ecode {
|
||||
|
||||
class Git;
|
||||
@@ -97,6 +101,72 @@ class GitPlugin : public PluginBase {
|
||||
void updateUINow( bool force = false );
|
||||
};
|
||||
|
||||
class GitBranchModel : public Model {
|
||||
public:
|
||||
enum Column { Name, Remote, Type, LastCommit };
|
||||
|
||||
GitBranchModel( std::vector<Git::Branch>&& branches ) : mBranches( std::move( branches ) ) {}
|
||||
|
||||
size_t rowCount( const ModelIndex& ) const { return mBranches.size(); }
|
||||
|
||||
size_t columnCount( const ModelIndex& ) const { return 4; }
|
||||
|
||||
Variant data( const ModelIndex& index, ModelRole role ) const {
|
||||
if ( role == ModelRole::Display && index.row() < mBranches.size() ) {
|
||||
const Git::Branch& branch = mBranches[index.row()];
|
||||
switch ( index.column() ) {
|
||||
case Column::Name:
|
||||
return branch.name.c_str();
|
||||
case Column::Remote:
|
||||
return branch.remote.c_str();
|
||||
case Column::Type:
|
||||
return branch.typeStr();
|
||||
case Column::LastCommit:
|
||||
return branch.lastCommit.c_str();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<Git::Branch> mBranches;
|
||||
};
|
||||
|
||||
class GitStatusModel : public Model {
|
||||
public:
|
||||
enum Column { File, Inserted, Removed, FileStatus };
|
||||
|
||||
GitStatusModel( Git::FilesStatus&& status ) {
|
||||
mStatus.reserve( status.size() );
|
||||
for ( auto& s : status )
|
||||
mStatus.emplace_back( std::move( s.second ) );
|
||||
}
|
||||
|
||||
size_t rowCount( const ModelIndex& ) const { return mStatus.size(); }
|
||||
|
||||
size_t columnCount( const ModelIndex& ) const { return 4; }
|
||||
|
||||
Variant data( const ModelIndex& index, ModelRole role ) const {
|
||||
if ( role == ModelRole::Display && index.row() < mStatus.size() ) {
|
||||
const Git::DiffFile& s = mStatus[index.row()];
|
||||
switch ( index.column() ) {
|
||||
case Column::File:
|
||||
return s.file.c_str();
|
||||
case Column::Inserted:
|
||||
return s.inserts;
|
||||
case Column::Removed:
|
||||
return s.deletes;
|
||||
case Column::FileStatus:
|
||||
return Variant( std::string( static_cast<char>( s.status ), 1 ) );
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<Git::DiffFile> mStatus;
|
||||
};
|
||||
|
||||
} // namespace ecode
|
||||
|
||||
#endif // ECODE_GITPLUGIN_HPP
|
||||
|
||||
@@ -58,8 +58,6 @@ class LSPLocationModel : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
void update() override { onModelUpdate(); }
|
||||
|
||||
protected:
|
||||
struct Location {
|
||||
LSPLocation loc;
|
||||
@@ -108,8 +106,6 @@ class LSPCodeActionModel : public Model {
|
||||
|
||||
bool hasCodeActions() const { return !mCodeActions.empty(); }
|
||||
|
||||
void update() override { onModelUpdate(); }
|
||||
|
||||
const LSPCodeAction& getCodeAction( size_t row ) const { return mCodeActions[row]; }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -398,8 +398,6 @@ class PluginsModel : public Model {
|
||||
|
||||
virtual Variant data( const ModelIndex& index, ModelRole role = ModelRole::Display ) const;
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
PluginManager* getManager() const;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -60,8 +60,6 @@ class FileListModel : public Model {
|
||||
mIcons[idx] = icon;
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
protected:
|
||||
std::vector<std::string> mFiles;
|
||||
std::vector<std::string> mNames;
|
||||
|
||||
@@ -182,8 +182,6 @@ class ProjectSearch {
|
||||
return Variant( EMPTY );
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
const Result& getResult() const { return mResult; }
|
||||
|
||||
void removeLastNewLineCharacter();
|
||||
|
||||
@@ -437,8 +437,6 @@ class StatusMessageModel : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
virtual std::string columnName( const size_t& idx ) const {
|
||||
switch ( idx ) {
|
||||
case 2:
|
||||
|
||||
@@ -63,8 +63,6 @@ class OutputParserModel final : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void update() { onModelUpdate(); }
|
||||
|
||||
private:
|
||||
std::vector<ProjectBuildOutputParserConfig>& mData;
|
||||
std::function<String( const std::string&, const String& )> i18n;
|
||||
|
||||
@@ -50,8 +50,6 @@ class LSPSymbolInfoModel : public Model {
|
||||
return {};
|
||||
}
|
||||
|
||||
void update() override { onModelUpdate(); }
|
||||
|
||||
const LSPSymbolInformationList& getInfo() const { return mInfo; }
|
||||
|
||||
LSPSymbolInformation at( const size_t& idx ) {
|
||||
|
||||
Reference in New Issue
Block a user