MainView.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 == null) {
  33. commitPlane.commit = null
  34. commitPlane.diff = _handler.diff()
  35. commitList.state = "commitsOnly"
  36. return;
  37. }
  38. if(commit.diff === null) {
  39. commitPlane.commit = null
  40. commitPlane.diff = null
  41. commitList.state = "full"
  42. return
  43. }
  44. commitList.state = "commitsOnly"
  45. if(!root.controlActive) {
  46. commitPlane.commit = commit
  47. root.commitsForDiff=[]
  48. } else {
  49. console.log("root.controlActive: " + root.controlActive)
  50. if(root.commitsForDiff === null) {
  51. root.commitsForDiff = new Array(0);
  52. }
  53. console.log("Length" + root.commitsForDiff.length)
  54. root.commitsForDiff.push(commit)
  55. if(root.commitsForDiff.length === 2) {
  56. commitPlane.commit = root.commitsForDiff[1]
  57. commitPlane.diff = _handler.diff(root.commitsForDiff[0], root.commitsForDiff[1])
  58. root.commitsForDiff=[]
  59. }
  60. }
  61. }
  62. }
  63. CommitPlane {
  64. id: commitPlane
  65. anchors.left: commitList.right
  66. anchors.right: parent.right
  67. anchors.top: topBar.bottom
  68. anchors.bottom: consoleContol.top
  69. // visible: diff != null
  70. // opacity: diff != null ? 1.0 : 0.0
  71. }
  72. ConsoleControl {
  73. id: consoleContol
  74. anchors.left: parent.left
  75. anchors.right: parent.right
  76. anchors.bottom: parent.bottom
  77. }
  78. Keys.onPressed: {
  79. event.accepted = true
  80. switch(event.key) {
  81. case Qt.Key_Control:
  82. root.controlActive = true
  83. console.log("control pressed")
  84. break
  85. case Qt.Key_F4:
  86. consoleContol.state = consoleContol.state === "closed" ? "opened" : "closed"
  87. break
  88. case Qt.Key_G://Found the G point. Let's open console using this action.
  89. //TODO: Later has to be part of Console C++ class to read settings
  90. consoleContol.state = "opened"
  91. _handler.console.requestAutocomplete("g");
  92. break
  93. default:
  94. event.accepted = false
  95. }
  96. }
  97. Keys.onReleased: {
  98. if(event.key === Qt.Key_Control) {
  99. root.controlActive = false
  100. console.log("control released");
  101. }
  102. }
  103. onActiveFocusChanged: {
  104. root.controlActive = false
  105. console.log("control released");
  106. }
  107. Tooltip {
  108. }
  109. // Component.onCompleted: {
  110. // commitPlane.diff = _handler.diff();
  111. // }
  112. }