1. ed.ex :: simple pick list menus

I guess you would call this a "Quick and Dirty" pick-list menu system. I have been using it with my EDS/ed.ex routines:

 
 
 
-- insert in the get_escape(boolean help) routines "first-bold" list of hotkey clauses: 
 
        first_bold("Db ") --<------------ 
	first_bold("help ") 
	first_bold("clone ") 
	first_bold("open ") 
-- 
command = key_gets("Dhcqswnedfrlm", {}) & ' ' -- add the upper-case "D" to sequence of hot-keys 
--  
 
-- add elsif clause to list of menu commands: 
elsif command[1] = 'D' then 
	DbMenu() 
-- 
 
-- insert following menu code. All of the menu items are names of procedures with 
-- routine-id's. For example: 
 
procedure DbSelect() 
    -- Select/Open/Create DB: 
    -- select a db, if select fails, try to open the db, if open fails try to create db: 
     
    DbBanner("Select/Open/Create Database") 
    current_dir_db = cur_dir_db() 
 
    lm = select_db_lm() -- DB_LOCK_METHOD 
     
    if db_select(sprintf("%s", {current_dir_db}), lm) != DB_OK then 
	if db_open(sprintf("%s", {current_dir_db}), lm) != DB_OK then 
	    if db_create(sprintf("%s", {current_dir_db}), lm) != DB_OK then 
		DbBanner(" ") 
		any_key("Could not Select/open/create db!")  
	    end if     
	end if   
    end if 
     
    current_db = db_current() 
     
   -- the update_history routine is the same routine that tracks 
   -- file_names, search, and command "history" sequences:  
   open_db_history = update_history(open_db_history, current_db) 
DbMenu() 
end procedure 
integer db_select_edx = routine_id("DbSelect") 
 
procedure DbCloseAll() 
    for i = length(open_db_history) to 1 by -1 do 
	db_select(open_db_history[i]) 
	db_close() 
    end for 
open_db_history = {} 
DbMenu() 
end procedure 
integer DbCloseAll_edx = routine_id("DbCloseAll") 
 
 
constant DB_MENU = {"Quit",  "RecordsMenu", "TablesMenu", "DbCloseAll", 
		    "DbClose", "DbCompress", "DbConnect", "DbDump", "DbSelect"}, 
	  
	TABLES_MENU =  {"Quit",  "DbMenu", "RecordsMenu", "TableSize",  
			"TablesList",  "TableRename", "TableClear", "TableDelete",  
					    "TableSelect" }, 
 
sequence MENU = {} 
sequence selection = " " 
 
procedure DbMenu() 
MENU &= DB_MENU 
	    set_mode(DEFAULT_DB) 
	    DbBanner("DataBase") 
display_menu() 
end procedure 
integer dbx_menu = routine_id("DbMenu") 
 
procedure TablesMenu() 
MENU = TABLES_MENU 
	    set_mode(TABLES) 
	    DbBanner("TABLES") 
display_menu() 
end procedure 
integer tables_menu = routine_id("TablesMenu") 
 
 
procedure display_menu() 
    selection = " " 
    while equal(selection, " ") do 
	text_color(TOP_LINE_TEXT_COLOR) 
        -- use arrow keys to scroll through the list of menu items 
	selection = trim(key_gets("", MENU)) 
	if find(selection, MENU) then 
	    call_proc(routine_id(sprintf("%s", {selection})), {}) 
	end if 
    end while 
end procedure 
 
-------------------------------------------------------------------------------- 
 
-- This is the top-line color code schemes for different editing "modes" 
-- used as "switches" to change color schemes: 
integer DEFAULT_DB = 1,                 -- default edx.ex and top level EDS database functions 
	TABLES = 2,                             -- EDS tables top line menu color scheme   
	RECORDS = 3,                            -- EDS records top line menu color scheme 
	DB_TEXT_COLOR = YELLOW, 
	TABLES_COLOR = BROWN, 
	RECORDS_COLOR = RED, 
	TOP_LINE_TEXT_COLOR, 
	TOP_LINE_BACK_COLOR, 
	TOP_LINE_DIM_COLOR, 
	BACKGROUND_COLOR 
 
