[rkward-cvs] rkward/rkward/windows rkcommandeditorwindow.cpp,1.7,1.8 rkcommandeditorwindow.h,1.4,1.5
Pierre
ecoch at users.sourceforge.net
Tue Nov 2 18:51:29 UTC 2004
Update of /cvsroot/rkward/rkward/rkward/windows
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4672/windows
Modified Files:
rkcommandeditorwindow.cpp rkcommandeditorwindow.h
Log Message:
Integration of the command editor in the main window. There are still bugs, but main functionalities are there.
Index: rkcommandeditorwindow.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/windows/rkcommandeditorwindow.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** rkcommandeditorwindow.cpp 27 Oct 2004 08:58:16 -0000 1.7
--- rkcommandeditorwindow.cpp 2 Nov 2004 18:51:27 -0000 1.8
***************
*** 19,22 ****
--- 19,23 ----
#include <kate/document.h>
#include <kate/view.h>
+ #include <kparts/partmanager.h>
#include <ktexteditor/configinterface.h>
***************
*** 32,35 ****
--- 33,37 ----
#include <qpopupmenu.h>
#include <qapplication.h>
+ #include <qtabwidget.h>
#include <klocale.h>
***************
*** 46,125 ****
#include "../rkeditormanager.h"
#include "../rkglobals.h"
#include "../debug.h"
! RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent) : KParts::MainWindow (parent) {
RK_TRACE (COMMANDEDITOR);
- connect (qApp, SIGNAL (aboutToQuit ()), this, SLOT (close ()));
-
- if ( !(m_doc = KTextEditor::EditorChooser::createDocument(0,"KTextEditor::Document")) ){
- KMessageBox::error(this, i18n("A KDE text-editor component could not be found;\nplease check your KDE installation."));
- delete this;
- }
-
- m_view = m_doc->createView (this, 0L);
-
- setCentralWidget(m_view);
- setAcceptDrops(true);
-
- setXMLFile( "rkcommandeditorwindowui.rc" );
- KAction * file_new = KStdAction::openNew (this, SLOT (newFile ()), actionCollection(), "file_new");
- file_new->setWhatsThis(i18n("Use this command to create a new document"));
- KAction * file_open = KStdAction::open (this, SLOT (openFile ()), actionCollection(), "file_open");
- file_open->setWhatsThis(i18n("Use this command to open an existing document for editing"));
! KAction * close_window = KStdAction::close (this, SLOT (close ()), actionCollection(), "file_close");
! close_window->setWhatsThis(i18n("Use this to close the current document"));
!
! KAction * run_all = new KAction (i18n ("Run all"), KShortcut ("Ctrl+R"), this, SLOT (run ()), actionCollection(), "run_all" );
! run_all->setWhatsThis(i18n("Use this to run the current document"));
! KAction * run_selection = new KAction (i18n ("Run selection"), KShortcut ("Ctrl+E"), this, SLOT (runSelection ()), actionCollection(), "run_selection" );
! run_selection->setWhatsThis(i18n("Use this to run the current selection"));
! /*KAction * interrupt = new KAction (i18n ("Interrupt command"), KShortcut ("Ctrl+I"), this, SLOT (interruptCommand ()), actionCollection(), "interrupt" );
! interrupt->setWhatsThis(i18n("Use this to interrupt the current command"));*/
- KLibFactory *factory = KLibLoader::self()->factory( "libkatepart" );
- createShellGUI( true );
- guiFactory()->addClient( m_view );
-
- setRHighlighting ();
- m_doc->setModified (false);
-
-
- setCaption (caption = i18n ("Command editor"));
- resize (minimumSizeHint ().expandedTo (QSize (640, 480)));
-
-
- show ();
}
RKCommandEditorWindow::~RKCommandEditorWindow () {
RK_TRACE (COMMANDEDITOR);
! delete m_view;
! delete m_doc;
! }
!
! void RKCommandEditorWindow::closeEvent (QCloseEvent *e) {
! RK_TRACE (COMMANDEDITOR);
! // TODO: call quit in order to try to save changes
! if (m_doc->closeURL ()) {
! e->accept ();
! delete this;
! }
}
!
! void RKCommandEditorWindow::setRHighlighting () {
// set syntax-highlighting for R
! int modes_count = highlightingInterface(m_doc)->hlModeCount ();
bool found_mode = false;
int i;
RK_DO (qDebug ("%s", "Looking for syntax highlighting definition"), COMMANDEDITOR, DL_INFO);
for (i = 0; i < modes_count; ++i) {
! RK_DO (qDebug ("%s", highlightingInterface(m_doc)->hlModeName(i).lower().latin1 ()), COMMANDEDITOR, DL_DEBUG);
! if (highlightingInterface(m_doc)->hlModeName(i).lower() == "r script") {
found_mode = true;
break;
--- 48,88 ----
#include "../rkeditormanager.h"
#include "../rkglobals.h"
+ #include "../rkward.h"
#include "../debug.h"
! RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent) : KMdiChildView (parent) {
RK_TRACE (COMMANDEDITOR);
! m_library = KLibLoader::self()->library("libkatepart");
! m_doc = (Kate::Document *) m_library->factory ()->create (0L,"kate","KTextEditor::Document");
! m_view = (Kate::View *)m_doc->createView(this);
! m_view->setName("Kate Part View");
! setRHighlighting(m_doc);
! pLayout = new QHBoxLayout( this, 0, -1, "layout");
! pLayout->addWidget(m_view);
!
! connect (this, SIGNAL (gotFocus (KMdiChildView *)), this, SLOT (slotGotFocus ()));
! connect (this, SIGNAL (lostFocus (KMdiChildView *)), this, SLOT (slotLostFocus ()));
}
RKCommandEditorWindow::~RKCommandEditorWindow () {
RK_TRACE (COMMANDEDITOR);
! delete pLayout;
}
! void RKCommandEditorWindow::setRHighlighting (Kate::Document *doc) {
// set syntax-highlighting for R
! int modes_count = highlightingInterface(doc)->hlModeCount ();
bool found_mode = false;
int i;
RK_DO (qDebug ("%s", "Looking for syntax highlighting definition"), COMMANDEDITOR, DL_INFO);
for (i = 0; i < modes_count; ++i) {
! RK_DO (qDebug ("%s", highlightingInterface(doc)->hlModeName(i).lower().latin1 ()), COMMANDEDITOR, DL_DEBUG);
! if (highlightingInterface(doc)->hlModeName(i).lower() == "r script") {
found_mode = true;
break;
***************
*** 127,202 ****
}
if (found_mode) {
! highlightingInterface(m_doc)->setHlMode(i);
} else {
! RK_DO (qDebug ("%s", highlightingInterface(m_doc)->hlModeName(i).lower().latin1 ()), COMMANDEDITOR, DL_WARNING);
}
}
! // GUI slots below
! void RKCommandEditorWindow::newWindow () {
! RK_TRACE (COMMANDEDITOR);
! new RKCommandEditorWindow (0);
}
! void RKCommandEditorWindow::closeWindow () {
! RK_TRACE (COMMANDEDITOR);
! if (m_doc->closeURL ()) delete this;
}
! void RKCommandEditorWindow::run () {
! RK_TRACE (COMMANDEDITOR);
! if ( ! editInterface(m_doc)->text().isEmpty() ) {
! RKGlobals::rInterface ()->issueCommand (new RCommand (editInterface(m_doc)->text(), RCommand::User, ""));
}
}
! void RKCommandEditorWindow::runSelection () {
! RK_TRACE (COMMANDEDITOR);
! if ( ! selectionInterface(m_doc)->selection().isEmpty() ) {
! RKGlobals::rInterface ()->issueCommand (new RCommand (selectionInterface(m_doc)->selection(), RCommand::User, ""));
}
}
! void RKCommandEditorWindow::runToCursor () {
! RK_TRACE (COMMANDEDITOR);
}
! void RKCommandEditorWindow::runFromCursor () {
! RK_TRACE (COMMANDEDITOR);
}
! void RKCommandEditorWindow::interruptCommand () {
! RK_TRACE (COMMANDEDITOR);
}
! void RKCommandEditorWindow::newFile()
! {
! if (m_view->document()->isModified() || !m_view->document()->url().isEmpty())
! new RKCommandEditorWindow (0);
! else
! m_view->document()->openURL(KURL());
}
! void RKCommandEditorWindow::openFile()
! {
! RK_TRACE (COMMANDEDITOR);
! if (!m_doc->closeURL ()) return;
!
! KURL url = KFileDialog::getOpenURL (QString::null, "*.R", this);
! if (!url.isEmpty ()) {
! if (m_view->document()->openURL(url)) {
! setCaption (caption + " - " + url.filename ());
! setRHighlighting ();
! }
! }
}
! #include "rkcommandeditorwindow.moc"
--- 90,233 ----
}
if (found_mode) {
! highlightingInterface(doc)->setHlMode(i);
} else {
! RK_DO (qDebug ("%s", highlightingInterface(doc)->hlModeName(i).lower().latin1 ()), COMMANDEDITOR, DL_WARNING);
}
}
!
!
!
!
! QString RKCommandEditorWindow::getSelection()
! {
! RK_TRACE (COMMANDEDITOR);
! return selectionInterface(m_doc)->selection();
}
!
! QString RKCommandEditorWindow::getText()
! {
! return editInterface(m_doc)->text();
}
! #include "rkcommandeditorwindow.moc"
!
!
!
! void RKCommandEditorWindow::slotGotFocus()
! {
!
! //RKGlobals::rkApp()->guiFactory()->addClient( m_view );
!
! //RKGlobals::rkApp()->changeGUI((KParts::Part *) this );//createGUI((KParts::Part *) m_view );
! }
!
!
!
! void RKCommandEditorWindow::slotLostFocus()
! {
! //RKGlobals::rkApp()->guiFactory()->removeClient(m_view);
! }
!
!
!
! bool RKCommandEditorWindow::openURL(const KURL &url){
! if (m_doc->openURL(url)){
! setRHighlighting(m_doc);
!
! QString fname;
! if (getFilenameAndPath(url,&fname)){
! setTabCaption(fname);
! }
! else {
! setTabCaption(url.prettyURL());
! }
!
! return true;
}
+ return false;
+
+
}
! bool RKCommandEditorWindow::getFilenameAndPath(const KURL &url,QString *fname){
! QString fullpath = url.path();
! int i,length,fnamepos;
! bool done;
!
! if ((length = (int)fullpath.length()) == 0)
! return false;
!
! fnamepos = 0;
! for (i = length-1,done = false ; i >= 0 && !done ; i--){
! if (fullpath[i] == '/'){
! done = true;
! fnamepos = i+1;
! }
}
+
+ if (!done)
+ return false;
+
+ if (fnamepos >= length)
+ return false;
+
+ if (fname)
+ *fname = fullpath.right(length-fnamepos);
+
+ return true;
}
!
!
!
!
! KURL RKCommandEditorWindow::url(){
! return m_doc->url();
}
!
!
! bool RKCommandEditorWindow::save(){
! return m_doc->save();
}
! bool RKCommandEditorWindow::saveAs(const KURL &url){
! return m_doc->saveAs(url);
! }
!
!
+ bool RKCommandEditorWindow::isModified() {
+ return m_doc->isModified();
}
+ void RKCommandEditorWindow::cut(){
+ m_view->cut();
+ }
!
! void RKCommandEditorWindow::copy(){
! m_view->copy();
}
!
!
! void RKCommandEditorWindow::paste(){
! m_view->paste();
}
+ void RKCommandEditorWindow::undo(){
+ m_doc->undo();
+ }
+
! void RKCommandEditorWindow::redo(){
! m_doc->redo();
! }
Index: rkcommandeditorwindow.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/windows/rkcommandeditorwindow.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** rkcommandeditorwindow.h 22 Oct 2004 15:24:01 -0000 1.4
--- rkcommandeditorwindow.h 2 Nov 2004 18:51:27 -0000 1.5
***************
*** 27,31 ****
--- 27,33 ----
#include <kparts/partmanager.h>
#include <kparts/part.h>
+ #include <kparts/factory.h>
+ #include <kmdichildview.h>
#include <kurl.h>
***************
*** 34,44 ****
class KAction;
class KToggleAction;
/**
! This class provides an editor window for R-commands. Basically this class is responsible for adding a GUI to RKCommandEditor.
! @author Thomas Friedrichsmeier
*/
! class RKCommandEditorWindow : public KParts::MainWindow {
Q_OBJECT
public:
--- 36,47 ----
class KAction;
class KToggleAction;
+ class RKwardApp;
/**
! This class provides an editor window for R-commands. It is an MDI child that is added to the main window.
! @author Pierre Ecochard
*/
! class RKCommandEditorWindow : public KMdiChildView {
Q_OBJECT
public:
***************
*** 46,71 ****
~RKCommandEditorWindow();
! public slots:
! void newWindow ();
!
! void closeWindow ();
- void run ();
- void runSelection ();
- void runFromCursor ();
- void runToCursor ();
- void interruptCommand ();
- void newFile ();
- void openFile ();
private:
! RKCommandEditor *editor;
! KTextEditor::View *m_view;
! KTextEditor::Document *m_doc;
! void setRHighlighting ();
- QString caption;
-
- protected:
- void closeEvent (QCloseEvent *e);
};
--- 49,78 ----
~RKCommandEditorWindow();
! QString getSelection();
! QString getText();
! bool openURL(const KURL &url);
! KURL url();
! bool save();
! Kate::View *m_view;
! bool saveAs(const KURL &url);
! bool isModified();
! void cut();
! void copy();
! void paste();
! void undo();
! void redo();
private:
! Kate::Document *m_doc;
!
! void setRHighlighting (Kate::Document *doc);
! KLibrary *m_library;
! bool getFilenameAndPath(const KURL &url,QString *fname);
! QBoxLayout* pLayout;
! private slots:
! void slotGotFocus();
! void slotLostFocus();
!
};
More information about the rkward-tracker
mailing list