JBoolean SyGApplication::RestoreProgramState() { JPtrArray<JString> children(JPtrArrayT::kDeleteAll); if (!(SyGGetPrefsMgr())->RestoreProgramState(&children)) { return kJFalse; } const JSize count = children.GetElementCount(); for (JIndex i=1; i<=count; i++) { const JString* str = children.NthElement(i); OpenDirectory(*str, NULL, NULL, kJFalse, kJFalse); } if (itsWindowList->IsEmpty()) { JString path; if (!JGetHomeDirectory(&path) || !JFSFileTreeNode::CanHaveChildren(path)) { path = JGetRootDirectory(); } OpenDirectory(path); SyGTreeDir* dir; if (SyGGetTrashDirectory(&path, kJFalse) && OpenDirectory(path, &dir)) { (dir->GetWindow())->Iconify(); } } return kJTrue; }
void JXPathInput::HandleKeyPress ( const int key, const JXKeyModifiers& modifiers ) { if (key == '\t') { if (itsCompleter == NULL) { if (!JDirInfo::Create(JGetRootDirectory(), &itsCompleter)) { return; } itsCompleter->ShowHidden(kJTrue); itsCompleter->ShowVCSDirs(kJFalse); itsCompleter->ShowDirs(kJTrue); itsCompleter->ShowFiles(kJFalse); itsCompleter->ShouldApplyWildcardFilterToDirs(); } Complete(this, itsBasePath, itsCompleter, &itsCompletionMenu); } else { if (itsCompletionMenu != NULL) { itsCompletionMenu->ClearRequestCount(); } JXInputField::HandleKeyPress(key, modifiers); } }
JBoolean JDirInfo::ForceUpdate() { if (JDirectoryExists(*itsCWD)) { Broadcast(ContentsWillBeUpdated()); const JError err = BuildInfo(); if (err.OK()) { return kJTrue; } } if (itsSwitchIfInvalidFlag) { JString path; if (!JGetHomeDirectory(&path) || !OKToCreate(path)) { path = JGetRootDirectory(); } GoTo(path); } else { itsIsValidFlag = kJFalse; itsIsWritableFlag = kJFalse; itsDirEntries->CleanOut(); itsVisEntries->CleanOut(); itsAlphaEntries->CleanOut(); } return kJFalse; }
JString CBCommandPathInput::GetTextForChoosePath() const { if (!GetText().IsEmpty() && GetText().GetFirstCharacter() == '@') { JString s; if (!GetBasePath(&s) && !JGetHomeDirectory(&s)) { s = JGetRootDirectory(); } return s; } else { return JXPathInput::GetTextForChoosePath(); } }
JString JGetCurrentDirectory() { char buf[1024]; char* result = getcwd(buf, 1024); JString dirName; if (result == buf) { dirName = buf; } else if (!JGetHomeDirectory(&dirName) || !(JChangeDirectory(dirName)).OK()) { dirName = JGetRootDirectory(); JChangeDirectory(dirName); } JAppendDirSeparator(&dirName); return dirName; }
JBoolean JXPathInput::Complete ( JXInputField* te, const JCharacter* basePath, // can be NULL JDirInfo* completer, JXStringCompletionMenu** menu // constructed if NULL ) { // only complete if caret is at end of text JIndex caretIndex; if (!te->GetCaretLocation(&caretIndex) || caretIndex != te->GetTextLength()+1) { return kJFalse; } // catch empty path if (te->IsEmpty()) { const JString path = JGetRootDirectory(); te->Paste(path); return kJTrue; } // convert to absolute path JString fullName; if (!JExpandHomeDirShortcut(te->GetText(), &fullName)) { return kJFalse; } if (JIsRelativePath(fullName)) { if (JStringEmpty(basePath)) { return kJFalse; } fullName = JCombinePathAndName(basePath, fullName); } // if completing ~ rather than ~/ if (fullName.EndsWith(ACE_DIRECTORY_SEPARATOR_STR) && !(te->GetText()).EndsWith(ACE_DIRECTORY_SEPARATOR_STR)) { JStripTrailingDirSeparator(&fullName); } // get path and wildcard filter JString path, name; if (fullName.EndsWith(ACE_DIRECTORY_SEPARATOR_STR)) { path = fullName; name = "*"; } else { JSplitPathAndName(fullName, &path, &name); name.AppendCharacter('*'); } // build completion list if (!(completer->GoTo(path)).OK()) { return kJFalse; } completer->SetWildcardFilter(name, kJFalse, kJTrue); if (completer->IsEmpty()) { return kJFalse; } // check for characters common to all matches JString maxPrefix = jGetFullName(completer, 1); const JSize matchCount = completer->GetEntryCount(); JString entryName; for (JIndex i=2; i<=matchCount; i++) { entryName = jGetFullName(completer, i); const JSize matchLength = JCalcMatchLength(maxPrefix, entryName); const JSize prefixLength = maxPrefix.GetLength(); if (matchLength < prefixLength) { maxPrefix.RemoveSubstring(matchLength+1, prefixLength); } } // use the completion list if (matchCount > 0 && maxPrefix.GetLength() > fullName.GetLength()) { maxPrefix.RemoveSubstring(1, fullName.GetLength()); if (matchCount == 1 && (completer->GetEntry(1)).IsDirectory()) { JAppendDirSeparator(&maxPrefix); } te->Paste(maxPrefix); // so Undo removes completion if (*menu != NULL) { (**menu).ClearRequestCount(); } return kJTrue; } else if (matchCount > 1) { if (*menu == NULL) { *menu = new JXStringCompletionMenu(te, kJFalse); assert( *menu != NULL ); } else { (**menu).RemoveAllItems(); } for (JIndex i=1; i<=matchCount; i++) { entryName = jGetName(completer, i); (**menu).AddString(entryName); } (**menu).CompletionRequested(name.GetLength()-1); return kJTrue; } else { return kJFalse; } }
JString JGetClosestDirectory ( const JCharacter* origDirName, const JBoolean requireWrite, const JCharacter* basePath ) { assert( !JStringEmpty(origDirName) ); JString workingDir; if (!JStringEmpty(basePath)) { workingDir = basePath; JAppendDirSeparator(&workingDir); } else { workingDir = JGetCurrentDirectory(); } JString dirName = origDirName; JString homeDir; JSize homeLength; if (origDirName[0] == '~' && !JExpandHomeDirShortcut(origDirName, &dirName, &homeDir, &homeLength)) { return JGetRootDirectory(); } else if (JIsRelativePath(origDirName)) { dirName.Prepend(workingDir); } assert( !JIsRelativePath(dirName) ); JString newDir, junkName; while (!JDirectoryExists(dirName) || !JCanEnterDirectory(dirName) || !JDirectoryReadable(dirName) || (requireWrite && !JDirectoryWritable(dirName))) { JStripTrailingDirSeparator(&dirName); if (JIsRootDirectory(dirName)) { break; } JSplitPathAndName(dirName, &newDir, &junkName); dirName = newDir; } // convert back to partial path, if possible if (origDirName[0] == '~' && dirName.BeginsWith(homeDir)) { dirName.ReplaceSubstring(1, homeDir.GetLength(), origDirName, homeLength); } else if (JIsRelativePath(origDirName) && dirName.GetLength() > workingDir.GetLength() && dirName.BeginsWith(workingDir)) { dirName.RemoveSubstring(1, workingDir.GetLength()); } return dirName; }