Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
d19b911a
Commit
d19b911a
authored
Mar 13, 2021
by
Waqar Ahmed
Browse files
New dialog for branch checkout deriving from base
Signed-off-by:
Waqar Ahmed
<
waqar.17a@gmail.com
>
parent
eb69ab2c
Changes
5
Hide whitespace changes
Inline
Side-by-side
addons/project/CMakeLists.txt
View file @
d19b911a
...
...
@@ -59,6 +59,7 @@ target_sources(
kateprojectconfigpage.cpp
kateprojectcodeanalysistool.cpp
branchesdialog.cpp
branchcheckoutdialog.cpp
branchesdialogmodel.cpp
gitwidget.cpp
gitstatusmodel.cpp
...
...
addons/project/branchcheckoutdialog.cpp
0 → 100644
View file @
d19b911a
#include "branchcheckoutdialog.h"
#include "branchesdialogmodel.h"
#include <KLocalizedString>
#include <QtConcurrentRun>
BranchCheckoutDialog
::
BranchCheckoutDialog
(
QWidget
*
mainWindow
,
KateProjectPluginView
*
pluginView
,
QString
projectPath
)
:
BranchesDialog
(
mainWindow
,
pluginView
,
projectPath
)
{
connect
(
&
m_checkoutWatcher
,
&
QFutureWatcher
<
GitUtils
::
CheckoutResult
>::
finished
,
this
,
&
BranchCheckoutDialog
::
onCheckoutDone
);
}
BranchCheckoutDialog
::~
BranchCheckoutDialog
()
{
if
(
m_checkoutWatcher
.
isRunning
())
{
onCheckoutDone
();
}
}
void
BranchCheckoutDialog
::
resetValues
()
{
m_checkoutBranchName
.
clear
();
m_checkingOutFromBranch
=
false
;
m_lineEdit
.
setPlaceholderText
(
i18n
(
"Select branch to checkout. Press 'Esc' to cancel."
));
}
void
BranchCheckoutDialog
::
openDialog
()
{
resetValues
();
GitUtils
::
Branch
newBranch
;
newBranch
.
name
=
i18n
(
"Create New Branch"
);
GitUtils
::
Branch
newBranchFrom
;
newBranchFrom
.
name
=
i18n
(
"Create New Branch From..."
);
QVector
<
GitUtils
::
Branch
>
branches
{
newBranch
,
newBranchFrom
};
branches
<<
GitUtils
::
getAllBranches
(
m_projectPath
);
m_model
->
refresh
(
branches
,
/*checkingOut:*/
true
);
reselectFirst
();
updateViewGeometry
();
setFocus
();
exec
();
}
void
BranchCheckoutDialog
::
onCheckoutDone
()
{
const
GitUtils
::
CheckoutResult
res
=
m_checkoutWatcher
.
result
();
bool
warn
=
false
;
QString
msgStr
=
i18n
(
"Branch %1 checked out"
,
res
.
branch
);
if
(
res
.
returnCode
>
0
)
{
warn
=
true
;
msgStr
=
i18n
(
"Failed to checkout to branch %1, Error: %2"
,
res
.
branch
,
res
.
error
);
}
sendMessage
(
msgStr
,
warn
);
}
void
BranchCheckoutDialog
::
slotReturnPressed
()
{
// we cleared the model to checkout new branch
if
(
m_model
->
rowCount
()
==
0
)
{
createNewBranch
(
m_lineEdit
.
text
(),
m_checkoutBranchName
);
return
;
}
// branch is selected, do actual checkout
if
(
m_checkingOutFromBranch
)
{
m_checkingOutFromBranch
=
false
;
const
auto
fromBranch
=
m_proxyModel
->
data
(
m_treeView
.
currentIndex
(),
BranchesDialogModel
::
CheckoutName
).
toString
();
m_checkoutBranchName
=
fromBranch
;
m_model
->
clear
();
clearLineEdit
();
m_lineEdit
.
setPlaceholderText
(
i18n
(
"Enter new branch name. Press 'Esc' to cancel."
));
return
;
}
const
auto
branch
=
m_proxyModel
->
data
(
m_treeView
.
currentIndex
(),
BranchesDialogModel
::
CheckoutName
).
toString
();
const
auto
itemType
=
(
BranchesDialogModel
::
ItemType
)
m_proxyModel
->
data
(
m_treeView
.
currentIndex
(),
BranchesDialogModel
::
ItemTypeRole
).
toInt
();
if
(
itemType
==
BranchesDialogModel
::
BranchItem
)
{
QFuture
<
GitUtils
::
CheckoutResult
>
future
=
QtConcurrent
::
run
(
&
GitUtils
::
checkoutBranch
,
m_projectPath
,
branch
);
m_checkoutWatcher
.
setFuture
(
future
);
}
else
if
(
itemType
==
BranchesDialogModel
::
CreateBranch
)
{
m_model
->
clear
();
m_lineEdit
.
setPlaceholderText
(
i18n
(
"Enter new branch name. Press 'Esc' to cancel."
));
return
;
}
else
if
(
itemType
==
BranchesDialogModel
::
CreateBranchFrom
)
{
m_model
->
clearBranchCreationItems
();
clearLineEdit
();
m_lineEdit
.
setPlaceholderText
(
i18n
(
"Select branch to checkout from. Press 'Esc' to cancel."
));
m_checkingOutFromBranch
=
true
;
return
;
}
clearLineEdit
();
hide
();
}
void
BranchCheckoutDialog
::
reselectFirst
()
{
QModelIndex
index
=
m_proxyModel
->
index
(
0
,
0
);
m_treeView
.
setCurrentIndex
(
index
);
}
void
BranchCheckoutDialog
::
createNewBranch
(
const
QString
&
branch
,
const
QString
&
fromBranch
)
{
if
(
branch
.
isEmpty
())
{
clearLineEdit
();
hide
();
return
;
}
// the branch name might be invalid, let git handle it
const
GitUtils
::
CheckoutResult
r
=
GitUtils
::
checkoutNewBranch
(
m_projectPath
,
branch
,
fromBranch
);
const
bool
warn
=
true
;
if
(
r
.
returnCode
==
0
)
{
sendMessage
(
i18n
(
"Checked out to new branch: %1"
,
r
.
branch
),
!
warn
);
}
else
{
sendMessage
(
i18n
(
"Failed to create new branch. Error
\"
%1
\"
"
,
r
.
error
),
warn
);
}
clearLineEdit
();
hide
();
}
addons/project/branchcheckoutdialog.h
0 → 100644
View file @
d19b911a
#ifndef BRANCHCHECKOUTDIALOG_H
#define BRANCHCHECKOUTDIALOG_H
#include "branchesdialog.h"
class
BranchCheckoutDialog
:
public
BranchesDialog
{
Q_OBJECT
public:
BranchCheckoutDialog
(
QWidget
*
mainWindow
,
KateProjectPluginView
*
pluginView
,
QString
projectPath
);
~
BranchCheckoutDialog
();
void
openDialog
();
private
Q_SLOTS
:
void
slotReturnPressed
()
override
;
void
reselectFirst
();
void
onCheckoutDone
();
private:
void
resetValues
();
void
createNewBranch
(
const
QString
&
branch
,
const
QString
&
fromBranch
=
QString
());
private:
QFutureWatcher
<
GitUtils
::
CheckoutResult
>
m_checkoutWatcher
;
QString
m_checkoutBranchName
;
bool
m_checkingOutFromBranch
=
false
;
};
#endif // BRANCHCHECKOUTDIALOG_H
addons/project/gitwidget.cpp
View file @
d19b911a
...
...
@@ -744,7 +744,7 @@ void GitWidget::buildMenu()
}
});
m_gitMenu
->
addAction
(
i18n
(
"Checkout Branch"
),
this
,
[
this
]
{
Branch
es
Dialog
bd
(
m_mainWin
->
window
(),
m_pluginView
,
m_project
->
baseDir
());
Branch
Checkout
Dialog
bd
(
m_mainWin
->
window
(),
m_pluginView
,
m_project
->
baseDir
());
bd
.
openDialog
();
});
...
...
addons/project/kateprojectview.cpp
View file @
d19b911a
...
...
@@ -6,7 +6,7 @@
*/
#include "kateprojectview.h"
#include "branch
es
dialog.h"
#include "branch
checkout
dialog.h"
#include "filehistorywidget.h"
#include "git/gitutils.h"
#include "gitwidget.h"
...
...
@@ -74,7 +74,7 @@ KateProjectView::KateProjectView(KateProjectPluginView *pluginView, KateProject
*/
m_branchBtn
->
setHidden
(
true
);
connect
(
m_branchBtn
,
&
QPushButton
::
clicked
,
this
,
[
this
,
mainWindow
]
{
Branch
es
Dialog
bd
(
mainWindow
->
window
(),
m_pluginView
,
m_project
->
baseDir
());
Branch
Checkout
Dialog
bd
(
mainWindow
->
window
(),
m_pluginView
,
m_project
->
baseDir
());
bd
.
openDialog
();
});
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment