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/main.cpp
src/documenthandler.cpp src/documenthandler.cpp
src/highlightmodel.cpp src/highlightmodel.cpp
src/texteditor.cpp
qml.qrc qml.qrc
) )

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

@ -3,6 +3,7 @@ import QtQuick.Window 2.15
import QtQuick.Controls 2.15 import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import FishUI 1.0 as FishUI import FishUI 1.0 as FishUI
import Cutefish.TextEditor 1.0
FishUI.Window { FishUI.Window {
id: root id: root
@ -13,6 +14,14 @@ FishUI.Window {
visible: true visible: true
title: qsTr("Text Editor") title: qsTr("Text Editor")
FileHelper {
id: fileHelper
onNewPath: {
_tabView.addTab(textEditorCompeont, { fileUrl: path })
}
}
headerItem: Item { headerItem: Item {
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
@ -23,7 +32,7 @@ FishUI.Window {
id: _tabbar id: _tabbar
anchors.fill: parent anchors.fill: parent
anchors.margins: FishUI.Units.smallSpacing / 2 anchors.margins: FishUI.Units.smallSpacing / 2
anchors.rightMargin: FishUI.Units.largeSpacing * 2 anchors.rightMargin: FishUI.Units.largeSpacing * 4
model: _tabView.count model: _tabView.count
currentIndex : _tabView.currentIndex 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 { ColumnLayout {
anchors.fill: parent anchors.fill: parent
spacing: 0 spacing: 0
@ -87,12 +109,17 @@ FishUI.Window {
anchors.bottomMargin: FishUI.Units.smallSpacing anchors.bottomMargin: FishUI.Units.smallSpacing
Label { 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() { function addTab() {
_tabView.addTab(textEditorCompeont, {}) _tabView.addTab(textEditorCompeont, {})
} }
@ -106,6 +133,6 @@ FishUI.Window {
} }
Component.onCompleted: { Component.onCompleted: {
addTab() // addTab()
} }
} }

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

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