Warning, /maui/bonsai/src/views/ProjectView.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.15
0002 import QtQuick.Controls 2.15
0003 import QtQuick.Layouts 1.12
0004 
0005 import org.mauikit.controls 1.3 as Maui
0006 import org.mauikit.filebrowsing 1.3 as FB
0007 import org.mauikit.texteditor 1.0 as TE
0008 import org.mauikit.terminal 1.0 as Term
0009 
0010 import org.maui.bonsai 1.0 as Bonsai
0011 
0012 Maui.Page
0013 {
0014     id: control
0015 
0016     Maui.TabViewInfo.tabTitle: title
0017     Maui.TabViewInfo.tabToolTipText: url
0018 
0019     property alias project: _project
0020     property alias url : _project.url
0021 
0022     property alias dialog : _dialogLoader.item
0023 
0024     headBar.visible: false
0025 
0026     Bonsai.Project
0027     {
0028         id: _project
0029 
0030         onActionFinished:
0031         {
0032             root.notify("dialog-warning", ok ? i18n("Action Finished") : i18n("Action Failed"), message)
0033         }
0034     }
0035 
0036     title: project.title
0037     showTitle: false
0038 
0039     footBar.leftContent: Maui.ToolActions
0040     {
0041         id: _actionViews
0042         expanded: true
0043         autoExclusive: true
0044         display: ToolButton.IconOnly
0045 
0046         Action
0047         {
0048             icon.name: "deep-history"
0049             text: i18n("Commits")
0050             checked:  _stackView.depth === 1
0051             onTriggered: _stackView.pop()
0052         }
0053 
0054         Action
0055         {
0056             icon.name: "folder"
0057             text: i18n("Browser")
0058             checked:  _stackView.depth === 2
0059             onTriggered:
0060             {
0061                 if(_stackView.depth === 1)
0062                 {
0063                     _stackView.push(_browserViewComponent)
0064                 }
0065             }
0066         }
0067     }
0068 
0069     footBar.rightContent: [
0070 
0071 
0072         ToolButton
0073         {
0074             icon.name: "folder-remote"
0075             onClicked:
0076             {
0077                 _dialogLoader.sourceComponent = _remoteDialogComponent
0078                 control.dialog.open()
0079             }
0080         },
0081 
0082         Switch{},
0083 
0084         ToolButton
0085         {
0086             visible: String(_project.readmeFile).length > 0
0087             icon.name: "documentinfo"
0088             onClicked:
0089             {
0090                 _dialogLoader.sourceComponent = _readmeDialogComponent
0091                 control.dialog.open()
0092             }
0093         }
0094     ]
0095 
0096     Loader
0097     {
0098         id: _dialogLoader
0099     }
0100 
0101     Component
0102     {
0103         id: _remoteDialogComponent
0104 
0105         Maui.PopupPage
0106         {
0107             persistent: false
0108             maxWidth: 800
0109             maxHeight: 600
0110 
0111             page.content: Maui.ProgressIndicator
0112             {
0113                 width: parent.width
0114                 anchors.bottom: parent.bottom
0115                 visible:  _project.remotesModel.status === Bonsai.RemotesModel.Loading
0116             }
0117 
0118             Repeater
0119             {
0120                 model: _project.remotesModel
0121                 delegate:  Maui.SectionGroup
0122                 {
0123                     title: model.name
0124 
0125                     Maui.SectionItem
0126                     {
0127                         label1.text: i18n("Default Branch")
0128                         label2.text: model.headBranch
0129                     }
0130 
0131                     Maui.SectionItem
0132                     {
0133                         label1.text: i18n("Push Url")
0134                         label2.text: model.pushUrl
0135                     }
0136 
0137                     Maui.SectionItem
0138                     {
0139                         label1.text: i18n("Fetch Url")
0140                         label2.text: model.fetchUrl
0141                     }
0142                 }
0143             }
0144 
0145 
0146         }
0147     }
0148 
0149     Component
0150     {
0151         id: _readmeDialogComponent
0152 
0153         Maui.PopupPage
0154         {
0155             maxHeight: 800
0156             maxWidth: 900
0157 
0158             hint: 1
0159             title: "README.MD"
0160             stack: TE.TextEditor
0161             {
0162                 Layout.fillWidth: true
0163                 Layout.fillHeight: true
0164                 fileUrl: _project.readmeFile
0165                 //                    document.isRich: true
0166                 body.textFormat: TextEdit.MarkdownText
0167                 body.readOnly: true
0168             }
0169         }
0170     }
0171 
0172     Component
0173     {
0174         id: _commitInfoDialogComponent
0175         CommitInfoDialog
0176         {
0177 
0178         }
0179     }
0180 
0181     Maui.Holder
0182     {
0183         anchors.fill: parent
0184         title:
0185         {
0186             switch(project.status.code)
0187             {
0188             case Bonsai.StatusMessage.Loading: return i18n("Loading...");
0189             case Bonsai.StatusMessage.Error: return i18n("Error");
0190             }
0191         }
0192 
0193         emoji: "indicator-messages"
0194         body: project.status.message
0195     }
0196 
0197     StackView
0198     {
0199         id: _stackView
0200         anchors.fill: parent
0201 
0202         clip: true
0203         visible: project.status.code === Bonsai.StatusMessage.Ready
0204 
0205         initialItem: Maui.Page
0206         {
0207 
0208             headBar.forceCenterMiddleContent: root.isWide
0209             headBar.middleContent: Maui.SearchField
0210             {
0211                 Layout.alignment: Qt.AlignCenter
0212                 Layout.maximumWidth: 500
0213                 Layout.fillWidth: true
0214                 placeholderText: i18n("Filter commit by id, message or author")
0215                 onAccepted: _commitsListView.model.filters = text.split(",")
0216                 onCleared: _commitsListView.model.clearFilters()
0217             }
0218 
0219             headBar.rightContent: Maui.ToolButtonMenu
0220             {
0221                 icon.name: "view-sort"
0222                 autoExclusive: true
0223 
0224                 MenuItem
0225                 {
0226                     text: i18n("Author")
0227                 }
0228 
0229                 MenuItem
0230                 {
0231                     text: i18n("Date")
0232                 }
0233 
0234                 MenuSeparator{}
0235 
0236                 MenuItem
0237                 {
0238                     text: i18n("Asc")
0239                 }
0240 
0241                 MenuItem
0242                 {
0243                     text: i18n("Desc")
0244                 }
0245             }
0246 
0247             Maui.ListBrowser
0248             {
0249                 id: _commitsListView
0250                 currentIndex: -1
0251                 anchors.fill: parent
0252 
0253                 flickable.header: Column
0254                 {
0255                     width: parent.width
0256 
0257                     Maui.SectionHeader
0258                     {
0259                         topPadding: Maui.Style.space.big
0260                         bottomPadding: topPadding + _commitsListView.topPadding
0261                         padding: _commitsListView.padding
0262 
0263                         width: parent.width
0264                         template.imageSource: _project.logo
0265                         template.imageSizeHint: Maui.Style.iconSizes.big
0266 
0267                         label1.text: _project.title
0268                         label2.text: _project.currentBranch
0269                         //                        template.label3.text: _project.currentBranchRemote.name
0270                         //                        template.label4.text: _project.currentBranchRemote.url
0271 
0272                         template.content:[ Maui.GridItemTemplate
0273                             {
0274                                 implicitWidth: 58
0275                                 //                            implicitHeight: 64
0276 
0277                                 iconSource: "vcs-commit"
0278                                 iconSizeHint: Maui.Style.iconSizes.small
0279                                 label1.text:  _commitsListView.count
0280                                 label1.font.pointSize: Maui.Style.fontSizes.small
0281                             },
0282                             Maui.GridItemTemplate
0283                             {
0284                                 implicitWidth: 58
0285                                 iconVisible: true
0286                                 //                            implicitHeight: 64
0287 
0288                                 iconSizeHint: Maui.Style.iconSizes.small
0289 
0290                                 iconSource: "vcs-branch"
0291                                 label1.text:   _project.allBranches.length
0292                                 label1.font.pointSize: Maui.Style.fontSizes.small
0293                             }
0294 
0295                         ]
0296                     }
0297                 }
0298 
0299                 Maui.ProgressIndicator
0300                             {
0301                                 width: parent.width
0302                                 anchors.bottom: parent.bottom
0303                                 visible:  _project.commitsModel.status === Bonsai.CommitsModel.Loading
0304                             }
0305 
0306 
0307                 model: project.commitsModel
0308 
0309                 delegate: Maui.ListBrowserDelegate
0310                 {
0311                     isCurrentItem: ListView.isCurrentItem
0312                     width: ListView.view.width
0313                     height:  ListView.isCurrentItem ? implicitHeight : Math.min(100, implicitHeight)
0314                     label1.text: model.subject
0315                     label3.text: model.hash
0316                     label2.text: model.author
0317                     label4.text: Qt.formatDateTime(model.date, "dd MM yyyy")
0318                     rightLabels.visible: true
0319 
0320                     onClicked:
0321                     {
0322                         _commitsListView.currentIndex = index
0323                     }
0324 
0325                     onDoubleClicked:
0326                     {
0327                         _commitsListView.currentIndex = index
0328                         openCommitInfoDialog(model.hash)
0329                     }
0330 
0331 
0332                     onRightClicked:
0333                     {
0334                         _commitsListView.currentIndex = index
0335                         _commitMenu.show()
0336                     }
0337                 }
0338 
0339                 Maui.ContextualMenu
0340                 {
0341                     id: _commitMenu
0342 
0343                     MenuItem
0344                     {
0345                         text: i18n("Checkout")
0346                     }
0347 
0348                     MenuItem
0349                     {
0350                         text: i18n("Info")
0351                         onTriggered: openCommitInfoDialog(_commitsModel.get(_commitsListView.currentIndex).id)
0352                     }
0353 
0354 
0355                     MenuItem
0356                     {
0357                         text: i18n("Copy ID")
0358                         onTriggered: Maui.Handy.copyTextToClipboard(_commitsModel.get(_commitsListView.currentIndex).id)
0359                     }
0360                 }
0361             }
0362         }
0363 
0364         Component
0365         {
0366             id:  _browserViewComponent
0367 
0368             Maui.Page
0369             {
0370                 id: _browserView
0371                 title: _browser.title
0372                 showTitle: true
0373 
0374                 FB.FileBrowser
0375                 {
0376                     id: _browser
0377                     anchors.fill: parent
0378                     currentPath: control.project.url
0379                     onItemClicked: openItem(index)
0380                     settings.viewType: FB.FMList.LIST_VIEW
0381                     settings.showHiddenFiles: true
0382                     browser.delegateInjector: Rectangle
0383                     {
0384                         radius: Maui.Style.radiusV
0385                         color: Maui.Theme.backgroundColor
0386 
0387                         Maui.Icon
0388                         {
0389                             visible: itemData.isdir
0390                             source: _project.fileStatusIcon(itemData.url)
0391                             anchors.centerIn: parent
0392                         }
0393                     }
0394                 }
0395 
0396                 headBar.leftContent: [
0397 
0398                     ToolButton
0399                     {
0400                         visible: _browser.currentPath !== control.project.url
0401                         icon.name: "go-up"
0402                         onClicked:
0403                         {
0404                             _browser.goUp()
0405                         }
0406                     }
0407 
0408                 ]
0409 
0410                 headBar.rightContent: [
0411 
0412                     Maui.ToolButtonMenu
0413                     {
0414                         icon.name: "list-add"
0415                         MenuItem
0416                         {
0417                             text: i18n("New Branch")
0418                             icon.name: "branch"
0419                         }
0420 
0421                         MenuItem
0422                         {
0423                             text: i18n("New Tag")
0424                             icon.name: "tag"
0425                         }
0426 
0427                         MenuSeparator{}
0428 
0429                         MenuItem
0430                         {
0431                             text: i18n("New File")
0432                             icon.name: "document-new"
0433                         }
0434                     }
0435 
0436                 ]
0437 
0438                 footBar.rightContent: ToolButtonOp
0439                     {
0440                         id: _switchButton
0441                         icon.name: "vcs-branch"
0442                         text: i18n("Switch: %1", selectedBranch)
0443                         property string selectedBranch : _project.currentBranch
0444 
0445                         onClicked:
0446                         {
0447                             _project.checkout(selectedBranch)
0448                         }
0449 
0450                         Repeater
0451                         {
0452                             model: _project.allBranches
0453                             MenuItem
0454                             {
0455                                 autoExclusive: true
0456                                 checked: _project.currentBranch === text
0457                                 text: modelData
0458                                 onTriggered: _switchButton.selectedBranch = text
0459                             }
0460                         }
0461 
0462                         MenuSeparator{}
0463 
0464                         MenuItem
0465                         {
0466                             id: _forceOption
0467                             text: i18n("Force")
0468                         }
0469 
0470                         MenuItem
0471                         {
0472                             id: _remote
0473                             text: i18n("Remote")
0474                         }
0475                     }
0476 
0477                 footBar.leftContent: [
0478 
0479                     ToolButtonOp
0480                     {
0481                         id: _pullOp
0482                         icon.name: "vcs-pull"
0483                         text: i18n("Pull")
0484                         display: ToolButton.TextBesideIcon
0485 
0486 
0487                         property string remote : control.project.headBranch.remote
0488                         property string branch: control.project.headBranch.name
0489 
0490                         onClicked:
0491                         {
0492                             control.project.pull(remote, branch)
0493                         }
0494 
0495                         Menu
0496                         {
0497                             title: i18n("Branch")
0498                             Repeater
0499                             {
0500                                 model: control.project.allBranches
0501                                 delegate: MenuItem
0502                                 {
0503                                     autoExclusive: true
0504                                     text: modelData
0505                                     checkable: true
0506                                     checked: modelData === _pullOp.branch
0507                                 }
0508 
0509                             }
0510                         }
0511 
0512                         Menu
0513                         {
0514                             title: i18n("Remote")
0515                             Repeater
0516                             {
0517                                 model: control.project.remoteBranches
0518                                 delegate: MenuItem
0519                                 {
0520                                     autoExclusive: true
0521                                     text: modelData
0522                                     checkable: true
0523                                     checked: modelData === _pullOp.remote
0524                                 }
0525 
0526                             }
0527                         }
0528 
0529                         MenuSeparator {}
0530 
0531                         Column
0532                         {
0533                             width: ListView.view.width
0534                             spacing: Maui.Style.defaultSpacing
0535                             MenuItem
0536                             {
0537                                 width: parent.width
0538                                 text: i18n("No Commit")
0539                                 checkable: true
0540                             }
0541 
0542                             MenuItem
0543                             {
0544                                 width: parent.width
0545                                 text: i18n("Prune")
0546                                 checkable: true
0547                             }
0548 
0549                             MenuItem
0550                             {
0551                                 width: parent.width
0552                                 text: i18n("Tags")
0553                                 checkable: true
0554 
0555                             }
0556 
0557                             MenuItem
0558                             {
0559                                 width: parent.width
0560                                 text: i18n("Squash")
0561                                 checkable: true
0562                             }
0563                         }
0564 
0565                         MenuSeparator{}
0566 
0567                         Menu
0568                         {
0569                             title: i18n("Rebase")
0570 
0571                             MenuItem
0572                             {
0573                                 text: i18n("Unset")
0574                                 checkable: true
0575                                 autoExclusive: true
0576                             }
0577 
0578                             MenuItem
0579                             {
0580                                 text: i18n("Yes")
0581                                 checkable: true
0582                                 autoExclusive: true
0583                             }
0584 
0585                             MenuItem
0586                             {
0587                                 text: i18n("No")
0588                                 checkable: true
0589                                 autoExclusive: true
0590                             }
0591 
0592                             MenuItem
0593                             {
0594                                 text: i18n("Only")
0595                                 checkable: true
0596                                 autoExclusive: true
0597                             }
0598                         }
0599 
0600                         Menu
0601                         {
0602                             title: i18n("Fast Forward")
0603 
0604                             MenuItem
0605                             {
0606                                 text: i18n("Unset")
0607                                 checkable: true
0608                                 autoExclusive: true
0609                             }
0610 
0611                             MenuItem
0612                             {
0613                                 text: i18n("Yes")
0614                                 checkable: true
0615                                 autoExclusive: true
0616                             }
0617 
0618                             MenuItem
0619                             {
0620                                 text: i18n("No")
0621                                 checkable: true
0622                                 autoExclusive: true
0623                             }
0624 
0625                             MenuItem
0626                             {
0627                                 text: i18n("Only")
0628                                 checkable: true
0629                                 autoExclusive: true
0630                             }
0631                         }
0632                     },
0633 
0634                     ToolButton
0635                     {
0636                         icon.name: "vcs-pull"
0637                     },
0638 
0639                     ToolButton
0640                     {
0641                         icon.name: "vcs-push"
0642                     },
0643 
0644                     ToolButton
0645                     {
0646                         icon.name: "vcs-merge"
0647                     },
0648 
0649                     ToolButton
0650                     {
0651                         icon.name: "vcs-commit"
0652                     },
0653                     ToolButton
0654                     {
0655                         icon.name: "vcs-diff"
0656                     },
0657 
0658                     ToolButtonOp
0659                     {
0660                         icon.name: "vcs-stash"
0661                         text: i18n("Stash")
0662 
0663                         onClicked: _project.stash()
0664                     },
0665 
0666                     ToolButtonOp
0667                     {
0668                         icon.name: "vcs-stash-pop"
0669                         text: i18n("Stash Pop")
0670 
0671                         onClicked: runCommand("git stash pop")
0672                     }
0673 
0674                 ]
0675             }
0676         }
0677     }
0678 
0679 
0680     Maui.ProgressIndicator
0681     {
0682         width: parent.width
0683         visible: project.status.code === Bonsai.StatusMessage.Loading
0684         anchors.bottom: parent.bottom
0685     }
0686 
0687     function openCommitInfoDialog(id)
0688     {
0689         _dialogLoader.sourceComponent = _commitInfoDialogComponent
0690         control.dialog.commitId = id
0691         control.dialog.open()
0692     }
0693 
0694     function runCommand(command)
0695     {
0696         if(_terminal.session.hasActiveProcess)
0697         {
0698             return;
0699         }
0700 
0701         _terminal.session.sendText(command+ "\n")
0702     }
0703 }