void ViewCompCmd::Execute () { Editor* ed = GetEditor(); if (OnlyOneEditorOf(ed->GetComponent()) && !ReadyToClose(ed)) { return; } Style* style; boolean reset_caption = false; if (chooser_ == nil) { style = new Style(Session::instance()->style()); chooser_ = DialogKit::instance()->file_chooser(".", style); Resource::ref(chooser_); char buf[CHARBUFSIZE]; const char* domain = unidraw->GetCatalog()->GetAttribute("domain"); domain = (domain == nil) ? "component" : domain; sprintf(buf, "Select a %s to open:", domain); style->attribute("caption", ""); style->attribute("subcaption", buf); } else { style = chooser_->style(); } while (chooser_->post_for(ed->GetWindow())) { const String* s = chooser_->selected(); NullTerminatedString ns(*s); const char* name = ns.string(); Catalog* catalog = unidraw->GetCatalog(); GraphicComp* comp; if (catalog->Retrieve(name, (Component*&) comp)) { ModifStatusVar* modif = (ModifStatusVar*) ed->GetState( "ModifStatusVar" ); Component* orig = ed->GetComponent(); ed->SetComponent(comp); unidraw->Update(); StateVar* sv = ed->GetState("CompNameVar"); CompNameVar* cnv = (CompNameVar*) sv; if (cnv != nil) cnv->SetComponent(comp); if (modif != nil) modif->SetComponent(comp); if (orig != nil && unidraw->FindAny(orig) == nil) { Component* root = orig->GetRoot(); delete root; } break; } else { style->attribute("caption", "Open failed!"); reset_caption = true; } } if (reset_caption) { style->attribute("caption", ""); } }
void OpenCmd::Execute () { Editor* ed = GetEditor(); Component* orig_comp = ed->GetComponent(); ViewCompCmd::Execute(); Component* new_comp = ed->GetComponent(); if (new_comp != orig_comp) { IdrawComp* idcomp = (IdrawComp*) new_comp; Grid* grid = ed->GetViewer()->GetGrid(); float xincr, yincr; idcomp->GetGridSpacing(xincr, yincr); grid->SetSpacing(xincr, yincr); } }
void BackCmd::Execute () { Clipboard* cb = GetClipboard(); Editor* ed = GetEditor(); if (cb == nil) { Selection* s = ed->GetSelection(); if (s->IsEmpty()) { return; } SetClipboard(cb = new Clipboard); GraphicView* views = ed->GetViewer()->GetGraphicView(); s->Sort(views); Iterator i; for (s->First(i); !s->Done(i); s->Next(i)) { s->GetView(i)->Interpret(this); } } else { Clipboard* oldcb = cb; SetClipboard(cb = new Clipboard); Iterator i; for (oldcb->First(i); !oldcb->Done(i); oldcb->Next(i)) { oldcb->GetComp(i)->Interpret(this); } delete oldcb; } if (!cb->IsEmpty()) { ed->GetComponent()->Interpret(this); } }
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(); } } } } }
void QuitCmd::Execute () { Editor* ed = GetEditor(); if (ReadyToClose(ed)) { Component* comp = ed->GetComponent(); if (comp == nil) { unidraw->Close(ed); } else { unidraw->CloseDependents(comp->GetRoot()); } Iterator i; for (;;) { unidraw->First(i); if (unidraw->Done(i)) { break; } ed = unidraw->GetEditor(i); if (ReadyToClose(ed)) { comp = ed->GetComponent(); if (comp == nil) { unidraw->Close(ed); } else { unidraw->CloseDependents(comp->GetRoot()); } } else { return; } } unidraw->Quit(); } }
void NewCompCmd::Execute () { Editor* ed = GetEditor(); Component* orig = ed->GetComponent(); Component* comp = prototype_->Copy(); CompNameVar* compNameVar = (CompNameVar*) ed->GetState("CompNameVar"); ModifStatusVar* modifVar = (ModifStatusVar*)ed->GetState("ModifStatusVar"); if (OnlyOneEditorOf(orig) && !ReadyToClose(ed)) { return; } if (compNameVar != nil) compNameVar->SetComponent(comp); if (modifVar != nil) modifVar->SetComponent(comp); ed->SetComponent(comp); ed->Update(); if (orig != nil && unidraw->FindAny(orig) == nil) { Component* root = orig->GetRoot(); delete root; } }
boolean GraphExportCmd::Export (const char* pathname) { Editor* editor = GetEditor(); Selection* s = editor->GetSelection(); GraphIdrawComp* real_top = (GraphIdrawComp*)editor->GetComponent(); boolean ok = false; char* old_format = NULL; boolean empty = s->IsEmpty(); GraphIdrawComp* false_top = new GraphIdrawComp(); Iterator i; empty ? real_top->First(i) : s->First(i); while (empty ? !real_top->Done(i) : !s->Done(i)) { if (chooser_->idraw_format() || chooser_->postscript_format()) { OverlayComp* oc = empty ? new OverlayComp(real_top->GetComp(i)->GetGraphic()->Copy()) : new OverlayComp(s->GetView(i)->GetGraphicComp()->GetGraphic()->Copy()); false_top->Append(oc); } else { OverlayComp* oc = empty ? (OverlayComp*)real_top->GetComp(i)->Copy() : (OverlayComp*)s->GetView(i)->GetGraphicComp()->Copy(); false_top->Append(oc); } empty ? real_top->Next(i) : s->Next(i); } OverlayPS* ovpsv; if (chooser_->idraw_format() || chooser_->postscript_format()) ovpsv = (OverlayPS*) false_top->Create(POSTSCRIPT_VIEW); else { ovpsv = (OverlayPS*) false_top->Create(SCRIPT_VIEW); if(strcmp(chooser_->format(), "dot")==0) { old_format = OverlayScript::format() ? strnew(OverlayScript::format()) : NULL; OverlayScript::format("dot"); } } if (ovpsv != nil) { filebuf fbuf; char* tmpfilename; if (chooser_->to_printer()) { tmpfilename = tmpnam(nil); false_top->SetPathName(tmpfilename); ok = fbuf.open(tmpfilename, output) != 0; } else { ok = fbuf.open(pathname, output) != 0; } if (ok) { ostream out(&fbuf); false_top->Attach(ovpsv); ovpsv->SetCommand(this); if (!chooser_->idraw_format() && !chooser_->postscript_format()) ((GraphIdrawScript*)ovpsv)->SetByPathnameFlag(chooser_->by_pathname_flag()); ovpsv->Update(); ok = ovpsv->Emit(out); fbuf.close(); if (chooser_->to_printer()) { char cmd[CHARBUFSIZE]; if (strstr(pathname, "%s")) { char buf[CHARBUFSIZE]; sprintf(buf, pathname, tmpfilename); sprintf(cmd, "(%s;rm %s)&", buf, tmpfilename); } else sprintf(cmd, "(%s %s;rm %s)&", pathname, tmpfilename, tmpfilename); ok = system(cmd) == 0; } } delete ovpsv; } delete false_top; if (old_format) { OverlayScript::format(old_format); delete old_format; } return ok; }
void SaveCompAsCmd::Execute () { Editor* ed = GetEditor(); char buf[CHARBUFSIZE]; const char* domain = unidraw->GetCatalog()->GetAttribute("domain"); domain = (domain == nil) ? "component" : domain; sprintf(buf, "Save this %s as:", domain); boolean reset_caption = false; Style* style = new Style(Session::instance()->style()); style->attribute("subcaption", buf); style->attribute("open", "Save"); if (chooser_ == nil) { chooser_ = DialogKit::instance()->file_chooser(".", style); Resource::ref(chooser_); } while (chooser_->post_for(ed->GetWindow())) { const String* str = chooser_->selected(); NullTerminatedString ns(*str); const char* name = ns.string(); Catalog* catalog = unidraw->GetCatalog(); boolean ok = true; if (catalog->Exists(name) && catalog->Writable(name)) { char buf[CHARBUFSIZE]; sprintf(buf, "\"%s\" already exists.", name); ConfirmDialog dialog(buf, "Overwrite?"); ed->InsertDialog(&dialog); char confirmation = dialog.Confirm(); ed->RemoveDialog(&dialog); if (confirmation == 'n') { ok = false; } else if (confirmation != 'y') { break; } } if (ok) { CompNameVar* cnv = (CompNameVar*) ed->GetState("CompNameVar"); const char* oldname = (cnv == nil) ? nil : cnv->GetName(); Component* comp = ed->GetComponent(); if (catalog->Exists(name) && !catalog->Writable(name)) { style->attribute( "caption", "Couldn't save! (File not writable.)" ); } else { if (oldname == nil) { comp = comp->GetRoot(); } else { catalog->Retrieve(oldname, comp); catalog->Forget(comp); } StateVar* sv = ed->GetState("ModifStatusVar"); ModifStatusVar* mv = (ModifStatusVar*) sv; if (catalog->Save(comp, name)) { if (mv != nil) mv->SetModifStatus(false); unidraw->ClearHistory(comp); UpdateCompNameVars(); break; } else { if (mv != nil) mv->Notify(); UpdateCompNameVars(); style->attribute("caption", "Couldn't save!"); reset_caption = true; } } } } if (reset_caption) { style->attribute("caption", ""); } }
void OverlaysComp::Uninterpret (Command* cmd) { Editor* ed = cmd->GetEditor(); if ( (cmd->IsA(DELETE_CMD) || cmd->IsA(CUT_CMD)) && ed->GetComponent() != this ) { Iterator i; for (Last(i); !Done(i); Prev(i)) { GetComp(i)->Uninterpret(cmd); } } else if (cmd->IsA(DELETE_CMD)) { Clipboard* cb = cmd->GetClipboard(); if (cb != nil) { Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { OverlayComp* comp = (OverlayComp*) cb->GetComp(i); RestorePosition(comp, cmd); comp->Uninterpret(cmd); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } } else if (cmd->IsA(CUT_CMD)) { Clipboard* cb = cmd->GetClipboard(); if (cb != nil) { Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { OverlayComp* comp = (OverlayComp*) cb->GetComp(i); RestorePosition(comp, cmd); comp->Uninterpret(cmd); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } } else if (cmd->IsA(PASTE_CMD)) { Clipboard* cb = cmd->GetClipboard(); if (cb != nil) { Selection* s = ed->GetSelection(); Iterator i, pos; s->Clear(); for (cb->First(i); !cb->Done(i); cb->Next(i)) { GraphicComp* comp = cb->GetComp(i); unidraw->CloseDependents(comp); Remove(comp); } Notify(); unidraw->Update(); } } else if (cmd->IsA(DUP_CMD)) { Clipboard* cb = cmd->GetClipboard(); if (cb != nil) { Selection* s = ed->GetSelection(); Iterator i; s->Clear(); for (cb->First(i); !cb->Done(i); cb->Next(i)) { GraphicComp* comp = cb->GetComp(i); unidraw->CloseDependents(comp); Remove(comp); } Notify(); unidraw->Update(); } } else if (cmd->IsA(OVGROUP_CMD)) { OvGroupCmd* gcmd = (OvGroupCmd*) cmd; OverlayComp* group = gcmd->GetGroup(); Component* edComp = gcmd->GetEditor()->GetComponent(); if (group == this) { edComp->Uninterpret(gcmd); } else if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; cb->First(i); OverlayComp* group = (OverlayComp*) cb->GetComp(i)->GetParent(); GroupCmd* gcmd = (GroupCmd*) cmd; unidraw->CloseDependents(group); for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { RestorePosition((OverlayComp*)cb->GetComp(i), cmd); } Remove(group); Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else { OverlayComp::Uninterpret(gcmd); } } else if (cmd->IsA(UNGROUP_CMD)) { UngroupCmd* ucmd = (UngroupCmd*) cmd; Component* edComp = ucmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = ucmd->GetClipboard(); Clipboard* kids = ucmd->GetKids(); Clipboard insertedParents; Iterator k; for (kids->First(k); !kids->Done(k); kids->Next(k)) { OverlayComp* kid = (OverlayComp*) kids->GetComp(k); UngroupData* ud = (UngroupData*) cmd->Recall(kid); OverlayComp* parent = (OverlayComp*)ud->_parent; *kid->GetGraphic() = *ud->_gs; if (!insertedParents.Includes(parent)) { GSData* gd = (GSData*) cmd->Recall(parent); *parent->GetGraphic() = *gd->_gs; Iterator insertPt; SetComp(kid, insertPt); InsertBefore(insertPt, parent); insertedParents.Append(parent); } Remove(kid); parent->Append(kid); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); delete kids; ucmd->SetKids(nil); } } else if (cmd->IsA(FRONT_CMD)) { Component* edComp = cmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { RestorePosition((OverlayComp*)cb->GetComp(i), cmd); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else { OverlayComp::Uninterpret(cmd); } } else if (cmd->IsA(BACK_CMD)) { Component* edComp = cmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { RestorePosition((OverlayComp*)cb->GetComp(i), cmd); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else { OverlayComp::Uninterpret(cmd); } } else { OverlayComp::Uninterpret(cmd); } }
void OverlaysComp::Interpret (Command* cmd) { Editor* ed = cmd->GetEditor(); if ( (cmd->IsA(DELETE_CMD) || cmd->IsA(CUT_CMD)) && ed->GetComponent() != this ) { Iterator i; for (First(i); !Done(i); Next(i)) { GetComp(i)->Interpret(cmd); } } else if (cmd->IsA(DELETE_CMD)) { Clipboard* cb = cmd->GetClipboard(); Selection* s = ed->GetSelection(); if (cb == nil) { if (s->IsEmpty()) { return; } cmd->SetClipboard(cb = new Clipboard); cb->Init(s); } s->Clear(); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* comp = (OverlayComp*)cb->GetComp(i); unidraw->CloseDependents(comp); comp->Interpret(cmd); StorePosition(comp, cmd); Remove(comp); } Notify(); unidraw->Update(); } else if (cmd->IsA(CUT_CMD)) { Clipboard* cb = cmd->GetClipboard(); Selection* s = ed->GetSelection(); if (cb == nil) { if (s->IsEmpty()) { return; } GraphicView* views = ed->GetViewer()->GetGraphicView(); s->Sort(views); cmd->SetClipboard(cb = new Clipboard); cb->Init(s); Clipboard* globalcb = unidraw->GetCatalog()->GetClipboard(); globalcb->DeleteComps(); globalcb->CopyInit(s); } s->Clear(); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* comp = (OverlayComp*)cb->GetComp(i); unidraw->CloseDependents(comp); comp->Interpret(cmd); StorePosition(comp, cmd); Remove(comp); } Notify(); unidraw->Update(); } else if (cmd->IsA(PASTE_CMD)) { Clipboard* cb = cmd->GetClipboard(); Iterator i; if (cb == nil) { Clipboard* globalcb = unidraw->GetCatalog()->GetClipboard(); if (globalcb->IsEmpty()) { return; } cmd->SetClipboard(cb = globalcb->DeepCopy()); } for (cb->First(i); !cb->Done(i); cb->Next(i)) { Append((OverlayComp*)cb->GetComp(i)); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else if (cmd->IsA(DUP_CMD)) { GraphicView* views = ed->GetViewer()->GetGraphicView(); OverlayComp* prev, *dup1; Iterator i, pos; Clipboard* cb = cmd->GetClipboard(); const float offset = 8; MoveCmd move(ed, offset, offset); if (cb == nil) { OverlaySelection* s = (OverlaySelection*)ed->GetSelection(); if (s->IsEmpty()) { return; } cmd->SetClipboard(cb = new Clipboard); s->Sort(views); for (s->First(i); !s->Done(i); s->Next(i)) { OverlayComp* orig = s->GetView(i)->GetOverlayComp(); dup1 = (OverlayComp*) orig->Copy(); if (!dup1->attrlist() && orig->attrlist()) { AttributeList* al = new AttributeList(orig->attrlist()); dup1->SetAttributeList(al); } dup1->Interpret(&move); cb->Append(dup1); } cb->First(i); dup1 = (OverlayComp*) cb->GetComp(i); Last(pos); prev = (OverlayComp*) GetComp(pos); cmd->Store(dup1, new VoidData(prev)); } else { cb->First(i); dup1 = (OverlayComp*) cb->GetComp(i); VoidData* vd = (VoidData*) cmd->Recall(dup1); prev = (OverlayComp*) vd->_void; SetComp(prev, pos); } for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { InsertAfter(pos, cb->GetComp(i)); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else if (cmd->IsA(OVGROUP_CMD)) { OvGroupCmd* gcmd = (OvGroupCmd*) cmd; OverlayComp* group = gcmd->GetGroup(); Component* edComp = gcmd->GetEditor()->GetComponent(); if (group == this) { edComp->Interpret(gcmd); } else if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); NullGS(group->GetGraphic()); Group(cb, group, cmd); Notify(); SelectViewsOf(group, ed); unidraw->Update(); } else { OverlayComp::Interpret(gcmd); } } else if (cmd->IsA(UNGROUP_CMD)) { UngroupCmd* ucmd = (UngroupCmd*) cmd; Component* edComp = ucmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Clipboard* kids = new Clipboard; ucmd->SetKids(kids); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* parent = (OverlayComp*)cb->GetComp(i); unidraw->CloseDependents(parent); Ungroup(parent, kids, cmd); } Notify(); SelectClipboard(kids, ed); unidraw->Update(); } else { cmd->GetClipboard()->Append(this); } } else if (cmd->IsA(PUSH_CMD) || cmd->IsA(PULL_CMD)) { Component* edComp = cmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; if (cmd->IsA(PULL_CMD)) { for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* comp = (OverlayComp*)cb->GetComp(i); Iterator j; SetComp(comp, j); Next(j); StorePosition(comp, cmd); if (!Done(j)) { Remove(comp); InsertAfter(j, comp); } } } else { for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { OverlayComp* comp = (OverlayComp*) cb->GetComp(i); Iterator j; SetComp(comp, j); Prev(j); StorePosition(comp, cmd); if (!Done(j)) { Remove(comp); InsertBefore(j, comp); } } } Notify(); unidraw->Update(); } else { OverlayComp::Interpret(cmd); } } else if (cmd->IsA(FRONT_CMD) || cmd->IsA(BACK_CMD)) { Component* edComp = cmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; if (cmd->IsA(FRONT_CMD)) { for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* comp = (OverlayComp*)cb->GetComp(i); StorePosition(comp, cmd); Remove(comp); Append(comp); } } else { for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { OverlayComp* comp = (OverlayComp*) cb->GetComp(i); StorePosition(comp, cmd); Remove(comp); Prepend(comp); } } Notify(); unidraw->Update(); } else { OverlayComp::Interpret(cmd); } } else { OverlayComp::Interpret(cmd); } }