Skip to content

Commit

Permalink
switch branch: add option to create new branch (#98)
Browse files Browse the repository at this point in the history
fixes #88
  • Loading branch information
rcoup committed Apr 27, 2023
1 parent 4b0fc39 commit 40a254c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
21 changes: 18 additions & 3 deletions kart/gui/switchdialog.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os

from qgis.utils import iface

from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QDialog
from qgis.PyQt.QtWidgets import QInputDialog

from kart.kartapi import executeskart


WIDGET, BASE = uic.loadUiType(
Expand All @@ -13,15 +14,29 @@

class SwitchDialog(BASE, WIDGET):
def __init__(self, repo):
super(QDialog, self).__init__(iface.mainWindow())
super().__init__(iface.mainWindow())
self.repo = repo
self.setupUi(self)

self.comboBranch.addItems(repo.branches())

self.btnCreateNew.clicked.connect(self.createNewClicked)

self.buttonBox.accepted.connect(self.okClicked)
self.buttonBox.rejected.connect(self.reject)

def okClicked(self):
self.branch = self.comboBranch.currentText()
self.force = self.chkForce.isChecked()
self.accept()

@executeskart
def createNewClicked(self, item):
name, ok = QInputDialog.getText(
self, "Create branch", "Enter name of branch to create"
)
if ok and name:
self.repo.createBranch(name)
self.branch = name
self.force = False
self.accept()
27 changes: 20 additions & 7 deletions kart/gui/switchdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,35 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QComboBox" name="comboBranch"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Branch</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBranch"/>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="btnCreateNew">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Create New</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
3 changes: 2 additions & 1 deletion kart/kartapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Optional,
List
)
from functools import partial
from functools import partial, wraps

from urllib.parse import urlparse

Expand Down Expand Up @@ -51,6 +51,7 @@ class KartNotSupportedOperationException(Exception):


def executeskart(f):
@wraps(f)
def inner(*args):
try:
if checkKartInstalled():
Expand Down

0 comments on commit 40a254c

Please sign in to comment.