factorized GUI result popup menu code

This commit is contained in:
Jean-Francois Dockes 2013-04-27 11:11:35 +02:00
parent 974541f6c1
commit 3def1e444c
9 changed files with 219 additions and 206 deletions

View file

@ -81,6 +81,7 @@ using std::pair;
#include "indexer.h" #include "indexer.h"
#include "rclzg.h" #include "rclzg.h"
#include "fileudi.h" #include "fileudi.h"
#include "snippets_w.h"
using namespace confgui; using namespace confgui;
@ -90,6 +91,7 @@ using namespace confgui;
QString g_stringAllStem, g_stringNoStem; QString g_stringAllStem, g_stringNoStem;
static const QKeySequence quitKeySeq("Ctrl+q"); static const QKeySequence quitKeySeq("Ctrl+q");
static const QKeySequence closeKeySeq("Ctrl+w");
void RclMain::init() void RclMain::init()
{ {
@ -294,6 +296,8 @@ void RclMain::init()
this, SLOT(startPreview(int, Rcl::Doc, int))); this, SLOT(startPreview(int, Rcl::Doc, int)));
connect(restable, SIGNAL(docExpand(Rcl::Doc)), connect(restable, SIGNAL(docExpand(Rcl::Doc)),
this, SLOT(docExpand(Rcl::Doc))); this, SLOT(docExpand(Rcl::Doc)));
connect(restable, SIGNAL(showSubDocs(Rcl::Doc)),
this, SLOT(showSubDocs(Rcl::Doc)));
connect(restable, SIGNAL(previewRequested(Rcl::Doc)), connect(restable, SIGNAL(previewRequested(Rcl::Doc)),
this, SLOT(startPreview(Rcl::Doc))); this, SLOT(startPreview(Rcl::Doc)));
connect(restable, SIGNAL(editRequested(Rcl::Doc)), connect(restable, SIGNAL(editRequested(Rcl::Doc)),
@ -329,6 +333,8 @@ void RclMain::init()
this, SLOT(enablePrevPage(bool))); this, SLOT(enablePrevPage(bool)));
connect(reslist, SIGNAL(docEditClicked(Rcl::Doc)), connect(reslist, SIGNAL(docEditClicked(Rcl::Doc)),
this, SLOT(startNativeViewer(Rcl::Doc))); this, SLOT(startNativeViewer(Rcl::Doc)));
connect(reslist, SIGNAL(showSnippets(Rcl::Doc)),
this, SLOT(showSnippets(Rcl::Doc)));
connect(reslist, SIGNAL(showSubDocs(Rcl::Doc)), connect(reslist, SIGNAL(showSubDocs(Rcl::Doc)),
this, SLOT(showSubDocs(Rcl::Doc))); this, SLOT(showSubDocs(Rcl::Doc)));
connect(reslist, SIGNAL(docSaveToFileClicked(Rcl::Doc)), connect(reslist, SIGNAL(docSaveToFileClicked(Rcl::Doc)),
@ -1541,6 +1547,18 @@ static bool lookForHtmlBrowser(string &exefile)
return false; return false;
} }
void RclMain::showSnippets(Rcl::Doc doc)
{
SnippetsW *sp = new SnippetsW(doc, m_source);
connect(sp, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)),
this, SLOT(startNativeViewer(Rcl::Doc, int, QString)));
connect(new QShortcut(quitKeySeq, sp), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(new QShortcut(closeKeySeq, sp), SIGNAL (activated()),
sp, SLOT (close()));
sp->show();
}
void RclMain::showSubDocs(Rcl::Doc doc) void RclMain::showSubDocs(Rcl::Doc doc)
{ {
LOGDEB(("RclMain::showSubDocs\n")); LOGDEB(("RclMain::showSubDocs\n"));

View file

@ -119,6 +119,7 @@ public slots:
virtual void enablePrevPage(bool); virtual void enablePrevPage(bool);
virtual void docExpand(Rcl::Doc); virtual void docExpand(Rcl::Doc);
virtual void showSubDocs(Rcl::Doc); virtual void showSubDocs(Rcl::Doc);
virtual void showSnippets(Rcl::Doc);
virtual void startPreview(int docnum, Rcl::Doc doc, int keymods); virtual void startPreview(int docnum, Rcl::Doc doc, int keymods);
virtual void startPreview(Rcl::Doc); virtual void startPreview(Rcl::Doc);
virtual void startNativeViewer(Rcl::Doc, int pagenum = -1, virtual void startNativeViewer(Rcl::Doc, int pagenum = -1,

View file

@ -48,6 +48,7 @@ SOURCES += \
rclhelp.cpp \ rclhelp.cpp \
rclmain_w.cpp \ rclmain_w.cpp \
rclzg.cpp \ rclzg.cpp \
respopup.cpp \
reslist.cpp \ reslist.cpp \
restable.cpp \ restable.cpp \
rtitool.cpp \ rtitool.cpp \

View file

@ -31,7 +31,6 @@
#include <qtimer.h> #include <qtimer.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qimage.h> #include <qimage.h>
#include <qclipboard.h>
#include <qscrollbar.h> #include <qscrollbar.h>
#include <QTextBlock> #include <QTextBlock>
#include <QShortcut> #include <QShortcut>
@ -59,6 +58,7 @@
#ifdef RCL_USE_ASPELL #ifdef RCL_USE_ASPELL
#include "rclaspell.h" #include "rclaspell.h"
#endif #endif
#include "respopup.h"
static const QKeySequence quitKeySeq("Ctrl+q"); static const QKeySequence quitKeySeq("Ctrl+q");
static const QKeySequence closeKeySeq("Ctrl+w"); static const QKeySequence closeKeySeq("Ctrl+w");
@ -815,20 +815,6 @@ void ResList::mouseDoubleClickEvent(QMouseEvent *event)
#endif #endif
} }
void ResList::newSnippetsW(const Rcl::Doc& doc)
{
SnippetsW *sp = new SnippetsW(doc, m_source);
if (m_rclmain) {
connect(sp, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)),
m_rclmain, SLOT(startNativeViewer(Rcl::Doc, int, QString)));
connect(new QShortcut(quitKeySeq, sp), SIGNAL (activated()),
m_rclmain, SLOT (fileExit()));
}
connect(new QShortcut(closeKeySeq, sp), SIGNAL (activated()),
sp, SLOT (close()));
sp->show();
}
void ResList::newDupsW(const Rcl::Doc&, const vector<Rcl::Doc>& dups) void ResList::newDupsW(const Rcl::Doc&, const vector<Rcl::Doc>& dups)
{ {
ListDialog dialog; ListDialog dialog;
@ -886,7 +872,7 @@ void ResList::linkWasClicked(const QUrl &url)
LOGERR(("ResList::linkWasClicked: can't get doc for %d\n", i)); LOGERR(("ResList::linkWasClicked: can't get doc for %d\n", i));
return; return;
} }
newSnippetsW(doc); emit(showSnippets(doc));
} }
break; break;
@ -990,45 +976,12 @@ void ResList::createPopupMenu(const QPoint& pos)
if (m_popDoc < 0) if (m_popDoc < 0)
return; return;
Rcl::Doc doc; Rcl::Doc doc;
bool havedoc = getDoc(m_popDoc, doc); if (!getDoc(m_popDoc, doc))
string apptag; return;
if (havedoc) int options = 0;
doc.getmeta(Rcl::Doc::keyapptg, &apptag);
QMenu *popup = new QMenu(this);
popup->addAction(tr("&Preview"), this, SLOT(menuPreview()));
if (havedoc &&
!theconfig->getMimeViewerDef(doc.mimetype, apptag, 0).empty()) {
popup->addAction(tr("&Open"), this, SLOT(menuEdit()));
}
popup->addAction(tr("Copy &File Name"), this, SLOT(menuCopyFN()));
popup->addAction(tr("Copy &URL"), this, SLOT(menuCopyURL()));
if (havedoc && !doc.ipath.empty()) {
popup->addAction(tr("&Write to File"), this, SLOT(menuSaveToFile()));
}
if (m_ismainlist) if (m_ismainlist)
popup->addAction(tr("Find &similar documents"), options |= ResultPopup::showExpand;
this, SLOT(menuExpand())); QMenu *popup = ResultPopup::create(this, options, m_source, doc);
Rcl::Doc pdoc;
if (m_source.isNotNull() && m_source->getEnclosing(doc, pdoc))
popup->addAction(tr("Preview P&arent document/folder"),
this, SLOT(menuPreviewParent()));
popup->addAction(tr("&Open Parent document/folder"),
this, SLOT(menuOpenParent()));
if (havedoc && doc.haspages && m_source->snippetsCapable())
popup->addAction(tr("Open &Snippets window"),
this, SLOT(menuOpenSnippets()));
if (havedoc && rcldb && rcldb->hasSubDocs(doc))
popup->addAction(tr("Show subdocuments / attachments"),
this, SLOT(menuShowSubDocs()));
popup->popup(mapToGlobal(pos)); popup->popup(mapToGlobal(pos));
} }
@ -1054,45 +1007,28 @@ void ResList::menuSaveToFile()
void ResList::menuPreviewParent() void ResList::menuPreviewParent()
{ {
Rcl::Doc doc; Rcl::Doc doc;
if (!getDoc(m_popDoc, doc) || m_source.isNull()) if (getDoc(m_popDoc, doc) && !m_source.isNull()) {
return; Rcl::Doc pdoc = ResultPopup::getParent(m_source, doc);
Rcl::Doc pdoc; if (pdoc.mimetype == "inode/directory") {
if (m_source->getEnclosing(doc, pdoc)) { emit editRequested(pdoc);
emit previewRequested(pdoc); } else {
} else { emit previewRequested(pdoc);
// No parent doc: show enclosing folder with app configured for }
// directories
pdoc.url = path_getfather(doc.url);
pdoc.mimetype = "inode/directory";
emit editRequested(pdoc);
} }
} }
void ResList::menuOpenParent() void ResList::menuOpenParent()
{ {
Rcl::Doc doc; Rcl::Doc doc;
if (!getDoc(m_popDoc, doc) || m_source.isNull()) if (getDoc(m_popDoc, doc) && m_source.isNotNull())
return; emit editRequested(ResultPopup::getParent(m_source, doc));
Rcl::Doc pdoc;
if (m_source->getEnclosing(doc, pdoc)) {
emit editRequested(pdoc);
} else {
// No parent doc: show enclosing folder with app configured for
// directories
pdoc.url = path_getfather(doc.url);
pdoc.meta[Rcl::Doc::keychildurl] = doc.url;
pdoc.meta[Rcl::Doc::keyapptg] = "parentopen";
pdoc.mimetype = "inode/directory";
emit editRequested(pdoc);
}
} }
void ResList::menuOpenSnippets() void ResList::menuShowSnippets()
{ {
Rcl::Doc doc; Rcl::Doc doc;
if (!getDoc(m_popDoc, doc) || m_source.isNull()) if (getDoc(m_popDoc, doc))
return; emit showSnippets(doc);
newSnippetsW(doc);
} }
void ResList::menuShowSubDocs() void ResList::menuShowSubDocs()
@ -1111,34 +1047,16 @@ void ResList::menuEdit()
void ResList::menuCopyFN() void ResList::menuCopyFN()
{ {
LOGDEB(("menuCopyFN\n"));
Rcl::Doc doc; Rcl::Doc doc;
if (getDoc(m_popDoc, doc)) { if (getDoc(m_popDoc, doc))
LOGDEB(("menuCopyFN: Got doc, fn: [%s]\n", doc.url.c_str())); ResultPopup::copyFN(doc);
// Our urls currently always begin with "file://"
//
// Problem: setText expects a QString. Passing a (const char*)
// as we used to do causes an implicit conversion from
// latin1. File are binary and the right approach would be no
// conversion, but it's probably better (less worse...) to
// make a "best effort" tentative and try to convert from the
// locale's charset than accept the default conversion.
QString qfn = QString::fromLocal8Bit(doc.url.c_str()+7);
QApplication::clipboard()->setText(qfn, QClipboard::Selection);
QApplication::clipboard()->setText(qfn, QClipboard::Clipboard);
}
} }
void ResList::menuCopyURL() void ResList::menuCopyURL()
{ {
Rcl::Doc doc; Rcl::Doc doc;
if (getDoc(m_popDoc, doc)) { if (getDoc(m_popDoc, doc))
string url = url_encode(doc.url, 7); ResultPopup::copyURL(doc);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Selection);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Clipboard);
}
} }
void ResList::menuExpand() void ResList::menuExpand()

View file

@ -92,7 +92,7 @@ class ResList : public RESLIST_PARENTCLASS
virtual void menuExpand(); virtual void menuExpand();
virtual void menuPreviewParent(); virtual void menuPreviewParent();
virtual void menuOpenParent(); virtual void menuOpenParent();
virtual void menuOpenSnippets(); virtual void menuShowSnippets();
virtual void menuShowSubDocs(); virtual void menuShowSubDocs();
virtual void previewExposed(int); virtual void previewExposed(int);
virtual void append(const QString &text); virtual void append(const QString &text);
@ -108,6 +108,7 @@ class ResList : public RESLIST_PARENTCLASS
void docPreviewClicked(int, Rcl::Doc, int); void docPreviewClicked(int, Rcl::Doc, int);
void docSaveToFileClicked(Rcl::Doc); void docSaveToFileClicked(Rcl::Doc);
void previewRequested(Rcl::Doc); void previewRequested(Rcl::Doc);
void showSnippets(Rcl::Doc);
void showSubDocs(Rcl::Doc); void showSubDocs(Rcl::Doc);
void editRequested(Rcl::Doc); void editRequested(Rcl::Doc);
void docExpand(Rcl::Doc); void docExpand(Rcl::Doc);
@ -153,7 +154,6 @@ class ResList : public RESLIST_PARENTCLASS
bool scrollIsAtTop(); bool scrollIsAtTop();
bool scrollIsAtBottom(); bool scrollIsAtBottom();
void setupArrows(); void setupArrows();
void newSnippetsW(const Rcl::Doc &doc);
void newDupsW(const Rcl::Doc& doc, const std::vector<Rcl::Doc>& dups); void newDupsW(const Rcl::Doc& doc, const std::vector<Rcl::Doc>& dups);
}; };

