📄 ecosynth.tcl
字号:
variable _handle_exit_after ""
proc _handle_exit_request { } {
if { !$synth::ecos_running } {
exit 0
}
# Setting this flag causes ecosynth to exit immediately once
# the application terminates.
set synth::flag_immediate_exit 1
# Now ask the application to exit
synth::request_application_exit
# Set up a timer to retry this
if { "" == $synth::_handle_exit_after } {
set synth::_handle_exit_after [after 1000 synth::_handle_exit_timer]
# And output something so the user knows the request has been received
synth::report "Waiting for the eCos application to exit.\n"
}
}
# This routine requests termination of eCos, but not of
# ecosynth
proc _handle_kill_request { } {
if { $synth::ecos_running } {
synth::request_application_exit
if { "" == $synth::_handle_exit_after } {
set synth::_handle_exit_after [after 1000 synth::_handle_exit_timer]
}
}
}
proc _handle_exit_timer { } {
if { $synth::ecos_running } {
incr synth::_handle_exit_retries
if { $synth::_handle_exit_retries < 5 } {
synth::request_application_exit
synth::report "Still waiting for the eCos application to exit.\n"
} else {
synth::_send_SIGKILL
}
set synth::_handle_exit_after [after 1000 synth::_handle_exit_timer]
}
}
}
# }}}
# {{{ Main window layout
# ----------------------------------------------------------------------------
# The window layout is as follows:
# 1) a menu bar at the top (surprise surprise). Many of the menus will be
# empty or nearly so, but device-specific scripts may want to extend
# the menus.
# 2) a toolbar. This is primarily for use by device-specific scripts
# 3) a central grid.
# 4) a status line at the bottom.
#
# The central grid is organised as a 3x3 set of frames. The centre frame holds
# the main text display, plus associated scrollbars, and is the frame that
# will expand or shrink as the toplevel is resized. The remaining eight frames
# (nw, n, ne, e, se, s, sw, w) are available for use by device-specific
# scripts, typically under control of settings in the target definition file.
# It is very possible that some or all of these eight frames will be empty,
# and if an entire row or column is empty then Tk will make them invisible.
#
# Possible enhancements:
# 1) implement some sort of paning/resizing around the central text window.
# That would provide some way of letting the user control the space
# taken by device-specific subwindows. This would be implemented
# by modifying the weights assigned to different rows/columns.
# 2) it would be very useful if the main text window could be split,
# like emacs. This would require multiple text widgets, with output
# being pasted in each one.
# 3) possibly the text window should not be hard-wired to the centre frame,
# instead its frame could be selected by preferences somehow.
if { $synth::flag_debug } {
synth::report "Creating main window layout\n"
}
# The various frames are generally accessed via variables
menu .menubar -borderwidth 1
menu .menubar.file
menu .menubar.edit
menu .menubar.view
menu .menubar.windows
menu .menubar.help
. configure -menu .menubar
.menubar add cascade -label "File" -underline 0 -menu .menubar.file
.menubar add cascade -label "Edit" -underline 0 -menu .menubar.edit
.menubar add cascade -label "View" -underline 0 -menu .menubar.view
.menubar add cascade -label "Windows" -underline 0 -menu .menubar.windows
.menubar add cascade -label "Help" -underline 0 -menu .menubar.help
.menubar.file add command -label "Save" -underline 0 -accelerator "Ctrl-S" -command [list synth::_handle_file_save]
.menubar.file add command -label "Save As..." -underline 5 -command [list synth::_handle_file_save_as]
.menubar.file add command -label "Save All..." -underline 6 -command [list synth::_handle_file_save_all]
.menubar.file add command -label "Kill eCos" -underline 0 -command [list synth::_handle_kill_request]
.menubar.file add command -label "Exit" -underline 1 -accelerator "Ctrl-Q" -command [list synth::_handle_exit_request]
bind . <Control-KeyPress-q> [list synth::_handle_exit_request]
bind . <Control-KeyPress-s> [list synth::_handle_file_save]
# Once eCos has exited, the kill option should be disabled
namespace eval synth {
proc _menubar_ecos_exit_clean { arg_list } {
.menubar.file entryconfigure "Kill eCos" -state disabled
}
synth::hook_add "ecos_exit" synth::_menubar_ecos_exit_clean
}
frame .toolbar -borderwidth 1 -relief groove
if { "" != $synth::image_save } {
button .toolbar.save -image $synth::image_save -borderwidth 0 -command [list synth::_handle_file_save]
pack .toolbar.save -side left -padx 2
synth::register_balloon_help .toolbar.save "Save visible output"
}
if { "" != $synth::image_saveall } {
button .toolbar.saveall -image $synth::image_saveall -borderwidth 0 -command [list synth::_handle_file_save_all]
pack .toolbar.saveall -side left -padx 2
synth::register_balloon_help .toolbar.saveall "Save all output"
}
if { "" != $synth::image_cut } {
button .toolbar.cut -image $synth::image_cut -borderwidth 0 -state disabled -command [list synth::_handle_edit_cut]
pack .toolbar.cut -side left -padx 2
synth::register_balloon_help .toolbar.cut "Cut"
}
if { "" != $synth::image_copy } {
button .toolbar.copy -image $synth::image_copy -borderwidth 0 -command [list synth::_handle_edit_copy]
pack .toolbar.copy -side left -padx 2
synth::register_balloon_help .toolbar.copy "Copy"
}
if { "" != $synth::image_paste } {
button .toolbar.paste -image $synth::image_paste -borderwidth 0 -state disabled -command [list synth::_handle_edit_paste]
pack .toolbar.paste -side left -padx 2
synth::register_balloon_help .toolbar.paste "Paste"
}
pack .toolbar -side top -fill x
frame .main
frame .main.nw -borderwidth 0
frame .main.n -borderwidth 0
frame .main.ne -borderwidth 0
frame .main.e -borderwidth 0
frame .main.se -borderwidth 0
frame .main.s -borderwidth 0
frame .main.sw -borderwidth 0
frame .main.w -borderwidth 0
frame .main.centre
frame .main.border_nw_n -width 2 -background black -borderwidth 0
frame .main.border_n_ne -width 2 -background black -borderwidth 0
frame .main.border_w_centre -width 2 -background black -borderwidth 0
frame .main.border_centre_e -width 2 -background black -borderwidth 0
frame .main.border_sw_s -width 2 -background black -borderwidth 0
frame .main.border_s_se -width 2 -background black -borderwidth 0
frame .main.border_nw_w -height 2 -background black -borderwidth 0
frame .main.border_n_centre -height 2 -background black -borderwidth 0
frame .main.border_ne_e -height 2 -background black -borderwidth 0
frame .main.border_w_sw -height 2 -background black -borderwidth 0
frame .main.border_centre_s -height 2 -background black -borderwidth 0
frame .main.border_e_se -height 2 -background black -borderwidth 0
text .main.centre.text -xscrollcommand [list .main.centre.horizontal set] -yscrollcommand [list .main.centre.vertical set]
scrollbar .main.centre.horizontal -orient horizontal -command [list .main.centre.text xview]
scrollbar .main.centre.vertical -orient vertical -command [list .main.centre.text yview]
grid configure .main.centre.text -row 0 -column 0 -sticky news
grid configure .main.centre.vertical -row 0 -column 1 -sticky ns
grid configure .main.centre.horizontal -row 1 -column 0 -sticky ew
# Is there anything useful to be done in 1,1? e.g. a >> button to
# go directly to perform ".main.centre.text see end"
# Make sure that row 0 column 0, i.e. the text widget rather than the
# scrollbars, grows to fit all available space.
grid rowconfigure .main.centre 0 -weight 1
grid rowconfigure .main.centre 1 -weight 0
grid columnconfigure .main.centre 0 -weight 1
grid columnconfigure .main.centre 1 -weight 0
grid configure .main.nw -row 0 -column 0 -sticky news
grid configure .main.border_nw_n -row 0 -column 1 -sticky ns
grid configure .main.n -row 0 -column 2 -sticky news
grid configure .main.border_n_ne -row 0 -column 3 -sticky ns
grid configure .main.ne -row 0 -column 4 -sticky news
grid configure .main.border_nw_w -row 1 -column 0 -sticky ew
grid configure .main.border_n_centre -row 1 -column 1 -columnspan 3 -sticky ew
grid configure .main.border_ne_e -row 1 -column 4 -sticky ew
grid configure .main.w -row 2 -column 0 -sticky news
grid configure .main.border_w_centre -row 2 -column 1 -sticky ns
grid configure .main.centre -row 2 -column 2 -sticky news
grid configure .main.border_centre_e -row 2 -column 3 -sticky ns
grid configure .main.e -row 2 -column 4 -sticky news
grid configure .main.border_w_sw -row 3 -column 0 -sticky ew
grid configure .main.border_centre_s -row 3 -column 1 -columnspan 3 -sticky ew
grid configure .main.border_e_se -row 3 -column 4 -sticky ew
grid configure .main.sw -row 4 -column 0 -sticky news
grid configure .main.border_sw_s -row 4 -column 1 -sticky ns
grid configure .main.s -row 4 -column 2 -sticky news
grid configure .main.border_s_se -row 4 -column 3 -sticky ns
grid configure .main.se -row 4 -column 4 -sticky news
grid columnconfigure .main 0 -weight 0
grid columnconfigure .main 1 -weight 0
grid columnconfigure .main 2 -weight 1
grid columnconfigure .main 3 -weight 0
grid columnconfigure .main 4 -weight 0
grid rowconfigure .main 0 -weight 0
grid rowconfigure .main 1 -weight 0
grid rowconfigure .main 2 -weight 1
grid rowconfigure .main 3 -weight 0
grid rowconfigure .main 4 -weight 0
# The .main frame should not be packed into the main window yet.
# Until all devices have been instantiated the various subwindows
# are not yet known, so the desired size of .main is not known
# either. Packing it too early and then adding more windows
# causes confusion.
# }}}
# {{{ Help
# ----------------------------------------------------------------------------
# Two main sources of documentation are of interest to the synthetic
# target. The first is the toplevel eCos documentation. The second
# is the documentation specific to the generic target. Device-specific
# scripts may want to add menu entries for their own documentation.
#
# The problems are:
# 1) where to find the documentation
# 2) how to view it?
#
# The documentation should be in the component repository. If there is
# a variable ECOS_REPOSITORY then that gives the appropriate information.
# Otherwise things get messy because the repository being used for
# eCos may not match the repository used when building the host-side
# support - the versions should match but the repository may have
# moved. Never the less that is the best we can do.
# NOTE: sources.redhat.com might provide another alternative, but the
# documentation is not organized in the same way as the repository.
#
# As for how to view the documentation, this is up to user preferences
# but ecosynth has built-in knowledge of three different viewers.
namespace eval synth {
if { $synth::flag_debug } {
synth::report "Setting up help menu\n"
}
variable _browser1 "mozilla -remote openURL(%s)"
variable _browser2 "mozilla %s"
variable _browser3 "gnome-help-browser %s"
variable _main_help ""
variable _synth_help ""
set _repo ""
if { [info exists env(ECOS_REPOSITORY)] } {
set _repo $env(ECOS_REPOSITORY)
} else {
set _repo $synth::_ecos_repository
}
if { ![file exists [file join $_repo "ecos.db"]] } {
synth::report_warning "Failed to locate eCos component repository.\n \
Please define an environment variable ECOS_REPOSITORY.\n"
} else {
# FIXME: this needs attention once the documentation is more sorted
set synth::_main_help [file join $_repo "index.html"]
if { ![file exists $synth::_main_help] } {
if { 0 } {
synth::report_warning "Failed to locate toplevel documentation file $synth::_main_help\n \
Help->eCos menu option disabled.\n"
}
set synth::_main_help ""
} else {
set synth::_main_help "file://$_main_help"
}
set synth::_synth_help [file join $_repo $synth::_ecosynth_package_dir $synth::_ecosynth_package_version "doc/hal-synth-arch.html"]
if { ![file exists $synth::_synth_help] } {
synth::report_warning "Failed to locate synthetic target documentation $synth::_synth_help\n \
Help->Synthetic target menu option disabled.\n"
set synth::_synth_help ""
} else {
set synth::_synth_help "file://$_synth_help"
}
}
if { "" != $_main_help } {
.menubar.help add command -label "eCos" -command [list synth::_menu_help $synth::handle_help]
} else {
.menubar.help add command -label "eCos" -state disabled
}
if { "" != $_synth_help } {
.menubar.help add command -label "Synthetic target" -command [list synth::handle_help "$synth::_synth_help"]
} else {
.menubar.help add command -label "Synthetic target" -state disabled
}
unset _repo
proc handle_help { which } {
set command [format $synth::_browser1 $which]
if { 0 != [catch { eval exec -- "$command > /dev/null" } & ] } {
set command [format $synth::_browser2 $which]
if { 0 != [catch { eval exec -- "$command > /dev/null &" } ] } {
set command [format $synth::_browser3 $which]
if { 0 != [catch { eval exec -- "$command > /dev/null &"} ] } {
synth::report_warning "Unable to start a help browser.\n Please check the settings in Edit->Preferences.\n"
}
}
}
}
# FIXME: add an about box as well.
}
# }}}
# {{{ Filters
# ----------------------------------------------------------------------------
# The central text window is expected to provide the bulk of the information
# to the user. This information can b
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -