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
aa070e1f
Commit
aa070e1f
authored
Mar 06, 2021
by
Waqar Ahmed
Committed by
Christoph Cullmann
Mar 06, 2021
Browse files
Dont depend on gitwidget process in StashDialog
parent
c1b454b4
Changes
8
Hide whitespace changes
Inline
Side-by-side
addons/project/branchesdialog.cpp
View file @
aa070e1f
...
...
@@ -153,7 +153,7 @@ private:
};
BranchesDialog
::
BranchesDialog
(
QWidget
*
window
,
KateProjectPluginView
*
pluginView
,
QString
projectPath
)
:
QuickDialog
(
window
)
:
QuickDialog
(
nullptr
,
window
)
,
m_pluginView
(
pluginView
)
,
m_projectPath
(
projectPath
)
{
...
...
addons/project/gitwidget.cpp
View file @
aa070e1f
...
...
@@ -747,6 +747,20 @@ void GitWidget::buildMenu()
m_gitMenu
->
addAction
(
i18n
(
"Stash"
))
->
setMenu
(
stashMenu
());
}
void
GitWidget
::
createStashDialog
(
StashMode
m
,
const
QString
&
gitPath
)
{
auto
stashDialog
=
new
StashDialog
(
this
,
mainWindow
()
->
window
(),
gitPath
);
connect
(
stashDialog
,
&
StashDialog
::
message
,
this
,
&
GitWidget
::
sendMessage
);
connect
(
stashDialog
,
&
StashDialog
::
openTempFile
,
this
,
[
this
](
const
QString
&
t
,
const
QByteArray
&
r
)
{
openTempFile
(
QString
(),
t
,
r
);
});
connect
(
stashDialog
,
&
StashDialog
::
done
,
this
,
[
this
,
stashDialog
]
{
getStatus
();
stashDialog
->
deleteLater
();
});
stashDialog
->
openDialog
(
m
);
}
QMenu
*
GitWidget
::
stashMenu
()
{
QMenu
*
menu
=
new
QMenu
(
this
);
...
...
@@ -761,40 +775,31 @@ QMenu *GitWidget::stashMenu()
auto
showStashAct
=
menu
->
addAction
(
i18n
(
"Show Stash Content"
));
connect
(
stashAct
,
&
QAction
::
triggered
,
this
,
[
this
]
{
StashDialog
stashDialog
(
this
,
m_mainWin
->
window
());
stashDialog
.
openDialog
(
StashDialog
::
Stash
);
createStashDialog
(
StashMode
::
Stash
,
m_gitPath
);
});
connect
(
stashUAct
,
&
QAction
::
triggered
,
this
,
[
this
]
{
StashDialog
stashDialog
(
this
,
m_mainWin
->
window
());
stashDialog
.
openDialog
(
StashDialog
::
StashUntrackIncluded
);
createStashDialog
(
StashMode
::
StashUntrackIncluded
,
m_gitPath
);
});
connect
(
stashKeepStagedAct
,
&
QAction
::
triggered
,
this
,
[
this
]
{
StashDialog
stashDialog
(
this
,
m_mainWin
->
window
());
stashDialog
.
openDialog
(
StashDialog
::
StashKeepIndex
);
createStashDialog
(
StashMode
::
StashKeepIndex
,
m_gitPath
);
});
connect
(
popAct
,
&
QAction
::
triggered
,
this
,
[
this
]
{
StashDialog
stashDialog
(
this
,
m_mainWin
->
window
());
stashDialog
.
openDialog
(
StashDialog
::
StashPop
);
createStashDialog
(
StashMode
::
StashPop
,
m_gitPath
);
});
connect
(
applyStashAct
,
&
QAction
::
triggered
,
this
,
[
this
]
{
StashDialog
stashDialog
(
this
,
m_mainWin
->
window
());
stashDialog
.
openDialog
(
StashDialog
::
StashApply
);
createStashDialog
(
StashMode
::
StashApply
,
m_gitPath
);
});
connect
(
dropAct
,
&
QAction
::
triggered
,
this
,
[
this
]
{
StashDialog
stashDialog
(
this
,
m_mainWin
->
window
());
stashDialog
.
openDialog
(
StashDialog
::
StashDrop
);
createStashDialog
(
StashMode
::
StashDrop
,
m_gitPath
);
});
connect
(
popLastAct
,
&
QAction
::
triggered
,
this
,
[
this
]
{
StashDialog
stashDialog
(
this
,
m_mainWin
->
window
());
stashDialog
.
openDialog
(
StashDialog
::
StashPopLast
);
createStashDialog
(
StashMode
::
StashPopLast
,
m_gitPath
);
});
connect
(
applyLastAct
,
&
QAction
::
triggered
,
this
,
[
this
]
{
StashDialog
stashDialog
(
this
,
m_mainWin
->
window
());
stashDialog
.
openDialog
(
StashDialog
::
StashApplyLast
);
createStashDialog
(
StashMode
::
StashApplyLast
,
m_gitPath
);
});
connect
(
showStashAct
,
&
QAction
::
triggered
,
this
,
[
this
]
{
StashDialog
stashDialog
(
this
,
m_mainWin
->
window
());
stashDialog
.
openDialog
(
StashDialog
::
ShowStashContent
);
createStashDialog
(
StashMode
::
ShowStashContent
,
m_gitPath
);
});
return
menu
;
...
...
addons/project/gitwidget.h
View file @
aa070e1f
...
...
@@ -33,6 +33,7 @@ class Document;
}
enum
class
ClickAction
:
uint8_t
;
enum
class
StashMode
:
uint8_t
;
class
GitWidget
:
public
QWidget
{
...
...
@@ -91,6 +92,7 @@ private:
void
selectedContextMenu
(
QContextMenuEvent
*
e
);
QString
getDiff
(
KTextEditor
::
View
*
view
,
bool
hunk
,
bool
alreadyStaged
);
void
createStashDialog
(
StashMode
m
,
const
QString
&
gitPath
);
public
Q_SLOTS
:
void
clearTempFile
(
KTextEditor
::
Document
*
document
);
...
...
addons/project/pushpulldialog.cpp
View file @
aa070e1f
...
...
@@ -8,7 +8,7 @@
#include <QProcess>
PushPullDialog
::
PushPullDialog
(
QWidget
*
mainWindow
,
const
QString
&
repoPath
)
:
QuickDialog
(
mainWindow
)
:
QuickDialog
(
nullptr
,
mainWindow
)
,
m_repo
(
repoPath
)
{
}
...
...
addons/project/quickdialog.cpp
View file @
aa070e1f
...
...
@@ -14,8 +14,8 @@
#include <QDebug>
QuickDialog
::
QuickDialog
(
QWidget
*
mainWindow
)
:
QMenu
()
QuickDialog
::
QuickDialog
(
QWidget
*
parent
,
QWidget
*
mainWindow
)
:
QMenu
(
parent
)
,
m_mainWindow
(
mainWindow
)
{
QVBoxLayout
*
layout
=
new
QVBoxLayout
();
...
...
addons/project/quickdialog.h
View file @
aa070e1f
...
...
@@ -24,7 +24,7 @@ class QuickDialog : public QMenu
{
Q_OBJECT
public:
QuickDialog
(
QWidget
*
mainWindow
);
QuickDialog
(
QWidget
*
parent
,
QWidget
*
mainWindow
);
protected:
bool
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
override
;
...
...
addons/project/stashdialog.cpp
View file @
aa070e1f
...
...
@@ -132,9 +132,9 @@ private:
QString
m_filterString
;
};
StashDialog
::
StashDialog
(
Git
Widget
*
gitwidge
t
,
QWidget
*
window
)
:
QuickDialog
(
window
)
,
m_git
widget
(
gitwidget
)
StashDialog
::
StashDialog
(
Q
Widget
*
paren
t
,
QWidget
*
window
,
const
QString
&
gitPath
)
:
QuickDialog
(
parent
,
window
)
,
m_git
Path
(
gitPath
)
{
m_model
=
new
QStandardItemModel
(
this
);
m_proxyModel
=
new
StashFilterModel
(
this
);
...
...
@@ -152,29 +152,29 @@ StashDialog::StashDialog(GitWidget *gitwidget, QWidget *window)
m_proxyModel
->
setFilterRole
(
Qt
::
DisplayRole
);
}
void
StashDialog
::
openDialog
(
Stash
Dialog
::
Mode
m
)
void
StashDialog
::
openDialog
(
StashMode
m
)
{
m_model
->
clear
();
switch
(
m
)
{
case
Mode
::
Stash
:
case
Mode
::
StashKeepIndex
:
case
Mode
::
StashUntrackIncluded
:
case
Stash
Mode
::
Stash
:
case
Stash
Mode
::
StashKeepIndex
:
case
Stash
Mode
::
StashUntrackIncluded
:
m_lineEdit
.
setPlaceholderText
(
i18n
(
"Stash message (optional). Enter to confirm, Esc to leave."
));
m_currentMode
=
m
;
break
;
case
Mode
::
StashPop
:
case
Mode
::
StashDrop
:
case
Mode
::
StashApply
:
case
Mode
::
ShowStashContent
:
case
Stash
Mode
::
StashPop
:
case
Stash
Mode
::
StashDrop
:
case
Stash
Mode
::
StashApply
:
case
Stash
Mode
::
ShowStashContent
:
m_lineEdit
.
setPlaceholderText
(
i18n
(
"Type to filter, Enter to pop stash, Esc to leave."
));
m_currentMode
=
m
;
getStashList
();
break
;
case
Mode
::
StashApplyLast
:
case
Stash
Mode
::
StashApplyLast
:
applyStash
({});
return
;
case
Mode
::
StashPopLast
:
case
Stash
Mode
::
StashPopLast
:
popStash
({});
return
;
default:
...
...
@@ -191,25 +191,25 @@ void StashDialog::openDialog(StashDialog::Mode m)
void
StashDialog
::
slotReturnPressed
()
{
switch
(
m_currentMode
)
{
case
Mode
::
Stash
:
case
Stash
Mode
::
Stash
:
stash
(
false
,
false
);
break
;
case
Mode
::
StashKeepIndex
:
case
Stash
Mode
::
StashKeepIndex
:
stash
(
true
,
false
);
break
;
case
Mode
::
StashUntrackIncluded
:
case
Stash
Mode
::
StashUntrackIncluded
:
stash
(
false
,
true
);
break
;
case
Mode
::
StashApply
:
case
Stash
Mode
::
StashApply
:
applyStash
(
m_treeView
.
currentIndex
().
data
(
StashIndexRole
).
toByteArray
());
break
;
case
Mode
::
StashPop
:
case
Stash
Mode
::
StashPop
:
popStash
(
m_treeView
.
currentIndex
().
data
(
StashIndexRole
).
toByteArray
());
break
;
case
Mode
::
StashDrop
:
case
Stash
Mode
::
StashDrop
:
dropStash
(
m_treeView
.
currentIndex
().
data
(
StashIndexRole
).
toByteArray
());
break
;
case
Mode
::
ShowStashContent
:
case
Stash
Mode
::
ShowStashContent
:
showStash
(
m_treeView
.
currentIndex
().
data
(
StashIndexRole
).
toByteArray
());
break
;
default:
...
...
@@ -220,10 +220,12 @@ void StashDialog::slotReturnPressed()
hide
();
}
void
StashDialog
::
sendMessage
(
const
QString
&
message
,
bool
warn
)
QProcess
*
StashDialog
::
gitp
(
)
{
// just proxy to git widget
m_gitwidget
->
sendMessage
(
message
,
warn
);
auto
git
=
new
QProcess
(
this
);
git
->
setProgram
(
QStringLiteral
(
"git"
));
git
->
setWorkingDirectory
(
m_gitPath
);
return
git
;
}
void
StashDialog
::
stash
(
bool
keepIndex
,
bool
includeUntracked
)
...
...
@@ -242,21 +244,16 @@ void StashDialog::stash(bool keepIndex, bool includeUntracked)
args
.
append
(
m_lineEdit
.
text
());
}
auto
git
=
m_gitwidget
->
gitprocess
();
auto
gitWidget
=
m_gitwidget
;
if
(
!
git
)
{
return
;
}
disconnect
(
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
connect
(
git
,
&
QProcess
::
finished
,
m_gitwidget
,
[
gitWidget
](
int
exitCode
,
QProcess
::
ExitStatus
es
)
{
disconnect
(
gitWidget
->
gitprocess
(),
&
QProcess
::
finished
,
nullptr
,
nullptr
);
gitWidget
->
getStatus
();
auto
git
=
gitp
();
connect
(
git
,
&
QProcess
::
finished
,
this
,
[
this
,
git
](
int
exitCode
,
QProcess
::
ExitStatus
es
)
{
if
(
es
!=
QProcess
::
NormalExit
||
exitCode
!=
0
)
{
gitWidget
->
sendMessage
(
i18n
(
"Failed to stash changes"
),
true
);
qWarning
()
<<
git
->
errorString
();
Q_EMIT
message
(
i18n
(
"Failed to stash changes %1"
,
QString
::
fromUtf8
(
git
->
readAllStandardError
())),
true
);
}
else
{
gitWidget
->
sendM
essage
(
i18n
(
"Changes stashed successfully."
),
false
);
Q_EMIT
m
essage
(
i18n
(
"Changes stashed successfully."
),
false
);
}
Q_EMIT
done
();
git
->
deleteLater
();
});
git
->
setArguments
(
args
);
git
->
start
(
QProcess
::
ReadOnly
);
...
...
@@ -264,11 +261,7 @@ void StashDialog::stash(bool keepIndex, bool includeUntracked)
void
StashDialog
::
getStashList
()
{
auto
git
=
m_gitwidget
->
gitprocess
();
if
(
!
git
)
{
return
;
}
auto
git
=
gitp
();
git
->
setArguments
({
QStringLiteral
(
"stash"
),
QStringLiteral
(
"list"
)});
git
->
start
(
QProcess
::
ReadOnly
);
...
...
@@ -277,7 +270,7 @@ void StashDialog::getStashList()
if
(
git
->
exitStatus
()
==
QProcess
::
NormalExit
&&
git
->
exitCode
()
==
0
)
{
stashList
=
git
->
readAllStandardOutput
().
split
(
'\n'
);
}
else
{
m_gitwidget
->
sendM
essage
(
i18n
(
"Failed to get stash list. Error: "
)
+
QString
::
fromUtf8
(
git
->
readAll
()),
true
);
Q_EMIT
m
essage
(
i18n
(
"Failed to get stash list. Error: "
)
+
QString
::
fromUtf8
(
git
->
readAll
()),
true
);
}
}
...
...
@@ -302,39 +295,32 @@ void StashDialog::getStashList()
void
StashDialog
::
popStash
(
const
QByteArray
&
index
,
const
QString
&
command
)
{
auto
git
=
m_gitwidget
->
gitprocess
();
auto
gitWidget
=
m_gitwidget
;
if
(
!
git
)
{
return
;
}
disconnect
(
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
auto
git
=
gitp
();
QStringList
args
{
QStringLiteral
(
"stash"
),
command
};
if
(
!
index
.
isEmpty
())
{
args
.
append
(
QString
::
fromUtf8
(
index
));
}
connect
(
git
,
&
QProcess
::
finished
,
gitWidget
,
[
gitWidget
,
command
](
int
exitCode
,
QProcess
::
ExitStatus
es
)
{
disconnect
(
gitWidget
->
gitprocess
(),
&
QProcess
::
finished
,
nullptr
,
nullptr
);
gitWidget
->
getStatus
();
connect
(
git
,
&
QProcess
::
finished
,
this
,
[
this
,
command
,
git
](
int
exitCode
,
QProcess
::
ExitStatus
es
)
{
if
(
es
!=
QProcess
::
NormalExit
||
exitCode
!=
0
)
{
auto
git
=
gitWidget
->
gitprocess
();
if
(
command
==
QLatin1String
(
"apply"
))
{
gitWidget
->
sendM
essage
(
i18n
(
"Failed to apply stash. Error: "
)
+
QString
::
fromUtf8
(
git
->
readAll
()),
true
);
Q_EMIT
m
essage
(
i18n
(
"Failed to apply stash. Error: "
)
+
QString
::
fromUtf8
(
git
->
readAll
()),
true
);
}
else
if
(
command
==
QLatin1String
(
"drop"
))
{
gitWidget
->
sendM
essage
(
i18n
(
"Failed to drop stash. Error: "
)
+
QString
::
fromUtf8
(
git
->
readAll
()),
true
);
Q_EMIT
m
essage
(
i18n
(
"Failed to drop stash. Error: "
)
+
QString
::
fromUtf8
(
git
->
readAll
()),
true
);
}
else
{
gitWidget
->
sendM
essage
(
i18n
(
"Failed to pop stash. Error: "
)
+
QString
::
fromUtf8
(
git
->
readAll
()),
true
);
Q_EMIT
m
essage
(
i18n
(
"Failed to pop stash. Error: "
)
+
QString
::
fromUtf8
(
git
->
readAll
()),
true
);
}
}
else
{
if
(
command
==
QLatin1String
(
"apply"
))
{
gitWidget
->
sendM
essage
(
i18n
(
"Stash applied successfully."
),
false
);
Q_EMIT
m
essage
(
i18n
(
"Stash applied successfully."
),
false
);
}
else
if
(
command
==
QLatin1String
(
"drop"
))
{
gitWidget
->
sendM
essage
(
i18n
(
"Stash dropped successfully."
),
false
);
Q_EMIT
m
essage
(
i18n
(
"Stash dropped successfully."
),
false
);
}
else
{
gitWidget
->
sendM
essage
(
i18n
(
"Stash popped successfully."
),
false
);
Q_EMIT
m
essage
(
i18n
(
"Stash popped successfully."
),
false
);
}
}
Q_EMIT
done
();
git
->
deleteLater
();
});
git
->
setArguments
(
args
);
git
->
start
(
QProcess
::
ReadOnly
);
...
...
@@ -355,24 +341,18 @@ void StashDialog::showStash(const QByteArray &index)
if
(
index
.
isEmpty
())
{
return
;
}
auto
git
=
gitp
();
auto
git
=
m_gitwidget
->
gitprocess
();
auto
gitWidget
=
m_gitwidget
;
if
(
!
git
)
{
return
;
}
disconnect
(
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
QStringList
args
{
QStringLiteral
(
"stash"
),
QStringLiteral
(
"show"
),
QStringLiteral
(
"-p"
),
QString
::
fromUtf8
(
index
)};
connect
(
git
,
&
QProcess
::
finished
,
gitWidget
,
[
gitWidget
](
int
exitCode
,
QProcess
::
ExitStatus
es
)
{
disconnect
(
gitWidget
->
gitprocess
(),
&
QProcess
::
finished
,
nullptr
,
nullptr
);
connect
(
git
,
&
QProcess
::
finished
,
this
,
[
this
,
git
](
int
exitCode
,
QProcess
::
ExitStatus
es
)
{
if
(
es
!=
QProcess
::
NormalExit
||
exitCode
!=
0
)
{
gitWidget
->
sendMessage
(
i18n
(
"Show stash failed. Error: "
)
+
QString
::
fromUtf8
(
gitWidget
->
gitprocess
()
->
readAll
()),
true
);
gitWidget
->
getStatus
();
Q_EMIT
message
(
i18n
(
"Show stash failed. Error: "
)
+
QString
::
fromUtf8
(
git
->
readAll
()),
true
);
}
else
{
gitWidget
->
openTempFile
(
QString
(),
QStringLiteral
(
"XXXXXX.diff"
),
git
Widget
->
gitprocess
()
->
readAllStandardOutput
());
Q_EMIT
openTempFile
(
QStringLiteral
(
"XXXXXX.diff"
),
git
->
readAllStandardOutput
());
}
Q_EMIT
done
();
git
->
deleteLater
();
});
git
->
setArguments
(
args
);
...
...
addons/project/stashdialog.h
View file @
aa070e1f
...
...
@@ -27,36 +27,36 @@ namespace GitUtils
struct
CheckoutResult
;
}
enum
class
StashMode
:
uint8_t
{
None
=
0
,
Stash
,
StashKeepIndex
,
StashUntrackIncluded
,
StashPopLast
,
StashPop
,
StashDrop
,
StashApply
,
StashApplyLast
,
ShowStashContent
,
};
class
StashDialog
:
public
QuickDialog
{
Q_OBJECT
public:
enum
Mode
{
None
,
Stash
,
StashKeepIndex
,
StashUntrackIncluded
,
StashPopLast
,
StashPop
,
StashDrop
,
StashApply
,
StashApplyLast
,
ShowStashContent
,
};
StashDialog
(
QWidget
*
parent
,
QWidget
*
window
,
const
QString
&
gitPath
);
StashDialog
(
GitWidget
*
gitwidget
,
QWidget
*
window
);
void
openDialog
(
StashMode
mode
);
void
openDialog
(
Mode
mode
);
Q_SIGNAL
void
branchChanged
(
const
QString
&
branch
);
Q_SIGNAL
void
message
(
const
QString
&
msg
,
bool
warn
);
Q_SIGNAL
void
done
();
Q_SIGNAL
void
openTempFile
(
const
QString
&
templatee
,
const
QByteArray
&
gitOutput
);
protected
Q_SLOTS
:
void
slotReturnPressed
()
override
;
private
Q_SLOTS
:
void
sendMessage
(
const
QString
&
message
,
bool
warn
);
private:
QProcess
*
gitp
();
void
stash
(
bool
keepIndex
,
bool
includeUntracked
);
void
getStashList
();
void
popStash
(
const
QByteArray
&
index
,
const
QString
&
command
=
QStringLiteral
(
"pop"
));
...
...
@@ -66,7 +66,7 @@ private:
QStandardItemModel
*
m_model
;
StashFilterModel
*
m_proxyModel
;
GitWidget
*
m_gitwidget
;
QString
m_gitPath
;
QString
m_projectPath
;
Mode
m_currentMode
=
None
;
Stash
Mode
m_currentMode
=
StashMode
::
None
;
};
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