forked from geraldspreer/the-maker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makerAddNewLanguageCodedFile.py
executable file
·131 lines (78 loc) · 3.99 KB
/
makerAddNewLanguageCodedFile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import makerController
import makerNewFileDialog
import os
import makerFileTemplates
from makerUtilities import readFile, writeFile
class Controller(makerController.SuperController):
def drawDialog(self):
self.dialog = makerNewFileDialog.xrcnewFile(self.view)
self.dialog.Cancel.Bind(self.view.wx.EVT_BUTTON,
self.close)
self.dialog.Add.Bind(self.view.wx.EVT_BUTTON,
self.add)
self.dialog.SetTitle("add new " + self.model.type + " file..." )
def updateLanguageList(self, itemList):
self.dialog.langChoice.Clear()
self.dialog.langChoice.AppendItems(itemList)
self.dialog.langChoice.Select(0)
self.dialog.langChoice.Update()
def showDialog(self):
self.dialog.Show()
def close(self, event):
self.dialog.Close()
def add(self, event):
name = self.dialog.textField.GetValue()
lang = self.dialog.langChoice.GetStringSelection()
if not name.endswith("_"):
name += "_"
self.dialog.textField.SetValue(name)
if self.model.makerFileExists(name + lang + self.model.type):
return
else:
self.model.createFile(name , lang)
self.dialog.Destroy()
class NewLangFile:
def __init__(self, mainView, project, type, content):
self.content = content
self.type = type
self.projectController = project.projectController
self.project = project
self.controller = Controller(self, mainView)
self.controller.drawDialog()
self.controller.updateLanguageList(project.getProjectLanguages())
self.controller.showDialog()
def makerFileExists(self, thePath):
if os.path.isfile(os.path.join(self.project.getPathParts(), thePath)):
message = "%s is an existing file !\n" % thePath
self.projectController.infoMessage(message)
return True
return False
def createFile(self, name, lang):
# just making sure
if not name.endswith("_"):
name += "_"
if not self.content:
content = makerFileTemplates.getTemplate(self.type)
if self.type == ".content":
# TO DO: convert to use os.path.join()
pathToHead = self.project.getPathParts()+"../templates/"+ lang +".head"
head = readFile(pathToHead)
pathToNewHead = self.project.getPathParts() + name + lang +".head"
writeFile(pathToNewHead, head)
# TO DO: convert to use os.path.join()
nameInTable = name + lang + ".htm"
self.project.addToDistributionTable(nameInTable,
self.project.getDefaultRemoteFolder(self.type),
"lines",
nameInTable)
newFile = self.project.getPathParts() + name + lang + self.type
writeFile(newFile, content)
elif self.type==".dynamic":
# TO DO: convert to use os.path.join()
newFile = self.project.getPathParts() + name + lang + self.type
writeFile(newFile, content)
group = self.projectController.findTreeItemByText(self.type)
if not group:
group = self.projectController.treeViewAddFolder(self.type)
newItem = self.projectController.treeViewAppendItem(group, name + lang, type=None)
self.projectController.selectTreeItemAndLoad(newItem)