summaryrefslogtreecommitdiffstats
path: root/awlsim/gui/sourcetabs.py
blob: ff2c5404ab250545ece7746a8a607c15962d6952 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# -*- coding: utf-8 -*-
#
# AWL simulator - GUI source tabs
#
# Copyright 2014 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.common.compat import *

from awlsim.gui.editwidget import *
from awlsim.gui.symtabwidget import *
from awlsim.gui.finddialog import *
from awlsim.gui.util import *
from awlsim.gui.fup.fupwidget import *


class SourceTabContextMenu(QMenu):
	# Signal: Add new source
	add = Signal()
	# Signal: Delete current source
	delete = Signal()
	# Signal: Rename current source
	rename = Signal()
	# Signal: Integrate source
	integrate = Signal()
	# Signal: Import source
	import_ = Signal()
	# Signal: Export source
	export = Signal()

	def __init__(self, itemName, parent=None):
		QMenu.__init__(self, parent)

		self.itemName = itemName

		self.addAction(getIcon("doc_new"), "&Add %s" % itemName, self.__add)
		self.addAction(getIcon("doc_close"), "&Delete %s..." % itemName, self.__delete)
		self.addAction(getIcon("doc_edit"), "&Rename %s..." % itemName, self.__rename)
		self.addSeparator()
		self.addAction(getIcon("doc_import"), "&Import %s..." % itemName, self.__import)
		self.addAction(getIcon("doc_export"), "&Export %s..." % itemName, self.__export)
		self.__integrateAction = self.addAction("&Integrate %s into project..." % itemName,
							self.__integrate)

		self.showIntegrateButton(False)

	def __add(self):
		self.add.emit()

	def __delete(self):
		self.delete.emit()

	def __rename(self):
		self.rename.emit()

	def __import(self):
		self.import_.emit()

	def __export(self):
		self.export.emit()

	def __integrate(self):
		res = QMessageBox.question(self,
			"Integrate current %s" % self.itemName,
			"The current %s is stored in an external file.\n"
			"Do you want to integrate this file info "
			"the awlsim project file (.awlpro)?" %\
			self.itemName,
			QMessageBox.Yes, QMessageBox.No)
		if res == QMessageBox.Yes:
			self.integrate.emit()

	def showIntegrateButton(self, show=True):
		self.__integrateAction.setVisible(show)

class SourceTabCorner(QWidget):
	def __init__(self, itemName, contextMenu, parent=None):
		QWidget.__init__(self, parent)
		self.setLayout(QGridLayout())
		self.layout().setContentsMargins(QMargins(3, 0, 0, 0))

		self.menuButton = QPushButton("+/-", self)
		self.menuButton.setIcon(getIcon("tab_new"))
		self.menuButton.setMenu(contextMenu)
		self.layout().addWidget(self.menuButton, 0, 0)

class DummySourceWidget(QWidget):
	def getSource(self):
		return None

class SourceTabWidget(QTabWidget):
	"Abstract source tab-widget"

	# Signal: Emitted, if the source code changed.
	sourceChanged = Signal()
	# Signal: Keyboard focus in/out event.
	focusChanged = Signal(bool)
	# Signal: UndoAvailable state changed
	undoAvailableChanged = Signal(bool)
	# Signal: RedoAvailable state changed
	redoAvailableChanged = Signal(bool)
	# Signal: CopyAvailable state changed
	copyAvailableChanged = Signal(bool)
	# Signal: Change the font size.
	#         If the parameter is True, increase font size.
	resizeFont = Signal(bool)
	# Signal: Validation request.
	#	  A code validation should take place.
	#	  The parameter is the source editor.
	validateDocument = Signal(SourceCodeEdit)


	def __init__(self, itemName, parent=None):
		QTabWidget.__init__(self, parent)
		self.itemName = itemName

		self.guiSettings = GuiSettings()

		self.contextMenu = SourceTabContextMenu(itemName, self)

		self.setMovable(True)
		self.actionButton = SourceTabCorner(itemName, self.contextMenu, self)
		self.setCornerWidget(self.actionButton, Qt.TopRightCorner)

		self.contextMenu.integrate.connect(self.integrateSource)
		self.currentChanged.connect(self.__currentChanged)
		self.tabBar().tabMoved.connect(self.__tabMoved)

	def reset(self):
		self.clear()

	def __currentChanged(self, index):
		self.updateActionMenu()

	def __tabMoved(self, fromIdx, toIdx):
		self.sourceChanged.emit()

	def updateActionMenu(self):
		curWidget = self.currentWidget()
		showIntegrate = False
		if curWidget:
			source = curWidget.getSource()
			if source:
				showIntegrate = source.isFileBacked()
		self.contextMenu.showIntegrateButton(showIntegrate)

	def updateTabTexts(self):
		for i in range(self.count()):
			source = self.widget(i).getSource()
			if source:
				self.setTabText(i, source.name)
		self.sourceChanged.emit()

	def allTabWidgets(self):
		for i in range(self.count()):
			yield self.widget(i)

	def removeDummyWidgets(self):
		for i in range(self.count() - 1, -1, -1):
			fupWidget = self.widget(i)
			if isinstance(fupWidget, DummySourceWidget):
				self.removeTab(i)

	def addDummyWidget(self):
		self.addTab(DummySourceWidget(), "")

	def updateRunState(self, runState):
		pass

	def handleValidationResult(self, exception):
		pass

	def getSources(self):
		"Returns a list of sources"
		return [ s for s in (w.getSource() for w in self.allTabWidgets())
		         if s ]

	def setSources(self, sources):
		raise NotImplementedError

	def getCurrentSource(self):
		"Returns the currently selected source, or None."
		curWidget = self.currentWidget()
		if curWidget:
			return curWidget.getSource()
		return None

	def setSettings(self, guiSettings):
		self.guiSettings = guiSettings

	def integrateSource(self):
		curWidget = self.currentWidget()
		if curWidget:
			source = curWidget.getSource()
			if source:
				source.forceNonFileBacked(self.contextMenu.itemName)
				self.updateActionMenu()
				self.updateTabTexts()

	def contextMenuEvent(self, ev):
		QTabWidget.contextMenuEvent(self, ev)
		tabBar = self.tabBar()
		pos = tabBar.mapFrom(self, ev.pos())
		if tabBar.geometry().contains(pos):
			# Tab context menu was requested.
			index = tabBar.tabAt(pos)
			if index >= 0:
				tabBar.setCurrentIndex(index)
				self.contextMenu.exec_(self.mapToGlobal(ev.pos()))

	def undoIsAvailable(self):
		return False

	def undo(self):
		pass

	def redoIsAvailable(self):
		return False

	def redo(self):
		pass

	def copyIsAvailable(self):
		return False

	def clipboardCut(self):
		pass

	def clipboardCopy(self):
		pass

	def clipboardPaste(self):
		pass

	def findText(self):
		pass

	def findReplaceText(self):
		pass

	def handleIdentsMsg(self, identsMsg):
		pass

class AwlSourceTabWidget(SourceTabWidget):
	"AWL source tab-widget"

	# Signal: The visible AWL line range changed
	#         Parameters are: source, visibleFromLine, visibleToLine
	visibleLinesChanged = Signal(object, int, int)

	def __init__(self, parent=None):
		SourceTabWidget.__init__(self, "source", parent)

		self.reset()

		self.contextMenu.add.connect(self.addEditWidget)
		self.contextMenu.delete.connect(self.deleteCurrent)
		self.contextMenu.rename.connect(self.renameCurrent)
		self.contextMenu.export.connect(self.exportCurrent)
		self.contextMenu.import_.connect(self.importSource)
		self.currentChanged.connect(self.__currentChanged)

	def reset(self):
		SourceTabWidget.reset(self)
		self.onlineDiagEnabled = False
		index, editWidget = self.addEditWidget()
		source = editWidget.getSource()
		source.name = "Main source"
		self.updateTabTexts()

	def clear(self):
		for editWidget in self.allTabWidgets():
			editWidget.shutdown()
		SourceTabWidget.clear(self)

	def __emitVisibleLinesSignal(self):
		editWidget = self.currentWidget()
		if editWidget:
			fromLine, toLine = editWidget.getVisibleLineRange()
			source = editWidget.getSource()
			self.visibleLinesChanged.emit(source, fromLine, toLine)
		else:
			self.visibleLinesChanged.emit(None, -1, -1)

	# Handle a change in editor-code <-> cpu-code match.
	def __handleCodeMatchChange(self, editWidget, matchesCpu):
		index = self.indexOf(editWidget)
		if matchesCpu:
			self.setTabIcon(index, QIcon())
			self.setTabToolTip(index, "")
		else:
			self.setTabIcon(index, getIcon("warning"))
			self.setTabToolTip(index, "Warning:\n"
				"The code in the editor "
				"widget does not match the code on the CPU.\n"
				"Please re-download the code to the CPU.")

	def __currentChanged(self, index):
		if self.onlineDiagEnabled:
			for editWidget in self.allTabWidgets():
				editWidget.enableCpuStats(False)
				editWidget.resetCpuStats()
			if index >= 0:
				editWidget = self.widget(index)
				editWidget.enableCpuStats(True)
		self.__emitVisibleLinesSignal()
		# Update undo/redo/copy states
		editWidget = self.currentWidget()
		self.undoAvailableChanged.emit(editWidget.undoIsAvailable()
					       if editWidget else False)
		self.redoAvailableChanged.emit(editWidget.redoIsAvailable()
					       if editWidget else False)
		self.copyAvailableChanged.emit(editWidget.copyIsAvailable()
					       if editWidget else False)
		self.validateDocument.emit(editWidget)

	def updateRunState(self, runState):
		for editWidget in self.allTabWidgets():
			editWidget.runStateChanged(runState)

	def handleValidationResult(self, exception):
		for editWidget in self.allTabWidgets():
			editWidget.handleValidationResult(exception)

	def handleOnlineDiagChange(self, enabled):
		self.onlineDiagEnabled = enabled
		editWidget = self.currentWidget()
		if editWidget:
			editWidget.enableCpuStats(enabled)
		self.__emitVisibleLinesSignal()

	def handleInsnDump(self, insnDumpMsg):
		editWidget = self.currentWidget()
		if editWidget:
			editWidget.updateCpuStats_afterInsn(insnDumpMsg)

	def setSources(self, awlSources):
		self.clear()
		if not awlSources:
			self.addEditWidget()
			return
		for awlSource in awlSources:
			index, editWidget = self.addEditWidget()
			self.setTabText(index, awlSource.name)
			editWidget.setSource(awlSource)
		self.updateActionMenu()
		self.setCurrentIndex(0)

	def setSettings(self, guiSettings):
		SourceTabWidget.setSettings(self, guiSettings)

		for editWidget in self.allTabWidgets():
			editWidget.setSettings(guiSettings)

	def addEditWidget(self):
		editWidget = EditWidget(self)
		editWidget.setSettings(self.guiSettings)
		editWidget.codeChanged.connect(self.sourceChanged)
		editWidget.focusChanged.connect(self.focusChanged)
		editWidget.visibleRangeChanged.connect(self.__emitVisibleLinesSignal)
		editWidget.cpuCodeMatchChanged.connect(self.__handleCodeMatchChange)
		editWidget.undoAvailable.connect(self.undoAvailableChanged)
		editWidget.redoAvailable.connect(self.redoAvailableChanged)
		editWidget.copyAvailable.connect(self.copyAvailableChanged)
		editWidget.resizeFont.connect(self.resizeFont)
		editWidget.validateDocument.connect(
			lambda editWidget: self.validateDocument.emit(editWidget))
		index = self.addTab(editWidget, editWidget.getSource().name)
		self.setCurrentIndex(index)
		self.updateActionMenu()
		self.sourceChanged.emit()
		return index, editWidget

	def deleteCurrent(self):
		index = self.currentIndex()
		if index >= 0 and self.count() > 1:
			text = self.tabText(index)
			res = QMessageBox.question(self,
				"Delete %s" % text,
				"Delete source '%s'?" % text,
				QMessageBox.Yes, QMessageBox.No)
			if res == QMessageBox.Yes:
				self.widget(index).shutdown()
				self.removeTab(index)
				self.sourceChanged.emit()

	def renameCurrent(self):
		index = self.currentIndex()
		if index >= 0:
			text = self.tabText(index)
			newText, ok = QInputDialog.getText(self,
					"Rename %s" % text,
					"New name for current source:",
					QLineEdit.Normal,
					text)
			if ok and newText != text:
				editWidget = self.widget(index)
				source = editWidget.getSource()
				source.name = newText
				self.updateTabTexts()

	def exportCurrent(self):
		editWidget = self.currentWidget()
		if not editWidget:
			return
		source = editWidget.getSource()
		if not source:
			return
		fn, fil = QFileDialog.getSaveFileName(self,
			"AWL/STL source export", "",
			"AWL/STL source file (*.awl)",
			"*.awl")
		if not fn:
			return
		if not fn.endswith(".awl"):
			fn += ".awl"
		try:
			awlFileWrite(fn, source.sourceBytes, encoding="binary")
		except AwlSimError as e:
			MessageBox.handleAwlSimError(self,
				"Failed to export source", e)

	def importSource(self):
		fn, fil = QFileDialog.getOpenFileName(self,
			"Import AWL/STL source", "",
			"AWL source (*.awl);;"
			"All files (*)")
		if not fn:
			return
		source = AwlSource.fromFile("Imported source",
					    fn)
		res = QMessageBox.question(self,
			"Integrate source into project?",
			"Do you want to integrate the source\n"
			"%s\n"
			"into the project file (.awlpro)?\n"
			"If you do not integrate the source, it "
			"will stay in the external file.\n\n"
			"It is highly recommended to say 'Yes'." %\
			fn,
			QMessageBox.Yes | QMessageBox.No,
			QMessageBox.Yes)
		if res == QMessageBox.Yes:
			source.forceNonFileBacked(source.name)
		index, editWidget = self.addEditWidget()
		editWidget.setSource(source)
		self.setCurrentIndex(index)
		self.updateTabTexts()
		self.updateActionMenu()

	def pasteText(self, text):
		editWidget = self.currentWidget()
		if editWidget:
			editWidget.pasteText(text)

	def undoIsAvailable(self):
		editWidget = self.currentWidget()
		if editWidget:
			return editWidget.undoIsAvailable()
		return False

	def undo(self):
		editWidget = self.currentWidget()
		if editWidget:
			editWidget.undo()

	def redo(self):
		editWidget = self.currentWidget()
		if editWidget:
			editWidget.redo()

	def redoIsAvailable(self):
		editWidget = self.currentWidget()
		if editWidget:
			return editWidget.redoIsAvailable()
		return False

	def copyIsAvailable(self):
		editWidget = self.currentWidget()
		if editWidget:
			return editWidget.copyIsAvailable()
		return False

	def clipboardCut(self):
		editWidget = self.currentWidget()
		if editWidget:
			editWidget.cut()

	def clipboardCopy(self):
		editWidget = self.currentWidget()
		if editWidget:
			editWidget.copy()

	def clipboardPaste(self):
		editWidget = self.currentWidget()
		if editWidget:
			editWidget.paste()

	def findText(self):
		editWidget = self.currentWidget()
		if editWidget:
			dlg = FindReplaceDialog(editWidget, False, editWidget)
			dlg.exec_()
			dlg.deleteLater()

	def findReplaceText(self):
		editWidget = self.currentWidget()
		if editWidget:
			dlg = FindReplaceDialog(editWidget, True, editWidget)
			dlg.exec_()
			dlg.deleteLater()

	def handleIdentsMsg(self, identsMsg):
		SourceTabWidget.handleIdentsMsg(self, identsMsg)
		for editWidget in self.allTabWidgets():
			editWidget.handleIdentsMsg(identsMsg)

class SymSourceTabWidget(SourceTabWidget):
	"Symbol table source tab-widget"	

	def __init__(self, parent=None):
		SourceTabWidget.__init__(self, "symbol table", parent)

		self.reset()

		self.contextMenu.add.connect(self.addSymTable)
		self.contextMenu.delete.connect(self.deleteCurrent)
		self.contextMenu.rename.connect(self.renameCurrent)
		self.contextMenu.export.connect(self.exportCurrent)
		self.contextMenu.import_.connect(self.importSource)

	def reset(self):
		SourceTabWidget.reset(self)
		index, symTabView = self.addSymTable()
		source = symTabView.getSource()
		source.name = "Main table"
		self.updateTabTexts()

	def setSources(self, symTabSources):
		self.clear()
		if not symTabSources:
			self.addSymTable()
			return
		for symTabSource in symTabSources:
			index, symTabView = self.addSymTable()
			self.setTabText(index, symTabSource.name)
			symTabView.model().setSource(symTabSource)
		self.updateActionMenu()
		self.setCurrentIndex(0)

	def addSymTable(self):
		symTabView = SymTabView(self)
		symTabView.setSymTab(SymbolTable())
		symTabView.model().sourceChanged.connect(self.sourceChanged)
		symTabView.focusChanged.connect(self.focusChanged)
		index = self.addTab(symTabView, symTabView.model().getSource().name)
		self.setCurrentIndex(index)
		self.updateActionMenu()
		self.sourceChanged.emit()
		return index, symTabView

	def deleteCurrent(self):
		index = self.currentIndex()
		if index >= 0 and self.count() > 1:
			text = self.tabText(index)
			res = QMessageBox.question(self,
				"Delete %s" % text,
				"Delete symbol table '%s'?" % text,
				QMessageBox.Yes, QMessageBox.No)
			if res == QMessageBox.Yes:
				self.removeTab(index)
				self.sourceChanged.emit()

	def renameCurrent(self):
		index = self.currentIndex()
		if index >= 0:
			text = self.tabText(index)
			newText, ok = QInputDialog.getText(self,
					"Rename %s" % text,
					"New name for current symbol table:",
					QLineEdit.Normal,
					text)
			if ok and newText != text:
				symTabView = self.widget(index)
				source = symTabView.getSource()
				source.name = newText
				self.updateTabTexts()

	def exportCurrent(self):
		symTabView = self.currentWidget()
		if not symTabView:
			return
		source = symTabView.getSource()
		if not source:
			return
		fn, fil = QFileDialog.getSaveFileName(self,
			"Symbol table export", "",
			"Symbol table file (*.asc)",
			"*.asc")
		if not fn:
			return
		if not fn.endswith(".asc"):
			fn += ".asc"
		try:
			awlFileWrite(fn, source.sourceBytes, encoding="binary")
		except AwlSimError as e:
			MessageBox.handleAwlSimError(self,
				"Failed to export symbol table", e)

	def importSource(self):
		fn, fil = QFileDialog.getOpenFileName(self,
			"Import symbol table", "",
			"Symbol table file (*.asc);;"
			"All files (*)")
		if not fn:
			return
		source = SymTabSource.fromFile("Imported symbol table",
					       fn)
		res = QMessageBox.question(self,
			"Integrate symbol table into project?",
			"Do you want to integrate the symbol table\n"
			"%s\n"
			"into the project file (.awlpro)?\n"
			"If you do not integrate the symbol table, it "
			"will stay in the external file.\n\n"
			"It is highly recommended to say 'Yes'." %\
			fn,
			QMessageBox.Yes | QMessageBox.No,
			QMessageBox.Yes)
		if res == QMessageBox.Yes:
			source.forceNonFileBacked(source.name)
		index, symTabView = self.addSymTable()
		symTabView.setSource(source)
		self.setCurrentIndex(index)
		self.updateTabTexts()
		self.updateActionMenu()

	def handleIdentsMsg(self, identsMsg):
		pass#TODO

class FupTabWidget(SourceTabWidget):
	"FUP/FBD tab widget"

	def __init__(self, parent=None):
		SourceTabWidget.__init__(self, "FUP/FBD diagram", parent)

		self.reset()

		self.contextMenu.add.connect(self.addDiagram)
		self.contextMenu.delete.connect(self.deleteCurrent)
		self.contextMenu.rename.connect(self.renameCurrent)
		self.contextMenu.export.connect(self.exportCurrent)
		self.contextMenu.import_.connect(self.importSource)

	def reset(self):
		SourceTabWidget.reset(self)
		self.addDummyWidget()
		self.updateTabTexts()

	def setSources(self, fupSources):
		self.clear()
		if not fupSources:
			self.addDummyWidget()
			return
		for fupSource in fupSources:
			index, fupWidget = self.addDiagram()
			self.setTabText(index, fupSource.name)
			fupWidget.setSource(fupSource)
		self.updateActionMenu()
		self.setCurrentIndex(0)

	def addDiagram(self):
		fupWidget = FupWidget(self)
		fupWidget.diagramChanged.connect(self.sourceChanged)
		self.removeDummyWidgets()
		index = self.addTab(fupWidget, fupWidget.getSource().name)
		self.setCurrentIndex(index)
		self.updateActionMenu()
		self.sourceChanged.emit()
		return index, fupWidget

	def deleteCurrent(self):
		index = self.currentIndex()
		if index >= 0:
			text = self.tabText(index)
			res = QMessageBox.question(self,
				"Delete %s" % text,
				"Delete FUP/FBD diagram '%s'?" % text,
				QMessageBox.Yes, QMessageBox.No)
			if res == QMessageBox.Yes:
				self.removeTab(index)
				self.sourceChanged.emit()
			if self.count() <= 0:
				self.addDummyWidget()

	def renameCurrent(self):
		index = self.currentIndex()
		if index >= 0:
			text = self.tabText(index)
			fupWidget = self.widget(index)
			source = fupWidget.getSource()
			if source:
				newText, ok = QInputDialog.getText(self,
						"Rename %s" % text,
						"New name for current FUP/FBD diagram:",
						QLineEdit.Normal,
						text)
				if ok and newText != text:
					source.name = newText
					self.updateTabTexts()

	def exportCurrent(self):
		pass#TODO

	def importSource(self):
		pass#TODO

	def handleIdentsMsg(self, identsMsg):
		pass#TODO
bues.ch cgit interface