📄 helpc.c
字号:
// FILE *fp; CharC nl("\n"); CharC text; u_int acount = This->addList.size(); for (int a=0; a<acount; a++) { CardRecC *rec = (CardRecC*)*This->addList[a]; fp = fopen(rec->file, "a"); if ( !fp ) { perror(rec->file); continue; } fprintf(fp, "[CARD] "); rec->name.WriteFile(fp); nl.WriteFile(fp); fprintf(fp, "[TITLE] "); rec->title.WriteFile(fp); nl.WriteFile(fp); if ( rec->locator.size() > 0 ) { fprintf(fp, "[LOCATOR] "); rec->locator.WriteFile(fp); nl.WriteFile(fp); } rec->text.WriteFile(fp); if ( !rec->text.EndsWith('\n') ) nl.WriteFile(fp); fclose(fp); } // End for each added card This->addList.removeAll(); This->SetChanged(False);} // End DoFileSave/*----------------------------------------------------------------------- * Method to check for changes before a new card name is entered */voidHelpC::ModifyName(Widget, HelpC *This, XmTextVerifyCallbackStruct *cb){ cb->doit = This->CheckChanges();}/*----------------------------------------------------------------------- * Method to enter a new helpcard name */voidHelpC::EnterName(Widget, HelpC *This, XtPointer){ if ( !This->CheckChanges() ) return; halApp->BusyCursor(True); char *cs = XmTextFieldGetString(This->nameTF); StringC nameStr(cs); XtFree(cs); nameStr.Trim();//// Look through each database looking for the name// u_int count = This->dbList.size(); for (int i=0; i<count; i++) { HelpDbC *db = (HelpDbC*)*This->dbList[i]; HelpCardC *card = db->FindCard(nameStr); if ( card ) { This->ShowCard(card, (Widget)-1/*No popup necessary*/); halApp->BusyCursor(False); return; } }//// Clear fields if name not found// XmTextFieldSetString(This->locTF, ""); XmTextFieldSetString(This->helpTitle, ""); This->richText->Clear(); This->curCard = NULL; This->SetChanged(False); halApp->BusyCursor(False);} // End EnterNamevoidHelpC::DoEditPlain(Widget, HelpC *This, XtPointer){ This->richText->ChangeFont(FC_PLAIN);}voidHelpC::DoEditBold(Widget, HelpC *This, XtPointer){ This->richText->ChangeFont(FC_BOLD);}voidHelpC::DoEditItalic(Widget, HelpC *This, XtPointer){ This->richText->ChangeFont(FC_ITALIC);}voidHelpC::DoEditFixed(Widget, HelpC *This, XtPointer){ This->richText->ChangeFont(FC_FIXED);}voidHelpC::DoEditUnder(Widget, HelpC *This, XtPointer){ This->richText->ChangeFont(FC_UNDERLINE);}voidHelpC::DoEditBig(Widget, HelpC *This, XtPointer){ This->richText->ChangeFont(FC_BIGGER);}voidHelpC::DoEditSmall(Widget, HelpC *This, XtPointer){ This->richText->ChangeFont(FC_SMALLER);}voidHelpC::DoEditUndel(Widget, HelpC *This, XtPointer){ This->richText->Undelete();}voidHelpC::DoJustLeft(Widget, HelpC *This, XtPointer){ This->richText->ChangeJust(JC_LEFT);}voidHelpC::DoJustRight(Widget, HelpC *This, XtPointer){ This->richText->ChangeJust(JC_RIGHT);}voidHelpC::DoJustCenter(Widget, HelpC *This, XtPointer){ This->richText->ChangeJust(JC_CENTER);}voidHelpC::DoIndentLeftMore(Widget, HelpC *This, XtPointer){ This->richText->ChangeMargin(MC_LEFT_IN);}voidHelpC::DoIndentLeftLess(Widget, HelpC *This, XtPointer){ This->richText->ChangeMargin(MC_LEFT_OUT);}voidHelpC::DoIndentRightMore(Widget, HelpC *This, XtPointer){ This->richText->ChangeMargin(MC_RIGHT_IN);}voidHelpC::DoIndentRightLess(Widget, HelpC *This, XtPointer){ This->richText->ChangeMargin(MC_RIGHT_OUT);}voidHelpC::DoColorRed(Widget, HelpC *This, XtPointer){ This->richText->ChangeColor("Red");}voidHelpC::DoColorGreen(Widget, HelpC *This, XtPointer){ This->richText->ChangeColor("Green");}voidHelpC::DoColorBlue(Widget, HelpC *This, XtPointer){ This->richText->ChangeColor("Blue");}voidHelpC::DoColorYellow(Widget, HelpC *This, XtPointer){ This->richText->ChangeColor("Yellow");}voidHelpC::DoColorMagenta(Widget, HelpC *This, XtPointer){ This->richText->ChangeColor("Magenta");}voidHelpC::DoColorCyan(Widget, HelpC *This, XtPointer){ This->richText->ChangeColor("Cyan");}voidHelpC::DoColorBlack(Widget, HelpC *This, XtPointer){ This->richText->ChangeColor("Black");}voidHelpC::DoColorWhite(Widget, HelpC *This, XtPointer){ This->richText->ChangeColor("White");}voidHelpC::DoColorNone(Widget, HelpC *This, XtPointer){ This->richText->ChangeColor("None");}voidHelpC::TextChanged(Widget, HelpC *This, XtPointer){ This->SetChanged(True);}voidHelpC::RichTextChanged(void*, HelpC *This){ This->SetChanged(True);}/*--------------------------------------------------------------- * Callback routine to handle response in a question dialog */static voidAnswerQuery(Widget, int *answer, XmAnyCallbackStruct *cbs){ *answer = cbs->reason;}/*------------------------------------------------------------------------ * Trap window manager close */static voidWmClose(Widget, int *answer, XtPointer){ *answer = XmCR_CANCEL;}/*------------------------------------------------------------------------ * Check for changes to current information */BooleanHelpC::CheckChanges(Boolean cancelOk){ if ( !changed ) return True;//// Ask about saving changes// WArgList args; args.DialogStyle(XmDIALOG_FULL_APPLICATION_MODAL); if ( halApp->questionPM ) args.SymbolPixmap(halApp->questionPM); Widget dialog = XmCreateQuestionDialog(helpWin, "saveChangesWin",ARGS); int answer; Widget noPB = XmCreatePushButton(dialog, "noPB", 0,0); XtManageChild(noPB); XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); XtAddCallback(noPB, XmNactivateCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); if ( cancelOk ) XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); else XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON)); XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));//// Trap window manager close function// XmAddWMProtocolCallback(XtParent(dialog), halApp->delWinAtom, (XtCallbackProc)WmClose, (caddr_t)&answer);//// Display dialog// XtManageChild(dialog);//// Wait for answer// answer = XmCR_NONE; while ( answer == XmCR_NONE ) { XtAppProcessEvent(halApp->context, XtIMXEvent); XSync(halApp->display, False); } XtUnmanageChild(dialog); XtDestroyWidget(dialog); XSync(halApp->display, False); switch (answer) { case XmCR_ACTIVATE: // Discard current SetChanged(False); return True; case XmCR_CANCEL: // Cancel operation return False; default: // Save current break; }//// If there is a current card, create a record for the "mod" list.// If there is no current card, create a record for the "add" list.// We need a database or filename for new cards.// CardRecC *rec = new CardRecC; char *cs = XmTextFieldGetString(nameTF); rec->name = cs; XtFree(cs); rec->name.Trim(); cs = XmTextFieldGetString(locTF); rec->locator = cs; XtFree(cs); rec->locator.Trim(); cs = XmTextFieldGetString(helpTitle); rec->title = cs; XtFree(cs); rec->title.Trim(); if ( enriched ) { richText->GetString(rec->text, TT_ENRICHED); } else { cs = XmTextGetString(helpText); rec->text = cs; XtFree(cs); }//// Add entry to appropriate list// void *tmp = (void*)rec; if ( curCard ) { rec->db = curCard->db; modList.add(tmp);//// If the title has changed, update the index// if ( indexList && rec->title != curCard->title ) { } } else { if ( dbList.size() == 1 ) { rec->db = (HelpDbC*)*dbList[0]; } else if ( !GetDbFileName(rec->file) ) { delete rec; return False; }//// Add this card to the index// if ( indexList ) { } addList.add(tmp); } SetChanged(False); return True;} // End CheckChanges/*------------------------------------------------------------------------ * Get name of database file for new card */BooleanHelpC::GetDbFileName(StringC& file){//// Prompt for file name// WArgList args; args.DialogStyle(XmDIALOG_FULL_APPLICATION_MODAL); if ( halApp->questionPM ) args.SymbolPixmap(halApp->questionPM); Widget dialog = XmCreatePromptDialog(helpWin, "dbFileNameWin",ARGS); int answer; XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc)AnswerQuery, (XtPointer)&answer); XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));//// Trap window manager close function// XmAddWMProtocolCallback(XtParent(dialog), halApp->delWinAtom, (XtCallbackProc)WmClose, (caddr_t)&answer);//// Display dialog// XtManageChild(dialog); while ( file.size() == 0 ) {//// Wait for answer// answer = XmCR_NONE; while ( answer == XmCR_NONE ) { XtAppProcessEvent(halApp->context, XtIMXEvent); XSync(halApp->display, False); }//// Read file name from text field// if ( answer != XmCR_CANCEL ) { XmString str; XtVaGetValues(dialog, XmNtextString, &str, NULL); WXmString wstr(str); char *cs = (char*)wstr; file = cs; file.Trim(); XtFree(cs); XmStringFree(str); if ( file.size() == 0 ) { halApp->PopupMessage("Please enter a file name"); set_invalid(XmSelectionBoxGetChild(dialog, XmDIALOG_TEXT), True, True); } } } XtUnmanageChild(dialog); XtDestroyWidget(dialog); XSync(halApp->display, False); return (answer != XmCR_CANCEL);} // End GetDbFileName#endif/*----------------------------------------------------------------------- * Method to display a helpcard for the specified widget */HelpCardC*HelpC::FindCard(const Widget w, const char *res){ if ( !isActive ) return NULL; StringC name = CardName(w, res); return FindCard(name);}/*----------------------------------------------------------------------- * Method to find the help card by name. */HelpCardC*HelpC::FindCard(StringC& name){ if ( name.size() > 0 ) {//// Look through each database for the card name.// u_int count = dbList.size(); for (int i=0; i<count; i++) { HelpDbC *db = (HelpDbC*)*dbList[i]; HelpCardC *card = db->FindCard((char*)name); if ( card ) return card; } } return NULL;}BooleanHelpC::Editable() const{#if EDIT_OK return edit;#else return False;#endif}HelpResWinC*HelpC::HelpResWin(){#if EDIT_OK if ( !helpResWin ) helpResWin = new HelpResWinC(*halApp);#endif return helpResWin;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -