From 84da08d7b7fcda12c85caeb5a10b4903770a6f69 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kate/snippets/plugin_katesnippets.cpp | 321 ++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 kate/snippets/plugin_katesnippets.cpp (limited to 'kate/snippets/plugin_katesnippets.cpp') diff --git a/kate/snippets/plugin_katesnippets.cpp b/kate/snippets/plugin_katesnippets.cpp new file mode 100644 index 0000000..07cba2b --- /dev/null +++ b/kate/snippets/plugin_katesnippets.cpp @@ -0,0 +1,321 @@ +/* + * Copyright (C) 2004 Stephan Möres + */ + +#include "plugin_katesnippets.h" + +#include +#include +#include +#include + + +// let the world know ... +K_EXPORT_COMPONENT_FACTORY(katesnippetsplugin, KGenericFactory( "katesnippets" ) ) + + +// < IMPLEMENTAIONS for KatePluginSnippetsView > +// +// + +/** + * ctor KatePluginSnippetsView + * @param w + * @return + */ +KatePluginSnippetsView::KatePluginSnippetsView(Kate::MainWindow *w, QWidget *dock) : CWidgetSnippets(dock,"snippetswidget") + , dock (dock) +{ + setInstance (new KInstance("kate")); + setXMLFile("plugins/katesnippets/plugin_katesnippets.rc"); + + w->guiFactory()->addClient (this); + win = w; + + + // + connect ( + lvSnippets, SIGNAL( selectionChanged(QListViewItem *) ), + this, SLOT( slot_lvSnippetsSelectionChanged(QListViewItem *) ) + ); + connect ( + lvSnippets, SIGNAL( doubleClicked (QListViewItem *) ), + this, SLOT( slot_lvSnippetsClicked(QListViewItem *) ) + ); + connect ( + lvSnippets, SIGNAL( itemRenamed(QListViewItem *, int, const QString &) ), + this, SLOT( slot_lvSnippetsItemRenamed(QListViewItem *, int, const QString &) ) + ); + + connect ( + btnNew, SIGNAL( clicked () ), + this, SLOT( slot_btnNewClicked() ) + ); + connect ( + btnSave, SIGNAL( clicked () ), + this, SLOT( slot_btnSaveClicked() ) + ); + connect ( + btnDelete, SIGNAL( clicked () ), + this, SLOT( slot_btnDeleteClicked() ) + ); + // + + lSnippets.setAutoDelete( TRUE ); // the list owns the objects + + config = new KConfig("katesnippetspluginrc"); + readConfig(); + + // set text of selected item at startup + slot_lvSnippetsSelectionChanged(lvSnippets->selectedItem() ); +} + + +/** + * dtor KatePluginSnippetsView + * @return + */ +KatePluginSnippetsView::~ KatePluginSnippetsView() { + writeConfig(); + + win->guiFactory()->removeClient(this); +} + + +// +// +// < IMPLEMENTAIONS for KatePluginSnippetsView > + + + + +// < IMPLEMENTAIONS for KatePluginSnippets > +// +// + +/** + * ctor KatePluginSnippets + * @param parent + * @param name + * @return + */ +KatePluginSnippets::KatePluginSnippets( QObject* parent, const char* name, const QStringList& ) + : Kate::Plugin ( (Kate::Application*)parent, name ) {} + +/** + * dtor KatePluginSnippets + * @return + */ +KatePluginSnippets::~KatePluginSnippets() {} + +/** + * + * @param win + */ +void KatePluginSnippets::addView(Kate::MainWindow *win) +{ + QWidget *dock = win->toolViewManager()->createToolView( + "kate_plugin_snippets", + Kate::ToolViewManager::Left, + SmallIcon("contents"), + i18n("Snippets")); + + KatePluginSnippetsView *view = new KatePluginSnippetsView (win,dock); + m_views.append(view); +} + + +/** + * + * @param win + */ +void KatePluginSnippets::removeView(Kate::MainWindow *win) { + for (uint z=0; z < m_views.count(); z++) + if (m_views.at(z)->win == win) { + KatePluginSnippetsView *view = m_views.at(z); + m_views.remove (view); + delete view->dock; + } +} + +/** + * + * @param item + */ +void KatePluginSnippetsView::slot_lvSnippetsSelectionChanged(QListViewItem * item) { + CSnippet *snippet; + if ( (snippet = findSnippetByListViewItem(item))!= NULL ) { + teSnippetText->setText(snippet->getValue()); + } + +} + + +/** + * Special meaning of and ... + * @param item + */ +void KatePluginSnippetsView::slot_lvSnippetsClicked (QListViewItem * item) { + Kate::View *kv = win->viewManager()->activeView(); + CSnippet *snippet; + + if (kv) { + if ( (snippet = findSnippetByListViewItem(item))!= NULL ) { + QString sText = snippet->getValue(); + QString sSelection = ""; + + if ( kv->getDoc()->hasSelection() ) { + sSelection = kv->getDoc()->selection(); + // clear selection + kv->keyDelete(); + } + + sText.replace( QRegExp(""), sSelection ); + sText.replace( QRegExp(""), QDate::currentDate().toString(Qt::LocalDate) ); + sText.replace( QRegExp("