📄 todo.c
字号:
if (fontID != currFontID)
FrmUpdateForm (formID, updateFontChanged);
return (fontID);
}
/***********************************************************************
*
* FUNCTION: SeekRecord
*
* DESCRIPTION: Given the index of a ToDo record, this routine scans
* forwards or backwards for displayable ToDo records.
*
* PARAMETERS: indexP - pointer to the index of a record to start from;
* the index of the record sought is returned in
* this parameter.
*
* offset - number of records to skip:
* 0 - seek from the current record to the
* next display record, if the current record is
* a display record, its index is retuned.
* 1 - seek foreward, skipping one displayable
* record
* -1 - seek backwards, skipping one displayable
* record
*
*
* RETURNED: false is return if a displayable record was not found.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 4/11/95 Initial Revision
*
***********************************************************************/
static Boolean SeekRecord (UInt16* indexP, Int16 offset, Int16 direction)
{
Int32 dateL;
Int32 todayL;
MemHandle recordH;
DateTimeType today;
ToDoDBRecordPtr toDoRec;
ErrFatalDisplayIf ( (offset < -1 || offset > 1) , "Invalid offset");
while (true)
{
DmSeekRecordInCategory (ToDoDB, indexP, offset, direction, CurrentCategory);
if (DmGetLastErr()) return (false);
if ( ShowCompletedItems && (! ShowOnlyDueItems))
return (true);
recordH = DmQueryRecord (ToDoDB, *indexP);
toDoRec = (ToDoDBRecordPtr) MemHandleLock (recordH);
if ( (ShowCompletedItems) || (! (toDoRec->priority & completeFlag)))
{
if (! ShowOnlyDueItems) break;
if (DateToInt (toDoRec->dueDate) == toDoNoDueDate) break;
// Check if the item is due.
TimSecondsToDateTime (TimGetSeconds(), &today);
todayL = ( ((Int32) today.year) << 16) +
( ((Int32) today.month) << 8) +
((Int32) today.day);
dateL = ( ((Int32) toDoRec->dueDate.year + firstYear) << 16) +
( ((Int32) toDoRec->dueDate.month) << 8) +
((Int32) toDoRec->dueDate.day);
if (dateL <= todayL) break;
}
if (offset == 0) offset = 1;
MemHandleUnlock (recordH);
}
MemHandleUnlock (recordH);
return (true);
}
/***********************************************************************
*
* FUNCTION: GetToDoNotePtr
*
* DESCRIPTION: This routine returns a pointer to the note field in a to
* do record.
*
* PARAMETERS: recordP - pointer to a ToDo record
*
* RETURNED: pointer to a null-terminated note
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 4/15/95 Initial Revision
*
***********************************************************************/
Char* GetToDoNotePtr (ToDoDBRecordPtr recordP)
{
return (&recordP->description + StrLen (&recordP->description) + 1);
}
/***********************************************************************
*
* FUNCTION: DirtyRecord
*
* DESCRIPTION: Mark a record dirty (modified). Record marked dirty
* will be synchronized.
*
* PARAMETERS: index
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 4/15/95 Initial Revision
*
***********************************************************************/
static void DirtyRecord (UInt16 index)
{
UInt16 attr;
DmRecordInfo (ToDoDB, index, &attr, NULL, NULL);
attr |= dmRecAttrDirty;
DmSetRecordInfo (ToDoDB, index, &attr, NULL);
}
/***********************************************************************
*
* FUNCTION: DeleteRecord
*
* DESCRIPTION: This routine deletes the selected ToDo item.
*
* PARAMETERS: nothing
*
* RETURNED: true if the delete occurred, false if it was canceled.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 9/30/95 Initial Revision
*
***********************************************************************/
static Boolean DeleteRecord (UInt16 index)
{
UInt16 ctlIndex;
UInt16 buttonHit;
FormPtr alert;
Boolean saveBackup;
// Display an alert to comfirm the operation.
alert = FrmInitForm (DeleteToDoDialog);
ctlIndex = FrmGetObjectIndex (alert, DeleteToDoSaveBackup);
FrmSetControlValue (alert, ctlIndex, SaveBackup);
buttonHit = FrmDoDialog (alert);
saveBackup = FrmGetControlValue (alert, ctlIndex);;
FrmDeleteForm (alert);
if (buttonHit == DeleteToDoCancel)
return (false);
SaveBackup = saveBackup;
// Delete or archive the record.
if (SaveBackup)
DmArchiveRecord (ToDoDB, index);
else
DmDeleteRecord (ToDoDB, index);
DmMoveRecord (ToDoDB, index, DmNumRecords (ToDoDB));
return (true);
}
/***********************************************************************
*
* FUNCTION: ClearEditState
*
* DESCRIPTION: This routine take the application out of edit mode.
* The edit state of the current record is remember until
* this routine is called.
*
* If the current record is empty, it will be deleted
* by this routine.
*
* PARAMETERS: nothing
*
* RETURNED: true is current record is deleted by this routine.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/14/95 Initial Revision
*
***********************************************************************/
static Boolean ClearEditState (void)
{
UInt16 recordNum;
Boolean empty;
MemHandle recordH;
ToDoDBRecordPtr recordP;
if (!ItemSelected)
{
CurrentRecord = noRecordSelected;
return (false);
}
recordNum = CurrentRecord;
// Clear the global variables that keeps track of the edit start of the
// current record.
ItemSelected = false;
CurrentRecord = noRecordSelected;
ListEditPosition = 0;
ListEditSelectionLength = 0;
PendingUpdate = 0;
// If the description field is empty and the note field is empty, delete
// the ToDo record.
recordH = DmQueryRecord (ToDoDB, recordNum);
recordP = MemHandleLock (recordH);
empty = (! recordP->description) && (! *GetToDoNotePtr(recordP));
MemHandleUnlock (recordH);
if (empty)
{
// If the description was not modified, and the description and
// note fields are empty, remove the record from the database.
// This can occur when a new empty record is deleted.
if (RecordDirty)
{
DmDeleteRecord (ToDoDB, recordNum);
DmMoveRecord (ToDoDB, recordNum, DmNumRecords (ToDoDB));
}
else
DmRemoveRecord (ToDoDB, recordNum);
return (true);
}
return (false);
}
/***********************************************************************
*
* FUNCTION: DetemineDueDate
*
* DESCRIPTION: This routine is called when an item of the "due date"
* popup list is selected. For items such as "today" and
* "end of week" the due date is computed, for "select
* date" the date picker is displayed.
*
* PARAMETERS: item selected in due date popup list.
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 5/31/95 Initial Revision
*
***********************************************************************/
static void DetermineDueDate (UInt16 itemSelected, DateType * dueDateP)
{
Int16 month, day, year;
Int32 adjustment;
UInt32 timeInSeconds;
Char* titleP;
MemHandle titleH;
DateTimeType date;
// "No due date" items selected?
if (itemSelected == noDueDateItem)
{
*((Int16*) dueDateP) = -1;
return;
}
// "Select date" item selected?
else if (itemSelected == selectDateItem)
{
if ( *((Int16*) dueDateP) == -1)
{
timeInSeconds = TimGetSeconds ();
TimSecondsToDateTime (timeInSeconds, &date);
year = date.year;
month = date.month;
day = date.day;
}
else
{
year = dueDateP->year + firstYear;
month = dueDateP->month;
day = dueDateP->day;
}
titleH = DmGetResource (strRsc, DueDateTitleStr);
titleP = (Char*) MemHandleLock (titleH);
if (SelectDay (selectDayByDay, &month, &day, &year, titleP))
{
dueDateP->day = day;
dueDateP->month = month;
dueDateP->year = year - firstYear;
}
MemHandleUnlock (titleH);
return;
}
// "Today" item seleted?
else if (itemSelected == dueTodayItem)
adjustment = 0;
// "Tomorrow" item selected?
else if (itemSelected == dueTomorrowItem)
adjustment = daysInSeconds;
// "One week later" item selected?
else if (itemSelected == dueOneWeekLaterItem)
{
adjustment = ((Int32) daysInSeconds) * ((Int32) daysInWeek);
}
timeInSeconds = TimGetSeconds ();
TimSecondsToDateTime (timeInSeconds, &date);
TimAdjust (&date, adjustment);
dueDateP->year = date.year - firstYear;
dueDateP->month = date.month;
dueDateP->day = date.day;
}
#pragma mark ----------------
/***********************************************************************
*
* FUNCTION: OptionsApply
*
* DESCRIPTION: This routine applies the changes made in the Options Dialog
* (aka Preferences).
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 5/23/95 Initial Revision
* rbb 4/14/99 Uses GetObjectValue (trimming a few bytes of code)
*
***********************************************************************/
static void OptionsApply (void)
{
UInt8 sortOrder;
UInt16 listItem;
Int16 val;
// Update the sort order. Reset the ToDo list to the top.
listItem = LstGetSelection (GetObjectPtr (OptionsSortByList));
switch (listItem)
{
case priorityDueDateItem: sortOrder = soPriorityDueDate; break;
case dueDatePriorityItem: sortOrder = soDueDatePriority; break;
case categoryPriorityItem: sortOrder = soCategoryPriority; break;
case categoryDueDateItem: sortOrder = soCategoryDueDate; break;
}
if (ToDoGetSortOrder (ToDoDB) != sortOrder)
{
ToDoChangeSortOrder (ToDoDB, sortOrder);
TopVisibleRecord = 0;
}
// Show or hide items marked complete. Reset the list to the top.
val = GetObjectValue (OptionsShowCompleted);
if (ShowCompletedItems != val)
{
ShowCompletedItems = val;
TopVisibleRecord = 0;
}
// Show only items due today or show all items (in the current
// category).
val = GetObjectValue (OptionsShowDueItems);
if (ShowOnlyDueItems != val)
{
ShowOnlyDueItems = val;
TopVisibleRecord = 0;
}
// Change the due date field, in the record, to the completion
// date when the item is mark complete.
ChangeDueDate = GetObjectValue(OptionsChangeDueDate);
// Show or hide the due date, priorities, and categories columns
ShowDueDates = GetObjectValue(OptionsShowDueDates);
ShowPriorities = GetObjectValue(OptionsShowPriorities);
ShowCategories = GetObjectValue(OptionsShowCategories);
}
/***********************************************************************
*
* FUNCTION: OptionsInit
*
* DESCRIPTION: This routine initializes the Options Dialog.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 5/23/95 Initial Revision
* rbb 4/14/99 Uses SetObjectValue (trimming a few bytes of code)
*
***********************************************************************/
static void OptionsInit (void)
{
UInt8 sortOrder;
UInt16 listItem;
Char* label;
ListPtr lst;
ControlPtr ctl;
// Set the trigger and popup list that indicates the sort order.
sortOrder = ToDoGetSortOrder (ToDoDB);
if (sortOrder == soPriorityDueDate)
listItem = priorityDueDateItem;
else if (sortOrder == soDueDatePriority)
listItem = dueDatePriorityItem;
else if (sortOrder == soCategoryPriority)
listItem = categoryPriorityItem;
else
listItem = categoryDueDateItem;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -