Changeset View
Changeset View
Standalone View
Standalone View
addons/kate-ctags/kate_ctags_view.cpp
Show All 14 Lines | |||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | 16 | * General Public License for more details. | ||
17 | * | 17 | * | ||
18 | * You should have received a copy of the GNU General Public | 18 | * You should have received a copy of the GNU General Public | ||
19 | * License along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * License along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "kate_ctags_view.h" | 22 | #include "kate_ctags_view.h" | ||
23 | #include "kate_ctags_plugin.h" | ||||
23 | #include "kate_ctags_debug.h" | 24 | #include "kate_ctags_debug.h" | ||
24 | 25 | | |||
25 | #include <QFileInfo> | 26 | #include <QFileInfo> | ||
26 | #include <QFileDialog> | 27 | #include <QFileDialog> | ||
27 | #include <QKeyEvent> | 28 | #include <QKeyEvent> | ||
28 | 29 | | |||
29 | #include <KXMLGUIFactory> | 30 | #include <KXMLGUIFactory> | ||
30 | #include <KActionCollection> | 31 | #include <KActionCollection> | ||
Show All 30 Lines | 44 | { | |||
61 | QAction *defin = actionCollection()->addAction(QLatin1String("ctags_lookup_current_as_definition")); | 62 | QAction *defin = actionCollection()->addAction(QLatin1String("ctags_lookup_current_as_definition")); | ||
62 | defin->setText(i18n("Go to Definition")); | 63 | defin->setText(i18n("Go to Definition")); | ||
63 | connect(defin, &QAction::triggered, this, &KateCTagsView::gotoDefinition); | 64 | connect(defin, &QAction::triggered, this, &KateCTagsView::gotoDefinition); | ||
64 | 65 | | |||
65 | QAction *lookup = actionCollection()->addAction(QLatin1String("ctags_lookup_current")); | 66 | QAction *lookup = actionCollection()->addAction(QLatin1String("ctags_lookup_current")); | ||
66 | lookup->setText(i18n("Lookup Current Text")); | 67 | lookup->setText(i18n("Lookup Current Text")); | ||
67 | connect(lookup, &QAction::triggered, this, &KateCTagsView::lookupTag); | 68 | connect(lookup, &QAction::triggered, this, &KateCTagsView::lookupTag); | ||
68 | 69 | | |||
70 | QAction *updateDB = actionCollection()->addAction(QLatin1String("ctags_update_global_db")); | ||||
71 | updateDB->setText(i18n("Update the Database")); | ||||
72 | connect(updateDB, &QAction::triggered, this, [this, plugin, mainWin] (bool) { | ||||
73 | KateCTagsPlugin *p = dynamic_cast<KateCTagsPlugin*>(plugin); | ||||
anthonyfieroni: Dynamic_cast is pretty expensive to not check against nullptr, use static_cast instead. | |||||
74 | QDialog *confWin = new QDialog(mainWin->window()); | ||||
75 | auto confPage = p->configPage(0, confWin); | ||||
76 | confPage->show(); | ||||
77 | confWin->exec(); | ||||
78 | }); | ||||
79 | | ||||
69 | // popup menu | 80 | // popup menu | ||
70 | m_menu = new KActionMenu(i18n("CTags"), this); | 81 | m_menu = new KActionMenu(i18n("CTags"), this); | ||
71 | actionCollection()->addAction(QLatin1String("popup_ctags"), m_menu); | 82 | actionCollection()->addAction(QLatin1String("popup_ctags"), m_menu); | ||
72 | 83 | | |||
73 | m_gotoDec=m_menu->menu()->addAction(i18n("Go to Declaration: %1",QString()), this, SLOT(gotoDeclaration())); | 84 | m_gotoDec=m_menu->menu()->addAction(i18n("Go to Declaration: %1",QString()), this, SLOT(gotoDeclaration())); | ||
74 | m_gotoDef=m_menu->menu()->addAction(i18n("Go to Definition: %1",QString()), this, SLOT(gotoDefinition())); | 85 | m_gotoDef=m_menu->menu()->addAction(i18n("Go to Definition: %1",QString()), this, SLOT(gotoDefinition())); | ||
75 | m_lookup=m_menu->menu()->addAction(i18n("Lookup: %1",QString()), this, SLOT(lookupTag())); | 86 | m_lookup=m_menu->menu()->addAction(i18n("Lookup: %1",QString()), this, SLOT(lookupTag())); | ||
76 | 87 | | |||
77 | connect(m_menu->menu(), &QMenu::aboutToShow, this, &KateCTagsView::aboutToShow); | 88 | connect(m_menu->menu(), &QMenu::aboutToShow, this, &KateCTagsView::aboutToShow); | ||
78 | 89 | | |||
anthonyfieroni: Add attribute to confWin deleteOnClose and make it parent of others. | |||||
79 | QWidget *ctagsWidget = new QWidget(m_toolView); | 90 | QWidget *ctagsWidget = new QWidget(m_toolView); | ||
80 | m_ctagsUi.setupUi(ctagsWidget); | 91 | m_ctagsUi.setupUi(ctagsWidget); | ||
81 | m_ctagsUi.cmdEdit->setText(DEFAULT_CTAGS_CMD); | 92 | m_ctagsUi.cmdEdit->setText(DEFAULT_CTAGS_CMD); | ||
82 | 93 | | |||
83 | m_ctagsUi.addButton->setToolTip(i18n("Add a directory to index.")); | 94 | m_ctagsUi.addButton->setToolTip(i18n("Add a directory to index.")); | ||
84 | m_ctagsUi.addButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); | 95 | m_ctagsUi.addButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); | ||
85 | 96 | | |||
86 | m_ctagsUi.delButton->setToolTip(i18n("Remove a directory.")); | 97 | m_ctagsUi.delButton->setToolTip(i18n("Remove a directory.")); | ||
Show All 26 Lines | |||||
113 | connect(m_ctagsUi.tagTreeWidget, &QTreeWidget::itemActivated, this, &KateCTagsView::tagHitClicked); | 124 | connect(m_ctagsUi.tagTreeWidget, &QTreeWidget::itemActivated, this, &KateCTagsView::tagHitClicked); | ||
114 | 125 | | |||
115 | connect(m_mWin, &KTextEditor::MainWindow::unhandledShortcutOverride, this, &KateCTagsView::handleEsc); | 126 | connect(m_mWin, &KTextEditor::MainWindow::unhandledShortcutOverride, this, &KateCTagsView::handleEsc); | ||
116 | 127 | | |||
117 | m_toolView->installEventFilter(this); | 128 | m_toolView->installEventFilter(this); | ||
118 | 129 | | |||
119 | m_mWin->guiFactory()->addClient(this); | 130 | m_mWin->guiFactory()->addClient(this); | ||
120 | 131 | | |||
121 | m_commonDB = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1String("/katectags/common_db"); | 132 | m_commonDB = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kate/katectags/common_db"); | ||
122 | } | 133 | } | ||
123 | 134 | | |||
124 | 135 | | |||
125 | /******************************************************************/ | 136 | /******************************************************************/ | ||
126 | KateCTagsView::~KateCTagsView() | 137 | KateCTagsView::~KateCTagsView() | ||
127 | { | 138 | { | ||
139 | if (m_mWin->guiFactory()) { | ||||
128 | m_mWin->guiFactory()->removeClient( this ); | 140 | m_mWin->guiFactory()->removeClient( this ); | ||
141 | } | ||||
129 | 142 | | |||
130 | delete m_toolView; | 143 | delete m_toolView; | ||
131 | } | 144 | } | ||
132 | 145 | | |||
133 | /******************************************************************/ | 146 | /******************************************************************/ | ||
134 | void KateCTagsView::aboutToShow() | 147 | void KateCTagsView::aboutToShow() | ||
135 | { | 148 | { | ||
136 | QString currWord = currentWord(); | 149 | QString currWord = currentWord(); | ||
▲ Show 20 Lines • Show All 352 Lines • ▼ Show 20 Line(s) | 495 | { | |||
489 | for (int i=0; i<m_ctagsUi.targetList->count(); i++) { | 502 | for (int i=0; i<m_ctagsUi.targetList->count(); i++) { | ||
490 | target = m_ctagsUi.targetList->item(i)->text(); | 503 | target = m_ctagsUi.targetList->item(i)->text(); | ||
491 | if (target.endsWith(QLatin1Char('/')) || target.endsWith(QLatin1Char('\\'))) { | 504 | if (target.endsWith(QLatin1Char('/')) || target.endsWith(QLatin1Char('\\'))) { | ||
492 | target = target.left(target.size() - 1); | 505 | target = target.left(target.size() - 1); | ||
493 | } | 506 | } | ||
494 | targets += target + QLatin1Char(' '); | 507 | targets += target + QLatin1Char(' '); | ||
495 | } | 508 | } | ||
496 | 509 | | |||
497 | QString pluginFolder = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1String("/katectags"); | 510 | QString pluginFolder = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("kate/katectags"); | ||
498 | QDir().mkpath(pluginFolder); | 511 | QDir().mkpath(pluginFolder); | ||
499 | 512 | | |||
500 | if (m_ctagsUi.tagsFile->text().isEmpty()) { | 513 | if (m_ctagsUi.tagsFile->text().isEmpty()) { | ||
501 | // FIXME we need a way to get the session name | 514 | // FIXME we need a way to get the session name | ||
502 | pluginFolder += QLatin1String("/session_db_"); | 515 | pluginFolder += QLatin1String("/session_db_"); | ||
503 | pluginFolder += QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyyyMMdd_hhmmss")); | 516 | pluginFolder += QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyyyMMdd_hhmmss")); | ||
504 | m_ctagsUi.tagsFile->setText(pluginFolder); | 517 | m_ctagsUi.tagsFile->setText(pluginFolder); | ||
505 | } | 518 | } | ||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |
Dynamic_cast is pretty expensive to not check against nullptr, use static_cast instead.