#!/usr/bin/tclsh # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ # Copyright (C) 2007-2009 by Martin Ošmera # # 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. # ############################################################################ # -------------------------------------------------------------------------- # DESCRIPTION # "Provides various dialogs and various variables for various things" # For instance the "Go to" dialog is placed here # -------------------------------------------------------------------------- # Dialog for selecting MCU and loading MCU details from definition file source "${::LIB_DIRNAME}/dialogs/selectmcu.tcl" namespace eval X { ## General variable unsaved_projects {} ;# List: List of project object marked as "unsaved" variable critical_procedure_in_progress 1 ;# Bool: Disable critical procedures (like compilation, start simulator, etc.) variable foo_procedure_in_progress 0 ;# Bool: Disables some non-critical procedures variable last_WIN_GEOMETRY {} ;# Last window geometry (main window) variable actualProject {} ;# Object: Current project variable openedProjects {} ;# List of opened projects (Object references) variable actualProjectIdx -1 ;# Index of the current project in $openedProjects variable project_menu_locked 1 ;# Bool: Indicates than there is at least one opened project if {!$::MICROSOFT_WINDOWS} { variable defaultDirectory ${::env(HOME)} ;# Default directory } { variable defaultDirectory ${::env(USERPROFILE)} ;# Default directory } variable simulator_enabled {} ;# List of booleans: Simulator engaged variable editor_lines ;# Number of lines in the current editor variable fsd_result {} ;# Value returnded by file selection dialog (in some cases) variable projectmenu {.project_menu} ;# ID of Popup menu for project tabs variable projectmenu_project {} ;# Object: project selected by project popup menu variable selectedView ;# Int: Selected editor by editor statusbar popup menu variable open_f_external_editor 0 ;# Bool: Use procedure __open to open new file for embedded external editor variable file_recent_files {} ;# List: recently opened files variable project_recent_files {} ;# List: recently opened projects variable vhw_recent_files {} ;# List: recently opened Virtual HW files # List of supported processors variable avaliable_processors [::SelectMCU::get_avaliable_processors] variable procedure_exit_in_progress 0 ;# Bool: proc "__exit" in progress ## Doxygen variable doxygen_run_doxywizard 0 ;# Bool: Run doxywizard variable doxygen_build_api_doc 0 ;# Bool: Build API documentation variable doxygen_pid 0 ;# Int: Doxygen PID variable doxygen_mess_project ;# Object: Project related to running doxygen compilation ## ASCII chart variable ascii_chart_win_object {} ;# Object: ASCII chart window object ## 8-segment LED editor variable eightsegment_editors {} ;# List: All 8-segment LED display editors invoked ## Base convertor variable base_convertors {} ;# List: All base convertor objects ## Special calculator variable spec_calc_objects {} ;# List: All special calculator objects ## UART/RS232 debugger variable rs232debugger_objects {} ;# List: All "RS232 debugger" objects ## Dialog "Go to" variable goto ;# Line where to go ## Function "Auto-indent" variable reformat_code_abort ;# Bool: Abort function 'reformat_code' ## Dialog "Find" variable find_String ;# Search string variable find_forward_index ;# Search index for forward search variable find_backward_index ;# Search index for backward search variable find_option_CS ;# Bool: Case sensitive variable find_option_notCS ;# Bool: Case insensitive variable find_option_back ;# Bool: Search backwards (checkbox) variable find_option_cur ;# Book: Search from cursor variable find_option_sel ;# Bool: Search only in the seleted text variable find_option_reg ;# Bool: Consider search string to be a regular expression variable find_allow_selection ;# Bool: There is some selected text in editor variable find_retry_search ;# Bool: Search restarted from begining/end variable find_back_dir ;# Bool: Search backwards (real option) variable find_history {} ;# List of the last 10 search strings variable find_next_prev_in_P 0 ;# Bool: Procedure 'find_next_prev' in progress ## Dialog "Replace" variable replace_String ;# String to replace variable replace_Replacement ;# Replacement for the search string variable replace_option_CS ;# Bool: Case sensitive variable replace_option_back ;# Bool: Search backwards (checkbox) variable replace_option_cur ;# Book: Search from cursor variable replace_option_reg ;# Bool: Consider search string to be a regular expression variable replace_option_prompt ;# Bool: Prompt on replace variable replace_prompt_opened 0 ;# Bool: Replace prompt dialog opened variable replace_prompt_return_value ;# Replace prompt dialog return value variable replace_prompt_geometry ;# Geometry of replace prompt dialog window variable replace_search_history {} ;# List of the last 10 search strings variable replace_repl_history {} ;# List of the last 10 replacement strings ## Dialog "Select directory" variable select_directory_var {} ;# Selected directory ## Dialog "New project" variable project_new_name ;# Name of the new project variable project_new_dir ;# Directory of the new project ## Variable common for "New project" and "Edit project" variable project_new_processor ;# Processor type (e.g. "8051") variable project_new_xdata_ena ;# Bool: XDATA memory connected variable project_new_xcode_ena ;# Bool: XCODE memory connected variable project_new_xdata ;# Int: Amount of XDATA memory variable project_new_xcode ;# Int: Amount of XCODE memory variable project_new_max_xcode ;# Int: Maximum valid value of external program memory variable project_new_xd_chb ;# Widget: XDATA enable checkbutton variable project_new_xd_scl ;# Widget: XDATA scale variable project_new_xd_spb ;# Widget: XDATA spinbox variable project_new_xc_chb ;# Widget: XCODE enable checkbutton variable project_new_xc_scl ;# Widget: XCODE scale variable project_new_xc_spb ;# Widget: XCODE spinbox ## Dialog "Edit project" variable project_edit_version ;# Project version variable project_edit_date ;# Project date (last update) variable project_edit_copyright ;# Copyright information variable project_edit_licence ;# Licence information variable project_edit_authors ;# Project authors variable project_edit_description ;# Project description variable project_edit_clock ;# Default clock rate variable project_edit_main_file ;# Project main file variable project_edit_main_file_clr_but ;# Widget: Project main file clear button # Some default project values # format: {{variable value} {variable value} ...} variable project_edit_defaults { {project_edit_family 8051 } {project_edit_clock 12000 } {project_edit_calc_rad Dec } {project_edit_calc_ang rad } } ## Functions related to project management (save, load) variable project_watches_file ;# File of register watches of the current poject variable project_todo ;# Todo text variable project_graph ;# Graph configuration list variable project_calculator ;# Calculator list (display contents, etc.) variable project_other_options ;# Other project options variable project_compiler_options ;# Compiler options variable project_files ;# List of project files (special format) variable project_file ;# Full name of the project file variable project_dir ;# Path to project directory ## Compilation related variables variable compilation_success_callback {} ;# String: Indented for HW plugins variable compilation_fail_callback {} ;# String: Indented for HW plugins variable compilation_mess_project {} ;# Object: Project related to running compilation variable compilation_successfull 1 ;# Bool: Compilation successfull variable compilation_in_progress 0 ;# Bool: Compiler engaged variable compilation_progress 0 ;# Variable for compilation progressbar variable compiler_pid 0 ;# Int: PID of external compiler if used variable compilation_start_simulator 0 ;# Bool: Start simulator after successful compilation variable compile_this_file_only 0 ;# Bool: Compile the current file only ## Dialog "Select input/uotput file" variable input_file ;# Input file variable output_file ;# Output file variable IO ;# Bool: 1 == choose input file; 0 == choose output file ### Dialogs "Hex->Bin; Bin->Hex; Sim->Hex; Sim->Bin; Nomalize Hex" # Type of conversion # 0 == Bin -> Hex # 1 == Hex -> Bin # 2 == Sim -> Hex # 3 == Sim -> Bin variable hex__bin ## XDATA/CODE/ERAM/EEPROM/UNI memory hexadecimal editors variable opended_code_mem_windows {} ;# List of project object with opened CODE memory hex editor variable code_mem_window_objects {} ;# List of CODE memory hex editor objects variable opended_xdata_mem_windows {} ;# List of project object with opened XDATA memory hex editor variable xdata_mem_window_objects {} ;# List of XDATA memory hex editor objects variable opended_eram_windows {} ;# List of project object with opened ERAM hex editor variable eram_window_objects {} ;# List of ERAM hex editor objects variable opended_eeprom_mem_windows {} ;# List of project object with opened data EEPROM hex editor variable eeprom_mem_window_objects {} ;# List of data EEPROM hex editor objects variable opended_eeprom_wr_bf_windows {} ;# List of project objects with opened data EEPROM write buffer editor variable eeprom_wr_bf_window_objects {} ;# List of data EEPROM write buffer hex editor objects variable eeprom_wr_buf_counter 0 ;# Counter of EEPROM write buffer hex editor objects variable saving_progress 0 ;# Variable for progressbars representing saving progress variable abort_saving 0 ;# Bool: Abort saving of IHEX8 file variable independent_hexeditor_count 0 ;# Counter of intances of independent hexadecimal editor # Path to file defining the last session variable session_file "${::CONFIG_DIR}/last_session.conf" ## Dialog "Cleanup project folder" # GLOB patterns in certain order ! variable cleanup_masks { *.asm~ *.lst~ *.sim~ *.hex~ *.bin~ *.html~ *.tex~ *.wtc~ *.mcu8051ide~ *.m5ihib~ *.cdb~ *.ihx~ *.adf~ *.omf~ *.map~ *.c~ *.h~ *.vhc~ *.vhw~ *.txt~ *~ *.lst *.sim *.hex *.bin *.html *.tex *.m5ihib *.noi *.obj *.map *.p *.mac *.i *.ihx *.adf *.adb *.rel *.cdb *.mem *.lnk *.sym *.omf *.rst *.hashes *bak } ## Dialog "Change letter case" variable change_letter_case_options ;# Options (which fields should be adjusted) ## Dialog "Line to address" variable line2pc ;# Int: Selected line in source code variable line2pc_jump 1 ;# Bool: Perform program jump (1) or subprogram call (0) variable line2pc_line_max ;# Int: Number of lines in the source code variable line2pc_value_lbl ;# Widget: Label containing PC value variable line2pc_new_value ;# Int: Resolved address or {} variable line2pc_org_line ;# Int: Original line variable line2pc_ok_button ;# Widget: Button "OK" variable line2pc_file_number ;# Int: File number ## Dialog "File statistics" variable statistics_counter 0 ;# Int: Counter of invocations of this dialog ## Project details window variable PROJECTDETAILSWIN ;# ID of project details window variable projectdetails_last_project {} ;# Project object of the last project details window ## Cutom commands related variables variable custom_cmd_dialog_index 0 ;# Index of results dialog (to keep win IDs unique) variable custom_command_cmd ;# Array of custom commands (shell scripts) variable custom_command_options ;# Array of Lists of custom command options variable custom_command_desc ;# Array of custom command descriptions variable custom_command_PID ;# Array of custom command PIDs (Process IDentifiers) variable custom_command_NUM ;# Array of custom command numbers variable custom_command_counter 0 ;# Counter of custom command invocations ## Initialize custom commands related variables # Shell scripts set custom_command_cmd(0) [mc "echo \"This is a custom command\"\necho \"\tYou can configure it in Main menu->Configure->Edit user commands.\"\necho \"\tCustom commands are intended for running external programs from this IDE (e.g. program uploaders)\""] append custom_command_cmd(0) "\n\necho \"\nThis is a custom command\"\necho \"\tYou can configure it in Main menu->Configure->Edit user commands.\"\necho \"\tCustom commands are intended for running external programs from this IDE (e.g. program uploaders)\"" set custom_command_cmd(1) $custom_command_cmd(0) set custom_command_cmd(2) $custom_command_cmd(0) # Command options set custom_command_options(0) {0 1 0} set custom_command_options(1) $custom_command_options(0) set custom_command_options(2) $custom_command_options(0) # Command descritpions set custom_command_desc(0) [mc "More: Main menu -> Configure -> Edit user commands"] set custom_command_desc(1) $custom_command_desc(0) set custom_command_desc(2) $custom_command_desc(0) # Command Thread IDentifiers set custom_command_PID(0) {} set custom_command_PID(1) $custom_command_PID(0) set custom_command_PID(2) $custom_command_PID(0) # Custom command numbers set custom_command_NUM(0) {} set custom_command_NUM(1) $custom_command_NUM(0) set custom_command_NUM(2) $custom_command_NUM(0) ## Menu and Toolbar related variables # Menu bar items which require opened project variable mainmenu_project_dependent_buttons { { ".mainMenu" { "Edit" "View" "Simulator" "Virtual MCU" "Virtual HW" "Tools"} } { ".mainMenu.project" { "Save" "Edit project" "Close without saving" "Save and close"} } { ".mainMenu.file" { "New" "Open" "Open recent" "Save" "Save as" "Save all" "Close" "Close all" "File statistics"} } { ".mainMenu.configure" { "Configure Compiler"} } } # Menu bar items which require ENGAGED simulator variable mainmenu_simulator_engaged { { ".mainMenu.simulator" { "Step" "Step over" "Animate" "Run" "Jump to line" "Find cursor" "Step back" "Clear highlight" "Hiberante program" "Resume hibernated program" } } { ".mainMenu.virtual_mcu" { "Reset" } } } # Menu bar items which require DISENGAGED simulator variable mainmenu_simulator_disengaged { { ".mainMenu.file" { "New" "Open" "Close" "Close all"} } { ".mainMenu.edit" { "Undo" "Redo" "Cut" "Paste" "Replace" "Comment" "Uncomment" "Indent" "Unindent"} } { ".mainMenu.display" { "Read only mode" "Reload"} } { ".mainMenu.simulator" { "Debug this file only" } } { ".mainMenu.tools" { "Compile" "Disassemble" "Encoding" "End of line" "Auto indent" "Change letter case" "Document current function" "Compile this file"} } } # Menu bar items which are not avaliable when editor is in read only mode variable mainmenu_editor_readonly { { ".mainMenu.edit" { "Undo" "Redo" "Cut" "Paste" "Replace" "Comment" "Uncomment" "Indent" "Unindent"} } { ".mainMenu.tools" { "Auto indent" "Change letter case" "Document current function"} } } # Menu bar items which are not avaliable only for C language variable mainmenu_editor_c_only { { ".mainMenu.tools" { "Document current function"} } } # Menu bar items which are not avaliable when external embedded editor is used variable mainmenu_editor_external_na { {.mainMenu.tools { {Encoding} {End of line} {Auto indent} {Change letter case} {Export as XHTML} {Export as LaTeX} {Auto indent} {Change letter case} {Document current function} } } {.mainMenu.file { {Save} {Save as} {Save all} {File statistics} } } {.mainMenu.display { {Read only mode} {Switch to command line} {Highlight} {Show/Hide line numbers} {Reload} {Show/Hide icon border} } } {.mainMenu.simulator { {Find cursor} {Jump to line} } } {.mainMenu { {Edit} } } } # Toolbar buttons which require opened project variable toolbar_project_dependent_buttons { new open save save_as save_all close close_all undo redo cut copy paste find findnext findprev replace goto reload clear proj_save proj_edit proj_close proj_close_imm show_code_mem show_ext_mem start_sim reset step stepover animate run assemble disasm reformat_code toHTML toLaTeX cleanup custom0 custom1 custom2 change_case forward back clear_hg intrmon hibernate resume stepback find_sim_cur line2addr show_exp_mem sfrmap show_eeprom show_eem_wr_b stopwatch bitmap ledpanel leddisplay ledmatrix mleddisplay simplekeypad matrixkeypad vhw_open vhw_load vhw_save vhw_saveas vhw_remove_all stack } # Toolbar buttons which require ENGAGED simulator variable toolbar_simulator_engaged { reset step stepover animate run clear_hg find_sim_cur line2addr stepback hibernate resume } # Toolbar buttons which require DISENGAGED simulator variable toolbar_simulator_disengaged { new open close close_all undo redo cut copy paste replace reload assemble start_sim0 disasm reformat_code change_case assemble0 } # Toolbar items which are not avaliable when editor is in read only mode variable toolbar_editor_readonly { undo redo cut paste replace reformat_code change_case } # Toolbar items which are not avaliable only for C language variable toolbar_editor_c_only { } # Toolbar items which are not avaliable when external embedded editor is used variable toolbar_editor_external_na { save save_as undo redo cut copy paste find findnext findprev replace goto reload reformat_code change_case toHTML toLaTeX find_sim_cur line2addr save_all } ## This function should be immediately after load of environment.tcl # @return void proc initialize {} { variable projectmenu ;# ID of Popup menu for project tabs menuFactory { {command "Save" "$project:proj_save" 0 {__project_pmenu_save} "filesave" "Save this project"} {command "Edit project" "$project:proj_edit" 0 {__project_pmenu_edit} "configure" "Edit additional project detail"} {separator} {command "Save and close" "$project:proj_close" 1 {__project_pmenu_close} "fileclose" "Save and close this project"} {command "Close without saving" "$project:proj_clsimm" 0 {__project_pmenu_close_imm} "no" "Close this project"} {separator} {command "Move left" "" 5 {__project_move_to_left} "1leftarrow" "Move this tab to right the beginning of the tab bar"} {command "Move right" "" 5 {__project_move_to_right} "1rightarrow" "Move this tab to right the end of the tab bar"} {separator} {command "Move to beginning" "" 8 {__project_move_to_beginning} "2leftarrow" "Move this tab to right the beginning of the tab bar"} {command "Move to end" "" 9 {__project_move_to_end} "2rightarrow" "Move this tab to right the end of the tab bar"} } $projectmenu 0 "::X::" 0 {} } ## Switch current project # @parm String project_name - Project object reference # @return void proc switch_project {project_name} { variable actualProject ;# Object: Current project variable actualProjectIdx ;# Index of the current project in $openedProjects variable openedProjects ;# List of opened projects (Object references) variable simulator_enabled ;# List of booleans: Simulator engaged # Ensure that autocompletion window is closed ::Editor::close_completion_popup_window_NOW if {$actualProjectIdx != -1 && ([lindex $simulator_enabled $actualProjectIdx] == 1)} { if {[$actualProject sim_stepover_in_progress]} { $actualProject sim_stepover } elseif {[$actualProject sim_run_in_progress]} { $actualProject sim_run } elseif {[$actualProject sim_anim_in_progress]} { $actualProject sim_animate } } set actualProject [string trimleft $project_name {:}] set actualProjectIdx [lsearch -exact -ascii $openedProjects $actualProject] disaena_menu_toolbar_for_current_project adjust_title $actualProject adjust_compiler_settings } ## Enable / Disable menu and toolbar item acording to current state of current project # @return void proc disaena_menu_toolbar_for_current_project {} { variable project_menu_locked ;# Bool: Indicates than there is at least one opened project variable actualProject ;# Object: Current project variable actualProjectIdx ;# Index of the current project in $openedProjects variable simulator_enabled ;# List of booleans: Simulator engaged # This procedure requires at least one opened project if {$project_menu_locked} {return} # Adjust state simulator related menu/toolbar items if {[lindex $simulator_enabled $actualProjectIdx] == 1} { Unlock_simulator_menu # Enable / Disabled stepback buttons stepback_button_set_ena [$actualProject simulator_get_SBS_len] } { Lock_simulator_menu adjust_mainmenu_and_toolbar_to_editor \ ${::editor_RO_MODE} \ [expr {1 == [$actualProject editor_procedure {} get_language {}]}] } ## Disable/Enable menu+toolbar entries related to simulator controls which depends on current MCU disena_simulator_menu $actualProject } ## Disable/Enable menu+toolbar entries related to simulator # +controls which depends on current MCU # @parm Object project - Current project # @return void proc disena_simulator_menu {project} { # Enable/Disable controls related to hexadecimal editors ena_dis_menu_buttons 0 {{ ".mainMenu.virtual_mcu" { "Show XDATA memory" "Show ERAM" "Show EEPROM write buffer" "Show Data EEPROM"} }} ena_dis_iconBar_buttons 0 .mainIconBar. { show_ext_mem show_exp_mem show_eeprom show_eem_wr_b } set toolbar {} set mainmenu {} if {[lindex [$project cget -procData] 8]} { lappend toolbar {show_exp_mem} lappend mainmenu {Show ERAM} } if {[$project cget -P_option_mcu_xdata]} { lappend toolbar {show_ext_mem} lappend mainmenu {Show XDATA memory} } if {[lindex [$project cget -procData] 32]} { lappend toolbar {show_eeprom} lappend toolbar {show_eem_wr_b} lappend mainmenu {Show EEPROM write buffer} lappend mainmenu {Show Data EEPROM} } ena_dis_menu_buttons 1 [list [list {.mainMenu.virtual_mcu} $mainmenu]] ena_dis_iconBar_buttons 1 .mainIconBar. $toolbar } ## Ensure than simulator isn't engaged # @parm Bool message - Invoke error message if simulator is engaged # @return Bool - result (1 == is engaged; 0 == is not engaged) proc simulator_must_be_disabled {message} { variable simulator_enabled ;# List of booleans: Simulator engaged variable actualProjectIdx ;# Index of the current project in $openedProjects if {[lindex $simulator_enabled $actualProjectIdx] == {}} { return 1 } if {[lindex $simulator_enabled $actualProjectIdx] == 1} { if {$message} { tk_messageBox \ -title [mc "Unable to compile"] \ -icon info \ -type ok \ -message [mc "Simulator is engaged, shutdown the simulator first."] } return 1 } return 0 } ## New file # @return void proc __new {} { variable actualProject ;# Object: Current project variable actualProjectIdx ;# Index of the current project in $openedProjects variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 1]} {return} # Use dialog "Open file" to create new file with embedded external editor if {${::Editor::editor_to_use}} { __open 1 return } # This function is critical if {$critical_procedure_in_progress} {return} set critical_procedure_in_progress 1 # Create new editor $actualProject editor_new set critical_procedure_in_progress 0 } ## Open file # @parm Bool = 0 - 1 == New file (for embedded external editor); 0 == Open an existing file # @return void proc __open args { variable actualProject ;# Object: Current project variable actualProjectIdx ;# Index of the current project in $openedProjects variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project variable open_f_external_editor ;# Bool: Use procedure __open to open new file for embedded external editor if {$project_menu_locked} {return} if {[simulator_must_be_disabled 1]} {return} # This function is critical if {$critical_procedure_in_progress} {return} set critical_procedure_in_progress 1 # Parse input arguments set open_f_external_editor [lindex $args 0] if {$open_f_external_editor != 1} { set title [mc "Open file - MCU 8051 IDE"] set open_f_external_editor 0 } { set title [mc "New file - MCU 8051 IDE"] set open_f_external_editor 1 } # Invoke the file selection dialog switch -- [file extension [lindex [$actualProject editor_procedure {} getFileName {}] 1]] { {.asm} {set defaultmask 0} {.c} {set defaultmask 1} {.h} {set defaultmask 2} {.lst} {set defaultmask 3} default {set defaultmask 4} } set directory [lindex [$actualProject editor_procedure {} getFileName {}] 0] if {$directory == {.}} { set directory [$actualProject cget -projectPath] } catch {delete object fsd} KIFSD::FSD fsd \ -title $title -directory $directory \ -defaultmask $defaultmask -multiple 1 -filetypes [list \ [list [mc "Assembly language"] {*.asm}] \ [list [mc "C source"] {*.c}] \ [list [mc "C header"] {*.h}] \ [list [mc "Code listing"] {*.lst}] \ [list [mc "All files"] {*}] \ ] # Open file after press of OK button fsd setokcmd { foreach filename [X::fsd get] { if {!$::MICROSOFT_WINDOWS} { ;# POSIX way if {![regexp "^(~|/)" $filename]} { set filename "[${X::actualProject} cget -ProjectDir]/$filename" } } { ;# Microsoft windows way if {![regexp "^\w:" $filename]} { set filename [file join [${X::actualProject} cget -ProjectDir] $filename] } } set filename [file normalize $filename] if {[file isdirectory $filename]} { tk_messageBox \ -type ok \ -icon warning \ -parent . \ -title [mc "Operation aborted"] \ -message [mc "The file you choosed appears to be a directory:\n%s\n\nSuch an operation doesn't make sense." $filename] continue } # Open the specified file if {${::X::open_f_external_editor} || [file exists $filename]} { if {[${X::actualProject} openfile $filename 1 \ [X::fsd get_window_name] def def 0 0 {}] != {} } { ${X::actualProject} switch_to_last update idle ${X::actualProject} editor_procedure {} parseAll {} # Make LST read only if {[file extension $filename] == {.lst}} { set ::editor_RO_MODE 1 ${X::actualProject} switch_editor_RO_MODE } ::X::recent_files_add 1 $filename } } { ${X::actualProject} editor_new ${X::actualProject} save_as $filename if {!${::Editor::editor_to_use}} { tk_messageBox \ -type ok \ -icon warning \ -parent [::X::fsd get_window_name] \ -title [mc "File not found - MCU 8051 IDE"] \ -message [mc "The selected file do not exist:\n%s" $filename] } } } } # activate the dialog fsd activate adjust_title set critical_procedure_in_progress 0 } ## Save file # @return void proc __save {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} # This function is critical if {$critical_procedure_in_progress} {return} set critical_procedure_in_progress 1 # Save file $actualProject editor_procedure {} save {} set critical_procedure_in_progress 0 } ## Save file under different filename # @return void proc __save_as {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} # This function is critical if {$critical_procedure_in_progress} {return} set critical_procedure_in_progress 1 # Invoke the dialog set filename [$actualProject editor_procedure {} getFileName {}] switch -- [file extension [lindex $filename 1]] { {.asm} {set defaultmask 0} {.c} {set defaultmask 1} {.h} {set defaultmask 2} default {set defaultmask 3} } set directory [lindex [$actualProject editor_procedure {} getFileName {}] 0] if {$directory == {.}} { set directory [$actualProject cget -projectPath] } catch {delete object fsd} KIFSD::FSD fsd \ -initialfile [lindex $filename 1] \ -title [mc "Save file - MCU 8051 IDE"] \ -directory $directory \ -defaultmask $defaultmask -multiple 0 -filetypes { {{Assembly language} {*.asm} } {{C source} {*.c} } {{C header} {*.h} } {{All files} {*} } } # Save file after press of OK button fsd setokcmd { set filename [X::fsd get] ${X::actualProject} save_as $filename } # activate the dialog fsd activate set critical_procedure_in_progress 0 } ## Save all opened file of the current project # @return void proc __save_all {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} # This function is critical if {$critical_procedure_in_progress} {return} set critical_procedure_in_progress 1 # Save all opended files $actualProject editor_save_all set critical_procedure_in_progress 0 } ## Close the curent file # @return void proc __close {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 1]} {return} # This function is critical if {$critical_procedure_in_progress} {return} set critical_procedure_in_progress 1 # Close file $actualProject editor_close 1 {} set critical_procedure_in_progress 0 } ## Close all opended files # @return void proc __close_all {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 1]} {return} # This function is critical if {$critical_procedure_in_progress} {return} set critical_procedure_in_progress 1 # Close all files $actualProject editor_close_all 1 0 set critical_procedure_in_progress 0 } ## Take back the last operation # @return void proc __undo {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} return if {$critical_procedure_in_progress} {return} # Undo $actualProject editor_procedure {} undo {} } ## Take back the last undo operation # @return void proc __redo {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} return if {$critical_procedure_in_progress} {return} # Redo $actualProject editor_procedure {} redo {} } ## Copy selected text to clipboard # @return void proc __copy {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} return if {$critical_procedure_in_progress} {return} # Copy $actualProject editor_procedure {} copy {} } ## Cut selected text (copy to clipboard and remove) # @return void proc __cut {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} return if {$critical_procedure_in_progress} {return} # Cut $actualProject editor_procedure {} cut {} } ## Paste text from clipboard # @return void proc __paste {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} return if {$critical_procedure_in_progress} {return} # Paste $actualProject editor_procedure {} paste {} } ## Indent selected text or the current line # @return void proc __indent {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} return if {$critical_procedure_in_progress} {return} # Indent $actualProject editor_procedure {} indent {} } ## Unindent selected text or the current line # @return void proc __unindent {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} return if {$critical_procedure_in_progress} {return} # Unindent $actualProject editor_procedure {} unindent {} } ## Invoke find dialog # @return void proc __find {} { variable actualProject ;# Object: Current project variable find_String ;# Search string variable find_option_CS ;# Bool: Case sensitive variable find_option_back ;# Bool: Search backwards (checkbox) variable find_option_cur ;# Book: Search from cursor variable find_option_sel ;# Bool: Search only in the seleted text variable find_option_reg ;# Bool: Consider search string to be a regular expression variable find_allow_selection ;# Bool: There is some selected text in editor variable find_history ;# List of the last 10 search strings variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {${::Editor::editor_to_use}} {return} if {$project_menu_locked} {return} if {$critical_procedure_in_progress} {return} # Determinate selected text set selectedText [$actualProject editor_procedure {} getselection {}] if {$selectedText != {}} { set find_String $selectedText } # Create a new toplevel window for the dialog set win [toplevel .find -class {Find dialog} -bg {#EEEEEE}] # String to search for label $win.findLabel -compound left -image ::ICONS::16::find -text [mc "Text to find:"] set findFrame [ttk::labelframe $win.findFrame \ -labelwidget $win.findLabel \ -relief flat \ ] pack $findFrame -fill x -expand 1 -pady 10 -padx 5 pack [ttk::combobox $findFrame.entry \ -textvariable X::find_String \ -exportselection 0 \ -values $find_history \ ] -fill x -expand 1 -padx 10 DynamicHelp::add $findFrame.entry -text [mc "String to find"] # Create and pack options labelframe label $win.optionsLabel -compound left -image ::ICONS::16::configure -text [mc "Options"] set optionsFrame [ttk::labelframe $win.optionsFrame \ -labelwidget $win.optionsLabel \ ] pack $optionsFrame -fill both -expand 1 -padx 10 # Determinate wheather there is some selected text if {[$actualProject editor_procedure {} getselection {}] == {}} { set find_allow_selection 0 } { set find_allow_selection 1 } # Create matrix of option checkbuttons set col 0 ;# Grid column set row 0 ;# Grid row foreach opt { CS back cur sel reg } \ txt { "Case sensitive" "Backwards" "From cursor" "Selected text" "Regular expr." } \ helptext { {Case sensitive search} {Search backwards from the specified location} {Start search from cursor instead of begining} {Search within selected text only} {Use search string as regular expression} } \ { # Disable/Enable "in selection" checkbox if {$opt == {sel} && !$find_allow_selection} { set state disabled set X::find_option_sel 0 } { set state normal } # Create checkbutton grid [checkbutton $optionsFrame.option_$opt \ -text [mc $txt] \ -variable X::find_option_$opt \ -state $state \ ] -column $col -row $row -sticky wns DynamicHelp::add $optionsFrame.option_$opt -text $helptext incr col if {$col == 2} { set col 0 incr row } } # Create and pack 'OK' and 'CANCEL' buttons set buttonFrame [frame $win.buttonFrame] pack [ttk::button $buttonFrame.ok \ -text [mc "Ok"] \ -compound left \ -image ::ICONS::16::ok \ -command {X::find_FIND} \ ] -side left -padx 2 pack [ttk::button $buttonFrame.cancel \ -text [mc "Cancel"] \ -compound left \ -image ::ICONS::16::button_cancel \ -command {X::find_CANCEL} \ ] -side left -padx 2 pack $buttonFrame -pady 5 # Events binding (Enter == Find; Escape == Cancel) bind $win {X::find_FIND; break} bind $win {X::find_FIND; break} bind $win {X::find_CANCEL; break} # Nessesary window manager options -- for modal window wm iconphoto $win ::ICONS::16::find wm title $win [mc "Find - MCU 8051 IDE"] wm minsize $win 300 210 wm protocol $win WM_DELETE_WINDOW { X::find_CANCEL } wm transient $win . update raise $win catch {grab $win} focus $findFrame.entry catch { $findFrame.entry.e selection range 0 end } tkwait window $win } ## Cancel find dialog -- auxiliary procedure for '__find' # @return void proc find_CANCEL {} { if {![winfo exists .find]} {return} destroy .find grab release .find } ## Perform search -- auxiliary procedure for '__find' # @return Bool - result proc find_FIND {} { variable actualProject ;# Object: Current project variable find_allow_selection ;# Bool: There is some selected text in editor variable find_String ;# Search string variable find_forward_index ;# Search index for forward search variable find_backward_index ;# Search index for backward search variable find_option_CS ;# Bool: Case sensitive variable find_option_notCS ;# Bool: Case insensitive variable find_option_back ;# Bool: Search backwards (checkbox) variable find_option_cur ;# Book: Search from cursor variable find_option_sel ;# Bool: Search only in the seleted text variable find_option_reg ;# Bool: Consider search string to be a regular expression variable find_retry_search ;# Bool: Search restarted from begining/end variable find_back_dir ;# Bool: Search backwards (real option) variable find_history ;# List of the last 10 search strings # Append search string to history if {[lsearch -exact -ascii $find_history $find_String] == -1} { lappend find_history $find_String } # History mustn't contain more than 10 items if {[llength $find_history] > 10} { set find_history [lrange $find_history [expr {[llength $find_history] - 10}] end] } # New search set find_retry_search 0 ;# Search has not been restarted set find_back_dir $find_option_back ;# Search backwards/forwards # Cancel the find dialog find_CANCEL # Check for validity of the search string if {$find_String == {}} { return 0 } # Adjust option "Search in selected text" set find_option_notCS [expr {!$find_option_CS}] if {!$find_allow_selection} { set option_sel 0 } { set option_sel $find_option_sel } # Perform search set result [$actualProject editor_procedure {} find [list \ $find_option_cur $find_option_back \ $find_option_reg $find_option_notCS \ $option_sel {} \ $find_String]] # Search failed -> show error message if {[lindex $result 0] == -1} { tk_messageBox -icon warning \ -parent . -type ok \ -title [mc "Unable to execute"] \ -message [lindex $result 1] return 0 } # Set search indexes set find_backward_index [lindex $result 0] set find_forward_index [lindex $result 1] # Finalize set matches [lindex $result 2] Sbar [mc "Search result: %s matches found" $matches] ;# Show final result if {$matches == 0} retry_search ;# Ask for retry # Success return 1 } ## Retry search -- auxiliary procedure for '__find' # Useful when search cursor reach begining/end of the document # @return Bool result proc retry_search {} { variable find_retry_search ;# Bool: Search restarted from begining/end variable find_String ;# Search string variable find_option_back ;# Bool: Search backwards (checkbox) variable find_option_cur ;# Book: Search from cursor variable find_backward_index ;# Search index for backward search variable find_forward_index ;# Search index for forward search variable find_back_dir ;# Bool: Search backwards (real option) variable find_next_prev_in_P ;# Bool: Procedure 'find_next_prev' in progress # There is only one allowed retry if {$find_retry_search || !$find_option_cur} { set find_retry_search 0 tk_messageBox \ -icon warning \ -type ok \ -title [mc "Find - %s" ${::APPNAME}] \ -message [mc "Search string '%s' not found !" $find_String] \ -parent . set find_next_prev_in_P 0 return } set find_option_cur_tmp $find_option_cur ;# Search cursor set find_retry_search 1 ;# This is the first retry # Backward search if {$find_back_dir} { if {[tk_messageBox \ -icon question \ -type yesno \ -parent . \ -title [mc "Find - %s" ${::APPNAME}] \ -message [mc "Begining of document reached\n\nContinue from end ?"] \ ]} { set find_next_prev_in_P 0 set find_backward_index end set find_forward_index 1.0 set find_option_cur 0 # Retry search find_next_prev [expr {!$find_option_back}] } # Forward search } { if {[tk_messageBox \ -icon question \ -type yesno \ -parent . \ -title [mc "Find - %s" ${::APPNAME}] \ -message [mc "End of document reached\n\nContinue from begining ?"] \ ]} { set find_next_prev_in_P 0 set find_backward_index end set find_forward_index 1.0 set find_option_cur 0 # Retry search find_next_prev $find_option_back } } set find_next_prev_in_P 0 set find_option_cur $find_option_cur_tmp set find_retry_search 0 } ## Find next occurence of the search string # @return void proc __find_next {} { variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {$critical_procedure_in_progress} {return} # Perform search find_next_prev 0 } ## Find previous occurence of the search string # @return void proc __find_prev {} { variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {$critical_procedure_in_progress} {return} # Perform search find_next_prev 1 } ## Find next/previous occurence of the search string # @parm Bool back_dir - Search backwards # @return void proc find_next_prev {back_dir} { variable actualProject ;# Object: Current project variable find_String ;# Search string variable find_backward_index ;# Search index for backward search variable find_forward_index ;# Search index for forward search variable find_option_notCS ;# Bool: Case insensitive variable find_option_back ;# Bool: Search backwards (checkbox) variable find_option_cur ;# Book: Search from cursor variable find_option_sel ;# Bool: Search only in the seleted text variable find_option_reg ;# Bool: Consider search string to be a regular expression variable find_retry_search ;# Bool: Search restarted from begining/end variable find_back_dir ;# Bool: Search backwards (real option) variable find_next_prev_in_P ;# Bool: Procedure 'find_next_prev' in progress # This function is not avaliable for exeternal embedded editors if {${::Editor::editor_to_use}} {return} # This function cannot run multithreaded if {$find_next_prev_in_P} {return} set find_next_prev_in_P 1 # Check for valid search index if {![info exists find_backward_index]} { Sbar [mc "Editor: Nothing to search ..."] set find_next_prev_in_P 0 return } # Determinate direction set find_back_dir [expr {$find_option_back ^ $back_dir}] # Determinate start index if {$find_option_cur} { set editor [[$actualProject get_current_editor_object] cget -editor] if {$find_back_dir} { if {[$editor compare $find_forward_index == insert]} { $editor mark set insert $find_backward_index } } { if {[$editor compare $find_backward_index == insert]} { $editor mark set insert $find_forward_index } } set index insert } { if {$find_back_dir} { set index $find_backward_index } { set index $find_forward_index } } # Perform search set result [$actualProject editor_procedure {} find [list \ $find_option_cur $find_back_dir \ $find_option_reg $find_option_notCS \ $find_option_sel $index \ $find_String]] # Set search indexes set find_backward_index [lindex $result 0] set find_forward_index [lindex $result 1] # Finalize set matches [lindex $result 2] Sbar [mc "Search result: %s matches found" $matches] ;# Show final result if {$matches == 0} retry_search ;# Retry search if this one failed set find_next_prev_in_P 0 } ## Invoke dialog to replace one string with another (in editor) # @return void proc __replace {} { variable actualProject ;# Object: Current project variable replace_String ;# String to replace variable replace_Replacement ;# Replacement for the search string variable replace_option_CS ;# Bool: Case sensitive variable replace_option_back ;# Bool: Search backwards (checkbox) variable replace_option_cur ;# Book: Search from cursor variable replace_option_reg ;# Bool: Consider search string to be a regular expression variable replace_option_prompt ;# Bool: Prompt on replace variable replace_search_history ;# List of the last 10 search strings variable replace_repl_history ;# List of the last 10 replacement strings variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {${::Editor::editor_to_use}} {return} if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} {return} if {$critical_procedure_in_progress} {return} # Determinate selected text set selectedText [$actualProject editor_procedure {} getselection {}] if {$selectedText != {}} { set replace_String $selectedText } # Create a new toplevel window for the dialog set win [toplevel .replace -class {Replace dialog} -bg {#EEEEEE}] # Create labelframe "String to find" label $win.findLabel -compound left -image ::ICONS::16::find -text [mc "Text to find: "] set findFrame [ttk::labelframe $win.findFrame \ -labelwidget $win.findLabel \ -relief flat \ ] pack $findFrame -fill x -expand 1 -pady 10 -padx 5 pack [ttk::combobox $findFrame.entry \ -textvariable X::replace_String \ -exportselection 0 \ -values $replace_search_history \ ] -fill x -expand 1 -padx 10 DynamicHelp::add $findFrame.entry -text [mc "String to replace"] pack $findFrame # Create labelframe "Replace with" set replaceFrame [ttk::labelframe $win.replaceFrame \ -text [mc "Replace with:"] \ -relief flat \ ] pack $replaceFrame -fill x -expand 1 -pady 5 -padx 5 pack [ttk::combobox $replaceFrame.entry \ -textvariable X::replace_Replacement \ -exportselection 0 \ -values $replace_repl_history \ ] -fill x -expand 1 -padx 10 DynamicHelp::add $replaceFrame.entry -text [mc "Replacement for search string"] # Create and pack options checkboxes labelframe label $win.optionsLabel -compound left -image ::ICONS::16::configure -text "Options" set optionsFrame [ttk::labelframe $win.optionsFrame \ -labelwidget $win.optionsLabel \ ] pack $optionsFrame -fill both -expand 1 -padx 10 # Create matrix of option checkboxes set col 0 ;# Grid column set row 0 ;# Grid row foreach opt { CS back cur reg prompt} \ txt { "Case sensitive" "Backwards" "From cursor" "Regular expr." "Prompt on replace"} \ helptext { {Case sensitive search} {Search backwards from the specified location} {Start search from cursor instead of begining} {Use search string as regular expression} {Prompt on replace} } { # Create checkbutton grid [checkbutton $optionsFrame.option_$opt \ -text [mc $txt] \ -variable X::replace_option_$opt \ ] -column $col -row $row -sticky wns DynamicHelp::add $optionsFrame.option_$opt -text $helptext incr col if {$col == 2} { set col 0 incr row } } # Create and pack 'OK' and 'CANCEL' buttons set buttonFrame [frame $win.buttonFrame] pack [ttk::button $buttonFrame.ok \ -text [mc "Ok"] \ -compound left \ -image ::ICONS::16::ok \ -command {X::replace_REPLACE} \ ] -side left pack [ttk::button $buttonFrame.cancel \ -text [mc "Cancel"] \ -compound left \ -image ::ICONS::16::button_cancel \ -command {X::replace_CANCEL} \ ] -side left pack $buttonFrame -pady 5 # Events binding (Enter == Replace; Escape == Cancel) bind $win {X::replace_REPLACE; break} bind $win {X::replace_REPLACE; break} bind $win {X::replace_CANCEL; break} # Nessesary window manager options -- for modal window wm iconphoto $win ::ICONS::16::find wm title $win [mc "Replace - MCU 8051 IDE"] wm minsize $win 300 270 wm protocol $win WM_DELETE_WINDOW { X::replace_CANCEL } wm transient $win . update raise $win catch {grab $win} focus $findFrame.entry catch { $findFrame.entry.e selection range 0 end } tkwait window $win } ## Perform replacement -- auxiliary procedure for '__replace' # @return Bool - result proc replace_REPLACE {} { variable actualProject ;# Object: Current project variable replace_String ;# String to replace variable replace_Replacement ;# Replacement for the search string variable replace_option_CS ;# Bool: Case sensitive variable replace_option_back ;# Bool: Search backwards (checkbox) variable replace_option_cur ;# Book: Search from cursor variable replace_option_reg ;# Bool: Consider search string to be a regular expression variable replace_option_prompt ;# Bool: Prompt on replace variable replace_search_history ;# List of the last 10 search strings variable replace_repl_history ;# List of the last 10 replacement strings # Append search string to history if {[lsearch -exact -ascii $replace_search_history $replace_String] == -1} { lappend replace_search_history $replace_String } # History mustn't contain more than 10 items if {[llength $replace_search_history] > 10} { set replace_search_history [lrange $replace_search_history \ [expr {[llength $replace_search_history] - 10}] end] } # Append replace string to history if {[lsearch -exact -ascii $replace_repl_history $replace_Replacement] == -1} { lappend replace_repl_history $replace_Replacement } # History mustn't contain more than 10 items if {[llength $replace_repl_history] > 10} { set replace_repl_history [lrange \ $replace_repl_history \ [expr {[llength $replace_repl_history] - 10}] \ end \ ] } # Cancel the replace dialog replace_CANCEL # Perform replacement set replace_option_notCS [expr {!$replace_option_CS}] if {![$actualProject editor_procedure {} replace [list \ $replace_option_cur $replace_option_back \ $replace_option_reg $replace_option_notCS \ $replace_String $replace_Replacement \ $replace_option_prompt X::replace_prompt] ]} { if {!$replace_option_cur} {return} set replace_option_cur_tmp $replace_option_cur set replace_option_cur 0 # Retry search if {$replace_option_back} { if {[tk_messageBox \ -icon question \ -type yesno \ -parent . \ -title [mc "Replace - %s" ${::APPNAME}] \ -message [mc "Begining of document reached\n\nContinue from end ?"] \ ]} { replace_REPLACE } } { if {[tk_messageBox \ -icon question \ -type yesno \ -parent . \ -title [mc "Replace - %s" ${::APPNAME}] \ -message [mc "End of document reached\n\nContinue from begining ?"] \ ]} { replace_REPLACE } } set replace_option_cur $replace_option_cur_tmp } } ## Cancel replace dialog -- auxiliary procedure for '__replace' # @return bool proc replace_CANCEL {} { destroy .replace grab release .replace } ## Invoke dialog "Replace confirmation" # @return bool proc replace_prompt {} { variable replace_prompt_opened ;# Bool: Replace prompt dialog opened variable replace_prompt_return_value ;# Replace prompt dialog return value variable replace_prompt_geometry ;# Geometry of replace prompt dialog window # Dialog already opened -> close it if {$replace_prompt_opened} { replace_prompt_DESTROY # Open the dialog } { set replace_prompt_opened 1 # Create dialog window and restore previous geometry toplevel .replace_prompt -class {Replace prompt dialog} -bg {#EEEEEE} if {[info exists replace_prompt_geometry]} { wm geometry .replace_prompt $replace_prompt_geometry } # Create window header pack [frame .replace_prompt.topFrame] -fill x -expand 1 pack [label .replace_prompt.topFrame.image \ -image ::ICONS::32::help \ ] -side left -padx 10 pack [label .replace_prompt.topFrame.label \ -text [mc "Found an occurence of your search term.\nWhat do you want to do ?"] \ ] -fill both -expand 1 -side right # Create separator pack [ttk::separator .replace_prompt.separator -orient horizontal] -fill x -expand 1 pack [frame .replace_prompt.buttonFrame] -fill x -expand 1 # Create buttuns foreach id { repl relp_close repl_all find_next close } \ text { "Replace" "Replace & close" "Replace all" "Find next" "Close" } \ val { 0 1 2 3 4 } \ under { 0 2 8 0 0 } { pack [ttk::button .replace_prompt.buttonFrame.$id \ -text [mc $text] -underline $under \ -command "X::replace_prompt_return $val;set wait 1;unset wait" \ ] -fill x -expand 1 -side left -padx 5 } # Set key-events bindings bind .replace_prompt { X::replace_prompt_return 0 set wait 1 unset wait break } bind .replace_prompt { X::replace_prompt_return 1 set wait 1 unset wait break } bind .replace_prompt { X::replace_prompt_return 2 set wait 1 unset wait break } bind .replace_prompt { X::replace_prompt_return 3 set wait 1 unset wait break } bind .replace_prompt { X::replace_prompt_return 4 set wait 1 unset wait break } # Nessesary window manager options -- modal window wm iconphoto .replace_prompt ::ICONS::16::help wm title .replace_prompt [mc "Replace confirmation - %s" ${::APPNAME}] wm minsize .replace_prompt 480 100 wm protocol .replace_prompt WM_DELETE_WINDOW { X::replace_prompt_DESTROY } wm transient .replace_prompt . raise .replace_prompt vwait ::wait return $replace_prompt_return_value } } ## Cancel replace prompt dialog -- auxiliary procedure for 'replace_prompt' # @return bool proc replace_prompt_DESTROY {} { variable replace_prompt_opened ;# Bool: Replace prompt dialog opened variable replace_prompt_geometry ;# Geometry of replace prompt dialog window # Save the current dialog geometry set replace_prompt_geometry [wm geometry .replace_prompt] # Destroy dislog window destroy .replace_prompt set replace_prompt_opened 0 } ## Cancel replace prompt dialog and set its return value # @parm Int val - result value of the dialog # @return void proc replace_prompt_return {val} { variable replace_prompt_return_value ;# Replace prompt dialog return value set replace_prompt_return_value $val replace_prompt_DESTROY } ## Select all text in the editor # @return void proc __select_all {} { variable actualProject ;# Object: Current project variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} # Select all $actualProject editor_procedure {} select_all {} } ## Invoke dialog "Go to" # If simulator is engaged the run this: __simulator_set_PC_by_line # @return void proc __goto {} { variable actualProject ;# Object: Current project variable actualProjectIdx ;# Index of the current project in $openedProjects variable goto ;# Line where to go variable editor_lines ;# Number of lines in the current editor variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project variable simulator_enabled ;# List of booleans: Simulator engaged if {$project_menu_locked} {return} if {$critical_procedure_in_progress} {return} if {[lindex $simulator_enabled $actualProjectIdx] == 1} { __simulator_set_PC_by_line return } set goto [$actualProject editor_actLineNumber] set editor_lines [$actualProject editor_linescount] # Create dialog window set goto_opened 1 set win [toplevel .goto -class {Goto dialog} -bg {#EEEEEE}] # Create window label frame label $win.header -text [mc "Go to line"] -image ::ICONS::16::goto -compound left set topFrame [ttk::labelframe $win.topFrame -labelwidget $win.header -relief flat] pack $topFrame -expand 1 -fill x -padx 10 # Create scale widget pack [ttk::scale $topFrame.scale \ -from 1 -to $editor_lines \ -orient horizontal \ -variable X::goto \ -command " set ::X::goto \[expr {int(\${::X::goto})}\] $topFrame.spinbox selection range 0 end #" \ ] -side left -expand 1 -fill x -padx 2 DynamicHelp::add $topFrame.scale \ -text [mc "Graphical representation of line where to go"] # Create spinbox widget pack [spinbox $topFrame.spinbox \ -from 1 -to $editor_lines \ -textvariable X::goto \ -validate key \ -validatecommand {X::goto_validate %P} \ -width 6 \ -command "$topFrame.spinbox selection range 0 end" \ ] -side left DynamicHelp::add $topFrame.spinbox -text [mc "Line where to go"] # Create and pack 'OK' and 'CANCEL' buttons set buttonFrame [frame .goto.buttonFrame] pack [ttk::button $buttonFrame.ok \ -text [mc "Ok"] \ -compound left \ -image ::ICONS::16::ok \ -command {X::goto_OK} \ ] -side left pack [ttk::button $buttonFrame.cancel \ -text [mc "Cancel"] \ -compound left \ -image ::ICONS::16::button_cancel \ -command {X::goto_CANCEL} \ ] -side left pack $buttonFrame -pady 5 # Events binding (Enter == Ok, Esc == CANCEL) bind $win {X::goto_OK; break} bind $win {X::goto_OK; break} bind $win {X::goto_CANCEL; break} # Focus on the Spinbox focus $topFrame.spinbox $topFrame.spinbox selection range 0 end # Nessesary window manager options -- modal window wm iconphoto $win ::ICONS::16::goto wm title $win [mc "Goto line - MCU 8051 IDE"] wm minsize $win 200 100 wm protocol $win WM_DELETE_WINDOW { X::goto_CANCEL } wm transient $win . catch {grab $win} raise $win tkwait window $win } ## Validate value of spinbox in the Go to dialog -- auxiliary procedure for '__goto' # @parm # @return bool proc goto_validate {value} { variable editor_lines ;# Number of lines in the current editor if {$value > $editor_lines} { return 0 } { return 1 } } ## Cancel Go to dialog -- auxiliary procedure for '__goto' # @return bool proc goto_CANCEL {} { destroy .goto grab release .goto } ## Go to line -- auxiliary procedure for '__goto' # @return bool proc goto_OK {} { variable actualProject ;# Object: Current project variable goto ;# Line where to go # Go to the specified line $actualProject editor_procedure {} goto $goto # Destroy dialog window goto_CANCEL } ## Comment block of selected text in the editor # @return void proc __comment {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} {return} if {$critical_procedure_in_progress} {return} # Comment $actualProject editor_procedure {} comment {} } ## Uncomment block of selected text in the editor # @return void proc __uncomment {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} return if {$critical_procedure_in_progress} {return} # Uncomment $actualProject editor_procedure {} uncomment {} } ## Reload the current file # @return void proc __reload {} { variable actualProject ;# Object: Current project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_menu_locked ;# Bool: Indicates than there is at least one opened project if {$project_menu_locked} {return} if {[simulator_must_be_disabled 0]} return if {$critical_procedure_in_progress} {return} # Reload $actualProject filelist_reload_file } ## Invoke directory selection dialog # @parm Widget master - GUI parent # @return void proc select_directory {master} { variable project_menu_locked ;# Bool: Indicates than there is at least one opened project variable actualProject ;# Object: Current project variable select_directory_var {} ;# Selected directory variable defaultDirectory ;# Default directory # Determinate initial directory if {$project_menu_locked} { set directory {~} } { set directory [$actualProject cget -projectPath] } # Invoke the dialog catch {delete object fsd} KIFSD::FSD fsd \ -title [mc "Choose directory - MCU 8051 IDE"] \ -directory $directory -fileson 0 -master $master # Save choice to variable select_directory_var fsd setokcmd { set X::select_directory_var [X::fsd get] } fsd activate ;# Activate the dialog # Return path to the selected directory return $select_directory_var } ## Invoke dialog "New Project" # @return void proc __proj_new {} { variable avaliable_processors ;# List of supported processors variable actualProject ;# Object: Current project variable project_new_name ;# Name of the new project variable project_new_dir ;# Directory of the new project variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time variable project_new_processor {AT89S52};# Processor type (e.g. "AT89C2051") variable project_new_xdata_ena 0 ;# Bool: XDATA memory connected variable project_new_xcode_ena 0 ;# Bool: XCODE memory connected variable project_new_xdata 0 ;# Int: Amount of XDATA memory variable project_new_xcode 0 ;# Int: Amount of XCODE memory variable project_new_max_xcode 0 ;# Int: Maximum valid value of external program memory variable project_new_xd_chb ;# Widget: XDATA enable checkbutton variable project_new_xd_scl ;# Widget: XDATA scale variable project_new_xd_spb ;# Widget: XDATA spinbox variable project_new_xc_chb ;# Widget: XCODE enable checkbutton variable project_new_xc_scl ;# Widget: XCODE scale variable project_new_xc_spb ;# Widget: XCODE spinbox if {$critical_procedure_in_progress} {return} # Create dialog window set win [toplevel .project_new -class {New project} -bg {#EEEEEE}] # Create window header (text and some icon) set header [frame $win.header] pack [label $header.image -image ::ICONS::32::wizard] -padx 10 -side left pack [label $header.text \ -text [mc "Create a new project.\n All entries are required. Other options --> edit project."] \ ] -side left -expand 1 -fill x pack $header -fill both -expand 1 # Create labelframe "General" set genaral_labelframe [ttk::labelframe $win.general -text [mc "General"]] # Entry "Project name" set name [ttk::labelframe $genaral_labelframe.name \ -text [mc "Project name"] \ -relief flat \ ] pack [ttk::entry $name.entry \ -textvariable X::project_new_name \ -width 20 \ ] -fill x -expand 1 DynamicHelp::add $name.entry -text [mc "Name of XML file representing the project"] pack $name -fill x -expand 1 -padx 10 -pady 5 # Entry "Project directory" set dir [ttk::labelframe $genaral_labelframe.dir \ -text [mc "Project directory"] \ -relief flat \ ] pack [ttk::entry $dir.entry \ -textvariable X::project_new_dir \ -width 20 \ ] -side left -fill x -expand 1 DynamicHelp::add $dir.entry -text [mc "Directory where the project file should be located"] pack [ttk::button $dir.choose \ -image ::ICONS::16::fileopen \ -style Flat.TButton \ -command { set foo [X::select_directory .project_new] if {$foo != {}} { set X::project_new_dir $foo } unset foo } \ ] -side left DynamicHelp::add $dir.choose -text [mc "Choose destination location"] pack $dir -fill x -expand 1 -padx 10 -pady 5 pack $genaral_labelframe -fill both -expand 1 -pady 10 -padx 10 # Create labelframe "Processor" set proc_frame [ttk::labelframe $win.proc_frame -text [mc "Processor"]] set proc_frame_top [frame $proc_frame.top] set proc_frame_middle [frame $proc_frame.middle] set proc_frame_middle_left [ttk::labelframe $proc_frame_middle.middle \ -padding 5 -text [mc "XDATA"]] set proc_frame_middle_right [ttk::labelframe $proc_frame_middle.right \ -padding 5 -text [mc "XCODE"]] # Create components of top frame (Type: