Warning, /maui/strike/src/main.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.14
0002 import QtQml 2.14
0003
0004 import QtQuick.Controls 2.14
0005 import QtQuick.Layouts 1.3
0006
0007 import Qt.labs.settings 1.0
0008
0009 import org.mauikit.controls 1.3 as Maui
0010 import org.mauikit.filebrowsing 1.3 as FB
0011
0012 import org.slike.strike 1.0 as Strike
0013
0014 import "views"
0015 import "views/editor"
0016 import "views/widgets" as Widgets
0017
0018 Maui.ApplicationWindow
0019 {
0020 id: root
0021 title: currentEditor ? currentTab.title : ""
0022
0023 property alias project : _project
0024 property alias manager : _project.manager
0025
0026 property alias currentTab : editorView.currentTab
0027 property alias currentEditor: editorView.currentEditor
0028 property alias dialog : _dialogLoader.item
0029
0030 readonly property font defaultFont:
0031 {
0032 family: "Monospace"
0033 pointSize: Maui.Style.fontSizes.default
0034 }
0035
0036 //Global editor props
0037 property alias appSettings: settings
0038
0039 property Strike.CMakeProject _cmakeProject : _project.manager.project
0040
0041 Maui.WindowBlur
0042 {
0043 view: root
0044 geometry: Qt.rect(root.x, root.y, root.width, root.height)
0045 windowRadius: Maui.Style.radiusV
0046 enabled: !Maui.Handy.isMobile
0047 }
0048
0049 Settings
0050 {
0051 id: settings
0052 category: "General"
0053
0054 property bool showLineNumbers : true
0055 property bool autoSave : true
0056 property bool supportSplit :true
0057 property double tabSpace: 8
0058 property string theme : ""
0059 property color backgroundColor : root.Maui.Theme.backgroundColor
0060 property color textColor : root.Maui.Theme.textColor
0061 property bool enableSidebar: true
0062 property font font : defaultFont
0063 }
0064
0065 Strike.Project
0066 {
0067 id: _project
0068 preferences.installPrefix: "/usr"
0069
0070 onProjectUrlChanged:
0071 {
0072 _initialConfigDialog.open()
0073 editorView.openTab(projectUrl)
0074 }
0075 }
0076
0077 onCurrentEditorChanged:
0078 {
0079 syncSidebar(currentEditor.fileUrl)
0080 editorView.outputPanel.syncTerminal(currentEditor.fileUrl)
0081 }
0082
0083 onClosing:
0084 {
0085 _dialogLoader.sourceComponent = _unsavedDialogComponent
0086
0087 dialog.callback = function () {root.close()}
0088
0089 if(!dialog.discard)
0090 {
0091 for(var i = 0; i < editorView.count; i++)
0092 {
0093 if(editorView.tabHasUnsavedFiles(i))
0094 {
0095 close.accepted = false
0096 dialog.open()
0097 return
0098 }
0099 }
0100 }
0101
0102 close.accepted = true
0103 }
0104
0105 Widgets.ProjectConfigDialog
0106 {
0107 id: _initialConfigDialog
0108
0109 filling: !root.isWide
0110 maxHeight: 400
0111 maxWidth: 350
0112 hint: 1
0113 }
0114
0115 Loader
0116 {
0117 id: _dialogLoader
0118 }
0119
0120 Component
0121 {
0122 id: _unsavedDialogComponent
0123
0124 Maui.InfoDialog
0125 {
0126 property bool discard : false
0127 property var callback : ({})
0128
0129 title: i18n("Unsaved files")
0130 message: i18n("You have unsaved files. Do you want to go back and save them or discard all changes and exit?")
0131
0132 template.iconSource: "emblem-warning"
0133
0134 standardButtons: Dialog.Save | Dialog.Discard
0135
0136 onRejected:
0137 {
0138 discard = true
0139
0140 if(callback instanceof Function)
0141 {
0142 callback()
0143 }
0144 close()
0145 }
0146
0147 onAccepted: close()
0148 }
0149 }
0150
0151 Component
0152 {
0153 id: _settingsDialogComponent
0154 Widgets.SettingsDialog
0155 {}
0156 }
0157
0158 Component
0159 {
0160 id: _fileDialogComponent
0161 FB.FileDialog
0162 {
0163 settings.onlyDirs: false
0164 settings.filterType: FB.FMList.TEXT
0165 settings.sortBy: FB.FMList.MODIFIED
0166 }
0167 }
0168
0169 Component
0170 {
0171 id: _tagsDialogComponent
0172 FB.TagsDialog
0173 {
0174 onTagsReady: composerList.updateToUrls(tags)
0175 composerList.strict: false
0176 taglist.strict: false
0177 }
0178 }
0179
0180 Maui.SideBarView
0181 {
0182 id: _sideBarView
0183
0184 anchors.fill: parent
0185
0186 sideBar.preferredWidth: Maui.Style.units.gridUnit*16
0187 sideBar.minimumWidth: Maui.Style.units.gridUnit*14
0188 sideBar.enabled: editorView.count > 0 && settings.enableSidebar
0189
0190 Connections
0191 {
0192 target: _sideBarView.sideBar
0193 function onVisibleChanged()
0194 {
0195 if(currentEditor)
0196 syncSidebar(currentEditor.fileUrl)
0197 }
0198 }
0199
0200 sideBarContent: PlacesSidebar
0201 {
0202 id : _drawer
0203 anchors.fill: parent
0204 }
0205
0206 DropArea
0207 {
0208 id: _dropArea
0209 property var urls : []
0210 anchors.fill: parent
0211 onDropped:
0212 {
0213 if(drop.urls)
0214 {
0215 var m_urls = drop.urls.join(",")
0216 _dropArea.urls = m_urls.split(",")
0217 Strike.Strike.requestFiles( _dropArea.urls )
0218 }
0219 }
0220 }
0221
0222 EditorView
0223 {
0224 id: editorView
0225 anchors.fill: parent
0226 showCSDControls: true
0227
0228 headBar.forceCenterMiddleContent: false
0229
0230 headBar.farLeftContent: ToolButton
0231 {
0232 visible: _sideBarView.sideBar.enabled
0233 Layout.minimumWidth: implicitWidth
0234 Layout.alignment: Qt.AlignLeft
0235 icon.name: _sideBarView.sideBar.visible ? "sidebar-collapse" : "sidebar-expand"
0236 onClicked: _sideBarView.sideBar.toggle()
0237
0238 checked: _sideBarView.sideBar.visible
0239
0240 ToolTip.delay: 1000
0241 ToolTip.timeout: 5000
0242 ToolTip.visible: hovered
0243 ToolTip.text: i18n("Toogle SideBar")
0244 }
0245
0246 headBar.rightContent: [
0247
0248 Maui.ToolButtonMenu
0249 {
0250 icon.name: "list-add"
0251
0252
0253 MenuItem
0254 {
0255 icon.name: "applications-development"
0256 text: i18n("Create New Project")
0257
0258 onTriggered:
0259 {
0260 openFileDialog()
0261 control.close()
0262 }
0263 }
0264
0265 MenuItem
0266 {
0267 icon.name: "folder"
0268 text: i18n("Open Project")
0269
0270 onTriggered:
0271 {
0272
0273 _dialogLoader.sourceComponent = _fileDialogComponent
0274 dialog.mode = dialog.modes.OPEN
0275 // dialog.singleSelection = true
0276 dialog.settings.filters = ["CMakeLists.txt"]
0277 dialog.callback = function (urls)
0278 {
0279 _projectManager.projectUrl = urls[0]
0280 }
0281 dialog.open()
0282 control.close()
0283 }
0284 }
0285
0286 MenuItem
0287 {
0288 icon.name: "text-plain"
0289 text: i18n("Open File")
0290
0291 onTriggered:
0292 {
0293 openFileDialog()
0294 control.close()
0295 }
0296 }
0297
0298 MenuItem
0299 {
0300 icon.name: "text-enriched"
0301 text: i18n("New Template Source File")
0302
0303 onTriggered:
0304 {
0305 openTab("")
0306 // _editorListView.currentItem.body.textFormat = TextEdit.RichText
0307 control.close()
0308 }
0309 }
0310 MenuSeparator{}
0311 MenuItem
0312 {
0313 text: i18n("Settings")
0314 icon.name: "settings-configure"
0315 onTriggered:
0316 {
0317 _dialogLoader.sourceComponent = _settingsDialogComponent
0318 dialog.open()
0319 }
0320 }
0321
0322 MenuItem
0323 {
0324 text: i18n("About")
0325 icon.name: "documentinfo"
0326 onTriggered: root.about()
0327 }
0328 }
0329 ]
0330
0331 headBar.middleContent: Widgets.BuildBar
0332 {
0333 Layout.fillWidth: true
0334 Layout.alignment: Qt.AlignCenter
0335 Layout.maximumWidth: 300
0336 Layout.minimumWidth: 0
0337 }
0338
0339 }
0340 }
0341
0342 Connections
0343 {
0344 target: Strike.Strike
0345 function onOpenFiles(urls)
0346 {
0347 for(var i in urls)
0348 editorView.openTab(urls[i])
0349 }
0350 }
0351
0352 function syncSidebar(path)
0353 {
0354 if(path && FB.FM.fileExists(path))
0355 {
0356 _drawer.browser.openFolder(FB.FM.fileDir(path))
0357 }
0358 }
0359
0360 function openFileDialog()
0361 {
0362 _dialogLoader.sourceComponent = _fileDialogComponent
0363 dialog.mode = dialog.modes.OPEN
0364 dialog.callback = function (urls)
0365 {
0366 for(var url of urls)
0367 {
0368 editorView.openTab(url)
0369 }
0370 }
0371 dialog.open()
0372 }
0373 }