105
src/qtgui/respopup.cpp Normal file
View file

@ -0,0 +1,105 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#include <qapplication.h>
#include <qmenu.h>
#include <qclipboard.h>
#include "debuglog.h"
#include "smallut.h"
#include "recoll.h"
#include "docseq.h"
#include "respopup.h"
namespace ResultPopup {
QMenu *create(QWidget *me, int opts, RefCntr<DocSequence> source, Rcl::Doc& doc)
{
QMenu *popup = new QMenu(me);
string apptag;
doc.getmeta(Rcl::Doc::keyapptg, &apptag);
popup->addAction(me->tr("&Preview"), me, SLOT(menuPreview()));
if (!theconfig->getMimeViewerDef(doc.mimetype, apptag, 0).empty()) {
popup->addAction(me->tr("&Open"), me, SLOT(menuEdit()));
}
popup->addAction(me->tr("Copy &File Name"), me, SLOT(menuCopyFN()));
popup->addAction(me->tr("Copy &URL"), me, SLOT(menuCopyURL()));
if (!doc.ipath.empty())
popup->addAction(me->tr("&Write to File"), me, SLOT(menuSaveToFile()));
Rcl::Doc pdoc;
if (source.isNotNull() && source->getEnclosing(doc, pdoc)) {
popup->addAction(me->tr("Preview P&arent document/folder"),
me, SLOT(menuPreviewParent()));
popup->addAction(me->tr("&Open Parent document/folder"),
me, SLOT(menuOpenParent()));
}
if (opts & showExpand)
popup->addAction(me->tr("Find &similar documents"),
me, SLOT(menuExpand()));
if (doc.haspages && source->snippetsCapable())
popup->addAction(me->tr("Open &Snippets window"),
me, SLOT(menuOpenSnippets()));
if (rcldb && rcldb->hasSubDocs(doc))
popup->addAction(me->tr("Show subdocuments / attachments"),
me, SLOT(menuShowSubDocs()));
return popup;
}
Rcl::Doc getParent(RefCntr<DocSequence> source,
Rcl::Doc& doc)
{
Rcl::Doc pdoc;
if (source.isNull() || !source->getEnclosing(doc, pdoc)) {
// No parent doc: show enclosing folder with app configured for
// directories
pdoc.url = path_getfather(doc.url);
pdoc.meta[Rcl::Doc::keychildurl] = doc.url;
pdoc.meta[Rcl::Doc::keyapptg] = "parentopen";
pdoc.mimetype = "inode/directory";
}
return pdoc;
}
void copyFN(const Rcl::Doc &doc)
{
// Our urls currently always begin with "file://"
//
// Problem: setText expects a QString. Passing a (const char*)
// as we used to do causes an implicit conversion from
// latin1. File are binary and the right approach would be no
// conversion, but it's probably better (less worse...) to
// make a "best effort" tentative and try to convert from the
// locale's charset than accept the default conversion.
QString qfn = QString::fromLocal8Bit(doc.url.c_str()+7);
QApplication::clipboard()->setText(qfn, QClipboard::Selection);
QApplication::clipboard()->setText(qfn, QClipboard::Clipboard);
}
void copyURL(const Rcl::Doc &doc)
{
string url = url_encode(doc.url, 7);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Selection);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Clipboard);
}
}

31
src/qtgui/respopup.h Normal file
View file

@ -0,0 +1,31 @@
/* Copyright (C) 2006 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _RESPOPUP_H_INCLUDED_
#define _RESPOPUP_H_INCLUDED_
namespace ResultPopup {
enum Options {showExpand = 0x1};
extern QMenu *create(QWidget *me, int opts,
RefCntr<DocSequence> source,
Rcl::Doc& doc);
extern Rcl::Doc getParent(RefCntr<DocSequence> source,
Rcl::Doc& doc);
extern void copyFN(const Rcl::Doc &doc);
extern void copyURL(const Rcl::Doc &doc);
};
#endif /* _RESPOPUP_H_INCLUDED_ */

View file

@ -31,7 +31,6 @@
#include <QTextDocument> #include <QTextDocument>
#include <QPainter> #include <QPainter>
#include <QSplitter> #include <QSplitter>
#include <QClipboard>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
@ -46,6 +45,7 @@
#include "rclconfig.h" #include "rclconfig.h"
#include "plaintorich.h" #include "plaintorich.h"
#include "indexer.h" #include "indexer.h"
#include "respopup.h"
// Compensate for the default and somewhat bizarre vertical placement // Compensate for the default and somewhat bizarre vertical placement
// of text in cells // of text in cells
@ -137,18 +137,9 @@ void ResTableDetailArea::createPopupMenu(const QPoint& pos)
LOGDEB(("ResTableDetailArea::createPopupMenu: no table/detaildoc\n")); LOGDEB(("ResTableDetailArea::createPopupMenu: no table/detaildoc\n"));
return; return;
} }
QMenu *popup = new QMenu(this); QMenu *popup = ResultPopup::create(m_table, ResultPopup::showExpand,
popup->addAction(tr("&Preview"), m_table, SLOT(menuPreview())); m_table->m_model->getDocSource(),
popup->addAction(tr("&Open"), m_table, SLOT(menuEdit())); m_table->m_detaildoc);
popup->addAction(tr("Copy &File Name"), m_table, SLOT(menuCopyFN()));
popup->addAction(tr("Copy &URL"), m_table, SLOT(menuCopyURL()));
if (!m_table->m_detaildoc.ipath.empty())
popup->addAction(tr("&Write to File"), m_table, SLOT(menuSaveToFile()));
popup->addAction(tr("Find &similar documents"), m_table, SLOT(menuExpand()));
popup->addAction(tr("Preview P&arent document/folder"),
m_table, SLOT(menuPreviewParent()));
popup->addAction(tr("&Open Parent document/folder"),
m_table, SLOT(menuOpenParent()));
popup->popup(mapToGlobal(pos)); popup->popup(mapToGlobal(pos));
} }
@ -503,6 +494,7 @@ void ResTable::init()
header->setSortIndicatorShown(true); header->setSortIndicatorShown(true);
header->setSortIndicator(-1, Qt::AscendingOrder); header->setSortIndicator(-1, Qt::AscendingOrder);
header->setContextMenuPolicy(Qt::CustomContextMenu); header->setContextMenuPolicy(Qt::CustomContextMenu);
header->setStretchLastSection(1);
connect(header, SIGNAL(sectionResized(int,int,int)), connect(header, SIGNAL(sectionResized(int,int,int)),
this, SLOT(saveColState())); this, SLOT(saveColState()));
connect(header, SIGNAL(customContextMenuRequested(const QPoint&)), connect(header, SIGNAL(customContextMenuRequested(const QPoint&)),
@ -740,25 +732,9 @@ void ResTable::createPopupMenu(const QPoint& pos)
LOGDEB(("ResTable::createPopupMenu: m_detaildocnum %d\n", m_detaildocnum)); LOGDEB(("ResTable::createPopupMenu: m_detaildocnum %d\n", m_detaildocnum));
if (m_detaildocnum < 0) if (m_detaildocnum < 0)
return; return;
QMenu *popup = new QMenu(this); QMenu *popup = ResultPopup::create(this, ResultPopup::showExpand,
popup->addAction(tr("&Preview"), this, SLOT(menuPreview())); m_model->getDocSource(),
popup->addAction(tr("&Open"), this, SLOT(menuEdit())); m_detaildoc);
popup->addAction(tr("Copy &File Name"), this, SLOT(menuCopyFN()));
popup->addAction(tr("Copy &URL"), this, SLOT(menuCopyURL()));
if (m_detaildoc.ipath.empty())
popup->addAction(tr("&Write to File"), this, SLOT(menuSaveToFile()));
popup->addAction(tr("Find &similar documents"), this, SLOT(menuExpand()));
RefCntr<DocSequence> source = m_model->getDocSource();
Rcl::Doc pdoc;
if (source.isNotNull() && source->getEnclosing(m_detaildoc, pdoc))
popup->addAction(tr("Preview P&arent document/folder"),
this, SLOT(menuPreviewParent()));
popup->addAction(tr("&Open Parent document/folder"),
this, SLOT(menuOpenParent()));
popup->popup(mapToGlobal(pos)); popup->popup(mapToGlobal(pos));
} }
@ -771,98 +747,59 @@ void ResTable::menuPreview()
void ResTable::menuSaveToFile() void ResTable::menuSaveToFile()
{ {
if (m_detaildocnum < 0) if (m_detaildocnum >= 0)
return; emit docSaveToFileClicked(m_detaildoc);
emit docSaveToFileClicked(m_detaildoc);
} }
void ResTable::menuPreviewParent() void ResTable::menuPreviewParent()
{ {
if (!m_model || m_detaildocnum < 0) if (m_detaildocnum >= 0 && m_model &&
return; m_model->getDocSource().isNotNull()) {
RefCntr<DocSequence> source = m_model->getDocSource(); Rcl::Doc pdoc = ResultPopup::getParent(m_model->getDocSource(),
if (source.isNull()) m_detaildoc);
return; if (pdoc.mimetype == "inode/directory") {
Rcl::Doc& doc = m_detaildoc; emit editRequested(pdoc);
Rcl::Doc pdoc; } else {
if (source->getEnclosing(doc, pdoc)) { emit previewRequested(pdoc);
emit previewRequested(pdoc); }
} else {
// No parent doc: show enclosing folder with app configured for
// directories
pdoc.url = path_getfather(doc.url);
pdoc.meta[Rcl::Doc::keychildurl] = doc.url;
pdoc.meta[Rcl::Doc::keyapptg] = "parentopen";
pdoc.mimetype = "inode/directory";
emit editRequested(pdoc);
} }
} }
void ResTable::menuOpenParent() void ResTable::menuOpenParent()
{ {
if (!m_model || m_detaildocnum < 0) if (m_detaildocnum >= 0 && m_model && m_model->getDocSource().isNotNull())
return; emit editRequested(
RefCntr<DocSequence> source = m_model->getDocSource(); ResultPopup::getParent(m_model->getDocSource(), m_detaildoc));
if (source.isNull())
return;
Rcl::Doc& doc = m_detaildoc;
Rcl::Doc pdoc;
if (source->getEnclosing(doc, pdoc)) {
emit editRequested(pdoc);
} else {
// No parent doc: show enclosing folder with app configured for
// directories
pdoc.url = path_getfather(doc.url);
pdoc.meta[Rcl::Doc::keychildurl] = doc.url;
pdoc.meta[Rcl::Doc::keyapptg] = "parentopen";
pdoc.mimetype = "inode/directory";
emit editRequested(pdoc);
}
} }
void ResTable::menuEdit() void ResTable::menuEdit()
{ {
if (m_detaildocnum < 0) if (m_detaildocnum >= 0)
return; emit docEditClicked(m_detaildoc);
emit docEditClicked(m_detaildoc);
} }
void ResTable::menuCopyFN() void ResTable::menuCopyFN()
{ {
if (m_detaildocnum < 0) if (m_detaildocnum >= 0)
return; ResultPopup::copyFN(m_detaildoc);
Rcl::Doc &doc = m_detaildoc;
// Our urls currently always begin with "file://"
//
// Problem: setText expects a QString. Passing a (const char*)
// as we used to do causes an implicit conversion from
// latin1. File are binary and the right approach would be no
// conversion, but it's probably better (less worse...) to
// make a "best effort" tentative and try to convert from the
// locale's charset than accept the default conversion.
QString qfn = QString::fromLocal8Bit(doc.url.c_str()+7);
QApplication::clipboard()->setText(qfn, QClipboard::Selection);
QApplication::clipboard()->setText(qfn, QClipboard::Clipboard);
} }
void ResTable::menuCopyURL() void ResTable::menuCopyURL()
{ {
if (m_detaildocnum < 0) if (m_detaildocnum >= 0)
return; ResultPopup::copyURL(m_detaildoc);
Rcl::Doc &doc = m_detaildoc;
string url = url_encode(doc.url, 7);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Selection);
QApplication::clipboard()->setText(url.c_str(),
QClipboard::Clipboard);
} }
void ResTable::menuExpand() void ResTable::menuExpand()
{ {
if (m_detaildocnum < 0) if (m_detaildocnum >= 0)
return; emit docExpand(m_detaildoc);
emit docExpand(m_detaildoc); }
void ResTable::menuShowSubDocs()
{
if (m_detaildocnum >= 0)
emit showSubDocs(m_detaildoc);
} }
void ResTable::createHeaderPopupMenu(const QPoint& pos) void ResTable::createHeaderPopupMenu(const QPoint& pos)

View file

@ -136,6 +136,7 @@ public slots:
virtual void menuExpand(); virtual void menuExpand();
virtual void menuPreviewParent(); virtual void menuPreviewParent();
virtual void menuOpenParent(); virtual void menuOpenParent();
virtual void menuShowSubDocs();
virtual void createHeaderPopupMenu(const QPoint&); virtual void createHeaderPopupMenu(const QPoint&);
virtual void deleteColumn(); virtual void deleteColumn();
virtual void addColumn(); virtual void addColumn();
@ -152,6 +153,7 @@ signals:
void editRequested(Rcl::Doc); void editRequested(Rcl::Doc);
void headerClicked(); void headerClicked();
void docExpand(Rcl::Doc); void docExpand(Rcl::Doc);
void showSubDocs(Rcl::Doc);
friend class ResTablePager; friend class ResTablePager;
friend class ResTableDetailArea; friend class ResTableDetailArea;