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

0001 import QtQuick 2.15
0002 import QtQuick.Controls 2.14
0003 import QtQuick.Layouts 1.3
0004 
0005 import Qt.labs.settings 1.0
0006 import org.mauikit.controls 1.3 as Maui
0007 import org.mauikit.terminal 1.0 as Term
0008 
0009 import org.maui.station 1.0 as Station
0010 
0011 import "widgets"
0012 
0013 Maui.ApplicationWindow
0014 {
0015     id: root
0016 
0017     Maui.Style.styleType: settings.colorStyle
0018 
0019     title: currentTerminal? currentTerminal.session.title : ""
0020 
0021     readonly property alias dialog : _dialogLoader.item
0022     readonly property alias currentTab : _layout.currentItem
0023 
0024     readonly property Term.Terminal currentTerminal : currentTab.currentItem.terminal
0025     readonly property font defaultFont : Maui.Style.monospacedFont
0026     readonly property alias currentTabIndex : _layout.currentIndex
0027 
0028     Maui.WindowBlur
0029     {
0030         view: root
0031         geometry: Qt.rect(root.x, root.y, root.width, root.height)
0032         windowRadius: Maui.Style.radiusV
0033         enabled: !Maui.Handy.isMobile && settings.windowTranslucency
0034     }
0035 
0036     property bool discard : !settings.preventClosing
0037     onClosing: (close) =>
0038     {
0039         // _dialogLoader.sourceComponent = null
0040         close.accepted = !settings.restoreSession
0041         root.saveSession()
0042 
0043         _dialogLoader.sourceComponent = _confirmCloseDialogComponent
0044 
0045         if(anyTabHasActiveProcess() && !root.discard)
0046         {
0047             close.accepted = false
0048 
0049             dialog.index = -1
0050             dialog.cb =  ()=> {root.discard = true; root.close();}
0051             close.accepted = false
0052             dialog.open()
0053             return
0054         }
0055 
0056         close.accepted = true
0057     }
0058 
0059     Settings
0060     {
0061         id: settings
0062         property string colorScheme: "Maui-Dark"
0063 
0064         property int lineSpacing : 0
0065         property int historySize : -1
0066 
0067         property font font : defaultFont
0068         property int keysModelCurrentIndex : 4
0069         property int colorStyle : Maui.Style.Dark
0070 
0071         property double windowOpacity: 0.6
0072         property bool windowTranslucency: false
0073 
0074         property bool adaptiveColorScheme : true
0075         property bool preventClosing: true
0076         property bool alertProcess: true
0077 
0078         property bool enableBold: true
0079         property bool blinkingCursor: true
0080         property bool fullCursorHeight: true
0081         property bool antialiasText: true
0082 
0083         property bool showSignalBar: false
0084         property bool watchForSilence: false
0085 
0086         property bool restoreSession : false
0087         property var lastSession: []
0088         property int lastTabIndex : 0
0089         property int tabTitleStyle: Terminal.TabTitle.Auto
0090     }
0091 
0092     Loader
0093     {
0094         id: _dialogLoader
0095     }
0096 
0097     Component
0098     {
0099         id: _tutorialDialogComponent
0100         TutorialDialog {}
0101     }
0102 
0103     Component
0104     {
0105         id: _settingsDialogComponent
0106         SettingsDialog {}
0107     }
0108 
0109     Maui.Page
0110     {
0111         anchors.fill: parent
0112         headBar.visible: false
0113 
0114         background: Rectangle
0115         {
0116             color: Maui.Theme.backgroundColor
0117             opacity: _layout.count === 0 ? 1 : 0
0118         }
0119 
0120         Maui.TabView
0121         {
0122             id: _layout
0123 
0124             background: null
0125 
0126             altTabBar: Maui.Handy.isMobile
0127 
0128             anchors.fill: parent
0129 
0130             onNewTabClicked: root.openTab("$PWD")
0131             onCloseTabClicked:(index) => root.closeTab(index)
0132 
0133             tabBar.showNewTabButton: false
0134             tabBar.visible: true
0135             tabBar.background: Rectangle
0136             {
0137                 color: Maui.Theme.backgroundColor
0138                 opacity: settings.windowTranslucency ? settings.windowOpacity : 1
0139             }
0140 
0141             tabBar.content: [
0142 
0143                 ToolButton
0144                 {
0145                     icon.name: "edit-find"
0146                     checked: root.currentTerminal.footBar.visible
0147                     onClicked: root.currentTerminal.toggleSearchBar()
0148                 },
0149 
0150                 Maui.ToolButtonMenu
0151                 {
0152                     icon.name: "list-add"
0153 
0154                     MenuItem
0155                     {
0156                         icon.name: "tab-new"
0157                         text: i18n("New Tab")
0158                         onTriggered: root.openTab("$PWD")
0159                     }
0160 
0161                     MenuItem
0162                     {
0163                         enabled: root.currentTab
0164                         checked: root.currentTab && root.currentTab.count === 2
0165                         text: i18n("Split")
0166 
0167                         icon.name: root.currentTab.orientation === Qt.Horizontal ? "view-split-left-right" : "view-split-top-bottom"
0168                         onTriggered: root.currentTab.split()
0169                     }
0170 
0171                     MenuSeparator {}
0172 
0173                     MenuItem
0174                     {
0175                         text: i18n("Tutorial")
0176                         onTriggered:
0177                         {
0178                             _dialogLoader.sourceComponent = _tutorialDialogComponent
0179                             dialog.open()
0180                         }
0181                         icon.name : "help-contents"
0182                     }
0183 
0184                     MenuItem
0185                     {
0186                         icon.name: "settings-configure"
0187                         text: i18n("Settings")
0188                         onTriggered:
0189                         {
0190                             _dialogLoader.sourceComponent = _settingsDialogComponent
0191                             dialog.open()
0192                         }
0193                     }
0194 
0195                     MenuItem
0196                     {
0197                         text: i18n("About")
0198                         icon.name: "documentinfo"
0199                         onTriggered: root.about()
0200                     }
0201                 },
0202 
0203                 Maui.WindowControls {}
0204             ]
0205 
0206             holder.visible: _layout.count === 0
0207             holder.emoji: "terminal-symbolic"
0208             holder.title: i18n("Nothing here")
0209             holder.body: i18n("To start hacking open a new tab or a split screen.")
0210             holder.actions: Action
0211             {
0212                 text: i18n("New Tab")
0213                 onTriggered: root.openTab("$PWD")
0214             }
0215         }
0216 
0217         footBar.visible: true
0218 
0219         footBar.farRightContent: Loader
0220         {
0221             asynchronous: true
0222             sourceComponent: Maui.ToolButtonMenu
0223             {
0224                 icon.name: "overflow-menu"
0225                 MenuItem
0226                 {
0227                     text: i18n("Function Keys")
0228                     autoExclusive: true
0229                     checked: settings.keysModelCurrentIndex === 0
0230                     checkable: true
0231                     onTriggered: settings.keysModelCurrentIndex = 0
0232                 }
0233 
0234                 MenuItem
0235                 {
0236                     text: i18n("Nano")
0237                     autoExclusive: true
0238                     checked: settings.keysModelCurrentIndex === 1
0239                     checkable: true
0240                     onTriggered: settings.keysModelCurrentIndex = 1
0241                 }
0242 
0243                 MenuItem
0244                 {
0245                     text: i18n("Ctrl Modifiers")
0246                     autoExclusive: true
0247                     checked: settings.keysModelCurrentIndex === 2
0248                     checkable: true
0249                     onTriggered: settings.keysModelCurrentIndex = 2
0250                 }
0251 
0252                 MenuItem
0253                 {
0254                     text: i18n("Navigation")
0255                     autoExclusive: true
0256                     checked: settings.keysModelCurrentIndex === 3
0257                     checkable: true
0258                     onTriggered: settings.keysModelCurrentIndex = 3
0259                 }
0260 
0261                 MenuItem
0262                 {
0263                     text: i18n("Favorite")
0264                     autoExclusive: true
0265                     checked: settings.keysModelCurrentIndex === 4
0266                     checkable: true
0267                     onTriggered: settings.keysModelCurrentIndex = 4
0268                 }
0269 
0270                 MenuItem
0271                 {
0272                     text: i18n("Signals")
0273                     autoExclusive: true
0274                     checked: settings.keysModelCurrentIndex === 5
0275                     checkable: true
0276                     onTriggered: settings.keysModelCurrentIndex = 5
0277                 }
0278 
0279                 MenuSeparator {}
0280 
0281                 MenuItem
0282                 {
0283                     text: i18n("More Signals")
0284                     checked: settings.showSignalBar
0285                     checkable: true
0286                     onTriggered: settings.showSignalBar = !settings.showSignalBar
0287                 }
0288             }
0289         }
0290 
0291         footerColumn: Maui.ToolBar
0292         {
0293             visible: settings.showSignalBar
0294             width: parent.width
0295             position: ToolBar.Footer
0296 
0297             Repeater
0298             {
0299                 model: _keysModel.signalsGroup
0300 
0301                 delegate:  Button
0302                 {
0303                     font.bold: true
0304                     text: modelData.label + "/ " + modelData.signal
0305 
0306                     onClicked: currentTerminal.session.sendSignal(9)
0307 
0308                     activeFocusOnTab: false
0309                     focusPolicy: Qt.NoFocus
0310                     autoRepeat: true
0311                 }
0312             }
0313         }
0314 
0315         footBar.leftContent: [
0316 
0317             ToolButton
0318             {
0319                 icon.name: "document-edit"
0320                 onClicked: openCommandDialog()
0321             },
0322 
0323             Repeater
0324             {
0325                 model: Station.KeysModel
0326                 {
0327                     id: _keysModel
0328                     group: settings.keysModelCurrentIndex
0329                 }
0330 
0331                 Button
0332                 {
0333                     font.bold: true
0334                     text: model.label
0335                     icon.name: model.iconName
0336 
0337                     onClicked: _keysModel.sendKey(index, currentTerminal.kterminal)
0338 
0339                     activeFocusOnTab: false
0340                     focusPolicy: Qt.NoFocus
0341                     autoRepeat: true
0342                 }
0343             }
0344         ]
0345     }
0346 
0347     Component
0348     {
0349         id: _terminalComponent
0350         TerminalLayout {}
0351     }
0352 
0353     Component
0354     {
0355         id: _commandDialogComponent
0356 
0357         CommandShortcuts
0358         {
0359             onCommandTriggered:
0360             {
0361                 root.currentTerminal.session.sendText(command)
0362                 root.currentTerminal.forceActiveFocus()
0363             }
0364         }
0365     }
0366 
0367     Component
0368     {
0369         id: _confirmCloseDialogComponent
0370 
0371         Maui.InfoDialog
0372         {
0373             id : _dialog
0374 
0375             property var cb : ({})
0376             property int index: -1
0377 
0378             title: i18n("Close")
0379             message: i18n("A process is still running. Are you sure you want to interrupt it and close it?")
0380 
0381             template.iconSource: "dialog-warning"
0382             template.iconVisible: true
0383             template.iconSizeHint: Maui.Style.iconSizes.huge
0384 
0385             standardButtons: Dialog.Ok | Dialog.Cancel
0386 
0387             onAccepted:
0388             {
0389                 _dialog.close()
0390 
0391                 if(cb instanceof Function)
0392                 {
0393                     cb(index)
0394                 }
0395 
0396             }
0397 
0398             onRejected:
0399             {
0400                 close()
0401             }
0402         }
0403     }
0404 
0405     Component
0406     {
0407         id: _restoreDialogComponent
0408         Maui.InfoDialog
0409         {
0410             message: i18n("Do you want to restore the previous session?")
0411             standardButtons: Dialog.Ok | Dialog.Cancel
0412             template.iconSource: "dialog-question"
0413 
0414             onAccepted:
0415             {
0416                 const tabs = settings.lastSession
0417                 if(tabs.length)
0418                 {
0419                     console.log("restore", tabs.length)
0420                     // root.closeTab(0)
0421                     restoreSession(tabs)
0422                     return
0423                 }
0424             }
0425         }
0426     }
0427 
0428     Component.onCompleted:
0429     {
0430         if(settings.restoreSession)
0431         {
0432             _dialogLoader.sourceComponent = _restoreDialogComponent
0433             dialog.open()
0434             return
0435         }
0436     }
0437 
0438     function openTab(path : string)
0439     {
0440         _layout.addTab(_terminalComponent, {'path': path});
0441         _layout.currentIndex = _layout.count -1
0442     }
0443 
0444     function closeTab(index)
0445     {
0446         var tab = _layout.tabAt(index)
0447 
0448         if(tab && tab.hasActiveProcess && settings.preventClosing)
0449         {
0450             _dialogLoader.sourceComponent = _confirmCloseDialogComponent
0451             dialog.index = index
0452             dialog.cb = _layout.closeTab
0453             dialog.open()
0454             return;
0455         }
0456 
0457         _layout.closeTab(index)
0458     }
0459 
0460     function openCommandDialog()
0461     {
0462         _dialogLoader.sourceComponent = _commandDialogComponent
0463         dialog.open()
0464     }
0465 
0466     function anyTabHasActiveProcess()
0467     {
0468         for(var i = 0; i++; i < _layout.count)
0469         {
0470             let tab = _layout.tabAt(i)
0471             if(tab && tab.hasActiveProcess)
0472             {
0473                 return true;
0474             }
0475         }
0476 
0477         return false;
0478     }
0479 
0480     function saveSession()
0481     {
0482         var tabs = [];
0483 
0484         for(var i = 0; i < _layout.count; i ++)
0485         {
0486             var tab = _layout.contentModel.get(i)
0487             var tabPaths = []
0488 
0489             for(var j = 0; j < tab.count; j ++)
0490             {
0491                 const term = tab.contentModel.get(j)
0492                 var path = String(term.session.currentDir)
0493                 const tabMap = {'path': path}
0494 
0495                 tabPaths.push(tabMap)
0496             }
0497 
0498             tabs.push(tabPaths)
0499         }
0500 
0501         settings.lastSession = tabs
0502         console.log("Saving Session", settings.lastSession.length)
0503 
0504         // settings.lastTabIndex = currentTabIndex
0505     }
0506 
0507     function restoreSession(tabs)
0508     {
0509         console.log("TRYING TO RESTORE SESSION",tabs )
0510 
0511 
0512         for(var i = 0; i < tabs.length; i++ )
0513         {
0514             const tab = tabs[i]
0515 
0516             if(tab.length === 2)
0517             {
0518                 root.openTab(tab[0].path, tab[1].path)
0519             }else
0520             {
0521                 console.log("TRYING TO RESTORE SESSION", tab[0].path)
0522                 root.openTab(tab[0].path)
0523             }
0524         }
0525 
0526         // currentTabIndex = settings.lastTabIndex
0527     }
0528 }