[Konsole-devel] drag & drop actions: non-emacs keys shell support & non-"file:" actions
Alexander Kellett
lypanov at kde.org
Thu Nov 28 13:15:40 UTC 2002
hi all,
the attached patch does two things:
adds a "viBindings" config option
- to stop uri dnd from sending emacs specific keypresses
adds a new dnd action menu for non file: urls
- currently wget only
its ugly, and probably incorrect.
but then, it Works For Me (Tm) :)
not really hoping for peer review,
just wanted to "say" that i'm
working on this.
groetjes,
Alex
-------------- next part --------------
? konsole/ppc970-3.html
Index: konsole/TEWidget.cpp
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/TEWidget.cpp,v
retrieving revision 1.170
diff -u -p -B -w -r1.170 TEWidget.cpp
--- konsole/TEWidget.cpp 2002/10/17 07:48:30 1.170
+++ konsole/TEWidget.cpp 2002/11/28 12:48:53
@@ -312,11 +312,13 @@ TEWidget::TEWidget(QWidget *parent, cons
,cuttobeginningofline(false)
,isBlinkEvent(false)
,m_drop(0)
+,m_drop2(0)
,possibleTripleClick(false)
,mResizeWidget(0)
,mResizeLabel(0)
,mResizeTimer(0)
,m_lineSpacing(0)
+,m_cmd_vi(false)
{
// The offsets are not yet calculated.
// Do not calculate these too often to be more smoothly when resizing
@@ -1234,6 +1236,11 @@ int TEWidget::charClass(UINT16 ch) const
return 1;
}
+void TEWidget::setViBindings(bool vi_bindings)
+{
+ m_cmd_vi = vi_bindings;
+}
+
void TEWidget::setWordCharacters(QString wc)
{
word_characters = wc;
@@ -1617,6 +1624,14 @@ void TEWidget::dropEvent(QDropEvent* eve
m_drop->insertItem( "mv", 4);
connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
};
+ if (m_drop2==0)
+ {
+ m_drop2 = new KPopupMenu(this);
+ m_drop2->insertItem( i18n("Paste"), 0);
+ m_drop2->insertSeparator();
+ m_drop2->insertItem( "wget", 1);
+ connect(m_drop2, SIGNAL(activated(int)), SLOT(drop2_menu_activated(int)));
+ };
// 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/cp/ln/mv
// * if there are only LOCAL urls, ask for paste or cp/ln/mv
@@ -1626,15 +1641,16 @@ void TEWidget::dropEvent(QDropEvent* eve
m_dnd_file_count = 0;
dropText = "";
bool bPopup = true;
- m_drop->setItemEnabled(1,true);
if(KURLDrag::decode(event, urllist)) {
if (!urllist.isEmpty()) {
+ bool use2 = false;
+ bool noPaste = false;
KURL::List::Iterator it;
for ( it = urllist.begin(); it != urllist.end(); ++it ) {
if(m_dnd_file_count++ > 0) {
dropText += " ";
- m_drop->setItemEnabled(1,false);
+ noPaste = true;
}
KURL url = *it;
QString tmp;
@@ -1642,17 +1658,20 @@ void TEWidget::dropEvent(QDropEvent* eve
tmp = url.path(); // local URL : remove protocol
}
else {
+ // TODO - check if can be handled by wget
+ // else should
tmp = url.url();
- bPopup = false; // a non-local file, don't popup
+ use2 = true;
}
if (urllist.count()>1)
KRun::shellQuote(tmp);
dropText += tmp;
}
+ (use2?m_drop2:m_drop)->setItemEnabled(1,!noPaste);
if (bPopup)
// m_drop->popup(pos() + event->pos());
- m_drop->popup(mapToGlobal(event->pos()));
+ (use2?m_drop2:m_drop)->popup(mapToGlobal(event->pos()));
else
{
if (m_dnd_file_count==1)
@@ -1677,6 +1696,27 @@ void TEWidget::doDrag()
// Don't delete the QTextDrag object. Qt will delete it when it's done with it.
}
+#define SHELLCMD(a) (m_cmd_vi?"" a:"\001\013" a)
+
+void TEWidget::drop2_menu_activated(int item)
+{
+ switch (item)
+ {
+ case 0: // paste
+ drop_menu_activated(0);
+ break;
+ case 1: // wget
+ emit sendStringToEmu(SHELLCMD("wget "));
+ if (m_dnd_file_count==1)
+ KRun::shellQuote(dropText);
+ emit sendStringToEmu(dropText.local8Bit());
+ emit sendStringToEmu("\n");
+ setActiveWindow();
+ break;
+ }
+}
+
+
void TEWidget::drop_menu_activated(int item)
{
switch (item)
@@ -1688,7 +1728,7 @@ void TEWidget::drop_menu_activated(int i
setActiveWindow();
break;
case 1: // cd ...
- emit sendStringToEmu("\001\013cd ");
+ emit sendStringToEmu(SHELLCMD("cd "));
struct stat statbuf;
if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
{
@@ -1705,13 +1745,13 @@ void TEWidget::drop_menu_activated(int i
setActiveWindow();
break;
case 2: // copy
- emit sendStringToEmu("\001\013cp -ri ");
+ emit sendStringToEmu(SHELLCMD("cp -ri "));
break;
case 3: // link
- emit sendStringToEmu("\001\013ln -s ");
+ emit sendStringToEmu(SHELLCMD("ln -s "));
break;
case 4: // move
- emit sendStringToEmu("\001\013mv -i ");
+ emit sendStringToEmu(SHELLCMD("mv -i "));
break;
}
if (item>1 && item<5) {
Index: konsole/TEWidget.h
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/TEWidget.h,v
retrieving revision 1.61
diff -u -p -B -w -r1.61 TEWidget.h
--- konsole/TEWidget.h 2002/10/06 16:41:21 1.61
+++ konsole/TEWidget.h 2002/11/28 12:48:53
@@ -80,6 +80,9 @@ public:
QSize sizeHint() const;
+ void setViBindings(bool viBindings);
+ bool viBindings() { return m_cmd_vi; }
+
void setWordCharacters(QString wc);
QString wordCharacters() { return word_characters; }
@@ -223,8 +226,10 @@ private:
QTimer* blinkCursorT; // active when hasBlinkingCursor
KPopupMenu* m_drop;
+ KPopupMenu* m_drop2;
QString dropText;
int m_dnd_file_count;
+ bool m_cmd_vi;
bool possibleTripleClick; // is set in mouseDoubleClickEvent and deleted
// after QApplication::doubleClickInterval() delay
@@ -241,6 +246,7 @@ private:
private slots:
void drop_menu_activated(int item);
+ void drop2_menu_activated(int item);
void swapColorTable();
void tripleClickTimeout(); // resets possibleTripleClick
};
Index: konsole/konsole.cpp
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/konsole.cpp,v
retrieving revision 1.346
diff -u -p -B -w -r1.346 konsole.cpp
--- konsole/konsole.cpp 2002/11/23 17:24:12 1.346
+++ konsole/konsole.cpp 2002/11/28 12:48:53
@@ -993,6 +993,7 @@ void Konsole::saveProperties(KConfig* co
}
config->setDesktopGroup();
config->writeEntry("Fullscreen",b_fullscreen);
+ config->writeEntry("viBindings", b_vi_bindings);
config->writeEntry("font",n_defaultFont);
config->writeEntry("defaultfont", defaultFont);
config->writeEntry("schema",s_kconfigSchema);
@@ -1062,6 +1063,7 @@ void Konsole::readProperties(KConfig* co
{
n_defaultKeytab=KeyTrans::find(config->readEntry("keytab","default"))->numb(); // act. the keytab for this session
b_fullscreen = config->readBoolEntry("Fullscreen",false);
+ b_vi_bindings = config->readBoolEntry("viBindings",false);
n_defaultFont = n_font = QMIN(config->readUnsignedNumEntry("font",3),TOPFONT);
n_scroll = QMIN(config->readUnsignedNumEntry("scrollbar",TEWidget::SCRRIGHT),2);
n_bell = QMIN(config->readUnsignedNumEntry("bellmode",TEWidget::BELLSYSTEM),2);
@@ -1103,6 +1105,7 @@ void Konsole::readProperties(KConfig* co
te->setColorTable(sch->table());
te->setScrollbarLocation(n_scroll);
+ te->setViBindings(b_vi_bindings);
te->setBellMode(n_bell);
// History
Index: konsole/konsole.h
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/konsole.h,v
retrieving revision 1.139
diff -u -p -B -w -r1.139 konsole.h
--- konsole/konsole.h 2002/10/23 07:05:14 1.139
+++ konsole/konsole.h 2002/11/28 12:48:53
@@ -331,6 +331,7 @@ private:
bool b_framevis:1;
bool b_fullscreen:1;
+ bool b_vi_bindings:1;
bool m_menuCreated:1;
bool skip_exit_query:1;
bool b_warnQuit:1;
Index: konsole/konsole_part.cpp
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/konsole_part.cpp,v
retrieving revision 1.66
diff -u -p -B -w -r1.66 konsole_part.cpp
--- konsole/konsole_part.cpp 2002/11/23 17:24:12 1.66
+++ konsole/konsole_part.cpp 2002/11/28 12:48:53
@@ -480,6 +480,7 @@ void konsolePart::readProperties()
n_scroll = QMIN(config->readUnsignedNumEntry("scrollbar",TEWidget::SCRRIGHT),2);
m_histSize = config->readNumEntry("history",DEFAULT_HISTORY_SIZE);
s_word_seps= config->readEntry("wordseps",":@-./_~");
+ b_vi_bindings= config->readBoolEntry("viBindings",true);
QFont tmpFont("fixed");
tmpFont.setFixedPitch(true);
@@ -524,6 +525,7 @@ void konsolePart::readProperties()
te->setLineSpacing( config->readUnsignedNumEntry( "LineSpacing", 0 ) );
te->setScrollbarLocation(n_scroll);
te->setWordCharacters(s_word_seps);
+ te->setViBindings(b_vi_bindings);
delete config;
@@ -552,6 +554,7 @@ void konsolePart::saveProperties()
config->writeEntry("schema",s_kconfigSchema);
config->writeEntry("scrollbar",n_scroll);
config->writeEntry("wordseps",s_word_seps);
+ config->writeEntry("viBindings",b_vi_bindings);
config->sync();
delete config;
Index: konsole/konsole_part.h
===================================================================
RCS file: /home/kde/kdebase/konsole/konsole/konsole_part.h,v
retrieving revision 1.17
diff -u -p -B -w -r1.17 konsole_part.h
--- konsole/konsole_part.h 2002/11/15 17:30:59 1.17
+++ konsole/konsole_part.h 2002/11/28 12:48:53
@@ -154,6 +154,7 @@ class konsolePart: public KParts::ReadOn
QString fontNotFound_par;
bool b_framevis:1;
+ bool b_vi_bindings:1;
bool b_histEnabled:1;
int curr_schema; // current schema no
More information about the konsole-devel
mailing list