/* * 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("