📄 sendedit.c
字号:
}//// Open the save file// FILE *fp = fopen(saveFile, "a"); if ( !fp ) { StringC errmsg("Could not open file \""); errmsg += saveFile; errmsg += "\".\n"; errmsg += SystemErrorMessage(errno); pub->PopupMessage(errmsg); unlink(bodyFile); pub->BusyCursor(False); pub->Message("Composition not saved."); return False; }//// Merge lists// count = contList.size(); for (i=0; i<count; i++) AddHeader(*contList[i], headList);//// Write the headers to the save file// count = headList.size(); Boolean error = False; for (i=0; !error && i<count; i++) { headStr = *headList[i]; if ( !headStr.EndsWith('\n') ) headStr += '\n'; error = !headStr.WriteFile(fp); }//// Write a blank line// if ( !error ) { headStr = "\n"; error = !headStr.WriteFile(fp); }//// Copy the body file// if ( !error ) error = !CopyFile(bodyFile, saveFile, False, False, NULL, fp); if ( error ) { StringC errmsg("Error writing to save file \""); errmsg += saveFile; errmsg += "\".\n"; errmsg += SystemErrorMessage(errno); pub->PopupMessage(errmsg); fclose(fp); unlink(bodyFile); pub->BusyCursor(False); pub->Message("Composition not saved."); return False; } fclose(fp); unlink(bodyFile);//// If we created the save file, link it to the icon// if ( !cs ) { if ( editIcon ) editIcon->SetSourceFile(saveFile, /*delete=*/True); else if ( editMsg ) editDoneCall((char*)saveFile); pub->changed = False; } pub->BusyCursor(False); pub->Message("Save complete."); return True;} // End Save/*--------------------------------------------------------------- * Callback to handle external editor */voidSendWinP::DoEdit(Widget, SendWinP *This, XtPointer){ This->edit_pid = This->FilterBody(ishApp->compPrefs->editCmd, (CallbackFn*)EditFinished);}/*--------------------------------------------------------------- * Callback to handle spell checker */voidSendWinP::DoSpell(Widget, SendWinP *This, XtPointer){ This->spell_pid = This->FilterBody(ishApp->compPrefs->spellCmd, (CallbackFn*)SpellFinished);}/*--------------------------------------------------------------- * Method to pass body text to a filter and read the result */pid_tSendWinP::FilterBody(StringC& cmd, CallbackFn *doneFn){ pub->BusyCursor(True);//// Create a temporary edit file// char *file = tempnam(NULL, "filt.");//// Set up a description template so that graphics will generate a description// string that we can later use to re-insert the graphic in the modified// text.// descTemplate = " (GRAPHIC %a - DO NOT MODIFY) ";//// Display the text// StringC textStr; Boolean plain; if ( optMsgPlainTB ) plain = (XmToggleButtonGetState(optMsgPlainTB) || XmToggleButtonGetState(optTextPlainTB)); else plain = (ishApp->mailPrefs->mailType == MAIL_PLAIN || ishApp->mailPrefs->textType == CT_PLAIN); if ( plain ) { bodyText->GetString(textStr, TT_PLAIN, XmToggleButtonGetState(optWrapTB) ? bodyText->ColumnCount() : 0); filterEnriched = False; } else { bodyText->GetString(textStr, TT_ENRICHED); filterEnriched = True; } if ( !textStr.EndsWith("\n") ) textStr += "\n";//// Go back to the normal way of generating descriptions// descTemplate.Clear(); if ( !textStr.WriteFile(file) ) { StringC msg("Couldn't write temp file: "); msg += file; pub->PopupMessage(msg); pub->BusyCursor(False); free(file); return 0; }//// Make the text widget insensitive during the edit// bodyText->SetSensitive(False); XtSetSensitive(pub->FilePulldown(), False); XtSetSensitive(editPD, False); buttMgr->EnableButtons();//// Start the edit process// CallbackC modCall ((CallbackFn *)FileModified, this); CallbackC doneCall(doneFn, this); pid_t pid = FilterFile(cmd, file, modCall, doneCall); if ( debuglev > 0 ) cout <<"Started process " <<pid NL; free(file); if ( pid <= 0 ) { bodyText->SetSensitive(True); XtSetSensitive(pub->FilePulldown(), True); XtSetSensitive(editPD, True); buttMgr->EnableButtons(); } pub->BusyCursor(False); return pid;} // End FilterBody/*--------------------------------------------------------------- * Callback routine to handle completion of edit */voidSendWinP::EditFinished(char *file, SendWinP *This){ if ( debuglev > 0 ) cout <<"Edit finished" <<endl;//// Make the text widget sensitive again// This->bodyText->SetSensitive(True); XtSetSensitive(This->pub->FilePulldown(), True); XtSetSensitive(This->editPD, True); This->buttMgr->EnableButtons(); XmProcessTraversal(This->bodyText->TextArea(), XmTRAVERSE_CURRENT);//// Delete the temporary file// unlink(file); This->edit_pid = 0;}/*--------------------------------------------------------------- * Callback routine to handle completion of spellcheck */voidSendWinP::SpellFinished(char *file, SendWinP *This){ if ( debuglev > 0 ) cout <<"Spellcheck finished" <<endl;//// Make the text widget sensitive again// This->bodyText->SetSensitive(True); XtSetSensitive(This->pub->FilePulldown(), True); XtSetSensitive(This->editPD, True); This->buttMgr->EnableButtons(); XmProcessTraversal(This->bodyText->TextArea(), XmTRAVERSE_CURRENT);//// Delete the temporary file// unlink(file); This->spell_pid = 0;}/*--------------------------------------------------------------- * Callback routine to handle modification of edited file */voidSendWinP::FileModified(char *file, SendWinP *This){ if ( debuglev > 0 ) cout <<"File " <<file <<" was modified" <<endl;//// Clear the text and read in the file// MappedFileC *mf = MapFile(file); if ( mf ) { This->ReadFilter(mf->data); UnmapFile(mf); } else { StringC tmpStr; if ( !tmpStr.ReadFile(file) ) { StringC msg("Could not read file: "); msg += file; This->pub->PopupMessage(msg); return; } This->ReadFilter(tmpStr); } // End if file not mapped} // End FileModified/*--------------------------------------------------------------- * Method to read in the changes made during and external edit or spell * session. */voidSendWinP::ReadFilter(CharC data){ bodyText->Defer(True); if ( filterEnriched ) bodyText->SetTextType(TT_ENRICHED); else bodyText->SetTextType(TT_PLAIN);//// Loop through and save any existing graphics. Also mark them so they// won't be deleted// PtrListC graphicList = bodyText->GraphicList(); u_int count = graphicList.size(); int i; for (i=0; i<count; i++) { SendIconC *icon = (SendIconC*)*graphicList[i]; icon->okToDelete = False; }//// Clear the composition window// bodyText->Clear();//// Scan the text for any graphic tags// static RegexC *pat = NULL; if ( !pat ) pat = new RegexC("(GRAPHIC[ \n]\\([0-9]+\\)[ \n]-[ \n]DO[ \n]NOT[ \n]MODIFY)"); int pos; int start = 0; u_int len; StringC addrStr; while ( (pos=pat->search(data, start)) >= 0 ) {//// Display the text between "start" and "pos"// len = pos-start; if ( len > 0 ) bodyText->AddString(data(start, len));//// Look for a graphic with the specified tag// addrStr = data((*pat)[1]); void *tmp = (void*)atoi(addrStr); int index = graphicList.indexOf(tmp); if ( index == graphicList.NULL_INDEX ) { StringC errmsg("The graphic attachment: "); errmsg += (int)tmp; errmsg += " could not be found.\n"; errmsg += "Perhaps the address was modified by accident."; pub->PopupMessage(errmsg); }//// If the graphic was found, add it to the composition window and remove it// from the list.// else { SendIconC *icon = (SendIconC*)tmp; icon->okToDelete = True; bodyText->AddGraphic(icon); graphicList.remove(index); } // End if graphic was found start = pos + (*pat)[0].length(); } // End for each tag//// Display the text between "start" and the end// len = data.Length() - start; if ( len > 0 ) bodyText->AddString(data(start, len)); bodyText->Defer(False);//// If there are any graphics remaining in the list, delete them// if ( graphicList.size() == 1 ) { SendIconC *icon = (SendIconC*)*graphicList[0]; StringC label; icon->data->GetLabel(label); StringC errmsg("The graphic attachment: "); errmsg += label; errmsg += "\nis missing from the modified text and will be deleted.\n"; pub->PopupMessage(errmsg); delete icon; } else if ( graphicList.size() > 1 ) { SendIconC *icon; StringC label; StringC errmsg("The following graphic attachments are missing from"); errmsg += "\nthe modified text and will be deleted:\n\n"; u_int count = graphicList.size(); for (i=0; i<count; i++) { icon = (SendIconC*)*graphicList[i]; icon->data->GetLabel(label); errmsg += label; errmsg += '\n'; } pub->PopupMessage(errmsg); count = graphicList.size(); for (i=0; i<count; i++) { icon = (SendIconC*)*graphicList[i]; delete icon; } }} // End ReadFilter#ifdef HGLTERM/*--------------------------------------------------------------- * Method to find or create a new terminal window */TermWinC*SendWinP::GetTermWin(){//// First look for an existing, unused window// TermWinC *termWin = NULL; unsigned count = termWinList.size(); Boolean found = False; for (int i=0; !found && i<count; i++) { termWin = (TermWinC*)*termWinList[i]; if ( !termWin->IsShown() ) found = True; } // End for each existing terminal window//// If we didn't find a window, we need to create a new one// if ( !found ) { pub->BusyCursor(True); termWin = new TermWinC("termWin", *pub); void *tmp = (void*)termWin; termWinList.add(tmp); pub->BusyCursor(False); } return termWin;} // End GetTermWin#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -