home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
NOTEBOOK.PEL
< prev
next >
Wrap
Text File
|
1995-03-20
|
16KB
|
530 lines
# $Header: P:\source\wmacros\notebook.pev 1.54 20 Mar 1995 10:29:34 PFHJXM0 $
##############################################################################
#
# 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: notebook.pel $: tags support
## notebook manager functions and variables available to the user
#
# nbhand create_notebook_template(callback_id, parent, label, x0, y0, width, height)
#
# void delete_notebook(nbhand)
#
# void begin_notebook(nbhand)
#
# void set_notebook_major_tab_size(nbhand, width, height)
#
# void set_notebook_minor_tab_size(nbhand, width, height)
#
# void set_notebook_page_button_size(nbhand, width, height)
#
# void set_notebook_binder_type(nbhand, bindertype)
#
# void set_notebook_tab_type(nbhand, tabtype)
#
# void set_notebook_tab_location(nbhand, tabloc)
#
# void set_notebook_tab_alignment(nbhand, tabalign)
#
# void set_notebook_status_alignment(nbhand, statalign)
#
# void set_notebook_backpage_intersection(nbhand, backpos)
#
# int count_notebook_pages(nbhand)
#
# hPage append_notebook_page(nbhand, dlghand, stat_text,
# tab_text, tab_type, resize)
#
# hPage insert_notebook_page_at_top(nbhand, dlghand, stat_text,
# tab_text, tab_type, resize)
#
# hPage insert_notebook_page_before(nbhand, before_page, dlghand,
# stat_text, tab_text, tab_type, resize)
#
# hPage insert_notebook_page_after(nbhand, after_page, dlghand,
# stat_text, tab_text, tab_type, resize)
#
# void delete_notebook_page(nbhand, pagehand)
#
# void turnto_notebook_page(nbhand, pagehand)
#
# long set_notebook_page_dialog(nbhand, pagehand, dlghand)
#
# long get_notebook_page_dialog(nbhand, pagehand)
#
# void set_notebook_page_tab_text(nbhand, pagehand, text)
#
# void set_notebook_page_stat_text(nbhand, pagehand, text)
#
# dlghand create_page_template(x0, y0, width, height)
#
# void delete_page_template(dlghand)
#
#
#
# Constants
#
global NBTAB_NONE = 0
global NBTAB_MINOR = 1
global NBTAB_MAJOR = 2
global NB_NO_RESIZE = 0
global NB_RESIZE = 1
global NB_BINDER_SOLID = 0
global NB_BINDER_SPIRAL = 1
global NB_ALIGN_LEFT = 0
global NB_ALIGN_CENTER = 1
global NB_ALIGN_RIGHT = 2
global NBTAB_SQUARE = 0
global NBTAB_ROUNDED = 1
global NBTAB_POLYGON = 2
global NBTAB_LEFT = 0
global NBTAB_RIGHT = 1
global NBTAB_TOP = 2
global NBTAB_BOTTOM = 3
global NB_BACK_BR = 0
global NB_BACK_BL = 1
global NB_BACK_TR = 2
global NB_BACK_TL = 3
global MAJOR_TAB_WIDTH = 78
global MAJOR_TAB_HEIGHT = 28
global MINOR_TAB_WIDTH = 128
global MINOR_TAB_HEIGHT = 30
global comp_buff = FALSE; # flag to compile language.pel when buffer pages are exposed
#global DRC_EXIT = 0
#global DRC_CONTINUE = 1
local assign_changes = FALSE;
local dialog_return_value = 0
local nhSettingsNotebook = 0
global current_nb_page;
global last_nb_page_name = "edithelp";
global nbPagePrefix; # Prefix to functions called by the dynamic
# page creater; indexed by page id;
# Signals that pages are creating themselves in all notebooks
global nb_initializing = TRUE
global function settings_notebook()
{
local tempid = 0, temp_name, pageid, old_level = message_level;
if ( nhSettingsNotebook )
{
# Notebook is already active from another detached window
nb_initializing = FALSE;
set_dialog_window( nhSettingsNotebook, DWC_SHOW )
}
else
{
set_busy_cursor();
nb_initializing = TRUE;
create_settings_notebook();
optional_function("editor_settings_notebook", nhSettingsNotebook);
optional_function("window_settings_notebook", nhSettingsNotebook);
optional_function("extension_settings_notebook", nhSettingsNotebook);
optional_function("buffer_settings_notebook", nhSettingsNotebook);
optional_function("file_settings_notebook", nhSettingsNotebook);
if ( status_bar_flags )
message( "" );
set_normal_cursor();
# Find the pageid for the last exposed page in the notebook;
for(pageid in nbPagePrefix)
{
temp_name = nbPagePrefix[pageid].name;
if(temp_name == last_nb_page_name)
{
tempid = pageid;
break;
}
else if(!tempid && (substr(temp_name, length(temp_name)-3) == "help"))
{
tempid = pageid;
}
}
pageid = tempid;
last_nb_page_name = nbPagePrefix[pageid].name;
# Create the page and turn to it;
optional_function("create_" last_nb_page_name "_page", pageid, nhSettingsNotebook);
turnto_notebook_page(nhSettingsNotebook, pageid);
# Begin viewing notebook;
begin_notebook(nhSettingsNotebook);
# let exposes get handled before
# we do time-consuming processing
idle()
set_busy_cursor();
message_level = 1;
if(assign_changes)
{
assign_notebook_changes(nhSettingsNotebook);
}
apply_to_all(); # apply settings globally if appropriate
set_normal_cursor();
delete_notebook(nhSettingsNotebook);
set_busy_cursor();
# Restore the message_level if it was not set by the user;
for(pageid in nbPagePrefix)
{
if( (nbPagePrefix[pageid].name == "stb2") &&
(!nbPagePrefix[pageid].modified || !assign_changes) )
{
message_level = old_level;
break;
}
}
delete nbPagePrefix;
delete nb_apply_to_all;
nhSettingsNotebook = 0;
notify("Reseting notebook variables.");
optional_function("reset_editor_settings_notebook");
optional_function("reset_extension_settings_notebook");
optional_function("reset_window_settings_notebook");
optional_function("reset_buffer_settings_notebook");
optional_function("reset_file_settings_notebook");
assign_changes = FALSE;
set_normal_cursor();
display_redraw();
message("")
}
}
global function create_settings_notebook()
{
if ( status_bar_flags )
message( "Creating Settings Notebook..." )
nhSettingsNotebook = create_notebook_template(function_id( "settings_notebook_callback" ),
0, "Settings")
set_notebook_major_tab_size(nhSettingsNotebook, MAJOR_TAB_WIDTH, MAJOR_TAB_HEIGHT)
set_notebook_minor_tab_size(nhSettingsNotebook, MINOR_TAB_WIDTH, MINOR_TAB_HEIGHT)
# set_notebook_tab_type(nhSettingsNotebook, NBTAB_SQUARE)
attach_help(editor_helpfile, nhSettingsNotebook)
}
global function settings_notebook_callback()
{
local set, fid, return_msg = DRC_CONTINUE, dlgid = 0;
local name, helppage;
local ask, page;
if ( callback_msg == DM_CLOSE )
{
# User double clicked on the system icon;
ask = comp_buff;
if(!ask)
{
for(page in nbPagePrefix)
{
ask = nbPagePrefix[page].modified;
if(ask)
break;
}
}
if(!ask)
{
for(page in languages)
{
ask = Modified(page);
if(ask)
break;
}
}
nb_initializing = TRUE;
if(ask)
{
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
set = confirm("Do you want to save your settings changes? (Y/N):", "YyNn");
restore_status_bar();
if(tolower(set) == "y")
assign_changes = TRUE;
else if(tolower(set) == "n")
{
optional_function("undo_cursor_settings", "all");
optional_function("undo_extension_section_settings");
}
else
return_msg = DRC_MSG_PROCESSED
}
}
else if ( callback_msg == DM_CANCEL )
{
# User pressed the CANCEL button;
nb_initializing = TRUE;
optional_function("undo_cursor_settings", "all");
optional_function("undo_extension_section_settings");
}
else if((callback_msg == DM_PAGECHANGED) && !nb_initializing)
{
# Save the page id and the name for access from other areas,
# and next time notebook is opened;
set_busy_cursor()
current_nb_page = callback_data;
last_nb_page_name = nbPagePrefix[current_nb_page].name;
if(!nbPagePrefix[current_nb_page].dialog_handle)
{
# name = nbPagePrefix[current_nb_page].name;
execute_function(function_id("create_" last_nb_page_name "_page", current_nb_page, nhSettingsNotebook));
}
else
{
execute_function(function_id("initialize_" last_nb_page_name "_settings",
nbPagePrefix[current_nb_page].dialog_handle,
global_type));
}
set_normal_cursor()
}
else if ( ( callback_msg == DM_CLICK && callback_index == DI_HELP ) ||
( callback_msg == DM_HELPREQUESTED ) )
{
helppage = nbPagePrefix[current_nb_page].help;
if(helppage == "")
helppage = "settings"
display_help(helppage, callback_dialog_handle);
return_msg = DRC_MSG_PROCESSED
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
{
if(callback_index == DI_OK)
{
assign_changes = TRUE;
nb_initializing = TRUE;
}
else if(callback_index == DI_CANCEL)
{
# How does the user get here?;
dialog_return_value = "";
nb_initializing = TRUE;
optional_function("undo_cursor_settings", "all");
optional_function("undo_extension_section_settings");
}
}
else if(callback_msg == DM_OK)
{
# User pressed CLOSE button;
assign_changes = TRUE;
nb_initializing = TRUE;
}
return return_msg;
}
local function assign_notebook_changes(nbHand)
{
local page, name, dlgid;
local old_sb_flags;
local apply = FALSE, asked = FALSE;
# Syntax page assignments must be made before language.pel is written.
notify("Assigning syntax changes.");
for(page in nbPagePrefix)
{
if((nbPagePrefix[page].name == "syntax") && nbPagePrefix[page].dialog_handle)
{
optional_function("assign_syntax_changes");
break;
}
}
for(page in nbPagePrefix)
{
dlgid = nbPagePrefix[page].dialog_handle;
if(dlgid)
{
name = nbPagePrefix[page].name;
if((name == "buffer1") || (name == "buffer2") || (name == "buffer3"))
{
execute_function(function_id("assign_" name "_changes", dlgid));
if(comp_buff)
apply = TRUE;
if(!language_compiled && comp_buff)
{
old_sb_flags = status_bar_flags
status_bar_flags = or(status_bar_flags, STB_MESSAGES)
notify("Compiling settings changes")
status_bar_flags = old_sb_flags
write_language_data();
notify("")
}
}
else if((name == "ext") || (name == "compiler") || (name == "template") || (name == "syntax"))
{
apply = TRUE;
if(!language_compiled)
{
old_sb_flags = status_bar_flags
status_bar_flags = or(status_bar_flags, STB_MESSAGES)
notify("Compiling settings changes")
status_bar_flags = old_sb_flags
write_language_data();
notify("")
}
}
else
{
execute_function(function_id("assign_" name "_changes", dlgid));
}
}
}
if(apply)
apply_type_changes();
}
global function apply_type_changes()
{
local cur_buf = 0
local start_buf = current_buffer
local first_buf = current_buffer
local set_bits, save;
local type;
local MASK = BUFFER_OVERTYPE_MODE +
BUFFER_EXPAND_TABS +
BUFFER_TABS_TO_SPACES +
BUFFER_REAL_SPACE_ONLY +
BUFFER_SNAP_TO_EOL +
BUFFER_WP_ENABLED +
BUFFER_WP_CARRY_COMMENTS +
BUFFER_WP_WRAP_CONTINUOUS
# BUFFER_READ_ONLY +
# Apply to all buffers.
# This gets a little complex. We need to set the bits that
# are set, and unset all of the bits that are not set
delete_event(EVENT.NEW_CURNT_BUFFER, "syntax_new_buffer")
notify("Assigning type changes to all buffers.");
if (!(and(buffer_flags, BUFFER_SYSTEM)))
{
next_buffer("", 0, 1); # go to a non-system buffer
first_buf = current_buffer;
}
do
{
type = Type(path_ext(buffer_filename));
type = (type ? type : DEFAULT);
if(languages_id != type)
languages_id = (type == DEFAULT) ? "" : type;
if((current_buffer == start_buf) && (Modified(CURRENT_BUFFER)))
type = CURRENT_BUFFER;
# # Save the bits that are curently set and we don't change;
# save = and(buffer_flags, not(flags));
#
# # Get the bits that are set and we do change;
# set_bits = and(BufferFlags(type), flags);
#
# # Add the old unchanged bits to the new changed bits;
# buffer_flags = or(save, set_bits);
# Why isn't set_flag_bits used here???
buffer_flags = set_flag_bits(buffer_flags, MASK, BufferFlags(type));
buffer_tabs = Tabs(type);
wp_left_margin = LeftMargin(type);
wp_right_margin = RightMargin(type);
auto_indent_mode = AutoIndent(type);
set_word_mode(get_word_mode(type));
case_insensitive = !get_case_sensitive(type);
style_delimiter = StyleDelimiters(type);
escape_character = EscapeCharacter(type);
syntax_highlight = Syntax(type);
} while( (cur_buf = next_buffer("", 0, 1)) != first_buf )
attach_event_handler(EVENT.NEW_CURNT_BUFFER, "syntax_new_buffer")
current_buffer = start_buf
}
local oldIndex;
global function enable_undo( handle, ind )
{
if ( !nb_initializing && (ind > 0) && (callback_msg != DM_HELPREQUESTED) &&
(callback_msg != DM_SET_FOCUS) && (callback_msg != DM_KILL_FOCUS) &&
(ind != DI_HELP) && (ind != IDB_UNDO) )
{
set_dialog_item( handle, IDB_UNDO, DAC_ENABLE)
oldIndex = ind
}
}
local nb_apply_to_all[]
global function apply_page_to_all( page, func_id )
{
nb_apply_to_all[ page ] = func_id
}
global function apply_to_all()
{
local page = 0
local cw = current_window
local cb = current_buffer
for ( page in nb_apply_to_all )
{
current_buffer = cb
current_window = cw
if ( nb_apply_to_all[ page ] )
execute_function( nb_apply_to_all[ page ] )
}
}
global function deselect_checks(dlgid)
{
set_dialog_item(dlgid, IDC_MAKE_DEFAULT, DAC_UNCHECK);
set_dialog_item(dlgid, IDC_APPLY_TO_ALL, DAC_UNCHECK);
}