void CloseEditorCmd::Execute () { Editor* ed = GetEditor(); Iterator i; unidraw->First(i); unidraw->Next(i); if (!unidraw->Done(i)) { ModifStatusVar* mv = (ModifStatusVar*) ed->GetState("ModifStatusVar"); if (mv != nil && mv->GetModifStatus() && !FoundAnyExcept(ed)) { ConfirmDialog dialog("Save changes?"); ed->InsertDialog(&dialog); char resp = dialog.Confirm(); ed->RemoveDialog(&dialog); if (resp == '\007') { return; } else if (resp == 'y') { SaveCompCmd saveComp(ed); saveComp.Execute(); if (mv->GetModifStatus()) { return; // save dialog was aborted } } } unidraw->Close(ed); } }
void RevertCmd::Execute () { Editor* ed = GetEditor(); Component* comp = ed->GetComponent(); Catalog* catalog = unidraw->GetCatalog(); const char* name = catalog->GetName(comp); ModifStatusVar* mv = (ModifStatusVar*) ed->GetState("ModifStatusVar"); if (name != nil && (mv == nil || mv->GetModifStatus())) { char buf[CHARBUFSIZE]; strcpy(buf, name); ConfirmDialog dialog("Really revert to last version saved?"); ed->InsertDialog(&dialog); char confirmation = dialog.Confirm(); ed->RemoveDialog(&dialog); if (confirmation == 'y') { Component* orig = comp; catalog->Forget(orig); if (unidraw->GetCatalog()->Retrieve(buf, comp)) { ed->SetComponent(comp); unidraw->CloseDependents(orig); unidraw->Update(); CompNameVar* cv = (CompNameVar*) ed->GetState("CompNameVar"); if (cv != nil) cv->SetComponent(comp); if (mv != nil) mv->SetComponent(comp); Component* root = orig->GetRoot(); delete root; } else { ConfirmDialog dialog( "Couldn't revert! (File nonexistent?)", "Save changes?" ); ed->InsertDialog(&dialog); char confirmation = dialog.Confirm(); ed->RemoveDialog(&dialog); UpdateCompNameVars(); if (mv != nil) mv->Notify(); if (confirmation == 'y') { SaveCompAsCmd saveCompAs(ed); saveCompAs.Execute(); } } } } }
static boolean ReadyToClose (Editor* ed) { ModifStatusVar* mv = (ModifStatusVar*) ed->GetState("ModifStatusVar"); if (mv != nil && Writable(mv->GetComponent()) && mv->GetModifStatus()) { ConfirmDialog dialog("Save changes?"); ed->InsertDialog(&dialog); char resp = dialog.Confirm(); ed->RemoveDialog(&dialog); if (resp == '\007') { return false; // confirm dialog aborted } else if (resp == 'y') { SaveCompCmd saveComp(ed); saveComp.Execute(); if (mv->GetModifStatus()) { return false; // save dialog was aborted } } } return true; }
void SaveCompCmd::Execute () { Editor* ed = GetEditor(); ModifStatusVar* modifVar = (ModifStatusVar*)ed->GetState("ModifStatusVar"); CompNameVar* compNameVar = (CompNameVar*) ed->GetState("CompNameVar"); const char* name = (compNameVar == nil) ? nil : compNameVar->GetName(); if (name == nil) { SaveCompAsCmd saveCompAs(ed); saveCompAs.Execute(); } else if (modifVar == nil || modifVar->GetModifStatus()) { Catalog* catalog = unidraw->GetCatalog(); Component* comp; if (catalog->Retrieve(name, comp) && catalog->Save(comp, name)) { if (modifVar != nil) modifVar->SetModifStatus(false); unidraw->ClearHistory(comp); } else { char title[CHARBUFSIZE]; const char* reason = !Writable(comp) ? "(File not writable.)" : ""; sprintf(title, "Couldn't save! %s", reason); char subtitle[CHARBUFSIZE]; const char* domain = unidraw->GetCatalog()->GetAttribute("domain"); domain = (domain == nil) ? "component" : domain; sprintf(subtitle, "Save this %s as:", domain); Style* s = new Style(Session::instance()->style()); s->attribute("caption", title); s->attribute("subcaption", subtitle); s->attribute("open", "Save"); /* BUG: style s is never used!!!! */ SaveCompAsCmd saveCompAs(ed); saveCompAs.Execute(); } } }