Пример #1
0
void
JXCheckbox::HandleShortcut
	(
	const int				key,
	const JXKeyModifiers&	modifiers
	)
{
	SetState( JNegate(itsIsCheckedFlag) );
}
Пример #2
0
JBoolean
JXFileInput::InputValid()
{
	if (itsAllowInvalidFileFlag)
		{
		return kJTrue;
		}
	else if (!JXInputField::InputValid())
		{
		return kJFalse;
		}

	const JString& text = GetText();
	if (text.IsEmpty())
		{
		return JNegate(IsRequired());
		}

	JString fullName;
	const JCharacter* errID = NULL;
	if (JIsRelativePath(text) && !HasBasePath())
		{
		errID = kNoRelPathID;
		RecalcAll(kJTrue);
		}
	else if (!JConvertToAbsolutePath(text, itsBasePath, &fullName) ||
			 !JFileExists(fullName))
		{
		errID = kDoesNotExistID;
		}
	else if (itsRequireReadFlag && !JFileReadable(fullName))
		{
		errID = kUnreadableID;
		}
	else if (itsRequireWriteFlag && !JFileWritable(fullName))
		{
		errID = kUnwritableID;
		}
	else if (itsRequireExecFlag && !JFileExecutable(fullName))
		{
		errID = kCannotExecID;
		}

	if (JStringEmpty(errID))
		{
		return kJTrue;
		}
	else
		{
		(JGetUserNotification())->ReportError(JGetString(errID));
		return kJFalse;
		}
}
JBoolean
CBHTMLCompleter::IsWordCharacter
	(
	const JString&	s,
	const JIndex	index,
	const JBoolean	includeNS
	)
	const
{
	const JCharacter c = s.GetCharacter(index);
	return JNegate(c == '<' || c == '>' || c == '&' || c == '=' || isspace(c));
}
JBoolean
JFSBindingList::GetBinding
	(
	const JCharacter*	origFileName,
	const JFSBinding**	binding
	)
{
	// ignore # and ~ on end

	JString fileName = origFileName;
	CleanFileName(&fileName);

	// read content

	JString content;
	ifstream input(origFileName);
	content.Read(input, kContentLength);
	input.close();

	// scan bindings for match -- check content types first

	const JSize count = GetElementCount();
	for (JIndex j=0; j<=1; j++)
		{
		const JBoolean isContent = JNegate(j);
		for (JIndex i=1; i<=count; i++)
			{
			*binding = GetBinding(i);
			if ((**binding).IsContentBinding() == isContent &&
				(**binding).Match(fileName, content))
				{
				return kJTrue;
				}
			}
		}

	if (itsUseDefaultFlag && itsUserDefault != NULL)
		{
		*binding = itsUserDefault;
		return kJTrue;
		}

	if (itsUseDefaultFlag && itsSystemDefault != NULL)
		{
		*binding = itsSystemDefault;
		return kJTrue;
		}

	*binding = NULL;
	return kJFalse;
}
Пример #5
0
JBoolean
JExtractHTMLTitle::ExtractTitle
	(
	const JCharacter*	text,
	JString*			title
	)
{
	title->Clear();

	itsInTitleFlag = kJFalse;
	itsNeedWSFlag  = kJFalse;
	itsTitle       = title;
	LexHTML(text);
	itsTitle       = NULL;

	return JNegate(title->IsEmpty());
}
Пример #6
0
JBoolean
JKillDirectory
	(
	const JCharacter* dirName
	)
{
	const JCharacter* argv[] = {"rm", "-rf", dirName, NULL};
	const JError err = JExecute(argv, sizeof(argv), NULL,
								kJIgnoreConnection, NULL,
								kJIgnoreConnection, NULL,
								kJTossOutput,       NULL);
	if (err.OK())
		{
		return JNegate( JNameUsed(dirName) );
		}
	else
		{
		return kJFalse;
		}
}
Пример #7
0
JBoolean
JDirInfo::MatchesNameFilter
	(
	const JDirEntry& entry
	)
	const
{
	if (itsNameRegex != NULL)
		{
		const JString& name = entry.GetName();
		JBoolean match      = itsNameRegex->Match(name);
		if (itsInvertNameRegexFlag)
			{
			match = JNegate(match);
			}
		return match;
		}
	else
		{
		return kJTrue;
		}
}
Пример #8
0
JBoolean
JXFileInput::GetDroppedFileName
	(
	const Time		time,
	const JBoolean	reportErrors,
	JString*		fileName
	)
{
	fileName->Clear();

	JXSelectionManager* selMgr = GetSelectionManager();

	Atom returnType;
	unsigned char* data;
	JSize dataLength;
	JXSelectionManager::DeleteMethod delMethod;
	if (selMgr->GetData((GetDNDManager())->GetDNDSelectionName(),
						time, selMgr->GetURLXAtom(),
						&returnType, &data, &dataLength, &delMethod))
		{
		if (returnType == selMgr->GetURLXAtom())
			{
			JPtrArray<JString> fileNameList(JPtrArrayT::kDeleteAll),
							   urlList(JPtrArrayT::kDeleteAll);
			JXUnpackFileNames((char*) data, dataLength, &fileNameList, &urlList);
			if (fileNameList.GetElementCount() == 1 &&
				(JFileExists(*(fileNameList.FirstElement())) ||
				 JDirectoryExists(*(fileNameList.FirstElement()))))
				{
				*fileName = *(fileNameList.FirstElement());
				}
			JXReportUnreachableHosts(urlList);
			}

		selMgr->DeleteData(&data, delMethod);
		}

	return JNegate( fileName->IsEmpty() );
}
Пример #9
0
JBoolean
JSplitRootAndSuffix
	(
	const JCharacter*	name,
	JString*			root,
	JString*			suffix
	)
{
	*root = name;
	suffix->Clear();

	JIndex dotIndex;
	if (root->LocateLastSubstring(".", &dotIndex) && dotIndex > 1)
		{
		const JSize length = root->GetLength();
		if (dotIndex < length)
			{
			JBoolean isSuffix = kJFalse;
			for (JIndex i=dotIndex+1; i<=length; i++)
				{
				if (!isdigit(root->GetCharacter(i)))
					{
					isSuffix = kJTrue;
					break;
					}
				}

			if (isSuffix)
				{
				*suffix = root->GetSubstring(dotIndex+1, length);
				root->RemoveSubstring(dotIndex, length);
				}
			}
		}

	return JNegate( suffix->IsEmpty() );
}
void
JDirInfo::CopySettings
	(
	const JDirInfo& source
	)
{
	const JBoolean rebuild = JNegate(
		itsContentRegex != NULL && source.itsContentRegex != NULL &&
		itsContentRegex->GetPattern() == (source.itsContentRegex)->GetPattern());

	PrivateCopySettings(source);

	if (rebuild)
		{
		ForceUpdate();
		}
	else
		{
		itsDirEntries->Sort();
		ApplyFilters(kJTrue);
		}

	Broadcast(SettingsChanged());
}
Пример #11
0
JBoolean
JTEStyler::SetStyle
	(
	const JIndexRange&	range,
	const JFontStyle&	style
	)
{
	assert( !range.IsEmpty() );

	if (itsCheckRange.last < range.first)
		{
		// we are beyond the range where anything could have changed
		return kJFalse;
		}

	assert( range.first == itsTokenStart );

	if (itsRedoAllFlag)
		{
		JFontID fid = itsDefFontID;
		if (!OnlyColorChanged(style, itsDefFontStyle))
			{
			fid = itsFontMgr->GetFontID(itsFontName, itsFontSize, style);
			}
		itsStyles->AppendElements(JTextEditor::Font(fid, itsFontSize, style, itsDefFontAlign),
								  range.GetLength());
		}
	else if (range.last >= itsCheckRange.first)
		{
		JIndexRange fontRange;
		fontRange.SetFirstAndLength(itsTokenFirstInRun, itsStyles->GetRunLength(itsTokenRunIndex));
		const JBoolean beyondCurrentRun = JNegate( fontRange.Contains(range) );

		JTextEditor::Font f = itsStyles->GetRunData(itsTokenRunIndex);
		if (beyondCurrentRun || style != f.style)
			{
			// extend the check range if we slop over into another style run
			// (HTML: type '<' after 'x' in "x<!--<br><h3>text</h3>-->")

			// extend past end of run to insure that we keep going until we
			// find a correctly styled token

			if (beyondCurrentRun)
				{
				JIndex runIndex   = itsTokenRunIndex;
				JIndex firstInRun = itsTokenFirstInRun;
				const JBoolean ok = itsStyles->FindRun(itsTokenStart, range.last,
													   &runIndex, &firstInRun);
				ExtendCheckRange(firstInRun + itsStyles->GetRunLength(runIndex));
				}

			// extend check range to next token since this token was not
			// correctly styled -- should only stop when find correctly
			// styled tokens

			else	// style != f.style
				{
				ExtendCheckRange(range.last+1);
				}

			// update the styles

			if (!beyondCurrentRun && OnlyColorChanged(style, f.style))
				{
				*itsRedrawRange += range;
				}
			else
				{
				*itsRecalcRange += range;
				}

			f.size  = itsFontSize;
			f.style = style;
			if (OnlyColorChanged(style, itsDefFontStyle))
				{
				f.id = itsDefFontID;
				}
			else
				{
				f.id = itsFontMgr->GetFontID(itsFontName, itsFontSize, style);
				}
			f.align  = itsDefFontAlign;

			itsStyles->RemoveNextElements(range.first, range.GetLength(),
										  &itsTokenRunIndex, &itsTokenFirstInRun);

			run_assert(itsStyles, range.first, itsTokenRunIndex, itsTokenFirstInRun);

			itsStyles->InsertElementsAtIndex(range.first, f, range.GetLength(),
											 &itsTokenRunIndex, &itsTokenFirstInRun);

			run_assert(itsStyles, range.first, itsTokenRunIndex, itsTokenFirstInRun);
			}
		}

	itsTokenStart = range.last+1;
	if (!itsRedoAllFlag)
		{
		const JBoolean ok = itsStyles->FindRun(range.first, itsTokenStart,
											   &itsTokenRunIndex, &itsTokenFirstInRun);
		assert( ok || range.last == itsText->GetLength() );
		assert( range.last == itsText->GetLength() ||
				check_run(itsStyles, itsTokenStart, itsTokenRunIndex, itsTokenFirstInRun) );
		}

	return JConvertToBoolean( range.last < itsCheckRange.last );
}
void
CBCommandTable::UpdateOptionsMenu()
{
	JPoint cell;
	const JBoolean ok = (GetTableSelection()).GetFirstSelectedCell(&cell);
	assert( ok );

	JBoolean changed = kJFalse;

	CBCommandManager::CmdInfo info = itsCmdList->GetElement(cell.y);
	if (info.isMake)
		{
		itsOptionsMenu->CheckItem(kIsMakeCmd);
		info.saveAll   = kJTrue;
		info.useWindow = kJTrue;
		changed        = kJTrue;
		}

	if (info.isVCS)
		{
		itsOptionsMenu->CheckItem(kIsCVSCmd);
		info.saveAll = kJTrue;
		changed      = kJTrue;
		}

	itsOptionsMenu->SetItemEnable(kSaveAllCmd, JNegate(info.isMake || info.isVCS));
	if (info.saveAll)
		{
		itsOptionsMenu->CheckItem(kSaveAllCmd);
		}

	if (info.oneAtATime)
		{
		itsOptionsMenu->CheckItem(kOneAtATimeCmd);
		}

//
	itsOptionsMenu->DisableItem(kOneAtATimeCmd);
	itsOptionsMenu->CheckItem(kOneAtATimeCmd);
//

	itsOptionsMenu->SetItemEnable(kUseWindowCmd, !info.isMake);
	if (info.useWindow)
		{
		itsOptionsMenu->CheckItem(kUseWindowCmd);
		}
	else
		{
		info.raiseWindowWhenStart = kJFalse;
		changed                   = kJTrue;
		}

	itsOptionsMenu->SetItemEnable(kRaisedWhenStartCmd, info.useWindow);
	if (info.raiseWindowWhenStart)
		{
		itsOptionsMenu->CheckItem(kRaisedWhenStartCmd);
		}

	if (info.beepWhenFinished)
		{
		itsOptionsMenu->CheckItem(kBeepWhenFinishedCmd);
		}

	if (info.separator)
		{
		itsOptionsMenu->CheckItem(kShowSeparatorCmd);
		}

	if (changed)
		{
		itsCmdList->SetElement(cell.y, info);
		TableRefreshCell(cell);
		}
}
Пример #13
0
void
TestWidget::HandleActionsMenu
(
    const JIndex index
)
{
    if (index == kChangeSizeCmd)
    {
        GetNewSize();
    }
    else if (index == kToggleFillCmd)
    {
        itsFillFlag = JNegate(itsFillFlag);
        Refresh();
    }

    else if (index == kShowHideCmd && IsVisible())
    {
        Hide();
        itsActionsMenu->SetItemText(kShowHideCmd, kShowStr);
    }
    else if (index == kShowHideCmd)
    {
        Show();
        itsActionsMenu->SetItemText(kShowHideCmd, kHideStr);
    }

    else if (index == kActDeactCmd && IsActive())
    {
        Deactivate();
        itsActionsMenu->SetItemText(kActDeactCmd, kActivateStr);
    }
    else if (index == kActDeactCmd)
    {
        Activate();
        itsActionsMenu->SetItemText(kActDeactCmd, kDeactivateStr);
    }

    else if (index == kRedGreenCmd)
    {
        JXColormap* colormap  = GetColormap();
        const JIndex redColor = colormap->GetRedColor();
        itsAnimButton->SetFontStyle(itsNextAnimColor);
        if (itsNextAnimColor == redColor)
        {
            itsNextAnimColor = colormap->GetGreenColor();
            itsActionsMenu->SetItemText(kRedGreenCmd, kGreenStr);
        }
        else
        {
            itsNextAnimColor = redColor;
            itsActionsMenu->SetItemText(kRedGreenCmd, kRedStr);
        }
    }

    else if (index == kShowHideQuitCmd && itsQuitButton != NULL &&
             itsQuitButton->WouldBeVisible())
    {
        itsQuitButton->Hide();
        itsActionsMenu->SetItemText(kShowHideQuitCmd, kShowQuitStr);
    }
    else if (index == kShowHideQuitCmd && itsQuitButton != NULL)
    {
        itsQuitButton->Show();
        itsActionsMenu->SetItemText(kShowHideQuitCmd, kHideQuitStr);
    }

    else if (index == kActDeactQuitCmd && itsQuitButton != NULL &&
             itsQuitButton->WouldBeActive())
    {
        itsQuitButton->Deactivate();
        itsActionsMenu->SetItemText(kActDeactQuitCmd, kActivateQuitStr);
    }
    else if (index == kActDeactQuitCmd && itsQuitButton != NULL)
    {
        itsQuitButton->Activate();
        itsActionsMenu->SetItemText(kActDeactQuitCmd, kDeactivateQuitStr);
    }

    else if (index == kPrintSelectionTargetsCmd)
    {
        PrintSelectionTargets(CurrentTime);
    }
    else if (index == kPrintOldSelectionTargetsCmd)
    {
        PrintSelectionTargets((GetDisplay())->GetLastEventTime() - 10000);
    }
}
void
CBEditTextPrefsDialog::UpdateSettings()
{
	CBTextEditor* te = itsDoc->GetTextEditor();

	JString fontName;
	JSize fontSize;
	itsFontMenu->GetFont(&fontName, &fontSize);
	const JBoolean fontChanged = JI2B(
		fontName != te->GetDefaultFont().GetName() ||
		fontSize != te->GetDefaultFont().GetSize() );

	JFloat vScrollScale = 1.0;
	if (fontChanged)
		{
		const JFontManager* fontMgr = te->GetFontManager();
		const JFloat h1 = te->GetDefaultFont().GetLineHeight();
		const JFloat h2 = fontMgr->GetFont(fontName, fontSize).GetLineHeight();
		vScrollScale    = h2 / h1;
		}

	JInteger tabCharCount;
	JBoolean ok = itsTabCharCountInput->GetValue(&tabCharCount);
	assert( ok );

	JInteger crmLineWidth;
	ok = itsCRMLineWidthInput->GetValue(&crmLineWidth);
	assert( ok );

	JInteger undoDepth;
	ok = itsUndoDepthInput->GetValue(&undoDepth);
	assert( ok );

	JInteger rightMargin;
	ok = itsRightMarginInput->GetValue(&rightMargin);
	assert( ok );

	CBPrefsManager* prefsMgr = CBGetPrefsManager();
	const JBoolean textColorChanged = JNegate(
		itsColor[ CBPrefsManager::kTextColorIndex-1 ] ==
		prefsMgr->GetColor(CBPrefsManager::kTextColorIndex));

	// set colors before RecalcStyles() so stylers update themselves

	prefsMgr->SetDefaultFont(fontName, fontSize);
	for (JIndex j=1; j<=CBPrefsManager::kColorCount; j++)
		{
		prefsMgr->SetColor(j, itsColor[j-1]);
		}

	JPtrArray<CBTextDocument>* docList = (CBGetDocumentManager())->GetTextDocList();
	const JSize docCount = docList->GetElementCount();

	JProgressDisplay* pg = JNewPG();
	pg->FixedLengthProcessBeginning(docCount, "Updating preferences...", kJFalse, kJFalse);

	for (JIndex i=1; i<=docCount; i++)
		{
		CBTextDocument* doc = docList->NthElement(i);

		doc->ShouldMakeBackupFile(itsCreateBackupCB->IsChecked());
		doc->ShouldMakeNewBackupEveryOpen(!itsOnlyBackupIfNoneCB->IsChecked());
		doc->ShouldAllocateTitleSpace(itsExtraSpaceWindTitleCB->IsChecked());
		doc->ShouldOpenComplFileOnTop(itsOpenComplFileOnTopCB->IsChecked());

		te = doc->GetTextEditor();

		if (itsEmulatorIndex != itsOrigEmulatorIndex)
			{
			JTEKeyHandler* handler;
			CBInstallEmulator(kMenuIndexToEmulator[ itsEmulatorIndex-1 ], te, &handler);
			}

		te->ShouldAutoIndent(itsAutoIndentCB->IsChecked());
		te->CBShouldAllowDragAndDrop(itsUseDNDCB->IsChecked());
		te->ShouldMoveToFrontOfText(itsLeftToFrontOfTextCB->IsChecked());

		te->ShouldBalanceWhileTyping(itsBalanceWhileTypingCB->IsChecked());
		te->ShouldScrollToBalance(itsScrollToBalanceCB->IsChecked());
		te->ShouldBeepWhenTypeUnbalanced(itsBeepWhenTypeUnbalancedCB->IsChecked());

		te->TabShouldBeSmart(itsSmartTabCB->IsChecked());
		te->TabShouldInsertSpaces(itsTabToSpacesCB->IsChecked());

		if (fontChanged)
			{
			JXScrollbar *hScrollbar, *vScrollbar;
			const JBoolean ok = te->GetScrollbars(&hScrollbar, &vScrollbar);
			assert( ok );
			vScrollbar->PrepareForScaledMaxValue(vScrollScale);

			te->SetFont(fontName, fontSize, tabCharCount);
			}
		else
			{
			te->SetTabCharCount(tabCharCount);
			}

		te->SetCRMLineWidth(crmLineWidth);
		te->SetUndoDepth(undoDepth);
		te->SetRightMarginWidth(itsRightMarginCB->IsChecked(), rightMargin);

		te->SetDefaultFontStyle(itsColor [ CBPrefsManager::kTextColorIndex-1 ]);
		te->SetBackColor(itsColor [ CBPrefsManager::kBackColorIndex-1 ]);
		te->SetFocusColor(itsColor [ CBPrefsManager::kBackColorIndex-1 ]);
		te->SetCaretColor(itsColor [ CBPrefsManager::kCaretColorIndex-1 ]);
		te->SetSelectionColor(itsColor [ CBPrefsManager::kSelColorIndex-1 ]);
		te->SetSelectionOutlineColor(itsColor [ CBPrefsManager::kSelLineColorIndex-1 ]);
		te->SetRightMarginColor(itsColor [ CBPrefsManager::kRightMarginColorIndex-1 ]);

		if (textColorChanged)
			{
			te->RecalcStyles();
			}

		// force update of insertion font

		JIndex caretIndex;
		if (te->GetCaretLocation(&caretIndex))
			{
			te->SetCaretLocation(caretIndex);
			}

		pg->IncrementProgress();
		}

	CBFnMenuUpdater* updater = CBGetFnMenuUpdater();
	updater->ShouldSortFnNames(itsSortFnMenuCB->IsChecked());
	updater->ShouldIncludeNamespace(itsNSInFnMenuCB->IsChecked());
	updater->ShouldPackFnNames(itsPackFnMenuCB->IsChecked());

	JXTEBase::SetPartialWordModifier(
		(JXTEBase::PartialWordModifier) itsPWModRG->GetSelectedItem());

	JXTEBase::ShouldUseWindowsHomeEnd(itsHomeEndCB->IsChecked());
	CBTextEditor::CaretShouldFollowScroll(itsScrollCaretCB->IsChecked());
	JTextEditor::ShouldCopyWhenSelect(itsCopyWhenSelectCB->IsChecked());
	JXTEBase::MiddleButtonShouldPaste(itsMiddleButtonPasteCB->IsChecked());

	CBSearchTextDialog* dlog = CBGetSearchTextDialog();
	dlog->SetFont(fontName, fontSize);

	itsDoc->JPrefObject::WritePrefs();

	if (itsEmulatorIndex != itsOrigEmulatorIndex)
		{
		prefsMgr->SetEmulator(kMenuIndexToEmulator[ itsEmulatorIndex-1 ]);
		}

	CBMWriteSharedPrefs(kJTrue);

	pg->ProcessFinished();
	jdelete pg;
}
Пример #15
0
JBoolean
JXPathInput::InputValid()
{
	if (itsAllowInvalidPathFlag)
		{
		return kJTrue;
		}
	else if (!JXInputField::InputValid())
		{
		return kJFalse;
		}

	const JString& text = GetText();
	if (text.IsEmpty())		// paranoia -- JXInputField should have reported
		{
		return JNegate(IsRequired());
		}

	JString path;
	if (JIsRelativePath(text) && !HasBasePath())
		{
		(JGetUserNotification())->ReportError(JGetString(kNoRelPathID));
		RecalcAll(kJTrue);
		return kJFalse;
		}
	if (!JConvertToAbsolutePath(text, itsBasePath, &path))
		{
		(JGetUserNotification())->ReportError(JGetString(kInvalidPathID));
		RecalcAll(kJTrue);
		return kJFalse;
		}

	const JString currDir = JGetCurrentDirectory();
	const JError err      = JChangeDirectory(path);
	JChangeDirectory(currDir);

	if (err.OK())
		{
		if (!JDirectoryReadable(path))
			{
			(JGetUserNotification())->ReportError(JGetString(kUnreadableID));
			RecalcAll(kJTrue);
			return kJFalse;
			}
		else if (itsRequireWriteFlag && !JDirectoryWritable(path))
			{
			(JGetUserNotification())->ReportError(JGetString(kUnwritableID));
			RecalcAll(kJTrue);
			return kJFalse;
			}
		else
			{
			return kJTrue;
			}
		}

	const JCharacter* errID;
	if (err == kJAccessDenied)
		{
		errID = kAccessDeniedID;
		}
	else if (err == kJBadPath)
		{
		errID = kBadPathID;
		}
	else if (err == kJComponentNotDirectory)
		{
		errID = kCompNotDirID;
		}
	else
		{
		errID = kInvalidDirID;
		}

	(JGetUserNotification())->ReportError(JGetString(errID));
	RecalcAll(kJTrue);
	return kJFalse;
}
Пример #16
0
JBoolean
JXFontManager::GetFontSizes
	(
	const JCharacter*	name,
	JSize*				minSize,
	JSize*				maxSize,
	JArray<JSize>*		sizeList
	)
	const
{
	*minSize = *maxSize = 0;
	sizeList->RemoveAll();
	sizeList->SetCompareFunction(JCompareSizes);
	sizeList->SetSortOrder(JOrderedSetT::kSortAscending);

#ifdef _J_USE_XFT
	XftFontSet* fs = XftListFonts(*itsDisplay, DefaultScreen((Display*)*itsDisplay), XFT_FAMILY, XftTypeString, name, 0, XFT_SIZE, 0);

	if (fs->nfont == 0)
	{
		*minSize = 8;
		*maxSize = 24;
		XftFontSetDestroy(fs);		
		return kJTrue;
	}

	for (int i=0; i<fs->nfont; i++)
	{
		double raw_size;
		if (XftPatternGetDouble(fs->fonts[i], XFT_SIZE, 0, &raw_size) == XftResultMatch)
		{
			JSize fontSize = static_cast<JSize>(raw_size);
			if (sizeList->IsEmpty())
			{
				*minSize = *maxSize = fontSize;
			}

			JBoolean isDuplicate;
			const JIndex index =
				sizeList->GetInsertionSortIndex(fontSize, &isDuplicate);
			if (!isDuplicate)
			{
				sizeList->InsertElementAtIndex(index, fontSize);

				if (fontSize < *minSize)
				{
					*minSize = fontSize;
				}
				else if (fontSize > *maxSize)
				{
					*maxSize = fontSize;
				}
			}
		}
	}
	
	// Look for scalable
	if ((*minSize == 0) && (*maxSize == 0))
	{
		*minSize = 8;
		*maxSize = 24;
		XftFontSetDestroy(fs);		
		return kJTrue;
	}
	
	XftFontSetDestroy(fs);		
#else
	JString xFontName, charSet;
	if (!ConvertToXFontName(name, &xFontName, &charSet))
		{
		charSet = "*-*";
		}

	// check for rescalable font

	JString regexStr = "-*-" + xFontName + "-*-*-*-*-*-0-75-75-*-*-" + charSet;

	int nameCount;
	char** nameList = XListFonts(*itsDisplay, regexStr, INT_MAX, &nameCount);
	if (nameList != NULL)
		{
		*minSize = 8;
		*maxSize = 24;
		XFreeFontNames(nameList);
		return kJTrue;
		}

	// get list of available sizes

	regexStr = "-*-" + xFontName + "-*-*-*-*-*-*-75-75-*-*-" + charSet;

	nameList = XListFonts(*itsDisplay, regexStr, INT_MAX, &nameCount);
	if (nameList == NULL)
		{
		return kJFalse;
		}

	JSize fontSize;
	for (int i=0; i<nameCount; i++)
		{
		const std::string s(nameList[i], strlen(nameList[i]));
		std::istringstream input(s);
		input.ignore();							// initial dash
		JIgnoreUntil(input, '-');				// foundry name
		JIgnoreUntil(input, '-');				// font name
		JIgnoreUntil(input, '-');				// medium/bold
		JIgnoreUntil(input, '-');				// roman/oblique/italic
		JIgnoreUntil(input, '-');				// character spacing
		input.ignore();							// extra dash
		JIgnoreUntil(input, '-');				// pixel height
		input >> fontSize;						// 10*(point size)

		if (fontSize < 10)
			{
			continue;		// we already checked for rescalable version
			}

		fontSize /= 10;
		if (sizeList->IsEmpty())
			{
			*minSize = *maxSize = fontSize;
			}

		JBoolean isDuplicate;
		const JIndex index =
			sizeList->GetInsertionSortIndex(fontSize, &isDuplicate);
		if (!isDuplicate)
			{
			sizeList->InsertElementAtIndex(index, fontSize);

			if (fontSize < *minSize)
				{
				*minSize = fontSize;
				}
			else if (fontSize > *maxSize)
				{
				*maxSize = fontSize;
				}
			}
		}

	XFreeFontNames(nameList);
#endif

	return JNegate( sizeList->IsEmpty() );
}
JBoolean
JIsMounted
	(
	const JCharacter*	path,
	JBoolean*			writable,
	JBoolean*			isTop,
	JString*			device,
	JFileSystemType*	fsType,
	JString*			fsTypeString
	)
{
	struct stat stbuf1, stbuf2;
	if (stat(path, &stbuf1) != 0)
		{
		return kJFalse;
		}

	JBoolean isMounted = kJFalse;

	struct statfs* info;
	const JSize count = getmntinfo(&info, MNT_WAIT);

	JString p;
	for (JIndex i=0; i<count; i++)
		{
		if (strcmp(info[i].f_mntonname, "/") != 0 &&
			stat(info[i].f_mntonname, &stbuf2) == 0 &&
			stbuf1.st_dev == stbuf2.st_dev)
			{
			isMounted = kJTrue;
			if (writable != NULL)
				{
				*writable = JNegate((info[i].f_flags & MNT_RDONLY) != 0);
				}
			if (isTop != NULL)
				{
				*isTop = JI2B(stbuf1.st_ino == stbuf2.st_ino);
				}
			if (device != NULL)
				{
				*device = info[i].f_mntfromname;
				}
			if (fsType != NULL)
				{
				*fsType = kOtherFSType;
				if (JStringCompare(info[i].f_fstypename, "vfat", kJFalse) == 0 ||	// UNIX
					JStringCompare(info[i].f_fstypename, "msdos", kJFalse) == 0)	// OSX
					{
					*fsType = kVFATType;
					}
				}
			if (fsTypeString != NULL)
				{
				*fsTypeString = info[i].f_fstypename;
				}
			break;
			}
		}

	return isMounted;
}
JBoolean
JVIKeyHandler::HandleKeyPress
	(
	const JCharacter				key,
	const JBoolean					selectText,
	const JTextEditor::CaretMotion	motion,
	const JBoolean					deleteToTabStop
	)
{
	JBoolean result;
	if (PrehandleKeyPress(key, &result))
		{
		return result;
		}

	if (key == kJLeftArrow || key == kJRightArrow ||
		key == kJUpArrow || key == kJDownArrow)
		{
		ClearKeyBuffers();
		return kJFalse;
		}

	JTextEditor* te = GetTE();

	JBoolean clearKeyBuffer = kJTrue;
	JArray<JIndexRange> matchList;
	JCharacter prevChar;
	if (key == 'i')
		{
		SetMode(kTextEntryMode);
		}
	else if (key == 'I')
		{
		SetMode(kTextEntryMode);

		const JBoolean save = te->WillMoveToFrontOfText();
		te->ShouldMoveToFrontOfText(kJTrue);
		te->GoToEndOfLine();
		te->GoToBeginningOfLine();
		te->ShouldMoveToFrontOfText(save);
		}
	else if (key == 'a')
		{
		SetMode(kTextEntryMode);
		const JIndex i = te->GetInsertionIndex();
		if (te->IndexValid(i) && (te->GetText()).GetCharacter(i) != '\n')
			{
			te->SetCaretLocation(te->GetInsertionIndex()+1);
			}
		}
	else if (key == 'A')
		{
		SetMode(kTextEntryMode);
		te->GoToEndOfLine();
		}
	else if (key == 'O')
		{
		SetMode(kTextEntryMode);

		te->GoToBeginningOfLine();
		const JIndex i = te->GetInsertionIndex();
		te->SetCaretLocation(i-1);
		InsertKeyPress('\n');
		if (i == 1)
			{
			te->SetCaretLocation(1);
			}
		}
	else if (key == 'o')
		{
		SetMode(kTextEntryMode);

		te->GoToEndOfLine();
		InsertKeyPress('\n');
		}

	else if ((key == '0' || key == '^') && itsKeyBuffer.IsEmpty())
		{
		te->GoToBeginningOfLine();
		}
	else if (key == '\n')
		{
		MoveCaretVert(1);

		const JBoolean save = te->WillMoveToFrontOfText();
		te->ShouldMoveToFrontOfText(kJTrue);
		te->GoToEndOfLine();
		te->GoToBeginningOfLine();
		te->ShouldMoveToFrontOfText(save);
		}
	else if (key == 'G')
		{
		te->SetCaretLocation(te->GetTextLength()+1);
		}

	else if (isdigit(key))	// after 0 => beginning of line
		{
		if (!numberPattern.Match(itsKeyBuffer))
			{
			ClearKeyBuffers();
			}
		itsKeyBuffer.AppendCharacter(key);
		clearKeyBuffer = kJFalse;
		}
	else if (key == '"')
		{
		itsMode = kBufferNameMode;		// don't use SetMode()
		itsKeyBuffer.AppendCharacter(key);
		clearKeyBuffer = kJFalse;
		}
	else if (key == 'X' || key == 'x')
		{
		CutBuffer* buf = GetCutBuffer(cutbufPattern);
		buf->Set("", kJFalse);

		const JSize count = GetOperationCount();
		JString s;
		for (JIndex i=1; i<=count; i++)
			{
			if (key == 'X')
				{
				if (te->GetInsertionIndex() == 1)
					{
					break;
					}
				BackwardDelete(deleteToTabStop, &s);
				}
			else
				{
				if (te->GetInsertionIndex() >= te->GetTextLength())
					{
					break;
					}
				ForwardDelete(deleteToTabStop, &s);
				}

			buf->buf->Append(s);
			}
		}
	else if (key == 'C' || key == 'D' ||
			 (key == '$' && GetPrevCharacter(&prevChar) &&
			  (prevChar == 'd' || prevChar == 'y')))
		{
		const JBoolean del = JNegate(GetPrevCharacter(&prevChar) && prevChar == 'y' && key == '$');
		YankToEndOfLine(del, JI2B(key == 'C'));
		}
	else if ((key == 'Y' || key == 'y' || key == 'd') &&
			 yankDeletePattern.Match(itsKeyBuffer, &matchList))
		{
		if (key == 'Y' ||
			(GetPrevCharacter(&prevChar) && prevChar == key))
			{
			YankLines(matchList, JI2B(key == 'd'));
			}
		else
			{
			itsKeyBuffer.AppendCharacter(key);
			clearKeyBuffer = kJFalse;
			}
		}

	else if (key == 'P' || key == 'p')
		{
		CutBuffer* buf = GetCutBuffer(cutbufPattern);
		if (buf->buf != NULL)
			{
			const JIndex i = te->GetInsertionIndex();
			if (buf->line)
				{
				te->GoToBeginningOfLine();
				if (key == 'p')
					{
					MoveCaretVert(1);
					}
				}
			else if (key == 'p' &&
					 (te->IndexValid(i) && (te->GetText()).GetCharacter(i) != '\n'))
				{
				te->SetCaretLocation(te->GetInsertionIndex()+1);
				}

			const JSize count = GetOperationCount();
			for (JIndex i=1; i<=count; i++)
				{
				te->Paste(*(buf->buf));
				}
			}
		}

	else if (key == 'u')
		{
		te->Undo();
		}

	else if (key == '$')	// after d$ and y$
		{
		te->GoToEndOfLine();
		const JIndex i = te->GetInsertionIndex();
		if (i > 1 && te->IndexValid(i) &&
			(te->GetText()).GetCharacter(i) == '\n')
			{
			te->SetCaretLocation(i-1);
			}
		}

	if (clearKeyBuffer)
		{
		ClearKeyBuffers();
		}
	return kJTrue;
}
Пример #19
0
JBoolean
JXFontManager::GetFontCharSets
	(
	const JCharacter*	name,
	const JSize			size,
	JPtrArray<JString>*	charSetList
	)
	const
{
	charSetList->CleanOut();
	charSetList->SetCompareFunction(JCompareStringsCaseInsensitive);
	charSetList->SetSortOrder(JOrderedSetT::kSortAscending);

	JString xFontName, charSet;
	ConvertToXFontName(name, &xFontName, &charSet);		// strip charSet

	const JString regexStr =
		"-*-" + xFontName + "-*-*-*-*-*-" +
		JString(10*size, 0, JString::kForceNoExponent) +
		"-75-75-*-*-*-*";

	int nameCount;
	char** nameList = XListFonts(*itsDisplay, regexStr, INT_MAX, &nameCount);
	if (nameList == NULL)
		{
		return kJFalse;
		}

	for (int i=0; i<nameCount; i++)
		{
		const std::string s(nameList[i], strlen(nameList[i]));
		std::istringstream input(s);
		input.ignore();							// initial dash
		JIgnoreUntil(input, '-');				// foundry name
		JIgnoreUntil(input, '-');				// font name
		JIgnoreUntil(input, '-');				// medium/bold
		JIgnoreUntil(input, '-');				// roman/oblique/italic
		JIgnoreUntil(input, '-');				// character spacing
		input.ignore();							// extra dash
		JIgnoreUntil(input, '-');				// pixel height
		JIgnoreUntil(input, '-');				// 10*(point size)
		JIgnoreUntil(input, '-');				// x resolution
		JIgnoreUntil(input, '-');				// y resolution
		JIgnoreUntil(input, '-');				// ?
		JIgnoreUntil(input, '-');				// ?
		JReadAll(input, &charSet);

		JBoolean isDuplicate;
		const JIndex index =
			charSetList->GetInsertionSortIndex(&charSet, &isDuplicate);
		if (!isDuplicate)
			{
			JString* s = new JString(charSet);
			assert( s != NULL );
			charSetList->InsertElementAtIndex(index, s);
			}
		}

	XFreeFontNames(nameList);
	return JNegate( charSetList->IsEmpty() );
}
void
JXFSBindingManager::ProcessFiles()
{
    if (!HasFiles() || itsRunFileDialog != NULL)
    {
        return;
    }

    // check for file with no command

    JSize count = itsFileList->GetElementCount();
    for (JIndex i=1; i<=count; i++)
    {
        JFSBinding* f           = itsFileList->NthElement(i);
        const JString& fileName = f->GetPattern();

        JFSBinding::CommandType type;
        JBoolean singleFile;
        const JString& cmd = f->GetCommand(&type, &singleFile);

        const JFSBinding* b;
        if (!itsIgnoreBindingsFlag &&
                cmd.IsEmpty() && itsBindingList->GetBinding(fileName, &b))
        {
            const JString& cmd = b->GetCommand(&type, &singleFile);
            f->SetCommand(cmd, type, singleFile);
        }
        else if (cmd.IsEmpty())
        {
            assert( itsRunFileDialog == NULL );
            itsRunFileDialog =
                new JXFSRunFileDialog(fileName, JNegate(count > 1 && itsIgnoreBindingsFlag));
            assert( itsRunFileDialog != NULL );
            ListenTo(itsRunFileDialog);
            itsRunFileDialog->BeginDialog();
            itsRunFileIndex = i;
            return;
        }
    }

    // exec one-at-a-time cmds

    (JXGetApplication())->DisplayBusyCursor();

    for (JIndex i=1; i<=count; i++)
    {
        JFSBinding::CommandType t;
        JBoolean singleFile;
        (itsFileList->NthElement(i))->GetCommand(&t, &singleFile);

        if (singleFile)
        {
            Exec(i, i);
            itsFileList->DeleteElement(i);
            count--;
            i--;	// compensate for shift
        }
    }

    // group remaining files and exec

    if (count > 0)
    {
        itsFileList->SetCompareFunction(CompareCommands);
        itsFileList->Sort();

        JIndex startIndex = 1;
        JString cmd;
        JFSBinding::CommandType type = JFSBinding::kRunPlain;

        for (JIndex i=1; i<=count; i++)
        {
            JFSBinding* f           = itsFileList->NthElement(i);
            const JString& fileName = f->GetPattern();

            JFSBinding::CommandType t;
            JBoolean singleFile;
            const JString& c = f->GetCommand(&t, &singleFile);
            assert( !singleFile );

            if (i == startIndex)
            {
                cmd  = c;
                type = t;
            }
            else if (c != cmd || type != t)
            {
                Exec(startIndex, i-1);

                startIndex = i;
                cmd        = c;
                type       = t;
            }
        }

        Exec(startIndex, count);
    }

    delete itsFileList;
    itsFileList = NULL;
}