Warning, /maui/nota/src/main.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.14
0002 import QtQuick.Controls 2.14
0003 
0004 import Qt.labs.settings 1.0
0005 
0006 import org.mauikit.controls 1.3 as Maui
0007 import org.mauikit.filebrowsing 1.3 as FB
0008 
0009 import org.maui.nota 1.0 as Nota
0010 
0011 import "views"
0012 import "views/editor"
0013 import "views/widgets" as Widgets
0014 
0015 Maui.ApplicationWindow
0016 {
0017     id: root
0018 
0019 //    title: currentEditor ? currentTab.title : ""
0020     Maui.Style.styleType: Maui.Handy.isAndroid ? (appSettings.darkMode ? Maui.Style.Dark : Maui.Style.Light) : undefined
0021 
0022 //    readonly property alias currentTab : editorView.currentTab
0023 //    readonly property alias currentEditor: editorView.currentEditor
0024     readonly property alias dialog : _dialogLoader.item
0025 
0026     readonly property font defaultFont : Maui.Style.monospacedFont
0027     readonly property alias appSettings: settings
0028 
0029     property bool focusMode : false
0030     //    Maui.WindowBlur
0031     //    {
0032     //        view: root
0033     //        geometry: Qt.rect(root.x, root.y, root.width, root.height)
0034     //        windowRadius: Maui.Style.radiusV
0035     //        enabled: !Maui.Handy.isMobile
0036     //    }
0037 
0038     Settings
0039     {
0040         id: settings
0041 
0042         property bool enableSidebar : false
0043         property bool showLineNumbers : true
0044         property bool showWordCount: false
0045         property bool autoSave : true
0046         property bool enableSyntaxHighlighting : true
0047         property bool showSyntaxHighlightingLanguages: false
0048         property bool supportSplit :true
0049         property double tabSpace: 8
0050         property string theme : ""
0051         property string backgroundColor : "white"
0052         property string textColor : "black"
0053         property bool darkMode : Maui.Style.styleType === Maui.Style.Dark
0054         property alias sideBarWidth : _sideBarView.sideBar.preferredWidth
0055         property font font : defaultFont
0056         property bool syncTerminal: true
0057          property bool terminalFollowsColorScheme: true
0058         property string terminalColorScheme: "Maui-Dark"
0059     }
0060 
0061 //    onCurrentEditorChanged: syncSidebar(currentEditor.fileUrl)
0062 
0063     onClosing: (close) =>
0064     {
0065         _dialogLoader.sourceComponent = _unsavedDialogComponent
0066 
0067         dialog.callback = function () {root.close()}
0068 
0069         if(!dialog.discard)
0070         {
0071             for(var i = 0; i < editorView.count; i++)
0072             {
0073                 if(editorView.tabHasUnsavedFiles(i))
0074                 {
0075                     close.accepted = false
0076                     dialog.open()
0077                     return
0078                 }
0079             }
0080         }
0081 
0082         close.accepted = true
0083     }
0084 
0085     Nota.History
0086     {
0087         id: historyList
0088     }
0089 
0090     Component
0091     {
0092         id: _plugingsDialogComponent
0093 
0094         Widgets.PluginsDialog {}
0095     }
0096     Loader
0097     {
0098         id: _dialogLoader
0099     }
0100 
0101     Component
0102     {
0103         id: _unsavedDialogComponent
0104 
0105         Maui.InfoDialog
0106         {
0107             property bool discard : false
0108             property var callback : ({})
0109 
0110             title: i18n("Unsaved files")
0111             message: i18n("You have unsaved files. You can go back and save them or choose to discard all changes and exit.")
0112 
0113             template.iconSource: "dialog-warning"
0114             template.iconVisible: true
0115 
0116             standardButtons: Dialog.Ok | Dialog.Discard
0117             onDiscarded:
0118             {
0119                 discard = true
0120                 close()
0121 
0122                 if(callback instanceof Function)
0123                 {
0124                     callback()
0125                 }
0126             }
0127             onAccepted: close()
0128         }
0129     }
0130 
0131     Component
0132     {
0133         id: _settingsDialogComponent
0134         Widgets.SettingsDialog {}
0135     }
0136 
0137     Component
0138     {
0139         id: _shortcutsDialogComponent
0140         Widgets.ShortcutsDialog {}
0141     }
0142 
0143     Component
0144     {
0145         id: _fileDialogComponent
0146         FB.FileDialog
0147         {
0148             settings.onlyDirs: false
0149             settings.filterType: FB.FMList.TEXT
0150             settings.sortBy: FB.FMList.MODIFIED
0151         }
0152     }
0153 
0154     Component
0155     {
0156         id: _tagsDialogComponent
0157         FB.TagsDialog
0158         {
0159             onTagsReady: composerList.updateToUrls(tags)
0160             composerList.strict: false
0161             taglist.strict: false
0162         }
0163     }
0164 
0165     StackView
0166     {
0167         id: _stackView
0168         anchors.fill: parent
0169 
0170         Keys.enabled: true
0171         Keys.onEscapePressed: _stackView.pop()
0172 
0173         initialItem: Maui.SideBarView
0174         {
0175             id: _sideBarView
0176             sideBar.enabled: settings.enableSidebar
0177             sideBar.autoHide: true
0178             sideBar.autoShow: false
0179             sideBarContent: PlacesSidebar
0180             {
0181                 id : _drawer
0182                 anchors.fill: parent
0183             }
0184 
0185             EditorView
0186             {
0187                 id: editorView
0188                 anchors.fill: parent
0189             }
0190         }
0191 
0192         Component
0193         {
0194             id: historyViewComponent
0195 
0196             RecentView {}
0197         }
0198     }
0199 
0200     Component.onCompleted:
0201     {
0202         setAndroidStatusBarColor()
0203     }
0204 
0205     function setAndroidStatusBarColor()
0206     {
0207         if(Maui.Handy.isAndroid)
0208         {
0209             Maui.Android.statusbarColor(Maui.Theme.backgroundColor, !appSettings.darkMode)
0210             Maui.Android.navBarColor(Maui.Theme.backgroundColor, !appSettings.darkMode)
0211         }
0212     }
0213 
0214     function syncSidebar(path)
0215     {
0216         if(path && FB.FM.fileExists(path) && settings.enableSidebar)
0217         {
0218             _drawer.page.browser.openFolder(FB.FM.fileDir(path))
0219         }
0220     }
0221 
0222     function openFileDialog()
0223     {
0224         _dialogLoader.sourceComponent = _fileDialogComponent
0225         dialog.mode = dialog.modes.OPEN
0226 
0227         if(root.currentEditor && editorView.currentFileExistsLocally)
0228             dialog.currentPath = FB.FM.fileDir(root.currentEditor.fileUrl)
0229 
0230         dialog.callback = (urls) =>
0231         {
0232             console.log("ASKIGN TO OPEN URLS", urls)
0233             root.openFiles(urls)
0234         }
0235         dialog.open()
0236     }
0237 
0238     function activateWindow()
0239     {
0240         console.log("RAISE WINDOW FORM QML")
0241         root.raise()
0242         //        root.requ
0243     }
0244 
0245     function openFile(url : string)
0246     {
0247         editorView.openTab(url)
0248     }
0249 
0250     function openFiles(urls : variant)
0251     {
0252         for(var url of urls)
0253         {
0254             root.openFile(url)
0255         }
0256     }
0257 
0258     function openTab()
0259     {
0260         editorView.openTab("")
0261     }
0262 
0263     function isUrlOpen(url : string) : bool
0264     {
0265         return editorView.isUrlOpen(url)
0266     }
0267 
0268         function focusFile(url : string)
0269         {
0270         editorView.openTab(url)
0271     }
0272     }