Commit 3a4301a6 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮 Committed by Waqar Ahmed
Browse files

remove openheader plugin in favor of LSP

LSP allows the open source/header, too
just move the F12 shortcut to the LSP
action for this and remove the old plugin
parent dae89c8b
......@@ -14,7 +14,6 @@ ecm_optional_add_subdirectory(katebuild-plugin)
ecm_optional_add_subdirectory(katesql)
ecm_optional_add_subdirectory(konsole)
ecm_optional_add_subdirectory(lspclient) # Language Server Protocol (LSP) client plugin.
ecm_optional_add_subdirectory(openheader) # Open header matching to current file.
ecm_optional_add_subdirectory(preview) # Live preview of sources in target format.
ecm_optional_add_subdirectory(project) # Small & smart project manager.
ecm_optional_add_subdirectory(replicode)
......
......@@ -455,6 +455,7 @@ public:
m_triggerRename->setText(i18n("Rename"));
m_switchSourceHeader = actionCollection()->addAction(QStringLiteral("lspclient_clangd_switchheader"), this, &self_type::clangdSwitchSourceHeader);
m_switchSourceHeader->setText(i18n("Switch Source Header"));
actionCollection()->setDefaultShortcut(m_switchSourceHeader, Qt::Key_F12);
m_requestCodeAction = actionCollection()->add<KActionMenu>(QStringLiteral("lspclient_code_action"));
m_requestCodeAction->setText(i18n("Code Action"));
connect(m_requestCodeAction->menu(), &QMenu::aboutToShow, this, &self_type::requestCodeAction);
......
add_library(kateopenheaderplugin MODULE "")
target_compile_definitions(kateopenheaderplugin PRIVATE TRANSLATION_DOMAIN="kateopenheader")
target_link_libraries(kateopenheaderplugin PRIVATE KF5::I18n KF5::TextEditor)
target_sources(
kateopenheaderplugin
PRIVATE
plugin_kateopenheader.cpp
plugin.qrc
)
kcoreaddons_desktop_to_json(kateopenheaderplugin kateopenheaderplugin.desktop)
# ensure we are able to load plugins pre-install, too, directories must match!
set_target_properties(kateopenheaderplugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/ktexteditor")
install(TARGETS kateopenheaderplugin DESTINATION ${KDE_INSTALL_PLUGINDIR}/ktexteditor)
#! /bin/sh
$EXTRACTRC *.rc >> rc.cpp
$XGETTEXT *.cpp -o $podir/kateopenheader.pot
[Desktop Entry]
Type=Service
ServiceTypes=KTextEditor/Plugin
X-KDE-Library=kateopenheaderplugin
Name=Open Header
Name[ar]=فتح التّرويسة
Name[ast]=Apertura de testeres
Name[az]=Başlıq faylını açın
Name[bg]=Отваряне на header
Name[bs]=Otvaranje zaglavlja
Name[ca]=Obre les capçaleres
Name[ca@valencia]=Obri les capçaleres
Name[cs]=Otevřít hlavičku
Name[da]=Åbn headerfil
Name[de]=Header öffnen
Name[el]=Άνοιγμα κεφαλίδας
Name[en_GB]=Open Header
Name[es]=Abrir cabecera
Name[et]=Päiseavaja
Name[eu]=Ireki goiburua
Name[fi]=Avaa otsake
Name[fr]=Ouvrir un fichier d'en-tête
Name[ga]=Oscail Comhad Ceanntáisc
Name[gl]=Abrir a cabeceira
Name[he]=פתח קובץ כותרת
Name[hu]=Fejlécböngésző
Name[ia]=Aperi capite (header)
Name[id]=Buka Header
Name[it]=Apri intestazioni
Name[ja]=オープンヘッダ
Name[kk]=Айдарын ашу
Name[km]=បើក​បឋមកថា​
Name[ko]=헤더 열기
Name[lt]=Atverti antraštę
Name[lv]=Atvērt galveni
Name[mr]=हेडर उघडा
Name[nb]=Åpne deklarasjonsfil
Name[nds]=Koppdatei opmaken
Name[nl]=OpenHeader
Name[nn]=Opna deklarasjonsfil
Name[pa]=ਹੈੱਡਰ ਖੋਲ੍ਹੋ
Name[pl]=Otwórz plik nagłówkowy
Name[pt]=Abrir um Ficheiro de Inclusão
Name[pt_BR]=Abrir arquivo de cabeçalho
Name[ro]=Deschide antet
Name[ru]=Открытие заголовочного файла
Name[si]=ශීර්ෂය විවෘතකරන්න
Name[sk]=Otvoriť hlavičku
Name[sl]=Odpiranje glav
Name[sr]=Отварање заглавља
Name[sr@ijekavian]=Отварање заглавља
Name[sr@ijekavianlatin]=Otvaranje zaglavlja
Name[sr@latin]=Otvaranje zaglavlja
Name[sv]=Öppna deklarationsfil
Name[tg]=Кушодани сарлавҳа
Name[tr]=Başlığı Aç
Name[ug]=باشنى ئاچ
Name[uk]=Відкрити заголовок
Name[x-test]=xxOpen Headerxx
Name[zh_CN]=打开头文件
Name[zh_TW]=開啟標頭
Comment=Opens the corresponding .h/[.cpp|.c] file
Comment[ar]=تفتح ملفّ ‎.h/[.cpp|.c]‎ المقابل
Comment[ast]=Abre'l ficheru .h/[.cpp|.c] correspondiente
Comment[az]=.h/[.cpp|.c] ilə uyğun faylı açır
Comment[bg]=Отваряне на съответните файлове .h/[.cpp|.c]
Comment[bs]=Otvara pridruženu .h/[.cpp|.c] datoteku
Comment[ca]=Obre el fitxer .h/[.cpp|.c] corresponent
Comment[ca@valencia]=Obri el fitxer .h/[.cpp|.c] corresponent
Comment[cs]=Otevře odpovídající soubor .h/[.cpp|.c]
Comment[da]=Åbner den tilhørende .h/[.cpp|.c]-fil
Comment[de]=Öffnet die zusammengehörigen .h/[.cpp|.c]-Dateien
Comment[el]=Άνοιγμα του αντίστοιχου αρχείου .h/[.cpp|.c]
Comment[en_GB]=Opens the corresponding .h/[.cpp|.c] file
Comment[es]=Abre el correspondiente archivo .h/[.cpp|.c]
Comment[et]=Vastava .h/[.cpp|.c] faili avamine
Comment[eu]=Dagokion .h/[.cpp|.c] fitxategia irekitzen du
Comment[fi]=Avaa vastaavan .h/[.cpp|.c]-tiedoston
Comment[fr]=Ouvre le fichier .h / [.cpp |.c] correspondant
Comment[ga]=Oscail an comhad .h/[.cpp|.c] a fhreagraíonn leis an gceann seo
Comment[gl]=Abre o ficheiro .h/[.cpp|.c] correspondente
Comment[he]=פותח את הקובץ המתאים (file.h, file.cpp)
Comment[hu]=Megnyitja a megfelelő .h/[.cpp|.c] fájlt
Comment[ia]=Aperi le correspondente file .h/[.cpp].c]
Comment[id]=Buka file .h/[.cppl.c] yang terkait
Comment[it]=Apre il file .h/[.cpp|.c] corrispondente
Comment[ja]=対応する .h/[.cpp|.c] ファイルを開きます
Comment[kk]=Сәйкесті .h/[.cpp|.c] файлын ашу
Comment[km]=បើក​ឯកសារ​ដែល​ត្រូវ​នឹង .h/[.cpp|.c]
Comment[ko]=해당하는 .h/[.cpp|.c] 파일 열기
Comment[lt]=Atveria atitinkamą .h/[.cpp|.c] failą
Comment[lv]=Atver atbilstošo .h/[.cpp|.c] datni
Comment[mr]=संबंधित .h/[.cpp|.c] फाईल उघडतो
Comment[nb]=Åpner tilhørende .h/[.cpp|.c] fil
Comment[nds]=Maakt de tohören .h/.cpp/.c-Datei op
Comment[ne]=संगत .h/[.cpp|.c] फाइल खोल्दछ
Comment[nl]=Open het bijhorende .h/[.cpp|.c]-bestand
Comment[nn]=Opna tilhøyrande .h/[.cpp|.c]-fil
Comment[pa]=ਸਬੰਧਿਤ .h/[.cpp|.c] ਫਾਇਲ ਖੋਲ੍ਹੋ
Comment[pl]=Otwiera odpowiedni plik .h/[.cpp|.c]
Comment[pt]=Abre o ficheiro .h/[.cpp|.c] correspondente
Comment[pt_BR]=Abre o arquivo .h/[.cpp|.c] correspondente
Comment[ro]=Deschide fișierul .h/[.cpp|.c] corespunzător
Comment[ru]=Открывает соответствующий файл .h/[.cpp|.c]
Comment[si]=අදාල .h/[.cpp|.c] ගොනුව විවෘත කරයි
Comment[sk]=Otvorí korešpondujúci .h/[.cpp|.c] súbor
Comment[sl]=Odpre ustrezno datoteko .h/[.cpp|.c]
Comment[sr]=Отвара придружени .h/[.cpp|.c] фајл
Comment[sr@ijekavian]=Отвара придружени .h/[.cpp|.c] фајл
Comment[sr@ijekavianlatin]=Otvara pridruženi .h/[.cpp|.c] fajl
Comment[sr@latin]=Otvara pridruženi .h/[.cpp|.c] fajl
Comment[sv]=Öppnar den motsvarande .h/[.cpp|.c]-filen
Comment[tg]=Кушодани фаилҳои мувофиқи .h/[.cpp|.c]
Comment[tr]=Karşılık gelen .h/[.cpp|.c] dosyalarını açar
Comment[ug]=نۆۋەتتىكى ھۆججەت .h/[.cpp.c] غا ماس كەلگەن ھۆججەتنى ئاچىدۇ
Comment[uk]=Відкриває відповідний файл .h/[.cpp|.c]
Comment[x-test]=xxOpens the corresponding .h/[.cpp|.c] filexx
Comment[zh_CN]=打开对应于当前文件的 .h/[.cpp|.c] 文件
Comment[zh_TW]=開啟相關的 .h/.cpp/.c 檔
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="/kxmlgui5/kateopenheaderplugin">
<file>ui.rc</file>
</qresource>
</RCC>
/* This file is part of the KDE project
SPDX-FileCopyrightText: 2001 Joseph Wenninger
SPDX-FileCopyrightText: 2009 Erlend Hamberg <ehamberg@gmail.com>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "plugin_kateopenheader.h"
#include <ktexteditor/application.h>
#include <ktexteditor/document.h>
#include <ktexteditor/editor.h>
#include <ktexteditor/view.h>
#include <KAboutData>
#include <KActionCollection>
#include <KIO/StatJob>
#include <KJobWidgets>
#include <KLocalizedString>
#include <KXMLGUIFactory>
#include <QAction>
#include <QDir>
#include <QFileInfo>
K_PLUGIN_FACTORY_WITH_JSON(KateOpenHeaderFactory, "kateopenheaderplugin.json", registerPlugin<PluginKateOpenHeader>();)
// K_EXPORT_PLUGIN(KateOpenHeaderFactory(KAboutData("kateopenheader","kateopenheader",ki18n("Open Header"), "0.1", ki18n("Open header for a source file"),
// KAboutData::License_LGPL_V2)) )
PluginViewKateOpenHeader::PluginViewKateOpenHeader(PluginKateOpenHeader *plugin, KTextEditor::MainWindow *mainwindow)
: KTextEditor::Command(QStringList() << QStringLiteral("toggle-header"), mainwindow)
, m_plugin(plugin)
, m_mainWindow(mainwindow)
{
KXMLGUIClient::setComponentName(QStringLiteral("kateopenheaderplugin"), i18n("Open Header"));
setXMLFile(QStringLiteral("ui.rc"));
QAction *a = actionCollection()->addAction(QStringLiteral("file_openheader"));
a->setText(i18n("Open .h/.cpp/.c"));
actionCollection()->setDefaultShortcut(a, Qt::Key_F12);
connect(a, &QAction::triggered, plugin, &PluginKateOpenHeader::slotOpenHeader);
mainwindow->guiFactory()->addClient(this);
}
PluginViewKateOpenHeader::~PluginViewKateOpenHeader()
{
m_mainWindow->guiFactory()->removeClient(this);
}
PluginKateOpenHeader::PluginKateOpenHeader(QObject *parent, const QList<QVariant> &)
: KTextEditor::Plugin(parent)
{
}
PluginKateOpenHeader::~PluginKateOpenHeader()
{
}
QObject *PluginKateOpenHeader::createView(KTextEditor::MainWindow *mainWindow)
{
return new PluginViewKateOpenHeader(this, mainWindow);
}
void PluginKateOpenHeader::slotOpenHeader()
{
KTextEditor::Application *application = KTextEditor::Editor::instance()->application();
if (!application->activeMainWindow()) {
return;
}
KTextEditor::View *kv(application->activeMainWindow()->activeView());
if (!kv) {
return;
}
QUrl url = kv->document()->url();
if ((!url.isValid()) || (url.isEmpty())) {
return;
}
qDebug() << "Trying to open opposite of " << url.toString();
qDebug() << "Trying to open opposite of toLocalFile:" << url.toLocalFile();
qDebug() << "Trying to open opposite of path:" << url.path();
QFileInfo info(url.path());
QString extension = info.suffix().toLower();
QStringList headers(QStringList() << QStringLiteral("h") << QStringLiteral("H") << QStringLiteral("hh") << QStringLiteral("hpp") << QStringLiteral("cuh"));
QStringList sources(QStringList() << QStringLiteral("c") << QStringLiteral("cpp") << QStringLiteral("cc") << QStringLiteral("cp") << QStringLiteral("cxx")
<< QStringLiteral("m") << QStringLiteral("cu"));
if (sources.contains(extension)) {
if (tryOpenInternal(url, headers)) {
return;
}
tryOpen(url, headers);
} else if (headers.contains(extension)) {
if (tryOpenInternal(url, sources)) {
return;
}
tryOpen(url, sources);
}
}
bool PluginKateOpenHeader::tryOpenInternal(const QUrl &url, const QStringList &extensions)
{
KTextEditor::Application *application = KTextEditor::Editor::instance()->application();
if (!application->activeMainWindow()) {
return false;
}
qDebug() << "Trying to find already opened" << url.toString() << " with extensions " << extensions.join(QLatin1Char(' '));
QString basename = QFileInfo(url.path()).baseName();
QUrl newURL(url);
for (const auto &extension : extensions) {
setFileName(&newURL, basename + QStringLiteral(".") + extension);
KTextEditor::Document *doc = application->findUrl(newURL);
if (doc) {
application->activeMainWindow()->openUrl(newURL);
return true;
}
setFileName(&newURL, basename + QStringLiteral(".") + extension.toUpper());
doc = application->findUrl(newURL);
if (doc) {
application->activeMainWindow()->openUrl(newURL);
return true;
}
}
return false;
}
void PluginKateOpenHeader::tryOpen(const QUrl &url, const QStringList &extensions)
{
KTextEditor::Application *application = KTextEditor::Editor::instance()->application();
if (!application->activeMainWindow()) {
return;
}
qDebug() << "Trying to open " << url.toString() << " with extensions " << extensions.join(QLatin1Char(' '));
QString basename = QFileInfo(url.path()).baseName();
QUrl newURL(url);
for (const auto &extension : extensions) {
setFileName(&newURL, basename + QStringLiteral(".") + extension);
if (fileExists(newURL)) {
application->activeMainWindow()->openUrl(newURL);
return;
}
setFileName(&newURL, basename + QStringLiteral(".") + extension.toUpper());
if (fileExists(newURL)) {
application->activeMainWindow()->openUrl(newURL);
return;
}
}
}
bool PluginKateOpenHeader::fileExists(const QUrl &url)
{
if (url.isLocalFile()) {
return QFile::exists(url.toLocalFile());
}
KIO::JobFlags flags = KIO::DefaultFlags;
KIO::StatJob *job = KIO::stat(url, flags);
KJobWidgets::setWindow(job, KTextEditor::Editor::instance()->application()->activeMainWindow()->window());
job->setSide(KIO::StatJob::DestinationSide /*SourceSide*/);
job->exec();
return !job->error();
}
void PluginKateOpenHeader::setFileName(QUrl *url, const QString &_txt)
{
url->setFragment(QString());
int i = 0;
while (i < _txt.length() && _txt[i] == QLatin1Char('/')) {
++i;
}
QString tmp = i ? _txt.mid(i) : _txt;
QString path = url->path();
if (path.isEmpty()) {
#ifdef Q_OS_WIN
path = url->isLocalFile() ? QDir::rootPath() : QStringLiteral("/");
#else
path = QDir::rootPath();
#endif
} else {
int lastSlash = path.lastIndexOf(QLatin1Char('/'));
if (lastSlash == -1) {
path.clear(); // there's only the file name, remove it
} else if (!path.endsWith(QLatin1Char('/'))) {
path.truncate(lastSlash + 1); // keep the "/"
}
}
path += tmp;
url->setPath(path);
}
bool PluginViewKateOpenHeader::exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &)
{
Q_UNUSED(view)
Q_UNUSED(cmd)
Q_UNUSED(msg)
m_plugin->slotOpenHeader();
return true;
}
bool PluginViewKateOpenHeader::help(KTextEditor::View *view, const QString &cmd, QString &msg)
{
Q_UNUSED(view)
Q_UNUSED(cmd)
msg = i18n(
"<p><b>toggle-header &mdash; switch between header and corresponding c/cpp file</b></p>"
"<p>usage: <tt><b>toggle-header</b></tt></p>"
"<p>When editing C or C++ code, this command will switch between a header file and "
"its corresponding C/C++ file or vice versa.</p>"
"<p>For example, if you are editing myclass.cpp, <tt>toggle-header</tt> will change "
"to myclass.h if this file is available.</p>"
"<p>Pairs of the following filename suffixes will work:<br />"
" Header files: h, H, hh, hpp<br />"
" Source files: c, cpp, cc, cp, cxx</p>");
return true;
}
#include "plugin_kateopenheader.moc"
/* This file is part of the KDE project
SPDX-FileCopyrightText: 2001 Joseph Wenninger
SPDX-FileCopyrightText: 2009 Erlend Hamberg <ehamberg@gmail.com>
SPDX-License-Identifier: LGPL-2.0-only
*/
#ifndef PLUGIN_KATEOPENHEADER_H
#define PLUGIN_KATEOPENHEADER_H
#include <KPluginFactory>
#include <KTextEditor/Command>
#include <KXMLGUIClient>
#include <QObject>
#include <QUrl>
#include <ktexteditor/mainwindow.h>
#include <ktexteditor/plugin.h>
class PluginKateOpenHeader : public KTextEditor::Plugin
{
Q_OBJECT
public:
explicit PluginKateOpenHeader(QObject *parent = nullptr, const QList<QVariant> & = QList<QVariant>());
~PluginKateOpenHeader() override;
QObject *createView(KTextEditor::MainWindow *mainWindow) override;
public Q_SLOTS:
void slotOpenHeader();
void tryOpen(const QUrl &url, const QStringList &extensions);
bool tryOpenInternal(const QUrl &url, const QStringList &extensions);
private:
bool fileExists(const QUrl &url);
void setFileName(QUrl *url, const QString &_txt);
};
class PluginViewKateOpenHeader : public KTextEditor::Command, public KXMLGUIClient
{
Q_OBJECT
public:
PluginViewKateOpenHeader(PluginKateOpenHeader *plugin, KTextEditor::MainWindow *mainwindow);
~PluginViewKateOpenHeader() override;
bool exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range = KTextEditor::Range::invalid()) override;
bool help(KTextEditor::View *view, const QString &cmd, QString &msg) override;
private:
PluginKateOpenHeader *m_plugin;
KTextEditor::MainWindow *m_mainWindow;
};
#endif // PLUGIN_KATEOPENHEADER_H
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="kateopenheader" library="libkateopenheaderplugin" version="4" translationDomain="kateopenheader">
<MenuBar>
<Menu name="file">
<text>&amp;File</text>
<Action name="file_openheader" group="open_merge"/>
</Menu>
</MenuBar>
</gui>
<!-- kate: space-indent on; indent-width 4; replace-tabs on; -->
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment