MainView.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.4
  3. import org.semlanik.nicegit 1.0
  4. FocusScope {
  5. id: root
  6. property var commitsForDiff: null
  7. property bool controlActive: false
  8. focus: true
  9. TopBar {
  10. id: topBar
  11. onCloseClicked: {
  12. commitPlane.diff = null
  13. commitPlane.commit = null
  14. commitList.state = "full"
  15. commitList.activeCommit = null
  16. }
  17. closeVisible: commitPlane.diff != null
  18. }
  19. Rectangle {
  20. id: bg
  21. color: "#eeeeee"
  22. anchors.fill: commitList
  23. }
  24. CommitList {
  25. id: commitList
  26. anchors.top: topBar.bottom
  27. anchors.bottom: consoleContol.top
  28. anchors.left: parent.left
  29. commitsModel: _handler.commits
  30. graphModel: _handler.graph
  31. onCommitClicked: {
  32. if(commit.diff == null) {
  33. commitPlane.commit = null
  34. commitPlane.diff = null
  35. commitList.state = "full"
  36. return
  37. }
  38. commitList.state = "commitsOnly"
  39. if(!root.controlActive) {
  40. commitPlane.commit = commit
  41. root.commitsForDiff=[]
  42. } else {
  43. console.log("root.controlActive: " + root.controlActive)
  44. if(root.commitsForDiff === null) {
  45. root.commitsForDiff = new Array(0);
  46. }
  47. console.log("Length" + root.commitsForDiff.length)
  48. root.commitsForDiff.push(commit)
  49. if(root.commitsForDiff.length === 2) {
  50. commitPlane.commit = root.commitsForDiff[1]
  51. commitPlane.diff = _handler.diff(root.commitsForDiff[0], root.commitsForDiff[1])
  52. root.commitsForDiff=[]
  53. }
  54. }
  55. }
  56. }
  57. CommitPlane {
  58. id: commitPlane
  59. anchors.left: commitList.right
  60. anchors.right: parent.right
  61. anchors.top: topBar.bottom
  62. anchors.bottom: consoleContol.top
  63. // visible: diff != null
  64. // opacity: diff != null ? 1.0 : 0.0
  65. }
  66. ConsoleControl {
  67. id: consoleContol
  68. anchors.left: parent.left
  69. anchors.right: parent.right
  70. anchors.bottom: parent.bottom
  71. }
  72. Keys.onPressed: {
  73. event.accepted = true
  74. switch(event.key) {
  75. case Qt.Key_Control:
  76. root.controlActive = true
  77. console.log("control pressed")
  78. break
  79. case Qt.Key_F4:
  80. consoleContol.state = consoleContol.state === "closed" ? "opened" : "closed"
  81. break
  82. default:
  83. event.accepted = false
  84. }
  85. }
  86. Keys.onReleased: {
  87. if(event.key === Qt.Key_Control) {
  88. root.controlActive = false
  89. console.log("control released");
  90. }
  91. }
  92. Tooltip {
  93. }
  94. }