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 | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /kate/plugins/insertfile | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.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/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kate/plugins/insertfile')
-rw-r--r-- | kate/plugins/insertfile/Makefile.am | 17 | ||||
-rw-r--r-- | kate/plugins/insertfile/insertfileplugin.cpp | 185 | ||||
-rw-r--r-- | kate/plugins/insertfile/insertfileplugin.h | 70 | ||||
-rw-r--r-- | kate/plugins/insertfile/ktexteditor_insertfile.desktop | 156 | ||||
-rw-r--r-- | kate/plugins/insertfile/ktexteditor_insertfileui.rc | 9 |
5 files changed, 437 insertions, 0 deletions
diff --git a/kate/plugins/insertfile/Makefile.am b/kate/plugins/insertfile/Makefile.am new file mode 100644 index 000000000..783e93e0f --- /dev/null +++ b/kate/plugins/insertfile/Makefile.am @@ -0,0 +1,17 @@ +INCLUDES = -I$(top_srcdir)/interfaces $(all_includes) +METASOURCES = AUTO + +# Install this plugin in the KDE modules directory +kde_module_LTLIBRARIES = ktexteditor_insertfile.la + +ktexteditor_insertfile_la_SOURCES = insertfileplugin.cpp +ktexteditor_insertfile_la_LIBADD = $(top_builddir)/interfaces/ktexteditor/libktexteditor.la +ktexteditor_insertfile_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) + +insertfiledatadir = $(kde_datadir)/ktexteditor_insertfile +insertfiledata_DATA = ktexteditor_insertfileui.rc + +kde_services_DATA = ktexteditor_insertfile.desktop + +messages: rc.cpp + $(XGETTEXT) *.cpp *.h -o $(podir)/ktexteditor_insertfile.pot diff --git a/kate/plugins/insertfile/insertfileplugin.cpp b/kate/plugins/insertfile/insertfileplugin.cpp new file mode 100644 index 000000000..e25df8bd5 --- /dev/null +++ b/kate/plugins/insertfile/insertfileplugin.cpp @@ -0,0 +1,185 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002 Anders Lund <anders@alweb.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "insertfileplugin.h" +#include "insertfileplugin.moc" + +#include <ktexteditor/document.h> +#include <ktexteditor/viewcursorinterface.h> +#include <ktexteditor/editinterface.h> + +#include <assert.h> +#include <kio/job.h> +#include <kaction.h> +#include <kfiledialog.h> +#include <kgenericfactory.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kpushbutton.h> +#include <ktempfile.h> +#include <kurl.h> + +#include <qfile.h> +#include <qtextstream.h> + +K_EXPORT_COMPONENT_FACTORY( ktexteditor_insertfile, KGenericFactory<InsertFilePlugin>( "ktexteditor_insertfile" ) ) + + +//BEGIN InsertFilePlugin +InsertFilePlugin::InsertFilePlugin( QObject *parent, const char* name, const QStringList& ) + : KTextEditor::Plugin ( (KTextEditor::Document*) parent, name ) +{ +} + +InsertFilePlugin::~InsertFilePlugin() +{ +} + +void InsertFilePlugin::addView(KTextEditor::View *view) +{ + InsertFilePluginView *nview = new InsertFilePluginView (view, "Insert File Plugin"); + m_views.append (nview); +} + +void InsertFilePlugin::removeView(KTextEditor::View *view) +{ + for (uint z=0; z < m_views.count(); z++) + if (m_views.at(z)->parentClient() == view) + { + InsertFilePluginView *nview = m_views.at(z); + m_views.remove (nview); + delete nview; + } +} +//END InsertFilePlugin + +//BEGIN InsertFilePluginView +InsertFilePluginView::InsertFilePluginView( KTextEditor::View *view, const char *name ) + : QObject( view, name ), + KXMLGUIClient( view ) +{ + view->insertChildClient( this ); + setInstance( KGenericFactory<InsertFilePlugin>::instance() ); + _job = 0; + (void) new KAction( i18n("Insert File..."), 0, this, SLOT(slotInsertFile()), actionCollection(), "tools_insert_file" ); + setXMLFile( "ktexteditor_insertfileui.rc" ); +} + +void InsertFilePluginView::slotInsertFile() +{ + KFileDialog dlg("::insertfile", "", (QWidget*)parent(), "filedialog", true); + dlg.setOperationMode( KFileDialog::Opening ); + + dlg.setCaption(i18n("Choose File to Insert")); + dlg.okButton()->setText(i18n("&Insert")); + dlg.setMode( KFile::File ); + dlg.exec(); + + _file = dlg.selectedURL().url(); + if ( _file.isEmpty() ) return; + + if ( _file.isLocalFile() ) { + _tmpfile = _file.path(); + insertFile(); + } + else { + KTempFile tempFile( QString::null ); + _tmpfile = tempFile.name(); + + KURL destURL; + destURL.setPath( _tmpfile ); + _job = KIO::file_copy( _file, destURL, 0600, true, false, true ); + connect( _job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotFinished ( KIO::Job * ) ) ); + } +} + +void InsertFilePluginView::slotFinished( KIO::Job *job ) +{ + assert( job == _job ); + _job = 0; + if ( job->error() ) + KMessageBox::error( (QWidget*)parent(), i18n("Failed to load file:\n\n") + job->errorString(), i18n("Insert File Error") ); + else + insertFile(); +} + +void InsertFilePluginView::insertFile() +{ + QString error; + if ( _tmpfile.isEmpty() ) + return; + + QFileInfo fi; + fi.setFile( _tmpfile ); + if (!fi.exists() || !fi.isReadable()) + error = i18n("<p>The file <strong>%1</strong> does not exist or is not readable, aborting.").arg(_file.fileName()); + + QFile f( _tmpfile ); + if ( !f.open(IO_ReadOnly) ) + error = i18n("<p>Unable to open file <strong>%1</strong>, aborting.").arg(_file.fileName()); + + if ( ! error.isEmpty() ) { + KMessageBox::sorry( (QWidget*)parent(), error, i18n("Insert File Error") ); + return; + } + + // now grab file contents + QTextStream stream(&f); + QString str, tmp; + uint numlines = 0; + uint len = 0; + while (!stream.eof()) { + if ( numlines ) + str += "\n"; + tmp = stream.readLine(); + str += tmp; + len = tmp.length(); + numlines++; + } + f.close(); + + if ( str.isEmpty() ) + error = i18n("<p>File <strong>%1</strong> had no contents.").arg(_file.fileName()); + if ( ! error.isEmpty() ) { + KMessageBox::sorry( (QWidget*)parent(), error, i18n("Insert File Error") ); + return; + } + + // insert !! + KTextEditor::EditInterface *ei; + KTextEditor::ViewCursorInterface *ci; + KTextEditor::View *v = (KTextEditor::View*)parent(); + ei = KTextEditor::editInterface( v->document() ); + ci = KTextEditor::viewCursorInterface( v ); + uint line, col; + ci->cursorPositionReal( &line, &col ); + ei->insertText( line, col, str ); + + // move the cursor + ci->setCursorPositionReal( line + numlines - 1, numlines > 1 ? len : col + len ); + + // clean up + _file = KURL (); + _tmpfile.truncate( 0 ); + v = 0; + ei = 0; + ci = 0; +} + +//END InsertFilePluginView + diff --git a/kate/plugins/insertfile/insertfileplugin.h b/kate/plugins/insertfile/insertfileplugin.h new file mode 100644 index 000000000..3e882416c --- /dev/null +++ b/kate/plugins/insertfile/insertfileplugin.h @@ -0,0 +1,70 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002 Anders Lund <anders@alweb.dk> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + $Id$ +*/ + + +#ifndef _INSERT_FILE_PLUGIN_H_ +#define _INSERT_FILE_PLUGIN_H_ + +#include <ktexteditor/plugin.h> +#include <ktexteditor/view.h> + +#include <kxmlguiclient.h> +#include <qobject.h> +#include <jobclasses.h> +#include <kurl.h> + +class InsertFilePlugin : public KTextEditor::Plugin, public KTextEditor::PluginViewInterface +{ + Q_OBJECT + + public: + InsertFilePlugin( QObject *parent = 0, + const char* name = 0, + const QStringList &args = QStringList() ); + virtual ~InsertFilePlugin(); + + void addView (KTextEditor::View *view); + void removeView (KTextEditor::View *view); + + + private: + QPtrList<class InsertFilePluginView> m_views; +}; + +class InsertFilePluginView : public QObject, public KXMLGUIClient +{ + Q_OBJECT + public: + InsertFilePluginView( KTextEditor::View *view, const char *name=0 ); + ~InsertFilePluginView() {}; + public slots: + /* display a file dialog, and insert the chosen file */ + void slotInsertFile(); + private slots: + void slotFinished( KIO::Job *job ); + //slotAborted( KIO::Job *job ); + private: + void insertFile(); + KURL _file; + QString _tmpfile; + KIO::FileCopyJob *_job; +}; + +#endif // _INSERT_FILE_PLUGIN_H_ diff --git a/kate/plugins/insertfile/ktexteditor_insertfile.desktop b/kate/plugins/insertfile/ktexteditor_insertfile.desktop new file mode 100644 index 000000000..1854ea95f --- /dev/null +++ b/kate/plugins/insertfile/ktexteditor_insertfile.desktop @@ -0,0 +1,156 @@ +[Desktop Entry] +Name=KTextEditor Insert File Plugin +Name[af]=KTextEditor Voeg Lêer Inprop Module +Name[ar]=ملحق إدراج ملف لمحرر النصوص +Name[az]=KTextEditor Fayl Əlavəsi Daxil El +Name[be]=Модуль устаўкі файла +Name[bn]=কে-টেক্সট-এডিটর ফাইল অন্তর্ভুক্তি প্লাগ-ইন +Name[bs]=KTextEditor dodatak za ubacivanje datoteke +Name[ca]=Connector del KTextEditor per a inserir fitxers +Name[cs]=Modul pro vkládání souborů +Name[csb]=Plugins editorë wstôwianiô lopków +Name[cy]=Ategyn Mewnosod Ffeil KTextEditor +Name[da]=KTextEditor 'indsæt fil'-plugin +Name[de]=KTextEditor-Erweiterung zum Einfügen von Dateien +Name[el]=Πρόσθετο εισαγωγής αρχείου του KTextEditor +Name[eo]=KTextEditor Enmeti-Dosieron-kromaĵeto +Name[es]=Plugin de inserción de archivos de KTextEditor +Name[et]=KTextEditori faili lisamise plugin +Name[eu]=Fitxategiak txertatzeko KTextEditor-en plugin-a +Name[fa]=وصلۀ پروندۀ درج KTextEditor +Name[fi]=KTextEditorin 'Lisää tiedosto'-laajennus +Name[fr]=Module externe du fichier d'insertion de KTextEditor +Name[fy]=KTextEditor-plugin foar it ynfoegjen fan triemmen +Name[ga]=Breiseán KTextEditor chun comhad a ionsá +Name[gl]=Plugin de Inserción de Ficheiro de KTextEditor +Name[he]=תוסף הוספת קובץ ל־KTextEditor +Name[hi]=के-टेक्स्ट-एडिटर फ़ाइल घुसाने का प्लगिन +Name[hr]=KTextEditor dodatak za umetanje datoteka +Name[hu]=KTextEditor fájlbeszúró bővítőmodul +Name[id]=Plugin Penyisipan Berkas KTextEditor +Name[is]=KTextEditor setja inn skrá íforrit +Name[it]=Plugin inserimento file di KTextEditor +Name[ja]=KTextEditor ファイル挿入プラグイン +Name[ka]=ფაილის ჩადგმის KTextEditor-ის მოდული +Name[kk]=KTextEditor файлды ендіру модулі +Name[km]=កម្មវិធីជំនួយរបស់ KTextEditor Insert File +Name[ko]=K글월편집기 파일 끼워넣는 플러그인 +Name[lb]=KTextEditor-Plugin fir Dateien anzefügen +Name[lt]=KTextEditor bylos įterpimo priedas +Name[lv]=KTextEditor faila ievietošanas spraudnis +Name[mk]=KTextEditor приклучок за внес на датотеки +Name[mn]=XML-Plugin Залгаас файлуудын хувьд +Name[ms]=Plug masuk Fail KTextEditor +Name[mt]=Plagin ta' KTextEditor biex iddaħħal fajl +Name[nb]=Programtillegg for 'sett inn fil' i KTextEditor +Name[nds]=KTextEditor-Plugin för't Datei-Infögen +Name[ne]=KTextEditor घुसाउने फाइल प्लगइन +Name[nl]=KTextEditor-plugin voor het invoegen van bestanden +Name[nn]=Programtillegg for innsetjing av fil i skriveprogram +Name[nso]=Tsenyo ya Faele ya Mofetosi wa Sengwalwana sa K +Name[pa]=KTextEditor ਸ਼ਾਮਿਲ ਫਾਇਲ ਪਲੱਗਿੰਨ +Name[pl]=Wtyczka edytora wstawiania plików +Name[pt]='Plugin' de Inserção de Ficheiros do KTextEditor +Name[pt_BR]=Plug-in de Inserção de Arquivos para o Editor de textos +Name[ro]=Modul inserare fişier pentru KTextEditor +Name[ru]=Модуль вставки файла KTextEditor +Name[rw]=Icomeka ryo Kongeramo Idosiye rya KMuhinduziMwandiko +Name[se]=KTextEditor-fiillalasiheami lassemoduvla +Name[sk]=Module pre vloženie súboru KTextEditor +Name[sl]=Vstavek KTextEditor za vstavljanje datotek +Name[sq]=KTextEditor Shtojca: Fute skedën +Name[sr]=KTextEditor прикључак за уметање фајла +Name[sr@Latn]=KTextEditor priključak za umetanje fajla +Name[ss]=I-KTextEditor yingenisa i-plugin yelifayela +Name[sv]=Ktexteditor-insticksprogram för att infoga filer +Name[ta]=கேஉரைதொகுப்பாளர் கோப்பு உள்ளீட்டுச் சொருகுப்பொருள் +Name[te]=కెటెక్స్ట్ ఎడిటర్ దస్త్రాన్ని దూర్చు ప్లగిన్ +Name[tg]=Пуркунандаи KTextEditor барои дарҷи файлҳо +Name[th]=ปลักอินการแทรกแฟ้มของ KTextEditor +Name[tr]=KTextEditor Dosya Yerleştirme Eklentisi +Name[tt]=KTextEditor'nıñ Birem Tığu Quşılması +Name[uk]=Втулок KTextEditor для вставлення файла +Name[uz]=KTextEditor uchun fayldan qoʻyish plagin +Name[uz@cyrillic]=KTextEditor учун файлдан қўйиш плагин +Name[ven]=Musengulusi wa manwalwa K i dzhenisa pulagini ya faela +Name[vi]=Bộ cầm phít Chèn Tập tin KTextEditor +Name[wa]=Tchôke-divins di KTextEditor po stitchî des fitchîs +Name[xh]=KTextEditor Faka Ifayile ye Plagi efakiweyo +Name[zh_CN]=KTextEditor 插入文件插件 +Name[zh_HK]=文字編輯器插入檔案外掛程式 +Name[zh_TW]=文字編輯器插入檔案外掛程式 +Name[zu]=Faka Ifayela Lokungena ngaphakathi le-KTextEditor +Comment=Insert any readable file at cursor position +Comment[af]=Voeg enige leesbare lêer in by die merker posisie +Comment[be]=Устаўляе файл у пазіцыю курсора +Comment[bg]=Вмъкване на файл от мястото на курсора +Comment[bn]=কার্সার অবস্থানে যে কোনো (পাঠযোগ্য) ফাইল অন্তর্ভুক্ত করতে পারে +Comment[bs]=Ubacuje bilo koju čitljivu datoteku na poziciju kursora +Comment[ca]=Inserir qualsevol fitxer llegible en la posició del cursor +Comment[cs]=Vloží jakýkoliv čitelný soubor na místo kurzoru +Comment[csb]=Wstôwiô zamkłosc lopkù przë kursorze +Comment[da]=Indsæt en vilkårlig læsbar fil ved markørens position +Comment[de]=Beliebige lesbare Datei an Cursor-Position einfügen +Comment[el]=Εισαγωγή οποιουδήποτε αναγνώσιμου αρχείου στη θέση του δρομέα +Comment[eo]=Enmeti iun legeblan dosieron ĉe la pozicio de la kursoro +Comment[es]=Insertar cualquier archivo legible en la posición del cursor +Comment[et]=Suvalise loetava faili lisamine kursori asukohta +Comment[eu]=Kurtsorearen posizioan fitxategi irakurgarri bat txertatzen du +Comment[fa]=درج هر پروندۀ قابل خواندن در موقعیت مکاننما +Comment[fi]=Lisää mikä tahansa luettava tiedosto kursorin kohdalle +Comment[fr]=Insérer tout fichier lisible à la position du curseur +Comment[fy]=Els lêsber triem by it rinnerke ynfoegje +Comment[gl]=Inserir calquera ficheiro lexíbel na posición do cursor +Comment[he]=מוסיף כל קובץ בר קיראה במיקום הסמן +Comment[hr]=Na položaju pokazivača umetnite bilo koju čitljivu datoteku +Comment[hsb]=Zasunje lubowólnu čitajomnu dataju na poziciji cursora +Comment[hu]=Tetszőleges olvasható fájl beszúrása a kurzorpozíciónál +Comment[id]=Sisipkan berkas apa saja yang bisa dibaca ke posisi kursor +Comment[is]=Setur inn hvaða lesanlegu skrá sem er í stöðu bendilsins +Comment[it]=Inserisce un qualsiasi file leggibile alla posizione del cursore +Comment[ja]=カーソル位置に読み込み可能なファイルを挿入します +Comment[ka]=ნებისმიერი კითხვადი ფაილის კურსორის ადგილას ჩამატება +Comment[kk]=Меңзер көрсететін орынға кез-келген оқылатын файлды ендіру +Comment[km]=បញ្ចូលឯកសារដែលអាចអានបានណាមួយនៅទីតាំងរបស់ទស្សន៍ទ្រនិច +Comment[ko]=커서가 있는 곳에 읽을 수 있는 파일을 끼워 넣습니다 +Comment[lb]=Setzt eng liesbar Datei bei der Cursorpositioun an +Comment[lt]=Įterpią bet kokią skaitomą bylą ties žymekliu +Comment[lv]=Ievieto jebkuru lasāmu failu kursora atrašanās vietā +Comment[mk]=Внесува било која читлива датотека на позицијата на курсорот +Comment[ms]=Sisipkan sebarang fail boleh baca di posisi kursor +Comment[nb]=Sett inn en lesbar fil ved skrivemerket +Comment[nds]=Jichtenseen leesbore Datei bi'n Blinker infögen +Comment[ne]=कर्सर स्थितिमा कुनै पनि पढ्नयोग्य फाइल घुसाउनुहोस् +Comment[nl]=Voeg een willekeurig leesbaar bestand in op de cursorpositie +Comment[nn]=Set inn ei lesbar fil ved skrivemerket +Comment[pa]=ਕੋਈ ਪੜਨਯੋਗ ਫਾਇਲ ਕਰਸਰ ਸਥਿਤੀ ਤੇ ਸ਼ਾਮਿਲ ਕਰੋ +Comment[pl]=Wstawia zawartość pliku w pozycji kursora +Comment[pt]=Insira qualquer ficheiro legível na posição do cursor +Comment[pt_BR]=Insere qualquer arquivo com permissões de leitura na posição do cursor +Comment[ro]=Inserează la poziţia cursorului orice fişier citibil +Comment[ru]=вставка любого читаемого файла в позиции курсора +Comment[rw]=Kongeramo idosiye isomeka ibonetse ku mwanya w'inyoboranyandiko +Comment[se]=Lasiha logahahtti fiilla čállinmearkka sajádahkii +Comment[sk]=Vloží ľubovoľný súbor na pozíciu kurzora +Comment[sl]=Vstavi katerokoli berljivo datoteko na položaju kazalca +Comment[sr]=Убаците било који читљиви фајл на положају курсора +Comment[sr@Latn]=Ubacite bilo koji čitljivi fajl na položaju kursora +Comment[sv]=Infoga vilken läsbar fil som helst vid markörens plats +Comment[ta]=சுட்டும் இடத்தில் படிக்கக்கூடிய கோப்பினை உள்ளிடு +Comment[te]=ములుకు వున్న చోట చదవగలిగే దస్త్రాన్ని దూర్చును +Comment[tg]=Файли хондашавандаи ҳеҷгуна дар мавқеъи курсор ҷойгир мекунад +Comment[th]=ทำการแทรกแฟ้มที่สามารถอ่านได้ที่ตำแหน่งของเคอร์เซอร์ +Comment[tr]=İmleç konumunda herhangi bir dosyanın içeriğini ekle +Comment[tt]=Kürsär urınına, uqıp bulğan birem eçtälegen tığıp östi +Comment[uk]=Вставляє вміст будь-якого файла, який можна прочитати, у позицію курсора +Comment[uz]=Har qanday oʻqib boʻladigan faylni kursorning joyidan qoʻyish +Comment[uz@cyrillic]=Ҳар қандай ўқиб бўладиган файлни курсорнинг жойидан қўйиш +Comment[vi]=Chèn bất kỳ tập tin có khả năng đọc tại vị trí của con chạy. +Comment[zh_CN]=在光标位置插入任何可读文件 +Comment[zh_HK]=在游標處插入任意的檔案 +Comment[zh_TW]=在游標處插入任意的可讀檔案 +X-KDE-Library=ktexteditor_insertfile +ServiceTypes=KTextEditor/Plugin +Type=Service +InitialPreference=8 +MimeType=text/plain diff --git a/kate/plugins/insertfile/ktexteditor_insertfileui.rc b/kate/plugins/insertfile/ktexteditor_insertfileui.rc new file mode 100644 index 000000000..36ac0916f --- /dev/null +++ b/kate/plugins/insertfile/ktexteditor_insertfileui.rc @@ -0,0 +1,9 @@ +<!DOCTYPE kpartgui> +<kpartplugin name="ktexteditor_insertfile" library="ktexteditor_insertfile" version="2"> +<MenuBar> + <Menu name="tools"><Text>&Tools</Text> + <separator group="tools_operations" /> + <Action name="tools_insert_file" group="tools_operations"/> + </Menu> +</MenuBar> +</kpartplugin> |