procedure set_mode(integer mode) 
    -- edx: colors changed to differentiate edx.ex from ed.ex 
     
   if mode = DEFAULT_DB then   -- default color mode also used for database menu operations. 
	TOP_LINE_BACK_COLOR = BLUE 
	TOP_LINE_TEXT_COLOR = YELLOW 
	TOP_LINE_DIM_COLOR = BRIGHT_CYAN 
	BACKGROUND_COLOR = WHITE 
	TABLES_COLOR = BROWN 
     
    elsif mode = TABLES then          -- used for the EDS "Table" operations menu. 
	TOP_LINE_BACK_COLOR = BROWN 
	TOP_LINE_TEXT_COLOR = BLUE 
	TOP_LINE_DIM_COLOR = BLACK 
	BACKGROUND_COLOR = WHITE 
	TABLES_COLOR = GREEN 
	 
    elsif mode = RECORDS then         -- used for the EDS "Records" operations menu. 
	TOP_LINE_BACK_COLOR = GREEN 
	TOP_LINE_TEXT_COLOR = RED 
	TOP_LINE_DIM_COLOR = BLACK 
	BACKGROUND_COLOR = WHITE 
     
    else                                -- edx.ex default, same as "DEFAULT_DB". 
	TOP_LINE_BACK_COLOR = BLUE 
	TOP_LINE_TEXT_COLOR = YELLOW 
	TOP_LINE_DIM_COLOR = BRIGHT_CYAN 
	BACKGROUND_COLOR = WHITE 
	TABLES_COLOR = BROWN 
    end if 
end procedure 
set_mode(DEFAULT_DB)                    -- edx editor/default, db_menu/operations default 
 
 
 
-- This is the DbBanner code: 
procedure DbBanner(sequence operation) 
-- { current db : current table} {opendb1, opendb2, etc}     
-- { } { } -- no db open     
sequence all_other_open_db = {}  
    set_top_line(" ")   text_color(TOP_LINE_DIM_COLOR) 
    puts(SCREEN,"{")    text_color(DB_TEXT_COLOR)    
    current_db = filebase(db_current()) 
    printf(SCREEN, "%s",{current_db}) 
    current_table = db_current_table() 
    if length(current_table)!= 0 then 
		text_color(TOP_LINE_DIM_COLOR)  puts(SCREEN, ":") 
		text_color(TABLES_COLOR)     
		printf(SCREEN, "%s", {current_table}) 
    end if 
     
    text_color(TOP_LINE_DIM_COLOR)  puts(SCREEN, "} {") 
    current_db = db_current() 
    if length(current_db) != 0 then 
		open_db_history = remove_item(current_db, open_db_history) 
    end if 
    if length(open_db_history) != 0  then 
		for i = 1 to  length(open_db_history) do 
			if i != length(open_db_history)  
				and length(filebase(open_db_history[i])) !=0 then 
					text_color(TOP_LINE_TEXT_COLOR)  
					printf(SCREEN, "%s", {filebase(open_db_history[i])}) 
					text_color(TOP_LINE_DIM_COLOR)  puts(SCREEN,":") 
			elsif i = length(open_db_history) then 
				text_color(TOP_LINE_TEXT_COLOR)  
				printf(SCREEN, "%s", {filebase(open_db_history[i])}) 
			end if 
		end for 
    end if 
     
    open_db_history = update_history(open_db_history, current_db) 
    text_color(TOP_LINE_DIM_COLOR) puts(SCREEN, "} ") 
    if length(operation)>1 then 
		text_color(TOP_LINE_DIM_COLOR)   
		printf(SCREEN,"%s", {operation}) 
		text_color(TOP_LINE_TEXT_COLOR) puts(SCREEN,": ") 
    end if 
end procedure 

Comments and suggestions for improvements, etc., will be appreciated.

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu