diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /parts/tools | |
download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip |
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/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'parts/tools')
-rw-r--r-- | parts/tools/Makefile.am | 16 | ||||
-rw-r--r-- | parts/tools/README.dox | 12 | ||||
-rw-r--r-- | parts/tools/addtooldlg.ui | 245 | ||||
-rw-r--r-- | parts/tools/addtooldlg.ui.h | 31 | ||||
-rw-r--r-- | parts/tools/kapplicationtree.cpp | 258 | ||||
-rw-r--r-- | parts/tools/kapplicationtree.h | 102 | ||||
-rw-r--r-- | parts/tools/kdevpart_tools.rc | 14 | ||||
-rw-r--r-- | parts/tools/kdevtools.desktop | 82 | ||||
-rw-r--r-- | parts/tools/tools_part.cpp | 272 | ||||
-rw-r--r-- | parts/tools/tools_part.h | 55 | ||||
-rw-r--r-- | parts/tools/toolsconfig.cpp | 169 | ||||
-rw-r--r-- | parts/tools/toolsconfig.h | 71 | ||||
-rw-r--r-- | parts/tools/toolsconfigwidget.cpp | 284 | ||||
-rw-r--r-- | parts/tools/toolsconfigwidget.h | 60 | ||||
-rw-r--r-- | parts/tools/toolsconfigwidgetbase.ui | 410 |
15 files changed, 2081 insertions, 0 deletions
diff --git a/parts/tools/Makefile.am b/parts/tools/Makefile.am new file mode 100644 index 00000000..887ccdd5 --- /dev/null +++ b/parts/tools/Makefile.am @@ -0,0 +1,16 @@ +INCLUDES = -I$(top_srcdir)/lib/interfaces \ + -I$(top_srcdir)/lib/interfaces/extensions -I$(top_srcdir)/lib/util $(all_includes) + +kde_module_LTLIBRARIES = libkdevtools.la +libkdevtools_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) +libkdevtools_la_LIBADD = $(top_builddir)/lib/libkdevelop.la + +libkdevtools_la_SOURCES = tools_part.cpp toolsconfig.cpp toolsconfigwidgetbase.ui toolsconfigwidget.cpp kapplicationtree.cpp addtooldlg.ui + +METASOURCES = AUTO + +servicedir = $(kde_servicesdir) +service_DATA = kdevtools.desktop + +rc_DATA = kdevpart_tools.rc +rcdir = $(kde_datadir)/kdevtools diff --git a/parts/tools/README.dox b/parts/tools/README.dox new file mode 100644 index 00000000..00eab3bf --- /dev/null +++ b/parts/tools/README.dox @@ -0,0 +1,12 @@ +/** \class ToolsPart +This plugin provides an easy way to add external applications to the Tools menu and toolbar. + +\authors <a href="mailto:bernd AT kdevelop.org">Bernd Gehrmann</a> + +\unmaintained This part is currently un-maintained. + +\feature Provides an easy way to add external applications to the Tools menu and toolbar. +\feature Tool menu and the file and directory context menus can now be populated with any shell command. +\feature Output can be sent to the app output part. %S, %D, %T and %W magic works. + +*/ diff --git a/parts/tools/addtooldlg.ui b/parts/tools/addtooldlg.ui new file mode 100644 index 00000000..2ec5e8b4 --- /dev/null +++ b/parts/tools/addtooldlg.ui @@ -0,0 +1,245 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>AddToolDialog</class> +<widget class="QDialog"> + <property name="name"> + <cstring>add_tool_dialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>314</width> + <height>514</height> + </rect> + </property> + <property name="caption"> + <string>Add Tool</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>cmdlineLabel_2</cstring> + </property> + <property name="text"> + <string>&Parameters:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>paramEdit</cstring> + </property> + </widget> + <widget class="QCheckBox" row="4" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>capturedBox</cstring> + </property> + <property name="text"> + <string>C&apture output</string> + </property> + <property name="whatsThis" stdset="0"> + <string>If this is checked, the output of the application will be shown in the application output view; otherwise, all output will be ignored.</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>cmdlineLabel</cstring> + </property> + <property name="text"> + <string>&Executable:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>execEdit</cstring> + </property> + </widget> + <widget class="Line" row="5" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Line1</cstring> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>menutextLabel</cstring> + </property> + <property name="text"> + <string>&Menu text:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>menutextEdit</cstring> + </property> + </widget> + <widget class="KLineEdit" row="3" column="1"> + <property name="name"> + <cstring>paramEdit</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><p>The following placeholders can be used:</p> +<p> +<b>%D</b> - The project directory<br> +<b>%S</b> - The current filename<br> +<b>%T</b> - The current selection<br> +<b>%W</b> - The current word under the cursor<br> +</p> +<p>If any of the used placeholders cannot be evaluated (for example +if you use %T but there is no current selection), the tool will not be +executed.</p></string> + </property> + </widget> + <widget class="KLineEdit" row="1" column="1"> + <property name="name"> + <cstring>menutextEdit</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string>The text that appears in the Tools-Menu</string> + </property> + </widget> + <widget class="QLayoutWidget" row="6" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <spacer> + <property name="name"> + <cstring>Spacer4</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>0</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>okButton</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>cancelButton</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + </widget> + </hbox> + </widget> + <widget class="KURLRequester" row="2" column="1"> + <property name="name"> + <cstring>execEdit</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string>The path and name of the application to execute</string> + </property> + </widget> + <widget class="KDevApplicationTree" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>tree</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="focusPolicy"> + <enum>StrongFocus</enum> + </property> + </widget> + </grid> +</widget> +<customwidgets> + <customwidget> + <class>KDevApplicationTree</class> + <header location="local">kapplicationtree.h</header> + <sizehint> + <width>-1</width> + <height>-1</height> + </sizehint> + <container>0</container> + <sizepolicy> + <hordata>5</hordata> + <verdata>5</verdata> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + <pixmap>image0</pixmap> + </customwidget> +</customwidgets> +<images> + <image name="image0"> + <data format="XPM.GZ" length="4350">789c6dd7594f23471007f0f7fd14d6d6db2aaaf58c3db647511eb831b7317794879ac30760cc61c010e5bba7dcf5af5688167664fdb66bbaababbb67cccf1f8dab93c3c68f9fdf5e16b298968d7222cf8d1fd5eb6cf6f1e75f7ffcfded7b9a3656ff9aad46fafdb76fdf078b46d9389a3fd42bf04841699e964933b830b79a7019dd0b96955b895b5a703bcd572e08eea576ff6570ae0eedd477b792103f854b8b2fc6d1163f77237e646e37113f89b6f8307e3bf1785a8b0eedbc696eb7ad9db7e01ee6476ee4ffe0c6fd158c7c69182cde4eec6e87fea50dfbf8176e6ba7d07f96669999cfa325ccaf862bcc97a36dbccf60f178cee11cde706761f16917ae30fe6b7488a7851bf14d7327417f676eb4f756eea41e2f57e6d83e83919f6cba117f04235fd9765b3b0fa36dfc398cf973edc67a6fb951ffe768ab6765ee26b8dff213ef5f4630e2b9e7463ea7ee8ee5ff60ee2618af8eb6fe3238437eb91bf1299cdbfacad3cadd5617f5a11738c7fe4adcb8ffd68d7aeec15e8fc3683b9f62ee2518ef33dafa3f75e3bc957086f86eb4d56f3db8e8e6dd56f01a5cc1bbe65e629673d8ebd18d0efdc9058cf9f2c08df9e630ce037db8719ec37c7a9a7fb708f10267b65e7cef46fb3e9ca3fd23dad6ef0cf67abe99f304f95ec3a8871cbb71be52d8d777e8b6fee412f6f958be3adf5ea817b561afe7d86ded7c67ce13c46fc37ede2766c17a17059cd9f38e466e8c3f8eb6fd700f0b9ef7095c37cd3d37de178f2be76dcf876fa343bd790267f012f67a77cc319f69b4ed872e2ca8e732daeabfe3c6fa9cc235f21f9b8bd4f2a5cd687bfedbfd659ee7ede017b842becf6eb44fa3cbd0df8559b0ffe808ceb0ff37e01afba3652e52cc87a26dbe276ecca7097790ff73b4cdef0616ac4fdf6df1c2d1d67ee8c6f80318eb4bd1180ff529513f0ecf7b694b62f5a002ceccb2662e523c2fb7605f9f0fd8fbbf75e3bc2dcd3e9ebcb9f17ce8c05e8f83685bcf701e44eb2db65e4fd1b65eebe62245be53b8c6f3ffdd8dfd3933fbf884761f5f0edcd88f951bf118bf44bde926dae24fe01ae7af76e3f9169e2f45bb143c0f5fdcf6fea23b18f773eac6f3e63ddac6db75e37df5e8c6fbae65aebcde6d37beaf84f528aa52f03c9dc3359ea79939c627d136deab1befaf75b883ef23e76e3ccfaea36d7dc2f795322b05ebfb0ad738af7db7ad371f99fd7e59b8b13f276e9cdf1318f5e54337e6d78cb67cf761ec170efba1acaa1afd9db92d3f3a36d729ea77efc6f33cbccf2beddfe6478fe6d85e45dbfd851bf1577007f5d877e3bc86f5a9ea3a2d6cffdfc1debe116df5db73a39e37b0e777191dda257c7fa83b6e8a2eaae00eeceb13d6b7d69f325b79b058fd32b170c1a55ebffaac2ccae2b9e6118f79c253bd6ef9ee3fd7587fef79c60f7acf3cc617fcc84ffcac6d8ffcc20b7ee5377ee7257ff027aff1bac66ff0269716cf5b1ab7cd3bbcabb17ddee37d3ee0433ee2633ee1019ff290cff89c2ff89229c48b66f1ac3d5df135df7093134eb9c56dcef4b3c35dee71ce393111dbfa8c784a4205955451cd1d1ad1982634a55bbad3f80eddd38c1ef882e66cf52ab5ff2b8d7ea4277aa6175ad06bb866f446efb4d4df0ffad4fed762ffb7b44e1b9cd2266dd142c75e5ddb3cd0bb3e347a477bd9d5f83ee245e3f7689f0ee830f67d44c77412ee186946033aa5e197fecfe85c7bf7be2fe892aee89a6ea84989f6bfa434f4eff9df52c509b5d0779b32ea684d13ea528f728d1e882ebfce37f6cf077422b4ea5b440ad14af1a15452ab473aee52c65ff39789b64fe955f44eb9937b5d858c5b32d377c0c32a7fee7ecd5fe61aff284ff22c2fb290577993775db1443fb53ef2219f5ff2bf93356d5b970dd9d41eb77820dbb223bbab155ed55ffab2f725ffb1eccb81aed6931cca116ab490633909d10339fd5ffdef795d869ae7923bc27226e772415d5986b51d683663b9d4fcfbb1ff190fe54aaec35aeaa577ee20f24673e94b531249a585fc2b69ebfe3ed7dae91f75ba964b5c03e9d344ba1add93bce0826c3f87f3b2a9fb6f18aeba10ba2f563f25eb1b563771a5d17531e2513c5fba538b3111cd690dd73c7ef6a95f4c8aa99de12fe77da4951de9ffffea730be7fd9fdfbffd0b690edc6c</data> + </image> +</images> +<connections> + <connection> + <sender>okButton</sender> + <signal>clicked()</signal> + <receiver>add_tool_dialog</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>cancelButton</sender> + <signal>clicked()</signal> + <receiver>add_tool_dialog</receiver> + <slot>reject()</slot> + </connection> +</connections> +<tabstops> + <tabstop>tree</tabstop> + <tabstop>menutextEdit</tabstop> + <tabstop>execEdit</tabstop> + <tabstop>paramEdit</tabstop> + <tabstop>capturedBox</tabstop> + <tabstop>okButton</tabstop> + <tabstop>cancelButton</tabstop> +</tabstops> +<includes> + <include location="global" impldecl="in implementation">kdialog.h</include> + <include location="local" impldecl="in implementation">addtooldlg.ui.h</include> +</includes> +<forwards> + <forward>class QListViewItem;</forward> +</forwards> +<slots> + <slot>init()</slot> + <slot returnType="QString">getApp()</slot> + <slot access="private">treeSelectionChanged( QListViewItem * lvi )</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/> +<includehints> + <includehint>kurlrequester.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/parts/tools/addtooldlg.ui.h b/parts/tools/addtooldlg.ui.h new file mode 100644 index 00000000..d01c4da7 --- /dev/null +++ b/parts/tools/addtooldlg.ui.h @@ -0,0 +1,31 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename slots use Qt Designer which will +** update this file, preserving your code. Create an init() slot in place of +** a constructor, and a destroy() slot in place of a destructor. +*****************************************************************************/ + +#include <qheader.h> +#include <kurlrequester.h> +#include "kapplicationtree.h" + +void AddToolDialog::init() +{ + connect( tree, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(treeSelectionChanged(QListViewItem*)) ); + tree->header()->hide(); +} + +QString AddToolDialog::getApp() +{ + return execEdit->url() + " " + paramEdit->text(); +} + +void AddToolDialog::treeSelectionChanged( QListViewItem * lvi ) +{ + KDevAppTreeListItem* item = dynamic_cast<KDevAppTreeListItem*> ( lvi ); + if ( !item || item->isDirectory() ) + return; + execEdit->setURL( item->executable() ); + menutextEdit->setText( item->text( 0 ) ); +} diff --git a/parts/tools/kapplicationtree.cpp b/parts/tools/kapplicationtree.cpp new file mode 100644 index 00000000..dd33e851 --- /dev/null +++ b/parts/tools/kapplicationtree.cpp @@ -0,0 +1,258 @@ +/* This file is part of the KDE libraries + Nicked from KDElibs since KDevApplicationTree is not a public class.. + + Copyright (C) 1997 Torben Weis <weis@stud.uni-frankfurt.de> + Copyright (C) 1999 Dirk A. Mueller <dmuell@gmx.net> + Portions copyright (C) 1999 Preston Brown <pbrown@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include <qfile.h> +#include <qdir.h> +#include <qdialog.h> +#include <qpixmap.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qpushbutton.h> +#include <qtoolbutton.h> +#include <qcheckbox.h> +#include <qtooltip.h> +#include <qstyle.h> + +#include <kapplication.h> +#include <kbuttonbox.h> +#include <kcombobox.h> +#include <kdesktopfile.h> +#include <kdialog.h> +#include <kglobal.h> +#include <klineedit.h> +#include <klocale.h> +#include <kiconloader.h> +#include <kmimemagic.h> +#include <krun.h> +#include <kstandarddirs.h> +#include <kstringhandler.h> +#include <kuserprofile.h> +#include <kurlcompletion.h> +#include <kurlrequester.h> +#include <dcopclient.h> +#include <kmimetype.h> +#include <kservicegroup.h> +#include <klistview.h> +#include <ksycoca.h> +#include <kdebug.h> + +#include "kapplicationtree.h" + +template class QPtrList<QString>; + +#define SORT_SPEC (QDir::DirsFirst | QDir::Name | QDir::IgnoreCase) + + +// ---------------------------------------------------------------------- + +KDevAppTreeListItem::KDevAppTreeListItem( KListView* parent, const QString & name, + const QPixmap& pixmap, bool parse, bool dir, const QString& p, const QString& c, const QString& dE ) + : QListViewItem( parent, name ) +{ + init(pixmap, parse, dir, p, c, dE); +} + + +// ---------------------------------------------------------------------- + +KDevAppTreeListItem::KDevAppTreeListItem( QListViewItem* parent, const QString & name, + const QPixmap& pixmap, bool parse, bool dir, const QString& p, const QString& c, const QString& dE ) + : QListViewItem( parent, name ) +{ + init(pixmap, parse, dir, p, c, dE); +} + + +// ---------------------------------------------------------------------- + +void KDevAppTreeListItem::init(const QPixmap& pixmap, bool parse, bool dir, const QString& _path, const QString& _exec, const QString& _dEntry) +{ + setPixmap(0, pixmap); + parsed = parse; + directory = dir; + path = _path; // relative path + exec = _exec; + dEntry = _dEntry; + exec.simplifyWhiteSpace(); + exec.truncate(exec.find(' ')); +} + + +// ---------------------------------------------------------------------- +// Ensure that dirs are sorted in front of files and case is ignored + +QString KDevAppTreeListItem::key(int column, bool /*ascending*/) const +{ + if (directory) + return QString::fromLatin1(" ") + text(column).upper(); + else + return text(column).upper(); +} + +void KDevAppTreeListItem::activate() +{ + if ( directory ) + setOpen(!isOpen()); +} + +void KDevAppTreeListItem::setOpen( bool o ) +{ + if( o && !parsed ) { // fill the children before opening + ((KDevApplicationTree *) parent())->addDesktopGroup( path, this ); + parsed = true; + } + QListViewItem::setOpen( o ); +} + +bool KDevAppTreeListItem::isDirectory() +{ + return directory; +} + +// ---------------------------------------------------------------------- + +KDevApplicationTree::KDevApplicationTree( QWidget *parent, const char* name ) + : KListView( parent, name ), currentitem(0) +{ + addColumn( i18n("Known Applications") ); + setRootIsDecorated( true ); + + addDesktopGroup( QString::null ); + + connect( this, SIGNAL( currentChanged(QListViewItem*) ), SLOT( slotItemHighlighted(QListViewItem*) ) ); + connect( this, SIGNAL( selectionChanged(QListViewItem*) ), SLOT( slotSelectionChanged(QListViewItem*) ) ); +} + +// ---------------------------------------------------------------------- + +bool KDevApplicationTree::isDirSel() +{ + if (!currentitem) return false; // if currentitem isn't set + return currentitem->isDirectory(); +} + +// ---------------------------------------------------------------------- + +void KDevApplicationTree::addDesktopGroup( QString relPath, KDevAppTreeListItem *item) +{ + KServiceGroup::Ptr root = KServiceGroup::group(relPath); + KServiceGroup::List list = root->entries(); + + KDevAppTreeListItem * newItem; + for( KServiceGroup::List::ConstIterator it = list.begin(); + it != list.end(); it++) + { + QString icon; + QString text; + QString relPath; + QString exec; + QString dEntry; + bool isDir = false; + KSycocaEntry *p = (*it); + if (p->isType(KST_KService)) + { + KService *service = static_cast<KService *>(p); + icon = service->icon(); + text = service->name(); + exec = service->exec(); + dEntry = service->desktopEntryPath(); + } + else if (p->isType(KST_KServiceGroup)) + { + KServiceGroup *serviceGroup = static_cast<KServiceGroup *>(p); + icon = serviceGroup->icon(); + text = serviceGroup->caption(); + relPath = serviceGroup->relPath(); + isDir = true; + if ( text[0] == '.' ) // skip ".hidden" like kicker does + continue; + // avoid adding empty groups + KServiceGroup::Ptr subMenuRoot = KServiceGroup::group(relPath); + if (subMenuRoot->childCount() == 0) + continue; + } + else + { + kdWarning(250) << "KServiceGroup: Unexpected object in list!" << endl; + continue; + } + + QPixmap pixmap = SmallIcon( icon ); + + if (item) + newItem = new KDevAppTreeListItem( item, text, pixmap, false, isDir, + relPath, exec, dEntry ); + else + newItem = new KDevAppTreeListItem( this, text, pixmap, false, isDir, + relPath, exec, dEntry ); + if (isDir) + newItem->setExpandable( true ); + } +} + + +// ---------------------------------------------------------------------- + +void KDevApplicationTree::slotItemHighlighted(QListViewItem* i) +{ + // i may be 0 (see documentation) + if(!i) + return; + + KDevAppTreeListItem *item = (KDevAppTreeListItem *) i; + + currentitem = item; + + if( (!item->directory ) && (!item->exec.isEmpty()) ) + emit highlighted( item->text(0), item->exec ); +} + + +// ---------------------------------------------------------------------- + +void KDevApplicationTree::slotSelectionChanged(QListViewItem* i) +{ + // i may be 0 (see documentation) + if(!i) + return; + + KDevAppTreeListItem *item = (KDevAppTreeListItem *) i; + + currentitem = item; + + if( ( !item->directory ) && (!item->exec.isEmpty() ) ) + emit selected( item->text(0), item->exec ); +} + +// ---------------------------------------------------------------------- + +void KDevApplicationTree::resizeEvent( QResizeEvent * e) +{ + setColumnWidth(0, width()-QApplication::style().pixelMetric(QStyle::PM_ScrollBarExtent)); + KListView::resizeEvent(e); +} + + + +#include "kapplicationtree.moc" + diff --git a/parts/tools/kapplicationtree.h b/parts/tools/kapplicationtree.h new file mode 100644 index 00000000..7c11870a --- /dev/null +++ b/parts/tools/kapplicationtree.h @@ -0,0 +1,102 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 David Faure <faure@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +#ifndef __KDevApplicationTree_h__ +#define __KDevApplicationTree_h__ + +#include <kurl.h> +#include <klistview.h> + +class KURLRequester; + +class QWidget; +class QCheckBox; +class QPushButton; +class QLabel; +class QStringList; + + +/* ------------------------------------------------------------------------- */ + +/** + * @internal + */ +class KDevAppTreeListItem : public QListViewItem +{ + bool parsed; + bool directory; + QString path; + QString exec; + QString dEntry; + +protected: + QString key(int column, bool ascending) const; + + void init(const QPixmap& pixmap, bool parse, bool dir, const QString& _path, const QString& _exec, const QString& _dEntry); + +public: + KDevAppTreeListItem( KListView* parent, const QString & name, const QPixmap& pixmap, + bool parse, bool dir, const QString& p, const QString& c, const QString& dE ); + KDevAppTreeListItem( QListViewItem* parent, const QString & name, const QPixmap& pixmap, + bool parse, bool dir, const QString& p, const QString& c, const QString& dE ); + bool isDirectory(); + + QString desktopEntryPath() const { return dEntry; } + QString executable() const { return exec; } + +protected: + virtual void activate(); + virtual void setOpen( bool o ); + + friend class KDevApplicationTree; +}; + +/* ------------------------------------------------------------------------- */ + +/** + * @internal + */ +class KDevApplicationTree : public KListView +{ + Q_OBJECT +public: + KDevApplicationTree( QWidget *parent, const char* name = 0 ); + + /** + * Add a group of .desktop/.kdelnk entries + */ + void addDesktopGroup( QString relPath, KDevAppTreeListItem *item = 0 ); + + bool isDirSel(); + +protected: + void resizeEvent( QResizeEvent *_ev ); + KDevAppTreeListItem* currentitem; + +public slots: + void slotItemHighlighted(QListViewItem* i); + void slotSelectionChanged(QListViewItem* i); + +signals: + void selected( const QString& _name, const QString& _exec ); + void highlighted( const QString& _name, const QString& _exec ); +}; + +/* ------------------------------------------------------------------------- */ + +#endif diff --git a/parts/tools/kdevpart_tools.rc b/parts/tools/kdevpart_tools.rc new file mode 100644 index 00000000..ab8a6a98 --- /dev/null +++ b/parts/tools/kdevpart_tools.rc @@ -0,0 +1,14 @@ +<!DOCTYPE kpartgui> +<kpartplugin name="tools" library="libtoolsplugin" version="1"> +<MenuBar> + <Menu name="tools"> + <text>&Tools</text> + <ActionList name="tools_list"/> + <ActionList name="tools2_list"/> + </Menu> +</MenuBar> +<ToolBar position="Top" iconText="IconOnly" noMerge="1" name="extraToolBar" fullWidth="false" hidden="true" > + <text>Tools Toolbar</text> + <ActionList name="tools_list"/> +</ToolBar> +</kpartplugin> diff --git a/parts/tools/kdevtools.desktop b/parts/tools/kdevtools.desktop new file mode 100644 index 00000000..5e245562 --- /dev/null +++ b/parts/tools/kdevtools.desktop @@ -0,0 +1,82 @@ +[Desktop Entry] +Type=Service +Exec=blubb +Comment=This plugin provides an easy way to add external applications to the Tools menu and toolbar. +Comment[ca]=Aquest connector proporciona un mètode fàcil per afegir aplicacions externes en el menú Eines i a la barra d'eines. +Comment[da]=Dette plugin sørger for en nem måde at tilføje eksterne programmer til værktøjsmenuen og værktøjslinjen. +Comment[de]=Dieses Modul erleichtert das Hinzufügen externer Anwendungen zum Menü "Werkzeuge" und in die Werkzeugleiste. +Comment[el]=Αυτό το πρόσθετο προσφέρει μια εύκολη μέθοδο για τη προσθήκη εξωτερικών εφαρμογών στο μενού εργαλείων και τη γραμμή εργαλείων. +Comment[es]=Este complemento proporciona un método sencillo para añadir aplicaciones externas en el menú de Herramientas y en la barra de herramientas. +Comment[et]=See plugin võimaldab hõlpsasti lisada väliseid rakendusi tööriistade menüüsse ja tööriistaribale. +Comment[eu]=Plugin honek kanpoko aplikazioak Tresnak menu eta tresna-barran erraz gehitzeko aukera eskeintzen du. +Comment[fa]=این وصله، راه آسانی را برای افزودن کاربردهای خارجی به گزینگان ابزار و میله ابزار فراهم میکند. +Comment[fr]=Ce module externe fournit un moyen facile d'ajouter des applications externes au menu « Outils » et à la barre d'outils. +Comment[gl]=Esta extensión proporciona un método sinxelo para engadir aplicacións externas ao menú Ferramentas e á barra de ferramentas. +Comment[hu]=Ez a bővítőmodul lehetővé teszi az Eszközök menü és az eszköztár egyszerű kibővítését +Comment[it]=Questo plugin offre un modo per aggiungere applicazioni esterne al menu o alla barra degli strumenti. +Comment[ja]=このプラグインはツールメニューやツールバーに外部のアプリケーションを追加する簡単な方法を提供します。 +Comment[ms]=Plugin ini menyediakan cara mudah untuk menambah aplikasi luaran ke menu Alatan dan bar alatan. +Comment[nds]=Mit dit Moduul laat sik extern Programmen eenfach na dat "Warktüüch"-Menü un den Warktüüchbalken tofögen. +Comment[ne]=यो प्लगइनले उपकरण मेनु र उपकरणपट्टीमा बाह्य अनुप्रयोग थप्न सजिलो तरिका प्रदान गर्दछ । +Comment[nl]=Met deze plugin kunt u op eenvoudige wijze externe toepassingen aan het menu Gereedschap en de werkbalk toevoegen. +Comment[pl]=Ta wtyczka umożliwia łatwe dodawanie zewnętrznych programów do menu Narzędzia i do paska narzędzi. +Comment[pt]=Este 'plugin' oferece uma forma simples de adicionar as aplicações externas ao menu Ferramentas e à barra de ferramentas. +Comment[pt_BR]=Este plug-in fornece uma maneira fácil de adicionar aplicativos externos ao menu Ferramentas e barra de ferramentas. +Comment[ru]=Предоставляет возможности добавления в меню пунктов вызова внешних приложений. +Comment[sk]=Modul poskytuje jednoduchý spôsob ako pridať externú aplikáciu do menu Nástroje a do panelu nástrojov. +Comment[sl]=Ta vstavek omogoča preprost način dodajanja zunanjih programov v meni Orodja in v orodjarno. +Comment[sr]=Овај прикључак обезбеђује лак начин за додавање спољних програма у мени „Алати“ и у траку са алатом. +Comment[sr@Latn]=Ovaj priključak obezbeđuje lak način za dodavanje spoljnih programa u meni „Alati“ i u traku sa alatom. +Comment[sv]=Insticksprogrammet tillhandahåller ett enkelt sätt att lägga till yttre program i verktygsmenyn och verktygsraden. +Comment[ta]=இந்த சொருகி கருவிப்பட்டியல் மற்றும் கருவிப்பட்டையில் வெளிபுற பயன்பாடு எளிய முறையில் சேர்க்கலாம். +Comment[tg]=Барои илова намудан дар меню нуқтаҳои ҷеғ задани гузоришҳои берунро имкон медиҳад. +Comment[zh_CN]=这个插件提供向工具菜单和工具栏添加外部程序的方法。 +Comment[zh_TW]=此外掛程式提供一個簡單的方式,將外部應用程式新增到工具選單與工具列中。 +Name=KDevTools +Name[da]=KDevelop Værktøjer +Name[de]="Werkzeug"-Menüerweiterung (KDevelop) +Name[hi]=के-डेव-टूल्स +Name[nds]=Warktüüch-Menüverwiedern (KDevelop) +Name[pl]=KDevNarzędzia +Name[sk]=KDev nástroje +Name[sv]=KDevelop verktyg +Name[ta]=KDev கருவிகள் +Name[tg]=Асбобҳои KDev +Name[zh_TW]=KDevelop 工具 +GenericName=Tools Menu Addition +GenericName[ca]=Afegiment al menú Eines +GenericName[da]=Værktøjsmenu tilføjelse +GenericName[de]="Werkzeuge"-Menüerweiterung +GenericName[el]=Προσθήκη μενού εργαλείων +GenericName[es]=Añadir al menú Herramientas +GenericName[et]=Tööriistade menüü lisamine +GenericName[eu]=Tresnak menuan gehitu +GenericName[fa]=افزودن گزینگان ابزار +GenericName[fr]=Ajout au menu « Outils » +GenericName[gl]=Engadidos ao menú Ferramentas +GenericName[hu]=Bővítés az Eszközök menühöz +GenericName[it]=Aggiunte al menu Strumenti +GenericName[ja]=ツールメニュー追加 +GenericName[nds]=Warktüüch-Menüverwiedern +GenericName[ne]=उपकरण मेनु अतिरिक्त +GenericName[nl]=Gereedschapsmenu-toevoeging +GenericName[pl]=Dodatek do menu Narzędzia +GenericName[pt]=Adicionar ao Menu de Ferramentas +GenericName[pt_BR]=Adição ao Menu Ferramentas +GenericName[ru]=Дополнение меню инструментов +GenericName[sk]=Prídavky menu Nástroje +GenericName[sl]=Dodatek menija orodij +GenericName[sr]=Додаци менију „Алати“ +GenericName[sr@Latn]=Dodaci meniju „Alati“ +GenericName[sv]=Tillägg i verktygsmenyn +GenericName[ta]=கருவிப்பட்டியல் சேர்ப்பு +GenericName[tg]=Асбобҳои иловагии меню +GenericName[tr]=Araçlar Menü Eklemesi +GenericName[zh_CN]=工具菜单附加 +GenericName[zh_TW]=新增工具選單 +Icon=configure +ServiceTypes=KDevelop/Plugin +X-KDE-Library=libkdevtools +X-KDevelop-Version=5 +X-KDevelop-Scope=Global +X-KDevelop-Properties=AdditionalTools diff --git a/parts/tools/tools_part.cpp b/parts/tools/tools_part.cpp new file mode 100644 index 00000000..f4285546 --- /dev/null +++ b/parts/tools/tools_part.cpp @@ -0,0 +1,272 @@ +#include "tools_part.h" + +#include <qfile.h> +#include <qpopupmenu.h> +#include <qregexp.h> +#include <qtimer.h> +#include <qvbox.h> +#include <qwhatsthis.h> + +#include <kaction.h> +#include <kapplication.h> +#include <kconfig.h> +#include <kdebug.h> +#include <kdesktopfile.h> +#include <kdialogbase.h> +#include <kiconloader.h> +#include <klocale.h> +#include <kparts/part.h> +#include <kprocess.h> +#include <ktexteditor/document.h> + +#include "kdevcore.h" +#include "kdevproject.h" +#include "kdevpartcontroller.h" +#include "kdevappfrontend.h" +#include "kdevplugininfo.h" +#include "urlutil.h" +#include "configwidgetproxy.h" +#include "kdeveditorutil.h" + +#include "toolsconfig.h" +#include "toolsconfigwidget.h" + +#define TOOLSSETTINGS 1 +#define EXTRATOOLSSETTINGS 2 + +static const KDevPluginInfo data("kdevtools"); +K_EXPORT_COMPONENT_FACTORY( libkdevtools, ToolsFactory( data ) ) + +QMap<int, QString> externalToolMenuEntries; + +ToolsPart::ToolsPart(QObject *parent, const char *name, const QStringList &) + : KDevPlugin( &data, parent, name ? name : "ToolsPart") +{ + setInstance(ToolsFactory::instance()); + + setXMLFile("kdevpart_tools.rc"); + + m_configProxy = new ConfigWidgetProxy( core() ); + m_configProxy->createGlobalConfigPage( i18n("Tools Menu"), TOOLSSETTINGS, info()->icon() ); + m_configProxy->createGlobalConfigPage( i18n("External Tools"), EXTRATOOLSSETTINGS, info()->icon() ); + connect( m_configProxy, SIGNAL(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int )), + this, SLOT(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int )) ); + + connect(core(), SIGNAL(coreInitialized()), this, SLOT(updateMenu())); + + connect( core(), SIGNAL(contextMenu(QPopupMenu *, const Context *)), + this, SLOT(contextMenu(QPopupMenu *, const Context *)) ); + + // Apparently action lists can only be plugged after the + // xmlgui client has been registered + QTimer::singleShot(0, this, SLOT(updateToolsMenu())); +} + + +ToolsPart::~ToolsPart() +{ + delete m_configProxy; +} + +void ToolsPart::insertConfigWidget( const KDialogBase * dlg, QWidget * page, unsigned int pagenumber ) +{ + if ( pagenumber == TOOLSSETTINGS ) + { + ToolsConfig *w = new ToolsConfig( page, "tools config widget" ); + connect(dlg, SIGNAL(okClicked()), w, SLOT(accept())); + connect(dlg, SIGNAL(destroyed()), this, SLOT(updateMenu())); + } + else if ( pagenumber == EXTRATOOLSSETTINGS ) + { + ToolsConfigWidget *w2 = new ToolsConfigWidget( page, "tools config widget" ); + connect(dlg, SIGNAL(okClicked()), w2, SLOT(accept())); + connect(dlg, SIGNAL(destroyed()), this, SLOT(updateToolsMenu())); + } +} + +void ToolsPart::updateMenu() +{ + QPtrList<KAction> actions; + + unplugActionList("tools_list"); + + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("Tools"); + + QStringList list = config->readListEntry("Tools"); + for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) + { + QString name = *it; + + KDesktopFile df(name, true); + if (df.readName().isNull()) + continue; + + KAction *action = new KAction(df.readName(), df.readIcon(), 0, + this, SLOT(slotToolActivated()), (QObject*)0, name.latin1()); + actions.append(action); + } + + plugActionList("tools_list", actions); +} + + +void ToolsPart::slotToolActivated() +{ + QString df = sender()->name(); + kapp->startServiceByDesktopPath(df); +} + +void ToolsPart::startCommand(QString cmdline, bool captured, QString fileName) +{ + KTextEditor::Document * doc = dynamic_cast<KTextEditor::Document*>( partController()->activePart() ); + + if ( fileName.isNull() && doc ) + fileName = doc->url().path(); + + QString projectDirectory; + if (project()) + projectDirectory = project()->projectDirectory(); + + QString selection = KDevEditorUtil::currentSelection( doc ); + if ( !selection.isEmpty() ) + selection = KShellProcess::quote( selection ); + + QString word = KDevEditorUtil::currentWord( doc ); + + // This should really be checked before inserting into the popup + if (cmdline.contains("%D") && projectDirectory.isNull()) + return; + cmdline.replace(QRegExp("%D"), projectDirectory); + + if (cmdline.contains("%S") && fileName.isNull()) + return; + cmdline.replace(QRegExp("%S"), fileName); + + if (cmdline.contains("%T") && selection.isNull()) + return; + cmdline.replace(QRegExp("%T"), selection); + + if (cmdline.contains("%W") && word.isNull()) + return; + cmdline.replace(QRegExp("%W"), word); + + if (captured) + { + if (KDevAppFrontend *appFrontend = extension<KDevAppFrontend>("KDevelop/AppFrontend")) + appFrontend->startAppCommand(QString::QString(), cmdline, false); + } + else + { + KShellProcess proc; + proc << cmdline; + proc.start(KProcess::DontCare, KProcess::NoCommunication); + } +} + + +void ToolsPart::updateToolsMenu() +{ + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("External Tools"); + QStringList l = config->readListEntry("Tool Menu"); + + + QPtrList<KAction> actions; + QStringList::ConstIterator it; + for (it = l.begin(); it != l.end(); ++it) { + QString menutext = *it; + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("Tool Menu " + menutext); + bool isdesktopfile = config->readBoolEntry("DesktopFile"); + KAction *action = new KAction(*it, 0, + this, SLOT(toolsMenuActivated()), + (QObject*) 0, menutext.utf8()); + if (isdesktopfile) { + KDesktopFile df(config->readPathEntry("CommandLine")); + action->setIcon(df.readIcon()); + } + actions.append(action); + } + + unplugActionList("tools2_list"); + plugActionList("tools2_list", actions); +} + + +void ToolsPart::contextMenu(QPopupMenu *popup, const Context *context) +{ + if (!context->hasType( Context::FileContext )) + return; + + const FileContext *fcontext = static_cast<const FileContext*>(context); + m_contextPopup = popup; + m_contextFileName = fcontext->urls().first().path(); + externalToolMenuEntries.clear(); + + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("External Tools"); + QStringList filecontextList = config->readListEntry("File Context"); + + if (URLUtil::isDirectory(m_contextFileName)) { + QStringList l = config->readListEntry("Dir Context"); + QStringList::ConstIterator it; + for (it = l.begin(); it != l.end(); ++it) + externalToolMenuEntries.insert( popup->insertItem( (*it), this, SLOT(dirContextActivated(int)) ), (*it) ); + } else { + QStringList l = config->readListEntry("File Context"); + QStringList::ConstIterator it; + for (it = l.begin(); it != l.end(); ++it) + externalToolMenuEntries.insert( popup->insertItem( (*it), this, SLOT(fileContextActivated(int)) ), (*it) ); + } +} + + +void ToolsPart::toolsMenuActivated() +{ + QString menutext = sender()->name(); + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("Tool Menu " + menutext); + QString cmdline = config->readPathEntry("CommandLine"); + bool isdesktopfile = config->readBoolEntry("DesktopFile"); + bool captured = config->readBoolEntry("Captured"); + kdDebug() << "tools:" << "activating " << menutext + << "with cmdline " << cmdline + << "and desktopfile " << isdesktopfile << endl; + if (isdesktopfile) + kapp->startServiceByDesktopPath(cmdline); + else + startCommand(cmdline, captured, QString::null); +} + + +void ToolsPart::fileContextActivated(int id) +{ + QString menutext = externalToolMenuEntries[ id ]; + + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("File Context " + menutext); + QString cmdline = config->readPathEntry("CommandLine"); + bool captured = config->readBoolEntry("Captured"); + kdDebug() << "filecontext:" << "activating " << menutext + << " with cmdline " << cmdline + << " on file " << m_contextFileName << endl; + startCommand(cmdline, captured, m_contextFileName); +} + + +void ToolsPart::dirContextActivated(int id) +{ + QString menutext = externalToolMenuEntries[ id ]; + + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("Dir Context " + menutext); + QString cmdline = config->readPathEntry("CommandLine"); + bool captured = config->readBoolEntry("Captured"); + kdDebug() << "dircontext:" << "activating " << menutext + << "with cmdline " << cmdline + << " on directory " << m_contextFileName << endl; + startCommand(cmdline, captured, m_contextFileName); +} + +#include "tools_part.moc" diff --git a/parts/tools/tools_part.h b/parts/tools/tools_part.h new file mode 100644 index 00000000..b0d82c99 --- /dev/null +++ b/parts/tools/tools_part.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2001 Matthias Hoelzer-Kluepfel <mhk@caldera.de> + */ + + +#ifndef __KDEVPART_TOOLS_H__ +#define __KDEVPART_TOOLS_H__ + + +#include <qguardedptr.h> +#include <kdevplugin.h> +#include <kdevgenericfactory.h> + + +class QPopupMenu; +class KDialogBase; +class Context; +class ConfigWidgetProxy; + +class ToolsWidget; + + +class ToolsPart : public KDevPlugin + { + Q_OBJECT + +public: + + ToolsPart( QObject *parent, const char *name, const QStringList & ); + ~ToolsPart(); + + +private slots: + void insertConfigWidget( const KDialogBase * dlg, QWidget * page, unsigned int pagenumber ); + void updateMenu(); + + void slotToolActivated(); + + void contextMenu(QPopupMenu *popup, const Context *context); + void updateToolsMenu(); + void toolsMenuActivated(); + void fileContextActivated(int id); + void dirContextActivated(int id); + +private: + void startCommand(QString cmdline, bool captured, QString fileName); + + QPopupMenu *m_contextPopup; + QString m_contextFileName; + ConfigWidgetProxy * m_configProxy; + }; + +typedef KDevGenericFactory<ToolsPart> ToolsFactory; + +#endif diff --git a/parts/tools/toolsconfig.cpp b/parts/tools/toolsconfig.cpp new file mode 100644 index 00000000..523fe388 --- /dev/null +++ b/parts/tools/toolsconfig.cpp @@ -0,0 +1,169 @@ +#include "toolsconfig.h" + +#include <qapplication.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlistbox.h> +#include <qpushbutton.h> +#include <qheader.h> + +#include <kapplication.h> +#include <kdesktopfile.h> +#include <kdialog.h> +#include <kiconloader.h> +#include <klocale.h> + +#include "tools_part.h" +#include "kapplicationtree.h" + + +ToolsConfig::ToolsConfig(QWidget *parent, const char *name) + : QWidget(parent, name), _tree(0) +{ + _entries.setAutoDelete(true); +} + + +void ToolsConfig::showEvent(QShowEvent *e) +{ + QWidget::showEvent(e); + + if (!_tree) + { + QApplication::setOverrideCursor(Qt::waitCursor); + + QHBoxLayout *hbox = new QHBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint()); + + QVBoxLayout *vbox = new QVBoxLayout(hbox); + _tree = new KDevApplicationTree(this); + _tree->header()->hide(); + QLabel *l = new QLabel(_tree, i18n("&Applications:"), this); + l->show(); + _tree->show(); + + vbox->addWidget(l); + vbox->addWidget(_tree); + + vbox = new QVBoxLayout(hbox); + + _toList = new QPushButton(QApplication::reverseLayout() ? "<<" : ">>", this); + _toList->show(); + vbox->addWidget(_toList); + + connect(_toList, SIGNAL(clicked()), this, SLOT(toList())); + + _toTree = new QPushButton(QApplication::reverseLayout() ? ">>" : "<<", this); + _toTree->show(); + vbox->addWidget(_toTree); + + connect(_toTree, SIGNAL(clicked()), this, SLOT(toTree())); + + vbox = new QVBoxLayout(hbox); + _list = new QListBox(this); + l = new QLabel(_list, i18n("&Tools menu:"), this); + l->show(); + _list->show(); + vbox->addWidget(l); + vbox->addWidget(_list); + + QApplication::restoreOverrideCursor(); + } + + fill(); + checkButtons(); + + connect(_tree, SIGNAL(selectionChanged()), this, SLOT(checkButtons())); + connect(_list, SIGNAL(selectionChanged()), this, SLOT(checkButtons())); +} + + +void ToolsConfig::checkButtons() +{ + _toList->setEnabled(_tree->selectedItem() && !_tree->selectedItem()->firstChild()); + _toTree->setEnabled(_list->currentItem() >= 0 && _list->currentItem() < (int)_list->count()); +} + + +void ToolsConfig::fill() +{ + _entries.clear(); + + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("Tools"); + + QStringList list = config->readListEntry("Tools"); + + for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) + add(*it); +} + + +void ToolsConfig::add(const QString &desktopFile) +{ + KDesktopFile df(desktopFile, true); + if (df.readName().isEmpty()) + return; + + Entry *entry = new Entry; + + if (!df.readIcon().isEmpty()) + entry->icon = BarIcon(df.readIcon()); + entry->name = df.readName(); + entry->desktopFile = desktopFile; + + _entries.append(entry); + + updateList(); + + checkButtons(); +} + + +void ToolsConfig::toList() +{ + KDevAppTreeListItem *item = dynamic_cast<KDevAppTreeListItem*>(_tree->selectedItem()); + if (item && !item->desktopEntryPath().isEmpty()) + add(item->desktopEntryPath()); + checkButtons(); +} + + +void ToolsConfig::toTree() +{ + _entries.remove(_list->currentItem()); + updateList(); + checkButtons(); +} + + +void ToolsConfig::accept() +{ + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("Tools"); + + QStringList l; + QPtrListIterator<Entry> it(_entries); + for ( ; it.current(); ++it) + l.append(it.current()->desktopFile); + + config->writeEntry("Tools", l); + config->sync(); +} + + +void ToolsConfig::updateList() +{ + _list->setUpdatesEnabled(false); + + _list->clear(); + + QPtrListIterator<Entry> it(_entries); + for ( ; it.current(); ++it) + _list->insertItem(it.current()->icon, it.current()->name); + + _list->setUpdatesEnabled(true); + _list->repaint(); +} + + +#include "toolsconfig.moc" diff --git a/parts/tools/toolsconfig.h b/parts/tools/toolsconfig.h new file mode 100644 index 00000000..5dc87d70 --- /dev/null +++ b/parts/tools/toolsconfig.h @@ -0,0 +1,71 @@ +#ifndef __TOOLS_CONFIG_H__ +#define __TOOLS_CONFIG_H__ + + +#include <qwidget.h> +#include <qptrlist.h> +#include <qpixmap.h> + + +class QListBox; +class QPushButton; +class KDevApplicationTree; + +class Entry +{ +public: + + Entry() {}; + + QString name; + QString desktopFile; + QPixmap icon; + +}; + + +class ToolsConfig : public QWidget + { + Q_OBJECT + +public: + + ToolsConfig(QWidget *parent = 0, const char *name = 0); + + +public slots: + + void accept(); + + +protected: + + void showEvent(QShowEvent *); + + void fill(); + void add(const QString &desktopFile); + void remove(const QString &desktopFile); + + +private slots: + + void checkButtons(); + + void toList(); + void toTree(); + + void updateList(); + + +private: + + KDevApplicationTree *_tree; + QListBox *_list; + QPushButton *_toList, *_toTree; + + QPtrList<Entry> _entries; + + }; + + +#endif diff --git a/parts/tools/toolsconfigwidget.cpp b/parts/tools/toolsconfigwidget.cpp new file mode 100644 index 00000000..72b102be --- /dev/null +++ b/parts/tools/toolsconfigwidget.cpp @@ -0,0 +1,284 @@ +/*************************************************************************** + * Copyright (C) 2002 by Bernd Gehrmann * + * bernd@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "toolsconfigwidget.h" + +#include <qcheckbox.h> +#include <qlistbox.h> +#include <qtimer.h> + +#include <klineedit.h> +#include <kconfig.h> +#include <kdeversion.h> +#include <kdebug.h> +#include <kdesktopfile.h> +#include <kiconloader.h> +#include <kmessagebox.h> +#include <kurl.h> +#include <kurldrag.h> + +#include "addtooldlg.h" +#include "kapplicationtree.h" + + +struct ToolsConfigEntry +{ + QString menutext; + QString cmdline; + bool isdesktopfile; + bool captured; + bool isEmpty() const { + return ( menutext.isEmpty() && cmdline.isEmpty() ); + } +}; + + +ToolsConfigWidget::ToolsConfigWidget(QWidget *parent, const char *name) + : ToolsConfigWidgetBase(parent, name) +{ + m_toolsmenuEntries.setAutoDelete(true); + m_filecontextEntries.setAutoDelete(true); + m_dircontextEntries.setAutoDelete(true); + + toolsmenuBox->setAcceptDrops(true); + toolsmenuBox->installEventFilter(this); + toolsmenuBox->viewport()->setAcceptDrops(true); + toolsmenuBox->viewport()->installEventFilter(this); + + readConfig(); +} + + +ToolsConfigWidget::~ToolsConfigWidget() +{} + + +void ToolsConfigWidget::readGroup(const QString &group, QDict<ToolsConfigEntry> *entryDict) +{ + KConfig *config = ToolsFactory::instance()->config(); + config->setGroup("External Tools"); + QStringList list = config->readListEntry(group); + + QStringList::ConstIterator it; + for (it = list.begin(); it != list.end(); ++it) { + config->setGroup(group + " " + (*it)); + QString cmdline = config->readPathEntry("CommandLine"); + bool isdesktopfile = config->readBoolEntry("DesktopFile"); + bool captured = config->readBoolEntry("Captured"); + ToolsConfigEntry *entry = new ToolsConfigEntry; + entry->menutext = (*it); + entry->cmdline = cmdline; + entry->isdesktopfile = isdesktopfile; + entry->captured = captured; + entryDict->insert(*it, entry); + } +} + + +void ToolsConfigWidget::storeGroup(const QString &group, const QDict<ToolsConfigEntry> &entryDict) +{ + KConfig *config = ToolsFactory::instance()->config(); + + QStringList list; + + QDictIterator<ToolsConfigEntry> it(entryDict); + for (; it.current(); ++it) { + ToolsConfigEntry *entry = it.current(); + list << entry->menutext; + config->setGroup(group + " " + entry->menutext); + config->writePathEntry("CommandLine", entry->cmdline); + config->writeEntry("DesktopFile", entry->isdesktopfile); + config->writeEntry("Captured", entry->captured); + } + + config->setGroup("External Tools"); + config->writeEntry(group, list); +} + + + +void ToolsConfigWidget::fillListBox(QListBox *lb, const QDict<ToolsConfigEntry> &entryDict) +{ + lb->clear(); + + QDictIterator<ToolsConfigEntry> it(entryDict); + for (; it.current(); ++it) { + ToolsConfigEntry *entry = it.current(); + if (entry->isdesktopfile) { + KDesktopFile df(entry->cmdline); + lb->insertItem(SmallIcon(df.readIcon()), entry->menutext); + } else { + lb->insertItem(entry->menutext); + } + } +} + + +bool ToolsConfigWidget::addEntry(ToolsConfigEntry *entry, QDict<ToolsConfigEntry> *entryDict) +{ + QString menutext = entry->menutext; + if (entryDict->find(menutext)) { + delete entry; + KMessageBox::sorry(this, i18n("An entry with this title exists already.")); + return false; + } + + entryDict->insert(menutext, entry); + + updateListBoxes(); + return true; +} + + +void ToolsConfigWidget::readConfig() +{ + readGroup("Tool Menu", &m_toolsmenuEntries); + readGroup("File Context", &m_filecontextEntries); + readGroup("Dir Context", &m_dircontextEntries); + + updateListBoxes(); +} + + +void ToolsConfigWidget::storeConfig() +{ + storeGroup("Tool Menu", m_toolsmenuEntries); + storeGroup("File Context", m_filecontextEntries); + storeGroup("Dir Context", m_dircontextEntries); +} + + +void ToolsConfigWidget::updateListBoxes() +{ + fillListBox(toolsmenuBox, m_toolsmenuEntries); + fillListBox(filecontextBox, m_filecontextEntries); + fillListBox(dircontextBox, m_dircontextEntries); +} + + +void ToolsConfigWidget::toolsmenuaddClicked() +{ + AddToolDialog dlg(this); + dlg.setCaption(i18n("Add to Tools Menu")); + dlg.tree->setFocus(); + while (dlg.exec()) { + ToolsConfigEntry *entry = new ToolsConfigEntry; + entry->menutext = dlg.menutextEdit->text(); + entry->cmdline = dlg.getApp().stripWhiteSpace(); + entry->isdesktopfile = false; + entry->captured = dlg.capturedBox->isChecked(); + if ( entry->isEmpty() ) + delete entry; + else if (addEntry(entry, &m_toolsmenuEntries)) + return; + } +} + + +void ToolsConfigWidget::toolsmenuremoveClicked() +{ + QString menutext = toolsmenuBox->currentText(); + m_toolsmenuEntries.remove(menutext); + updateListBoxes(); +} + + +void ToolsConfigWidget::filecontextaddClicked() +{ + AddToolDialog dlg(this); + dlg.setCaption(i18n("Add to File Context Menus")); + dlg.tree->setFocus(); + while (dlg.exec()) { + ToolsConfigEntry *entry = new ToolsConfigEntry; + entry->menutext = dlg.menutextEdit->text(); + entry->cmdline = dlg.getApp().stripWhiteSpace(); + entry->isdesktopfile = false; + entry->captured = dlg.capturedBox->isChecked(); + if ( entry->isEmpty() ) + delete entry; + + else if (addEntry(entry, &m_filecontextEntries)) + return; + } +} + + +void ToolsConfigWidget::filecontextremoveClicked() +{ + QString menutext = filecontextBox->currentText(); + m_filecontextEntries.remove(menutext); + updateListBoxes(); +} + + +void ToolsConfigWidget::dircontextaddClicked() +{ + AddToolDialog dlg(this); + dlg.setCaption(i18n("Add to Directory Context Menus")); + dlg.tree->setFocus(); + if (dlg.exec()) { + ToolsConfigEntry *entry = new ToolsConfigEntry; + entry->menutext = dlg.menutextEdit->text(); + entry->cmdline = dlg.getApp().stripWhiteSpace(); + entry->isdesktopfile = false; + entry->captured = dlg.capturedBox->isChecked(); + if ( entry->isEmpty() ) + delete entry; + else if (addEntry(entry, &m_dircontextEntries)) + return; + } +} + + +void ToolsConfigWidget::dircontextremoveClicked() +{ + QString menutext = dircontextBox->currentText(); + m_dircontextEntries.remove(menutext); + updateListBoxes(); +} + + +bool ToolsConfigWidget::eventFilter(QObject *o, QEvent *e) +{ + if (e->type() == QEvent::DragEnter || e->type() == QEvent::DragMove) { + QDragMoveEvent *dme = static_cast<QDragMoveEvent*>(e); + if (KURLDrag::canDecode(dme)) + dme->accept(); + return true; + } else if (e->type() == QEvent::Drop) { + QDropEvent *de = static_cast<QDropEvent*>(e); + KURL::List fileList; + if (KURLDrag::decode(de, fileList)) { + KURL::List::ConstIterator it; + for (it = fileList.begin(); it != fileList.end(); ++it) { + if ((*it).isLocalFile() && KDesktopFile::isDesktopFile((*it).path())) { + KDesktopFile df((*it).path()); + ToolsConfigEntry *entry = new ToolsConfigEntry; + entry->menutext = df.readName(); + entry->cmdline = (*it).path(); + entry->isdesktopfile = true; + entry->captured = false; + addEntry(entry, &m_toolsmenuEntries); + } + } + } + return true; + } + + return ToolsConfigWidgetBase::eventFilter(o, e); +} + + +void ToolsConfigWidget::accept() +{ + storeConfig(); +} +#include "toolsconfigwidget.moc" diff --git a/parts/tools/toolsconfigwidget.h b/parts/tools/toolsconfigwidget.h new file mode 100644 index 00000000..51e1b005 --- /dev/null +++ b/parts/tools/toolsconfigwidget.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2002 by Bernd Gehrmann * + * bernd@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef _TOOLSCONFIGWIDGET_H_ +#define _TOOLSCONFIGWIDGET_H_ + +#include "toolsconfigwidgetbase.h" +#include "tools_part.h" +#include <qdict.h> + + +struct ToolsConfigEntry; + + +class ToolsConfigWidget : public ToolsConfigWidgetBase +{ + Q_OBJECT + +public: + ToolsConfigWidget(QWidget *parent=0, const char *name=0); + ~ToolsConfigWidget(); + +public slots: + void accept(); + +private: + virtual void toolsmenuaddClicked(); + virtual void toolsmenuremoveClicked(); + virtual void filecontextaddClicked(); + virtual void filecontextremoveClicked(); + virtual void dircontextaddClicked(); + virtual void dircontextremoveClicked(); + + virtual bool eventFilter(QObject *o, QEvent *e); + + void readGroup(const QString &group, QDict<ToolsConfigEntry> *entryDict); + void storeGroup(const QString &group, const QDict<ToolsConfigEntry> &entryDict); + void fillListBox(QListBox *lb, const QDict<ToolsConfigEntry> &entryDict); + bool addEntry(ToolsConfigEntry *entry, QDict<ToolsConfigEntry> *entryDict); + + void readConfig(); + void storeConfig(); + void updateListBoxes(); + + QDict<ToolsConfigEntry> m_toolsmenuEntries; + QDict<ToolsConfigEntry> m_filecontextEntries; + QDict<ToolsConfigEntry> m_dircontextEntries; + + ToolsPart *m_part; +}; + +#endif diff --git a/parts/tools/toolsconfigwidgetbase.ui b/parts/tools/toolsconfigwidgetbase.ui new file mode 100644 index 00000000..5b8baab0 --- /dev/null +++ b/parts/tools/toolsconfigwidgetbase.ui @@ -0,0 +1,410 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>ToolsConfigWidgetBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>tools_config_widget</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>541</width> + <height>376</height> + </rect> + </property> + <property name="caption"> + <string>External Tools</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QTabWidget"> + <property name="name"> + <cstring>tabwidget</cstring> + </property> + <widget class="QWidget"> + <property name="name"> + <cstring>toolmenuTab</cstring> + </property> + <attribute name="title"> + <string>&Tools Menu</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QListBox" row="0" column="0"> + <property name="name"> + <cstring>toolsmenuBox</cstring> + </property> + </widget> + <widget class="QLayoutWidget" row="0" column="1"> + <property name="name"> + <cstring>Layout4_3</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <spacer> + <property name="name"> + <cstring>Spacer9_3</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>toolsmenuaddButton</cstring> + </property> + <property name="text"> + <string>&Add...</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>toolsmenuremoveButton</cstring> + </property> + <property name="text"> + <string>&Remove</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer10_3</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </vbox> + </widget> + <spacer row="1" column="0"> + <property name="name"> + <cstring>Spacer11_3</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>filecontextTab</cstring> + </property> + <attribute name="title"> + <string>&File Context Menu</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QListBox" row="0" column="0"> + <property name="name"> + <cstring>filecontextBox</cstring> + </property> + </widget> + <widget class="QLayoutWidget" row="0" column="1"> + <property name="name"> + <cstring>Layout4_2</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <spacer> + <property name="name"> + <cstring>Spacer9_2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>filecontextaddButton</cstring> + </property> + <property name="text"> + <string>&Add...</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>filecontextremoveButton</cstring> + </property> + <property name="text"> + <string>&Remove</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer10_2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </vbox> + </widget> + <spacer row="1" column="0"> + <property name="name"> + <cstring>Spacer11_2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>dircontextTab</cstring> + </property> + <attribute name="title"> + <string>&Directory Context Menu</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QListBox" row="0" column="0"> + <property name="name"> + <cstring>dircontextBox</cstring> + </property> + </widget> + <widget class="QLayoutWidget" row="0" column="1"> + <property name="name"> + <cstring>Layout4</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <spacer> + <property name="name"> + <cstring>Spacer9</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>dircontextaddButton</cstring> + </property> + <property name="text"> + <string>&Add...</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>dircontextremoveButton</cstring> + </property> + <property name="text"> + <string>&Remove</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer10</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </vbox> + </widget> + <spacer row="1" column="0"> + <property name="name"> + <cstring>Spacer11</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> + </widget> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>filecontextaddButton</sender> + <signal>clicked()</signal> + <receiver>tools_config_widget</receiver> + <slot>filecontextaddClicked()</slot> + </connection> + <connection> + <sender>dircontextaddButton</sender> + <signal>clicked()</signal> + <receiver>tools_config_widget</receiver> + <slot>dircontextaddClicked()</slot> + </connection> + <connection> + <sender>dircontextremoveButton</sender> + <signal>clicked()</signal> + <receiver>tools_config_widget</receiver> + <slot>dircontextremoveClicked()</slot> + </connection> + <connection> + <sender>filecontextremoveButton</sender> + <signal>clicked()</signal> + <receiver>tools_config_widget</receiver> + <slot>filecontextremoveClicked()</slot> + </connection> + <connection> + <sender>toolsmenuaddButton</sender> + <signal>clicked()</signal> + <receiver>tools_config_widget</receiver> + <slot>toolsmenuaddClicked()</slot> + </connection> + <connection> + <sender>toolsmenuremoveButton</sender> + <signal>clicked()</signal> + <receiver>tools_config_widget</receiver> + <slot>toolsmenuremoveClicked()</slot> + </connection> +</connections> +<tabstops> + <tabstop>toolsmenuBox</tabstop> + <tabstop>toolsmenuaddButton</tabstop> + <tabstop>toolsmenuremoveButton</tabstop> + <tabstop>tabwidget</tabstop> + <tabstop>filecontextBox</tabstop> + <tabstop>filecontextaddButton</tabstop> + <tabstop>filecontextremoveButton</tabstop> + <tabstop>dircontextBox</tabstop> + <tabstop>dircontextaddButton</tabstop> + <tabstop>dircontextremoveButton</tabstop> +</tabstops> +<includes> + <include location="global" impldecl="in implementation">kdialog.h</include> +</includes> +<slots> + <slot access="protected">dircontextaddClicked()</slot> + <slot access="protected">filecontextaddClicked()</slot> + <slot access="protected">filecontextremoveClicked()</slot> + <slot access="protected">dircontextremoveClicked()</slot> + <slot access="protected">toolsmenuaddClicked()</slot> + <slot access="protected">toolsmenuremoveClicked()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/> +</UI> |