• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Kate

iconinserterplugin.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  *   This file is part of the KTextEditor-Icon-Inserter-Plugin              *
00003  *   Copyright 2009-2010 Jonathan Schmidt-Dominé <devel@the-user.org>       *
00004  *                                                                          *
00005  *   This program is free software; you can redistribute it and/or modify   *
00006  *   it under the terms of the GNU Library General Public License version   *
00007  *   3, or (at your option) any later version, as published by the Free     *
00008  *   Software Foundation.                                                   *
00009  *                                                                          *
00010  *   This library is distributed in the hope that it will be useful, but    *
00011  *   WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
00013  *   Library General Public License for more details.                       *
00014  *                                                                          *
00015  *   You should have received a copy of the GNU Library General Public      *
00016  *   License along with the kdelibs library; see the file COPYING.LIB. If   *
00017  *   not, write to the Free Software Foundation, Inc., 51 Franklin Street,  *
00018  *   Fifth Floor, Boston, MA 02110-1301, USA. or see                        *
00019  *   <http://www.gnu.org/licenses/>.                                        *
00020  ****************************************************************************/
00021 
00022 #include "iconinserterplugin.h"
00023 
00024 #include <kicondialog.h>
00025 
00026 #include <kpluginfactory.h>
00027 #include <kaboutdata.h>
00028 #include <ktexteditor/document.h>
00029 #include <ktexteditor/view.h>
00030 #include <QMenu>
00031 #include <kactioncollection.h>
00032 
00033 
00034 
00035 K_PLUGIN_FACTORY_DEFINITION(IconInserterPluginFactory,
00036         registerPlugin<IconInserterPlugin>("ktexteditor_iconinserter");
00037         )
00038 K_EXPORT_PLUGIN(IconInserterPluginFactory(KAboutData ("ktexteditor_iconinserter","ktexteditor_iconinserter", ki18n ("Select an Icon to use it inside the Code"), "0.1", ki18n ("Insert Code for KIcon-Creation"), KAboutData::License_LGPL_V3)))
00039 
00040 
00041 IconInserterPluginView::IconInserterPluginView(IconInserterPlugin *plugin, KTextEditor::View *view): QObject(plugin),KXMLGUIClient(view),m_view(view)
00042 {
00043     setComponentData( IconInserterPluginFactory::componentData() );
00044     setXMLFile("ktexteditor_iconinserterui.rc");
00045     QAction *a=actionCollection()->addAction("iconinserter_inserticon",this,SLOT(insertIcon()));    
00046     a->setIcon(KIcon("kcoloredit"));
00047     a->setText(i18n ("Insert KIcon-Code"));
00048     a->setToolTip (i18n ("Insert Code for KIcon-Creation"));
00049     a->setWhatsThis (i18n ("<b>IconInserter</b><p> Select an icon and use it as a KIcon in your source code."));
00050 }
00051 
00052 IconInserterPluginView::~IconInserterPluginView()
00053 {
00054 }
00055 
00056 
00057 void IconInserterPluginView::insertIcon()
00058 {
00059     if (m_view.isNull()) return;
00060     QString iconName = KIconDialog::getIcon ( KIconLoader::Desktop,
00061                             KIconLoader::Application,
00062                             false,
00063                             0,
00064                             false,
00065                             0,
00066                             i18n( "Select the Icon you want to use in your code as KIcon." )
00067                         );
00068     if(iconName == "")
00069         return;
00070     
00071     View *view=m_view.data();
00072     Document *doc=view->document();
00073     
00074     
00075     QString suffix = doc->url().url();
00076     suffix = suffix.right(suffix.size() - suffix.lastIndexOf('.') - 1);
00077     QString code;
00078     if(suffix == "cpp" || suffix == "h" || suffix == "py")
00079         code = "KIcon (\"" + iconName + "\")";
00080     else if(suffix == "rb")
00081         code = "KDE::Icon.new (:\"" + iconName + "\")";
00082     else if(suffix == "js" || suffix == "qts" || suffix == "cs")
00083         code = "new KIcon (\"" + iconName + "\")";
00084     else if(suffix == "java")
00085         code = "new org.kde.kdeui.KIcon (\"" + iconName + "\")";
00086     else if(suffix == "fal" || suffix == "ftd")
00087         code = "KIcon ('" + iconName + "')";
00088     else if(suffix == "php")
00089         code = "new KIcon ('" + iconName + "')";
00090     else if(suffix == "pl")
00091         code = "KDE::Icon (\"" + iconName + "\")";
00092     else if(suffix == "pas")
00093         code = "KIcon_create ('" + iconName + "')";
00094     else if(suffix == "scm")
00095         code = "(make KIcon '" + iconName + ")";
00096     else if(suffix == "hs")
00097         code = "kIcon \"" + iconName + "\"";
00098     else if(suffix == "ads" || suffix == "adb")
00099         code = "KDEui.Icons.Constructos.Create (\"" + iconName + "\")";
00100     else
00101         code = iconName;
00102     doc->insertText(view->cursorPosition(), code);
00103 }
00104 
00105 
00106 
00107 
00108 IconInserterPlugin::IconInserterPlugin (QObject *parent, const QVariantList &)
00109     : Plugin (parent)
00110 {
00111 }
00112 
00113 IconInserterPlugin::~IconInserterPlugin()
00114 {
00115 }
00116 
00117 
00118 void IconInserterPlugin::addView (KTextEditor::View *view)
00119 {
00120     m_views.insert(view,new IconInserterPluginView(this,view));
00121 }
00122 
00123 void IconInserterPlugin::removeView(KTextEditor::View *view)
00124 {
00125     kDebug();
00126     delete m_views.take(view);
00127 }
00128 
00129 #include "iconinserterplugin.moc"

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal