summaryrefslogtreecommitdiff
path: root/lib/bottompanel/bottomnotebook.tcl
blob: 7a2b5b36f7e0936b6c7299f6a5af39c79381045d (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
#!/usr/bin/tclsh
# Part of MCU 8051 IDE ( http://https://sourceforge.net/projects/mcu8051ide/ )

############################################################################
#    Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin OŇ°mera     #
#    martin.osmera@gmail.com                                               #
#                                                                          #
#    Copyright (C) 2014 by Moravia Microsystems, s.r.o.                    #
#    martin.osmera@gmail.com                                #
#                                                                          #
#    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.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

# >>> File inclusion guard
if { ! [ info exists _BOTTOMNOTEBOOK_TCL ] } {
set _BOTTOMNOTEBOOK_TCL _
# <<< File inclusion guard

# --------------------------------------------------------------------------
# DESCRIPTION
# Implements bottom panel of the project tab
# --------------------------------------------------------------------------

# Import nesesary sources
source "${::LIB_DIRNAME}/bottompanel/calculator.tcl"	;# Calculator
source "${::LIB_DIRNAME}/bottompanel/todo.tcl"		;# Todo list
source "${::LIB_DIRNAME}/bottompanel/graph.tcl"		;# Graph
source "${::LIB_DIRNAME}/bottompanel/messages.tcl"	;# Messages
source "${::LIB_DIRNAME}/bottompanel/terminal.tcl"	;# Terminal
source "${::LIB_DIRNAME}/bottompanel/find_in_files.tcl"	;# Find in files
source "${::LIB_DIRNAME}/bottompanel/cvarsview.tcl"	;# C variables

class BottomNoteBook {

	# Inherit content of some other clases
	inherit Calculator Todo Simulator Graph Messages Terminal FindInFiles CVarsView

	## Public
	public variable simulator_frame		;# Identifier of tab of NoteBook widget for simulator
	public variable cvarsview_frame		;# Identifier of tab of NoteBook widget for c variables
	public variable graph_frame		;# Identifier of tab of NoteBook widget for graph
	public variable messages_frame		;# Identifier of tab of NoteBook widget for messages box
	public variable todo_frame		;# Identifier of tab of NoteBook widget for to do box
	public variable calculator_frame	;# Identifier of tab of NoteBook widget for calculator
	public variable terminal_frame		;# Identifier of tab of NoteBook widget for terminal
	public variable findinfiles_frame	;# Identifier of tab of NoteBook widget for terminal

	## Private
	private variable pri_notebook		;# Identifier of NoteBook widget when panel is visible
	private variable main_frame		;# Identifier of frame containing both NoteBooks

	private variable panel_hidding_ena		1	;# Is panel hidding enabled
	private variable redraw_pane_in_progress	0	;# Is panel pane redraw in progress
	private variable parentPane				;# Identifier of parent pane
	private variable last_PanelSize				;# Last panel height
	private variable PanelVisible	$CONFIG(BOTTOM_PANEL)			;# Is panel visible
	private variable active_page	$CONFIG(BOTTOM_PANEL_ACTIVE_PAGE)	;# Identifier of active NoteBook page
	private variable PanelSize	$CONFIG(BOTTOM_PANEL_SIZE)		;# Current panel height

	## object constructor
	constructor {} {
		# Validate and set active page
		if {$active_page == {Terminal}} {
			set active_page {Simulator}
		} elseif {
			[lsearch {Simulator CVarsView Graph Messages Todo Calculator FindInFiles} $active_page] == -1
		} then {
			puts stderr "Invalid value of active page '$active_page', setting to {Simulator}"
			set active_page {Simulator}
		}
	}

	## object destructor
	destructor {
		# Destroy GUI
		destroy $main_frame
		notebook_Sbar_unset {bottomnb}
	}

	## Create Bottom NoteBook (This function must be called after contructor)
	 # @parm widget mainframe	- Frame for bottom notebook
	 # @parm widget PaneWindow	- parent pane window contaier
	 # @parm String todoText	- content of to do text
	 # @parm List calculatorList	- List of values for calculator (display content, radix, etc.)
	 # @parm List graph_config	- Graph configuration list
	 # @return Widget - ID of frame containg both notebooks
	public method initalize_BottomNoteBook {mainframe PaneWindow todoText calculatorList graph_config} {

		# set parent pane window
		set parentPane $PaneWindow

		## Create some widgets
		# Frame for primary and secondary notebook
		set main_frame $mainframe
		# Primary notebook
		set pri_notebook [ModernNoteBook $main_frame.ntb_bottomNB_pri]

		# Register notebook status bar tips
		notebook_Sbar_set {bottomnb} [list					\
			Simulator	[mc "Simulator panel"]				\
			CVarsView	[mc "List of variables defined in C program"]	\
			Graph		[mc "Graph showing voltage levels"]		\
			Messages	[mc "Compiler messages"]			\
			Todo		[mc "Editable notepad"]				\
			Calculator	[mc "Scientific calculator"]			\
			Terminal	[mc "Linux terminal emulator"]			\
			FindInFiles	[mc "Search string in files"]			\
			Hide		[mc "Hide the panel"]				\
			Show		[mc "Show the panel"]				\
		]
		$pri_notebook bindtabs <Enter> "notebook_Sbar bottomnb"
		$pri_notebook bindtabs <Leave> "Sbar {} ;#"

		## create Primary NoteBook tabs
		# Tab "Simulator"
		set simulator_frame	[$pri_notebook insert end {Simulator}		\
			-text [mc "Simulator"]						\
			-image ::ICONS::16::kcmmemory					\
			-raisecmd [list $this bottomNB_set_active_page {Simulator}]	\
			-helptext [mc "Simulator panel %s" "(Ctrl+1)"]			\
			-createcmd [list $this CreateSimulatorGUI]			\
		]
		# Tab "C variables"
		set cvarsview_frame	[$pri_notebook insert end {CVarsView}		\
			-text [mc "C variables"]					\
			-image ::ICONS::16::player_playlist				\
			-raisecmd [list $this bottomNB_set_active_page {CVarsView}]	\
			-helptext [mc "Variables from C source code %s" ""]		\
			-createcmd [list $this CreateCVarsViewGUI]			\
		]
		# Tab "Graph"
		set graph_frame	[$pri_notebook insert end {Graph}		\
			-text [mc "IO Ports"]					\
			-image ::ICONS::16::graph				\
			-raisecmd [list $this bottomNB_set_active_page {Graph}]	\
			-helptext [mc "Graph showing state of MCU ports %s" "(Ctrl+2)"]	\
			-createcmd [list $this CreateGraphGUI]			\
		]
		# Tab "Messages"
		set messages_frame	[$pri_notebook insert end {Messages}		\
			-text [mc "Messages"]						\
			-image ::ICONS::16::kcmsystem					\
			-raisecmd [list $this bottomNB_set_active_page {Messages}]	\
			-helptext [mc "Compiler messages %s" "(Ctrl+3)"]		\
			-createcmd [list $this CreateMessagesGUI]			\
			-leavecmd "
				$pri_notebook itemconfigure {Messages} -image ::ICONS::16::kcmsystem
			"	\
		]
		# Tab "Notes"
		set todo_frame		[$pri_notebook insert end {Todo} 	\
			-text [mc "Notes"]					\
			-image ::ICONS::16::camera_test				\
			-raisecmd [list $this bottomNB_set_active_page {Todo}]	\
			-helptext [mc "Personal to do list & notepad %s" "(Ctrl+4)"]\
			-createcmd [list $this CreateTodoGUI]			\
		]
		# Tab "Calculator"
		set calculator_frame	[$pri_notebook insert end {Calculator}		\
			-text [mc "Calculator"]						\
			-image ::ICONS::16::xcalc					\
			-raisecmd [list $this bottomNB_set_active_page {Calculator}]	\
			-helptext [mc "Scientific calculator %s" "(Ctrl+5)"]		\
			-createcmd [list $this CreateCalculatorGUI]			\
		]
		if {!$::MICROSOFT_WINDOWS} {	;# Microsoft Windows has no terminal emulator
			# Tab "Terminal"
			set terminal_frame	[$pri_notebook insert end {Terminal}		\
				-text [mc "Terminal"]						\
				-image ::ICONS::16::terminal					\
				-raisecmd [list $this bottomNB_set_active_page {Terminal}]	\
				-helptext [mc "Terminal emulator %s" ""]			\
				-createcmd [list $this CreateTerminalEmulGUI]			\
				-state [expr {${::PROGRAM_AVAILABLE(urxvt)} ? "normal" : "disabled"}]	\
			]
		}
		# Tab "Find in files"
		set findinfiles_frame	[$pri_notebook insert end {FindInFiles}		\
			-text [mc "Find in files"]					\
			-image ::ICONS::16::filefind					\
			-raisecmd [list $this bottomNB_set_active_page {FindInFiles}]	\
			-helptext [mc "Find in files %s" ""]				\
			-createcmd [list $this CreateFindInFilesGUI]			\
		]

		# Tab "Hide"
		$pri_notebook insert end {Hide}				\
			-text [mc "Hide"]				\
			-image ::ICONS::16::2downarrow			\
			-raisecmd [list $this bottomNB_show_hide]	\
			-helptext [mc "Hide this panel"]		\

		# Prepare panel componenets but do not create GUI elements
		PrepareCalculator	$calculator_frame	$calculatorList
		PrepareGraph		$graph_frame		$graph_config
		PrepareMessages		$messages_frame
		PrepareTodo		$todo_frame		$todoText

		PrepareSimulator	$simulator_frame
		PrepareCVarsView	$cvarsview_frame
		if {!$::MICROSOFT_WINDOWS} {	;# Microsoft Windows has no terminal emulator
			PrepareTerminal		$terminal_frame
		}
		PrepareFindInFiles	$findinfiles_frame

		# take case of proper pane resizing
		bind $parentPane <ButtonRelease-1> "$this bottomNB_panel_set_size"

		# Show primary notebook if panel is visible or secondary notebook ohterwise
		pack [$pri_notebook get_nb] -expand 1 -fill both -padx 5 -pady 5
		if {$PanelVisible != 0} {
			$parentPane paneconfigure $main_frame -minsize 215
			$parentPane configure -sashwidth 4

			# Raise tab
			catch {$pri_notebook raise $active_page}
		} else {
			$pri_notebook hide_pages_area
			$pri_notebook deselect_tab_button
			$pri_notebook itemconfigure {Hide}			\
				-text [mc "Show"]				\
				-image ::ICONS::16::2uparrow			\
				-helptext [mc "Show this panel"]

			$parentPane paneconfigure $main_frame -minsize 0
			$parentPane configure -sashwidth 0
			bind $parentPane <Button> {break}
			set last_PanelSize $PanelSize
			set PanelSize 34
		}
	}

	## Return true if the panel is visible
	 # @return bool result
	public method isBottomPanelVisible	{} {return $PanelVisible}

	## Return panel height
	 # @return int panle height
	public method getBottomPanelSize	{} {
		if {$PanelVisible} {
			return $PanelSize
		} else {
			return $last_PanelSize
		}
	}

	## Return ID of active page of the NoteBook
	 # @return String Active page
	public method getBottomPanelActivePage	{} {return $active_page}

	## Set active page for both notebooks (primary and secondary)
	 # This function may also inform GUI of new active page about that it has became active
	 # @parm String pageName - ID of page to set
	 # @return void
	public method bottomNB_set_active_page {pageName} {
		switch -- $pageName {
			Simulator	{$this SimulatorTabRaised}
			CVarsView	{$this CVarsViewTabRaised}
			Graph		{$this GraphTabRaised}
			Messages	{$this MessagesTabRaised}
			Todo		{$this TodoTabRaised}
			Calculator	{$this CalculatorTabRaised}
			FindInFiles	{$this FindInFilesTabRaised}
		}
		if {$pageName != {Hide}} {
			set active_page $pageName
		}
		if {!$PanelVisible} {
			bottomNB_show_hide
		}
	}

	## Show or hide the panel
	 # @parm String a_page={} - name of active page (show panel)
	 # @return void
	public method bottomNB_show_hide {{a_page {}}} {

		# If panel hidding is disabled -- abort
		if {!$panel_hidding_ena} {return}

		# Hide the panel
		if {$PanelVisible} {
			$parentPane paneconfigure $main_frame -minsize 0

			$pri_notebook hide_pages_area
			$pri_notebook deselect_tab_button
			$pri_notebook itemconfigure {Hide}			\
				-text [mc "Show"]				\
				-image ::ICONS::16::2uparrow			\
				-helptext [mc "Show this panel"]
			set last_PanelSize $PanelSize	;# Save current panel size
			set PanelSize 34		;# Set New panel size
			bottomNB_redraw_pane		;# Perform hidding

			set panel_hidding_ena 0
			set panel_hidding_ena 1
			$parentPane configure -sashwidth 0
			bind $parentPane <Button> {break}

			# Panel is now hidden
			set PanelVisible 0

		# Show the panel
		} else {
			$parentPane paneconfigure $main_frame -minsize 215

			$pri_notebook show_pages_area
			$pri_notebook itemconfigure {Hide}			\
				-text [mc "Hide"]				\
				-image ::ICONS::16::2downarrow			\
				-helptext [mc "Hide this panel"]

			# Create and show primary notebook
			set PanelSize $last_PanelSize	;# Restore panel size
			bottomNB_redraw_pane		;# Perform showing

			# Raise active page
			if {$a_page == {}} {
				$pri_notebook raise $active_page
			} else {
				$pri_notebook raise $a_page
			}
			# Restore sash width
			$parentPane configure -sashwidth 4
			bind $parentPane <Button> {}

			# Panel is now shown
			set PanelVisible 1
		}

		update idletasks
		$this editor_procedure {} Configure {}
	}

	## Get true panel size and store it into variable PanelSize
	 # @return void
	public method bottomNB_panel_set_size {} {
		set PanelSize [lindex [$parentPane sash coord 0] 1]
		set PanelSize [expr {[winfo height $parentPane] - $PanelSize}]

		update idletasks
		$this editor_procedure {} Configure {}
		$this editor_procedure {} goto	\
			[$this editor_procedure {} get_current_line_number {}]
	}

	## Move panel pane up by the given number of pixels
	 # @parm Int by - pixels
	 # @return void
	public method bottomNB_move_pane_up {by} {
		update idletasks
		$parentPane sash place 0 0 [expr {[winfo height $parentPane] - $PanelSize - $by}]
	}

	## Redraw panel pane
	 # @return  void
	public method bottomNB_redraw_pane {} {
		update idletasks
		catch {
			$parentPane sash place 0 0 [expr {[winfo height $parentPane] - $PanelSize}]
		}
	}

	## Redraw panel pane on expose event
	 # @return  void
	public method bottomNB_redraw_pane_on_expose {} {
		if {$redraw_pane_in_progress} {
			after 50 "$this bottomNB_redraw_pane_on_expose"
			return
		}
		set redraw_pane_in_progress 1

		update idletasks
		$parentPane sash place 0 0 [expr {[winfo height $parentPane] - $PanelSize}]
		update idletasks

		set redraw_pane_in_progress 0
	}

	## Raise specified page
	 # This function should not be bypased
	 # @parm String page - ID of page to show
	 # @return void
	public method bottomNB_show_up {page} {
		if {$PanelVisible} {
			$pri_notebook raise $page
		} else {
			bottomNB_show_hide $page
		}
	}

	## Destroy current simulator control panel and create a new one
	 # @return void
	public method simulator_itialize_simulator_control_panel {} {
		foreach wdg [winfo children $simulator_frame] {
			destroy $wdg
		}
		$this sumulator_clear_widgets
		PrepareSimulator $simulator_frame
		CreateSimulatorGUI
	}

	## Destroy current graph panel and create a new one
	 # @return void
	public method graph_itialize_simulator_graph_panel {graph_config} {
		$this graph_change_mcu
	}

	## Configure particular page on bottom notebook widget
	 # @parm String page	- Page ID
	 # @parm List options	- Any options acceptable by the notebook widget
	 # @return void
	public method bottomnotebook_pageconfigure {page options} {
		eval "$pri_notebook itemconfigure {$page} $options"
	}
}

# >>> File inclusion guard
}
# <<< File inclusion guard