1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 #include "newscriptwizard.h"
19 #include "newscriptwizard.moc"
21 #include "script_mode.h"
26 //#include <kactionclasses.h>
27 //#include <kactioncollection.h>
28 // make it still work on old kde 3.1...
31 #include <kapplication.h>
32 #include <kglobalsettings.h>
33 #include <kpopupmenu.h>
34 #include <ktextedit.h>
35 #include <ktexteditor/clipboardinterface.h>
36 #include <ktexteditor/dynwordwrapinterface.h>
37 #include <ktexteditor/editinterface.h>
38 #include <ktexteditor/editorchooser.h>
39 #include <ktexteditor/popupmenuinterface.h>
40 #include <ktexteditor/undointerface.h>
41 #include <ktexteditor/view.h>
45 NewScriptWizard::~NewScriptWizard()
53 //restoring the state of the dynamic word wrap
54 dynamic_cast<KTextEditor::DynWordWrapInterface
*>( editor
)->setDynWordWrap( prevDynWordWrap
);
55 delete editor
->document();
59 NewScriptWizard::NewScriptWizard( QWidget
* parent
, ScriptMode
* mode
)
60 : NewScriptWizardBase( parent
, "New Script Wizard" ),
63 document
= KTextEditor::EditorChooser::createDocument( 0, "KTextEditor::Document" );
66 gridLayout
->expand( 2, 1 );
70 // there is no KDE textditor component installed, so we'll use a
72 textedit
= new KTextEdit( mpcode
, "textedit" );
73 textedit
->setFont( KGlobalSettings::fixedFont() );
74 gridLayout
->addWidget( textedit
, 1, 0 );
78 // creating the 'view', hat is what the user see and interact with
79 editor
= document
->createView( mpcode
, "editor" );
80 gridLayout
->addWidget( editor
, 1, 0 );
82 // casting to the interfaces we'll use often
83 hli
= dynamic_cast<KTextEditor::HighlightingInterface
*>( document
);
85 // displaying the left border with line numbers
86 KToggleAction
*a
= dynamic_cast<KToggleAction
*>( editor
->actionCollection()->action("view_line_numbers") );
89 // saving the state of dynamic word wrap and disabling it
90 prevDynWordWrap
= dynamic_cast<KTextEditor::DynWordWrapInterface
*>( editor
)->dynWordWrap();
91 dynamic_cast<KTextEditor::DynWordWrapInterface
*>( editor
)->setDynWordWrap( false );
93 // saving the "no highlight" id
94 noHlStyle
= hli
->hlMode();
96 // creating the popup menu
97 KPopupMenu
* pm
= new KPopupMenu( editor
);
98 // creating the actions for the code editor...
99 KActionCollection
* ac
= new KActionCollection( editor
);
100 KAction
* undoAction
= KStdAction::undo( this, SLOT( slotUndo() ), ac
);
101 KAction
* redoAction
= KStdAction::redo( this, SLOT( slotRedo() ), ac
);
102 KAction
* cutAction
= KStdAction::cut( this, SLOT( slotCut() ), ac
);
103 KAction
* copyAction
= KStdAction::copy( this, SLOT( slotCopy() ), ac
);
104 KAction
* pasteAction
= KStdAction::paste( this, SLOT( slotPaste() ), ac
);
105 // ... and plugging them into the popup menu (to build it, of course :) )
106 undoAction
->plug( pm
);
107 redoAction
->plug( pm
);
108 pm
->insertSeparator();
109 cutAction
->plug( pm
);
110 copyAction
->plug( pm
);
111 pasteAction
->plug( pm
);
113 // finally, we install the popup menu
114 dynamic_cast<KTextEditor::PopupMenuInterface
*>( editor
)->installPopup( pm
);
117 connect( this, SIGNAL( helpClicked() ), this, SLOT( slotHelpClicked() ) );
120 void NewScriptWizard::back()
122 if ( currentPage() == mpcode
)
124 // currentPage() is not yet updated, so we're now entering the
126 mmode
->argsPageEntered();
128 else assert( false );
129 NewScriptWizardBase::back();
132 void NewScriptWizard::next()
134 if ( currentPage() == mpargs
)
135 mmode
->codePageEntered();
136 else assert( false );
139 textedit
->setFocus();
145 NewScriptWizardBase::next();
148 void NewScriptWizard::reject()
150 if ( mmode
->queryCancel() )
151 NewScriptWizardBase::reject();
154 void NewScriptWizard::accept()
156 if ( mmode
->queryFinish() )
157 NewScriptWizardBase::accept();
160 void NewScriptWizard::slotHelpClicked()
162 kapp
->invokeHelp( QString::fromLatin1( "scripting" ),
163 QString::fromLatin1( "kig" ) );
166 void NewScriptWizard::setText( const QString
& text
)
170 textedit
->setText( text
);
174 dynamic_cast<KTextEditor::EditInterface
*>( document
)->setText( text
);
178 QString
NewScriptWizard::text()
182 return textedit
->text();
186 return dynamic_cast<KTextEditor::EditInterface
*>( document
)->text();
190 void NewScriptWizard::setType( ScriptType::Type type
)
192 labelFillCode
->setText( ScriptType::fillCodeStatement( type
) );
196 if ( type
!= ScriptType::Unknown
)
198 for ( uint i
= 0; i
< hli
->hlModeCount(); ++i
)
200 if ( hli
->hlModeName( i
) == ScriptType::highlightStyle( type
) )
202 // we found our highlight style, setting it
210 hli
->setHlMode( noHlStyle
);
215 void NewScriptWizard::slotUndo()
217 dynamic_cast<KTextEditor::UndoInterface
*>( document
)->undo();
220 void NewScriptWizard::slotRedo() {
221 dynamic_cast<KTextEditor::UndoInterface
*>( document
)->redo();
224 void NewScriptWizard::slotCut() {
225 dynamic_cast<KTextEditor::ClipboardInterface
*>( editor
)->cut();
228 void NewScriptWizard::slotCopy() {
229 dynamic_cast<KTextEditor::ClipboardInterface
*>( editor
)->copy();
232 void NewScriptWizard::slotPaste() {
233 dynamic_cast<KTextEditor::ClipboardInterface
*>( editor
)->paste();