From e2935eb1c04c3d9bf85f972cc9a7ecca15c7b3b9 Mon Sep 17 00:00:00 2001 From: Lotzi Boloni Date: Fri, 7 Apr 2000 16:18:56 +0000 Subject: [PATCH] -moved the drag and drop stuff to the widget instead of the toplevel window. This allows drag and drop in the part, which means that in konqueror you can now drag groups of files from above to the command line part. Which is kind of cool. Now only if we can detect the difference between the dragged dirs and files, because the popup appears too frequently. svn path=/trunk/kdebase/konsole/; revision=45904 --- include/TEWidget.h | 35 ++++++++++------ include/konsole.h | 4 +- src/TEWidget.C | 99 ++++++++++++++++++++++++++++++++++++++++++++++ src/konsole.C | 22 +++++------ src/konsole_part.C | 13 +----- 5 files changed, 135 insertions(+), 38 deletions(-) diff --git a/include/TEWidget.h b/include/TEWidget.h index 1a4df136..543bd739 100644 --- a/include/TEWidget.h +++ b/include/TEWidget.h @@ -1,14 +1,14 @@ -/* -------------------------------------------------------------------------- */ -/* */ -/* [te_widget.h] Terminal Emulation Widget */ -/* */ -/* -------------------------------------------------------------------------- */ -/* */ -/* Copyright (c) 1997,1998 by Lars Doelle */ -/* */ -/* This file is part of Konsole - an X terminal for KDE */ -/* */ -/* -------------------------------------------------------------------------- */ +/* ----------------------------------------------------------------------- */ +/* */ +/* [te_widget.h] Terminal Emulation Widget */ +/* */ +/* ----------------------------------------------------------------------- */ +/* */ +/* Copyright (c) 1997,1998 by Lars Doelle */ +/* */ +/* This file is part of Konsole - an X terminal for KDE */ +/* */ +/* ----------------------------------------------------------------------- */ #ifndef TE_WIDGET_H #define TE_WIDGET_H @@ -24,6 +24,8 @@ extern unsigned short vt100_graphics[32]; +class TESession; + class TEWidget : public QFrame // a widget representing attributed text { Q_OBJECT @@ -98,6 +100,10 @@ protected: void mousePressEvent( QMouseEvent* ); void mouseReleaseEvent( QMouseEvent* ); void mouseMoveEvent( QMouseEvent* ); + // Dnd + void dragEnterEvent(QDragEnterEvent* event); + void dropEvent(QDropEvent* event); + virtual int charClass(char) const; @@ -161,6 +167,13 @@ private: BOOL blinking; // hide text in paintEvent BOOL hasBlinker; // has characters to blink QTimer* blinkT; // active when hasBlinker + QPopupMenu* m_drop; + QString dropText; + public: + // current session in this widget + TESession *currentSession; +private slots: + void drop_menu_activated(int item); }; #endif // TE_WIDGET_H diff --git a/include/konsole.h b/include/konsole.h index 66489cbc..0ac0e3cd 100644 --- a/include/konsole.h +++ b/include/konsole.h @@ -1,5 +1,5 @@ -/* -------------------------------------------------------------------------- */ -/* */ +/* ----------------------------------------------------------------------- */ +/* */ /* [konsole.h] Konsole */ /* */ /* -------------------------------------------------------------------------- */ diff --git a/src/TEWidget.C b/src/TEWidget.C index 22ff163a..0a7c8499 100644 --- a/src/TEWidget.C +++ b/src/TEWidget.C @@ -44,10 +44,12 @@ #include "config.h" #include "TEWidget.h" +#include "session.h" #include #include #include +#include #include #include @@ -58,6 +60,9 @@ #include "TEWidget.moc" #include +#include +#include +#include #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) #define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } @@ -265,6 +270,15 @@ TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) setColorTable(base_color_table); // init color table qApp->installEventFilter( this ); //FIXME: see below + + // Init DnD //////////////////////////////////////////////////////////////// + currentSession = NULL; + setAcceptDrops(true); // attempt + m_drop = new QPopupMenu; + m_drop->insertItem( i18n("Paste"), 0); + m_drop->insertItem( i18n("cd"), 1); + connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); + } //FIXME: make proper destructor @@ -1000,3 +1014,88 @@ void TEWidget::styleChange(QStyle &) { propagateSize(); } + + +/* --------------------------------------------------------------------- */ +/* */ +/* Drag & Drop */ +/* */ +/* --------------------------------------------------------------------- */ + +void TEWidget::dragEnterEvent(QDragEnterEvent* e) +{ + e->accept(QTextDrag::canDecode(e) || + QUriDrag::canDecode(e)); +} + +void TEWidget::dropEvent(QDropEvent* event) +{ + // The current behaviour when url(s) are dropped is + // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd + // * in all other cases, just paste + // (for non-local ones, or for a list of URLs, 'cd' is nonsense) + QStrList strlist; + KURL *url; + int file_count = 0; + dropText = ""; + bool bPopup = true; + + if(QUriDrag::decode(event, strlist)) { + if (strlist.count()) { + for(const char* p = strlist.first(); p; p = strlist.next()) { + if(file_count++ > 0) { + dropText += " "; + bPopup = false; // more than one file, don't popup + } + url = new KURL( QString(p) ); + if (url->isLocalFile()) { + dropText += url->path(); // local URL : remove protocol + } + else { + dropText += p; + bPopup = false; // a non-local file, don't popup + } + delete url; + p = strlist.next(); + } + + if (bPopup) + // m_drop->popup(pos() + event->pos()); + m_drop->popup(mapToGlobal(event->pos())); + else + { + if (currentSession) { + currentSession->getEmulation()->sendString(dropText.latin1()); + } + kdDebug() << "Drop:" << dropText.latin1() << "\n"; + } + } + } + else if(QTextDrag::decode(event, dropText)) { + kdDebug() << "Drop:" << dropText.latin1() << "\n"; + if (currentSession) { + currentSession->getEmulation()->sendString(dropText.latin1()); + } + // Paste it + } +} + + +void TEWidget::drop_menu_activated(int item) +{ + switch (item) + { + case 0: // paste + currentSession->getEmulation()->sendString(dropText); +// KWM::activate((Window)this->winId()); + break; + case 1: // cd ... + currentSession->getEmulation()->sendString("cd "); + KURL url( dropText ); + currentSession->getEmulation()->sendString(url.directory()); + currentSession->getEmulation()->sendString("\n"); +// KWM::activate((Window)this->winId()); + break; + } +} + diff --git a/src/konsole.C b/src/konsole.C index 14e817d6..ca34828a 100644 --- a/src/konsole.C +++ b/src/konsole.C @@ -90,12 +90,6 @@ #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) -/* -#undef PACKAGE -#undef VERSION -#define PACKAGE "konsole" -#define VERSION "0.9.12" -*/ template class QPtrDict; @@ -149,7 +143,8 @@ Konsole::Konsole(const QString& name, // Init DnD //////////////////////////////////////////////////////////////// - setAcceptDrops(true); + // setAcceptDrops(true); + // FIXME: Now it is in TEWidget. Clean this up // load session commands /////////////////////////////////////////////////// @@ -341,14 +336,17 @@ void Konsole::makeMenu() QPopupMenu* m_help = helpMenu(aboutAuthor, false); m_help->insertItem( i18n("&Technical Reference ..."), this, SLOT(tecRef()), 0, -1, 1); + /* // Popup menu for drag & drop m_drop = new QPopupMenu; m_drop->insertItem( i18n("Paste"), 0); m_drop->insertItem( i18n("cd"), 1); connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); + */ m_options->installEventFilter( this ); + // For those who would like to add shortcuts here, be aware that // ALT-key combinations are heavily used by many programs. Thus, // activating shortcuts here means deactivating them in the other @@ -872,15 +870,12 @@ void Konsole::activateSession() if (!s) { fprintf(stderr,"session not found\n"); return; } // oops if (s->schemaNo()!=curr_schema) { - setSchema(s->schemaNo()); //FIXME: creates flicker? Do only if differs + setSchema(s->schemaNo()); //Set Font. Now setConnect should do the appropriate action. //if the size has changed, a resize event (noticable to the application) //should happen. Else, we could even start the application - s->setConnect(TRUE); // does a bulkShow (setImage) - setFont(s->fontNo()); //FIXME: creates flicker? - //FIXME: check here if we're still alife. - // if not, quit, otherwise, - // start propagating quit. + s->setConnect(TRUE); // does a bulkShow (setImage) + setFont(s->fontNo()); //FIXME: creates flicker? title = s->Title(); // take title from current session } else @@ -894,6 +889,7 @@ void Konsole::activateSession() s->setConnect(TRUE); } setHeader(); + te->currentSession = se; keytab_menu_activated(n_keytab); // act. the keytab for this session } diff --git a/src/konsole_part.C b/src/konsole_part.C index 15eee8b3..c9eae856 100644 --- a/src/konsole_part.C +++ b/src/konsole_part.C @@ -98,18 +98,7 @@ konsolePart::konsolePart(QWidget *parent, const char *name) m_extension = new konsoleBrowserExtension(this); - //bool login_shell = false; - //bool welcome = true; - //bool histon = true; - //const char* wname = PACKAGE; - - // QCString sz = ""; - //sz = args->getOption("vt_sz"); - //histon = args->isSet("hist"); - //wname = args->getOption("name"); - //login_shell = args->isSet("ls"); QStrList eargs; - // welcome = args->isSet("welcome"); const char* shell = getenv("SHELL"); if (shell == NULL || *shell == '\0') shell = "/bin/sh"; @@ -125,8 +114,8 @@ konsolePart::konsolePart(QWidget *parent, const char *name) // initial->run(); initial->setConnect(TRUE); QTimer::singleShot(0/*100*/,initial,SLOT(run())); - initial->getEmulation()->setKeytrans(0); + te->currentSession = initial; // setXMLFile("konsole_part.rc");