Skip to content
GitLab
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
68ad2b72
Commit
68ad2b72
authored
Oct 13, 2022
by
Eric Armbruster
🍁
Committed by
Christoph Cullmann
Oct 13, 2022
Browse files
Fix recent projects to work with new welcomeview
Also rename recentfiles to recentitems again.
parent
78149a31
Pipeline
#247317
passed with stage
in 8 minutes and 45 seconds
Changes
10
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
addons/project/kateprojectpluginview.cpp
View file @
68ad2b72
...
...
@@ -838,7 +838,7 @@ void KateProjectPluginView::openDirectoryOrProject(const QDir &dir)
if
(
auto
*
parentClient
=
qobject_cast
<
KXmlGuiWindow
*>
(
m_mainWindow
->
window
()))
{
if
(
auto
*
openRecentAction
=
parentClient
->
action
(
KStandardAction
::
name
(
KStandardAction
::
StandardAction
::
OpenRecent
)))
{
if
(
auto
*
recentFilesAction
=
qobject_cast
<
KRecentFilesAction
*>
(
openRecentAction
))
{
recentFilesAction
->
addUrl
(
QUrl
(
dir
.
path
()));
recentFilesAction
->
addUrl
(
QUrl
::
fromLocalFile
(
dir
.
path
()));
}
}
}
...
...
apps/lib/CMakeLists.txt
View file @
68ad2b72
...
...
@@ -120,7 +120,7 @@ target_sources(
filehistorywidget.cpp
welcomeview/welcomeview.cpp
welcomeview/recent
file
smodel.cpp
welcomeview/recent
item
smodel.cpp
welcomeview/savedsessionsmodel.cpp
)
...
...
apps/lib/katemainwindow.cpp
View file @
68ad2b72
...
...
@@ -292,15 +292,7 @@ void KateMainWindow::setupActions()
m_fileOpenRecent
=
KStandardAction
::
openRecent
(
m_viewManager
,
[
this
](
const
QUrl
&
url
)
{
if
(
url
.
isLocalFile
())
{
QDir
dir
(
url
.
path
());
if
(
dir
.
exists
())
{
Utils
::
openDirectoryOrProject
(
this
,
dir
);
return
;
}
}
openUrl
(
url
);
Utils
::
openUrlOrProject
(
viewManager
(),
url
);
},
this
);
m_fileOpenRecent
->
setMaxItems
(
KateConfigDialog
::
recentFilesMaxCount
());
...
...
apps/lib/ktexteditor_utils.cpp
View file @
68ad2b72
...
...
@@ -6,6 +6,7 @@
#include
"ktexteditor_utils.h"
#include
"katemainwindow.h"
#include
"kateviewmanager.h"
#include
<QDir>
#include
<QFontDatabase>
...
...
@@ -193,12 +194,23 @@ QVariantMap projectMapForDocument(KTextEditor::Document *doc)
return
projectMap
;
}
void
open
Directory
OrProject
(
Kate
MainWindow
*
mainWindow
,
const
Q
Dir
&
dir
)
void
open
Url
OrProject
(
Kate
ViewManager
*
viewManager
,
const
Q
Url
&
url
)
{
if
(
QObject
*
pview
=
mainWindow
->
pluginView
(
QStringLiteral
(
"kateprojectplugin"
)))
{
if
(
!
url
.
isLocalFile
())
{
viewManager
->
openUrl
(
url
);
return
;
}
QDir
dir
=
{
url
.
toLocalFile
()};
if
(
!
dir
.
exists
())
{
viewManager
->
openUrl
(
url
);
return
;
}
if
(
QObject
*
pview
=
viewManager
->
mainWindow
()
->
pluginView
(
QStringLiteral
(
"kateprojectplugin"
)))
{
QMetaObject
::
invokeMethod
(
pview
,
"openDirectoryOrProject"
,
Q_ARG
(
const
QDir
&
,
dir
));
}
else
{
KMessageBox
::
error
(
mainWindow
,
i18n
(
"Please enable the project plugin to load directories"
));
KMessageBox
::
error
(
viewManager
->
mainWindow
()
,
i18n
(
"Please enable the project plugin to load directories"
));
}
}
}
apps/lib/ktexteditor_utils.h
View file @
68ad2b72
...
...
@@ -10,11 +10,11 @@
QT_BEGIN_NAMESPACE
class
QScrollBar
;
class
QAction
;
class
QDir
;
class
QFont
;
class
QIcon
;
class
QVariant
;
class
QWidget
;
class
QUrl
;
typedef
QMap
<
QString
,
QVariant
>
QVariantMap
;
QT_END_NAMESPACE
...
...
@@ -25,7 +25,7 @@ class Document;
class
MainWindow
;
}
struct
DiffParams
;
class
Kate
MainWindow
;
class
Kate
ViewManager
;
namespace
Utils
{
...
...
@@ -96,5 +96,5 @@ KATE_PRIVATE_EXPORT QVariantMap projectMapForDocument(KTextEditor::Document *doc
*
* Returns whether the url is a directory
*/
KATE_PRIVATE_EXPORT
void
open
Directory
OrProject
(
Kate
MainWindow
*
mainWindow
,
const
Q
Dir
&
dir
);
KATE_PRIVATE_EXPORT
void
open
Url
OrProject
(
Kate
ViewManager
*
viewManager
,
const
Q
Url
&
url
);
}
apps/lib/welcomeview/recent
file
smodel.cpp
→
apps/lib/welcomeview/recent
item
smodel.cpp
View file @
68ad2b72
...
...
@@ -5,30 +5,30 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include
"recentfilesmodel.h"
#include
"kateconfigdialog.h"
#include
"recentitemsmodel.h"
#include
<QDebug>
#include
<QFileInfo>
#include
<QMimeDatabase>
Recent
File
sModel
::
Recent
File
sModel
(
QObject
*
parent
)
Recent
Item
sModel
::
Recent
Item
sModel
(
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
{}
{
}
QVariant
Recent
File
sModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
QVariant
Recent
Item
sModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
(
index
.
isValid
())
{
const
int
row
=
index
.
row
();
if
(
row
>=
0
&&
row
<
m_recent
File
s
.
count
())
{
const
Recent
File
Info
&
recent
File
=
m_recent
File
s
.
at
(
row
);
if
(
row
>=
0
&&
row
<
m_recent
Item
s
.
count
())
{
const
Recent
Item
Info
&
recent
Item
=
m_recent
Item
s
.
at
(
row
);
switch
(
role
)
{
case
Qt
::
DisplayRole
:
return
recent
File
.
name
;
return
recent
Item
.
name
;
case
Qt
::
DecorationRole
:
return
recent
File
.
icon
;
return
recent
Item
.
icon
;
case
Qt
::
ToolTipRole
:
return
recent
File
.
url
.
toString
(
QUrl
::
PreferLocalFile
);
return
recent
Item
.
url
.
toString
(
QUrl
::
PreferLocalFile
);
default:
break
;
}
...
...
@@ -38,22 +38,23 @@ QVariant RecentFilesModel::data(const QModelIndex &index, int role) const
return
QVariant
();
}
int
Recent
File
sModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
int
Recent
Item
sModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
Q_UNUSED
(
parent
);
return
m_recent
File
s
.
count
();
return
m_recent
Item
s
.
count
();
}
void
Recent
File
sModel
::
refresh
(
const
QList
<
QUrl
>
&
urls
)
void
Recent
Item
sModel
::
refresh
(
const
QList
<
QUrl
>
&
urls
)
{
QVector
<
Recent
File
Info
>
recent
File
s
;
recent
File
s
.
reserve
(
urls
.
count
());
QVector
<
Recent
Item
Info
>
recent
Item
s
;
recent
Item
s
.
reserve
(
urls
.
count
());
QIcon
icon
;
QString
name
;
for
(
const
QUrl
&
url
:
urls
)
{
for
(
const
QUrl
&
url
:
urls
)
{
if
(
url
.
isLocalFile
())
{
qDebug
()
<<
url
<<
" is local file"
;
const
QFileInfo
fileInfo
(
url
.
toLocalFile
());
if
(
!
fileInfo
.
exists
())
{
continue
;
...
...
@@ -62,24 +63,25 @@ void RecentFilesModel::refresh(const QList<QUrl> &urls)
icon
=
QIcon
::
fromTheme
(
QMimeDatabase
().
mimeTypeForFile
(
fileInfo
).
iconName
());
name
=
fileInfo
.
fileName
();
}
else
{
qDebug
()
<<
url
<<
" is not local file"
;
icon
=
QIcon
::
fromTheme
(
QStringLiteral
(
"network-server"
));
name
=
url
.
toString
();
}
recent
File
s
.
append
({
icon
,
name
,
url
});
recent
Item
s
.
append
({
icon
,
name
,
url
});
}
beginResetModel
();
m_recent
File
s
=
std
::
move
(
recent
File
s
);
m_recent
Item
s
=
std
::
move
(
recent
Item
s
);
endResetModel
();
}
QUrl
Recent
File
sModel
::
url
(
const
QModelIndex
&
index
)
const
QUrl
Recent
Item
sModel
::
url
(
const
QModelIndex
&
index
)
const
{
if
(
index
.
isValid
())
{
const
int
row
=
index
.
row
();
if
(
row
>=
0
&&
row
<
m_recent
File
s
.
count
())
{
return
m_recent
File
s
.
at
(
row
).
url
;
if
(
row
>=
0
&&
row
<
m_recent
Item
s
.
count
())
{
return
m_recent
Item
s
.
at
(
row
).
url
;
}
}
...
...
apps/lib/welcomeview/recent
file
smodel.h
→
apps/lib/welcomeview/recent
item
smodel.h
View file @
68ad2b72
...
...
@@ -12,12 +12,12 @@
#include
<QIcon>
#include
<QUrl>
class
Recent
File
sModel
:
public
QAbstractListModel
class
Recent
Item
sModel
:
public
QAbstractListModel
{
Q_OBJECT
public:
explicit
Recent
File
sModel
(
QObject
*
parent
=
nullptr
);
explicit
Recent
Item
sModel
(
QObject
*
parent
=
nullptr
);
QVariant
data
(
const
QModelIndex
&
index
,
int
role
=
Qt
::
DisplayRole
)
const
override
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
...
...
@@ -26,13 +26,13 @@ public:
QUrl
url
(
const
QModelIndex
&
index
)
const
;
private:
struct
Recent
File
Info
{
struct
Recent
Item
Info
{
QIcon
icon
;
QString
name
;
QUrl
url
;
};
QVector
<
Recent
File
Info
>
m_recent
File
s
;
QVector
<
Recent
Item
Info
>
m_recent
Item
s
;
};
#endif // RECENTFILESMODEL_H
apps/lib/welcomeview/welcomeview.cpp
View file @
68ad2b72
...
...
@@ -10,7 +10,7 @@
#include
"kateapp.h"
#include
"kateviewmanager.h"
#include
"ktexteditor_utils.h"
#include
"recent
file
smodel.h"
#include
"recent
item
smodel.h"
#include
"savedsessionsmodel.h"
#include
<KAboutData>
...
...
@@ -64,35 +64,27 @@ WelcomeView::WelcomeView(KateViewManager *viewManager, QWidget *parent)
layoutPlaceholderRecentFiles
->
addWidget
(
placeholderRecentFiles
);
listViewRecentFiles
->
setLayout
(
layoutPlaceholderRecentFiles
);
m_recent
File
sModel
=
new
Recent
File
sModel
(
this
);
connect
(
m_recent
File
sModel
,
&
Recent
File
sModel
::
modelReset
,
this
,
[
this
,
placeholderRecentFiles
]()
{
const
bool
noRecentFiles
=
m_recent
File
sModel
->
rowCount
()
==
0
;
m_recent
Item
sModel
=
new
Recent
Item
sModel
(
this
);
connect
(
m_recent
Item
sModel
,
&
Recent
Item
sModel
::
modelReset
,
this
,
[
this
,
placeholderRecentFiles
]()
{
const
bool
noRecentFiles
=
m_recent
Item
sModel
->
rowCount
()
==
0
;
buttonClearRecentFiles
->
setDisabled
(
noRecentFiles
);
placeholderRecentFiles
->
setVisible
(
noRecentFiles
);
});
KRecentFilesAction
*
recentFilesAction
=
m_viewManager
->
mainWindow
()
->
recentFilesAction
();
m_recent
File
sModel
->
refresh
(
recentFilesAction
->
urls
());
m_recent
Item
sModel
->
refresh
(
recentFilesAction
->
urls
());
connect
(
recentFilesAction
,
&
KRecentFilesAction
::
recentListCleared
,
this
,
[
this
,
recentFilesAction
]()
{
m_recent
File
sModel
->
refresh
(
recentFilesAction
->
urls
());
m_recent
Item
sModel
->
refresh
(
recentFilesAction
->
urls
());
});
listViewRecentFiles
->
setModel
(
m_recent
File
sModel
);
listViewRecentFiles
->
setModel
(
m_recent
Item
sModel
);
connect
(
listViewRecentFiles
,
&
QListView
::
customContextMenuRequested
,
this
,
&
WelcomeView
::
onRecentFilesContextMenuRequested
);
connect
(
listViewRecentFiles
,
&
QListView
::
activated
,
this
,
[
this
](
const
QModelIndex
&
index
)
{
if
(
index
.
isValid
())
{
const
QUrl
url
=
m_recent
File
sModel
->
url
(
index
);
const
QUrl
url
=
m_recent
Item
sModel
->
url
(
index
);
Q_ASSERT
(
url
.
isValid
());
if
(
url
.
isLocalFile
())
{
QDir
dir
=
{
url
.
path
()};
if
(
dir
.
exists
())
{
Utils
::
openDirectoryOrProject
(
m_viewManager
->
mainWindow
(),
dir
);
return
;
}
}
m_viewManager
->
openUrl
(
url
);
Utils
::
openUrlOrProject
(
m_viewManager
,
url
);
}
});
...
...
@@ -201,8 +193,10 @@ void WelcomeView::onPluginViewChanged(const QString &pluginName)
if
(
projectPluginView
)
{
connect
(
buttonOpenFolder
,
SIGNAL
(
clicked
()),
projectPluginView
,
SLOT
(
openDirectoryOrProject
()));
buttonOpenFolder
->
show
();
labelRecentItems
->
setText
(
i18n
(
"Recent Documents and Projects"
));
}
else
{
buttonOpenFolder
->
hide
();
labelRecentItems
->
setText
(
i18n
(
"Recent Documents"
));
}
}
}
...
...
@@ -214,7 +208,7 @@ void WelcomeView::onRecentFilesContextMenuRequested(const QPoint &pos)
return
;
}
const
QUrl
url
=
m_recent
File
sModel
->
url
(
index
);
const
QUrl
url
=
m_recent
Item
sModel
->
url
(
index
);
Q_ASSERT
(
url
.
isValid
());
QMenu
contextMenu
;
...
...
@@ -239,7 +233,7 @@ void WelcomeView::onRecentFilesContextMenuRequested(const QPoint &pos)
connect
(
action
,
&
QAction
::
triggered
,
this
,
[
this
,
url
]()
{
KRecentFilesAction
*
recentFilesAction
=
m_viewManager
->
mainWindow
()
->
recentFilesAction
();
recentFilesAction
->
removeUrl
(
url
);
m_recent
File
sModel
->
refresh
(
recentFilesAction
->
urls
());
m_recent
Item
sModel
->
refresh
(
recentFilesAction
->
urls
());
});
contextMenu
.
addAction
(
action
);
...
...
apps/lib/welcomeview/welcomeview.h
View file @
68ad2b72
...
...
@@ -11,7 +11,7 @@
#include
"ui_welcomeview.h"
class
KateViewManager
;
class
Recent
File
sModel
;
class
Recent
Item
sModel
;
class
SavedSessionsModel
;
class
WelcomeView
:
public
QScrollArea
,
Ui
::
WelcomeView
...
...
@@ -33,7 +33,7 @@ private:
bool
updateLayout
();
KateViewManager
*
m_viewManager
=
nullptr
;
Recent
File
sModel
*
m_recent
File
sModel
=
nullptr
;
Recent
Item
sModel
*
m_recent
Item
sModel
=
nullptr
;
SavedSessionsModel
*
m_savedSessionsModel
=
nullptr
;
};
...
...
apps/lib/welcomeview/welcomeview.ui
View file @
68ad2b72
...
...
@@ -177,8 +177,8 @@
</widget>
</item>
<item>
<widget
class=
"QWidget"
name=
"widgetRecent
File
s"
native=
"true"
>
<layout
class=
"QGridLayout"
name=
"layoutRecent
File
s"
rowstretch=
"0,0,0,0,1"
columnstretch=
"0,1,0"
>
<widget
class=
"QWidget"
name=
"widgetRecent
Item
s"
native=
"true"
>
<layout
class=
"QGridLayout"
name=
"layoutRecent
Item
s"
rowstretch=
"0,0,0,0,1"
columnstretch=
"0,1,0"
>
<property
name=
"leftMargin"
>
<number>
0
</number>
</property>
...
...
@@ -209,14 +209,14 @@
</widget>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"QLabel"
name=
"labelRecent
File
s"
>
<widget
class=
"QLabel"
name=
"labelRecent
Item
s"
>
<property
name=
"font"
>
<font>
<pointsize>
12
</pointsize>
</font>
</property>
<property
name=
"text"
>
<string>
Recent
File
s
</string>
<string>
Recent
Document
s
</string>
</property>
</widget>
</item>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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