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
1f748400
Commit
1f748400
authored
Jan 17, 2022
by
Waqar Ahmed
Committed by
Christoph Cullmann
Jan 29, 2022
Browse files
Allow drag and drop between different kate instances
parent
54f3ce88
Changes
5
Hide whitespace changes
Inline
Side-by-side
kate/katetabbar.cpp
View file @
1f748400
...
...
@@ -11,6 +11,7 @@
#include "tabmimedata.h"
#include <QApplication>
#include <QDataStream>
#include <QDrag>
#include <QIcon>
#include <QMimeData>
...
...
@@ -224,7 +225,21 @@ void KateTabBar::mouseMoveEvent(QMouseEvent *event)
auto
parentViewSpace
=
qobject_cast
<
KateViewSpace
*>
(
parentWidget
());
Q_ASSERT
(
parentViewSpace
);
auto
mime
=
new
TabMimeData
(
parentViewSpace
,
tabDocument
(
tab
),
tab
);
auto
view
=
parentViewSpace
->
currentView
();
if
(
!
view
)
{
return
;
}
QByteArray
data
;
KTextEditor
::
Cursor
cp
=
view
->
cursorPosition
();
QDataStream
ds
(
&
data
,
QIODevice
::
WriteOnly
);
ds
<<
cp
.
line
();
ds
<<
cp
.
column
();
ds
<<
view
->
document
()
->
url
();
auto
mime
=
new
TabMimeData
(
parentViewSpace
,
tabDocument
(
tab
));
mime
->
setData
(
QStringLiteral
(
"application/kate.tab.mimedata"
),
data
);
drag
->
setMimeData
(
mime
);
drag
->
setPixmap
(
p
);
QPoint
hp
;
...
...
kate/kateviewspace.cpp
View file @
1f748400
...
...
@@ -24,6 +24,7 @@
#include <QApplication>
#include <QClipboard>
#include <QDataStream>
#include <QHelpEvent>
#include <QMenu>
#include <QMessageBox>
...
...
@@ -430,23 +431,26 @@ void KateViewSpace::closeDocument(KTextEditor::Document *doc)
}
}
bool
KateViewSpace
::
acceptsDroppedTab
(
const
class
Tab
MimeData
*
tabMimeData
)
bool
KateViewSpace
::
acceptsDroppedTab
(
const
Q
MimeData
*
md
)
{
return
tabMimeData
&&
this
!=
tabMimeData
->
sourceVS
&&
// must not be same viewspace
viewManger
()
==
tabMimeData
->
sourceVS
->
viewManger
()
&&
// for now we don't support dropping into different windows
!
hasDocument
(
tabMimeData
->
doc
);
if
(
auto
tabMimeData
=
qobject_cast
<
const
TabMimeData
*>
(
md
))
{
return
this
!=
tabMimeData
->
sourceVS
&&
// must not be same viewspace
viewManger
()
==
tabMimeData
->
sourceVS
->
viewManger
()
&&
// for now we don't support dropping into different windows
!
hasDocument
(
tabMimeData
->
doc
);
}
return
TabMimeData
::
hasValidData
(
md
);
}
void
KateViewSpace
::
dragEnterEvent
(
QDragEnterEvent
*
e
)
{
auto
mimeData
=
qobject_cast
<
const
TabMimeData
*>
(
e
->
mimeData
());
if
(
acceptsDroppedTab
(
mimeData
))
{
if
(
acceptsDroppedTab
(
e
->
mimeData
()))
{
m_dropIndicator
.
reset
(
new
QRubberBand
(
QRubberBand
::
Rectangle
,
this
));
m_dropIndicator
->
setGeometry
(
rect
());
m_dropIndicator
->
show
();
e
->
acceptProposedAction
();
return
;
}
QWidget
::
dragEnterEvent
(
e
);
}
...
...
@@ -464,6 +468,17 @@ void KateViewSpace::dropEvent(QDropEvent *e)
e
->
accept
();
return
;
}
auto
droppedData
=
TabMimeData
::
data
(
e
->
mimeData
());
if
(
droppedData
.
has_value
())
{
auto
doc
=
KateApp
::
self
()
->
documentManager
()
->
openUrl
(
droppedData
.
value
().
url
);
auto
view
=
m_viewManager
->
activateView
(
doc
);
if
(
view
)
{
view
->
setCursorPosition
({
droppedData
.
value
().
line
,
droppedData
.
value
().
col
});
e
->
accept
();
return
;
}
}
QWidget
::
dropEvent
(
e
);
}
...
...
kate/kateviewspace.h
View file @
1f748400
...
...
@@ -222,7 +222,7 @@ private Q_SLOTS:
void
createNewDocument
();
private:
bool
acceptsDroppedTab
(
const
class
Tab
MimeData
*
tabMimeData
);
bool
acceptsDroppedTab
(
const
class
Q
MimeData
*
tabMimeData
);
/**
* Returns the amount of documents in KateDocManager that currently
* have no tab in this tab bar.
...
...
kate/tabmimedata.cpp
View file @
1f748400
#include "tabmimedata.h"
TabMimeData
::
TabMimeData
(
KateViewSpace
*
vs
,
KTextEditor
::
Document
*
d
,
int
sourceTabIdx
)
#include <QDataStream>
TabMimeData
::
TabMimeData
(
KateViewSpace
*
vs
,
KTextEditor
::
Document
*
d
)
:
QMimeData
()
,
sourceVS
(
vs
)
,
doc
(
d
)
,
tabIdx
(
sourceTabIdx
)
{
}
bool
TabMimeData
::
hasValidData
(
const
QMimeData
*
md
)
{
bool
valid
=
md
&&
md
->
hasFormat
(
QStringLiteral
(
"application/kate.tab.mimedata"
));
if
(
valid
)
{
QByteArray
data
=
md
->
data
(
QStringLiteral
(
"application/kate.tab.mimedata"
));
QDataStream
ds
(
data
);
int
line
=
0
;
int
column
=
0
;
QUrl
url
;
ds
>>
line
;
ds
>>
column
;
ds
>>
url
;
return
url
.
isValid
();
}
return
false
;
}
std
::
optional
<
TabMimeData
::
DroppedData
>
TabMimeData
::
data
(
const
QMimeData
*
md
)
{
if
(
!
md
||
!
md
->
hasFormat
(
QStringLiteral
(
"application/kate.tab.mimedata"
)))
{
return
{};
}
QByteArray
data
=
md
->
data
(
QStringLiteral
(
"application/kate.tab.mimedata"
));
QDataStream
ds
(
data
);
TabMimeData
::
DroppedData
d
;
ds
>>
d
.
line
;
ds
>>
d
.
col
;
ds
>>
d
.
url
;
if
(
!
d
.
url
.
isValid
())
{
return
{};
}
return
d
;
}
kate/tabmimedata.h
View file @
1f748400
...
...
@@ -5,6 +5,8 @@
#include "kateviewspace.h"
#include <optional>
namespace
KTextEditor
{
class
Document
;
...
...
@@ -14,11 +16,20 @@ class TabMimeData : public QMimeData
{
Q_OBJECT
public:
TabMimeData
(
KateViewSpace
*
vs
,
KTextEditor
::
Document
*
d
,
int
sourceTabIdx
);
struct
DroppedData
{
int
line
=
-
1
;
int
col
=
-
1
;
QUrl
url
;
};
TabMimeData
(
KateViewSpace
*
vs
,
KTextEditor
::
Document
*
d
);
static
bool
hasValidData
(
const
QMimeData
*
md
);
static
std
::
optional
<
DroppedData
>
data
(
const
QMimeData
*
md
);
KateViewSpace
*
const
sourceVS
;
KTextEditor
::
Document
*
const
doc
;
const
int
tabIdx
;
};
#endif
Write
Preview
Markdown
is supported
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