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
09ca221c
Commit
09ca221c
authored
Feb 03, 2021
by
Christoph Cullmann
🐮
Browse files
allow to have links to sub projects inside projects
parent
5371ccf6
Changes
6
Hide whitespace changes
Inline
Side-by-side
addons/project/kateprojectitem.cpp
View file @
09ca221c
...
...
@@ -78,16 +78,20 @@ QVariant KateProjectItem::data(int role) const
return
QVariant
(
*
icon
());
}
if
(
role
==
TypeRole
)
{
return
QVariant
(
m_type
);
}
return
QStandardItem
::
data
(
role
);
}
bool
KateProjectItem
::
operator
<
(
const
QStandardItem
&
other
)
const
{
// let directories stay first
const
bool
isDirectory
=
data
(
Qt
::
ToolTipRole
).
isNull
();
const
bool
other
IsDirectory
=
other
.
data
(
Qt
::
ToolTipRole
).
isNull
();
if
(
isDirectory
!=
otherIsDirectory
)
{
return
isDirectory
>
otherIsDirectory
;
const
auto
thisType
=
data
(
TypeRole
).
toInt
();
const
bool
other
Type
=
other
.
data
(
TypeRole
).
toInt
();
if
(
thisType
!=
otherType
)
{
return
thisType
<
otherType
;
}
// case-insensitive compare of the filename
...
...
@@ -101,6 +105,7 @@ QIcon *KateProjectItem::icon() const
}
switch
(
m_type
)
{
case
LinkedProject
:
case
Project
:
m_icon
=
new
QIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"folder-documents"
)));
break
;
...
...
addons/project/kateprojectitem.h
View file @
09ca221c
...
...
@@ -26,8 +26,14 @@ class KateProjectItem : public QStandardItem
public:
/**
* Possible Types
* We start with 1 to have 0 as invalid value!
*/
enum
Type
{
Project
,
Directory
,
File
};
enum
Type
{
LinkedProject
=
1
,
Project
=
2
,
Directory
=
3
,
File
=
4
};
/**
* Our defined roles
*/
enum
Role
{
TypeRole
=
Qt
::
UserRole
+
42
};
/**
* construct new item with given text
...
...
addons/project/kateprojectpluginview.cpp
View file @
09ca221c
...
...
@@ -405,6 +405,29 @@ void KateProjectPluginView::slotDocumentUrlChanged(KTextEditor::Document *docume
}
}
void
KateProjectPluginView
::
switchToProject
(
const
QDir
&
dir
)
{
/**
* search matching project
*/
KateProject
*
project
=
m_plugin
->
projectForDir
(
dir
);
if
(
!
project
)
{
return
;
}
/**
* get active project view and switch it, if it is for a different project
* do this AFTER file selection
*/
KateProjectView
*
active
=
static_cast
<
KateProjectView
*>
(
m_stackedProjectViews
->
currentWidget
());
if
(
active
!=
m_project2View
.
value
(
project
).
first
)
{
int
index
=
m_projectsCombo
->
findData
(
project
->
fileName
());
if
(
index
>=
0
)
{
m_projectsCombo
->
setCurrentIndex
(
index
);
}
}
}
void
KateProjectPluginView
::
slotViewCreated
(
KTextEditor
::
View
*
view
)
{
/**
...
...
addons/project/kateprojectpluginview.h
View file @
09ca221c
...
...
@@ -107,6 +107,12 @@ public Q_SLOTS:
*/
QPair
<
KateProjectView
*
,
KateProjectInfoView
*>
viewForProject
(
KateProject
*
project
);
/**
* Switch to project for given dir, if any there!
* @param dir dir with the project
*/
void
switchToProject
(
const
QDir
&
dir
);
private
Q_SLOTS
:
/**
* Plugin config updated
...
...
addons/project/kateprojectviewtree.cpp
View file @
09ca221c
...
...
@@ -92,6 +92,13 @@ void KateProjectViewTree::openSelectedDocument()
return
;
}
/**
* we only handle files here!
*/
if
(
selecteStuff
[
0
].
data
(
KateProjectItem
::
TypeRole
).
toInt
()
!=
KateProjectItem
::
File
)
{
return
;
}
/**
* open document for first element, if possible
*/
...
...
@@ -106,10 +113,23 @@ void KateProjectViewTree::slotClicked(const QModelIndex &index)
/**
* open document, if any usable user data
*/
QString
filePath
=
index
.
data
(
Qt
::
UserRole
).
toString
();
const
QString
filePath
=
index
.
data
(
Qt
::
UserRole
).
toString
();
if
(
!
filePath
.
isEmpty
())
{
m_pluginView
->
mainWindow
()
->
openUrl
(
QUrl
::
fromLocalFile
(
filePath
));
selectionModel
()
->
setCurrentIndex
(
index
,
QItemSelectionModel
::
Clear
|
QItemSelectionModel
::
Select
);
/**
* normal file?
*/
if
(
index
.
data
(
KateProjectItem
::
TypeRole
).
toInt
()
==
KateProjectItem
::
File
)
{
m_pluginView
->
mainWindow
()
->
openUrl
(
QUrl
::
fromLocalFile
(
filePath
));
selectionModel
()
->
setCurrentIndex
(
index
,
QItemSelectionModel
::
Clear
|
QItemSelectionModel
::
Select
);
}
/**
* we might be a linked project => trigger that we switch to the selected one!
*/
if
(
index
.
data
(
KateProjectItem
::
TypeRole
).
toInt
()
==
KateProjectItem
::
LinkedProject
)
{
m_pluginView
->
switchToProject
(
QDir
(
filePath
));
return
;
}
}
}
...
...
addons/project/kateprojectworker.cpp
View file @
09ca221c
...
...
@@ -94,12 +94,12 @@ void KateProjectWorker::loadProject(QStandardItem *parent, const QVariantMap &pr
/**
* recurse to sub-projects FIRST
*/
QVariantList
subGroups
=
project
[
QStringLiteral
(
"projects"
)].
toList
();
const
QVariantList
subGroups
=
project
[
QStringLiteral
(
"projects"
)].
toList
();
for
(
const
QVariant
&
subGroupVariant
:
subGroups
)
{
/**
* convert to map and get name, else skip
*/
QVariantMap
subProject
=
subGroupVariant
.
toMap
();
const
QVariantMap
subProject
=
subGroupVariant
.
toMap
();
const
QString
keyName
=
QStringLiteral
(
"name"
);
if
(
subProject
[
keyName
].
toString
().
isEmpty
())
{
continue
;
...
...
@@ -117,7 +117,7 @@ void KateProjectWorker::loadProject(QStandardItem *parent, const QVariantMap &pr
* load all specified files
*/
const
QString
keyFiles
=
QStringLiteral
(
"files"
);
QVariantList
files
=
project
[
keyFiles
].
toList
();
const
QVariantList
files
=
project
[
keyFiles
].
toList
();
for
(
const
QVariant
&
fileVariant
:
files
)
{
loadFilesEntry
(
parent
,
fileVariant
.
toMap
(),
file2Item
);
}
...
...
@@ -191,6 +191,51 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap
return
;
}
/**
* handle linked projects, if any
* one can reference other projects by specifying the path to them
*/
QStringList
linkedProjects
=
filesEntry
[
QStringLiteral
(
"projects"
)].
toStringList
();
if
(
!
linkedProjects
.
empty
())
{
/**
* ensure project files are made absolute in respect to correct base dir
*/
for
(
auto
&
project
:
linkedProjects
)
{
project
=
dir
.
absoluteFilePath
(
project
);
}
/**
* users might have specified duplicates, this can't happen for the other ways
*/
linkedProjects
.
removeDuplicates
();
/**
* filter out all directories that have no .kateproject inside!
*/
linkedProjects
.
erase
(
std
::
remove_if
(
linkedProjects
.
begin
(),
linkedProjects
.
end
(),
[](
const
QString
&
item
)
{
const
QFileInfo
projectFile
(
item
+
QLatin1String
(
"/.kateproject"
));
return
!
projectFile
.
exists
()
||
!
projectFile
.
isFile
();
}),
linkedProjects
.
end
());
/**
* now add our projects to the current item parent
* later the tree view will e.g. allow to jump to the sub-projects
*/
for
(
const
auto
&
project
:
linkedProjects
)
{
QStandardItem
*
subProjectItem
=
new
KateProjectItem
(
KateProjectItem
::
LinkedProject
,
dir
.
relativeFilePath
(
project
));
subProjectItem
->
setData
(
project
,
Qt
::
UserRole
);
parent
->
appendRow
(
subProjectItem
);
}
/**
* files with linked projects will ignore all other stuff inside
*/
return
;
}
/**
* get list of files for this directory, might query the VCS
*/
...
...
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