From acf2430dbdcad599bedf6cd9d54573b79c9c7f71 Mon Sep 17 00:00:00 2001 From: ahrenholz Date: Mon, 25 Nov 2013 19:56:08 +0000 Subject: [PATCH] allow executing XML files from GUI via File > Execute XML or Python script... adopt filename when connecting to running session having a filename (Boeing r1793) --- gui/api.tcl | 6 ++++-- gui/initgui.tcl | 3 ++- gui/plugins.tcl | 9 ++++++--- gui/util.tcl | 11 ++++++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/gui/api.tcl b/gui/api.tcl index 3c54bcea..f9b0fade 100755 --- a/gui/api.tcl +++ b/gui/api.tcl @@ -998,6 +998,7 @@ proc parseRegMessage { data len flags channel } { set current 0 set str 0 set session "" + set fnhint "" set plugin_cap_list {} ;# plugin capabilities list @@ -1034,6 +1035,7 @@ proc parseRegMessage { data len flags channel } { set session $str } else { lappend plugin_cap_list "$plugin_type=$str" + if { $plugin_type == "exec" } { set fnhint $str } } } else { if { $prmsg == 1} { puts -nonewline "unknown($type)," } @@ -1047,10 +1049,10 @@ proc parseRegMessage { data len flags channel } { if { $prmsg == 1 } { puts ") "} # reg message with session number indicates the sid of a session that - # was just started from a Python script (via reg exec=scriptfile.py) + # was just started from XML or Python script (via reg exec=scriptfile.py) if { $session != "" } { # assume session string only contains one session number - connectShutdownSession connect $channel $session + connectShutdownSession connect $channel $session $fnhint return } diff --git a/gui/initgui.tcl b/gui/initgui.tcl index f31d5e24..1121523c 100755 --- a/gui/initgui.tcl +++ b/gui/initgui.tcl @@ -240,7 +240,8 @@ bind . "fileSaveDialogBox {}" .menubar.file add separator .menubar.file add command -label "Export Python script..." -command exportPython -.menubar.file add command -label "Execute Python script..." -command execPython +.menubar.file add command -label "Execute XML or Python script..." \ + -command execPython .menubar.file add separator .menubar.file add command -label "Open current file in editor..." \ diff --git a/gui/plugins.tcl b/gui/plugins.tcl index 1c4b53c8..a6f2099a 100644 --- a/gui/plugins.tcl +++ b/gui/plugins.tcl @@ -989,9 +989,11 @@ proc sessionConfig { cmd wi channel } { # sid = 0 is new session, or the session number of an existing session set sid 0 + set fn "" foreach item [$wi.tree selection] { array set vals [$wi.tree set $item] set sid $vals(sid) + set fn $vals(fn) break; # TODO: loop on multiple selection for shutdown } if { $sid == $g_current_session } { @@ -1001,14 +1003,14 @@ proc sessionConfig { cmd wi channel } { set cmd "connect" set sid 0 } - connectShutdownSession $cmd $channel $sid + connectShutdownSession $cmd $channel $sid $fn } # switch sessions or shutdown the specified session # sid=0 indicates switching to a new session (disconnect from old and start a # new file) -proc connectShutdownSession { cmd channel sid } { - global g_current_session CORE_USER +proc connectShutdownSession { cmd channel sid fn } { + global g_current_session CORE_USER currentFile switch -exact -- $cmd { connect { @@ -1020,6 +1022,7 @@ proc connectShutdownSession { cmd channel sid } { set g_current_session $sid } # connect to an existing session + set currentFile $fn setOperMode exec set flags 0x11 ;# add flag, status req flag } diff --git a/gui/util.tcl b/gui/util.tcl index 79ebbe21..feed39e8 100644 --- a/gui/util.tcl +++ b/gui/util.tcl @@ -982,7 +982,16 @@ proc exportPython { } { # ask the daemon to execute the selected file proc execPython { } { - set fn [tk_getOpenFile -filetypes {{ "CORE Python scripts" {.py} }} ] + global fileDialogBox_initial g_prefs + set ft {{ "CORE XML or Python scripts" {.py .xml} } { "All files" {*}}} + + if { $fileDialogBox_initial == 0 } { + set fileDialogBox_initial 1 + set dir $g_prefs(default_conf_path) + set fn [tk_getOpenFile -filetypes $ft -initialdir $dir] + } else { + set fn [tk_getOpenFile -filetypes $ft] + } if { $fn == "" } { return } set flags 0x10 ;# status request flag sendRegMessage -1 $flags [list "exec" $fn]