Skip to content

Commit 1f2bfa3

Browse files
committed
Generate the name of the document when the first commit range is added
- only when the name field is empty - todo: add a button for regenerating the name
1 parent 039a3a4 commit 1f2bfa3

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

gitreviewdoc.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
1-
import os
1+
import os, re
22
import mainwin_ui as uimain
33
import mainwin_ui_support as uimain_s
44
import gitjobs
55
from generator import DiffGeneratorSettings, DiffGenerator, OverviewGenerator
66
from odt import OdtGenerator as DocGenerator
77

8+
def updateDocumentNameCb():
9+
gui = uimain_s.w
10+
txtIds = gui.txtCommitIds
11+
text = txtIds.get( "1.0", "end-1c" ).strip()
12+
lines = [ l.strip() for l in text.split("\n") if len(l.strip()) > 0 ]
13+
commitId = ""
14+
for l in lines:
15+
if l.find("..") > 0:
16+
commitId = l.split("..")[1].strip(". \t")
17+
break
18+
if len(commitId) < 1:
19+
for l in lines:
20+
if len(l.split()) > 1:
21+
commitId = l.split()[1]
22+
break
23+
commitId = re.sub( "[^a-zA-Z0-9]+", "_", commitId )
24+
25+
repo = os.path.basename(gui.edRepository.get().strip())
26+
repo = re.sub( "[^a-zA-Z0-9]+", "_", repo )
27+
28+
gui.edName.delete( 0, "end" )
29+
if len(commitId) > 0:
30+
gui.edName.insert( 0, "{}-{}".format(repo, commitId) )
31+
else:
32+
gui.edName.insert( 0, "{}".format(repo) )
33+
834

935
def generateDiffDocumentCb():
1036
settings = DiffGeneratorSettings.fromGuiFields(uimain_s.w)
@@ -29,14 +55,17 @@ def fixBranch( branch ):
2955
txtIds.delete( 0.0, "end" )
3056
txtIds.insert( 0.0, "\n".join( lines ))
3157

58+
if len(dialog.edName.get().strip()) < 1:
59+
updateDocumentNameCb()
60+
3261

3362
def prepareMainWindow( gui, guivars ):
3463
gitroot = findGitDir( os.getcwd() ) or os.getcwd()
64+
branches, curBranch = gitjobs.getBranches( gitroot )
65+
3566
gui.edRepository.delete( 0, "end" )
3667
gui.edRepository.insert( 0, gitroot )
37-
gui.edName.insert( 0, os.path.basename( gitroot ))
3868

39-
branches, curBranch = gitjobs.getBranches( gitroot )
4069
gui.comboBaseBranch.configure(values=branches)
4170
gui.comboToBranch.configure(values=branches)
4271
if "develop" in branches:

0 commit comments

Comments
 (0)