feat: support drop files

pull/4/head
kateleet 5 years ago
parent 85f041893e
commit 7c89a8078f

@ -18,6 +18,7 @@ set(PROJECT_SOURCES
src/main.cpp
src/documenthandler.cpp
src/highlightmodel.cpp
src/texteditor.cpp
qml.qrc
)

@ -14,8 +14,8 @@ Item {
property bool showLineNumbers: true
property int characterCount: body.text.length
height: ListView.view.height
width: ListView.view.width
height: ListView.view ? ListView.view.height : 0
width: ListView.view ? ListView.view.width : 0
DocumentHandler {
id: document
@ -25,6 +25,7 @@ Item {
selectionEnd: body.selectionEnd
backgroundColor: FishUI.Theme.backgroundColor
enableSyntaxHighlighting: true
theme: FishUI.Theme.darkMode ? "Breeze Dark" : "Breeze Light"
onSearchFound: {
body.select(start, end)
@ -47,6 +48,11 @@ Item {
Flickable {
id: _flickable
FishUI.WheelHandler {
id: wheelHandler
target: _flickable
}
boundsBehavior: Flickable.StopAtBounds
boundsMovement: Flickable.StopAtBounds

@ -3,6 +3,7 @@ import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import FishUI 1.0 as FishUI
import Cutefish.TextEditor 1.0
FishUI.Window {
id: root
@ -13,6 +14,14 @@ FishUI.Window {
visible: true
title: qsTr("Text Editor")
FileHelper {
id: fileHelper
onNewPath: {
_tabView.addTab(textEditorCompeont, { fileUrl: path })
}
}
headerItem: Item {
Rectangle {
anchors.fill: parent
@ -23,7 +32,7 @@ FishUI.Window {
id: _tabbar
anchors.fill: parent
anchors.margins: FishUI.Units.smallSpacing / 2
anchors.rightMargin: FishUI.Units.largeSpacing * 2
anchors.rightMargin: FishUI.Units.largeSpacing * 4
model: _tabView.count
currentIndex : _tabView.currentIndex
@ -59,6 +68,19 @@ FishUI.Window {
}
}
DropArea {
id: _dropArea
anchors.fill: parent
onDropped: {
if (drop.hasUrls) {
for (var i = 0; i < drop.urls.length; ++i) {
fileHelper.addPath(drop.urls[i])
}
}
}
}
ColumnLayout {
anchors.fill: parent
spacing: 0
@ -87,12 +109,17 @@ FishUI.Window {
anchors.bottomMargin: FishUI.Units.smallSpacing
Label {
text: qsTr("Characters %1").arg(_tabView.currentItem.characterCount)
text: _tabView.currentItem ? qsTr("Characters %1").arg(_tabView.currentItem.characterCount)
: ""
}
}
}
}
function addPath(path) {
_tabView.addTab(textEditorCompeont, { fileUrl: path })
}
function addTab() {
_tabView.addTab(textEditorCompeont, {})
}
@ -106,6 +133,6 @@ FishUI.Window {
}
Component.onCompleted: {
addTab()
// addTab()
}
}

@ -7,7 +7,5 @@ HighlightModel::HighlightModel(QObject *parent)
for (KSyntaxHighlighting::Definition def : m_repository.definitions()) {
if (def.isHidden())
continue;
qDebug() << def.translatedName();
}
}

@ -2,6 +2,7 @@
#include <QQmlApplicationEngine>
#include "documenthandler.h"
#include "highlightmodel.h"
#include "texteditor.h"
int main(int argc, char *argv[])
{
@ -12,6 +13,7 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
qmlRegisterType<DocumentHandler>("Cutefish.TextEditor", 1, 0, "DocumentHandler");
qmlRegisterType<FileHelper>("Cutefish.TextEditor", 1, 0, "FileHelper");
HighlightModel m;

@ -0,0 +1,12 @@
#include "texteditor.h"
FileHelper::FileHelper(QObject *parent)
: QObject(parent)
{
}
void FileHelper::addPath(const QString &path)
{
emit newPath(path);
}

@ -0,0 +1,19 @@
#ifndef TEXTEDITOR_H
#define TEXTEDITOR_H
#include <QObject>
class FileHelper : public QObject
{
Q_OBJECT
public:
explicit FileHelper(QObject *parent = nullptr);
Q_INVOKABLE void addPath(const QString &path);
signals:
void newPath(const QString &path);
};
#endif // TEXTEDITOR_H
Loading…
Cancel
Save