mirror of
https://github.com/Murmele/Gittyup.git
synced 2024-10-05 14:37:31 +03:00
first commit
This commit is contained in:
parent
04991eb1df
commit
c898eca8e0
@ -111,13 +111,13 @@ template <> void Config::setValue<QString>(const QString &, const QString &);
|
||||
|
||||
template <typename T>
|
||||
T Config::value(const QString &key, const T &defaultValue) const {
|
||||
static_assert(sizeof(T) == 0, "no specialization found");
|
||||
static_assert(sizeof(T) == 0, "no specialization found. Please implement specialization for this type!");
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Config::setValue(const QString &key, const T &value) {
|
||||
static_assert(sizeof(T) == 0, "no specialization found");
|
||||
static_assert(sizeof(T) == 0, "no specialization found. Please implement specialization for this type!");
|
||||
}
|
||||
|
||||
} // namespace git
|
||||
|
@ -53,7 +53,8 @@ add_library(
|
||||
TreeProxy.cpp
|
||||
TreeView.cpp
|
||||
TreeWidget.cpp
|
||||
ViewDelegate.cpp)
|
||||
ViewDelegate.cpp
|
||||
ConfigKeys.cpp)
|
||||
|
||||
target_compile_definitions(ui PRIVATE BUILD_DESCRIPTION="${BUILD_DESCRIPTION}")
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "ProgressIndicator.h"
|
||||
#include "RepoView.h"
|
||||
#include "Debug.h"
|
||||
#include "ConfigKeys.h"
|
||||
#include "app/Application.h"
|
||||
#include "conf/Settings.h"
|
||||
#include "dialogs/MergeDialog.h"
|
||||
@ -221,7 +222,7 @@ public:
|
||||
mWalker.push(mergeHead);
|
||||
}
|
||||
|
||||
if (mRefsAll) {
|
||||
if (mRefsFilter == CommitList::RefsFilter::AllRefs) {
|
||||
foreach (const git::Reference ref, mRepo.refs()) {
|
||||
if (!ref.isStash())
|
||||
mWalker.push(ref);
|
||||
@ -237,10 +238,10 @@ public:
|
||||
|
||||
void resetSettings(bool walk = false) {
|
||||
git::Config config = mRepo.appConfig();
|
||||
mRefsAll = config.value<bool>("commit.refs.all", true);
|
||||
mSortDate = config.value<bool>("commit.sort.date", true);
|
||||
mShowCleanStatus = config.value<bool>("commit.show.status", true);
|
||||
mGraphVisible = config.value<bool>("commit.graph.visible", true);
|
||||
mRefsFilter = static_cast<CommitList::RefsFilter>(config.value<int>(ConfigKeys::kRefsKey, (int)CommitList::RefsFilter::AllRefs));
|
||||
mSortDate = config.value<bool>(ConfigKeys::kSortKey, true);
|
||||
mShowCleanStatus = config.value<bool>(ConfigKeys::kStatusKey, true);
|
||||
mGraphVisible = config.value<bool>(ConfigKeys::kGraphKey, true);
|
||||
|
||||
if (walk)
|
||||
resetWalker();
|
||||
@ -557,7 +558,7 @@ private:
|
||||
|
||||
// walker settings
|
||||
bool mSuppressResetWalker{false};
|
||||
bool mRefsAll = true;
|
||||
CommitList::RefsFilter mRefsFilter{CommitList::RefsFilter::AllRefs};
|
||||
bool mSortDate = true;
|
||||
bool mShowCleanStatus = true;
|
||||
bool mGraphVisible = true;
|
||||
|
@ -25,6 +25,11 @@ class CommitList : public QListView {
|
||||
|
||||
public:
|
||||
enum Role { DiffRole = Qt::UserRole, CommitRole, GraphRole, GraphColorRole };
|
||||
enum class RefsFilter {
|
||||
AllRefs,
|
||||
SelectedRef,
|
||||
SelectedRefIgnoreMerge,
|
||||
};
|
||||
|
||||
CommitList(Index *index, QWidget *parent = nullptr);
|
||||
|
||||
|
@ -8,8 +8,10 @@
|
||||
//
|
||||
|
||||
#include "CommitToolBar.h"
|
||||
#include "CommitList.h"
|
||||
#include "ContextMenuButton.h"
|
||||
#include "RepoView.h"
|
||||
#include "ConfigKeys.h"
|
||||
#include "conf/Settings.h"
|
||||
#include "git/Config.h"
|
||||
#include <QApplication>
|
||||
@ -22,10 +24,6 @@
|
||||
|
||||
namespace {
|
||||
|
||||
const QString kRefsKey = "commit.refs.all";
|
||||
const QString kSortKey = "commit.sort.date";
|
||||
const QString kGraphKey = "commit.graph.visible";
|
||||
const QString kStatusKey = "commit.show.status";
|
||||
const QString kStyleSheet = "QToolBar {"
|
||||
" border: none"
|
||||
"}"
|
||||
@ -34,17 +32,19 @@ const QString kStyleSheet = "QToolBar {"
|
||||
" border-radius: 4px;"
|
||||
" padding-right: 12px"
|
||||
"}";
|
||||
|
||||
template <typename T>
|
||||
struct SettingsEntry {
|
||||
QString key;
|
||||
bool value;
|
||||
T value;
|
||||
};
|
||||
|
||||
using SettingsMap = QMap<QString, SettingsEntry>;
|
||||
template <typename T>
|
||||
using SettingsMap = QMap<QString, SettingsEntry<T>>;
|
||||
|
||||
template <typename T>
|
||||
class ToolButton : public QToolButton {
|
||||
public:
|
||||
ToolButton(const SettingsMap &map, CommitToolBar *parent)
|
||||
ToolButton(const SettingsMap<T> &map, CommitToolBar *parent, T defaultValue)
|
||||
: QToolButton(parent) {
|
||||
setPopupMode(QToolButton::InstantPopup);
|
||||
|
||||
@ -58,8 +58,8 @@ public:
|
||||
action->setCheckable(true);
|
||||
actions->addAction(action);
|
||||
|
||||
const SettingsEntry &entry = map.value(key);
|
||||
if (config.value<bool>(entry.key, true) == entry.value) {
|
||||
const SettingsEntry<T> &entry = map.value(key);
|
||||
if (config.value<T>(entry.key, defaultValue) == entry.value) {
|
||||
action->setChecked(true);
|
||||
setText(action->text());
|
||||
}
|
||||
@ -119,15 +119,16 @@ CommitToolBar::CommitToolBar(QWidget *parent) : QToolBar(parent) {
|
||||
setStyleSheet(kStyleSheet);
|
||||
setToolButtonStyle(Qt::ToolButtonTextOnly);
|
||||
|
||||
SettingsMap refsMap;
|
||||
refsMap.insert(tr("Show All Branches"), {kRefsKey, true});
|
||||
refsMap.insert(tr("Show Selected Branch"), {kRefsKey, false});
|
||||
addWidget(new ToolButton(refsMap, this));
|
||||
SettingsMap<int> refsMap;
|
||||
refsMap.insert(tr("Show All Branches"), {ConfigKeys::kRefsKey, (int)CommitList::RefsFilter::AllRefs});
|
||||
refsMap.insert(tr("Show Selected Branch"), {ConfigKeys::kRefsKey, (int)CommitList::RefsFilter::SelectedRef});
|
||||
refsMap.insert(tr("Show Selected Branch, Ignore Merge"), {ConfigKeys::kRefsKey, (int)CommitList::RefsFilter::SelectedRefIgnoreMerge});
|
||||
addWidget(new ToolButton<int>(refsMap, this, (int)CommitList::RefsFilter::AllRefs));
|
||||
|
||||
SettingsMap sortMap;
|
||||
sortMap.insert(tr("Sort by Date"), {kSortKey, true});
|
||||
sortMap.insert(tr("Sort Topologically"), {kSortKey, false});
|
||||
addWidget(new ToolButton(sortMap, this));
|
||||
SettingsMap<bool> sortMap;
|
||||
sortMap.insert(tr("Sort by Date"), {ConfigKeys::kSortKey, true});
|
||||
sortMap.insert(tr("Sort Topologically"), {ConfigKeys::kSortKey, false});
|
||||
addWidget(new ToolButton(sortMap, this, true));
|
||||
|
||||
QWidget *spacer = new QWidget(this);
|
||||
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
@ -145,20 +146,20 @@ CommitToolBar::CommitToolBar(QWidget *parent) : QToolBar(parent) {
|
||||
|
||||
QAction *graph = menu->addAction(tr("Show Graph"));
|
||||
graph->setCheckable(true);
|
||||
graph->setChecked(config.value<bool>(kGraphKey, true));
|
||||
graph->setChecked(config.value<bool>(ConfigKeys::kGraphKey, true));
|
||||
connect(graph, &QAction::triggered, [this](bool checked) {
|
||||
RepoView *view = RepoView::parentView(this);
|
||||
git::Config config = view->repo().appConfig();
|
||||
config.setValue(kGraphKey, checked);
|
||||
config.setValue(ConfigKeys::kGraphKey, checked);
|
||||
emit settingsChanged();
|
||||
});
|
||||
|
||||
QAction *status = menu->addAction(tr("Show Clean Status"));
|
||||
status->setCheckable(true);
|
||||
status->setChecked(config.value<bool>(kStatusKey, true));
|
||||
status->setChecked(config.value<bool>(ConfigKeys::kStatusKey, true));
|
||||
connect(status, &QAction::triggered, [this](bool checked) {
|
||||
RepoView *view = RepoView::parentView(this);
|
||||
view->repo().appConfig().setValue(kStatusKey, checked);
|
||||
view->repo().appConfig().setValue(ConfigKeys::kStatusKey, checked);
|
||||
emit settingsChanged();
|
||||
});
|
||||
|
||||
|
9
src/ui/ConfigKeys.cpp
Normal file
9
src/ui/ConfigKeys.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include <QString>
|
||||
#include "ConfigKeys.h"
|
||||
|
||||
namespace ConfigKeys {
|
||||
const QString kRefsKey = "commit.refs.all";
|
||||
const QString kSortKey = "commit.sort.date";
|
||||
const QString kGraphKey = "commit.graph.visible";
|
||||
const QString kStatusKey = "commit.show.status";
|
||||
}
|
13
src/ui/ConfigKeys.h
Normal file
13
src/ui/ConfigKeys.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef CONFIGKEYS_H
|
||||
#define CONFIGKEYS_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace ConfigKeys {
|
||||
extern const QString kRefsKey;
|
||||
extern const QString kSortKey;
|
||||
extern const QString kGraphKey;
|
||||
extern const QString kStatusKey;
|
||||
}
|
||||
|
||||
#endif // CONFIGKEYS_H
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "ReferenceWidget.h"
|
||||
#include "ExpandButton.h"
|
||||
#include "ConfigKeys.h"
|
||||
#include "git/Config.h"
|
||||
#include "git/Reference.h"
|
||||
#include "git/Repository.h"
|
||||
@ -88,7 +89,7 @@ public:
|
||||
QItemSelectionModel::SelectionFlags command) override {
|
||||
QModelIndex current = index;
|
||||
git::Reference head = mRepo.head();
|
||||
bool all = mRepo.appConfig().value<bool>("commit.refs.all", true);
|
||||
bool all = mRepo.appConfig().value<bool>(ConfigKeys::kRefsKey, true);
|
||||
git::Reference ref = index.data(Qt::UserRole).value<git::Reference>();
|
||||
if (all && ref && !ref.isHead() && !ref.isStash() && head.isValid())
|
||||
current = findReference(model(), head);
|
||||
@ -201,7 +202,7 @@ void ReferenceWidget::updateLabel(const git::Reference &ref) {
|
||||
|
||||
git::Reference ReferenceWidget::currentReference() const {
|
||||
git::Reference ref = mView->currentReference();
|
||||
bool all = mRepo.appConfig().value<bool>("commit.refs.all", true);
|
||||
bool all = mRepo.appConfig().value<bool>(ConfigKeys::kRefsKey, true);
|
||||
return (!all || (ref.isValid() && ref.isStash())) ? ref : mRepo.head();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user