27 #include "kateview.moc"
29 #include "kateviewinternal.h"
30 #include "kateviewhelpers.h"
31 #include "katerenderer.h"
32 #include "katedocument.h"
33 #include "katedocumenthelpers.h"
34 #include "katefactory.h"
35 #include "katehighlight.h"
36 #include "katedialogs.h"
37 #include "katetextline.h"
38 #include "katecodefoldinghelpers.h"
39 #include "katecodecompletion.h"
40 #include "katesearch.h"
41 #include "kateschema.h"
42 #include "katebookmarks.h"
43 #include "katesearch.h"
44 #include "kateconfig.h"
45 #include "katefiletype.h"
46 #include "kateautoindent.h"
47 #include "katespell.h"
49 #include <tdetexteditor/plugin.h>
51 #include <tdeparts/event.h>
53 #include <tdeio/netaccess.h>
55 #include <tdeconfig.h>
58 #include <tdeapplication.h>
61 #include <tdeglobal.h>
62 #include <kcharsets.h>
63 #include <tdemessagebox.h>
64 #include <tdeaction.h>
65 #include <kstdaction.h>
66 #include <kxmlguifactory.h>
68 #include <klibloader.h>
69 #include <kencodingfiledialog.h>
70 #include <tdemultipledrag.h>
71 #include <tdetempfile.h>
72 #include <ksavefile.h>
75 #include <tqfileinfo.h>
78 #include <tqpopupmenu.h>
80 #include <tqclipboard.h>
81 #include <tqstylesheet.h>
84 KateView::KateView( KateDocument *doc, TQWidget *parent,
const char * name )
87 , m_search( new KateSearch( this ) )
88 , m_spell( new KateSpell( this ) )
89 , m_bookmarks( new KateBookmarks( this ) )
95 , m_updatingDocumentConfig (false)
96 , selectStart (m_doc, true)
97 , selectEnd (m_doc, true)
104 , m_imComposeEvent( false )
106 KateFactory::self()->registerView(
this );
107 m_config =
new KateViewConfig (
this);
111 m_grid =
new TQGridLayout (
this, 3, 3);
113 m_grid->setRowStretch ( 0, 10 );
114 m_grid->setRowStretch ( 1, 0 );
115 m_grid->setColStretch ( 0, 0 );
116 m_grid->setColStretch ( 1, 10 );
117 m_grid->setColStretch ( 2, 0 );
119 m_viewInternal =
new KateViewInternal(
this, doc );
120 m_grid->addWidget (m_viewInternal, 0, 1);
122 setClipboardInterfaceDCOPSuffix (viewDCOPSuffix());
123 setCodeCompletionInterfaceDCOPSuffix (viewDCOPSuffix());
124 setDynWordWrapInterfaceDCOPSuffix (viewDCOPSuffix());
125 setPopupMenuInterfaceDCOPSuffix (viewDCOPSuffix());
126 setSessionConfigInterfaceDCOPSuffix (viewDCOPSuffix());
127 setViewCursorInterfaceDCOPSuffix (viewDCOPSuffix());
128 setViewStatusMsgInterfaceDCOPSuffix (viewDCOPSuffix());
130 setInstance( KateFactory::self()->
instance() );
131 doc->addView(
this );
133 setFocusProxy( m_viewInternal );
134 setFocusPolicy( TQ_StrongFocus );
136 if (!doc->singleViewMode()) {
137 setXMLFile(
"katepartui.rc" );
139 if( doc->readOnly() )
140 setXMLFile(
"katepartreadonlyui.rc" );
142 setXMLFile(
"katepartui.rc" );
149 setupCodeCompletion();
152 m_doc->enableAllPluginsGUI (
this);
157 m_startingUp =
false;
168 KateView::~KateView()
170 if (!m_doc->singleViewMode())
171 m_doc->disableAllPluginsGUI (
this);
173 m_doc->removeView(
this );
184 KateFactory::self()->deregisterView (
this);
187 void KateView::setupConnections()
189 connect( m_doc, TQT_SIGNAL(undoChanged()),
190 TQT_TQOBJECT(
this), TQT_SLOT(slotNewUndo()) );
191 connect( m_doc, TQT_SIGNAL(hlChanged()),
192 TQT_TQOBJECT(
this), TQT_SLOT(slotHlChanged()) );
193 connect( m_doc, TQT_SIGNAL(canceled(
const TQString&)),
194 TQT_TQOBJECT(
this), TQT_SLOT(slotSaveCanceled(
const TQString&)) );
195 connect( m_viewInternal, TQT_SIGNAL(dropEventPass(TQDropEvent*)),
196 TQT_TQOBJECT(
this), TQT_SIGNAL(dropEventPass(TQDropEvent*)) );
197 connect(
this,TQT_SIGNAL(cursorPositionChanged()),
this,TQT_SLOT(slotStatusMsg()));
198 connect(
this,TQT_SIGNAL(newStatus()),
this,TQT_SLOT(slotStatusMsg()));
199 connect(m_doc, TQT_SIGNAL(undoChanged()), TQT_TQOBJECT(
this), TQT_SLOT(slotStatusMsg()));
201 if ( m_doc->browserView() )
203 connect(
this, TQT_SIGNAL(dropEventPass(TQDropEvent*)),
204 TQT_TQOBJECT(
this), TQT_SLOT(slotDropEventPass(TQDropEvent*)) );
208 void KateView::setupActions()
213 m_toggleWriteLock = 0;
216 a->
setWhatsThis(i18n(
"Cut the selected text and move it to the clipboard"));
219 a->
setWhatsThis(i18n(
"Paste previously copied or cut clipboard contents"));
222 a->
setWhatsThis(i18n(
"Use this command to copy the currently selected text to the system clipboard."));
224 m_copyHTML = a =
new TDEAction(i18n(
"Copy as &HTML"),
"edit-copy", 0, TQT_TQOBJECT(
this), TQT_SLOT(copyHTML()), ac,
"edit_copy_html");
225 a->
setWhatsThis(i18n(
"Use this command to copy the currently selected text as HTML to the system clipboard."));
227 if (!m_doc->readOnly())
233 a->
setWhatsThis(i18n(
"Revert the most recent editing actions"));
236 a->
setWhatsThis(i18n(
"Revert the most recent undo operation"));
238 (
new TDEAction(i18n(
"&Word Wrap Document"),
"", 0, TQT_TQOBJECT(
this), TQT_SLOT(applyWordWrap()), ac,
"tools_apply_wordwrap"))->setWhatsThis(
239 i18n(
"Use this command to wrap all lines of the current document which are longer than the width of the"
240 " current view, to fit into this view.<br><br> This is a static word wrap, meaning it is not updated"
241 " when the view is resized."));
244 a=
new TDEAction(i18n(
"&Indent"),
"format-indent-more", Qt::CTRL+Qt::Key_I, TQT_TQOBJECT(
this), TQT_SLOT(indent()), ac,
"tools_indent");
245 a->
setWhatsThis(i18n(
"Use this to indent a selected block of text.<br><br>"
246 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
247 a=
new TDEAction(i18n(
"&Unindent"),
"format-indent-less", Qt::CTRL+Qt::SHIFT+Qt::Key_I, TQT_TQOBJECT(
this), TQT_SLOT(unIndent()), ac,
"tools_unindent");
248 a->
setWhatsThis(i18n(
"Use this to unindent a selected block of text."));
250 a=
new TDEAction(i18n(
"&Clean Indentation"), 0, TQT_TQOBJECT(
this), TQT_SLOT(cleanIndent()), ac,
"tools_cleanIndent");
251 a->
setWhatsThis(i18n(
"Use this to clean the indentation of a selected block of text (only tabs/only spaces)<br><br>"
252 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
254 a=
new TDEAction(i18n(
"&Align"), 0, TQT_TQOBJECT(
this), TQT_SLOT(align()), ac,
"tools_align");
255 a->
setWhatsThis(i18n(
"Use this to align the current line or block of text to its proper indent level."));
257 a=
new TDEAction(i18n(
"C&omment"), CTRL+Qt::Key_D, TQT_TQOBJECT(
this), TQT_SLOT(comment()),
258 ac,
"tools_comment");
259 a->
setWhatsThis(i18n(
"This command comments out the current line or a selected block of text.<BR><BR>"
260 "The characters for single/multiple line comments are defined within the language's highlighting."));
262 a=
new TDEAction(i18n(
"Unco&mment"), CTRL+SHIFT+Qt::Key_D, TQT_TQOBJECT(
this), TQT_SLOT(uncomment()),
263 ac,
"tools_uncomment");
264 a->
setWhatsThis(i18n(
"This command removes comments from the current line or a selected block of text.<BR><BR>"
265 "The characters for single/multiple line comments are defined within the language's highlighting."));
267 i18n(
"&Read Only Mode"), 0, 0,
268 TQT_TQOBJECT(
this), TQT_SLOT( toggleWriteLock() ),
269 ac,
"tools_toggle_write_lock" );
270 a->
setWhatsThis( i18n(
"Lock/unlock the document for writing") );
272 a =
new TDEAction( i18n(
"Uppercase"), CTRL + Qt::Key_U, TQT_TQOBJECT(
this),
273 TQT_SLOT(uppercase()), ac,
"tools_uppercase" );
274 a->
setWhatsThis( i18n(
"Convert the selection to uppercase, or the character to the "
275 "right of the cursor if no text is selected.") );
277 a =
new TDEAction( i18n(
"Lowercase"), CTRL + SHIFT + Qt::Key_U, TQT_TQOBJECT(
this),
278 TQT_SLOT(lowercase()), ac,
"tools_lowercase" );
279 a->
setWhatsThis( i18n(
"Convert the selection to lowercase, or the character to the "
280 "right of the cursor if no text is selected.") );
282 a =
new TDEAction( i18n(
"Capitalize"), CTRL + ALT + Qt::Key_U, TQT_TQOBJECT(
this),
283 TQT_SLOT(capitalize()), ac,
"tools_capitalize" );
284 a->
setWhatsThis( i18n(
"Capitalize the selection, or the word under the "
285 "cursor if no text is selected.") );
287 a =
new TDEAction( i18n(
"Join Lines"), CTRL + Qt::Key_J, TQT_TQOBJECT(
this),
288 TQT_SLOT( joinLines() ), ac,
"tools_join_lines" );
292 m_cut->setEnabled (
false);
293 m_paste->setEnabled (
false);
302 a->
setWhatsThis(i18n(
"Reload the current document from disk."));
305 a->
setWhatsThis(i18n(
"Save the current document to disk, with a name of your choice."));
308 a->
setWhatsThis(i18n(
"This command opens a dialog and lets you choose a line that you want the cursor to move to."));
310 a=
new TDEAction(i18n(
"&Configure Editor..."), 0, m_doc, TQT_SLOT(configDialog()),ac,
"set_confdlg");
311 a->
setWhatsThis(i18n(
"Configure various aspects of this editor."));
313 KateViewHighlightAction *menu =
new KateViewHighlightAction (i18n(
"&Highlighting"), ac,
"set_highlight");
314 menu->setWhatsThis(i18n(
"Here you can choose how the current document should be highlighted."));
315 menu->updateMenu (m_doc);
317 KateViewFileTypeAction *ftm =
new KateViewFileTypeAction (i18n(
"&Filetype"),ac,
"set_filetype");
318 ftm->updateMenu (m_doc);
320 KateViewSchemaAction *schemaMenu =
new KateViewSchemaAction (i18n(
"&Schema"),ac,
"view_schemas");
321 schemaMenu->updateMenu (
this);
327 a =
new TDEAction(i18n(
"E&xport as HTML..."), 0, 0, TQT_TQOBJECT(
this), TQT_SLOT(exportAsHTML()), ac,
"file_export_html");
328 a->
setWhatsThis(i18n(
"This command allows you to export the current document"
329 " with all highlighting information into a HTML document."));
332 a->
setWhatsThis(i18n(
"Select the entire text of the current document."));
335 a->
setWhatsThis(i18n(
"If you have selected something within the current document, this will no longer be selected."));
337 a=
new TDEAction(i18n(
"Enlarge Font"),
"zoom-in", 0, TQT_TQOBJECT(m_viewInternal), TQT_SLOT(slotIncFontSizes()), ac,
"incFontSizes");
338 a->
setWhatsThis(i18n(
"This increases the display font size."));
340 a=
new TDEAction(i18n(
"Shrink Font"),
"zoom-out", 0, TQT_TQOBJECT(m_viewInternal), TQT_SLOT(slotDecFontSizes()), ac,
"decFontSizes");
341 a->
setWhatsThis(i18n(
"This decreases the display font size."));
344 i18n(
"Bl&ock Selection Mode"), CTRL + SHIFT + Key_B,
345 TQT_TQOBJECT(
this), TQT_SLOT(toggleBlockSelectionMode()),
346 ac,
"set_verticalSelect");
347 a->
setWhatsThis(i18n(
"This command allows switching between the normal (line based) selection mode and the block selection mode."));
350 i18n(
"Overwr&ite Mode"), Key_Insert,
351 TQT_TQOBJECT(
this), TQT_SLOT(toggleInsert()),
353 a->
setWhatsThis(i18n(
"Choose whether you want the text you type to be inserted or to overwrite existing text."));
357 i18n(
"&Dynamic Word Wrap"), Key_F10,
358 TQT_TQOBJECT(
this), TQT_SLOT(toggleDynWordWrap()),
359 ac,
"view_dynamic_word_wrap" );
360 a->
setWhatsThis(i18n(
"If this option is checked, the text lines will be wrapped at the view border on the screen."));
362 a= m_setDynWrapIndicators =
new TDESelectAction(i18n(
"Dynamic Word Wrap Indicators"), 0, ac,
"dynamic_word_wrap_indicators");
363 a->
setWhatsThis(i18n(
"Choose when the Dynamic Word Wrap Indicators should be displayed"));
365 connect(m_setDynWrapIndicators, TQT_SIGNAL(activated(
int)), TQT_TQOBJECT(
this), TQT_SLOT(setDynWrapIndicators(
int)));
367 list2.append(i18n(
"&Off"));
368 list2.append(i18n(
"Follow &Line Numbers"));
369 list2.append(i18n(
"&Always On"));
370 m_setDynWrapIndicators->setItems(list2);
373 i18n(
"Show Folding &Markers"), Key_F9,
374 TQT_TQOBJECT(
this), TQT_SLOT(toggleFoldingMarkers()),
375 ac,
"view_folding_markers" );
376 a->
setWhatsThis(i18n(
"You can choose if the codefolding marks should be shown, if codefolding is possible."));
380 i18n(
"Show &Icon Border"), Key_F6,
381 TQT_TQOBJECT(
this), TQT_SLOT(toggleIconBorder()),
384 a->
setWhatsThis(i18n(
"Show/hide the icon border.<BR><BR> The icon border shows bookmark symbols, for instance."));
388 i18n(
"Show &Line Numbers"), Key_F11,
389 TQT_TQOBJECT(
this), TQT_SLOT(toggleLineNumbersOn()),
390 ac,
"view_line_numbers" );
391 a->
setWhatsThis(i18n(
"Show/hide the line numbers on the left hand side of the view."));
395 i18n(
"Show Scroll&bar Marks"), 0,
396 TQT_TQOBJECT(
this), TQT_SLOT(toggleScrollBarMarks()),
397 ac,
"view_scrollbar_marks");
398 a->
setWhatsThis(i18n(
"Show/hide the marks on the vertical scrollbar.<BR><BR>The marks, for instance, show bookmarks."));
402 i18n(
"Show Static &Word Wrap Marker"), 0,
403 TQT_TQOBJECT(
this), TQT_SLOT( toggleWWMarker() ),
404 ac,
"view_word_wrap_marker" );
406 "Show/hide the Word Wrap Marker, a vertical line drawn at the word "
407 "wrap column as defined in the editing properties" ));
411 i18n(
"Switch to Command Line"), Key_F7,
412 TQT_TQOBJECT(
this), TQT_SLOT(switchToCmdLine()),
413 ac,
"switch_to_cmd_line" );
414 a->
setWhatsThis(i18n(
"Show/hide the command line on the bottom of the view."));
416 a=m_setEndOfLine =
new TDESelectAction(i18n(
"&End of Line"), 0, ac,
"set_eol");
417 a->
setWhatsThis(i18n(
"Choose which line endings should be used, when you save the document"));
419 list.append(
"&UNIX");
420 list.append(
"&Windows/DOS");
421 list.append(
"&Macintosh");
422 m_setEndOfLine->setItems(list);
423 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
424 connect(m_setEndOfLine, TQT_SIGNAL(activated(
int)), TQT_TQOBJECT(
this), TQT_SLOT(setEol(
int)));
427 new KateViewEncodingAction (m_doc,
this, i18n(
"E&ncoding"), TQT_TQOBJECT(ac),
"set_encoding");
429 m_search->createActions( ac );
430 m_spell->createActions( ac );
431 m_bookmarks->createActions( ac );
433 slotSelectionChanged ();
435 connect (
this, TQT_SIGNAL(selectionChanged()), TQT_TQOBJECT(
this), TQT_SLOT(slotSelectionChanged()));
438 void KateView::setupEditActions()
440 m_editActions =
new TDEActionCollection( m_viewInternal, TQT_TQOBJECT(
this),
"edit_actions" );
444 i18n(
"Move Word Left"), CTRL + Key_Left,
445 TQT_TQOBJECT(
this),TQT_SLOT(wordLeft()),
448 i18n(
"Select Character Left"), SHIFT + Key_Left,
449 TQT_TQOBJECT(
this),TQT_SLOT(shiftCursorLeft()),
450 ac,
"select_char_left" );
452 i18n(
"Select Word Left"), SHIFT + CTRL + Key_Left,
453 TQT_TQOBJECT(
this), TQT_SLOT(shiftWordLeft()),
454 ac,
"select_word_left" );
457 i18n(
"Move Word Right"), CTRL + Key_Right,
458 TQT_TQOBJECT(
this), TQT_SLOT(wordRight()),
461 i18n(
"Select Character Right"), SHIFT + Key_Right,
462 TQT_TQOBJECT(
this), TQT_SLOT(shiftCursorRight()),
463 ac,
"select_char_right" );
465 i18n(
"Select Word Right"), SHIFT + CTRL + Key_Right,
466 TQT_TQOBJECT(
this),TQT_SLOT(shiftWordRight()),
467 ac,
"select_word_right" );
470 i18n(
"Move to Beginning of Line"), Key_Home,
471 TQT_TQOBJECT(
this), TQT_SLOT(
home()),
472 ac,
"beginning_of_line" );
475 TQT_TQOBJECT(
this), TQT_SLOT(top()),
476 ac,
"beginning_of_document" );
478 i18n(
"Select to Beginning of Line"), SHIFT + Key_Home,
479 TQT_TQOBJECT(
this), TQT_SLOT(shiftHome()),
480 ac,
"select_beginning_of_line" );
482 i18n(
"Select to Beginning of Document"), SHIFT + CTRL + Key_Home,
483 TQT_TQOBJECT(
this), TQT_SLOT(shiftTop()),
484 ac,
"select_beginning_of_document" );
487 i18n(
"Move to End of Line"), Key_End,
488 TQT_TQOBJECT(
this), TQT_SLOT(
end()),
492 TQT_TQOBJECT(
this), TQT_SLOT(bottom()),
493 ac,
"end_of_document" );
495 i18n(
"Select to End of Line"), SHIFT + Key_End,
496 TQT_TQOBJECT(
this), TQT_SLOT(shiftEnd()),
497 ac,
"select_end_of_line" );
499 i18n(
"Select to End of Document"), SHIFT + CTRL + Key_End,
500 TQT_TQOBJECT(
this), TQT_SLOT(shiftBottom()),
501 ac,
"select_end_of_document" );
504 i18n(
"Select to Previous Line"), SHIFT + Key_Up,
505 TQT_TQOBJECT(
this), TQT_SLOT(shiftUp()),
506 ac,
"select_line_up" );
508 i18n(
"Scroll Line Up"),
"", CTRL + Key_Up,
509 TQT_TQOBJECT(
this), TQT_SLOT(scrollUp()),
510 ac,
"scroll_line_up" );
512 new TDEAction(i18n(
"Move to Next Line"), Key_Down, TQT_TQOBJECT(
this), TQT_SLOT(down()),
513 ac,
"move_line_down");
515 new TDEAction(i18n(
"Move to Previous Line"), Key_Up, TQT_TQOBJECT(
this), TQT_SLOT(
up()),
518 new TDEAction(i18n(
"Move Character Right"), Key_Right, TQT_TQOBJECT(
this),
519 TQT_SLOT(cursorRight()), ac,
"move_cursor_right");
521 new TDEAction(i18n(
"Move Character Left"), Key_Left, TQT_TQOBJECT(
this), TQT_SLOT(cursorLeft()),
522 ac,
"move_cusor_left");
525 i18n(
"Select to Next Line"), SHIFT + Key_Down,
526 TQT_TQOBJECT(
this), TQT_SLOT(shiftDown()),
527 ac,
"select_line_down" );
529 i18n(
"Scroll Line Down"), CTRL + Key_Down,
530 TQT_TQOBJECT(
this), TQT_SLOT(scrollDown()),
531 ac,
"scroll_line_down" );
535 TQT_TQOBJECT(
this), TQT_SLOT(pageUp()),
536 ac,
"scroll_page_up" );
538 i18n(
"Select Page Up"), SHIFT + Key_PageUp,
539 TQT_TQOBJECT(
this), TQT_SLOT(shiftPageUp()),
540 ac,
"select_page_up" );
542 i18n(
"Move to Top of View"), CTRL + Key_PageUp,
543 TQT_TQOBJECT(
this), TQT_SLOT(topOfView()),
544 ac,
"move_top_of_view" );
546 i18n(
"Select to Top of View"), CTRL + SHIFT + Key_PageUp,
547 TQT_TQOBJECT(
this), TQT_SLOT(shiftTopOfView()),
548 ac,
"select_top_of_view" );
552 TQT_TQOBJECT(
this), TQT_SLOT(pageDown()),
553 ac,
"scroll_page_down" );
555 i18n(
"Select Page Down"), SHIFT + Key_PageDown,
556 TQT_TQOBJECT(
this), TQT_SLOT(shiftPageDown()),
557 ac,
"select_page_down" );
559 i18n(
"Move to Bottom of View"), CTRL + Key_PageDown,
560 TQT_TQOBJECT(
this), TQT_SLOT(bottomOfView()),
561 ac,
"move_bottom_of_view" );
563 i18n(
"Select to Bottom of View"), CTRL + SHIFT + Key_PageDown,
564 TQT_TQOBJECT(
this), TQT_SLOT(shiftBottomOfView()),
565 ac,
"select_bottom_of_view" );
567 i18n(
"Move to Matching Bracket"), CTRL + Key_6,
568 TQT_TQOBJECT(
this), TQT_SLOT(toMatchingBracket()),
569 ac,
"to_matching_bracket" );
571 i18n(
"Select to Matching Bracket"), SHIFT + CTRL + Key_6,
572 TQT_TQOBJECT(
this), TQT_SLOT(shiftToMatchingBracket()),
573 ac,
"select_matching_bracket" );
576 if ( !m_doc->readOnly() )
579 i18n(
"Transpose Characters"), CTRL + Key_T,
580 TQT_TQOBJECT(
this), TQT_SLOT(transpose()),
581 ac,
"transpose_char" );
584 i18n(
"Delete Line"), CTRL + Key_K,
585 TQT_TQOBJECT(
this), TQT_SLOT(killLine()),
590 TQT_TQOBJECT(
this), TQT_SLOT(deleteWordLeft()),
591 ac,
"delete_word_left" );
595 TQT_TQOBJECT(
this), TQT_SLOT(deleteWordRight()),
596 ac,
"delete_word_right" );
598 new TDEAction(i18n(
"Delete Next Character"), Key_Delete,
599 TQT_TQOBJECT(
this), TQT_SLOT(keyDelete()),
600 ac,
"delete_next_character");
603 TQT_TQOBJECT(
this), TQT_SLOT(backspace()),
610 connect(
this, TQT_SIGNAL(gotFocus(
Kate::View*)),
611 TQT_TQOBJECT(
this), TQT_SLOT(slotGotFocus()) );
612 connect(
this, TQT_SIGNAL(lostFocus(
Kate::View*)),
613 TQT_TQOBJECT(
this), TQT_SLOT(slotLostFocus()) );
615 m_editActions->readShortcutSettings(
"Katepart Shortcuts" );
625 void KateView::setupCodeFolding()
628 new TDEAction( i18n(
"Collapse Toplevel"), CTRL+SHIFT+Key_Minus,
629 m_doc->foldingTree(),TQT_SLOT(collapseToplevelNodes()),ac,
"folding_toplevel");
630 new TDEAction( i18n(
"Expand Toplevel"), CTRL+SHIFT+Key_Plus,
631 TQT_TQOBJECT(
this),TQT_SLOT(slotExpandToplevel()),ac,
"folding_expandtoplevel");
632 new TDEAction( i18n(
"Collapse One Local Level"), CTRL+Key_Minus,
633 TQT_TQOBJECT(
this),TQT_SLOT(slotCollapseLocal()),ac,
"folding_collapselocal");
634 new TDEAction( i18n(
"Expand One Local Level"), CTRL+Key_Plus,
635 TQT_TQOBJECT(
this),TQT_SLOT(slotExpandLocal()),ac,
"folding_expandlocal");
639 debugAccels->
insert(
"KATE_DUMP_REGION_TREE",i18n(
"Show the code folding region tree"),
"",
"Ctrl+Shift+Alt+D",m_doc,TQT_SLOT(dumpRegionTree()));
640 debugAccels->
insert(
"KATE_TEMPLATE_TEST",i18n(
"Basic template code test"),
"",
"Ctrl+Shift+Alt+T",m_doc,TQT_SLOT(testTemplateCode()));
645 void KateView::slotExpandToplevel()
647 m_doc->foldingTree()->expandToplevelNodes(m_doc->numLines());
650 void KateView::slotCollapseLocal()
652 int realLine = m_doc->foldingTree()->collapseOne(cursorLine());
656 setCursorPositionInternal(realLine, cursorColumn(), tabWidth(),
false);
659 void KateView::slotExpandLocal()
661 m_doc->foldingTree()->expandOne(cursorLine(), m_doc->numLines());
664 void KateView::setupCodeCompletion()
666 m_codeCompletion =
new KateCodeCompletion(
this);
667 connect( m_codeCompletion, TQT_SIGNAL(completionAborted()),
668 TQT_TQOBJECT(
this), TQT_SIGNAL(completionAborted()));
669 connect( m_codeCompletion, TQT_SIGNAL(completionDone()),
670 TQT_TQOBJECT(
this), TQT_SIGNAL(completionDone()));
671 connect( m_codeCompletion, TQT_SIGNAL(argHintHidden()),
672 TQT_TQOBJECT(
this), TQT_SIGNAL(argHintHidden()));
673 connect( m_codeCompletion, TQT_SIGNAL(completionDone(KTextEditor::CompletionEntry)),
674 TQT_TQOBJECT(
this), TQT_SIGNAL(completionDone(KTextEditor::CompletionEntry)));
675 connect( m_codeCompletion, TQT_SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,TQString*)),
676 TQT_TQOBJECT(
this), TQT_SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,TQString*)));
679 void KateView::slotGotFocus()
681 m_editActions->accel()->setEnabled(
true );
686 void KateView::slotLostFocus()
688 m_editActions->accel()->setEnabled(
false );
691 void KateView::setDynWrapIndicators(
int mode)
693 config()->setDynWordWrapIndicators (mode);
696 void KateView::slotStatusMsg ()
699 if (m_doc->isReadWrite())
701 if (m_doc->config()->configFlags() & KateDocument::cfOvr)
702 ovrstr = i18n(
" OVR ");
704 ovrstr = i18n(
" INS ");
707 ovrstr = i18n(
" R/O ");
709 uint r = cursorLine() + 1;
710 uint c = cursorColumn() + 1;
715 TQString modstr = m_doc->isModified() ? TQString (
" * ") : TQString (
" ");
716 TQString blockstr = blockSelectionMode() ? i18n(
" BLK ") : i18n(
" NORM ");
718 emit viewStatusMsg (s1 + s2 +
" " + ovrstr + blockstr + modstr);
721 void KateView::slotSelectionTypeChanged()
723 m_toggleBlockSelection->setChecked( blockSelectionMode() );
728 bool KateView::isOverwriteMode()
const
730 return m_doc->config()->configFlags() & KateDocument::cfOvr;
733 void KateView::reloadFile()
739 void KateView::slotUpdate()
746 void KateView::slotReadWriteChanged ()
748 if ( m_toggleWriteLock )
749 m_toggleWriteLock->setChecked( ! m_doc->isReadWrite() );
751 m_cut->setEnabled (m_doc->isReadWrite());
752 m_paste->setEnabled (m_doc->isReadWrite());
756 l <<
"edit_replace" <<
"set_insert" <<
"tools_spelling" <<
"tools_indent"
757 <<
"tools_unindent" <<
"tools_cleanIndent" <<
"tools_align" <<
"tools_comment"
758 <<
"tools_uncomment" <<
"tools_uppercase" <<
"tools_lowercase"
759 <<
"tools_capitalize" <<
"tools_join_lines" <<
"tools_apply_wordwrap"
760 <<
"edit_undo" <<
"edit_redo" <<
"tools_spelling_from_cursor"
761 <<
"tools_spelling_selection";
764 for (uint z = 0; z < l.size(); z++)
765 if ((a = actionCollection()->
action( l[z].ascii() )))
769 void KateView::slotNewUndo()
771 if (m_doc->readOnly())
774 if ((m_doc->undoCount() > 0) != m_editUndo->isEnabled())
775 m_editUndo->setEnabled(m_doc->undoCount() > 0);
777 if ((m_doc->redoCount() > 0) != m_editRedo->isEnabled())
778 m_editRedo->setEnabled(m_doc->redoCount() > 0);
781 void KateView::slotDropEventPass( TQDropEvent * ev )
791 void KateView::contextMenuEvent( TQContextMenuEvent *ev )
793 if ( !m_doc || !m_doc->browserExtension() )
795 emit m_doc->browserExtension()->popupMenu( ev->globalPos(), m_doc->url(),
796 TQString::fromLatin1(
"text/plain" ) );
800 bool KateView::setCursorPositionInternal( uint line, uint col, uint tabwidth,
bool calledExternally )
807 TQString line_str = m_doc->textLine( line );
811 for (z = 0; z < line_str.length() && z < col; z++) {
812 if (line_str[z] == TQChar(
'\t')) x += tabwidth - (x % tabwidth);
else x++;
815 m_viewInternal->updateCursor(
KateTextCursor( line, x ),
false,
true, calledExternally );
820 void KateView::setOverwriteMode(
bool b )
822 if ( isOverwriteMode() && !b )
823 m_doc->setConfigFlags( m_doc->config()->configFlags() ^ KateDocument::cfOvr );
825 m_doc->setConfigFlags( m_doc->config()->configFlags() | KateDocument::cfOvr );
827 m_toggleInsert->setChecked (isOverwriteMode ());
830 void KateView::toggleInsert()
832 m_doc->setConfigFlags(m_doc->config()->configFlags() ^ KateDocument::cfOvr);
833 m_toggleInsert->setChecked (isOverwriteMode ());
838 bool KateView::canDiscard()
840 return m_doc->closeURL();
850 if( !m_doc->url().isValid() || !doc()->isReadWrite() )
862 KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveURLAndEncoding(doc()->config()->encoding(),
863 m_doc->url().url(),TQString::null,
this,i18n(
"Save File"));
867 if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first() ) )
870 m_doc->config()->setEncoding( res.encoding );
872 if( m_doc->saveAs( res.URLs.first() ) )
878 bool KateView::checkOverwrite(
KURL u )
883 TQFileInfo info( u.
path() );
887 return KMessageBox::Continue
890 i18n(
"A file named \"%1\" already exists. Are you sure you want to overwrite it?" ).arg( info.fileName() ),
891 i18n(
"Overwrite File?" ),
892 KGuiItem( i18n(
"&Overwrite" ),
"document-save", i18n(
"Overwrite the file" ) )
896 void KateView::slotSaveCanceled(
const TQString& error )
898 if ( !error.isEmpty() )
902 void KateView::gotoLine()
904 KateGotoLineDialog *dlg =
new KateGotoLineDialog (
this, m_viewInternal->getCursor().line() + 1, m_doc->numLines());
906 if (dlg->exec() == TQDialog::Accepted)
907 gotoLineNumber( dlg->getLine() - 1 );
912 void KateView::gotoLineNumber(
int line )
915 if ( !config()->persistentSelection() )
917 setCursorPositionInternal ( line, 0, 1 );
920 void KateView::joinLines()
922 int first = selStartLine();
923 int last = selEndLine();
927 first = cursorLine();
930 m_doc->joinLines( first, last );
933 void KateView::readSessionConfig(
TDEConfig *config)
938 void KateView::writeSessionConfig(
TDEConfig *config)
940 config->
writeEntry(
"CursorLine",m_viewInternal->cursor.line());
941 config->
writeEntry(
"CursorColumn",m_viewInternal->cursor.col());
944 int KateView::getEol()
946 return m_doc->config()->eol();
949 void KateView::setEol(
int eol)
951 if (!doc()->isReadWrite())
954 if (m_updatingDocumentConfig)
957 m_doc->config()->setEol (eol);
960 void KateView::setIconBorder(
bool enable )
962 config()->setIconBar (enable);
965 void KateView::toggleIconBorder()
967 config()->setIconBar (!config()->iconBar());
970 void KateView::setLineNumbersOn(
bool enable )
972 config()->setLineNumbers (enable);
975 void KateView::toggleLineNumbersOn()
977 config()->setLineNumbers (!config()->lineNumbers());
980 void KateView::setScrollBarMarks(
bool enable )
982 config()->setScrollBarMarks (enable);
985 void KateView::toggleScrollBarMarks()
987 config()->setScrollBarMarks (!config()->scrollBarMarks());
990 void KateView::toggleDynWordWrap()
992 config()->setDynWordWrap( !config()->dynWordWrap() );
995 void KateView::setDynWordWrap(
bool b )
997 config()->setDynWordWrap( b );
1000 void KateView::toggleWWMarker()
1002 m_renderer->config()->setWordWrapMarker (!m_renderer->config()->wordWrapMarker());
1005 void KateView::setFoldingMarkersOn(
bool enable )
1007 config()->setFoldingBar ( enable );
1010 void KateView::toggleFoldingMarkers()
1012 config()->setFoldingBar ( !config()->foldingBar() );
1015 bool KateView::iconBorder() {
1016 return m_viewInternal->leftBorder->iconBorderOn();
1019 bool KateView::lineNumbersOn() {
1020 return m_viewInternal->leftBorder->lineNumbersOn();
1023 bool KateView::scrollBarMarks() {
1024 return m_viewInternal->m_lineScroll->showMarks();
1027 int KateView::dynWrapIndicators() {
1028 return m_viewInternal->leftBorder->dynWrapIndicators();
1031 bool KateView::foldingMarkersOn() {
1032 return m_viewInternal->leftBorder->foldingMarkersOn();
1035 void KateView::showCmdLine (
bool enabled )
1037 if (enabled == m_cmdLineOn)
1044 m_cmdLine =
new KateCmdLine (
this);
1045 m_grid->addMultiCellWidget (m_cmdLine, 2, 2, 0, 2);
1049 m_cmdLine->setFocus();
1056 m_cmdLineOn = enabled;
1059 void KateView::toggleCmdLine ()
1061 m_config->setCmdLine (!m_config->cmdLine ());
1064 void KateView::toggleWriteLock()
1066 m_doc->setReadWrite( ! m_doc->isReadWrite() );
1069 void KateView::enableTextHints(
int timeout)
1071 m_viewInternal->enableTextHints(timeout);
1074 void KateView::disableTextHints()
1076 m_viewInternal->disableTextHints();
1079 void KateView::applyWordWrap ()
1082 m_doc->wrapText (selectStart.line(), selectEnd.line());
1084 m_doc->wrapText (0, m_doc->lastLine());
1087 void KateView::slotNeedTextHint(
int line,
int col, TQString &text)
1089 text=TQString(
"test %1 %2").arg(line).arg(col);
1092 void KateView::find()
1097 void KateView::find(
const TQString& pattern,
long flags,
bool add )
1099 m_search->find( pattern, flags, add );
1102 void KateView::replace()
1104 m_search->replace();
1107 void KateView::replace(
const TQString &pattern,
const TQString &replacement,
long flags )
1109 m_search->replace( pattern, replacement, flags );
1112 void KateView::findAgain(
bool back )
1114 m_search->findAgain( back );
1117 void KateView::slotSelectionChanged ()
1119 m_copy->setEnabled (hasSelection());
1120 m_copyHTML->setEnabled (hasSelection());
1121 m_deSelect->setEnabled (hasSelection());
1123 if (m_doc->readOnly())
1126 m_cut->setEnabled (hasSelection());
1128 m_spell->updateActions ();
1131 void KateView::switchToCmdLine ()
1134 m_config->setCmdLine (
true);
1136 if (m_cmdLine->hasFocus()) {
1141 m_cmdLine->setFocus ();
1144 void KateView::showArgHint( TQStringList arg1,
const TQString& arg2,
const TQString& arg3 )
1146 m_codeCompletion->showArgHint( arg1, arg2, arg3 );
1149 void KateView::showCompletionBox( TQValueList<KTextEditor::CompletionEntry> arg1,
int offset,
bool cs )
1151 emit aboutToShowCompletionBox();
1152 m_codeCompletion->showCompletionBox( arg1, offset, cs );
1160 void KateView::updateConfig ()
1165 m_editActions->readShortcutSettings(
"Katepart Shortcuts" );
1168 if (m_hasWrap != config()->dynWordWrap()) {
1169 m_viewInternal->prepareForDynWrapChange();
1171 m_hasWrap = config()->dynWordWrap();
1173 m_viewInternal->dynWrapChanged();
1175 m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
1176 m_toggleDynWrap->setChecked( config()->dynWordWrap() );
1179 m_viewInternal->leftBorder->setDynWrapIndicators( config()->dynWordWrapIndicators() );
1180 m_setDynWrapIndicators->setCurrentItem( config()->dynWordWrapIndicators() );
1183 m_viewInternal->leftBorder->setLineNumbersOn( config()->lineNumbers() );
1184 m_toggleLineNumbers->setChecked( config()->lineNumbers() );
1187 m_viewInternal->leftBorder->setIconBorderOn( config()->iconBar() );
1188 m_toggleIconBar->setChecked( config()->iconBar() );
1191 m_viewInternal->m_lineScroll->setShowMarks( config()->scrollBarMarks() );
1192 m_toggleScrollBarMarks->setChecked( config()->scrollBarMarks() );
1195 showCmdLine (config()->cmdLine());
1199 m_toggleBlockSelection->setChecked( blockSelectionMode() );
1200 m_toggleInsert->setChecked( isOverwriteMode() );
1202 updateFoldingConfig ();
1205 m_bookmarks->setSorting( (KateBookmarks::Sorting) config()->bookmarkSort() );
1207 m_viewInternal->setAutoCenterLines(config()->autoCenterLines ());
1210 void KateView::updateDocumentConfig()
1215 m_updatingDocumentConfig =
true;
1217 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
1219 m_updatingDocumentConfig =
false;
1221 m_viewInternal->updateView (
true);
1223 m_renderer->setTabWidth (m_doc->config()->tabWidth());
1224 m_renderer->setIndentWidth (m_doc->config()->indentationWidth());
1227 void KateView::updateRendererConfig()
1232 m_toggleWWMarker->setChecked( m_renderer->config()->wordWrapMarker() );
1235 m_viewInternal->updateView (
true);
1236 m_viewInternal->repaint ();
1239 m_viewInternal->leftBorder->updateFont();
1240 m_viewInternal->leftBorder->repaint ();
1246 void KateView::updateFoldingConfig ()
1249 bool doit = config()->foldingBar() && m_doc->highlight() && m_doc->highlight()->allowsFolding();
1250 m_viewInternal->leftBorder->setFoldingMarkersOn(doit);
1251 m_toggleFoldingMarkers->setChecked( doit );
1252 m_toggleFoldingMarkers->setEnabled( m_doc->highlight() && m_doc->highlight()->allowsFolding() );
1256 l <<
"folding_toplevel" <<
"folding_expandtoplevel"
1257 <<
"folding_collapselocal" <<
"folding_expandlocal";
1260 for (uint z = 0; z < l.size(); z++)
1261 if ((a = actionCollection()->
action( l[z].ascii() )))
1262 a->
setEnabled (m_doc->highlight() && m_doc->highlight()->allowsFolding());
1266 void KateView::editStart ()
1268 m_viewInternal->editStart ();
1271 void KateView::editEnd (
int editTagLineStart,
int editTagLineEnd,
bool tagFrom)
1273 m_viewInternal->editEnd (editTagLineStart, editTagLineEnd, tagFrom);
1278 m_viewInternal->editSetCursor (cursor);
1285 return m_viewInternal->tagLine (virtualCursor);
1288 bool KateView::tagLines (
int start,
int end,
bool realLines)
1290 return m_viewInternal->tagLines (start, end, realLines);
1295 return m_viewInternal->tagLines (start, end, realCursors);
1298 void KateView::tagAll ()
1300 m_viewInternal->tagAll ();
1303 void KateView::clear ()
1305 m_viewInternal->clear ();
1308 void KateView::repaintText (
bool paintOnlyDirty)
1310 m_viewInternal->paintText(0,0,m_viewInternal->width(),m_viewInternal->height(), paintOnlyDirty);
1313 void KateView::updateView (
bool changed)
1315 m_viewInternal->updateView (changed);
1316 m_viewInternal->leftBorder->update();
1321 void KateView::slotHlChanged()
1323 KateHighlighting *hl = m_doc->highlight();
1324 bool ok ( !hl->getCommentStart(0).isEmpty() || !hl->getCommentSingleLineStart(0).isEmpty() );
1326 if (actionCollection()->
action(
"tools_comment"))
1327 actionCollection()->action(
"tools_comment")->setEnabled( ok );
1329 if (actionCollection()->
action(
"tools_uncomment"))
1330 actionCollection()->action(
"tools_uncomment")->setEnabled( ok );
1333 updateFoldingConfig ();
1336 uint KateView::cursorColumn()
1338 uint r = m_doc->currentColumn(m_viewInternal->getCursor());
1339 if ( !( m_doc->config()->configFlags() & KateDocumentConfig::cfWrapCursor ) &&
1340 (uint)m_viewInternal->getCursor().col() > m_doc->textLine( m_viewInternal->getCursor().line() ).length() )
1341 r += m_viewInternal->getCursor().col() - m_doc->textLine( m_viewInternal->getCursor().line() ).length();
1354 selectStart.setPos(start);
1355 selectEnd.setPos(end);
1357 selectStart.setPos(end);
1358 selectEnd.setPos(start);
1361 tagSelection(oldSelectStart, oldSelectEnd);
1365 emit selectionChanged ();
1366 emit m_doc->selectionChanged ();
1371 bool KateView::setSelection( uint startLine, uint startCol, uint endLine, uint endCol )
1374 clearSelection(
false,
false);
1379 void KateView::syncSelectionCache()
1381 m_viewInternal->selStartCached = selectStart;
1382 m_viewInternal->selEndCached = selectEnd;
1383 m_viewInternal->selectAnchor = selectEnd;
1386 bool KateView::clearSelection()
1388 return clearSelection(
true);
1391 bool KateView::clearSelection(
bool redraw,
bool finishedChangingSelection)
1393 if( !hasSelection() )
1399 selectStart.setPos(-1, -1);
1400 selectEnd.setPos(-1, -1);
1402 tagSelection(oldSelectStart, oldSelectEnd);
1404 oldSelectStart = selectStart;
1405 oldSelectEnd = selectEnd;
1410 if (finishedChangingSelection)
1412 emit selectionChanged();
1413 emit m_doc->selectionChanged ();
1419 bool KateView::hasSelection()
const
1421 return selectStart != selectEnd;
1424 TQString KateView::selection()
const
1426 int sc = selectStart.col();
1427 int ec = selectEnd.col();
1438 return m_doc->text (selectStart.line(), sc, selectEnd.line(), ec, blockSelect);
1441 bool KateView::removeSelectedText ()
1443 if (!hasSelection())
1446 m_doc->editStart ();
1448 int sc = selectStart.col();
1449 int ec = selectEnd.col();
1461 m_doc->removeText (selectStart.line(), sc, selectEnd.line(), ec, blockSelect);
1464 clearSelection(
false);
1471 bool KateView::selectAll()
1473 setBlockSelectionMode (
false);
1475 return setSelection (0, 0, m_doc->lastLine(), m_doc->lineLength(m_doc->lastLine()));
1478 bool KateView::lineColSelected (
int line,
int col)
1480 if ( (!blockSelect) && (col < 0) )
1486 return cursor.line() >= selectStart.line() && cursor.line() <= selectEnd.line() && cursor.col() >= selectStart.col() && cursor.col() < selectEnd.col();
1488 return (cursor >= selectStart) && (cursor < selectEnd);
1491 bool KateView::lineSelected (
int line)
1493 return (!blockSelect)
1495 && (line < selectEnd.line());
1498 bool KateView::lineEndSelected (
int line,
int endCol)
1500 return (!blockSelect)
1501 && (line > selectStart.line() || (line == selectStart.line() && (selectStart.col() < endCol || endCol == -1)))
1502 && (line < selectEnd.line() || (line == selectEnd.line() && (endCol <= selectEnd.col() && endCol != -1)));
1505 bool KateView::lineHasSelected (
int line)
1507 return (selectStart < selectEnd)
1508 && (line >= selectStart.line())
1509 && (line <= selectEnd.line());
1512 bool KateView::lineIsSelection (
int line)
1514 return (line == selectStart.line() && line == selectEnd.line());
1519 if (hasSelection()) {
1520 if (oldSelectStart.line() == -1) {
1524 tagLines(selectStart, selectEnd,
true);
1526 }
else if (blockSelectionMode() && (oldSelectStart.col() != selectStart.col() || oldSelectEnd.col() != selectEnd.col())) {
1528 tagLines(selectStart, selectEnd,
true);
1529 tagLines(oldSelectStart, oldSelectEnd,
true);
1532 if (oldSelectStart != selectStart) {
1533 if (oldSelectStart < selectStart)
1534 tagLines(oldSelectStart, selectStart,
true);
1536 tagLines(selectStart, oldSelectStart,
true);
1539 if (oldSelectEnd != selectEnd) {
1540 if (oldSelectEnd < selectEnd)
1541 tagLines(oldSelectEnd, selectEnd,
true);
1543 tagLines(selectEnd, oldSelectEnd,
true);
1549 tagLines(oldSelectStart, oldSelectEnd,
true);
1555 int start,
end, len;
1562 len = textLine->length();
1563 start =
end = cursor.col();
1564 while (start > 0 && m_doc->highlight()->isInWord(textLine->getChar(start - 1), textLine->attribute(start - 1))) start--;
1565 while (end < len && m_doc->highlight()->isInWord(textLine->getChar(end), textLine->attribute(start - 1)))
end++;
1566 if (end <= start)
return;
1568 setSelection (cursor.line(), start, cursor.line(), end);
1573 if (cursor.line()+1 >= m_doc->numLines())
1574 setSelection (cursor.line(), 0, cursor.line(), m_doc->lineLength(cursor.line()));
1576 setSelection (cursor.line(), 0, cursor.line()+1, 0);
1579 void KateView::selectLength(
const KateTextCursor& cursor,
int length )
1588 start = cursor.col();
1589 end = start + length;
1590 if (end <= start)
return;
1592 setSelection (cursor.line(), start, cursor.line(), end);
1595 void KateView::paste()
1597 m_doc->paste(
this );
1598 emit selectionChanged();
1599 m_viewInternal->repaint();
1602 void KateView::cut()
1604 if (!hasSelection())
1608 removeSelectedText();
1611 void KateView::copy()
const
1613 if (!hasSelection())
1616 TQApplication::clipboard()->setText(selection ());
1619 void KateView::copyHTML()
1621 if (!hasSelection())
1626 TQTextDrag *htmltextdrag =
new TQTextDrag(selectionAsHtml()) ;
1627 htmltextdrag->setSubtype(
"html");
1632 TQApplication::clipboard()->setData(drag);
1635 TQString KateView::selectionAsHtml()
1637 int sc = selectStart.col();
1638 int ec = selectEnd.col();
1650 return textAsHtml (selectStart.line(), sc, selectEnd.line(), ec, blockSelect);
1653 TQString KateView::textAsHtml ( uint startLine, uint startCol, uint endLine, uint endCol,
bool blockwise)
1656 if ( blockwise && (startCol > endCol) )
1660 TQTextStream ts( &s, IO_WriteOnly );
1661 ts.setEncoding(TQTextStream::UnicodeUTF8);
1662 ts <<
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" <<
endl;
1663 ts <<
"<html xmlns=\"http://www.w3.org/1999/xhtml\">" <<
endl;
1664 ts <<
"<head>" <<
endl;
1665 ts <<
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" <<
endl;
1666 ts <<
"<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" <<
endl;
1667 ts <<
"</head>" <<
endl;
1669 ts <<
"<body>" <<
endl;
1670 textAsHtmlStream(startLine, startCol, endLine, endCol, blockwise, &ts);
1672 ts <<
"</body>" <<
endl;
1673 ts <<
"</html>" <<
endl;
1678 void KateView::textAsHtmlStream ( uint startLine, uint startCol, uint endLine, uint endCol,
bool blockwise, TQTextStream *ts)
1680 if ( (blockwise || startLine == endLine) && (startCol > endCol) )
1683 if (startLine == endLine)
1689 (*ts) <<
"<pre>" <<
endl;
1691 lineAsHTML(textLine, startCol, endCol-startCol, ts);
1695 (*ts) <<
"<pre>" <<
endl;
1697 for (uint i = startLine; (i <= endLine) && (i < m_doc->numLines()); i++)
1704 lineAsHTML(textLine, startCol, textLine->length()-startCol, ts);
1705 else if (i == endLine)
1706 lineAsHTML(textLine, 0, endCol, ts);
1708 lineAsHTML(textLine, 0, textLine->length(), ts);
1712 lineAsHTML( textLine, startCol, endCol-startCol, ts);
1724 void KateView::lineAsHTML (
KateTextLine::Ptr line, uint startCol, uint length, TQTextStream *outputStream)
1730 TQMap<uchar,TQString> stylecache;
1736 for (uint curPos=startCol;curPos<(length+startCol);curPos++)
1738 if ( curPos == 0 || line->attribute( curPos ) != line->attribute( curPos - 1 ) &&
1743 (*outputStream) << textcache;
1744 textcache.truncate(0);
1746 if ( curPos > startCol )
1747 (*outputStream) <<
"</span>";
1749 charAttributes = m_renderer->attribute(line->attribute(curPos));
1751 if ( ! stylecache.contains( line->attribute(curPos) ) )
1753 TQString textdecoration;
1756 if ( charAttributes->bold() )
1757 style.append(
"font-weight: bold;");
1758 if ( charAttributes->italic() )
1759 style.append(
"font-style: italic;");
1760 if ( charAttributes->underline() )
1761 textdecoration =
"underline";
1762 if ( charAttributes->overline() )
1763 textdecoration.append(
" overline" );
1764 if ( charAttributes->strikeOut() )
1765 textdecoration.append(
" line-trough" );
1766 if ( !textdecoration.isEmpty() )
1767 style.append(
"text-decoration: %1;").arg(textdecoration);
1770 if ( charAttributes->itemSet(KateAttribute::BGColor) )
1771 style.append(TQString(
"background-color: %1;").arg(charAttributes->bgColor().name()));
1772 if ( charAttributes->itemSet(KateAttribute::TextColor) )
1773 style.append(TQString(
"color: %1;").arg(charAttributes->textColor().name()));
1775 stylecache[line->attribute(curPos)] = style;
1777 (*outputStream)<<
"<span style=\""
1778 << stylecache[line->attribute(curPos)]
1782 TQString s( line->getChar(curPos) );
1783 if ( s ==
"&" ) s =
"&";
1784 else if ( s ==
"<" ) s =
"<";
1785 else if ( s ==
">" ) s =
">";
1786 textcache.append( s );
1789 (*outputStream) << textcache <<
"</span>";
1792 void KateView::exportAsHTML ()
1794 KURL url = KFileDialog::getSaveURL(m_doc->docName(),
"text/html",0,i18n(
"Export File as HTML"));
1803 filename = url.
path();
1805 filename = tmp.
name();
1810 TQTextStream *outputStream = savefile->
textStream();
1812 outputStream->setEncoding(TQTextStream::UnicodeUTF8);
1815 (*outputStream) <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" <<
endl;
1816 (*outputStream) <<
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" <<
endl;
1817 (*outputStream) <<
"<html xmlns=\"http://www.w3.org/1999/xhtml\">" <<
endl;
1818 (*outputStream) <<
"<head>" <<
endl;
1819 (*outputStream) <<
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" <<
endl;
1820 (*outputStream) <<
"<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" <<
endl;
1822 (*outputStream) <<
"<title>" << m_doc->docName () <<
"</title>" <<
endl;
1823 (*outputStream) <<
"</head>" <<
endl;
1824 (*outputStream) <<
"<body>" <<
endl;
1826 textAsHtmlStream(0,0, m_doc->lastLine(), m_doc->lineLength(m_doc->lastLine()),
false, outputStream);
1828 (*outputStream) <<
"</body>" <<
endl;
1829 (*outputStream) <<
"</html>" <<
endl;
1842 TDEIO::NetAccess::upload( filename, url, 0 );
1848 bool KateView::blockSelectionMode ()
1853 bool KateView::setBlockSelectionMode (
bool on)
1855 if (on != blockSelect)
1862 clearSelection(
false,
false);
1864 setSelection(oldSelectStart, oldSelectEnd);
1866 slotSelectionTypeChanged();
1872 bool KateView::toggleBlockSelectionMode ()
1874 m_toggleBlockSelection->setChecked (!blockSelect);
1875 return setBlockSelectionMode (!blockSelect);
1878 bool KateView::wrapCursor ()
1880 return !blockSelectionMode() && (m_doc->configFlags() & KateDocument::cfWrapCursor);
1886 void KateView::setIMSelectionValue( uint imStartLine, uint imStart, uint imEnd,
1887 uint imSelStart, uint imSelEnd,
bool imComposeEvent )
1889 m_imStartLine = imStartLine;
1890 m_imStart = imStart;
1892 m_imSelStart = imSelStart;
1893 m_imSelEnd = imSelEnd;
1894 m_imComposeEvent = imComposeEvent;
1897 bool KateView::isIMSelection(
int _line,
int _column )
1899 return ( (
int( m_imStartLine ) == _line ) && ( m_imSelStart < m_imSelEnd ) && ( _column >=
int( m_imSelStart ) ) &&
1900 ( _column <
int( m_imSelEnd ) ) );
1903 bool KateView::isIMEdit(
int _line,
int _column )
1905 return ( (
int( m_imStartLine ) == _line ) && ( m_imStart < m_imEnd ) && ( _column >=
int( m_imStart ) ) &&
1906 ( _column <
int( m_imEnd ) ) );
1909 void KateView::getIMSelectionValue( uint *imStartLine, uint *imStart, uint *imEnd,
1910 uint *imSelStart, uint *imSelEnd )
1912 *imStartLine = m_imStartLine;
1913 *imStart = m_imStart;
1915 *imSelStart = m_imSelStart;
1916 *imSelEnd = m_imSelEnd;
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
static int warningContinueCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonContinue=KStdGuiItem::cont(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
void addDragObject(TQDragObject *dragObject)
static BrowserExtension * childObject(TQObject *obj)
void openURLRequest(const KURL &url, const KParts::URLArgs &args=KParts::URLArgs())
TQTextStream * textStream()
static bool decode(const TQMimeSource *e, KURL::List &urls)
The Attribute class incorporates all text decorations supported by Kate.
Handles all of the work of rendering the text (used for the views and printing)
Simple cursor class with no document pointer.
This action provides a list of available indenters and gets plugged into the KateView's TDEActionColl...
The Kate::View text editor interface.
saveResult
Return values for "save" related commands.
void setEnabled(bool bEnabled)
TDEAccelAction * insert(const TQString &sAction, const TQString &sLabel, const TQString &sWhatsThis, const TDEShortcut &cutDef, const TQObject *pObjSlot, const char *psMethodSlot, bool bConfigurable=true, bool bEnabled=true)
virtual bool setShortcut(const TDEShortcut &)
virtual void setWhatsThis(const TQString &text)
virtual void setEnabled(bool enable)
virtual const TDEShortcut & shortcut() const
int readNumEntry(const TQString &pKey, int nDefault=0) const
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
static TDELocale * locale()
bool append(const KKeySequence &keySeq)
void setCheckedState(const KGuiItem &checkedItem)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
kndbgstream & flush(kndbgstream &s)
TDEAction * selectAll(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * deselect(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * save(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * gotoLine(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * undo(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * redo(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * cut(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * pasteText(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * saveAs(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * copy(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * print(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
Kate namespace All classes in this namespace must stay BC during one major release series (e....
const TDEShortcut & copy()
const TDEShortcut & next()
const TDEShortcut & paste()
const TDEShortcut & prior()
TQString name(StdAccel id)
const TDEShortcut & cut()
const TDEShortcut & end()
const TDEShortcut & redo()
const TDEShortcut & deleteWordBack()
const TDEShortcut & save()
const TDEShortcut & undo()
const TDEShortcut & home()
const TDEShortcut & print()
TQString action(StdAccel id)
const TDEShortcut & gotoLine()
const TDEShortcut & deleteWordForward()
const TDEShortcut & reload()
const TDEShortcut & selectAll()