TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kateview.cpp 58KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2003 Hamish Rodda <rodda@kde.org>
  3. Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
  4. Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
  5. Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
  6. Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public
  9. License version 2 as published by the Free Software Foundation.
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public License
  15. along with this library; see the file COPYING.LIB. If not, write to
  16. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. Boston, MA 02110-1301, USA.
  18. */
  19. #define DEBUGACCELS
  20. //BEGIN includes
  21. #include "kateview.h"
  22. #include "kateview.moc"
  23. #include "kateviewinternal.h"
  24. #include "kateviewhelpers.h"
  25. #include "katerenderer.h"
  26. #include "katedocument.h"
  27. #include "katedocumenthelpers.h"
  28. #include "katefactory.h"
  29. #include "katehighlight.h"
  30. #include "katedialogs.h"
  31. #include "katetextline.h"
  32. #include "katecodefoldinghelpers.h"
  33. #include "katecodecompletion.h"
  34. #include "katesearch.h"
  35. #include "kateschema.h"
  36. #include "katebookmarks.h"
  37. #include "katesearch.h"
  38. #include "kateconfig.h"
  39. #include "katefiletype.h"
  40. #include "kateautoindent.h"
  41. #include "katespell.h"
  42. #include <tdetexteditor/plugin.h>
  43. #include <tdeparts/event.h>
  44. #include <tdeio/netaccess.h>
  45. #include <tdeconfig.h>
  46. #include <kurldrag.h>
  47. #include <kdebug.h>
  48. #include <tdeapplication.h>
  49. #include <kcursor.h>
  50. #include <tdelocale.h>
  51. #include <tdeglobal.h>
  52. #include <kcharsets.h>
  53. #include <tdemessagebox.h>
  54. #include <tdeaction.h>
  55. #include <kstdaction.h>
  56. #include <kxmlguifactory.h>
  57. #include <tdeaccel.h>
  58. #include <klibloader.h>
  59. #include <kencodingfiledialog.h>
  60. #include <tdemultipledrag.h>
  61. #include <tdetempfile.h>
  62. #include <ksavefile.h>
  63. #include <tqfont.h>
  64. #include <tqfileinfo.h>
  65. #include <tqstyle.h>
  66. #include <tqevent.h>
  67. #include <tqpopupmenu.h>
  68. #include <tqlayout.h>
  69. #include <tqclipboard.h>
  70. #include <tqstylesheet.h>
  71. //END includes
  72. KateView::KateView( KateDocument *doc, TQWidget *parent, const char * name )
  73. : Kate::View( doc, parent, name )
  74. , m_doc( doc )
  75. , m_search( new KateSearch( this ) )
  76. , m_spell( new KateSpell( this ) )
  77. , m_bookmarks( new KateBookmarks( this ) )
  78. , m_cmdLine (0)
  79. , m_cmdLineOn (false)
  80. , m_active( false )
  81. , m_hasWrap( false )
  82. , m_startingUp (true)
  83. , m_updatingDocumentConfig (false)
  84. , selectStart (m_doc, true)
  85. , selectEnd (m_doc, true)
  86. , blockSelect (false)
  87. , m_imStartLine( 0 )
  88. , m_imStart( 0 )
  89. , m_imEnd( 0 )
  90. , m_imSelStart( 0 )
  91. , m_imSelEnd( 0 )
  92. , m_imComposeEvent( false )
  93. {
  94. KateFactory::self()->registerView( this );
  95. m_config = new KateViewConfig (this);
  96. m_renderer = new KateRenderer(doc, this);
  97. m_grid = new TQGridLayout (this, 3, 3);
  98. m_grid->setRowStretch ( 0, 10 );
  99. m_grid->setRowStretch ( 1, 0 );
  100. m_grid->setColStretch ( 0, 0 );
  101. m_grid->setColStretch ( 1, 10 );
  102. m_grid->setColStretch ( 2, 0 );
  103. m_viewInternal = new KateViewInternal( this, doc );
  104. m_grid->addWidget (m_viewInternal, 0, 1);
  105. setClipboardInterfaceDCOPSuffix (viewDCOPSuffix());
  106. setCodeCompletionInterfaceDCOPSuffix (viewDCOPSuffix());
  107. setDynWordWrapInterfaceDCOPSuffix (viewDCOPSuffix());
  108. setPopupMenuInterfaceDCOPSuffix (viewDCOPSuffix());
  109. setSessionConfigInterfaceDCOPSuffix (viewDCOPSuffix());
  110. setViewCursorInterfaceDCOPSuffix (viewDCOPSuffix());
  111. setViewStatusMsgInterfaceDCOPSuffix (viewDCOPSuffix());
  112. setInstance( KateFactory::self()->instance() );
  113. doc->addView( this );
  114. setFocusProxy( m_viewInternal );
  115. setFocusPolicy( TQ_StrongFocus );
  116. if (!doc->singleViewMode()) {
  117. setXMLFile( "katepartui.rc" );
  118. } else {
  119. if( doc->readOnly() )
  120. setXMLFile( "katepartreadonlyui.rc" );
  121. else
  122. setXMLFile( "katepartui.rc" );
  123. }
  124. setupConnections();
  125. setupActions();
  126. setupEditActions();
  127. setupCodeFolding();
  128. setupCodeCompletion();
  129. // enable the plugins of this view
  130. m_doc->enableAllPluginsGUI (this);
  131. // update the enabled state of the undo/redo actions...
  132. slotNewUndo();
  133. m_startingUp = false;
  134. updateConfig ();
  135. slotHlChanged();
  136. /*test texthint
  137. connect(this,TQT_SIGNAL(needTextHint(int, int, TQString &)),
  138. this,TQT_SLOT(slotNeedTextHint(int, int, TQString &)));
  139. enableTextHints(1000);
  140. test texthint*/
  141. }
  142. KateView::~KateView()
  143. {
  144. if (!m_doc->singleViewMode())
  145. m_doc->disableAllPluginsGUI (this);
  146. m_doc->removeView( this );
  147. // its a TQObject. don't double-delete
  148. //delete m_viewInternal;
  149. //delete m_codeCompletion;
  150. delete m_renderer;
  151. m_renderer = 0;
  152. delete m_config;
  153. m_config = 0;
  154. KateFactory::self()->deregisterView (this);
  155. }
  156. void KateView::setupConnections()
  157. {
  158. connect( m_doc, TQT_SIGNAL(undoChanged()),
  159. TQT_TQOBJECT(this), TQT_SLOT(slotNewUndo()) );
  160. connect( m_doc, TQT_SIGNAL(hlChanged()),
  161. TQT_TQOBJECT(this), TQT_SLOT(slotHlChanged()) );
  162. connect( m_doc, TQT_SIGNAL(canceled(const TQString&)),
  163. TQT_TQOBJECT(this), TQT_SLOT(slotSaveCanceled(const TQString&)) );
  164. connect( m_viewInternal, TQT_SIGNAL(dropEventPass(TQDropEvent*)),
  165. TQT_TQOBJECT(this), TQT_SIGNAL(dropEventPass(TQDropEvent*)) );
  166. connect(this,TQT_SIGNAL(cursorPositionChanged()),this,TQT_SLOT(slotStatusMsg()));
  167. connect(this,TQT_SIGNAL(newStatus()),this,TQT_SLOT(slotStatusMsg()));
  168. connect(m_doc, TQT_SIGNAL(undoChanged()), TQT_TQOBJECT(this), TQT_SLOT(slotStatusMsg()));
  169. if ( m_doc->browserView() )
  170. {
  171. connect( this, TQT_SIGNAL(dropEventPass(TQDropEvent*)),
  172. TQT_TQOBJECT(this), TQT_SLOT(slotDropEventPass(TQDropEvent*)) );
  173. }
  174. }
  175. void KateView::setupActions()
  176. {
  177. TDEActionCollection *ac = this->actionCollection ();
  178. TDEAction *a;
  179. m_toggleWriteLock = 0;
  180. m_cut = a=KStdAction::cut(TQT_TQOBJECT(this), TQT_SLOT(cut()), ac);
  181. a->setWhatsThis(i18n("Cut the selected text and move it to the clipboard"));
  182. m_paste = a=KStdAction::pasteText(TQT_TQOBJECT(this), TQT_SLOT(paste()), ac);
  183. a->setWhatsThis(i18n("Paste previously copied or cut clipboard contents"));
  184. m_copy = a=KStdAction::copy(TQT_TQOBJECT(this), TQT_SLOT(copy()), ac);
  185. a->setWhatsThis(i18n( "Use this command to copy the currently selected text to the system clipboard."));
  186. m_copyHTML = a = new TDEAction(i18n("Copy as &HTML"), "editcopy", 0, TQT_TQOBJECT(this), TQT_SLOT(copyHTML()), ac, "edit_copy_html");
  187. a->setWhatsThis(i18n( "Use this command to copy the currently selected text as HTML to the system clipboard."));
  188. if (!m_doc->readOnly())
  189. {
  190. a=KStdAction::save(TQT_TQOBJECT(this), TQT_SLOT(save()), ac);
  191. a->setWhatsThis(i18n("Save the current document"));
  192. a=m_editUndo = KStdAction::undo(m_doc, TQT_SLOT(undo()), ac);
  193. a->setWhatsThis(i18n("Revert the most recent editing actions"));
  194. a=m_editRedo = KStdAction::redo(m_doc, TQT_SLOT(redo()), ac);
  195. a->setWhatsThis(i18n("Revert the most recent undo operation"));
  196. (new TDEAction(i18n("&Word Wrap Document"), "", 0, TQT_TQOBJECT(this), TQT_SLOT(applyWordWrap()), ac, "tools_apply_wordwrap"))->setWhatsThis(
  197. i18n("Use this command to wrap all lines of the current document which are longer than the width of the"
  198. " current view, to fit into this view.<br><br> This is a static word wrap, meaning it is not updated"
  199. " when the view is resized."));
  200. // setup Tools menu
  201. a=new TDEAction(i18n("&Indent"), "indent", Qt::CTRL+Qt::Key_I, TQT_TQOBJECT(this), TQT_SLOT(indent()), ac, "tools_indent");
  202. a->setWhatsThis(i18n("Use this to indent a selected block of text.<br><br>"
  203. "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
  204. a=new TDEAction(i18n("&Unindent"), "unindent", Qt::CTRL+Qt::SHIFT+Qt::Key_I, TQT_TQOBJECT(this), TQT_SLOT(unIndent()), ac, "tools_unindent");
  205. a->setWhatsThis(i18n("Use this to unindent a selected block of text."));
  206. a=new TDEAction(i18n("&Clean Indentation"), 0, TQT_TQOBJECT(this), TQT_SLOT(cleanIndent()), ac, "tools_cleanIndent");
  207. a->setWhatsThis(i18n("Use this to clean the indentation of a selected block of text (only tabs/only spaces)<br><br>"
  208. "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
  209. a=new TDEAction(i18n("&Align"), 0, TQT_TQOBJECT(this), TQT_SLOT(align()), ac, "tools_align");
  210. a->setWhatsThis(i18n("Use this to align the current line or block of text to its proper indent level."));
  211. a=new TDEAction(i18n("C&omment"), CTRL+Qt::Key_D, TQT_TQOBJECT(this), TQT_SLOT(comment()),
  212. ac, "tools_comment");
  213. a->setWhatsThis(i18n("This command comments out the current line or a selected block of text.<BR><BR>"
  214. "The characters for single/multiple line comments are defined within the language's highlighting."));
  215. a=new TDEAction(i18n("Unco&mment"), CTRL+SHIFT+Qt::Key_D, TQT_TQOBJECT(this), TQT_SLOT(uncomment()),
  216. ac, "tools_uncomment");
  217. a->setWhatsThis(i18n("This command removes comments from the current line or a selected block of text.<BR><BR>"
  218. "The characters for single/multiple line comments are defined within the language's highlighting."));
  219. a = m_toggleWriteLock = new TDEToggleAction(
  220. i18n("&Read Only Mode"), 0, 0,
  221. TQT_TQOBJECT(this), TQT_SLOT( toggleWriteLock() ),
  222. ac, "tools_toggle_write_lock" );
  223. a->setWhatsThis( i18n("Lock/unlock the document for writing") );
  224. a = new TDEAction( i18n("Uppercase"), CTRL + Qt::Key_U, TQT_TQOBJECT(this),
  225. TQT_SLOT(uppercase()), ac, "tools_uppercase" );
  226. a->setWhatsThis( i18n("Convert the selection to uppercase, or the character to the "
  227. "right of the cursor if no text is selected.") );
  228. a = new TDEAction( i18n("Lowercase"), CTRL + SHIFT + Qt::Key_U, TQT_TQOBJECT(this),
  229. TQT_SLOT(lowercase()), ac, "tools_lowercase" );
  230. a->setWhatsThis( i18n("Convert the selection to lowercase, or the character to the "
  231. "right of the cursor if no text is selected.") );
  232. a = new TDEAction( i18n("Capitalize"), CTRL + ALT + Qt::Key_U, TQT_TQOBJECT(this),
  233. TQT_SLOT(capitalize()), ac, "tools_capitalize" );
  234. a->setWhatsThis( i18n("Capitalize the selection, or the word under the "
  235. "cursor if no text is selected.") );
  236. a = new TDEAction( i18n("Join Lines"), CTRL + Qt::Key_J, TQT_TQOBJECT(this),
  237. TQT_SLOT( joinLines() ), ac, "tools_join_lines" );
  238. }
  239. else
  240. {
  241. m_cut->setEnabled (false);
  242. m_paste->setEnabled (false);
  243. m_editUndo = 0;
  244. m_editRedo = 0;
  245. }
  246. a=KStdAction::print( m_doc, TQT_SLOT(print()), ac );
  247. a->setWhatsThis(i18n("Print the current document."));
  248. a=new TDEAction(i18n("Reloa&d"), "reload", TDEStdAccel::reload(), TQT_TQOBJECT(this), TQT_SLOT(reloadFile()), ac, "file_reload");
  249. a->setWhatsThis(i18n("Reload the current document from disk."));
  250. a=KStdAction::saveAs(TQT_TQOBJECT(this), TQT_SLOT(saveAs()), ac);
  251. a->setWhatsThis(i18n("Save the current document to disk, with a name of your choice."));
  252. a=KStdAction::gotoLine(TQT_TQOBJECT(this), TQT_SLOT(gotoLine()), ac);
  253. a->setWhatsThis(i18n("This command opens a dialog and lets you choose a line that you want the cursor to move to."));
  254. a=new TDEAction(i18n("&Configure Editor..."), 0, m_doc, TQT_SLOT(configDialog()),ac, "set_confdlg");
  255. a->setWhatsThis(i18n("Configure various aspects of this editor."));
  256. KateViewHighlightAction *menu = new KateViewHighlightAction (i18n("&Highlighting"), ac, "set_highlight");
  257. menu->setWhatsThis(i18n("Here you can choose how the current document should be highlighted."));
  258. menu->updateMenu (m_doc);
  259. KateViewFileTypeAction *ftm = new KateViewFileTypeAction (i18n("&Filetype"),ac,"set_filetype");
  260. ftm->updateMenu (m_doc);
  261. KateViewSchemaAction *schemaMenu = new KateViewSchemaAction (i18n("&Schema"),ac,"view_schemas");
  262. schemaMenu->updateMenu (this);
  263. // indentation menu
  264. new KateViewIndentationAction (m_doc, i18n("&Indentation"),ac,"tools_indentation");
  265. // html export
  266. a = new TDEAction(i18n("E&xport as HTML..."), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(exportAsHTML()), ac, "file_export_html");
  267. a->setWhatsThis(i18n("This command allows you to export the current document"
  268. " with all highlighting information into a HTML document."));
  269. m_selectAll = a=KStdAction::selectAll(TQT_TQOBJECT(this), TQT_SLOT(selectAll()), ac);
  270. a->setWhatsThis(i18n("Select the entire text of the current document."));
  271. m_deSelect = a=KStdAction::deselect(TQT_TQOBJECT(this), TQT_SLOT(clearSelection()), ac);
  272. a->setWhatsThis(i18n("If you have selected something within the current document, this will no longer be selected."));
  273. a=new TDEAction(i18n("Enlarge Font"), "viewmag+", 0, TQT_TQOBJECT(m_viewInternal), TQT_SLOT(slotIncFontSizes()), ac, "incFontSizes");
  274. a->setWhatsThis(i18n("This increases the display font size."));
  275. a=new TDEAction(i18n("Shrink Font"), "viewmag-", 0, TQT_TQOBJECT(m_viewInternal), TQT_SLOT(slotDecFontSizes()), ac, "decFontSizes");
  276. a->setWhatsThis(i18n("This decreases the display font size."));
  277. a= m_toggleBlockSelection = new TDEToggleAction(
  278. i18n("Bl&ock Selection Mode"), CTRL + SHIFT + Key_B,
  279. TQT_TQOBJECT(this), TQT_SLOT(toggleBlockSelectionMode()),
  280. ac, "set_verticalSelect");
  281. a->setWhatsThis(i18n("This command allows switching between the normal (line based) selection mode and the block selection mode."));
  282. a= m_toggleInsert = new TDEToggleAction(
  283. i18n("Overwr&ite Mode"), Key_Insert,
  284. TQT_TQOBJECT(this), TQT_SLOT(toggleInsert()),
  285. ac, "set_insert" );
  286. a->setWhatsThis(i18n("Choose whether you want the text you type to be inserted or to overwrite existing text."));
  287. TDEToggleAction *toggleAction;
  288. a= m_toggleDynWrap = toggleAction = new TDEToggleAction(
  289. i18n("&Dynamic Word Wrap"), Key_F10,
  290. TQT_TQOBJECT(this), TQT_SLOT(toggleDynWordWrap()),
  291. ac, "view_dynamic_word_wrap" );
  292. a->setWhatsThis(i18n("If this option is checked, the text lines will be wrapped at the view border on the screen."));
  293. a= m_setDynWrapIndicators = new TDESelectAction(i18n("Dynamic Word Wrap Indicators"), 0, ac, "dynamic_word_wrap_indicators");
  294. a->setWhatsThis(i18n("Choose when the Dynamic Word Wrap Indicators should be displayed"));
  295. connect(m_setDynWrapIndicators, TQT_SIGNAL(activated(int)), TQT_TQOBJECT(this), TQT_SLOT(setDynWrapIndicators(int)));
  296. TQStringList list2;
  297. list2.append(i18n("&Off"));
  298. list2.append(i18n("Follow &Line Numbers"));
  299. list2.append(i18n("&Always On"));
  300. m_setDynWrapIndicators->setItems(list2);
  301. a= toggleAction=m_toggleFoldingMarkers = new TDEToggleAction(
  302. i18n("Show Folding &Markers"), Key_F9,
  303. TQT_TQOBJECT(this), TQT_SLOT(toggleFoldingMarkers()),
  304. ac, "view_folding_markers" );
  305. a->setWhatsThis(i18n("You can choose if the codefolding marks should be shown, if codefolding is possible."));
  306. toggleAction->setCheckedState(i18n("Hide Folding &Markers"));
  307. a= m_toggleIconBar = toggleAction = new TDEToggleAction(
  308. i18n("Show &Icon Border"), Key_F6,
  309. TQT_TQOBJECT(this), TQT_SLOT(toggleIconBorder()),
  310. ac, "view_border");
  311. a=toggleAction;
  312. a->setWhatsThis(i18n("Show/hide the icon border.<BR><BR> The icon border shows bookmark symbols, for instance."));
  313. toggleAction->setCheckedState(i18n("Hide &Icon Border"));
  314. a= toggleAction=m_toggleLineNumbers = new TDEToggleAction(
  315. i18n("Show &Line Numbers"), Key_F11,
  316. TQT_TQOBJECT(this), TQT_SLOT(toggleLineNumbersOn()),
  317. ac, "view_line_numbers" );
  318. a->setWhatsThis(i18n("Show/hide the line numbers on the left hand side of the view."));
  319. toggleAction->setCheckedState(i18n("Hide &Line Numbers"));
  320. a= m_toggleScrollBarMarks = toggleAction = new TDEToggleAction(
  321. i18n("Show Scroll&bar Marks"), 0,
  322. TQT_TQOBJECT(this), TQT_SLOT(toggleScrollBarMarks()),
  323. ac, "view_scrollbar_marks");
  324. a->setWhatsThis(i18n("Show/hide the marks on the vertical scrollbar.<BR><BR>The marks, for instance, show bookmarks."));
  325. toggleAction->setCheckedState(i18n("Hide Scroll&bar Marks"));
  326. a = toggleAction = m_toggleWWMarker = new TDEToggleAction(
  327. i18n("Show Static &Word Wrap Marker"), 0,
  328. TQT_TQOBJECT(this), TQT_SLOT( toggleWWMarker() ),
  329. ac, "view_word_wrap_marker" );
  330. a->setWhatsThis( i18n(
  331. "Show/hide the Word Wrap Marker, a vertical line drawn at the word "
  332. "wrap column as defined in the editing properties" ));
  333. toggleAction->setCheckedState(i18n("Hide Static &Word Wrap Marker"));
  334. a= m_switchCmdLine = new TDEAction(
  335. i18n("Switch to Command Line"), Key_F7,
  336. TQT_TQOBJECT(this), TQT_SLOT(switchToCmdLine()),
  337. ac, "switch_to_cmd_line" );
  338. a->setWhatsThis(i18n("Show/hide the command line on the bottom of the view."));
  339. a=m_setEndOfLine = new TDESelectAction(i18n("&End of Line"), 0, ac, "set_eol");
  340. a->setWhatsThis(i18n("Choose which line endings should be used, when you save the document"));
  341. TQStringList list;
  342. list.append("&UNIX");
  343. list.append("&Windows/DOS");
  344. list.append("&Macintosh");
  345. m_setEndOfLine->setItems(list);
  346. m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
  347. connect(m_setEndOfLine, TQT_SIGNAL(activated(int)), TQT_TQOBJECT(this), TQT_SLOT(setEol(int)));
  348. // encoding menu
  349. new KateViewEncodingAction (m_doc, this, i18n("E&ncoding"), TQT_TQOBJECT(ac), "set_encoding");
  350. m_search->createActions( ac );
  351. m_spell->createActions( ac );
  352. m_bookmarks->createActions( ac );
  353. slotSelectionChanged ();
  354. connect (this, TQT_SIGNAL(selectionChanged()), TQT_TQOBJECT(this), TQT_SLOT(slotSelectionChanged()));
  355. }
  356. void KateView::setupEditActions()
  357. {
  358. m_editActions = new TDEActionCollection( m_viewInternal, TQT_TQOBJECT(this), "edit_actions" );
  359. TDEActionCollection* ac = m_editActions;
  360. new TDEAction(
  361. i18n("Move Word Left"), CTRL + Key_Left,
  362. TQT_TQOBJECT(this),TQT_SLOT(wordLeft()),
  363. ac, "word_left" );
  364. new TDEAction(
  365. i18n("Select Character Left"), SHIFT + Key_Left,
  366. TQT_TQOBJECT(this),TQT_SLOT(shiftCursorLeft()),
  367. ac, "select_char_left" );
  368. new TDEAction(
  369. i18n("Select Word Left"), SHIFT + CTRL + Key_Left,
  370. TQT_TQOBJECT(this), TQT_SLOT(shiftWordLeft()),
  371. ac, "select_word_left" );
  372. new TDEAction(
  373. i18n("Move Word Right"), CTRL + Key_Right,
  374. TQT_TQOBJECT(this), TQT_SLOT(wordRight()),
  375. ac, "word_right" );
  376. new TDEAction(
  377. i18n("Select Character Right"), SHIFT + Key_Right,
  378. TQT_TQOBJECT(this), TQT_SLOT(shiftCursorRight()),
  379. ac, "select_char_right" );
  380. new TDEAction(
  381. i18n("Select Word Right"), SHIFT + CTRL + Key_Right,
  382. TQT_TQOBJECT(this),TQT_SLOT(shiftWordRight()),
  383. ac, "select_word_right" );
  384. new TDEAction(
  385. i18n("Move to Beginning of Line"), Key_Home,
  386. TQT_TQOBJECT(this), TQT_SLOT(home()),
  387. ac, "beginning_of_line" );
  388. new TDEAction(
  389. i18n("Move to Beginning of Document"), TDEStdAccel::home(),
  390. TQT_TQOBJECT(this), TQT_SLOT(top()),
  391. ac, "beginning_of_document" );
  392. new TDEAction(
  393. i18n("Select to Beginning of Line"), SHIFT + Key_Home,
  394. TQT_TQOBJECT(this), TQT_SLOT(shiftHome()),
  395. ac, "select_beginning_of_line" );
  396. new TDEAction(
  397. i18n("Select to Beginning of Document"), SHIFT + CTRL + Key_Home,
  398. TQT_TQOBJECT(this), TQT_SLOT(shiftTop()),
  399. ac, "select_beginning_of_document" );
  400. new TDEAction(
  401. i18n("Move to End of Line"), Key_End,
  402. TQT_TQOBJECT(this), TQT_SLOT(end()),
  403. ac, "end_of_line" );
  404. new TDEAction(
  405. i18n("Move to End of Document"), TDEStdAccel::end(),
  406. TQT_TQOBJECT(this), TQT_SLOT(bottom()),
  407. ac, "end_of_document" );
  408. new TDEAction(
  409. i18n("Select to End of Line"), SHIFT + Key_End,
  410. TQT_TQOBJECT(this), TQT_SLOT(shiftEnd()),
  411. ac, "select_end_of_line" );
  412. new TDEAction(
  413. i18n("Select to End of Document"), SHIFT + CTRL + Key_End,
  414. TQT_TQOBJECT(this), TQT_SLOT(shiftBottom()),
  415. ac, "select_end_of_document" );
  416. new TDEAction(
  417. i18n("Select to Previous Line"), SHIFT + Key_Up,
  418. TQT_TQOBJECT(this), TQT_SLOT(shiftUp()),
  419. ac, "select_line_up" );
  420. new TDEAction(
  421. i18n("Scroll Line Up"),"", CTRL + Key_Up,
  422. TQT_TQOBJECT(this), TQT_SLOT(scrollUp()),
  423. ac, "scroll_line_up" );
  424. new TDEAction(i18n("Move to Next Line"), Key_Down, TQT_TQOBJECT(this), TQT_SLOT(down()),
  425. ac, "move_line_down");
  426. new TDEAction(i18n("Move to Previous Line"), Key_Up, TQT_TQOBJECT(this), TQT_SLOT(up()),
  427. ac, "move_line_up");
  428. new TDEAction(i18n("Move Character Right"), Key_Right, TQT_TQOBJECT(this),
  429. TQT_SLOT(cursorRight()), ac, "move_cursor_right");
  430. new TDEAction(i18n("Move Character Left"), Key_Left, TQT_TQOBJECT(this), TQT_SLOT(cursorLeft()),
  431. ac, "move_cusor_left");
  432. new TDEAction(
  433. i18n("Select to Next Line"), SHIFT + Key_Down,
  434. TQT_TQOBJECT(this), TQT_SLOT(shiftDown()),
  435. ac, "select_line_down" );
  436. new TDEAction(
  437. i18n("Scroll Line Down"), CTRL + Key_Down,
  438. TQT_TQOBJECT(this), TQT_SLOT(scrollDown()),
  439. ac, "scroll_line_down" );
  440. new TDEAction(
  441. i18n("Scroll Page Up"), TDEStdAccel::prior(),
  442. TQT_TQOBJECT(this), TQT_SLOT(pageUp()),
  443. ac, "scroll_page_up" );
  444. new TDEAction(
  445. i18n("Select Page Up"), SHIFT + Key_PageUp,
  446. TQT_TQOBJECT(this), TQT_SLOT(shiftPageUp()),
  447. ac, "select_page_up" );
  448. new TDEAction(
  449. i18n("Move to Top of View"), CTRL + Key_PageUp,
  450. TQT_TQOBJECT(this), TQT_SLOT(topOfView()),
  451. ac, "move_top_of_view" );
  452. new TDEAction(
  453. i18n("Select to Top of View"), CTRL + SHIFT + Key_PageUp,
  454. TQT_TQOBJECT(this), TQT_SLOT(shiftTopOfView()),
  455. ac, "select_top_of_view" );
  456. new TDEAction(
  457. i18n("Scroll Page Down"), TDEStdAccel::next(),
  458. TQT_TQOBJECT(this), TQT_SLOT(pageDown()),
  459. ac, "scroll_page_down" );
  460. new TDEAction(
  461. i18n("Select Page Down"), SHIFT + Key_PageDown,
  462. TQT_TQOBJECT(this), TQT_SLOT(shiftPageDown()),
  463. ac, "select_page_down" );
  464. new TDEAction(
  465. i18n("Move to Bottom of View"), CTRL + Key_PageDown,
  466. TQT_TQOBJECT(this), TQT_SLOT(bottomOfView()),
  467. ac, "move_bottom_of_view" );
  468. new TDEAction(
  469. i18n("Select to Bottom of View"), CTRL + SHIFT + Key_PageDown,
  470. TQT_TQOBJECT(this), TQT_SLOT(shiftBottomOfView()),
  471. ac, "select_bottom_of_view" );
  472. new TDEAction(
  473. i18n("Move to Matching Bracket"), CTRL + Key_6,
  474. TQT_TQOBJECT(this), TQT_SLOT(toMatchingBracket()),
  475. ac, "to_matching_bracket" );
  476. new TDEAction(
  477. i18n("Select to Matching Bracket"), SHIFT + CTRL + Key_6,
  478. TQT_TQOBJECT(this), TQT_SLOT(shiftToMatchingBracket()),
  479. ac, "select_matching_bracket" );
  480. // anders: shortcuts doing any changes should not be created in browserextension
  481. if ( !m_doc->readOnly() )
  482. {
  483. new TDEAction(
  484. i18n("Transpose Characters"), CTRL + Key_T,
  485. TQT_TQOBJECT(this), TQT_SLOT(transpose()),
  486. ac, "transpose_char" );
  487. new TDEAction(
  488. i18n("Delete Line"), CTRL + Key_K,
  489. TQT_TQOBJECT(this), TQT_SLOT(killLine()),
  490. ac, "delete_line" );
  491. new TDEAction(
  492. i18n("Delete Word Left"), TDEStdAccel::deleteWordBack(),
  493. TQT_TQOBJECT(this), TQT_SLOT(deleteWordLeft()),
  494. ac, "delete_word_left" );
  495. new TDEAction(
  496. i18n("Delete Word Right"), TDEStdAccel::deleteWordForward(),
  497. TQT_TQOBJECT(this), TQT_SLOT(deleteWordRight()),
  498. ac, "delete_word_right" );
  499. new TDEAction(i18n("Delete Next Character"), Key_Delete,
  500. TQT_TQOBJECT(this), TQT_SLOT(keyDelete()),
  501. ac, "delete_next_character");
  502. TDEAction *a = new TDEAction(i18n("Backspace"), Key_Backspace,
  503. TQT_TQOBJECT(this), TQT_SLOT(backspace()),
  504. ac, "backspace");
  505. TDEShortcut cut = a->shortcut();
  506. cut.append( KKey( SHIFT + Key_Backspace ) );
  507. a->setShortcut( cut );
  508. }
  509. connect( this, TQT_SIGNAL(gotFocus(Kate::View*)),
  510. TQT_TQOBJECT(this), TQT_SLOT(slotGotFocus()) );
  511. connect( this, TQT_SIGNAL(lostFocus(Kate::View*)),
  512. TQT_TQOBJECT(this), TQT_SLOT(slotLostFocus()) );
  513. m_editActions->readShortcutSettings( "Katepart Shortcuts" );
  514. if( hasFocus() )
  515. slotGotFocus();
  516. else
  517. slotLostFocus();
  518. }
  519. void KateView::setupCodeFolding()
  520. {
  521. TDEActionCollection *ac=this->actionCollection();
  522. new TDEAction( i18n("Collapse Toplevel"), CTRL+SHIFT+Key_Minus,
  523. m_doc->foldingTree(),TQT_SLOT(collapseToplevelNodes()),ac,"folding_toplevel");
  524. new TDEAction( i18n("Expand Toplevel"), CTRL+SHIFT+Key_Plus,
  525. TQT_TQOBJECT(this),TQT_SLOT(slotExpandToplevel()),ac,"folding_expandtoplevel");
  526. new TDEAction( i18n("Collapse One Local Level"), CTRL+Key_Minus,
  527. TQT_TQOBJECT(this),TQT_SLOT(slotCollapseLocal()),ac,"folding_collapselocal");
  528. new TDEAction( i18n("Expand One Local Level"), CTRL+Key_Plus,
  529. TQT_TQOBJECT(this),TQT_SLOT(slotExpandLocal()),ac,"folding_expandlocal");
  530. #ifdef DEBUGACCELS
  531. TDEAccel* debugAccels = new TDEAccel(this,TQT_TQOBJECT(this));
  532. debugAccels->insert("KATE_DUMP_REGION_TREE",i18n("Show the code folding region tree"),"","Ctrl+Shift+Alt+D",m_doc,TQT_SLOT(dumpRegionTree()));
  533. debugAccels->insert("KATE_TEMPLATE_TEST",i18n("Basic template code test"),"","Ctrl+Shift+Alt+T",m_doc,TQT_SLOT(testTemplateCode()));
  534. debugAccels->setEnabled(true);
  535. #endif
  536. }
  537. void KateView::slotExpandToplevel()
  538. {
  539. m_doc->foldingTree()->expandToplevelNodes(m_doc->numLines());
  540. }
  541. void KateView::slotCollapseLocal()
  542. {
  543. int realLine = m_doc->foldingTree()->collapseOne(cursorLine());
  544. if (realLine != -1)
  545. // TODO rodda: fix this to only set line and allow internal view to chose column
  546. // Explicitly call internal because we want this to be registered as an internal call
  547. setCursorPositionInternal(realLine, cursorColumn(), tabWidth(), false);
  548. }
  549. void KateView::slotExpandLocal()
  550. {
  551. m_doc->foldingTree()->expandOne(cursorLine(), m_doc->numLines());
  552. }
  553. void KateView::setupCodeCompletion()
  554. {
  555. m_codeCompletion = new KateCodeCompletion(this);
  556. connect( m_codeCompletion, TQT_SIGNAL(completionAborted()),
  557. TQT_TQOBJECT(this), TQT_SIGNAL(completionAborted()));
  558. connect( m_codeCompletion, TQT_SIGNAL(completionDone()),
  559. TQT_TQOBJECT(this), TQT_SIGNAL(completionDone()));
  560. connect( m_codeCompletion, TQT_SIGNAL(argHintHidden()),
  561. TQT_TQOBJECT(this), TQT_SIGNAL(argHintHidden()));
  562. connect( m_codeCompletion, TQT_SIGNAL(completionDone(KTextEditor::CompletionEntry)),
  563. TQT_TQOBJECT(this), TQT_SIGNAL(completionDone(KTextEditor::CompletionEntry)));
  564. connect( m_codeCompletion, TQT_SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,TQString*)),
  565. TQT_TQOBJECT(this), TQT_SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,TQString*)));
  566. }
  567. void KateView::slotGotFocus()
  568. {
  569. m_editActions->accel()->setEnabled( true );
  570. slotStatusMsg ();
  571. }
  572. void KateView::slotLostFocus()
  573. {
  574. m_editActions->accel()->setEnabled( false );
  575. }
  576. void KateView::setDynWrapIndicators(int mode)
  577. {
  578. config()->setDynWordWrapIndicators (mode);
  579. }
  580. void KateView::slotStatusMsg ()
  581. {
  582. TQString ovrstr;
  583. if (m_doc->isReadWrite())
  584. {
  585. if (m_doc->config()->configFlags() & KateDocument::cfOvr)
  586. ovrstr = i18n(" OVR ");
  587. else
  588. ovrstr = i18n(" INS ");
  589. }
  590. else
  591. ovrstr = i18n(" R/O ");
  592. uint r = cursorLine() + 1;
  593. uint c = cursorColumn() + 1;
  594. TQString s1 = i18n(" Line: %1").arg(TDEGlobal::locale()->formatNumber(r, 0));
  595. TQString s2 = i18n(" Col: %1").arg(TDEGlobal::locale()->formatNumber(c, 0));
  596. TQString modstr = m_doc->isModified() ? TQString (" * ") : TQString (" ");
  597. TQString blockstr = blockSelectionMode() ? i18n(" BLK ") : i18n(" NORM ");
  598. emit viewStatusMsg (s1 + s2 + " " + ovrstr + blockstr + modstr);
  599. }
  600. void KateView::slotSelectionTypeChanged()
  601. {
  602. m_toggleBlockSelection->setChecked( blockSelectionMode() );
  603. emit newStatus();
  604. }
  605. bool KateView::isOverwriteMode() const
  606. {
  607. return m_doc->config()->configFlags() & KateDocument::cfOvr;
  608. }
  609. void KateView::reloadFile()
  610. {
  611. m_doc->reloadFile();
  612. emit newStatus();
  613. }
  614. void KateView::slotUpdate()
  615. {
  616. emit newStatus();
  617. slotNewUndo();
  618. }
  619. void KateView::slotReadWriteChanged ()
  620. {
  621. if ( m_toggleWriteLock )
  622. m_toggleWriteLock->setChecked( ! m_doc->isReadWrite() );
  623. m_cut->setEnabled (m_doc->isReadWrite());
  624. m_paste->setEnabled (m_doc->isReadWrite());
  625. TQStringList l;
  626. l << "edit_replace" << "set_insert" << "tools_spelling" << "tools_indent"
  627. << "tools_unindent" << "tools_cleanIndent" << "tools_align" << "tools_comment"
  628. << "tools_uncomment" << "tools_uppercase" << "tools_lowercase"
  629. << "tools_capitalize" << "tools_join_lines" << "tools_apply_wordwrap"
  630. << "edit_undo" << "edit_redo" << "tools_spelling_from_cursor"
  631. << "tools_spelling_selection";
  632. TDEAction *a = 0;
  633. for (uint z = 0; z < l.size(); z++)
  634. if ((a = actionCollection()->action( l[z].ascii() )))
  635. a->setEnabled (m_doc->isReadWrite());
  636. }
  637. void KateView::slotNewUndo()
  638. {
  639. if (m_doc->readOnly())
  640. return;
  641. if ((m_doc->undoCount() > 0) != m_editUndo->isEnabled())
  642. m_editUndo->setEnabled(m_doc->undoCount() > 0);
  643. if ((m_doc->redoCount() > 0) != m_editRedo->isEnabled())
  644. m_editRedo->setEnabled(m_doc->redoCount() > 0);
  645. }
  646. void KateView::slotDropEventPass( TQDropEvent * ev )
  647. {
  648. KURL::List lstDragURLs;
  649. bool ok = KURLDrag::decode( ev, lstDragURLs );
  650. KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject( doc() );
  651. if ( ok && ext )
  652. emit ext->openURLRequest( lstDragURLs.first() );
  653. }
  654. void KateView::contextMenuEvent( TQContextMenuEvent *ev )
  655. {
  656. if ( !m_doc || !m_doc->browserExtension() )
  657. return;
  658. emit m_doc->browserExtension()->popupMenu( /*this, */ev->globalPos(), m_doc->url(),
  659. TQString::fromLatin1( "text/plain" ) );
  660. ev->accept();
  661. }
  662. bool KateView::setCursorPositionInternal( uint line, uint col, uint tabwidth, bool calledExternally )
  663. {
  664. KateTextLine::Ptr l = m_doc->kateTextLine( line );
  665. if (!l)
  666. return false;
  667. TQString line_str = m_doc->textLine( line );
  668. uint z;
  669. uint x = 0;
  670. for (z = 0; z < line_str.length() && z < col; z++) {
  671. if (line_str[z] == TQChar('\t')) x += tabwidth - (x % tabwidth); else x++;
  672. }
  673. m_viewInternal->updateCursor( KateTextCursor( line, x ), false, true, calledExternally );
  674. return true;
  675. }
  676. void KateView::setOverwriteMode( bool b )
  677. {
  678. if ( isOverwriteMode() && !b )
  679. m_doc->setConfigFlags( m_doc->config()->configFlags() ^ KateDocument::cfOvr );
  680. else
  681. m_doc->setConfigFlags( m_doc->config()->configFlags() | KateDocument::cfOvr );
  682. m_toggleInsert->setChecked (isOverwriteMode ());
  683. }
  684. void KateView::toggleInsert()
  685. {
  686. m_doc->setConfigFlags(m_doc->config()->configFlags() ^ KateDocument::cfOvr);
  687. m_toggleInsert->setChecked (isOverwriteMode ());
  688. emit newStatus();
  689. }
  690. bool KateView::canDiscard()
  691. {
  692. return m_doc->closeURL();
  693. }
  694. void KateView::flush()
  695. {
  696. m_doc->closeURL();
  697. }
  698. KateView::saveResult KateView::save()
  699. {
  700. if( !m_doc->url().isValid() || !doc()->isReadWrite() )
  701. return saveAs();
  702. if( m_doc->save() )
  703. return SAVE_OK;
  704. return SAVE_ERROR;
  705. }
  706. KateView::saveResult KateView::saveAs()
  707. {
  708. KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveURLAndEncoding(doc()->config()->encoding(),
  709. m_doc->url().url(),TQString::null,this,i18n("Save File"));
  710. // kdDebug()<<"urllist is emtpy?"<<res.URLs.isEmpty()<<endl;
  711. // kdDebug()<<"url is:"<<res.URLs.first()<<endl;
  712. if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first() ) )
  713. return SAVE_CANCEL;
  714. m_doc->config()->setEncoding( res.encoding );
  715. if( m_doc->saveAs( res.URLs.first() ) )
  716. return SAVE_OK;
  717. return SAVE_ERROR;
  718. }
  719. bool KateView::checkOverwrite( KURL u )
  720. {
  721. if( !u.isLocalFile() )
  722. return true;
  723. TQFileInfo info( u.path() );
  724. if( !info.exists() )
  725. return true;
  726. return KMessageBox::Continue
  727. == KMessageBox::warningContinueCancel
  728. ( this,
  729. i18n( "A file named \"%1\" already exists. Are you sure you want to overwrite it?" ).arg( info.fileName() ),
  730. i18n( "Overwrite File?" ),
  731. KGuiItem( i18n( "&Overwrite" ), "filesave", i18n( "Overwrite the file" ) )
  732. );
  733. }
  734. void KateView::slotSaveCanceled( const TQString& error )
  735. {
  736. if ( !error.isEmpty() ) // happens when cancelling a job
  737. KMessageBox::error( this, error );
  738. }
  739. void KateView::gotoLine()
  740. {
  741. KateGotoLineDialog *dlg = new KateGotoLineDialog (this, m_viewInternal->getCursor().line() + 1, m_doc->numLines());
  742. if (dlg->exec() == TQDialog::Accepted)
  743. gotoLineNumber( dlg->getLine() - 1 );
  744. delete dlg;
  745. }
  746. void KateView::gotoLineNumber( int line )
  747. {
  748. // clear selection, unless we are in persistent selection mode
  749. if ( !config()->persistentSelection() )
  750. clearSelection();
  751. setCursorPositionInternal ( line, 0, 1 );
  752. }
  753. void KateView::joinLines()
  754. {
  755. int first = selStartLine();
  756. int last = selEndLine();
  757. //int left = m_doc->textLine( last ).length() - m_doc->selEndCol();
  758. if ( first == last )
  759. {
  760. first = cursorLine();
  761. last = first + 1;
  762. }
  763. m_doc->joinLines( first, last );
  764. }
  765. void KateView::readSessionConfig(TDEConfig *config)
  766. {
  767. setCursorPositionInternal (config->readNumEntry("CursorLine"), config->readNumEntry("CursorColumn"), 1);
  768. }
  769. void KateView::writeSessionConfig(TDEConfig *config)
  770. {
  771. config->writeEntry("CursorLine",m_viewInternal->cursor.line());
  772. config->writeEntry("CursorColumn",m_viewInternal->cursor.col());
  773. }
  774. int KateView::getEol()
  775. {
  776. return m_doc->config()->eol();
  777. }
  778. void KateView::setEol(int eol)
  779. {
  780. if (!doc()->isReadWrite())
  781. return;
  782. if (m_updatingDocumentConfig)
  783. return;
  784. m_doc->config()->setEol (eol);
  785. }
  786. void KateView::setIconBorder( bool enable )
  787. {
  788. config()->setIconBar (enable);
  789. }
  790. void KateView::toggleIconBorder()
  791. {
  792. config()->setIconBar (!config()->iconBar());
  793. }
  794. void KateView::setLineNumbersOn( bool enable )
  795. {
  796. config()->setLineNumbers (enable);
  797. }
  798. void KateView::toggleLineNumbersOn()
  799. {
  800. config()->setLineNumbers (!config()->lineNumbers());
  801. }
  802. void KateView::setScrollBarMarks( bool enable )
  803. {
  804. config()->setScrollBarMarks (enable);
  805. }
  806. void KateView::toggleScrollBarMarks()
  807. {
  808. config()->setScrollBarMarks (!config()->scrollBarMarks());
  809. }
  810. void KateView::toggleDynWordWrap()
  811. {
  812. config()->setDynWordWrap( !config()->dynWordWrap() );
  813. }
  814. void KateView::setDynWordWrap( bool b )
  815. {
  816. config()->setDynWordWrap( b );
  817. }
  818. void KateView::toggleWWMarker()
  819. {
  820. m_renderer->config()->setWordWrapMarker (!m_renderer->config()->wordWrapMarker());
  821. }
  822. void KateView::setFoldingMarkersOn( bool enable )
  823. {
  824. config()->setFoldingBar ( enable );
  825. }
  826. void KateView::toggleFoldingMarkers()
  827. {
  828. config()->setFoldingBar ( !config()->foldingBar() );
  829. }
  830. bool KateView::iconBorder() {
  831. return m_viewInternal->leftBorder->iconBorderOn();
  832. }
  833. bool KateView::lineNumbersOn() {
  834. return m_viewInternal->leftBorder->lineNumbersOn();
  835. }
  836. bool KateView::scrollBarMarks() {
  837. return m_viewInternal->m_lineScroll->showMarks();
  838. }
  839. int KateView::dynWrapIndicators() {
  840. return m_viewInternal->leftBorder->dynWrapIndicators();
  841. }
  842. bool KateView::foldingMarkersOn() {
  843. return m_viewInternal->leftBorder->foldingMarkersOn();
  844. }
  845. void KateView::showCmdLine ( bool enabled )
  846. {
  847. if (enabled == m_cmdLineOn)
  848. return;
  849. if (enabled)
  850. {
  851. if (!m_cmdLine)
  852. {
  853. m_cmdLine = new KateCmdLine (this);
  854. m_grid->addMultiCellWidget (m_cmdLine, 2, 2, 0, 2);
  855. }
  856. m_cmdLine->show ();
  857. m_cmdLine->setFocus();
  858. }
  859. else {
  860. m_cmdLine->hide ();
  861. //m_toggleCmdLine->setChecked(false);
  862. }
  863. m_cmdLineOn = enabled;
  864. }
  865. void KateView::toggleCmdLine ()
  866. {
  867. m_config->setCmdLine (!m_config->cmdLine ());
  868. }
  869. void KateView::toggleWriteLock()
  870. {
  871. m_doc->setReadWrite( ! m_doc->isReadWrite() );
  872. }
  873. void KateView::enableTextHints(int timeout)
  874. {
  875. m_viewInternal->enableTextHints(timeout);
  876. }
  877. void KateView::disableTextHints()
  878. {
  879. m_viewInternal->disableTextHints();
  880. }
  881. void KateView::applyWordWrap ()
  882. {
  883. if (hasSelection())
  884. m_doc->wrapText (selectStart.line(), selectEnd.line());
  885. else
  886. m_doc->wrapText (0, m_doc->lastLine());
  887. }
  888. void KateView::slotNeedTextHint(int line, int col, TQString &text)
  889. {
  890. text=TQString("test %1 %2").arg(line).arg(col);
  891. }
  892. void KateView::find()
  893. {
  894. m_search->find();
  895. }
  896. void KateView::find( const TQString& pattern, long flags, bool add )
  897. {
  898. m_search->find( pattern, flags, add );
  899. }
  900. void KateView::replace()
  901. {
  902. m_search->replace();
  903. }
  904. void KateView::replace( const TQString &pattern, const TQString &replacement, long flags )
  905. {
  906. m_search->replace( pattern, replacement, flags );
  907. }
  908. void KateView::findAgain( bool back )
  909. {
  910. m_search->findAgain( back );
  911. }
  912. void KateView::slotSelectionChanged ()
  913. {
  914. m_copy->setEnabled (hasSelection());
  915. m_copyHTML->setEnabled (hasSelection());
  916. m_deSelect->setEnabled (hasSelection());
  917. if (m_doc->readOnly())
  918. return;
  919. m_cut->setEnabled (hasSelection());
  920. m_spell->updateActions ();
  921. }
  922. void KateView::switchToCmdLine ()
  923. {
  924. if (!m_cmdLineOn)
  925. m_config->setCmdLine (true);
  926. else {
  927. if (m_cmdLine->hasFocus()) {
  928. this->setFocus();
  929. return;
  930. }
  931. }
  932. m_cmdLine->setFocus ();
  933. }
  934. void KateView::showArgHint( TQStringList arg1, const TQString& arg2, const TQString& arg3 )
  935. {
  936. m_codeCompletion->showArgHint( arg1, arg2, arg3 );
  937. }
  938. void KateView::showCompletionBox( TQValueList<KTextEditor::CompletionEntry> arg1, int offset, bool cs )
  939. {
  940. emit aboutToShowCompletionBox();
  941. m_codeCompletion->showCompletionBox( arg1, offset, cs );
  942. }
  943. KateRenderer *KateView::renderer ()
  944. {
  945. return m_renderer;
  946. }
  947. void KateView::updateConfig ()
  948. {
  949. if (m_startingUp)
  950. return;
  951. m_editActions->readShortcutSettings( "Katepart Shortcuts" );
  952. // dyn. word wrap & markers
  953. if (m_hasWrap != config()->dynWordWrap()) {
  954. m_viewInternal->prepareForDynWrapChange();
  955. m_hasWrap = config()->dynWordWrap();
  956. m_viewInternal->dynWrapChanged();
  957. m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
  958. m_toggleDynWrap->setChecked( config()->dynWordWrap() );
  959. }
  960. m_viewInternal->leftBorder->setDynWrapIndicators( config()->dynWordWrapIndicators() );
  961. m_setDynWrapIndicators->setCurrentItem( config()->dynWordWrapIndicators() );
  962. // line numbers
  963. m_viewInternal->leftBorder->setLineNumbersOn( config()->lineNumbers() );
  964. m_toggleLineNumbers->setChecked( config()->lineNumbers() );
  965. // icon bar
  966. m_viewInternal->leftBorder->setIconBorderOn( config()->iconBar() );
  967. m_toggleIconBar->setChecked( config()->iconBar() );
  968. // scrollbar marks
  969. m_viewInternal->m_lineScroll->setShowMarks( config()->scrollBarMarks() );
  970. m_toggleScrollBarMarks->setChecked( config()->scrollBarMarks() );
  971. // cmd line
  972. showCmdLine (config()->cmdLine());
  973. //m_toggleCmdLine->setChecked( config()->cmdLine() );
  974. // misc edit
  975. m_toggleBlockSelection->setChecked( blockSelectionMode() );
  976. m_toggleInsert->setChecked( isOverwriteMode() );
  977. updateFoldingConfig ();
  978. // bookmark
  979. m_bookmarks->setSorting( (KateBookmarks::Sorting) config()->bookmarkSort() );
  980. m_viewInternal->setAutoCenterLines(config()->autoCenterLines ());
  981. }
  982. void KateView::updateDocumentConfig()
  983. {
  984. if (m_startingUp)
  985. return;
  986. m_updatingDocumentConfig = true;
  987. m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
  988. m_updatingDocumentConfig = false;
  989. m_viewInternal->updateView (true);
  990. m_renderer->setTabWidth (m_doc->config()->tabWidth());
  991. m_renderer->setIndentWidth (m_doc->config()->indentationWidth());
  992. }
  993. void KateView::updateRendererConfig()
  994. {
  995. if (m_startingUp)
  996. return;
  997. m_toggleWWMarker->setChecked( m_renderer->config()->wordWrapMarker() );
  998. // update the text area
  999. m_viewInternal->updateView (true);
  1000. m_viewInternal->repaint ();
  1001. // update the left border right, for example linenumbers
  1002. m_viewInternal->leftBorder->updateFont();
  1003. m_viewInternal->leftBorder->repaint ();
  1004. // @@ showIndentLines is not cached anymore.
  1005. // m_renderer->setShowIndentLines (m_renderer->config()->showIndentationLines());
  1006. }
  1007. void KateView::updateFoldingConfig ()
  1008. {
  1009. // folding bar
  1010. bool doit = config()->foldingBar() && m_doc->highlight() && m_doc->highlight()->allowsFolding();
  1011. m_viewInternal->leftBorder->setFoldingMarkersOn(doit);
  1012. m_toggleFoldingMarkers->setChecked( doit );
  1013. m_toggleFoldingMarkers->setEnabled( m_doc->highlight() && m_doc->highlight()->allowsFolding() );
  1014. TQStringList l;
  1015. l << "folding_toplevel" << "folding_expandtoplevel"
  1016. << "folding_collapselocal" << "folding_expandlocal";
  1017. TDEAction *a = 0;
  1018. for (uint z = 0; z < l.size(); z++)
  1019. if ((a = actionCollection()->action( l[z].ascii() )))
  1020. a->setEnabled (m_doc->highlight() && m_doc->highlight()->allowsFolding());
  1021. }
  1022. //BEGIN EDIT STUFF
  1023. void KateView::editStart ()
  1024. {
  1025. m_viewInternal->editStart ();
  1026. }
  1027. void KateView::editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom)
  1028. {
  1029. m_viewInternal->editEnd (editTagLineStart, editTagLineEnd, tagFrom);
  1030. }
  1031. void KateView::editSetCursor (const KateTextCursor &cursor)
  1032. {
  1033. m_viewInternal->editSetCursor (cursor);
  1034. }
  1035. //END
  1036. //BEGIN TAG & CLEAR
  1037. bool KateView::tagLine (const KateTextCursor& virtualCursor)
  1038. {
  1039. return m_viewInternal->tagLine (virtualCursor);
  1040. }
  1041. bool KateView::tagLines (int start, int end, bool realLines)
  1042. {
  1043. return m_viewInternal->tagLines (start, end, realLines);
  1044. }
  1045. bool KateView::tagLines (KateTextCursor start, KateTextCursor end, bool realCursors)
  1046. {
  1047. return m_viewInternal->tagLines (start, end, realCursors);
  1048. }
  1049. void KateView::tagAll ()
  1050. {
  1051. m_viewInternal->tagAll ();
  1052. }
  1053. void KateView::clear ()
  1054. {
  1055. m_viewInternal->clear ();
  1056. }
  1057. void KateView::repaintText (bool paintOnlyDirty)
  1058. {
  1059. m_viewInternal->paintText(0,0,m_viewInternal->width(),m_viewInternal->height(), paintOnlyDirty);
  1060. }
  1061. void KateView::updateView (bool changed)
  1062. {
  1063. m_viewInternal->updateView (changed);
  1064. m_viewInternal->leftBorder->update();
  1065. }
  1066. //END
  1067. void KateView::slotHlChanged()
  1068. {
  1069. KateHighlighting *hl = m_doc->highlight();
  1070. bool ok ( !hl->getCommentStart(0).isEmpty() || !hl->getCommentSingleLineStart(0).isEmpty() );
  1071. if (actionCollection()->action("tools_comment"))
  1072. actionCollection()->action("tools_comment")->setEnabled( ok );
  1073. if (actionCollection()->action("tools_uncomment"))
  1074. actionCollection()->action("tools_uncomment")->setEnabled( ok );
  1075. // show folding bar if "view defaults" says so, otherwise enable/disable only the menu entry
  1076. updateFoldingConfig ();
  1077. }
  1078. uint KateView::cursorColumn()
  1079. {
  1080. uint r = m_doc->currentColumn(m_viewInternal->getCursor());
  1081. if ( !( m_doc->config()->configFlags() & KateDocumentConfig::cfWrapCursor ) &&
  1082. (uint)m_viewInternal->getCursor().col() > m_doc->textLine( m_viewInternal->getCursor().line() ).length() )
  1083. r += m_viewInternal->getCursor().col() - m_doc->textLine( m_viewInternal->getCursor().line() ).length();
  1084. return r;
  1085. }
  1086. //BEGIN KTextEditor::SelectionInterface stuff
  1087. bool KateView::setSelection( const KateTextCursor& start, const KateTextCursor& end )
  1088. {
  1089. KateTextCursor oldSelectStart = selectStart;
  1090. KateTextCursor oldSelectEnd = selectEnd;
  1091. if (start <= end) {
  1092. selectStart.setPos(start);
  1093. selectEnd.setPos(end);
  1094. } else {
  1095. selectStart.setPos(end);
  1096. selectEnd.setPos(start);
  1097. }
  1098. tagSelection(oldSelectStart, oldSelectEnd);
  1099. repaintText(true);
  1100. emit selectionChanged ();
  1101. emit m_doc->selectionChanged ();
  1102. return true;
  1103. }
  1104. bool KateView::setSelection( uint startLine, uint startCol, uint endLine, uint endCol )
  1105. {
  1106. if (hasSelection())
  1107. clearSelection(false, false);
  1108. return setSelection( KateTextCursor(startLine, startCol), KateTextCursor(endLine, endCol) );
  1109. }
  1110. void KateView::syncSelectionCache()
  1111. {
  1112. m_viewInternal->selStartCached = selectStart;
  1113. m_viewInternal->selEndCached = selectEnd;
  1114. m_viewInternal->selectAnchor = selectEnd;
  1115. }
  1116. bool KateView::clearSelection()
  1117. {
  1118. return clearSelection(true);
  1119. }
  1120. bool KateView::clearSelection(bool redraw, bool finishedChangingSelection)
  1121. {
  1122. if( !hasSelection() )
  1123. return false;
  1124. KateTextCursor oldSelectStart = selectStart;
  1125. KateTextCursor oldSelectEnd = selectEnd;
  1126. selectStart.setPos(-1, -1);
  1127. selectEnd.setPos(-1, -1);
  1128. tagSelection(oldSelectStart, oldSelectEnd);
  1129. oldSelectStart = selectStart;
  1130. oldSelectEnd = selectEnd;
  1131. if (redraw)
  1132. repaintText(true);
  1133. if (finishedChangingSelection)
  1134. {
  1135. emit selectionChanged();
  1136. emit m_doc->selectionChanged ();
  1137. }
  1138. return true;
  1139. }
  1140. bool KateView::hasSelection() const
  1141. {
  1142. return selectStart != selectEnd;
  1143. }
  1144. TQString KateView::selection() const
  1145. {
  1146. int sc = selectStart.col();
  1147. int ec = selectEnd.col();
  1148. if ( blockSelect )
  1149. {
  1150. if (sc > ec)
  1151. {
  1152. uint tmp = sc;
  1153. sc = ec;
  1154. ec = tmp;
  1155. }
  1156. }
  1157. return m_doc->text (selectStart.line(), sc, selectEnd.line(), ec, blockSelect);
  1158. }
  1159. bool KateView::removeSelectedText ()
  1160. {
  1161. if (!hasSelection())
  1162. return false;
  1163. m_doc->editStart ();
  1164. int sc = selectStart.col();
  1165. int ec = selectEnd.col();
  1166. if ( blockSelect )
  1167. {
  1168. if (sc > ec)
  1169. {
  1170. uint tmp = sc;
  1171. sc = ec;
  1172. ec = tmp;
  1173. }
  1174. }
  1175. m_doc->removeText (selectStart.line(), sc, selectEnd.line(), ec, blockSelect);
  1176. // don't redraw the cleared selection - that's done in editEnd().
  1177. clearSelection(false);
  1178. m_doc->editEnd ();
  1179. return true;
  1180. }
  1181. bool KateView::selectAll()
  1182. {
  1183. setBlockSelectionMode (false);
  1184. return setSelection (0, 0, m_doc->lastLine(), m_doc->lineLength(m_doc->lastLine()));
  1185. }
  1186. bool KateView::lineColSelected (int line, int col)
  1187. {
  1188. if ( (!blockSelect) && (col < 0) )
  1189. col = 0;
  1190. KateTextCursor cursor(line, col);
  1191. if (blockSelect)
  1192. return cursor.line() >= selectStart.line() && cursor.line() <= selectEnd.line() && cursor.col() >= selectStart.col() && cursor.col() < selectEnd.col();
  1193. else
  1194. return (cursor >= selectStart) && (cursor < selectEnd);
  1195. }
  1196. bool KateView::lineSelected (int line)
  1197. {
  1198. return (!blockSelect)
  1199. && (selectStart <= KateTextCursor(line, 0))
  1200. && (line < selectEnd.line());
  1201. }
  1202. bool KateView::lineEndSelected (int line, int endCol)
  1203. {
  1204. return (!blockSelect)
  1205. && (line > selectStart.line() || (line == selectStart.line() && (selectStart.col() < endCol || endCol == -1)))
  1206. && (line < selectEnd.line() || (line == selectEnd.line() && (endCol <= selectEnd.col() && endCol != -1)));
  1207. }
  1208. bool KateView::lineHasSelected (int line)
  1209. {
  1210. return (selectStart < selectEnd)
  1211. && (line >= selectStart.line())
  1212. && (line <= selectEnd.line());
  1213. }
  1214. bool KateView::lineIsSelection (int line)
  1215. {
  1216. return (line == selectStart.line() && line == selectEnd.line());
  1217. }
  1218. void KateView::tagSelection(const KateTextCursor &oldSelectStart, const KateTextCursor &oldSelectEnd)
  1219. {
  1220. if (hasSelection()) {
  1221. if (oldSelectStart.line() == -1) {
  1222. // We have to tag the whole lot if
  1223. // 1) we have a selection, and:
  1224. // a) it's new; or
  1225. tagLines(selectStart, selectEnd, true);
  1226. } else if (blockSelectionMode() && (oldSelectStart.col() != selectStart.col() || oldSelectEnd.col() != selectEnd.col())) {
  1227. // b) we're in block selection mode and the columns have changed
  1228. tagLines(selectStart, selectEnd, true);
  1229. tagLines(oldSelectStart, oldSelectEnd, true);
  1230. } else {
  1231. if (oldSelectStart != selectStart) {
  1232. if (oldSelectStart < selectStart)
  1233. tagLines(oldSelectStart, selectStart, true);
  1234. else
  1235. tagLines(selectStart, oldSelectStart, true);
  1236. }
  1237. if (oldSelectEnd != selectEnd) {
  1238. if (oldSelectEnd < selectEnd)
  1239. tagLines(oldSelectEnd, selectEnd, true);
  1240. else
  1241. tagLines(selectEnd, oldSelectEnd, true);
  1242. }
  1243. }
  1244. } else {
  1245. // No more selection, clean up
  1246. tagLines(oldSelectStart, oldSelectEnd, true);
  1247. }
  1248. }
  1249. void KateView::selectWord( const KateTextCursor& cursor )
  1250. {
  1251. int start, end, len;
  1252. KateTextLine::Ptr textLine = m_doc->plainKateTextLine(cursor.line());
  1253. if (!textLine)
  1254. return;
  1255. len = textLine->length();
  1256. start = end = cursor.col();
  1257. while (start > 0 && m_doc->highlight()->isInWord(textLine->getChar(start - 1), textLine->attribute(start - 1))) start--;
  1258. while (end < len && m_doc->highlight()->isInWord(textLine->getChar(end), textLine->attribute(start - 1))) end++;
  1259. if (end <= start) return;
  1260. setSelection (cursor.line(), start, cursor.line(), end);
  1261. }
  1262. void KateView::selectLine( const KateTextCursor& cursor )
  1263. {
  1264. if (cursor.line()+1 >= m_doc->numLines())
  1265. setSelection (cursor.line(), 0, cursor.line(), m_doc->lineLength(cursor.line()));
  1266. else
  1267. setSelection (cursor.line(), 0, cursor.line()+1, 0);
  1268. }
  1269. void KateView::selectLength( const KateTextCursor& cursor, int length )
  1270. {
  1271. int start, end;
  1272. KateTextLine::Ptr textLine = m_doc->plainKateTextLine(cursor.line());
  1273. if (!textLine)
  1274. return;
  1275. start = cursor.col();
  1276. end = start + length;
  1277. if (end <= start) return;
  1278. setSelection (cursor.line(), start, cursor.line(), end);
  1279. }
  1280. void KateView::paste()
  1281. {
  1282. m_doc->paste( this );
  1283. emit selectionChanged();
  1284. m_viewInternal->repaint();
  1285. }
  1286. void KateView::cut()
  1287. {
  1288. if (!hasSelection())
  1289. return;
  1290. copy();
  1291. removeSelectedText();
  1292. }
  1293. void KateView::copy() const
  1294. {
  1295. if (!hasSelection())
  1296. return;
  1297. TQApplication::clipboard()->setText(selection ());
  1298. }
  1299. void KateView::copyHTML()
  1300. {
  1301. if (!hasSelection())
  1302. return;
  1303. KMultipleDrag *drag = new KMultipleDrag();
  1304. TQTextDrag *htmltextdrag = new TQTextDrag(selectionAsHtml()) ;
  1305. htmltextdrag->setSubtype("html");
  1306. drag->addDragObject( htmltextdrag);
  1307. drag->addDragObject( new TQTextDrag( selection()));
  1308. TQApplication::clipboard()->setData(drag);
  1309. }
  1310. TQString KateView::selectionAsHtml()
  1311. {
  1312. int sc = selectStart.col();
  1313. int ec = selectEnd.col();
  1314. if ( blockSelect )
  1315. {
  1316. if (sc > ec)
  1317. {
  1318. uint tmp = sc;
  1319. sc = ec;
  1320. ec = tmp;
  1321. }
  1322. }
  1323. return textAsHtml (selectStart.line(), sc, selectEnd.line(), ec, blockSelect);
  1324. }
  1325. TQString KateView::textAsHtml ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise)
  1326. {
  1327. kdDebug(13020) << "textAsHtml" << endl;
  1328. if ( blockwise && (startCol > endCol) )
  1329. return TQString ();
  1330. TQString s;
  1331. TQTextStream ts( &s, IO_WriteOnly );
  1332. ts.setEncoding(TQTextStream::UnicodeUTF8);
  1333. ts << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl;
  1334. ts << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl;
  1335. ts << "<head>" << endl;
  1336. ts << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" << endl;
  1337. ts << "<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" << endl;
  1338. ts << "</head>" << endl;
  1339. ts << "<body>" << endl;
  1340. textAsHtmlStream(startLine, startCol, endLine, endCol, blockwise, &ts);
  1341. ts << "</body>" << endl;
  1342. ts << "</html>" << endl;
  1343. kdDebug(13020) << "html is: " << s << endl;
  1344. return s;
  1345. }
  1346. void KateView::textAsHtmlStream ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise, TQTextStream *ts)
  1347. {
  1348. if ( (blockwise || startLine == endLine) && (startCol > endCol) )
  1349. return;
  1350. if (startLine == endLine)
  1351. {
  1352. KateTextLine::Ptr textLine = m_doc->kateTextLine(startLine);
  1353. if ( !textLine )
  1354. return;
  1355. (*ts) << "<pre>" << endl;
  1356. lineAsHTML(textLine, startCol, endCol-startCol, ts);
  1357. }
  1358. else
  1359. {
  1360. (*ts) << "<pre>" << endl;
  1361. for (uint i = startLine; (i <= endLine) && (i < m_doc->numLines()); i++)
  1362. {
  1363. KateTextLine::Ptr textLine = m_doc->kateTextLine(i);
  1364. if ( !blockwise )
  1365. {
  1366. if (i == startLine)
  1367. lineAsHTML(textLine, startCol, textLine->length()-startCol, ts);
  1368. else if (i == endLine)
  1369. lineAsHTML(textLine, 0, endCol, ts);
  1370. else
  1371. lineAsHTML(textLine, 0, textLine->length(), ts);
  1372. }
  1373. else
  1374. {
  1375. lineAsHTML( textLine, startCol, endCol-startCol, ts);
  1376. }
  1377. if ( i < endLine )
  1378. (*ts) << "\n"; //we are inside a <pre>, so a \n is a new line
  1379. }
  1380. }
  1381. (*ts) << "</pre>";
  1382. }
  1383. // fully rewritten to use only inline CSS and support all used attribs.
  1384. // anders, 2005-11-01 23:39:43
  1385. void KateView::lineAsHTML (KateTextLine::Ptr line, uint startCol, uint length, TQTextStream *outputStream)
  1386. {
  1387. if(length == 0)
  1388. return;
  1389. // do not recalculate the style strings again and again
  1390. TQMap<uchar,TQString> stylecache;
  1391. // do not insert equally styled characters one by one
  1392. TQString textcache;
  1393. KateAttribute *charAttributes = 0;
  1394. for (uint curPos=startCol;curPos<(length+startCol);curPos++)
  1395. {
  1396. if ( curPos == 0 || line->attribute( curPos ) != line->attribute( curPos - 1 ) &&
  1397. // Since many highlight files contains itemdatas that have the exact
  1398. // same styles, join those to keep the HTML text size down
  1399. KateAttribute(*charAttributes) != KateAttribute(*m_renderer->attribute(line->attribute(curPos))) )
  1400. {
  1401. (*outputStream) << textcache;
  1402. textcache.truncate(0);
  1403. if ( curPos > startCol )
  1404. (*outputStream) << "</span>";
  1405. charAttributes = m_renderer->attribute(line->attribute(curPos));
  1406. if ( ! stylecache.contains( line->attribute(curPos) ) )
  1407. {
  1408. TQString textdecoration;
  1409. TQString style;
  1410. if ( charAttributes->bold() )
  1411. style.append("font-weight: bold;");
  1412. if ( charAttributes->italic() )
  1413. style.append("font-style: italic;");
  1414. if ( charAttributes->underline() )
  1415. textdecoration = "underline";
  1416. if ( charAttributes->overline() )
  1417. textdecoration.append(" overline" );
  1418. if ( charAttributes->strikeOut() )
  1419. textdecoration.append(" line-trough" );
  1420. if ( !textdecoration.isEmpty() )
  1421. style.append("text-decoration: %1;").arg(textdecoration);
  1422. // TQColor::name() returns a string in the form "#RRGGBB" in Qt 3.
  1423. // NOTE Qt 4 returns "#AARRGGBB"
  1424. if ( charAttributes->itemSet(KateAttribute::BGColor) )
  1425. style.append(TQString("background-color: %1;").arg(charAttributes->bgColor().name()));
  1426. if ( charAttributes->itemSet(KateAttribute::TextColor) )
  1427. style.append(TQString("color: %1;").arg(charAttributes->textColor().name()));
  1428. stylecache[line->attribute(curPos)] = style;
  1429. }
  1430. (*outputStream)<<"<span style=\""
  1431. << stylecache[line->attribute(curPos)]
  1432. << "\">";
  1433. }
  1434. TQString s( line->getChar(curPos) );
  1435. if ( s == "&" ) s = "&amp;";
  1436. else if ( s == "<" ) s = "&lt;";
  1437. else if ( s == ">" ) s = "&gt;";
  1438. textcache.append( s );
  1439. }
  1440. (*outputStream) << textcache << "</span>";
  1441. }
  1442. void KateView::exportAsHTML ()
  1443. {
  1444. KURL url = KFileDialog::getSaveURL(m_doc->docName(),"text/html",0,i18n("Export File as HTML"));
  1445. if ( url.isEmpty() )
  1446. return;
  1447. TQString filename;
  1448. KTempFile tmp; // ### only used for network export
  1449. if ( url.isLocalFile() )
  1450. filename = url.path();
  1451. else
  1452. filename = tmp.name();
  1453. KSaveFile *savefile=new KSaveFile(filename);
  1454. if (!savefile->status())
  1455. {
  1456. TQTextStream *outputStream = savefile->textStream();
  1457. outputStream->setEncoding(TQTextStream::UnicodeUTF8);
  1458. // let's write the HTML header :
  1459. (*outputStream) << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
  1460. (*outputStream) << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl;
  1461. (*outputStream) << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl;
  1462. (*outputStream) << "<head>" << endl;
  1463. (*outputStream) << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" << endl;
  1464. (*outputStream) << "<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" << endl;
  1465. // for the title, we write the name of the file (/usr/local/emmanuel/myfile.cpp -> myfile.cpp)
  1466. (*outputStream) << "<title>" << m_doc->docName () << "</title>" << endl;
  1467. (*outputStream) << "</head>" << endl;
  1468. (*outputStream) << "<body>" << endl;
  1469. textAsHtmlStream(0,0, m_doc->lastLine(), m_doc->lineLength(m_doc->lastLine()), false, outputStream);
  1470. (*outputStream) << "</body>" << endl;
  1471. (*outputStream) << "</html>" << endl;
  1472. savefile->close();
  1473. //if (!savefile->status()) --> Error
  1474. }
  1475. // else
  1476. // {/*ERROR*/}
  1477. delete savefile;
  1478. if ( url.isLocalFile() )
  1479. return;
  1480. TDEIO::NetAccess::upload( filename, url, 0 );
  1481. }
  1482. //END
  1483. //BEGIN KTextEditor::BlockSelectionInterface stuff
  1484. bool KateView::blockSelectionMode ()
  1485. {
  1486. return blockSelect;
  1487. }
  1488. bool KateView::setBlockSelectionMode (bool on)
  1489. {
  1490. if (on != blockSelect)
  1491. {
  1492. blockSelect = on;
  1493. KateTextCursor oldSelectStart = selectStart;
  1494. KateTextCursor oldSelectEnd = selectEnd;
  1495. clearSelection(false, false);
  1496. setSelection(oldSelectStart, oldSelectEnd);
  1497. slotSelectionTypeChanged();
  1498. }
  1499. return true;
  1500. }
  1501. bool KateView::toggleBlockSelectionMode ()
  1502. {
  1503. m_toggleBlockSelection->setChecked (!blockSelect);
  1504. return setBlockSelectionMode (!blockSelect);
  1505. }
  1506. bool KateView::wrapCursor ()
  1507. {
  1508. return !blockSelectionMode() && (m_doc->configFlags() & KateDocument::cfWrapCursor);
  1509. }
  1510. //END
  1511. //BEGIN IM INPUT STUFF
  1512. void KateView::setIMSelectionValue( uint imStartLine, uint imStart, uint imEnd,
  1513. uint imSelStart, uint imSelEnd, bool imComposeEvent )
  1514. {
  1515. m_imStartLine = imStartLine;
  1516. m_imStart = imStart;
  1517. m_imEnd = imEnd;
  1518. m_imSelStart = imSelStart;
  1519. m_imSelEnd = imSelEnd;
  1520. m_imComposeEvent = imComposeEvent;
  1521. }
  1522. bool KateView::isIMSelection( int _line, int _column )
  1523. {
  1524. return ( ( int( m_imStartLine ) == _line ) && ( m_imSelStart < m_imSelEnd ) && ( _column >= int( m_imSelStart ) ) &&
  1525. ( _column < int( m_imSelEnd ) ) );
  1526. }
  1527. bool KateView::isIMEdit( int _line, int _column )
  1528. {
  1529. return ( ( int( m_imStartLine ) == _line ) && ( m_imStart < m_imEnd ) && ( _column >= int( m_imStart ) ) &&
  1530. ( _column < int( m_imEnd ) ) );
  1531. }
  1532. void KateView::getIMSelectionValue( uint *imStartLine, uint *imStart, uint *imEnd,
  1533. uint *imSelStart, uint *imSelEnd )
  1534. {
  1535. *imStartLine = m_imStartLine;
  1536. *imStart = m_imStart;
  1537. *imEnd = m_imEnd;
  1538. *imSelStart = m_imSelStart;
  1539. *imSelEnd = m_imSelEnd;
  1540. }
  1541. //END IM INPUT STUFF
  1542. // kate: space-indent on; indent-width 2; replace-tabs on;