📄 filechooserwinc.c
字号:
/* * $Id: FileChooserWinC.C,v 1.3 2000/07/24 11:39:52 evgeny Exp $ * * Copyright (c) 1993 HAL Computer Systems International, Ltd. * * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. * 1315 Dell Avenue * Campbell, CA 95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <config.h>#include "FileChooserWinC.h"#include "FileMisc.h"#include "ShellExp.h"#include "IshAppC.h"#include "AppPrefC.h"#include "ImapServerC.h"#include "ImapMisc.h"#include "FolderPrefC.h"#include <hgl/WArgList.h>#include <hgl/HalAppC.h>#include <hgl/WXmString.h>#include <hgl/rsrc.h>#include <hgl/RegexC.h>#include <hgl/TextMisc.h>#include <hgl/CharC.h>#include <Xm/PanedW.h>#include <Xm/Form.h>#include <Xm/Label.h>#include <Xm/TextF.h>#include <Xm/List.h>#include <Xm/PushB.h>#include <Xm/ToggleB.h>#include <Xm/Text.h>#include <Xm/ScrolledW.h>#include <Xm/Separator.h>#include <sys/stat.h>#include <dirent.h>#include <unistd.h>XtActionsRec FileChooserWinC::actions[1] = { "FileChooserWinC-activate", (XtActionProc)FileChooserWinC::HandleActivate,};/*--------------------------------------------------------------- * Function to convert shell wildcard patterns into regex wildcard patterns */static StringCShellToRegex(StringC str){//// Look at each character in string// unsigned count = str.size(); int i=0; for (i=0; i<count; i++) { char c = str[i]; if ( c == '*' ) { if ( i == 0 || str[i-1] != '\\' ) { str(i,0) = "."; count++; i++; } } else if ( c == '?' ) { if ( i == 0 || str[i-1] != '\\' ) { str(i,1) = "."; } } else if ( c == '.' ) { str(i,0) = "\\"; count++; i++; } } str += "$"; return str;} // End ShellToRegex/*----------------------------------------------------------------------- * FileChooserWinC constructor */FileChooserWinC::FileChooserWinC(Widget parent, char* name, ArgList argv, Cardinal argc) : HalDialogC(name, parent, argv, argc){ WArgList args; Widget wlist[4]; char *cl = "FileChooserC"; localTextChange = False; listVisible = False; lastTimeListed = 0; defaultDir = ""; showImap = get_boolean(cl, *this, "showImapField", ishApp->appPrefs->usingImap); subdirNames.AllowDuplicates(FALSE); subdirNames.SetSorted(FALSE); fileNames.AllowDuplicates(FALSE); fileNames.SetSorted(FALSE); filtNames.AllowDuplicates(FALSE); filtNames.SetSorted(FALSE); selectNames.AllowDuplicates(FALSE); selectNames.SetSorted(TRUE); selectNames.AutoShrink(FALSE);//// Create the appForm children//// appForm// PanedWindow panedWin// args.Reset(); args.MarginHeight(0); args.MarginWidth(0); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); panedWin = XmCreatePanedWindow(appForm, "FileChooserC", ARGS);//// Create the panedWin children//// panedWin// Form selectForm// Form listForm// args.Reset(); args.AllowResize(True); selectForm = XmCreateForm(panedWin, "selectForm", ARGS); listForm = XmCreateForm(panedWin, "listForm", ARGS);//// Create the selectForm children//// selectForm// Label selectLabel// Form selectTextForm// ToggleButton listTB// Form imapForm// args.Reset(); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_NONE); selectLabel = XmCreateLabel(selectForm, "selectLabel", ARGS); XtManageChild(selectLabel); args.Reset(); args.TopAttachment(XmATTACH_WIDGET, selectLabel); args.LeftAttachment(XmATTACH_NONE); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); listTB = XmCreateToggleButton(selectForm, "listTB", ARGS); XtManageChild(listTB); XtAddCallback(listTB, XmNvalueChangedCallback, (XtCallbackProc)ToggleList, (XtPointer)this); args.Reset(); args.TopAttachment(XmATTACH_NONE); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); imapForm = XmCreateForm(selectForm, "imapForm", ARGS); args.Reset(); args.TopAttachment(XmATTACH_WIDGET, selectLabel); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_WIDGET, listTB); if ( showImap ) args.BottomAttachment(XmATTACH_WIDGET, imapForm); else args.BottomAttachment(XmATTACH_FORM); selectTextForm = XmCreateForm(selectForm, "selectTextForm", ARGS);//// Create the selectTextForm widgets//// selectTextForm// Text selectText -or-// TextField selectTF// args.Reset(); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); args.ScrollingPolicy(XmAUTOMATIC); args.ScrollBarDisplayPolicy(XmAS_NEEDED); //TEST args.VisualPolicy(XmCONSTANT); //TEST args.EditMode(XmMULTI_LINE_EDIT); args.UserData(this); selectText = CreateScrolledText(selectTextForm, "selectText", ARGS); selectTextSW = XtParent(selectText); XtManageChild(selectText); XtAddCallback(selectText, XmNvalueChangedCallback, (XtCallbackProc)SelectTextChanged, (XtPointer)this); args.Reset(); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); args.UserData(this); selectTF = CreateTextField(selectTextForm, "selectTF", ARGS); XtAddCallback(selectTF, XmNvalueChangedCallback, (XtCallbackProc)SelectTFChanged, (XtPointer)this); XtAddCallback(selectTF, XmNactivateCallback, (XtCallbackProc)DoOk, (XtPointer)this); XtManageChild(selectTF); XtVaSetValues(selectForm, XmNinitialFocus, selectTF, NULL); XtManageChild(selectTextForm);//// Add special activation translation// static Boolean actionsAdded = False; if ( !actionsAdded ) { XtAppAddActions(halApp->context, actions, XtNumber(actions)); actionsAdded = True; }//// Create the imapForm children//// imapForm// ToggleButton imapTB// TextField imapTF// args.Reset(); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_FORM); imapTB = XmCreateToggleButton(imapForm, "imapTB", ARGS); XtManageChild(imapTB); args.LeftAttachment(XmATTACH_WIDGET, imapTB); args.RightAttachment(XmATTACH_FORM); imapTF = CreateTextField(imapForm, "imapTF", ARGS); XtManageChild(imapTF); XtAddCallback(imapTF, XmNvalueChangedCallback, (XtCallbackProc)AutoSelectImap, this); if ( showImap ) { TextFieldSetString(imapTF, ishApp->appPrefs->imapServer); XmToggleButtonSetState(imapTB, ishApp->folderPrefs->defFolderType == IMAP_FOLDER, False); XtManageChild(imapForm); }//// Create the listForm children//// listForm// Form dirForm// Separator dirFileSep// Form fileForm// args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.TopAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_FORM); dirForm = XmCreateForm(listForm, "dirForm", ARGS); args.Reset(); args.LeftAttachment(XmATTACH_WIDGET, dirForm); args.TopAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_FORM); args.Orientation(XmVERTICAL); Widget dirFileSep = XmCreateSeparator(listForm, "dirFileSep", ARGS); args.Reset(); args.LeftAttachment(XmATTACH_WIDGET, dirFileSep); args.TopAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); fileForm = XmCreateForm(listForm, "fileForm", ARGS);//// Create the dirForm children//// dirForm// Label dirNameLabel// Form dirNameForm// Label dirListLabel// ScrolledList dirList// args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.TopAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_NONE); Widget dirNameLabel = XmCreateLabel(dirForm, "dirNameLabel", ARGS); args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.TopAttachment(XmATTACH_WIDGET, dirNameLabel); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); Widget dirNameForm = XmCreateForm(dirForm, "dirNameForm", ARGS); args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.TopAttachment(XmATTACH_WIDGET, dirNameForm); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_NONE); Widget dirListLabel = XmCreateLabel(dirForm, "dirListLabel", ARGS); args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.TopAttachment(XmATTACH_WIDGET, dirListLabel); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); args.SelectionPolicy(XmSINGLE_SELECT); args.ListSizePolicy(XmRESIZE_IF_POSSIBLE); dirList = XmCreateScrolledList(dirForm, "dirList", ARGS); XtManageChild(dirList); XtAddCallback(dirList, XmNdefaultActionCallback, (XtCallbackProc)DoChooseDir, (XtPointer)this); XtAddCallback(dirList, XmNsingleSelectionCallback, (XtCallbackProc)DoSelectDir, (XtPointer)this);//// Create the dirNameForm children//// dirNameForm// TextField dirNameTF// PushButton dirNamePB// args.Reset(); args.TopAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_NONE); args.RightAttachment(XmATTACH_FORM); Widget dirNamePB = XmCreatePushButton(dirNameForm, "dirNamePB", ARGS); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_WIDGET, dirNamePB); dirNameTF = CreateTextField(dirNameForm, "dirNameTF", ARGS); XtAddCallback(dirNamePB, XmNactivateCallback, (XtCallbackProc)DoSetDir, (XtPointer)this); XtAddCallback(dirNameTF, XmNactivateCallback, (XtCallbackProc)DoSetDir, (XtPointer)this); wlist[0] = dirNameTF; wlist[1] = dirNamePB; XtManageChildren(wlist, 2); // dirNameForm children wlist[0] = dirNameLabel; wlist[1] = dirNameForm; wlist[2] = dirListLabel; XtManageChildren(wlist, 3); // dirForm children//// Create the fileForm children//// fileForm// Label filterLabel// Form filterForm// Label fileListLabel// ScrolledList fileList// args.Reset(); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_NONE); filterLabel = XmCreateLabel(fileForm, "filterLabel", ARGS); args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.TopAttachment(XmATTACH_WIDGET, filterLabel); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); Widget filterForm = XmCreateForm(fileForm, "filterForm", ARGS); args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.TopAttachment(XmATTACH_WIDGET, filterForm); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_NONE); fileListLabel = XmCreateLabel(fileForm, "fileListLabel", ARGS); args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.TopAttachment(XmATTACH_WIDGET, fileListLabel); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); args.ListSizePolicy(XmRESIZE_IF_POSSIBLE); fileList = XmCreateScrolledList(fileForm, "fileList", ARGS); XtManageChild(fileList); XtAddCallback(fileList, XmNdefaultActionCallback, (XtCallbackProc)DoChooseFile, (XtPointer)this); XtAddCallback(fileList, XmNbrowseSelectionCallback, (XtCallbackProc)DoFileSelection, (XtPointer)this); XtAddCallback(fileList, XmNextendedSelectionCallback, (XtCallbackProc)DoFileSelection, (XtPointer)this); XtAddCallback(fileList, XmNmultipleSelectionCallback, (XtCallbackProc)DoFileSelection, (XtPointer)this); XtAddCallback(fileList, XmNsingleSelectionCallback, (XtCallbackProc)DoFileSelection, (XtPointer)this);//// Create the filterForm children//// filterForm// TextField filterTF// PushButton filterPB// args.Reset(); args.TopAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_NONE); args.RightAttachment(XmATTACH_FORM); Widget filterPB = XmCreatePushButton(filterForm, "filterPB", ARGS); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_WIDGET, filterPB); filterTF = CreateTextField(filterForm, "filterTF", ARGS); XtAddCallback(filterPB, XmNactivateCallback, (XtCallbackProc)DoFilter, (XtPointer)this); XtAddCallback(filterTF, XmNactivateCallback, (XtCallbackProc)DoFilter, (XtPointer)this); wlist[0] = filterTF; wlist[1] = filterPB; XtManageChildren(wlist, 2); // filterForm children wlist[0] = filterLabel; wlist[1] = filterForm; wlist[2] = fileListLabel; XtManageChildren(wlist, 3); // fileForm children wlist[0] = dirForm; wlist[1] = dirFileSep; wlist[2] = fileForm; XtManageChildren(wlist, 3); // listForm children wlist[0] = selectForm;// wlist[1] = listForm; XtManageChildren(wlist, 1); // panedWin children XtManageChild(panedWin);//// Create buttonRC hierarchy//// buttonRC// PushButton okPB// PushButton clearPB// PushButton cancelPB// PushButton helpPB// AddButtonBox(); okPB = XmCreatePushButton(buttonRC, "okPB", 0,0); Widget clearPB = XmCreatePushButton(buttonRC, "clearPB", 0,0); cancelPB = XmCreatePushButton(buttonRC, "cancelPB", 0,0); Widget helpPB = XmCreatePushButton(buttonRC, "helpPB", 0,0); XtAddCallback(okPB, XmNactivateCallback, (XtCallbackProc)DoOk, (XtPointer)this); XtAddCallback(clearPB, XmNactivateCallback, (XtCallbackProc)DoClear, (XtPointer)this); XtAddCallback(cancelPB, XmNactivateCallback, (XtCallbackProc)DoHide, (XtPointer)this); XtAddCallback(helpPB, XmNactivateCallback, (XtCallbackProc)HalAppC::DoHelp, (XtPointer)"helpcard"); wlist[0] = okPB; wlist[1] = clearPB; wlist[2] = cancelPB; wlist[3] = helpPB; XtManageChildren(wlist, 4); // buttonRC children XtSetSensitive(okPB, False); // Wait until some are selected ShowInfoMsg(); HandleHelp();//// Read resources//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -