better handling of / key in get-file and put-file dialogs
svn: r1162
This commit is contained in:
parent
dd4cf2990c
commit
56bc8dcb89
|
@ -259,6 +259,7 @@ extern "C" {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern char *scheme_expand_filename(char* filename, int ilen, const char *errorin, int *ex, int guards);
|
extern char *scheme_expand_filename(char* filename, int ilen, const char *errorin, int *ex, int guards);
|
||||||
extern int scheme_is_complete_path(const char *s, long len);
|
extern int scheme_is_complete_path(const char *s, long len);
|
||||||
|
extern int scheme_file_exists(const char *s);
|
||||||
extern char *scheme_find_completion(char *fn);
|
extern char *scheme_find_completion(char *fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +284,8 @@ static int log_base_10(int i)
|
||||||
class wxCallbackInfo {
|
class wxCallbackInfo {
|
||||||
public:
|
public:
|
||||||
NavDialogRef dialog;
|
NavDialogRef dialog;
|
||||||
int has_parent;
|
int has_parent, is_put;
|
||||||
|
int need_show_select;
|
||||||
char *initial_directory;
|
char *initial_directory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -299,7 +301,6 @@ class wxCallbackCallbackInfo {
|
||||||
public:
|
public:
|
||||||
WindowRef dialog;
|
WindowRef dialog;
|
||||||
ControlRef txt;
|
ControlRef txt;
|
||||||
NavCBRecPtr callBackParms;
|
|
||||||
wxCallbackInfo *cbi;
|
wxCallbackInfo *cbi;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -336,10 +337,15 @@ static OSStatus ok_evt_handler(EventHandlerCallRef inHandlerCallRef,
|
||||||
|
|
||||||
if (result && scheme_mac_path_to_spec(result, &spec)) {
|
if (result && scheme_mac_path_to_spec(result, &spec)) {
|
||||||
AEDesc desc;
|
AEDesc desc;
|
||||||
NavCBRecPtr callBackParms;
|
|
||||||
callBackParms = ccbi->callBackParms;
|
|
||||||
AECreateDesc (typeFSS, &spec, sizeof(FSSpec), &desc);
|
AECreateDesc (typeFSS, &spec, sizeof(FSSpec), &desc);
|
||||||
NavCustomControl(callBackParms->context, kNavCtlSetLocation, &desc);
|
if (scheme_file_exists(result)) {
|
||||||
|
NavCustomControl(ccbi->cbi->dialog, kNavCtlSetSelection, &desc);
|
||||||
|
if (ccbi->cbi->is_put) {
|
||||||
|
NavCustomControl(ccbi->cbi->dialog, kNavCtlSetEditFileName, spec.name);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
NavCustomControl(ccbi->cbi->dialog, kNavCtlSetLocation, &desc);
|
||||||
|
ccbi->cbi->need_show_select = 1;
|
||||||
AEDisposeDesc(&desc);
|
AEDisposeDesc(&desc);
|
||||||
if (!ccbi->cbi->has_parent) {
|
if (!ccbi->cbi->has_parent) {
|
||||||
::HideSheetWindow(dialog);
|
::HideSheetWindow(dialog);
|
||||||
|
@ -419,14 +425,14 @@ static OSStatus tab_evt_handler(EventHandlerCallRef inHandlerCallRef,
|
||||||
return eventNotHandledErr;
|
return eventNotHandledErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *extract_current_dir(NavCBRecPtr callBackParms)
|
static char *extract_current_dir(NavDialogRef context)
|
||||||
{
|
{
|
||||||
AEDesc here, there;
|
AEDesc here, there;
|
||||||
FSRef fsref;
|
FSRef fsref;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
char *dir = NULL;
|
char *dir = NULL;
|
||||||
|
|
||||||
NavCustomControl(callBackParms->context, kNavCtlGetLocation, &here);
|
NavCustomControl(context, kNavCtlGetLocation, &here);
|
||||||
|
|
||||||
err = AECoerceDesc(&here, typeFSRef, &there);
|
err = AECoerceDesc(&here, typeFSRef, &there);
|
||||||
if (err != noErr) {
|
if (err != noErr) {
|
||||||
|
@ -452,8 +458,7 @@ static char *extract_current_dir(NavCBRecPtr callBackParms)
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_text_path_dialog(wxCallbackInfo *cbi,
|
static void do_text_path_dialog(wxCallbackInfo *cbi)
|
||||||
NavCBRecPtr callBackParms)
|
|
||||||
{
|
{
|
||||||
int width = 500;
|
int width = 500;
|
||||||
WindowRef parent, dialog;
|
WindowRef parent, dialog;
|
||||||
|
@ -470,7 +475,7 @@ static void do_text_path_dialog(wxCallbackInfo *cbi,
|
||||||
info = new wxCallbackCallbackInfo;
|
info = new wxCallbackCallbackInfo;
|
||||||
info_sr = WRAP_SAFEREF(info);
|
info_sr = WRAP_SAFEREF(info);
|
||||||
|
|
||||||
init = extract_current_dir(callBackParms);
|
init = extract_current_dir(cbi->dialog);
|
||||||
if (!init)
|
if (!init)
|
||||||
init = "/";
|
init = "/";
|
||||||
|
|
||||||
|
@ -509,7 +514,6 @@ static void do_text_path_dialog(wxCallbackInfo *cbi,
|
||||||
::ShowControl(txt);
|
::ShowControl(txt);
|
||||||
|
|
||||||
info->txt = txt;
|
info->txt = txt;
|
||||||
info->callBackParms = callBackParms;
|
|
||||||
|
|
||||||
::SetRect(&r, width - 75, 60, width - 10, 80);
|
::SetRect(&r, width - 75, 60, width - 10, 80);
|
||||||
::CreatePushButtonControl(dialog, &r, CFSTR("Goto"), &ok);
|
::CreatePushButtonControl(dialog, &r, CFSTR("Goto"), &ok);
|
||||||
|
@ -547,12 +551,30 @@ static void do_text_path_dialog(wxCallbackInfo *cbi,
|
||||||
info_sr = NULL;
|
info_sr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static OSStatus slash_key_evt_handler(EventHandlerCallRef inHandlerCallRef,
|
||||||
|
EventRef inEvent,
|
||||||
|
void *inUserData)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
GetEventParameter(inEvent, kEventParamKeyMacCharCodes, typeChar,
|
||||||
|
NULL, sizeof(c), NULL, &c);
|
||||||
|
|
||||||
|
if (c == '/') {
|
||||||
|
wxCallbackInfo *cbi = (wxCallbackInfo *)GET_SAFEREF(inUserData);
|
||||||
|
do_text_path_dialog(cbi);
|
||||||
|
return noErr;
|
||||||
|
} else
|
||||||
|
return eventNotHandledErr;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// File-selector callback
|
// File-selector callback
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/* Sets the right initial directory, if one is supplied, and
|
/* Sets the right initial directory, if one is supplied, and
|
||||||
redirects '/' to open the text path dialog. */
|
redirects '/' to open the text path dialog. */
|
||||||
|
|
||||||
|
|
||||||
static void ExtensionCallback(NavEventCallbackMessage callBackSelector,
|
static void ExtensionCallback(NavEventCallbackMessage callBackSelector,
|
||||||
NavCBRecPtr callBackParms,
|
NavCBRecPtr callBackParms,
|
||||||
void *callBackUD)
|
void *callBackUD)
|
||||||
|
@ -561,12 +583,19 @@ static void ExtensionCallback(NavEventCallbackMessage callBackSelector,
|
||||||
|
|
||||||
switch (callBackSelector) {
|
switch (callBackSelector) {
|
||||||
case kNavCBEvent:
|
case kNavCBEvent:
|
||||||
if ((callBackParms->eventData.eventDataParms.event->what == keyUp)
|
if (cbi->need_show_select) {
|
||||||
&& ((callBackParms->eventData.eventDataParms.event->message & charCodeMask) == '/')) {
|
cbi->need_show_select = 0;
|
||||||
do_text_path_dialog(cbi, callBackParms);
|
NavCustomControl(cbi->dialog, kNavCtlShowSelection, NULL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kNavCBStart:
|
case kNavCBStart:
|
||||||
|
{
|
||||||
|
EventTypeSpec spec[1];
|
||||||
|
spec[0].eventClass = kEventClassKeyboard;
|
||||||
|
spec[0].eventKind = kEventRawKeyDown;
|
||||||
|
::InstallEventHandler(GetWindowEventTarget(NavDialogGetWindow(callBackParms->context)),
|
||||||
|
slash_key_evt_handler, 1, spec, callBackUD, NULL);
|
||||||
|
}
|
||||||
if (cbi->initial_directory) {
|
if (cbi->initial_directory) {
|
||||||
FSSpec spec;
|
FSSpec spec;
|
||||||
if (scheme_mac_path_to_spec(cbi->initial_directory, &spec)) {
|
if (scheme_mac_path_to_spec(cbi->initial_directory, &spec)) {
|
||||||
|
@ -723,6 +752,7 @@ char *wxFileSelector(char *message, char *default_path,
|
||||||
}
|
}
|
||||||
|
|
||||||
cbi_sr = WRAP_SAFEREF(cbi);
|
cbi_sr = WRAP_SAFEREF(cbi);
|
||||||
|
cbi->is_put = 0;
|
||||||
|
|
||||||
// create the dialog:
|
// create the dialog:
|
||||||
if (flags & wxGETDIR) {
|
if (flags & wxGETDIR) {
|
||||||
|
@ -737,9 +767,11 @@ char *wxFileSelector(char *message, char *default_path,
|
||||||
derr = NavCreatePutFileDialog(&dialogOptions, 'TEXT', 'mReD',
|
derr = NavCreatePutFileDialog(&dialogOptions, 'TEXT', 'mReD',
|
||||||
extProc, cbi_sr,
|
extProc, cbi_sr,
|
||||||
&outDialog);
|
&outDialog);
|
||||||
|
cbi->is_put = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cbi->dialog = outDialog;
|
cbi->dialog = outDialog;
|
||||||
|
cbi->need_show_select = 0;
|
||||||
|
|
||||||
if (derr != noErr) {
|
if (derr != noErr) {
|
||||||
if (default_filename)
|
if (default_filename)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user