home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
pr2grp.zip
/
group.pel
< prev
next >
Wrap
Text File
|
1995-08-06
|
13KB
|
381 lines
##############################################################################
##
## 2Rud Software
##
## This source code listing contains information that is
## has been written by 2Rud Software and may 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 2Rud Software
##
# Usage:
# 1) Add this file to the wpel.rsp
# 2) Run the PEL compiler
# 3) *I* suggest put putting a key-binding on ALT-G to open_group
# and another on ALT-A for add_file_to_group
# 4) Add Groups and add files to groups
#
##############################################################################
# dialog IDs
local GroupDlg = 0
local IDD_GROUP_DLG = 100
local IDLB_GROUP = 101
local IDLB_FILENAME = 102
local IDPB_ADD = 103
local IDPB_DELETE = 104
local IDRB_GROUP = 105
local IDRB_FILE = 106
local IDPB_SET = 107
local IDST_CURRENT = 108
#variables
local user_dll = "USER"
local GroupBufferID;
local current_group="";
local selected_group="";
local File_Checked=FALSE;
local Group_Checked=TRUE;
local filename_array[]
local num_files_in_group
local lastPath="*.*"
# create a buffer for the group information
function init_group()
{
GroupBufferID=create_buffer("group_buffer","group.dat",BUFFER_SYSTEM+BUFFER_NO_UNDO+BUFFER_REAL_SPACE_ONLY);
}
# shows the Group dialog box
function open_group()
{
local orig_buffer = current_buffer;
if (GroupBufferID==0)
{
init_group();
}
current_buffer = GroupBufferID;
GroupDlg = create_dialog(function_id("group_dlg_callback"), 0,
IDD_GROUP_DLG, user_dll );
begin_dialog(GroupDlg);
delete_dialog(GroupDlg);
current_buffer = orig_buffer;
}
# callback function for the Group dialog box
# handles all the events that are generated by it
function group_dlg_callback()
{
local new_group
local group
local filename
local old_winid
local next_winid
local winid_array[]
local i
local resp
local id
local search_str
local selected_filename
local listOfFiles
local arrayOfFiles
local fileToAdd
# initialization
if ( callback_msg == DM_INIT )
{
# check the group radio button
set_dialog_item(GroupDlg, IDRB_GROUP, DAC_CHECK);
# get all the group names and put them in the Group listbox
goto_buffer_top();
while (search("$$$",SEARCH_FORWARD+SEARCH_ADVANCE))
{
group = ltrim( trim(read_buffer()),"$$$" )
set_dialog_item(GroupDlg, IDLB_GROUP, DAC_ADD_ITEM, group);
Group_Checked=TRUE;
}
# select the first item in the group
set_dialog_item(GroupDlg, IDLB_GROUP, DAC_SELECT_INDEX,0);
# set the current group static text
set_dialog_item(GroupDlg, IDST_CURRENT, DAC_TEXT,current_group);
return DRC_MSG_PROCESSED
}
# if OPEN pushbutton pressed
if ( callback_msg == DM_OK )
{
current_group=selected_group
# make sure any changes are reflected
write_buffer()
#get an array of window ids for the current opened buffers
old_winid=current_window
i=1
winid_array[i]=current_window
next_winid=next_window("",1);
i++
while (old_winid != next_winid)
{
winid_array[i]=next_winid
next_winid=next_window("",1);
i++
}
#delete the current window/buffers
for (id in winid_array)
{
assign_current_window(winid_array[id])
delete_window_and_buffer()
}
# now open the files in the selected group
for (i in filename_array)
{
add_prompt_history("EDITFILE", filename_array[i])
create_buf_and_win(filename_array[i])
}
return DRC_EXIT
}
# a group in the listbox is selected
if ( callback_msg == DM_SELECT && callback_index == IDLB_GROUP )
{
goto_buffer_top();
# clear out file listbox
set_dialog_item(GroupDlg, IDLB_FILENAME, DAC_DELETE_INDEX);
# clear out filename array
for (i in filename_array)
{
filename_array[i]=""
}
# search for the selected group in the Group buffer
selected_group=query_dialog_item(GroupDlg, IDLB_GROUP, DAC_SELECT_ITEM);
num_files_in_group=0
search_str="\\$\\$\\$<"selected_group">";
search(search_str,SEARCH_FWD_REGEX_MAX);
# for all the files in the group put them in the filename array
# and in the filename listbox
if(down(1))
{
num_files_in_group=1
filename= ltrim( trim(read_buffer()) )
while (substr(filename,1,3) != "$$$")
{
# make sure there is a filename there
if (filename!="" && (length(filename) > 1) )
{
# add the filename to the filename array so we don't
# have to scan the buffer if OPEN is pressed
filename_array[num_files_in_group]=filename
num_files_in_group++
set_dialog_item(GroupDlg, IDLB_FILENAME, DAC_ADD_ITEM, filename);
}
if ( !down(1) )
break
filename = ltrim( trim(read_buffer()) )
}
}
return DRC_MSG_PROCESSED
}
# DELETE pushbutton pressed
if ( callback_msg == DM_CLICK && callback_index == IDPB_DELETE )
{
# if they want to delete a file
if (File_Checked==TRUE)
{
# find the group
goto_buffer_top()
selected_group=query_dialog_item(GroupDlg, IDLB_GROUP, DAC_SELECT_ITEM);
selected_filename=query_dialog_item(GroupDlg, IDLB_FILENAME, DAC_SELECT_ITEM);
search_str="\\$\\$\\$<"selected_group">";
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
# make sure they really want to do this
resp = toupper( confirm(
"Are you sure you want to delete " selected_filename"? [yn]? ",
"YyNn" ))
restore_status_bar();
if ( resp == "Y" )
{
# make sure the group exists
if(!search(search_str,SEARCH_FWD_REGEX_MAX))
{
error("Group not found!")
}
else
{
# find the filename
search_str="<"selected_filename">";
# do magical regex things with the backslash!
gsub("\\\\", "\\\\", search_str)
if(search(search_str,SEARCH_FWD_REGEX_MAX))
{
# delete the line containing the filename (buffer and listbox)
delete_line()
set_dialog_item(GroupDlg, IDLB_FILENAME, DAC_DELETE_ITEM,selected_filename);
}
else
{
error("Filename not found!")
}
}
}
}
# Group is checked; delete the group and associated filenames
else
{
selected_group=query_dialog_item(GroupDlg, IDLB_GROUP, DAC_SELECT_ITEM);
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
# make sure they really want to do this
resp = toupper( confirm(
"Are you sure you want to delete the Group - " selected_group"? [yn]? ",
"YyNn" ))
restore_status_bar();
if ( resp == "Y" )
{
set_dialog_item(GroupDlg, IDLB_GROUP, DAC_DELETE_ITEM,selected_group);
goto_buffer_top()
search_str="\\$\\$\\$<"selected_group">";
# find the group in the group buffer
if(search(search_str,SEARCH_FWD_REGEX_MAX))
{
# group is found - delete the line
delete_line()
# now delete all the filenames in the group
filename= ltrim( trim(read_buffer()) )
# stop when you get to the next group of a blank line (or eof)
while (substr(filename,1,3) != "$$$" && (length(filename)) > 1)
{
# make sure there is a filename there
if (filename!="" && (length(filename) > 1) )
{
set_dialog_item(GroupDlg, IDLB_FILENAME, DAC_DELETE_ITEM,filename);
delete_line()
}
#now read the next line
filename = ltrim( trim(read_buffer()) )
}
}
else
{
error("Group not found!")
}
}
}
return DRC_MSG_PROCESSED
}
# if SET pushbutton pressed
if ( callback_msg == DM_CLICK && callback_index == IDPB_SET )
{
current_group=selected_group
write_buffer()
return DRC_EXIT
}
# if CANCEL pushbutton pressed
if ( callback_msg == DM_CANCEL )
{
delete_buffer();
GroupBufferID=0;
return DRC_EXIT
}
# if they select the FILE radio button
if ( callback_msg == DM_CLICK && callback_index == IDRB_FILE )
{
File_Checked=TRUE;
Group_Checked=FALSE;
return DRC_MSG_PROCESSED
}
# selected the GROUP radio button
if ( callback_msg == DM_CLICK && callback_index == IDRB_GROUP )
{
File_Checked=FALSE;
Group_Checked=TRUE;
return DRC_MSG_PROCESSED
}
# ADD pushbutton pressed with GROUP radio button selected
if ( callback_msg == DM_CLICK && callback_index == IDPB_ADD && Group_Checked==TRUE )
{
# get the new group name from the user
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
new_group = prompt_history("GROUP", "Enter new Group :");
restore_status_bar();
# add the new group name to the listbox and buffer
set_dialog_item(GroupDlg, IDLB_GROUP, DAC_ADD_ITEM, new_group);
goto_buffer_bottom();
goto_eol();
insert_string("\n%s%s\n","$$$",new_group)
return DRC_MSG_PROCESSED
}
# ADD pushbutton pressed with FILENAME radio button selected
if ( callback_msg == DM_CLICK && callback_index == IDPB_ADD && File_Checked==TRUE )
{
# show the open dialog
listOfFiles = open_dialog( lastPath, "Add a file to a Group", 0, "" )
if ( listOfFiles )
{
# parse out the files and flags. Flags are always the first
# element in the list.
split(listOfFiles, arrayOfFiles, ";")
for(i in arrayOfFiles)
{
if ( i != 1 )
{
fileToAdd = arrayOfFiles[i]
# add it to the buffer
goto_buffer_top();
search("\\$\\$\\$<"selected_group">",SEARCH_FWD_REGEX_MAX);
goto_eol()
insert_string("\n%s",fileToAdd);
# add it to the listbox
set_dialog_item(GroupDlg, IDLB_FILENAME, DAC_ADD_ITEM, fileToAdd);
filename_array[num_files_in_group]=fileToAdd
num_files_in_group++
}
}
lastPath = path_path(fileToAdd) "*.*"
}
return DRC_MSG_PROCESSED
}
return DRC_MSG_PROCESSED
}
# adds the current buffer filename to the current group
function add_file_to_group()
{
local orig_buffer = current_buffer;
local orig_buffer_name =buffer_filename;
local resp;
if (GroupBufferID==0)
{
init_group();
}
if (current_group =="")
{
error("Current group not defined!")
}
else
{
current_buffer = GroupBufferID;
set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
resp = toupper( confirm(
"Add " orig_buffer_name " to group " current_group " [yn]? ",
"YyNn" ))
restore_status_bar();
if ( resp == "Y" )
{
goto_buffer_top();
search("\\$\\$\\$<"current_group">",SEARCH_FWD_REGEX_MAX);
goto_eol()
insert_string("\n%s",orig_buffer_name);
write_buffer();
}
current_buffer = orig_buffer;
}
}