/* * 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, TQWidget *dock) : CWidgetSnippets(dock,"snippetswidget") , dock (dock) { setInstance (new TDEInstance("kate")); setXMLFile("plugins/katesnippets/plugin_katesnippets.rc"); w->guiFactory()->addClient (this); win = w; // connect ( lvSnippets, TQT_SIGNAL( selectionChanged(TQListViewItem *) ), this, TQT_SLOT( slot_lvSnippetsSelectionChanged(TQListViewItem *) ) ); connect ( lvSnippets, TQT_SIGNAL( doubleClicked (TQListViewItem *) ), this, TQT_SLOT( slot_lvSnippetsClicked(TQListViewItem *) ) ); connect ( lvSnippets, TQT_SIGNAL( itemRenamed(TQListViewItem *, int, const TQString &) ), this, TQT_SLOT( slot_lvSnippetsItemRenamed(TQListViewItem *, int, const TQString &) ) ); connect ( btnNew, TQT_SIGNAL( clicked () ), this, TQT_SLOT( slot_btnNewClicked() ) ); connect ( btnSave, TQT_SIGNAL( clicked () ), this, TQT_SLOT( slot_btnSaveClicked() ) ); connect ( btnDelete, TQT_SIGNAL( clicked () ), this, TQT_SLOT( slot_btnDeleteClicked() ) ); // lSnippets.setAutoDelete( TRUE ); // the list owns the objects config = new TDEConfig("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( TQObject* parent, const char* name, const TQStringList& ) : Kate::Plugin ( (Kate::Application*)parent, name ) {} /** * dtor KatePluginSnippets * @return */ KatePluginSnippets::~KatePluginSnippets() {} /** * * @param win */ void KatePluginSnippets::addView(Kate::MainWindow *win) { TQWidget *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(TQListViewItem * item) { CSnippet *snippet; if ( (snippet = findSnippetByListViewItem(item))!= NULL ) { teSnippetText->setText(snippet->getValue()); } } /** * Special meaning of and ... * @param item */ void KatePluginSnippetsView::slot_lvSnippetsClicked (TQListViewItem * item) { Kate::View *kv = win->viewManager()->activeView(); CSnippet *snippet; if (kv) { if ( (snippet = findSnippetByListViewItem(item))!= NULL ) { TQString sText = snippet->getValue(); TQString sSelection = ""; if ( kv->getDoc()->hasSelection() ) { sSelection = kv->getDoc()->selection(); // clear selection kv->keyDelete(); } sText.replace( TQRegExp(""), sSelection ); sText.replace( TQRegExp(""), TQDate::currentDate().toString(Qt::LocalDate) ); sText.replace( TQRegExp("