home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
TYPESET.PEL
< prev
next >
Wrap
Text File
|
1995-04-11
|
96KB
|
2,985 lines
# $Header: P:\source\wmacros\typeset.pev 1.35.1.2 11 Apr 1995 15:09:58 WALKER $
## $Tabs:4 7$
##############################################################################
#
# 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: typeset.pel $:
############## EXTENSION/COMPILERS SETTINGS NOTEBOOK PAGE ###################
local IDE_EXTENSIONS = 102;
local IDC_EXPANSION = 101;
local IDB_ADVANCED = 101;
local IDD_ADVANCED_COMPILER_SETTINGS = 1082
local IDD_DOS_SETTINGS_DIALOG = 1083
local save_extensions;
local save_compilers;
local local_compiler;
local dos_settings_array;
global function extension_settings_notebook(dlgid)
{
local phandle, dhandle = 0;
nb_initializing = TRUE;
if ( status_bar_flags )
message( "Creating Type Settings pages..." )
phandle = append_notebook_page( dlgid, dhandle, " ",
"Types", NBTAB_MAJOR )
nbPagePrefix[phandle].name = "exthelp";
phandle = append_notebook_page(dlgid, dhandle, " Define Types",
"Extensions", NBTAB_MINOR)
nbPagePrefix[phandle].name = "ext";
phandle = append_notebook_page(dlgid, dhandle, " Setup Compilers",
"Compilers", NBTAB_MINOR)
nbPagePrefix[phandle].name = "compiler";
phandle = append_notebook_page(dlgid, dhandle, " Color Highlighting",
"Colors", NBTAB_MINOR)
nbPagePrefix[phandle].name = "syntax";
phandle = append_notebook_page(dlgid, dhandle, " Language Templates",
"Template", NBTAB_MINOR)
nbPagePrefix[phandle].name = "template";
nb_initializing = FALSE;
}
global function reset_extension_settings_notebook()
{
language_compiled = FALSE;
global_type = FALSE;
delete save_extensions;
delete save_compilers;
delete save_languages;
delete save_styles;
save_extensions = FALSE;
save_compilers = FALSE;
save_languages = FALSE;
save_styles = FALSE;
}
###############################################################################
#
# Extension Settings Create functions
#
###############################################################################
global function create_exthelp_page(pageid, dlgid)
{
local dhandle;
dhandle = create_page(function_id( "nop_settings_callback"),
dlgid, IDD_EXTENSION_HELP_PAGE, resource_dll );
attach_help(editor_helpfile, dhandle);
if(isWindows())
nbPagePrefix[pageid].help = "Type Settings";
else
nbPagePrefix[pageid].help = "typespages";
set_notebook_page_dialog(dlgid, pageid, dhandle);
nbPagePrefix[pageid].dialog_handle = dhandle;
}
global function create_ext_page(pageid, dlgid)
{
local dhandle;
dhandle = create_page(function_id( "ext_settings_callback" ),
dlgid, IDD_EXT_SETTINGS, resource_dll)
attach_help(editor_helpfile, dhandle);
if(isWindows())
nbPagePrefix[pageid].help = "Extension Settings";
else
nbPagePrefix[pageid].help = "extensionspage";
if(!save_extensions)
save_extensions = copy_extensions_array(extensions);
if(!save_languages)
save_languages = copy_languages_array(languages);
add_dialog_item(dhandle, IDE_EXTENSIONS, DCTRL_EDIT);
set_dialog_item(dhandle, IDE_EXTENSIONS, DAC_SET_TEXT_LEN, 255);
add_dialog_item(dhandle, IDE_PAIRS, DCTRL_EDIT);
set_dialog_item(dhandle, IDE_PAIRS, DAC_SET_TEXT_LEN, 255);
set_dialog_item(dhandle, IDL_TYPE, DAC_SORT_ASCENDING)
set_dialog_item(dhandle, IDB_CHG_COMP, DAC_DISABLE )
set_dialog_item(dhandle, IDB_CPY_COMP, DAC_DISABLE )
set_dialog_item(dhandle, IDB_DEL_COMP, DAC_DISABLE )
set_dialog_item(dhandle, IDB_DEFAULT, DAC_DISABLE )
# set_dialog_item(dhandle, IDB_UNDO, DAC_DISABLE )
initialize_ext_settings(dhandle, "dummy", 1);
set_notebook_page_dialog(dlgid, pageid, dhandle);
nbPagePrefix[pageid].dialog_handle = dhandle;
}
global function create_compiler_page(pageid, dlgid)
{
local dhandle;
dhandle = create_page(function_id( "compiler_settings_callback" ),
dlgid, IDD_COMP_SETTINGS, resource_dll)
attach_help(editor_helpfile, dhandle)
if(isWindows())
nbPagePrefix[pageid].help = "Compiler Settings";
else
nbPagePrefix[pageid].help = "compilerspage";
if(!save_compilers)
save_compilers = copy_compilers_array(compilers);
if(!save_languages)
save_languages = copy_languages_array(languages);
add_dialog_item(dhandle, IDE_OTHER, DCTRL_EDIT);
# add_dialog_item(dhandle, IDE_INPUT_FILE, DCTRL_EDIT);
add_dialog_item(dhandle, IDE_COMMAND_LINE, DCTRL_EDIT);
set_dialog_item(dhandle, IDE_OTHER, DAC_SET_TEXT_LEN, 255);
# set_dialog_item(dhandle, IDE_INPUT_FILE, DAC_SET_TEXT_LEN, 255);
set_dialog_item(dhandle, IDE_COMMAND_LINE, DAC_SET_TEXT_LEN, 255);
set_dialog_item(dhandle, IDL_TYPE, DAC_SORT_ASCENDING);
set_dialog_item(dhandle, IDL_ERROR, DAC_SORT_ASCENDING);
set_dialog_item(dhandle, IDL_COMPILER, DAC_SORT_ASCENDING);
set_dialog_item(dhandle, IDE_OTHER, DAC_DISABLE)
# set_dialog_item(dhandle, IDE_INPUT_FILE, DAC_DISABLE)
set_dialog_item(dhandle, IDT_BUFFER_DEF_TEXT, DAC_DISABLE)
set_dialog_item(dhandle, IDL_ERROR, DAC_DELETE_ITEM);
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "ada");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "clipper5");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "clipper87");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "force");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "generic");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "lahey");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "microfocus");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "other");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "pel");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "realia");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "turboc");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "watcom");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "zortech");
set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "[None]");
initialize_compiler_settings( dhandle, "dummy", 1 )
set_notebook_page_dialog(dlgid, pageid, dhandle);
nbPagePrefix[pageid].dialog_handle = dhandle;
}
global function create_template_page(pageid, dlgid)
{
local dhandle;
dhandle = create_page(function_id( "template_settings_callback" ),
dlgid, IDD_TEMPL_SETTINGS, resource_dll);
attach_help(editor_helpfile, dhandle);
if(isWindows())
nbPagePrefix[pageid].help = "Template Settings";
else
nbPagePrefix[pageid].help = "templatepage";
if(!save_languages)
save_languages = copy_languages_array(languages);
initialize_template_settings(dhandle, "dummy", 1);
set_notebook_page_dialog(dlgid, pageid, dhandle);
nbPagePrefix[pageid].dialog_handle = dhandle;
}
###############################################################################
#
# Extension Settings Initialize functions
#
###############################################################################
global function initialize_ext_settings( handle, dummy, load_types )
{
local list;
nb_initializing = TRUE;
# init_extensions(handle);
if(load_types)
init_types(handle);
establish_global_type(handle);
list = get_ext_list(global_type);
set_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT, list "");
set_dialog_item(handle, IDE_PAIRS, DAC_EDIT_TEXT, MatchingPairs(global_type) "");
apply_page_to_all( "EXT_PAGE", function_id("ext_apply_to_all") )
# set_dialog_item(handle, IDB_UNDO, DAC_DISABLE);
nb_initializing = FALSE;
}
global function initialize_compiler_settings( handle, dummy, load_types )
{
local name
nb_initializing = TRUE;
if(load_types)
{
init_types(handle);
init_compilers(handle);
}
establish_global_type(handle);
name = CompilerName(global_type);
if(!name)
name = "[None]";
set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, name "");
set_compiler(handle, global_type, name)
set_dialog_item(handle, IDB_UNDO, DAC_DISABLE);
nb_initializing = FALSE;
}
local function set_compiler( handle, type, name )
{
local err_format, file, num;
set_dialog_item(handle, IDE_COMMAND_LINE, DAC_EDIT_TEXT, CommandLine(name) "")
err_format = ErrorFormat(name)
if(prefix(err_format, 5) == "other")
{
set_dialog_item(handle, IDE_OTHER, DAC_EDIT_TEXT, substr(err_format, 7) "")
set_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM, "other")
}
else
{
if(!err_format || err_format == "none")
err_format = "[None]";
set_dialog_item(handle, IDE_OTHER, DAC_EDIT_TEXT, "")
if (!set_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM, err_format""))
set_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM, "generic")
}
file = CompilerInput(name)
num = file+0
if (num >= 0)
{
# set_dialog_item(handle, IDC_NEEDS_INPUT, DAC_CHECK);
# set_dialog_item(handle, IDE_INPUT_FILE, DAC_ENABLE)
# if (num == 1)
# set_dialog_item(handle, IDE_INPUT_FILE, DAC_EDIT_TEXT, "");
# else
# set_dialog_item(handle, IDE_INPUT_FILE, DAC_EDIT_TEXT, file "");
}
else
{
# set_dialog_item(handle, IDC_NEEDS_INPUT, DAC_UNCHECK);
# set_dialog_item(handle, IDE_INPUT_FILE, DAC_EDIT_TEXT, "");
# set_dialog_item(handle, IDE_INPUT_FILE, DAC_DISABLE)
}
}
global function initialize_template_settings( handle, dummy, load_types )
{
local type, name;
nb_initializing = TRUE;
if(load_types)
{
init_types(handle);
init_templates(handle);
}
establish_global_type(handle);
set_dialog_item(handle, IDL_TEMPLATE, DAC_SELECT_ITEM, Template(global_type) "");
if(get_expand_template(global_type))
set_dialog_item(handle, IDC_EXPANSION, DAC_CHECK);
else
set_dialog_item(handle, IDC_EXPANSION, DAC_UNCHECK);
set_dialog_item(handle, IDB_UNDO, DAC_DISABLE);
nb_initializing = FALSE;
}
#local function init_extensions(handle)
#{
# local ext
#
# set_dialog_item(handle, IDL_EXT, DAC_DELETE_ITEM)
# for (ext in extensions)
# {
# set_dialog_item(handle, IDL_EXT, DAC_ADD_ITEM, ext "")
# }
#}
local function establish_global_type(handle)
{
if(!global_type || (global_type == CURRENT_BUFFER) || (global_type == DEFAULT))
global_type = Type(path_ext(buffer_filename));
if(global_type)
set_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM, global_type "");
else
{
set_dialog_item(handle, IDL_TYPE, DAC_SELECT_INDEX, 0);
global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
}
}
local function init_compilers(handle)
{
local name;
set_dialog_item(handle, IDL_COMPILER, DAC_DELETE_ITEM)
for (name in compilers)
{
set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, name "")
}
# set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, "[None]")
}
local function init_templates(handle)
{
local template
set_dialog_item(handle, IDL_TEMPLATE, DAC_DELETE_ITEM)
for (template in templates)
{
set_dialog_item(handle, IDL_TEMPLATE, DAC_ADD_ITEM, template "")
}
# set_dialog_item(handle, IDL_TEMPLATE, DAC_ADD_ITEM, "[None]")
}
###############################################################################
#
# Extension Settings Callback functions
#
###############################################################################
local function valid_type_name(type)
{
local retval = FALSE;
if(!type)
nop();
else if(prefix(type, 1) == ".")
warning("You may not add a type that begins with a \".\"");
else if(match(type, "[^a-zA-Z_0-9]") || match(prefix(type, 1), "[0-9]"))
warning("Type name must be valid for use as a function name.");
else if(type in languages)
warning("\"" type "\" already exists as a type.");
else if((type == CURRENT_BUFFER) || (type == DEFAULT))
warning("\"" type "\" is a reserved type name.");
else
retval = TRUE;
return retval;
}
global function ext_settings_callback()
{
local ext, type, new_type, list, handle = callback_dialog_handle;
local ret_msg = DRC_CONTINUE;
# enable_undo(handle, callback_index);
if(callback_msg == DM_HELPREQUESTED)
{
display_help(nbPagePrefix[current_nb_page].help, handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_msg == DM_CANCEL)
{
ret_msg = DRC_MSG_PROCESSED;
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
{
if(callback_index == IDB_UNDO)
{
# Reset entire extensions array, TODO but what part of the languages array?;
undo_ext_settings(global_type);
# extensions = copy_extensions_array(save_extensions);
# languages = copy_languages_array(save_languages);
initialize_ext_settings(handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_DEFAULT )
{
# Load the factory defaults that cannot be changed by the user;
load_factory_default_extensions();
load_factory_default_types();
initialize_ext_settings(handle);
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_ADD_COMP )
{
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)))
type = prompt_history("TYPE", "Enter new type :", type, 1, 1, "type_name_prompt");
restore_status_bar();
set_dialog_item(handle, IDL_TYPE, DAC_SETFOCUS);
if(valid_type_name(type))
{
add_type(type);
set_dialog_item(handle, IDL_TYPE, DAC_ADD_ITEM, type);
propogate_type();
set_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM, type);
nbPagePrefix[current_nb_page].modified = TRUE;
}
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_DEL_COMP )
{
type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
delete_type(type);
set_dialog_item(handle, IDL_TYPE, DAC_DELETE_ITEM, type"");
set_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT, "");
set_dialog_item(handle, IDE_PAIRS, DAC_EDIT_TEXT, "");
set_dialog_item(handle, IDB_CHG_COMP, DAC_DISABLE);
set_dialog_item(handle, IDB_CPY_COMP, DAC_DISABLE);
set_dialog_item(handle, IDB_DEL_COMP, DAC_DISABLE);
propogate_type();
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_CHG_COMP )
{
type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
new_type = prompt_history("TYPE", "Change type name:", type, 1, 1, "type_name_prompt");
restore_status_bar();
if(valid_type_name(new_type) && (new_type != type))
{
CopyType(type, new_type);
delete_type(type);
set_dialog_item(handle, IDL_TYPE, DAC_DELETE_ITEM, type);
set_dialog_item(handle, IDL_TYPE, DAC_ADD_ITEM, new_type);
propogate_type();
set_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM, new_type);
nbPagePrefix[current_nb_page].modified = TRUE;
}
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_CPY_COMP )
{
type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
new_type = prompt_history("TYPE", "Enter type to copy to:", type, 1, 1, "type_name_prompt" );
restore_status_bar();
if(valid_type_name(new_type))
{
if(!(new_type in languages))
{
set_dialog_item(handle, IDL_TYPE, DAC_ADD_ITEM, new_type);
propogate_type();
}
CopyType(type, new_type);
nbPagePrefix[current_nb_page].modified = TRUE;
}
ret_msg = DRC_MSG_PROCESSED;
}
}
else if ( callback_msg == DM_SELECT )
{
if ( callback_index == IDL_TYPE )
{
global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
set_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT, get_ext_list(global_type)"");
set_dialog_item(handle, IDE_PAIRS, DAC_EDIT_TEXT, MatchingPairs(global_type)"");
if (global_type == "[None]")
{
set_dialog_item( handle, IDB_CHG_COMP, DAC_DISABLE )
set_dialog_item( handle, IDB_CPY_COMP, DAC_DISABLE )
set_dialog_item( handle, IDB_DEL_COMP, DAC_DISABLE )
}
else
{
set_dialog_item( handle, IDB_CHG_COMP, DAC_ENABLE )
set_dialog_item( handle, IDB_CPY_COMP, DAC_ENABLE )
set_dialog_item( handle, IDB_DEL_COMP, DAC_ENABLE )
}
ret_msg = DRC_MSG_PROCESSED;
}
}
else if(callback_msg == DM_KILL_FOCUS)
{
if(callback_index == IDE_PAIRS)
{
set_pairs(global_type, query_dialog_item(handle, IDE_PAIRS, DAC_EDIT_TEXT));
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDE_EXTENSIONS)
{
list = query_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT);
validate_ext_list(global_type, list);
list = get_ext_list(global_type);
set_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT, list"");
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
}
return ret_msg;
}
global function compiler_settings_callback()
{
local name, ext, new_name, value, file, state, err_format, cmd_line;
local advanced_dialog;
local ret_msg = DRC_CONTINUE;
local handle = callback_dialog_handle;
enable_undo(callback_dialog_handle, callback_index);
if(nb_initializing)
ret_msg = DRC_MSG_PROCESSED;
else if(callback_msg == DM_HELPREQUESTED)
{
display_help(nbPagePrefix[current_nb_page].help, handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_msg == DM_CANCEL )
{
ret_msg = DRC_MSG_PROCESSED;
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
{
if(callback_index == IDB_UNDO)
{
compilers = copy_compilers_array(save_compilers);
initialize_compiler_settings(handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_DEFAULT )
{
# Load factory default settings that cannot be changed by the user;
load_factory_default_compilers();
initialize_compiler_settings(handle)
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDB_ADVANCED)
{
advanced_dialog = create_dialog( function_id("advanced_compilers_callback"), handle, IDD_ADVANCED_COMPILER_SETTINGS );
if ( advanced_dialog )
{
local_compiler = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
initialize_advanced_compilers_dialog(advanced_dialog, local_compiler);
attach_help(editor_helpfile, advanced_dialog);
begin_dialog(advanced_dialog);
}
ret_msg = DRC_MSG_PROCESSED;
}
else if (callback_index == IDB_ADD_COMP )
{
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)))
name = prompt_history("COMPILER", "Enter new compiler :", name, 1, 1, "compiler_name_prompt" );
restore_status_bar();
set_dialog_item(handle, IDL_COMPILER, DAC_SETFOCUS);
if(!(name in compilers))
{
cmd_line = "$<"
err_format = "[None]"
add_compiler(name, cmd_line, "none");
set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, name);
}
else
{
cmd_line = CommandLine(name)
err_format = ErrorFormat(name)
if(!err_format || err_format == "none")
err_format = "[None]"
}
nbPagePrefix[current_nb_page].modified = TRUE;
set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, name "");
set_dialog_item(handle, IDE_COMMAND_LINE, DAC_EDIT_TEXT, cmd_line "");
set_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM, err_format);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_DEL_COMP )
{
name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
if(name)
{
delete_compiler(name);
set_dialog_item(handle, IDL_COMPILER, DAC_DELETE_ITEM, name);
set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, "[None]");
#set_dialog_item(handle, IDB_CHG_COMP, DAC_DISABLE);
#set_dialog_item(handle, IDB_CPY_COMP, DAC_DISABLE);
#set_dialog_item(handle, IDB_DEL_COMP, DAC_DISABLE);
nbPagePrefix[current_nb_page].modified = TRUE;
}
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_CHG_COMP )
{
name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
if(name)
{
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
new_name = prompt_history("COMPILER", "Change compiler name:", name, 1, 1, "compiler_name_prompt" );
restore_status_bar();
if(new_name && (new_name != name))
{
copy_compiler(name, new_name);
delete_compiler(name);
set_dialog_item(handle, IDL_COMPILER, DAC_DELETE_ITEM, name);
set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, new_name);
nbPagePrefix[current_nb_page].modified = TRUE;
}
set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, new_name);
}
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_CPY_COMP )
{
name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
new_name = prompt_history("COMPILER", "Enter compiler name to copy to:", name, 1, 1, "compiler_name_prompt" );
restore_status_bar();
if(new_name && (new_name != name)) # only do the copy if user entered a new name;
{
copy_compiler(name, new_name);
set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, new_name);
set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, new_name);
nbPagePrefix[current_nb_page].modified = TRUE;
}
ret_msg = DRC_MSG_PROCESSED;
}
}
else if ( callback_msg == DM_SELECT )
{
if(callback_index == IDL_TYPE)
{
global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
name = CompilerName(global_type);
if(name in compilers)
set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, name);
else
set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, "[None]");
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDL_COMPILER)
{
# type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
set_compiler_name(global_type, name);
if(name in compilers)
set_compiler(handle, global_type, name)
else
{
set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, "[None]")
set_dialog_item(handle, IDE_COMMAND_LINE, DAC_EDIT_TEXT, "[None]")
set_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM, "[None]")
set_dialog_item(handle, IDE_OTHER, DAC_EDIT_TEXT, "")
}
set_dialog_item(handle, IDB_CHG_COMP, DAC_ENABLE )
set_dialog_item(handle, IDB_CPY_COMP, DAC_ENABLE )
if(name != "[None]")
set_dialog_item(handle, IDB_DEL_COMP, DAC_ENABLE )
else
set_dialog_item(handle, IDB_DEL_COMP, DAC_DISABLE )
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDL_ERROR)
{
name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM)
if (name in compilers)
{
value = query_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM);
if(value != "other")
{
set_dialog_item(handle, IDE_OTHER, DAC_DISABLE);
set_dialog_item(handle, IDT_BUFFER_DEF_TEXT, DAC_DISABLE);
set_error_format(name, (value == "[None]") ? "none" : value);
}
else
{
set_dialog_item(handle, IDE_OTHER, DAC_ENABLE);
set_dialog_item(handle, IDT_BUFFER_DEF_TEXT, DAC_ENABLE);
set_error_format(name, "other," query_dialog_item(handle, IDE_OTHER, DAC_EDIT_TEXT));
}
nbPagePrefix[current_nb_page].modified = TRUE;
}
ret_msg = DRC_MSG_PROCESSED;
}
}
else if(callback_msg == DM_KILL_FOCUS)
{
if(callback_index == IDE_COMMAND_LINE)
{
name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM)
if (name in compilers)
{
value = query_dialog_item(handle, IDE_COMMAND_LINE, DAC_EDIT_TEXT);
set_command_line(name, value);
nbPagePrefix[current_nb_page].modified = TRUE;
}
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDE_OTHER)
{
name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM)
if (name in compilers)
{
value = query_dialog_item(handle, IDE_OTHER, DAC_EDIT_TEXT);
set_error_format(name, "other," value);
nbPagePrefix[current_nb_page].modified = TRUE;
}
ret_msg = DRC_MSG_PROCESSED;
}
}
return ret_msg;
}
global function initialize_advanced_compilers_dialog(handle, name)
{
local input = CompilerInput(name);
local save = CompilerSaveAll(name);
local output = CompilerOutput(name);
local background = CompilerBackground(name);
local flags = CompilerFlags(name);
local chgdir = CompilerChdir(name);
local file;
file = (input+0 < 0) ? "" : input"";
input = (length(file) > 0);
file = (file+0 == 1) ? "" : file;
if(input)
{
set_dialog_item(handle, IDC_NEEDS_INPUT, DAC_CHECK);
set_dialog_item(handle, IDE_INPUT_FILE, DAC_EDIT_TEXT, file"");
}
else
{
set_dialog_item(handle, IDC_NEEDS_INPUT, DAC_UNCHECK);
set_dialog_item(handle, IDE_INPUT_FILE, DAC_DISABLE);
}
if(save)
set_dialog_item(handle, IDC_SAVE_ALL, DAC_CHECK);
else
set_dialog_item(handle, IDC_SAVE_ALL, DAC_UNCHECK);
if(output)
set_dialog_item(handle, IDC_LIST_ALL, DAC_CHECK);
else
set_dialog_item(handle, IDC_LIST_ALL, DAC_UNCHECK);
if(chgdir)
set_dialog_item(handle, IDC_CHDIR, DAC_CHECK);
else
set_dialog_item(handle, IDC_CHDIR, DAC_UNCHECK);
if(background)
set_dialog_item(handle, IDC_BACKGROUND, DAC_CHECK);
else
set_dialog_item(handle, IDC_BACKGROUND, DAC_UNCHECK);
if (flags > 0)
{
if(and(flags, SYS_SESSION))
set_dialog_item(handle, IDC_SESSION, DAC_CHECK);
else
set_dialog_item(handle, IDC_SESSION, DAC_UNCHECK);
if(and(flags, SYS_SHELL))
set_dialog_item(handle, IDC_SHELL, DAC_CHECK);
else
set_dialog_item(handle, IDC_SHELL, DAC_UNCHECK);
if(and(flags, SYS_DOSSHELL))
{
set_dialog_item(handle, IDC_DOSSHELL, DAC_CHECK);
set_dialog_item(handle, IDB_DOS_SETTINGS, DAC_ENABLE);
}
else
{
set_dialog_item(handle, IDC_DOSSHELL, DAC_UNCHECK);
set_dialog_item(handle, IDB_DOS_SETTINGS, DAC_DISABLE);
}
}
else
{
set_dialog_item(handle, IDC_SHELL, DAC_UNCHECK);
set_dialog_item(handle, IDC_DOSSHELL, DAC_UNCHECK);
set_dialog_item(handle, IDC_SESSION, DAC_UNCHECK);
set_dialog_item(handle, IDB_DOS_SETTINGS, DAC_DISABLE);
}
}
global function advanced_compilers_callback()
{
local dos_settings_dialog
local shell, dos, session, flags
local state, file, ret_msg = DRC_CONTINUE;
local handle = callback_dialog_handle;
if(nb_initializing)
{
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_msg == DM_HELPREQUESTED)
{
if(isWindows())
display_help("Advanced Compilers", handle);
else
display_help("advcomp", handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_msg == DM_CANCEL )
{
ret_msg = DRC_EXIT;
}
else if ( callback_msg == DM_OK )
{
file = query_dialog_item(handle, IDE_INPUT_FILE, DAC_EDIT_TEXT);
state = query_dialog_item(handle, IDC_NEEDS_INPUT, DAC_CHECK );
set_compiler_input(local_compiler, state, file);
state = query_dialog_item(handle, IDC_SAVE_ALL, DAC_CHECK );
set_compiler_save_all(local_compiler, state);
state = query_dialog_item(handle, IDC_LIST_ALL, DAC_CHECK );
set_compiler_output(local_compiler, state);
state = query_dialog_item(handle, IDC_CHDIR, DAC_CHECK );
set_compiler_chdir(local_compiler, state);
state = query_dialog_item(handle, IDC_BACKGROUND, DAC_CHECK );
set_compiler_background(local_compiler, state);
dos = query_dialog_item(handle, IDC_DOSSHELL, DAC_CHECK );
shell = query_dialog_item(handle, IDC_SHELL, DAC_CHECK );
session = query_dialog_item(handle, IDC_SESSION, DAC_CHECK );
flags = (SYS_DOSSHELL * dos) + (SYS_SHELL * shell) + \
(SYS_SESSION * session)
set_compiler_flags(local_compiler, flags);
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_EXIT;
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
{
if ( callback_index == IDC_NEEDS_INPUT )
{
state = query_dialog_item(handle, IDC_NEEDS_INPUT, DAC_CHECK );
set_dialog_item(handle, IDE_INPUT_FILE,
state ? DAC_ENABLE : DAC_DISABLE)
ret_msg = DRC_MSG_PROCESSED;
}
else if( callback_index == IDC_DOSSHELL)
{
state = query_dialog_item(handle, IDC_DOSSHELL, DAC_CHECK );
set_dialog_item(handle, IDB_DOS_SETTINGS,
state ? DAC_ENABLE : DAC_DISABLE)
ret_msg = DRC_MSG_PROCESSED;
}
else if( callback_index == IDB_DOS_SETTINGS)
{
dos_settings_dialog = create_dialog( function_id("dos_settings_callback"), handle, IDD_DOS_SETTINGS_DIALOG );
if ( dos_settings_dialog )
{
initialize_dos_settings_dialog(dos_settings_dialog, local_compiler);
attach_help(editor_helpfile, dos_settings_dialog);
begin_dialog(dos_settings_dialog);
}
ret_msg = DRC_MSG_PROCESSED;
}
else if( callback_index == IDC_SAVE_ALL )
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_msg == DM_KILL_FOCUS)
{
if(callback_index == IDE_INPUT_FILE)
ret_msg = DRC_MSG_PROCESSED;
}
return ret_msg;
}
global function initialize_dos_settings_dialog(handle, name)
{
local s
dos_settings_array = CompilerDOSSettingsArray(name);
add_dialog_item(handle, IDE_VALUE, DCTRL_EDIT);
set_dialog_item(handle, IDE_VALUE, DAC_SET_TEXT_LEN, 255);
add_dialog_item(handle, IDL_SETTINGS, DCTRL_COMBO_BOX);
for (s in dos_settings_array)
set_dialog_item(handle, IDL_SETTINGS, DAC_ADD_ITEM, s);
}
global function dos_settings_callback()
{
local setting, value
local ret_msg = DRC_CONTINUE;
local handle = callback_dialog_handle;
if(nb_initializing)
{
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_msg == DM_HELPREQUESTED)
{
display_help("dossettings", handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_msg == DM_CANCEL )
{
ret_msg = DRC_EXIT;
}
else if ( callback_msg == DM_OK )
{
set_compiler_dos_settings_array(local_compiler, dos_settings_array)
ret_msg = DRC_EXIT;
}
else if ( callback_msg == DM_SELECT )
{
if(callback_index == IDL_SETTINGS)
{
setting = query_dialog_item(handle, IDL_SETTINGS, DAC_SELECT_ITEM);
set_dialog_item(handle, IDE_VALUE, DAC_EDIT_TEXT, dos_settings_array[setting] "")
}
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
{
if ( callback_index == IDB_ADD_SETTING )
{
setting = query_dialog_item(handle, IDL_SETTINGS, DAC_EDIT_TEXT);
value = query_dialog_item(handle, IDE_VALUE, DAC_EDIT_TEXT);
if (length(setting) && length(value))
{
dos_settings_array[setting] = value
set_dialog_item(handle, IDL_SETTINGS, DAC_TEXT, "");
set_dialog_item(handle, IDE_VALUE, DAC_EDIT_TEXT, "");
if (query_dialog_item(handle, IDL_SETTINGS, DAC_FIND, setting) < 0)
set_dialog_item(handle, IDL_SETTINGS, DAC_ADD_ITEM, setting);
}
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_DELETE_SETTING )
{
setting = query_dialog_item(handle, IDL_SETTINGS, DAC_EDIT_TEXT);
if (length(setting))
{
dos_settings_array[setting] = ""
delete dos_settings_array[setting]
set_dialog_item(handle, IDL_SETTINGS, DAC_DELETE_ITEM, setting);
set_dialog_item(handle, IDL_SETTINGS, DAC_TEXT, "");
set_dialog_item(handle, IDE_VALUE, DAC_EDIT_TEXT, "");
}
ret_msg = DRC_MSG_PROCESSED;
}
}
return ret_msg;
}
global function template_settings_callback()
{
local ret_msg = DRC_CONTINUE, value, type, name;
local handle = callback_dialog_handle;
enable_undo(callback_dialog_handle, callback_index);
if(callback_msg == DM_HELPREQUESTED)
{
display_help(nbPagePrefix[current_nb_page].help, callback_dialog_handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_msg == DM_CANCEL )
{
nbPagePrefix[current_nb_page].modified = FALSE;
ret_msg = DRC_MSG_PROCESSED;
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
{
if(callback_index == IDB_UNDO)
{
# Undo the changes that could have been made on this page;
undo_template_settings();
initialize_template_settings(handle);
nbPagePrefix[current_nb_page].modified = FALSE;
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_DEFAULT )
{ # TODO this looks too severe
load_factory_default_types();
initialize_template_settings(handle)
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDC_EXPANSION)
{
value = query_dialog_item(handle, IDC_EXPANSION, DAC_CHECK);
set_expand_template(global_type, value);
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
}
else if ( callback_msg == DM_SELECT )
{
if(callback_index == IDL_TYPE)
{
type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
global_type = type;
name = Template(type);
if(name in templates)
set_dialog_item(handle, IDL_TEMPLATE, DAC_SELECT_ITEM, name);
else
set_dialog_item(handle, IDL_TEMPLATE, DAC_SELECT_ITEM, "[None]");
if(get_expand_template(global_type))
set_dialog_item(handle, IDC_EXPANSION, DAC_CHECK);
else
set_dialog_item(handle, IDC_EXPANSION, DAC_UNCHECK);
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDL_TEMPLATE)
{
type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
name = query_dialog_item(handle, IDL_TEMPLATE, DAC_SELECT_ITEM);
set_template(type, name);
nbPagePrefix[current_nb_page].modified = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
}
return ret_msg;
}
###############################################################################
#
# Extension Settings Undo functions
#
###############################################################################
local function undo_ext_settings(type)
{
local list;
if(type in languages)
{
list = get_ext_list(type, TRUE);
validate_ext_list(type, list);
set_pairs(type, save_languages[type].matching_pairs);
}
}
local function undo_template_settings(type)
{
if(type in languages)
{
languages[type].template = save_languages[type].template;
languages[type].expand = save_languages[type].expand;
}
}
global function undo_extension_section_settings()
{
local type;
if(save_extensions)
extensions = copy_extensions_array(save_extensions);
if(save_compilers)
compilers = copy_compilers_array(save_compilers);
if(save_languages)
languages = copy_languages_array(save_languages);
for(type in syntax_loaded)
{
# This removes all types that were loaded while notebook was up;
if(syntax_loaded[type] == 23)
delete syntax_loaded[type];
}
}
########################## COMPILER SETTINGS DIALOG ##########################
global function ext_apply_to_all()
{
local ext
local first_buf = current_buffer
local sentinel = next_buffer("", 0, 1)
# Apply to all buffers.
do
{
ext = path_ext(buffer_name)
if(ext in extensions)
{
if(Tabs(ext))
buffer_tabs = Tabs(ext);
if(Margins(ext))
{
wp_left_margin = LeftMargin(ext);
wp_right_margin = RightMargin(ext);
}
# buffer_flags = BufferFlags(ext);
}
}
while( next_buffer("", 0, 1) != sentinel )
current_buffer = first_buf
}
#global function template_apply_to_all()
#{
# nop();
#}
global function get_ext_list(type, in_save)
{
local ext, result = "";
if(in_save)
{
for(ext in save_extensions)
{
if(save_extensions[ext] == type)
result = result ext " ";
}
}
else
{
for(ext in extensions)
{
if(Type(ext) == type)
result = result ext " ";
}
}
return result;
}
global function validate_ext_list(type, list)
{
local array, ext, i;
# This loop removes all extensions mapped to "type";
for(ext in extensions)
{
if(Type(ext) == type)
delete extensions[ext];
}
split(list, array);
# This loop maps all extensions in array to "type";
for(i in array)
{
ext = (prefix(array[i], 1) == ".") ? array[i] : "."array[i];
SetType(ext, type);
}
}
local function propogate_type()
{
local page, dlgid, page_name;
for(page in nbPagePrefix)
{
dlgid = nbPagePrefix[page].dialog_handle
if(dlgid)
{
page_name = nbPagePrefix[page].name;
if((page_name == "compiler") || (page_name == "syntax") ||(page_name == "template"))
init_types(dlgid);
else if((page_name == "buffer1") || (page_name == "buffer2") || (page_name == "buffer3"))
init_types(dlgid, 1);
}
}
}
################# SYNTAX HIGHLIGHTING SETTINGS NOTEBOOK PAGE ########################
local IDV_FOREGROUND = 101
local IDV_BACKGROUND = 105
local IDC_DEFAULT_FG = 104
local IDC_DEFAULT_BG = 107
local IDB_ADVANCEDITEMS = 103
local IDD_ADVANCED_ITEM_SETTINGS = 1091
local IDE_ESCAPE_CHAR = 102;
local IDB_CATEGORY_COLOR = 110
local IDB_ITEM_COLOR = 105
local IDD_SYNTAX_COLOR = 1700
local IDB_CUSTOM = 106
local IDD_NEW_SYTNAX_IC = 1701
local IDD_CONFIGURE_COLOR = 1702
local IDS_CATEGORY = 103
local IDS_CATEGORY_COLOR = 108;
local IDS_ITEM_COLOR = 104;
local IDS_USING_CAT = 111;
local IDS_USING_ITEM = 101;
local IDC_CASE_SENSITIVE = 109;
local IDR_KEYWORD = 116;
local IDR_LINE = 113;
local IDR_BLOCK = 115;
local local_iscat = FALSE; # global variables set before callbacks are
local local_item = FALSE; # called so i have access to these values.
local local_cat = FALSE;
local local_catname = FALSE;
local local_add = FALSE;
local local_fgind = FALSE;
local local_bgind = FALSE;
local mini_storage[];
local names_added[]
global function create_syntax_page(pageid, dlgid)
{
local row, col, dhandle, color;
dhandle = create_page(function_id( "syntax_settings_callback" ),
dlgid, IDD_SYNTAX_SETTINGS, resource_dll)
attach_help(editor_helpfile, dhandle)
if(isWindows())
nbPagePrefix[pageid].help = "Extension Settings";
else
nbPagePrefix[pageid].help = "colorspage";
if(!save_languages)
save_languages = copy_languages_array(languages);
set_dialog_item(dhandle, IDL_TYPE, DAC_SORT_ASCENDING);
set_dialog_item(dhandle, IDL_ITEMS, DAC_SORT_ASCENDING);
set_dialog_item(dhandle, IDL_CATEGORY, DAC_SORT_ASCENDING);
add_dialog_item(dhandle, IDE_ESCAPE_CHAR, DCTRL_EDIT);
add_dialog_item(dhandle, IDE_WORD_DELIMITER, DCTRL_EDIT);
set_dialog_item(dhandle, IDE_ESCAPE_CHAR, DAC_SET_TEXT_LEN, 1);
add_dialog_item(dhandle, IDR_KEYWORD, DCTRL_RADIO_BUTTON);
add_dialog_item(dhandle, IDR_LINE, DCTRL_RADIO_BUTTON);
add_dialog_item(dhandle, IDR_BLOCK, DCTRL_RADIO_BUTTON);
set_notebook_page_dialog(dlgid, pageid, dhandle);
initialize_syntax_settings( dhandle, "dummy" , 1 );
nbPagePrefix[pageid].dialog_handle = dhandle;
}
global function initialize_syntax_settings( handle, dummy, load_types )
{
local type, item;
# nb_initializing = TRUE;
if(load_types)
init_types(handle);
add_dialog_item(handle, IDL_ITEMS, DCTRL_COMBO_BOX);
type = (global_type ? global_type : Type(path_ext(buffer_filename)) "" );
set_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM, type "");
if(query_dialog_item(handle, IDL_TYPE, DAC_SELECT_INDEX) < 0)
set_dialog_item(handle, IDL_TYPE, DAC_SELECT_INDEX, 0);
global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM) "";
if(!(global_type in syntax_loaded))
{
if(!("__styles" in syntax_loaded))
{
optional_function("load_user_styles");
syntax_loaded["__styles"] = TRUE;
}
optional_function("load_user_" global_type "_syntax");
save_syntax_part(global_type);
syntax_loaded[global_type] = 23;
}
init_category(handle, global_type);
enable_buttons(handle);
set_dialog_item(handle, IDE_WORD_DELIMITER, DAC_EDIT_TEXT, StyleDelimiters(global_type) "");
set_dialog_item(handle, IDE_ESCAPE_CHAR, DAC_EDIT_TEXT, EscapeCharacter(global_type) "");
if(get_case_sensitive(global_type))
set_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_CHECK);
else
set_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_UNCHECK);
nb_initializing = FALSE;
}
local function init_category(handle, type)
{
local item, array = Category(type), count;
set_busy_cursor();
set_dialog_item(handle, IDL_CATEGORY, DAC_TEXT, "");
set_dialog_item(handle, IDL_CATEGORY, DAC_DELETE_ITEM);
for(item in array)
{
set_dialog_item(handle, IDL_CATEGORY, DAC_ADD_ITEM, array[item].name "");
}
if(!set_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM, "All"))
init_items(handle, type)
set_normal_cursor();
}
local function init_items(handle, type, category)
{
local item, array[], count;
array = Keyword(type);
set_busy_cursor();
set_dialog_item(handle, IDL_ITEMS, DAC_DELETE_ITEM);
set_dialog_item(handle, IDL_ITEMS, DAC_TEXT, "");
category += 0;
for(item in array)
{
if(!category || ((Keyword(type, item, CATEGORY_MASK)+0) == category))
{
set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, item "");
}
}
array = Line(type);
for(item in array)
{
if(!category || ((Line(type, item, CATEGORY_MASK)+0) == category))
{
set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, item "");
}
}
array = Block(type);
for(item in array)
{
if(!category || ((Block(type, item, CATEGORY_MASK)+0) == category))
{
set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, item "");
}
}
if(query_dialog_item(handle, IDL_ITEMS, DAC_COUNT_ITEMS))
set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_INDEX, 0);
set_normal_cursor();
}
local do_done = FALSE;
local assign_cats = FALSE;
global function syntax_settings_callback()
{
local ret_msg = DRC_CONTINUE, name, style, cat, new_name, value, type, once;
local handle = callback_dialog_handle, response, count, word, array;
local dfg, dbg, fgval, bgval, advanced_dialog, color_dialog, catname;
enable_undo(callback_dialog_handle, callback_index);
if(nb_initializing)
ret_msg = DRC_MSG_PROCESSED;
else if(callback_msg == DM_HELPREQUESTED)
{
display_help(nbPagePrefix[current_nb_page].help, handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_msg == DM_CANCEL )
{
ret_msg = DRC_MSG_PROCESSED;
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
{
if(callback_index == IDB_UNDO)
{
undo_syntax_settings(global_type);
set_modified(global_type, FALSE);
initialize_syntax_settings(handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_index == IDB_DEFAULT )
{
# Load factory default settings that cannot be changed by the user;
value = function_id("load_factory_"global_type"_syntax");
if(value)
{
reset_languages(0);
set_keyword(global_type, FALSE);
set_line(global_type, FALSE);
set_block(global_type, FALSE);
set_category(global_type); # one parameter to set_cat. deletes all categories
delete save_styles[global_type];
optional_function(value);
reset_languages(1);
initialize_syntax_settings(handle)
set_modified(global_type, TRUE);
}
else
warning("No factory defaults defined for type " global_type);
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDB_DEL_COMP)
{
set_modified(global_type, TRUE);
count = query_dialog_item(handle, IDL_ITEMS, DAC_COUNT_ITEMS);
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
response = confirm("Delete entire Category of " count " items? (Y/N):", "YyNn");
restore_status_bar();
if(tolower(response) == "y")
{
if(local_catname != "All")
{
set_dialog_item(handle, IDL_CATEGORY, DAC_DELETE_ITEM, local_catname"");
}
else
{
set_dialog_item(handle, IDL_ITEMS, DAC_DELETE_ITEM);
set_dialog_item(handle, IDL_ITEMS, DAC_TEXT, "");
}
delete_category(global_type, local_cat);
set_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM, "All");
enable_buttons(handle);
}
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDB_DEL_EXT)
{
set_modified(global_type, TRUE);
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
response = confirm("Delete item? (Y/N):", "YyNn");
restore_status_bar();
if(tolower(response) == "y")
{
delete_item(global_type, local_item);
set_dialog_item(handle, IDL_ITEMS, DAC_DELETE_ITEM, local_item);
set_dialog_item(handle, IDL_ITEMS, DAC_TEXT, "");
set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_INDEX, 0);
enable_buttons(handle);
}
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDB_ADD_COMP)
{
set_busy_cursor()
set_modified(global_type, TRUE);
local_iscat = TRUE;
local_add = TRUE;
color_dialog = create_dialog( function_id("create_item_callback"), handle, IDD_NEW_SYTNAX_IC);
initialize_select_color(color_dialog, global_type, 1, "", local_catname)
set_normal_cursor()
begin_dialog(color_dialog)
if(do_done)
do_done_processing();
local_add = FALSE;
set_dialog_item(handle, IDL_CATEGORY, DAC_DESELECT_ITEM);
once = 1
for ( cat in names_added )
{
set_dialog_item(handle, IDL_CATEGORY, DAC_ADD_ITEM, cat);
set_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM, cat);
if ( once )
{
enable_buttons(handle);
once = 0
}
}
delete names_added
names_added = 0
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDB_ADD_EXT)
{
set_busy_cursor()
set_modified(global_type, TRUE);
local_iscat = FALSE;
local_add = TRUE;
color_dialog = create_dialog( function_id("create_item_callback"), handle, IDD_NEW_SYTNAX_IC);
initialize_select_color(color_dialog, global_type, 0, "", local_catname);
set_normal_cursor()
begin_dialog(color_dialog)
if(do_done)
do_done_processing()
local_add = FALSE;
# Force updated colors to take affect.
once = 1
for ( cat in names_added )
{
set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, cat);
set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM, cat);
if ( once )
{
enable_buttons(handle);
once = 0
}
}
delete names_added
names_added = 0
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDB_ADVANCEDITEMS)
{
set_modified(global_type, TRUE);
advanced_dialog = create_dialog( function_id("advanced_items_callback"), handle, IDD_ADVANCED_ITEM_SETTINGS );
if ( advanced_dialog )
{
initialize_advanced_dialog(advanced_dialog, global_type, local_item);
attach_help(editor_helpfile, advanced_dialog);
begin_dialog(advanced_dialog);
}
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDC_CASE_SENSITIVE)
{
value = query_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_CHECK);
set_case_sensitive(global_type, value);
set_modified(global_type, TRUE);
if(!value)
{
tolower_keywords(global_type);
init_items(handle, global_type, local_cat);
}
}
else if(callback_index == IDB_CATEGORY_COLOR)
{
set_modified(global_type, TRUE);
local_iscat = TRUE;
color_dialog = create_dialog( function_id("select_color_callback"), handle, IDD_SYNTAX_COLOR );
save_select_color_category(global_type);
initialize_select_color(color_dialog, global_type, 1, local_catname, local_catname)
begin_dialog(color_dialog)
if(assign_cats)
assign_category_colors(global_type);
assign_cats = FALSE;
if(do_done)
do_done_processing();
# Force updated colors to take affect.
set_dialog_item(handle, IDL_CATEGORY, DAC_DESELECT_ITEM, local_catname);
set_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM, local_catname);
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDB_ITEM_COLOR)
{
set_modified(global_type, TRUE);
local_iscat = FALSE;
color_dialog = create_dialog( function_id("select_color_callback"), handle, IDD_SYNTAX_COLOR );
save_select_color_item(global_type);
initialize_select_color(color_dialog, global_type, 0, local_item, local_catname)
begin_dialog(color_dialog);
if(do_done)
do_done_processing()
set_dialog_item(handle, IDL_ITEMS, DAC_DESELECT_ITEM);
set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM, local_item "");
ret_msg = DRC_MSG_PROCESSED;
}
else if( (callback_index == IDR_KEYWORD) || (callback_index == IDR_LINE) \
|| (callback_index == IDR_BLOCK) )
{
# We don't need to check if the style selected is valid, because
# only valid styles are enabled.
if(callback_index == IDR_KEYWORD)
{
set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_DISABLE);
style = KEYWORD;
}
else if(callback_index == IDR_LINE)
{
set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_ENABLE);
style = LINE;
}
else if(callback_index == IDR_BLOCK)
{
set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_DISABLE);
style = BLOCK
}
if(local_item)
{
set_modified(global_type, TRUE);
value = Value(global_type, local_item);
delete_item(global_type, local_item);
add_syntax_item(global_type, style, local_item, value+0);
value = Value(global_type, local_item);
}
}
}
else if ( callback_msg == DM_SELECT )
{
if(callback_index == IDL_TYPE)
{
global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
initialize_syntax_settings(handle);
# if(!(global_type in syntax_loaded))
# {
# if(!("__styles" in syntax_loaded))
# {
# optional_function("load_user_styles");
# syntax_loaded["__styles"] = TRUE;
# }
# optional_function("load_user_" global_type "_syntax");
# save_syntax_part(global_type);
# syntax_loaded[global_type] = 23;
# }
# init_category(handle, global_type);
# enable_buttons(handle);
# set_dialog_item(handle, IDE_WORD_DELIMITER, DAC_EDIT_TEXT, StyleDelimiters(global_type) "");
# set_dialog_item(handle, IDE_ESCAPE_CHAR, DAC_EDIT_TEXT, EscapeCharacter(global_type) "");
#
# if(get_case_sensitive(global_type))
# set_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_CHECK);
# else
# set_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_UNCHECK);
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDL_CATEGORY)
{
local_catname = query_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM);
local_cat = Category(global_type, local_catname) + 0;
init_items(handle, global_type, local_cat);
enable_buttons(handle);
fgval = get_current_color_of_item(global_type, local_catname, 0, 1)
bgval = get_current_color_of_item(global_type, local_catname, 1, 1)
set_color(handle, fgval, bgval, 1);
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDL_ITEMS)
{
local_item = query_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM);
set_style(handle, isValidStyle(global_type, local_item), Style(global_type, local_item));
fgval = get_current_color_of_item(global_type, local_item, 0, 0)
bgval = get_current_color_of_item(global_type, local_item, 1, 0)
set_color(handle, fgval, bgval);
ret_msg = DRC_MSG_PROCESSED;
}
}
else if(callback_msg == DM_KILL_FOCUS)
{
if(callback_index == IDE_WORD_DELIMITER)
{
set_modified(global_type, TRUE);
set_style_delimiters(global_type, query_dialog_item(handle, IDE_WORD_DELIMITER, DAC_EDIT_TEXT) "");
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDE_ESCAPE_CHAR)
{
set_modified(global_type, TRUE);
value = query_dialog_item(handle, IDE_ESCAPE_CHAR, DAC_EDIT_TEXT)"";
set_escape_character(global_type, value);
ret_msg = DRC_MSG_PROCESSED;
}
}
return ret_msg;
}
local function enable_buttons(handle)
{
local count;
count = query_dialog_item(handle, IDL_CATEGORY, DAC_COUNT_ITEMS);
if(count < 1)
{
set_dialog_item(handle, IDB_CATEGORY_COLOR, DAC_DISABLE);
set_dialog_item(handle, IDB_DEL_COMP, DAC_DISABLE);
}
else
{
set_dialog_item(handle, IDB_CATEGORY_COLOR, DAC_ENABLE);
set_dialog_item(handle, IDB_DEL_COMP, DAC_ENABLE);
}
count = query_dialog_item(handle, IDL_ITEMS, DAC_COUNT_ITEMS);
if(count < 1)
{
set_dialog_item(handle, IDB_ITEM_COLOR, DAC_DISABLE);
set_dialog_item(handle, IDB_DEL_EXT, DAC_DISABLE);
set_dialog_item(handle, IDR_KEYWORD, DAC_DISABLE);
set_dialog_item(handle, IDR_LINE, DAC_DISABLE);
set_dialog_item(handle, IDR_BLOCK, DAC_DISABLE);
set_dialog_item(handle, IDR_KEYWORD, DAC_UNCHECK);
set_dialog_item(handle, IDR_LINE, DAC_UNCHECK);
set_dialog_item(handle, IDR_BLOCK, DAC_UNCHECK);
set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_DISABLE);
}
else
{
set_dialog_item(handle, IDB_ITEM_COLOR, DAC_ENABLE);
set_dialog_item(handle, IDB_DEL_EXT, DAC_ENABLE);
# set_dialog_item(handle, IDR_KEYWORD, DAC_ENABLE);
# set_dialog_item(handle, IDR_LINE, DAC_ENABLE);
# set_dialog_item(handle, IDR_BLOCK, DAC_ENABLE);
# set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_ENABLE);
}
}
local function assign_category_colors(type)
{
local fg, bg, cat, item, catname, array, catarray;
if(type in save_styles)
{
set_busy_cursor();
notify("Assigning new category colors.");
catarray = Category(type);
for(cat in catarray)
{
cat += 0;
catname = catarray[cat].name "";
if((catname in save_styles[type]) && save_styles[type][catname].category)
{
fg = save_styles[type][catname].foreground;
bg = save_styles[type][catname].background;
array = Keyword(type);
for(item in array)
{
if(!cat || (cat == (Keyword(type, item, CATEGORY_MASK)+0)))
{
save_styles[type][item].foreground = fg;
save_styles[type][item].background = bg;
}
}
array = Line(type);
for(item in array)
{
if(!cat || (cat == (Line(type, item, CATEGORY_MASK)+0)))
{
save_styles[type][item].foreground = fg;
save_styles[type][item].background = bg;
}
}
array = Block(type);
for(item in array)
{
if(!cat || (cat == (Block(type, item, CATEGORY_MASK)+0)))
{
save_styles[type][item].foreground = fg;
save_styles[type][item].background = bg;
}
}
}
}
set_normal_cursor();
}
}
#
# Returns the current color the specified type and item.
# If the item is in save_styles, that color is used, otherwise
# the color from the languages array is used.
#
local function get_current_color_of_item(type, item, isbg, cat)
{
local result = -1, index;
if((type in save_styles) && (item in save_styles[type]))
{
# Get the BGR value of the color saved in save_styles
if(isbg)
result = save_styles[type][item].background;
else
result = save_styles[type][item].foreground;
}
else
{
# Get BGR value of the color from languages array.
if(cat)
{
# if(local_catname == "All")
# result = -1;
if(isbg)
result = Category(type, local_cat, 2) +0;
else
result = Category(type, local_cat, 1) +0;
}
else
{
index = Value(type, item, ITEM_MASK) +0;
result = query_syntax_style(index, isbg);
}
}
return result;
}
local function delete_category(type, cat)
{
local array, item;
cat += 0;
array = Keyword(type);
for(item in array)
{
if(!cat || (Keyword(type, item, CATEGORY_MASK) == cat))
delete_item(type, item);
}
array = Line(type);
for(item in array)
{
if(!cat || (Line(type, item, CATEGORY_MASK) == cat))
delete_item(type, item);
}
array = Block(type);
for(item in array)
{
if(!cat || (Block(type, item, CATEGORY_MASK) == cat))
delete_item(type, item);
}
if(cat)
delete languages[type].category[cat];
}
local function delete_item(type, item)
{
if(type in languages)
{
if(item in languages[type].block)
{
delete languages[type].block[item];
}
if(item in languages[type].line)
{
delete languages[type].line[item];
}
if(item in languages[type].keyword)
{
delete languages[type].keyword[item];
}
}
}
local function Value(type, word, MASK)
{
local result = -1;
result = Block(type, word, MASK);
if(result+0 < 0)
result = Line(type, word, MASK);
if(result+0 < 0)
result = Keyword(type, word, MASK);
return result+0;
}
local function CategoryExist(type, cat)
{
local array = Category(type), index;
cat = cat"";
for(index in array)
{
if(array[index].name == cat)
return TRUE;
}
return FALSE;
}
local function undo_syntax_settings(type)
{
local word;
if(type in save_languages)
{
languages[type].stile_delimiters = save_languages[type].stile_delimiters;
reset_languages(0);
delete languages[type].category;
for(word in save_languages[type].category)
{
languages[type].category[word] = save_languages[type].category[word];
}
delete languages[type].keyword;
for(word in save_languages[type].keyword)
{
languages[type].keyword[word] = save_languages[type].keyword[word];
}
delete languages[type].line;
for(word in save_languages[type].line)
{
languages[type].line[word] = save_languages[type].line[word];
}
delete languages[type].block;
for(word in save_languages[type].block)
{
languages[type].block[word] = save_languages[type].block[word];
}
reset_languages(1);
delete save_styles[type];
}
else
{
warning("Initial values of this type were not saved.");
}
}
local function isValidStyle(type, item)
{
local result = 0;
result = or(result, isValidKeyword(type, item));
result = or(result, isValidLine(type, item));
result = or(result, isValidBlock(type, item));
return result;
}
local function isValidKeyword(type, item)
{
local result, pattern;
pattern = "[" quote_regex(StyleDelimiters(type)) " ]+";
result = !match(item, pattern);
return (result ? 0x1 : 0);
}
local function isValidLine(type, item)
{
local result = FALSE, array, count;
count = split(item, array);
result = ((count == 1) || (count == 2));
return (result ? 0x2 : 0);
}
local function isValidBlock(type, item)
{
local result = FALSE, array;
if(split(item, array) == 2)
{
result = (array[1] != array[2]);
}
return (result ? 0x4 : 0);
}
global function isDefined(fg, bg)
{
local ret_val = -1;
if(fg in defined_styles)
if(bg in defined_styles[fg])
ret_val = defined_styles[fg][bg];
return ret_val;
}
#
# Saves RGB value of selected color to save_styles array
#
local function saveItem(handle, type, dfg, dbg, add, iscat, item)
{
local fg, bg, fgval, bgval; # , item;
# Get the coordinates of the selected colors
fgval = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_SELECTED);
bgval = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_SELECTED);
# Get the RGB value of the selected colors
fgval = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_ITEM, fgval);
bgval = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_ITEM, bgval);
fg = (dfg ? -1 : fgval); # if default selected, use it;
bg = (dbg ? -1 : bgval); # otherwise use the valueset value
if(add)
{
if(!item)
item = query_dialog_item(handle, IDL_ITEMS, DAC_EDIT_TEXT);
if(iscat)
save_styles[type][item].category = TRUE;
# save RGB color values
save_styles[type][item].foreground = fg;
save_styles[type][item].background = bg;
}
else
{
if(!item)
item = query_dialog_item(handle, IDL_ITEMS, DAC_FIRST_ITEM)
while ( item != "" )
{
if(iscat)
save_styles[type][item].category = TRUE;
# save RGB color values
save_styles[type][item].foreground = fg;
save_styles[type][item].background = bg;
item = query_dialog_item(handle, IDL_ITEMS, DAC_NEXT_ITEM)
}
}
}
global function assign_syntax_changes()
{
local type, item, index, fg, bg;
set_busy_cursor();
notify("Creating new syntax styles.");
for(type in save_styles)
{
for(item in save_styles[type])
{
fg = save_styles[type][item].foreground;
bg = save_styles[type][item].background;
index = isDefined(fg, bg);
if(index < 0)
{
index = create_syntax_style(fg, bg);
defined_styles[fg][bg] = index;
}
if(save_styles[type][item].category)
add_syntax_category(type, -1, item, fg, bg);
else
add_syntax_item(type, Style(type, item), item, index, ITEM_MASK);
}
}
notify("");
set_normal_cursor();
}
# Color values passed as BGR if more than 2 parms
local function set_color(handle, value1, value2, iscat)
{
local row, col, fg, bg, text = "Using default ";
if(argcount() == 2)
{
fg = query_syntax_style(value1, 0);
bg = query_syntax_style(value1, 1);
}
else
{
fg = value1+0;
bg = value2+0;
}
if((fg < 0) && (bg < 0))
text = text "FG/BG";
else if(fg < 0)
text = text "FG";
else if(bg < 0)
text = text "BG";
else
text = "";
fg = (fg < 0) ? default_color_window_fg : fg;
bg = (bg < 0) ? default_color_window_bg : bg;
if(iscat)
{
set_dialog_item(handle, IDS_CATEGORY_COLOR, DAC_FG_COLOR, fg);
set_dialog_item(handle, IDS_CATEGORY_COLOR, DAC_BG_COLOR, bg);
set_dialog_item(handle, IDS_USING_CAT, DAC_TEXT, text);
}
else
{
set_dialog_item(handle, IDS_ITEM_COLOR, DAC_FG_COLOR, fg);
set_dialog_item(handle, IDS_ITEM_COLOR, DAC_BG_COLOR, bg);
set_dialog_item(handle, IDS_USING_ITEM, DAC_TEXT, text);
}
}
local function set_style(handle, valid, style)
{
if(and(valid, KEYWORD))
set_dialog_item(handle, IDR_KEYWORD, DAC_ENABLE);
else
set_dialog_item(handle, IDR_KEYWORD, DAC_DISABLE);
if(and(style, KEYWORD))
set_dialog_item(handle, IDR_KEYWORD, DAC_CHECK);
else
set_dialog_item(handle, IDR_KEYWORD, DAC_UNCHECK);
if(and(valid, LINE))
set_dialog_item(handle, IDR_LINE, DAC_ENABLE);
else
set_dialog_item(handle, IDR_LINE, DAC_DISABLE);
if(and(style, LINE))
{
set_dialog_item(handle, IDR_LINE, DAC_CHECK);
set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_ENABLE);
}
else
{
set_dialog_item(handle, IDR_LINE, DAC_UNCHECK);
set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_DISABLE);
}
if(and(valid, BLOCK))
set_dialog_item(handle, IDR_BLOCK, DAC_ENABLE);
else
set_dialog_item(handle, IDR_BLOCK, DAC_DISABLE);
if(and(style, BLOCK))
set_dialog_item(handle, IDR_BLOCK, DAC_CHECK);
else
set_dialog_item(handle, IDR_BLOCK, DAC_UNCHECK);
}
local function tolower_keywords(type)
{
local array = Keyword(type), word, new_word, value;
set_busy_cursor();
for(word in array)
{
new_word = tolower(word);
if(word != new_word)
{
value = delete_keyword(type, word);
set_keyword(type, new_word, value);
}
}
set_normal_cursor();
}
local function save_syntax_part(type)
{
local word;
save_languages[type].esc_character = languages[type].esc_character;
save_languages[type].stile_delimiters = languages[type].stile_delimiters;
save_languages[type].sensitive = languages[type].sensitive;
for(word in languages[type].category)
save_languages[type].category[word] = languages[type].category[word];
for(word in languages[type].keyword)
save_languages[type].keyword[word] = languages[type].keyword[word];
for(word in languages[type].line)
save_languages[type].line[word] = languages[type].line[word];
for(word in languages[type].block)
save_languages[type].block[word] = languages[type].block[word];
}
################################################################################
#
# Advanced items
#
################################################################################
local IDC_IS_ESCAPABLE = 105;
local IDC_NONE = 104;
local IDE_MUST_START_IN_COLUMN = 101;
local IDC_MUST_START_IN_COLUMN = 102;
local advanced_save_value = FALSE;
local function initialize_advanced_dialog(handle, type, item)
{
nb_initializing = TRUE;
add_dialog_item(handle, IDC_NONE, DCTRL_CHECK_BOX);
add_dialog_item(handle, IDC_IS_ESCAPABLE, DCTRL_CHECK_BOX);
add_dialog_item(handle, IDC_MUST_START_IN_COLUMN, DCTRL_CHECK_BOX);
add_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DCTRL_SPINBUTTON);
set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_SPIN_LIMITS, 1, 255);
advanced_save_value = Line(type, item);
if(length(item) > 1)
{
set_dialog_item(handle, IDC_MUST_START_IN_COLUMN, DAC_DISABLE);
set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE);
}
if(Line(type, item, COLUMN_MASK))
{
set_dialog_item(handle, IDC_MUST_START_IN_COLUMN, DAC_CHECK);
set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_SPIN_VALUE,
Line(type, item, COLUMN_MASK)+0);
set_dialog_item(handle, IDC_NONE, DAC_UNCHECK);
}
else if(Line(type, item, FLAG_MASK))
{
set_dialog_item(handle, IDC_IS_ESCAPABLE, DAC_CHECK);
set_dialog_item(handle, IDC_NONE, DAC_UNCHECK);
set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE);
}
else
{
set_dialog_item(handle, IDC_NONE, DAC_CHECK);
set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE);
}
nb_initializing = FALSE;
}
global function advanced_items_callback()
{
local ret_msg = DRC_CONTINUE
local handle = callback_dialog_handle;
local value;
if(nb_initializing)
{
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_msg == DM_HELPREQUESTED)
{
display_help("advanced_items", handle);
# display_help(nbPagePrefix[current_nb_page].help, handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_msg == DM_CANCEL )
{
set_line(global_type, local_item, advanced_save_value);
ret_msg = DRC_EXIT;
}
else if ( callback_msg == DM_OK )
{
ret_msg = DRC_EXIT;
}
else if ( callback_msg == DM_SPIN_CHANGE )
{
# validate the value the user entered
value = query_dialog_item(handle, callback_index, DAC_SPIN_VALUE );
set_line(global_type, local_item, value, COLUMN_MASK);
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
{
if(callback_index == IDC_IS_ESCAPABLE)
{
set_line(global_type, local_item, 0x1, FLAG_MASK);
set_line(global_type, local_item, 0x0, COLUMN_MASK);
set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE);
}
else if(callback_index == IDC_MUST_START_IN_COLUMN)
{
set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_ENABLE);
value = query_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_SPIN_VALUE);
set_line(global_type, local_item, 0x0, FLAG_MASK);
set_line(global_type, local_item, value, COLUMN_MASK);
}
else if(callback_index == IDC_NONE)
{
set_line(global_type, local_item, 0x0, FLAG_MASK);
set_line(global_type, local_item, 0x0, COLUMN_MASK);
set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE);
}
}
return ret_msg
}
local function save_select_color_item(type)
{
local array, item;
delete mini_storage;
array = Keyword(type);
for(item in array)
{
mini_storage[item].foreground = get_current_color_of_item(type, item, 0, 0);
mini_storage[item].background = get_current_color_of_item(type, item, 1, 0);
}
array = Line(type);
for(item in array)
{
mini_storage[item].foreground = get_current_color_of_item(type, item, 0, 0);
mini_storage[item].background = get_current_color_of_item(type, item, 1, 0);
}
array = Block(type);
for(item in array)
{
mini_storage[item].foreground = get_current_color_of_item(type, item, 0, 0);
mini_storage[item].background = get_current_color_of_item(type, item, 1, 0);
}
}
local function save_select_color_category(type)
{
local array, catnum;
delete mini_storage;
array = Category(type);
for(catnum in array)
{
local_cat = catnum
mini_storage[array[catnum].name].foreground = get_current_color_of_item(type, array[catnum].name, 0, 1);
mini_storage[array[catnum].name].background = get_current_color_of_item(type, array[catnum].name, 1, 1);
}
}
local function unsave_select_color_both(type, iscat)
{
local array, catname;
for(catname in mini_storage)
{
save_styles[type][catname].foreground = mini_storage[catname].foreground;
save_styles[type][catname].background = mini_storage[catname].background;
if(iscat)
save_styles[type][catname].category = TRUE;
}
}
local valueset_selected = FALSE;
local function initialize_select_color(handle, type, iscat, text, catname)
{
local cat, col, row, color, DID_CANCEL = 2, fg, bg;
local array[]
nb_initializing = TRUE;
attach_help(editor_helpfile, handle);
add_dialog_item(handle, IDV_FOREGROUND, DCTRL_VALUESET);
add_dialog_item(handle, IDV_BACKGROUND, DCTRL_VALUESET);
add_dialog_item(handle, IDS_CATEGORY, DCTRL_STATIC_TEXT);
# set_dialog_item(handle, DID_CANCEL, DAC_DISABLE);
reset_colors(handle);
if(iscat)
set_dialog_item(handle, IDS_CATEGORY, DAC_TEXT, "Category");
else
set_dialog_item(handle, IDS_CATEGORY, DAC_TEXT, "Item");
if(local_add)
{
add_dialog_item(handle, IDL_ITEMS, DCTRL_EDIT);
if(catname)
{
fg = get_current_color_of_item(type, catname, 0, 1);
bg = get_current_color_of_item(type, catname, 1, 1);
select_color(handle, fg, bg);
}
}
else
{
add_dialog_item(handle, IDL_ITEMS, DCTRL_MULTI_LIST_BOX);
set_dialog_item(handle, IDL_ITEMS, DAC_SORT_ASCENDING);
set_dialog_item(handle, IDL_ITEMS, DAC_DELETE_ITEM);
if(iscat)
{
array = Category(type);
for(cat in array)
set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, array[cat].name "");
# set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, "All");
}
else
{
if ( catname == "All" )
init_items(handle, type);
else
init_items(handle, type, Value(type, text, CATEGORY_MASK));
}
if(!text)
set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_INDEX, 0);
else
{
set_dialog_item(handle, IDL_ITEMS, DAC_DESELECT_ITEM)
set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM, text);
}
}
valueset_selected = FALSE;
nb_initializing = FALSE;
}
global function create_item_callback()
{
local handle = callback_dialog_handle;
if(callback_msg == DM_HELPREQUESTED)
{
display_help("create_new_item", handle);
return DRC_MSG_PROCESSED;
}
else
return select_color_callback()
}
global function select_color_callback()
{
local ret_msg = DRC_CONTINUE, item, dbg, dfg, cat, value;
local custom_dlg, fgval, bgval, i;
local handle = callback_dialog_handle;
# if(nb_initializing)
# ret_msg = DRC_MSG_PROCESSED;
if(callback_msg == DM_HELPREQUESTED)
{
display_help("select_color", handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_msg == DM_CANCEL )
{
if(!local_add)
unsave_select_color_both(global_type, local_iscat);
ret_msg = DRC_EXIT;
}
else if ( callback_msg == DM_OK )
{
ret_msg = perform_ok( handle )
assign_cats = local_iscat;
do_done = (ret_msg == DRC_EXIT) && local_add;
# for ( i in save_styles[global_type] )
# {
# if ( save_styles[global_type][i].category &&
# (i in names_added) && names_added[i] )
# {
# add_syntax_category(global_type, -1, i,
# save_styles[global_type][i].foreground,
# save_styles[global_type][i].background);
# }
# else if( (i in names_added) && names_added[i] )
# {
# if(isValidKeyword(global_type, i))
# add_syntax_item(global_type, KEYWORD, i, local_cat, CATEGORY_MASK);
# else if(isValidLine(global_type, i))
# add_syntax_item(global_type, LINE, i, local_cat, CATEGORY_MASK);
# else if(isValidBlock(global_type, i))
# add_syntax_item(global_type, BLOCK, i, local_cat, CATEGORY_MASK);
# }
# }
# }
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
{
if(callback_index == IDB_CUSTOM)
{
local_fgind = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_SELECTED);
local_bgind = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_SELECTED);
custom_dlg = create_dialog( function_id("custom_color_callback"), handle, IDD_CONFIGURE_COLOR );
initialize_custom_dialog(custom_dlg, handle, local_fgind, local_bgind);
begin_dialog(custom_dlg);
reset_colors(handle);
set_select_text(handle);
# Save new colors of selected item;
if(!local_add)
{
dfg = query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK);
dbg = query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK);
saveItem(handle, global_type, dfg, dbg, local_add, local_iscat);
}
ret_msg = DRC_MSG_PROCESSED;
}
else if((callback_index == IDC_DEFAULT_FG) || (callback_index == IDC_DEFAULT_BG) )
{
set_select_text(handle);
dfg = query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK);
dbg = query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK);
if(!local_add)
saveItem(handle, global_type, dfg, dbg, local_add, local_iscat);
}
else if(callback_index == IDB_DEFAULT)
{
load_factory_syntax_colors();
reset_colors(handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_index == IDB_ADD_COMP)
{
perform_ok(handle)
# clear out edit field
set_dialog_item(handle, IDL_ITEMS, DAC_EDIT_TEXT, "" )
set_dialog_item(handle, IDL_ITEMS, DAC_SETFOCUS )
ret_msg = DRC_MSG_PROCESSED;
}
}
else if(callback_msg == DM_SELECT)
{
valueset_selected = FALSE;
item = query_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM);
if ( local_iscat )
local_cat = Category(global_type, item) + 0;
fgval = get_current_color_of_item(global_type, item, 0, local_iscat);
bgval = get_current_color_of_item(global_type, item, 1, local_iscat);
select_color(handle, fgval, bgval);
valueset_selected = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
else if(callback_msg == DM_VS_SELECT)
{
if(callback_index == IDV_FOREGROUND)
{
dbg = query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK);
if(!local_add && valueset_selected)
saveItem(handle, global_type, FALSE, dbg, local_add, local_iscat);
set_dialog_item(handle, IDC_DEFAULT_FG, DAC_UNCHECK);
# assign selected item the appropriate style;
}
else if(callback_index == IDV_BACKGROUND)
{
dfg = query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK);
if(!local_add && valueset_selected)
saveItem(handle, global_type, dfg, FALSE, local_add, local_iscat);
set_dialog_item(handle, IDC_DEFAULT_BG, DAC_UNCHECK);
}
set_select_text(handle);
valueset_selected = TRUE;
ret_msg = DRC_MSG_PROCESSED;
}
return ret_msg
}
local function do_done_processing()
{
local cat;
for ( cat in save_styles[global_type] )
{
if ( save_styles[global_type][cat].category &&
(cat in names_added) && names_added[cat] )
{
add_syntax_category(global_type, -1, cat,
save_styles[global_type][cat].foreground,
save_styles[global_type][cat].background);
}
else if( (cat in names_added) && names_added[cat] )
{
if(isValidKeyword(global_type, cat))
add_syntax_item(global_type, KEYWORD, cat, local_cat, CATEGORY_MASK);
else if(isValidLine(global_type, cat))
add_syntax_item(global_type, LINE, cat, local_cat, CATEGORY_MASK);
else if(isValidBlock(global_type, cat))
add_syntax_item(global_type, BLOCK, cat, local_cat, CATEGORY_MASK);
}
}
do_done = FALSE;
}
local function perform_ok( handle )
{
local item, dfg, dbg
local ret_msg = DRC_EXIT;
if(local_add)
{
dfg = query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK)
dbg = query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK)
if(local_iscat)
{
item = query_dialog_item(handle, IDL_ITEMS, DAC_EDIT_TEXT);
if(item != "" && !CategoryExist(global_type, item))
{
names_added[item] = 1;
saveItem(handle, global_type, dfg, dbg, local_add, local_iscat)
}
else if ( item != "" )
warning("Cannot add " item ". It already exists as a category.");
}
else
{
local_item = query_dialog_item(handle, IDL_ITEMS, DAC_EDIT_TEXT);
local_item = get_case_sensitive(global_type) ? local_item : tolower(local_item);
local_item = compress(local_item) # we need to remove any whitespace the user may have enter
local_item = ltrim(local_item) # (except for a single space in line/block styles)
local_item = trim(local_item)
if ( local_item != "" )
{
if(!isValidKeyword(global_type, local_item) &&
!isValidLine(global_type, local_item) &&
!isValidBlock(global_type, local_item))
{
warning("Not a valid item for highlighting.");
ret_msg = DRC_MSG_PROCESSED;
}
else
{
# If I saveItem now, cancel works, and I can set the
# category without creating a syntax style;
names_added[local_item] = 1;
saveItem(handle, global_type, dfg, dbg, local_add, local_iscat, local_item)
}
}
}
}
# else if(local_iscat)
# assign_category_colors(global_type);
return ret_msg
}
# Color passed in as BGR if 3 parms specified
local function select_color(handle, fg, bg)
{
local row, col, color_index;
# The if structure is implemented this way because the default check
# boxes need to be set first. If they are not, an incorrect color is
# saved during the initialization of the select color dialog;
if(fg < 0)
set_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK);
if(bg < 0)
set_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK);
if(fg >= 0)
{
set_dialog_item(handle, IDC_DEFAULT_FG, DAC_UNCHECK);
color_index = get_color_index(fg, 0);
if(color_index)
{
row = and(color_index, 0xf);
col = shiftr(and(color_index, 0xf0000), 16);
set_dialog_item(handle, IDV_FOREGROUND, DAC_VS_SELECT_ITEM, row, col);
}
else
set_dialog_item(handle, IDV_FOREGROUND, DAC_VS_SELECT_ITEM, 1, 1);
}
if(bg >= 0)
{
set_dialog_item(handle, IDC_DEFAULT_BG, DAC_UNCHECK);
color_index = get_color_index(bg, 1);
if(color_index)
{
row = and(color_index, 0xf);
col = shiftr(and(color_index, 0xf0000), 16);
set_dialog_item(handle, IDV_BACKGROUND, DAC_VS_SELECT_ITEM, row, col);
}
else
set_dialog_item(handle, IDV_BACKGROUND, DAC_VS_SELECT_ITEM, 1, 1);
}
set_select_text(handle, fg, bg);
}
local function set_select_text(handle, fg, bg)
{
if(argcount() < 3)
{
if(query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK))
fg = -1;
else
{
fg = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_SELECTED);
fg = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_ITEM, fg);
}
if(query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK))
bg = -1;
else
{
bg = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_SELECTED);
bg = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_ITEM, bg);
}
}
fg = (fg < 0) ? default_color_window_fg : fg;
bg = (bg < 0) ? default_color_window_bg : bg;
set_dialog_item(handle, IDS_CATEGORY, DAC_FG_COLOR, fg);
set_dialog_item(handle, IDS_CATEGORY, DAC_BG_COLOR, bg);
}
###############################################################################
#
# Custom color dialog section
#
################################################################################
local IDS_FG_RED = 119;
local IDS_FG_GREEN = 103;
local IDS_FG_BLUE = 104;
local IDS_BG_RED = 112;
local IDS_BG_GREEN = 113;
local IDS_BG_BLUE = 114;
local IDV_FG = 106;
local IDV_BG = 110;
local IDT_SAMPLE_TEXT = 116;
local function initialize_custom_dialog(handle, col_handle, fgind, bgind)
{
local fg, bg, value;
attach_help(editor_helpfile, handle);
set_dialog_item( handle, IDS_FG_RED, DAC_SPIN_LIMITS, 0, 255 );
set_dialog_item( handle, IDS_FG_GREEN, DAC_SPIN_LIMITS, 0, 255 );
set_dialog_item( handle, IDS_FG_BLUE, DAC_SPIN_LIMITS, 0, 255 );
set_dialog_item( handle, IDS_BG_RED, DAC_SPIN_LIMITS, 0, 255 );
set_dialog_item( handle, IDS_BG_GREEN, DAC_SPIN_LIMITS, 0, 255 );
set_dialog_item( handle, IDS_BG_BLUE, DAC_SPIN_LIMITS, 0, 255 );
fg = query_dialog_item(col_handle, IDV_FOREGROUND, DAC_VS_QUERY_ITEM, fgind);
bg = query_dialog_item(col_handle, IDV_BACKGROUND, DAC_VS_QUERY_ITEM, bgind);
set_dialog_item(handle, IDV_FG, DAC_VS_SET_ITEM, 1, 1, fg);
set_dialog_item(handle, IDV_BG, DAC_VS_SET_ITEM, 1, 1, bg);
value = and(fg, 0xff);
set_dialog_item(handle, IDS_FG_BLUE, DAC_SPIN_VALUE, value);
value = and(shiftr(fg, 8), 0xff);
set_dialog_item(handle, IDS_FG_GREEN, DAC_SPIN_VALUE, value);
value = and(shiftr(fg, 16), 0xff);
set_dialog_item(handle, IDS_FG_RED, DAC_SPIN_VALUE, value);
value = and(bg, 0xff);
set_dialog_item(handle, IDS_BG_BLUE, DAC_SPIN_VALUE, value);
value = and(shiftr(bg, 8), 0xff);
set_dialog_item(handle, IDS_BG_GREEN, DAC_SPIN_VALUE, value);
value = and(shiftr(bg, 16), 0xff);
set_dialog_item(handle, IDS_BG_RED, DAC_SPIN_VALUE, value);
}
global function custom_color_callback()
{
local ret_msg = DRC_CONTINUE
local handle = callback_dialog_handle;
local value;
if(callback_msg == DM_HELPREQUESTED)
{
display_help("customcolor", handle);
ret_msg = DRC_MSG_PROCESSED;
}
else if ( callback_msg == DM_OK )
{
syntax_colors_fg[local_fgind] = read_color(handle, 0);
syntax_colors_bg[local_bgind] = read_color(handle, 1);
ret_msg = DRC_EXIT;
}
else if(callback_msg == DM_CANCEL)
{
ret_msg = DRC_EXIT;
}
else if ( callback_msg == DM_SPIN_CHANGE )
{
# validate the value the user entered
query_dialog_item(handle, callback_index, DAC_SPIN_VALUE );
if((callback_index == IDS_FG_RED) || (callback_index == IDS_FG_GREEN) || (callback_index == IDS_FG_BLUE) )
{
value = read_color(handle, 0);
set_dialog_item(handle, IDV_FG, DAC_VS_SET_ITEM, 1, 1, value);
set_dialog_item(handle, IDT_SAMPLE_TEXT, DAC_FG_COLOR, value);
}
else if((callback_index == IDS_BG_RED) || (callback_index == IDS_BG_GREEN) || (callback_index == IDS_BG_BLUE) )
{
value = read_color(handle, 1);
set_dialog_item(handle, IDV_BG, DAC_VS_SET_ITEM, 1, 1, value);
set_dialog_item(handle, IDT_SAMPLE_TEXT, DAC_BG_COLOR, value);
}
}
return ret_msg
}
local function reset_colors(handle)
{
local color_index, col, row;
for(color_index in syntax_colors_fg)
{
row = and(color_index, 0xf);
col = shiftr(and(color_index, 0xf0000), 16);
set_dialog_item(handle, IDV_FOREGROUND, DAC_VS_SET_ITEM, row, col, syntax_colors_fg[color_index]+0 );
}
for(color_index in syntax_colors_bg)
{
row = and(color_index, 0xf);
col = shiftr(and(color_index, 0xf0000), 16);
set_dialog_item(handle, IDV_BACKGROUND, DAC_VS_SET_ITEM, row, col, syntax_colors_bg[color_index]+0 );
}
}
local function get_color_index(color, isbg)
{
local result, ind;
if(isbg)
{
for(ind in syntax_colors_bg)
{
if(color == syntax_colors_bg[ind])
{
result = ind;
break;
}
}
}
else
{
for(ind in syntax_colors_fg)
{
if(color == syntax_colors_fg[ind])
{
result = ind;
break;
}
}
}
return result;
}
local function read_color(handle, bg)
{
local value;
if(bg)
{
value = query_dialog_item(handle, IDS_BG_RED, DAC_SPIN_VALUE)+0;
value = shiftl(value, 8);
value = or(query_dialog_item(handle, IDS_BG_GREEN, DAC_SPIN_VALUE)+0, value);
value = shiftl(value, 8);
value = or(query_dialog_item(handle, IDS_BG_BLUE, DAC_SPIN_VALUE)+0, value);
}
else
{
value = query_dialog_item(handle, IDS_FG_RED, DAC_SPIN_VALUE)+0;
value = shiftl(value, 8);
value = or(query_dialog_item(handle, IDS_FG_GREEN, DAC_SPIN_VALUE)+0, value);
value = shiftl(value, 8);
value = or(query_dialog_item(handle, IDS_FG_BLUE, DAC_SPIN_VALUE)+0, value);
}
return value;
}