Beispiel #1
0
JBoolean
SVNTabBase::ExecuteDiff
	(
	const JCharacter*	origCmd,
	const JCharacter*	rev,
	const JBoolean		isPrev
	)
{
	JPtrArray<JString> fileList(JPtrArrayT::kDeleteAll);
	JArray<JIndex> revList;
	GetSelectedFilesForDiff(&fileList, &revList);
	if (fileList.IsEmpty())
		{
		return kJFalse;
		}

	(JXGetApplication())->DisplayBusyCursor();

	JSubstitute subst;
	subst.DefineVariable("rev_option", rev);
	const JBoolean customPrev = JI2B( isPrev && !revList.IsEmpty() );

	const JSize count = fileList.GetElementCount();
	JString cmd, fullName, r;
	for (JIndex i=1; i<=count; i++)
		{
		cmd      = origCmd;
		fullName = JPrepArgForExec(*(fileList.NthElement(i)));

		if (customPrev)
			{
			const JIndex j = revList.GetElement(i);
			r  = JString(j-1, JString::kBase10);
			r += ":";
			r += JString(j, JString::kBase10);
			subst.DefineVariable("rev_option", r);
			}

		subst.DefineVariable("file_name", fullName);
		subst.Substitute(&cmd);

		if (itsDirector->HasPath())
			{
			JSimpleProcess::Create(itsDirector->GetPath(), cmd, kJTrue);
			}
		else
			{
			JSimpleProcess::Create(cmd, kJTrue);
			}
		}

	return kJTrue;
}
static JBoolean
jGetUserInfo
	(
	const uid_t uid,
	jUIDInfo*	info
	)
{
	if (theUserInfoMap.IsEmpty())
		{
		theUserInfoMap.SetCompareFunction(jCompareUIDs);
		theUserInfoMap.SetSortOrder(JOrderedSetT::kSortAscending);
		atexit(jCleanUserInfoMap);
		}

	const jUIDInfo target = { uid, NULL, NULL };
	JIndex i;
	if (theUserInfoMap.SearchSorted(target, JOrderedSetT::kAnyMatch, &i))
		{
		*info = theUserInfoMap.GetElement(i);
		}
	else
		{
		passwd* pwbuf = getpwuid(uid);
		if (pwbuf != NULL)
			{
			info->userName = new JString(pwbuf->pw_name);
			assert( info->userName != NULL );

			info->realName = new JString(pwbuf->pw_gecos);
			assert( info->realName != NULL );

			info->homeDirectory = new JString(pwbuf->pw_dir);
			assert( info->homeDirectory != NULL );

			info->shell = new JString(pwbuf->pw_shell);
			assert( info->shell != NULL );

			info->id = uid;
			const JBoolean inserted = theUserInfoMap.InsertSorted(*info, kJFalse);
			assert( inserted );
			}
		else
			{
			info->userName = info->realName = info->homeDirectory = info->shell = NULL;
			}
		}

	return JI2B( info->userName != NULL );
}
void
JXComposeRuleList::AddRule
	(
	const JArray<KeySym>&	inputSeq,
	const KeySym			outputKeySym
	)
{
	assert( !inputSeq.IsEmpty() );

	if (!IsInitialKeySym(inputSeq.GetFirstElement()))
		{
		itsInitialKeySymList->AppendElement(inputSeq.GetFirstElement());
		}

	Rule r(jnew JArray<KeySym>(inputSeq), outputKeySym);
	assert( r.inputSeq != NULL );
	itsRuleList->InsertSorted(r);
}
static JBoolean
jGetGroupInfo
	(
	const gid_t	gid,
	jGIDInfo*	info
	)
{
	if (groupInfoMap.IsEmpty())
		{
		groupInfoMap.SetCompareFunction(jCompareGIDs);
		groupInfoMap.SetSortOrder(JOrderedSetT::kSortAscending);
		}

	const jGIDInfo target = { gid, NULL };
	JIndex i;
	if (groupInfoMap.SearchSorted(target, JOrderedSetT::kAnyMatch, &i))
		{
		*info = groupInfoMap.GetElement(i);
		}
	else
		{
		group* grpbuf = getgrgid(gid);
		if (grpbuf != NULL)
			{
			info->groupName = new JString(grpbuf->gr_name);
			assert( info->groupName != NULL );

			info->id = gid;
			const JBoolean inserted = groupInfoMap.InsertSorted(*info, kJFalse);
			assert( inserted );
			}
		else
			{
			info->groupName = NULL;
			}
		}

	return JI2B( info->groupName != NULL );
}
Beispiel #5
0
JBoolean
SVNTabBase::ExecuteJCCDiff
	(
	const JString&	rev,
	const JBoolean	isPrev
	)
{
	JPtrArray<JString> fileList(JPtrArrayT::kDeleteAll);
	JArray<JIndex> revList;
	GetSelectedFilesForDiff(&fileList, &revList);
	if (fileList.IsEmpty())
		{
		return kJFalse;
		}

	const JBoolean customPrev = JI2B( isPrev && !revList.IsEmpty() );

	const JSize count = fileList.GetElementCount();
	JString cmd, s, fullName;
	JSubstitute subst;
	for (JIndex i=1; i<=count; i++)
		{
		if (customPrev)
			{
			const JIndex j = revList.GetElement(i);
			s  = JString(j-1, JString::kBase10);
			s += ":";
			s += JString(j, JString::kBase10);
			}
		else
			{
			s = rev;
			}
		s += " $file_name";

		fullName = JPrepArgForExec(*(fileList.NthElement(i)));
		subst.DefineVariable("file_name", fullName);
		subst.Substitute(&s);

		if (count == 1)
			{
			s.Prepend(" --svn-diff ");
			}
		else
			{
			s.Prepend(" --svn-diff-silent ");
			}

		cmd += s;
		}

	cmd.Prepend("jcc");

	if (itsDirector->HasPath())
		{
		JSimpleProcess::Create(itsDirector->GetPath(), cmd, kJTrue);
		}
	else
		{
		JSimpleProcess::Create(cmd, kJTrue);
		}

	return kJTrue;
}
JParseResult
JParseAsSummation
	(
	const JCharacter*		origExpr,
	const JSize				origLength,
	const JVariableList*	theVariableList,
	JFunction**				theFunction,
	const JBoolean			allowUIF
	)
{
	*theFunction = NULL;

	// remove enclosing parentheses

	const JCharacter* expr = origExpr;
	const JSize length     = JStripParentheses(&expr, origLength);

	// build a list of the locations of all visible + and - operators

	const JCharacter* plusStr  = JPGetAdditionString();
	const JSize plusLength     = JPGetAdditionStringLength();
	const JCharacter* minusStr = JPGetSubtractionString();
	const JSize minusLength    = JPGetSubtractionStringLength();

	JArray<JCharacter> opList;
	JArray<JSize> opOffsetList;
	JArray<JSize> argOffsetList;
	JSize lastOffset = 0;
	while (1)
		{
		JSize plusOffset;
		const JBoolean foundPlus =
			JFindFirstOperator(expr + lastOffset, length - lastOffset,
							   plusStr, &plusOffset);
		plusOffset += lastOffset;

		JSize minusOffset;
		const JBoolean foundMinus =
			JFindFirstOperator(expr + lastOffset, length - lastOffset,
							   minusStr, &minusOffset);
		minusOffset += lastOffset;

		JCharacter opType;
		JSize opOffset, argOffset;
		if (foundPlus && foundMinus && plusOffset < minusOffset)
			{
			opType = '+';
			opOffset  = plusOffset;
			argOffset = plusOffset + plusLength;
			}
		else if (foundPlus && foundMinus && minusOffset < plusOffset)
			{
			opType = '-';
			opOffset  = minusOffset;
			argOffset = minusOffset + minusLength;
			}
		else if (foundPlus)
			{
			opType = '+';
			opOffset  = plusOffset;
			argOffset = plusOffset + plusLength;
			}
		else if (foundMinus)
			{
			opType = '-';
			opOffset  = minusOffset;
			argOffset = minusOffset + minusLength;
			}
		else
			{
			break;
			}

		if (!JIsExponentSign(expr, opOffset, argOffset))
			{
			opList.AppendElement(opType);
			opOffsetList.AppendElement(opOffset);
			argOffsetList.AppendElement(argOffset);
			}

		lastOffset = argOffset;
		}

	if (opList.IsEmpty())
		{
		return kJNotMyProblem;
		}
	else if (opList.GetElementCount() == 1 && opOffsetList.GetElement(1) == 0)
		{
		const JSize argOffset = argOffsetList.GetElement(1);
		JFunction* arg = NULL;
		if (!JRecurseFunction(expr + argOffset, length - argOffset, theVariableList,
							  &arg, allowUIF))
			{
			return kJParseError;
			}

		if (opList.GetElement(1) == '-')
			{
			*theFunction = new JNegation(arg);
			assert( *theFunction != NULL );
			return kJParsedOK;
			}
		else	// we ignore leading +
			{
			*theFunction = arg;
			return kJParsedOK;
			}
		}
	else
		{
		JSummation* sum = new JSummation;
		assert( sum != NULL );

		// No operand in front means implied +

		if (opOffsetList.GetElement(1) > 0)
			{
			opList.PrependElement('+');
			opOffsetList.PrependElement(0);
			argOffsetList.PrependElement(0);
			}

		// We append an extra element at the end of the list
		// so our loop catches the last summand.

		opList.AppendElement('+');
		opOffsetList.AppendElement(length);
		argOffsetList.AppendElement(length);

		// Parse each summand

		const JSize opCount = opList.GetElementCount();
		for (JIndex i=1; i<opCount; i++)
			{
			const JCharacter opType = opList.GetElement(i);
			const JSize startOffset = argOffsetList.GetElement(i);
			const JSize endOffset   = opOffsetList.GetElement(i+1);

			JFunction* arg = NULL;
			if (!JRecurseFunction(expr + startOffset, endOffset - startOffset,
								  theVariableList, &arg, allowUIF))
				{
				delete sum;
				return kJParseError;
				}
			else if (opType == '+')
				{
				sum->SetArg(i, arg);
				}
			else	// opType == '-'
				{
				JNegation* negArg = new JNegation(arg);
				assert( negArg != NULL );
				sum->SetArg(i, negArg);
				}
			}

		*theFunction = sum;
		return kJParsedOK;
		}
}
Beispiel #7
0
TestWidget::TestWidget
(
    const JBoolean		isMaster,
    const JBoolean		isImage,
    const JBoolean		allocDynamicColors,
    JXMenuBar*			menuBar,
    JXScrollbarSet*		scrollbarSet,
    JXContainer*		enclosure,
    const HSizingOption	hSizing,
    const VSizingOption	vSizing,
    const JCoordinate	x,
    const JCoordinate	y,
    const JCoordinate	w,
    const JCoordinate	h
)
    :
    JXScrollableWidget(scrollbarSet, enclosure, hSizing, vSizing, x,y, w,h),
    itsRNG()
{
    JIndex i;

    itsFillFlag       = kJFalse;
    itsNextAnimColor  = (GetColormap())->GetGreenColor();
    itsRandPointCount = 10;
    itsResizeDialog   = NULL;

    // cursors

    JXDisplay* display = GetDisplay();
    itsTrekCursor      = display->CreateBuiltInCursor("XC_trek",     XC_trek);
    itsGumbyCursor     = display->CreateBuiltInCursor("XC_gumby",    XC_gumby);
    itsBogosityCursor  = display->CreateBuiltInCursor("XC_bogosity", XC_bogosity);
    itsFleurCursor     = display->CreateBuiltInCursor("XC_fleur",    XC_fleur);
    SetDefaultCursor(itsTrekCursor);

    // dynamic colors

    itsAnimColorList = new JArray<JColorIndex>(kAnimColorCount);
    assert( itsAnimColorList != NULL );

    JArray<JDynamicColorInfo>* colorList =
        new JArray<JDynamicColorInfo>(kAnimColorCount);
    assert( colorList != NULL );

    JXColormap* colormap = GetColormap();
    if (allocDynamicColors)
    {
        for (i=1; i<=kAnimColorCount; i++)
        {
            JDynamicColorInfo info;
            if (colormap->AllocateDynamicColor(0,0,0, &(info.index)))
            {
                colorList->AppendElement(info);
                itsAnimColorList->AppendElement(info.index);
            }
            else
            {
                cerr << "Unable to allocate dynamic color " << i << endl;
                break;
            }
        }
    }

    if (!colorList->IsEmpty())
    {
        itsAnimColorTask = new AnimateColorTask(colormap, colorList);
        assert( itsAnimColorTask != NULL );
    }
    else
    {
        delete colorList;
        itsAnimColorTask = NULL;
    }

    ListenTo(GetWindow());		// remove AnimateColorTask when iconified

    // menus

    itsActionsMenu = menuBar->AppendTextMenu(kActionsMenuTitleStr);
    itsActionsMenu->SetTitleFontStyle((GetColormap())->GetWhiteColor());
    itsActionsMenu->SetShortcuts(kActionsMenuShortcutStr);
    itsActionsMenu->SetMenuItems(kActionsMenuStr);
    itsActionsMenu->SetUpdateAction(JXMenu::kDisableNone);
    ListenTo(itsActionsMenu);

    itsPointMenu = new JXTextMenu(itsActionsMenu, kPointMenuCmd, menuBar);
    assert( itsPointMenu != NULL );
    itsPointMenu->SetMenuItems(kPointMenuStr);
    itsPointMenu->SetUpdateAction(JXMenu::kDisableNone);
    ListenTo(itsPointMenu);

    // This tests the JX response to an empty menu.
    JXTextMenu* emptyMenu = new JXTextMenu(itsActionsMenu, kEmptyMenuCmd, menuBar);
    assert( emptyMenu != NULL );

    JXMenu* prevMenu     = itsActionsMenu;
    JIndex prevMenuIndex = kAdviceMenuCmd;
    for (i=1; i<=kAdviceMenuCount; i++)
    {
        JXTextMenu* adviceMenu = new JXTextMenu(prevMenu, prevMenuIndex, menuBar);
        assert( adviceMenu != NULL );
        adviceMenu->SetMenuItems(kAdviceMenuStr[i-1]);
        adviceMenu->SetUpdateAction(JXMenu::kDisableNone);

        if (i == kAdviceBoldMenuIndex)
        {
            adviceMenu->SetItemFontStyle(2,
                                         JFontStyle(kJTrue, kJFalse, 0, kJFalse, (GetColormap())->GetBlackColor()));
        }

        prevMenu      = adviceMenu;
        prevMenuIndex = 2;
    }

    BuildXlsfontsMenu(itsActionsMenu, menuBar);

    // secret menus are a bad idea because the user can't find them!

    itsSecretMenu = new JXTextMenu("", this, kFixedLeft, kFixedTop, 0,0, 10,10);
    assert( itsSecretMenu != NULL );
    itsSecretMenu->SetMenuItems(kSecretMenuStr);
    itsSecretMenu->SetUpdateAction(JXMenu::kDisableNone);
    itsSecretMenu->SetToHiddenPopupMenu(kJTrue);		// will assert() otherwise
    itsSecretMenu->Hide();
    ListenTo(itsSecretMenu);

    itsSecretSubmenu = new JXTextMenu(itsSecretMenu, kSecretSubmenuIndex, this);
    assert( itsSecretSubmenu != NULL );
    itsSecretSubmenu->SetMenuItems(kSecretSubmenuStr);
    itsSecretSubmenu->SetUpdateAction(JXMenu::kDisableNone);
    // we don't ListenTo() it because it's only there for show

    // image from xpm

    itsXPMImage = new JXImage(GetDisplay(), GetColormap(), JXPM(macapp_xpm));
    assert( itsXPMImage != NULL );

    // partial image from image

    itsPartialXPMImage = new JXImage(*itsXPMImage, JRect(5,5,14,16));
    assert( itsPartialXPMImage != NULL );

    // home symbol

    itsHomeImage = new JXImage(GetDisplay(), GetColormap(), JXPM(home_xpm));
    assert( itsHomeImage != NULL );

    itsHomeRect = itsHomeImage->GetBounds();
    itsHomeRect.Shift(120, 10);

    // buffer contents of Widget in JXImage

    itsImageBuffer = NULL;
    if (isImage)
    {
        CreateImageBuffer();
    }

    // initial size

    SetBounds(400,400);

    // enclosed objects

    itsAnimButton =
        new JXTextButton("Start", this, JXWidget::kFixedLeft, JXWidget::kFixedTop,
                         37,175, 50,30);
    assert( itsAnimButton != NULL );
    itsAnimButton->SetShortcuts("#A");
    ListenTo(itsAnimButton);

    if (isMaster)
    {
        itsQuitButton =
            new JXTextButton("Quit", this, JXWidget::kFixedRight, JXWidget::kFixedBottom,
                             x,y, 50,30);
        assert( itsQuitButton != NULL );

        JXColormap* colormap = GetColormap();
        itsQuitButton->CenterWithinEnclosure(kJTrue, kJTrue);
        itsQuitButton->SetFontStyle(JFontStyle(kJTrue, kJFalse, 0, kJFalse, colormap->GetRedColor()));
        itsQuitButton->SetNormalColor(colormap->GetCyanColor());
        itsQuitButton->SetPushedColor(colormap->GetBlueColor());

        ListenTo(itsQuitButton);
    }
    else
    {
        itsQuitButton = NULL;
    }

    // drops on iconfied window

    JXWindowIcon* windowIcon;
    const JBoolean hasIconWindow = (GetWindow())->GetIconWidget(&windowIcon);
    assert( hasIconWindow );
    ListenTo(windowIcon);
}