home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
GUI.PEL
< prev
next >
Wrap
Text File
|
1995-03-17
|
13KB
|
491 lines
# $Header: P:\source\wmacros\gui.pev 1.83 17 Mar 1995 11:59:06 WALKER $
##############################################################################
#
# Compuware Corporation
# 31440 Northwestern Highway
# Farmington Hills, Michigan 48334-2564
#
# This source code listing contains information that is
# proprietary to Compuware Corporation and may not be copied
# duplicated, translated, transmitted, stored, retrieved
# or in any manner or by any method conveyed or disclosed
# to a third party or parties without express written
# permission from Compuware Corporation.
#
#
##############################################################################
#### $Workfile: gui.pel $: gui functions
## $Tabs:4 7$
# Not used right now, but will be when and if we decide to disable buttons
#local function check_ext()
#{
# local ext = tolower(path_ext( buffer_filename ));
# return ( (file_extensions["c"] ~ ext) \
# || (file_extensions["basic"] ~ ext) \
# || (file_extensions["pascal"] ~ ext) \
# || (file_extensions["dbase"] ~ ext) \
# || (file_extensions["clipper87"] ~ ext) \
# || (file_extensions["clipper50"] ~ ext) \
# || (file_extensions["force"] ~ ext) )
#}
function gui_undo( index )
{
local status = !!undo_index()
if ( argcount() )
status = undo( index )
else
status = undo()
}
function gui_redo( index )
{
local status
if ( argcount() )
status = redo( index )
else
status = redo()
}
#------------- Basic text commands support ---------------------------------#
function gui_backspace()
{
if (( current_column > 1 ) \
|| and( buffer_flags, BUFFER_WP_ENABLED ))
{
backspace()
}
}
#------------- Playback/record and Macros functions unique to gui ----------#
#------------- Miscellaneous functions unique to gui -----------------------#
global function gui_invoke_function()
{
local mac
# UNCOMMENT next 3 lines when common command works and delete last line
# mac = ltrim( command_dialog() )
# if (mac)
# invoke_function(mac)
invoke_function()
}
#
# new_edit_file()
#
# Whenever a new edit file is created, the extension is stripped from
# the file name and a function with that extension (preceded by "_")
# is invoked. If the function does not exist, "default()" is called.
#
#global function new_edit_file()
#{
# local ext = path_ext( buffer_filename );
# local lev = message_level;
# local def_name = "default"
# local id
#
# message_level = 3;
#
# if (ext)
# {
# if (substr( ext, 1, 1 ) == "." )
# {
# ext = "_" substr( ext, 2 );
# id = function_id( ext );
# if ( id )
# {
# message_level = lev;
# execute_function( ext );
# return;
# }
# }
# }
#
# id = function_id( def_name );
# message_level = lev;
# if ( id )
# execute_function( def_name );
#}
# read the print settings the first time print is selected
local read_print_settings = 1
global function gui_print()
{
if (read_print_settings)
{
read_print_settings = 0
read_config_section("$PRINT_SETTINGS$")
}
print_dialog()
}
global function save_print_settings()
{
local data_array
local index = 0
# if read_print_settings is 1 then we haven't read the config
# information in so don't try to write it just return.
if (read_print_settings == 1)
return data_array;
data_array[ index++ ] = sprintf( "print_split=%d\n", print_split )
data_array[ index++ ] = sprintf( "print_word_wrap=%d\n", print_word_wrap )
data_array[ index++ ] = sprintf( "print_indent=%d\n", print_indent )
data_array[ index++ ] = sprintf( "print_program_indent=%d\n", print_program_indent )
data_array[ index++ ] = sprintf( "print_columns=%d\n", print_columns )
data_array[ index++ ] = sprintf( "print_orientation=%d\n", print_orientation )
data_array[ index++ ] = sprintf( "headers_enabled=%d\n", headers_enabled)
data_array[ index++ ] = sprintf( "footers_enabled=%d\n", footers_enabled)
data_array[ index++ ] = sprintf( "header=\"%s\"\n", quote_string(header))
data_array[ index++ ] = sprintf( "footer=\"%s\"\n", quote_string(footer))
if ( length(print_font_name) )
{
store_print_font("print", "Fonts")
data_array[ index++ ] = sprintf("load_print_font \"print\" \"Fonts\"\n")
}
if ( length(header_font_name) )
{
store_header_font("header", "Fonts")
data_array[ index++ ] = sprintf("load_header_font \"header\" \"Fonts\"\n")
}
if ( length(footer_font_name) )
{
store_footer_font("footer", "Fonts")
data_array[ index++ ] = sprintf("load_footer_font \"footer\" \"Fonts\"\n")
}
data_array[ index++ ] = sprintf( "\n" )
return data_array
}
global function gui_print_select()
{
print_select_dialog()
}
global function gui_new(dontCallCreate)
{
local this_buffer = current_buffer
local newBuffer;
next_buffer( this_buffer )
newBuffer = new_buffer_name();
if(newBuffer && !dontCallCreate)
{
create_buf_and_win(newBuffer);
buffer_flags = or(buffer_flags, BUFFER_SCRATCH);
}
return newBuffer;
}
local lastPath = "*.*"
local ENABLE_LOCK_FILE = 0x10000000
local ENABLE_COPY_FILE_TO_VM = 0x01000000
local ENABLE_OPEN_FILE_IN_WINDOW = 0x00100000
local ENABLE_READ_ONLY = 0x00010000
local ALL_ENABLED = ENABLE_COPY_FILE_TO_VM +
ENABLE_LOCK_FILE +
ENABLE_OPEN_FILE_IN_WINDOW +
ENABLE_READ_ONLY
local COPY_FILE_TO_VM_CHECKED = 0x00001000
local LOCK_FILE_CHECKED = 0x00000100
local OPEN_FILE_IN_WINDOW_CHECKED = 0x00000010
local READ_ONLY_CHECKED = 0x00000001
global function gui_open( infileToOpen )
{
local InitialPath
local listOfFiles
local arrayOfFiles
local fileToOpen
local ret
local i
local flags
local buffer_ro
local lock_buf
local copy
local wf
local editfile_list
local old_create_new_bufwin = create_new_bufwin
# if infileToOpen is specified use it otherwise use
# use the last path that was used.
InitialPath = (infileToOpen) ? infileToOpen : lastPath
flags = ALL_ENABLED
if ( !mdi_mode )
flags = and(flags, not(ENABLE_OPEN_FILE_IN_WINDOW) )
if ( create_new_bufwin )
flags = or(flags, OPEN_FILE_IN_WINDOW_CHECKED);
editfile_list = get_history_list("EDITFILE")
listOfFiles = open_dialog( InitialPath, "Open", flags, "open", editfile_list )
if ( listOfFiles )
{
# parse out the files and flags. Flags are always the first
# element in the list.
split(listOfFiles, arrayOfFiles, ";")
# the flags are the first items in the array
if ( and( arrayOfFiles[1], OPEN_FILE_IN_WINDOW_CHECKED) )
create_new_bufwin = 1
else
create_new_bufwin = 0
if ( and( arrayOfFiles[1], READ_ONLY_CHECKED ) )
buffer_ro = 1
else
buffer_ro = 0
if ( and( arrayOfFiles[1], LOCK_FILE_CHECKED ) )
lock_buf = TRUE
else
lock_buf = FALSE
if ( and( arrayOfFiles[1], COPY_FILE_TO_VM_CHECKED ) )
copy = TRUE
else
copy = FALSE
for(i in arrayOfFiles)
{
if ( i != 1 )
{
fileToOpen = arrayOfFiles[i]
add_prompt_history("EDITFILE", fileToOpen)
create_buf_and_win(fileToOpen)
if ( buffer_ro )
buffer_flags = or( buffer_flags, BUFFER_READ_ONLY )
if ( lock_buf )
lock_buffer()
if ( copy )
copy_buffer_internally()
# parse the drive:directory from the filename and store in
# last path.
#
lastPath = path_path(fileToOpen) "*.*"
}
}
# restore the old state of create_new_bufwin only if it was not toggled off;
if(!old_create_new_bufwin || create_new_bufwin)
create_new_bufwin = old_create_new_bufwin
# if ( current_window == 0 )
# {
# if ( mdi_mode )
# {
# wf = and(WINDOW_STANDARD_MDI, not(WINDOW_ZOOM))
# wf = or(wf, WINDOW_EXPANDED)
# current_window = create_window( 0, 0, 100, 100, wf)
# }
# else
# current_window = create_window( 0, 0, 100, 100, WINDOW_STANDARD_SDI )
#
# attach_window_buffer( current_window, current_buffer )
# }
# display current filename
#
display_filename()
return TRUE
}
else
return FALSE
}
function gui_save()
{
if ( is_scratch_file(current_buffer) )
return gui_saveas()
write_buffer_key()
}
global function edit_another(infileToOpen)
{
local InitialPath
local fileToOpen
local arr
local ret
# if infileToOpen is specified use it otherwise use
# use the last path that was used.
InitialPath = (infileToOpen) ? infileToOpen : lastPath
fileToOpen = open_dialog( InitialPath, "Edit Another File", 0, "open_dialog" )
split(fileToOpen, arr, ";")
if ( arr[2] ) {
ret = spawn( ARGV[0], arr[2] )
if (ret != 0) {
error("Could not execute: " ARGV[0] " " arr[2])
}
# parse the drive:directory from the filename and store in
# last path.
lastPath = path_path(arr[2]) "*.*"
}
}
global function gui_insert_file( infileToOpen )
{
local InitialPath
local fileToOpen
local arr
# if infileToOpen is specified use it otherwise use
# use the last path that was used.
#
InitialPath = (infileToOpen) ? infileToOpen : lastPath
fileToOpen = open_dialog( InitialPath, "Insert File", 0, "insert" )
# parse out the open flags
split(fileToOpen, arr, ";")
if ( arr[2] ) {
read_file_key(arr[2])
# parse the drive:directory from the filename and store in
# last path.
lastPath = path_path(arr[2]) "*.*"
}
return arr[2];
}
# gui_saveas returns 0 if file was not written, 1 if it was
global function gui_saveas( infileToWrite )
{
local fileToWrite
local old_bfname
local old_bname
local ret = 0
local overwrite = TRUE
local prompt_str
local fname
local start_buf
fileToWrite = saveas_dialog( (infileToWrite) ? infileToWrite : buffer_filename,
"saveas")
if ( filemode(fileToWrite) != -1 )
prompt_str = fileToWrite " exists"
start_buf = current_buffer
fname = path_fname(fileToWrite)
while ( (current_buffer = next_buffer("", 1, 1)) != start_buf )
{
if ( buildpath(fileToWrite) == buildpath(buffer_filename) )
{
if ( prompt_str )
prompt_str = prompt_str " and is in a buffer"
else
prompt_str = fileToWrite " is in a buffer"
current_buffer = start_buf
break
}
}
if ( prompt_str )
overwrite = tolower(confirm( prompt_str ". Overwrite? ", "yYnN" )) == "y"
if ( fileToWrite && overwrite )
{
ret = write_buffer_as(fileToWrite)
if ( ret )
{
new_edit_file()
syntax_new_buffer()
}
}
return ret
}
global function gui_saveall()
{
if ( !write_all_buffers() )
{
error("Unable to write buffers")
return
}
message("All buffers saved.")
}
function gui_write_block()
{
local fileToWrite
local status
if( selection_type() == NO_SELECTION )
{
warning("Cannot write block. Nothing selected.")
}
else
{
fileToWrite = prompt( "Write block as: ", "", "write_buffer_as_dialog" )
if (fileToWrite)
{
backup_file( fileToWrite );
if (write_marked_block( fileToWrite ))
message("Write successful.")
}
}
}
global function gui_delete_buffer()
{
delete_buffer_key("", 1);
}
function gui_delete_to_scrap()
{
delete_to_scrap()
}
global function gui_nyi() #PUBLIC #VOID
{
warning( " Not yet implemented" )
}
# unimplemented functions
global function init_menu_colors() { gui_nyi();}
global function pvcs_get_group() { gui_nyi();}