Skip to content

Commit 30f262d

Browse files
committed
liteeditor support drop file to open editor
1 parent 95a6b42 commit 30f262d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

liteidex/src/plugins/liteeditor/liteeditorwidget.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,30 @@ void LiteEditorWidget::updateFont(const QFont &font)
454454
this->m_completer->popup()->setFont(font);
455455
}
456456
}
457+
458+
void LiteEditorWidget::dropEvent(QDropEvent *event)
459+
{
460+
QList<QUrl> urls = event->mimeData()->urls();
461+
if (urls.isEmpty()) {
462+
LiteEditorWidgetBase::dropEvent(event);
463+
return;
464+
}
465+
bool hasFile = false;
466+
foreach (QUrl url, urls) {
467+
QString fileName = url.toLocalFile();
468+
if (!fileName.isEmpty()) {
469+
QFileInfo info(fileName);
470+
if (info.isFile()) {
471+
m_liteApp->fileManager()->openEditor(fileName,true);
472+
} else if(info.isDir()) {
473+
m_liteApp->fileManager()->addFolderList(fileName);
474+
}
475+
hasFile = true;
476+
}
477+
}
478+
if (hasFile) {
479+
event->accept();
480+
return;
481+
}
482+
LiteEditorWidgetBase::dropEvent(event);
483+
}

liteidex/src/plugins/liteeditor/liteeditorwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public slots:
6565
QString wordUnderCursor() const;
6666
QString textUnderCursor(QTextCursor tc) const;
6767
QString importUnderCursor(QTextCursor tc) const;
68+
virtual void dropEvent(QDropEvent *event);
6869
protected:
6970
LiteApi::ICompleter *m_completer;
7071
QMenu *m_contextMenu;

0 commit comments

Comments
 (0)