Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Add: git note support (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: Hamed Masafi <hamed.masfi@gmail.com>
  • Loading branch information
HamedMasafi and Hamed Masafi authored Aug 23, 2022
1 parent aaced53 commit 9eca342
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 2.8)

project(gitklient)
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 2)
set(PROJECT_VERSION_PATCH 1)
set(PROJECT_VERSION_MINOR 3)
set(PROJECT_VERSION_PATCH 0)

add_definitions(-DGK_VERSION="${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
find_package(ECM 5.18 REQUIRED NO_MODULE)
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ ki18n_wrap_ui(
dialogs/fetchdialog.ui
dialogs/switchbranchdialog.ui
dialogs/initdialog.ui
dialogs/notedialog.ui
)

include(git/CMakeLists.txt)
Expand Down
9 changes: 9 additions & 0 deletions src/actions/branchactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "dialogs/fetchdialog.h"
#include "dialogs/filestreedialog.h"
#include "dialogs/mergedialog.h"
#include "dialogs/notedialog.h"
#include "dialogs/runnerdialog.h"
#include "diffwindow.h"
#include "git/commands/commandmerge.h"
Expand All @@ -28,6 +29,7 @@ BranchActions::BranchActions(Git::Manager *git, QWidget *parent) : AbstractActio
_actionMerge = addActionDisabled(i18n("Merge..."), this, &BranchActions::merge);
_actionDiff = addActionDisabled(i18n("Diff"), this, &BranchActions::diff);
_actionRemove = addActionDisabled(i18n("Remove..."), this, &BranchActions::remove);
_actionNote = addActionDisabled(i18n("Note..."), this, &BranchActions::note);
}

const QString &BranchActions::branchName() const
Expand All @@ -45,6 +47,7 @@ void BranchActions::setBranchName(const QString &newBranchName)
setActionEnabled(_actionMerge, true);
setActionEnabled(_actionDiff, true);
setActionEnabled(_actionRemove, true);
setActionEnabled(_actionNote, true);
}

const QString &BranchActions::otherBranch() const
Expand Down Expand Up @@ -126,3 +129,9 @@ void BranchActions::merge()
runner.exec();
}
}

void BranchActions::note()
{
NoteDialog d{_git, _branchName, _parent};
d.exec();
}
2 changes: 2 additions & 0 deletions src/actions/branchactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class BranchActions : public AbstractActions
DEFINE_ACTION(actionMerge)
DEFINE_ACTION(actionCreate)
DEFINE_ACTION(actionRemove)
DEFINE_ACTION(actionNote)

public:
explicit BranchActions(Git::Manager *git, QWidget *parent = nullptr);
Expand All @@ -37,6 +38,7 @@ private slots:
void diff();
void remove();
void merge();
void note();
};

#endif // BRANCHACTIONS_H
17 changes: 17 additions & 0 deletions src/dialogs/notedialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "notedialog.h"

#include "git/gitmanager.h"

NoteDialog::NoteDialog(Git::Manager *git, const QString &branchName, QWidget *parent) :
AppDialog(git, parent), _branchName{branchName}
{
setupUi(this);

textEdit->setText(git->readNote(branchName));
}

void NoteDialog::on_buttonBox_accepted()
{
_git->saveNote(_branchName, textEdit->toPlainText());
close();
}
20 changes: 20 additions & 0 deletions src/dialogs/notedialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef NOTEDIALOG_H
#define NOTEDIALOG_H

#include "ui_notedialog.h"

#include "core/appdialog.h"

class NoteDialog : public AppDialog, private Ui::NoteDialog
{
Q_OBJECT
QString _branchName;

public:
explicit NoteDialog(Git::Manager *git, const QString &branchName, QWidget *parent = nullptr);

private slots:
void on_buttonBox_accepted();
};

#endif // NOTEDIALOG_H
54 changes: 54 additions & 0 deletions src/dialogs/notedialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NoteDialog</class>
<widget class="QDialog" name="NoteDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Note</string>
</property>
<property name="windowIcon">
<iconset theme="gitklient"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>NoteDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
10 changes: 10 additions & 0 deletions src/git/gitmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ void Manager::setLoadFlags(const LoadFlags &newLoadFlags)
_loadFlags = newLoadFlags;
}

QString Manager::readNote(const QString &branchName) const
{
return runGit({"notes", "show", branchName});
}

void Manager::saveNote(const QString &branchName, const QString &note) const
{
runGit({"notes", "add", branchName, "-f", "--message=" + note});
}

Manager::Manager()
: QObject()
, _remotesModel{new RemotesModel(this)}
Expand Down
4 changes: 4 additions & 0 deletions src/git/gitmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class Manager : public QObject
const LoadFlags &loadFlags() const;
void setLoadFlags(const LoadFlags &newLoadFlags);


QString readNote(const QString &branchName) const;
void saveNote(const QString &branchName, const QString &note) const;

signals:
void pathChanged();

Expand Down

0 comments on commit 9eca342

Please sign in to comment.