Beispiel #1
0
GraphicComp* ImportCmd::PostDialog () {
    bool imported = false;
    GraphicComp* comp = nil;
    Editor* ed = GetEditor();

    Style* style;
    bool reset_caption = false;
    if (chooser_ == nil) {
	style = new Style(Session::instance()->style());
	style->attribute("subcaption", "Import graphic from file:");
	style->attribute("open", "Import");
	chooser_ = DialogKit::instance()->file_chooser(".", style);
	Resource::ref(chooser_);
    } else {
	style = chooser_->style();
    }
    while (chooser_->post_for(ed->GetWindow())) {
	const String* str = chooser_->selected();
	if (str != nil) {
	    NullTerminatedString ns(*str);
	    comp = Import(ns.string());
	    if (comp != nil) {
		break;
	    }
	    style->attribute("caption", "Import failed!");
	    reset_caption = true;
	}
    }
    if (reset_caption) {
	style->attribute("caption", "");
    }
    return comp;
}
Beispiel #2
0
Chooser::Chooser(const char* name, const char* prompt) {
    Style* s = new Style(Session::instance()->style());
    s->attribute("name", name);
    s->attribute("subcaption", prompt);
    chooser_ = DialogKit::instance()->file_chooser(".", s, nil);
    Resource::ref(chooser_);
    style_ = s;
    Resource::ref(style_);
}
Beispiel #3
0
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", "");
    }
}
Beispiel #4
0
MonoKit::MonoKit() {
    impl_ = new MonoKitImpl(this);
    Style* s = Session::instance()->style();
    for (PropertyData* p = kit_props; p->path != nil; p++) {
        s->attribute(p->path, p->value, -5);
    }
}
Beispiel #5
0
Asker::Asker(const char* name, const char* prompt) {
    WidgetKit& kit = *WidgetKit::instance();
    const LayoutKit& layout = *LayoutKit::instance();
    Style* s = new Style(kit.style());
    s->attribute("name", name);
    editor_ = DialogKit::instance()->field_editor(
	"", s, new FieldEditorCallback(Asker)(
	    this, &Asker::accept_editor, &Asker::cancel_editor
	)
    );
    Glyph* sep = layout.vglue(11, fil, 11);
    dialog_ = new Dialog(
	kit.inset_frame(
	    layout.margin(
		layout.vbox(
		    layout.hbox(kit.label(prompt), layout.hglue()),
		    sep,
		    editor_,
		    sep,
		    layout.hbox(
			layout.hglue(100, fil, 100),
			kit.default_button("OK", new AskerCallback(accept)),
			layout.hglue(9, 0, 9),
			kit.push_button("Cancel", new AskerCallback(cancel))
		    )
		),
		12, 12
	    )
        ),
	s
    );
    dialog_->append_input_handler(editor_);
    dialog_->next_focus();
    Resource::ref(dialog_);
}
Beispiel #6
0
Confirmer::Confirmer(const char* name, const char* prompt) {
    WidgetKit& kit = *WidgetKit::instance();
    const LayoutKit& layout = *LayoutKit::instance();
    Style* s = new Style(kit.style());
    s->attribute("name", name);
    Glyph* sep = layout.hspace(8);
    dialog_ = new Dialog(
	kit.outset_frame(
	    layout.margin(
		layout.vbox(
		    layout.hbox(kit.label(prompt), layout.hglue()),
		    layout.vglue(16, 20, 8),
		    layout.hbox(
			layout.hglue(30, fil, 0),
			kit.push_button(
			    "Cancel", new ConfirmerCallback(cancel)
			),
			sep,
			kit.push_button(
			    "No", new ConfirmerCallback(no)
			),
			sep,
			kit.push_button(
			    "Yes", new ConfirmerCallback(yes)
			)
		    )
		),
		12, 12
	    )
	),
	s
    );
    Resource::ref(dialog_);
}
Beispiel #7
0
static void* scons(Object*) {
#if HAVE_IV
	SymChooser* sc = nil;
IFGUI
	const char* caption = "Choose a Variable Name or";
	if (ifarg(1)) {
		caption = gargstr(1);
	}
	Style* style = new Style(Session::instance()->style());
	style->attribute("caption", caption);
	if (ifarg(2)) {
		Symbol* sym = hoc_lookup(gargstr(2));
		int type = RANGEVAR;
		if (sym) {
			type = sym->type;
		}
		sc = new SymChooser(new SymDirectory(type), WidgetKit::instance(), style, nil, 1);
	}else{
		sc = new SymChooser(nil, WidgetKit::instance(), style);
	}
	Resource::ref(sc);
ENDGUI
	return (void*)sc;
#else
	return (void*)0;
#endif /* HAVE_IV */
}
Beispiel #8
0
boolean SessionRep::match(
    const String& arg, const OptionDesc& o, int& i, int argc, char** argv
) {
    String opt(o.name);
    if (arg != opt) {
	if (o.style == OptionValueAfter) {
	    int n = opt.length();
	    if (opt == arg.left(n)) {
		style_->attribute(String(o.path), arg.right(n));
		return true;
	    }
	}
	return false;
    }
    String name, value;
    extract(arg, o, i, argc, argv, name, value);
    style_->attribute(name, value);
    return true;
}
void Application::open (DocumentViewer* viewer) {
    long index = viewer_info(viewer, _viewer);
    if (index < 0) {
        index = _viewer->count();
        ApplicationViewerInfo info;
        info._dialogs = new DialogManager();
        info._viewer = viewer;
        info._viewer->ref();
        info._viewer->map();
        info._window_name = nil;
        info._icon_name = nil;
        _viewer->append(info);
    }
    ApplicationViewerInfo& info = _viewer->item_ref(index);
    const char* name = viewer->document()->name();
    if (info._window_name == nil || strcmp(info._window_name, name) != 0) {
        delete info._window_name;
        delete info._icon_name;
        if (name != nil) {
            info._window_name = strcpy(new char[strlen(name) + 1], name);
            const char* icon_name = strrchr(name, '/');
            if (icon_name != nil) {
                icon_name += 1;
            } else {
                icon_name = name;
            }
            info._icon_name = strcpy(new char[strlen(name) + 1], name);
	    Style* s = info._viewer->style();
	    if (s == nil) {
		s = new Style(Session::instance()->style());
		info._viewer->style(s);
	    }
	    s->attribute("name", info._window_name);
	    s->attribute("iconName", info._icon_name);
        } else {
            info._window_name = nil;
            info._icon_name = nil;
        }
    }
}
Beispiel #10
0
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();
        }
    }
}
Beispiel #11
0
int main (int argc, char** argv) {
    World world("iclass", argc, argv, options, properties);
    const char* recursive = world.GetAttribute("recursive");
    const char* verbose = world.GetAttribute("verbose");
    const char* CPlusPlusFiles = world.GetAttribute("CPlusPlusFiles");
    ClassBuffer* buffer = new ClassBuffer(
        strcmp(recursive, "true") == 0, strcmp(verbose, "true") == 0,
	strcmp(CPlusPlusFiles, "true") == 0
    );

    for (int i = 1; i < argc; ++i) {
        buffer->Search(argv[i]);
    }

    IClass* iclass = new IClass(buffer);
    ApplicationWindow* window = new ApplicationWindow(iclass);
    Style* s = new Style(Session::instance()->style());
    s->attribute("name", "InterViews class browser");
    s->attribute("iconName", "iclass");
    window->style(s);
    window->map();
    iclass->Run();
    return 0;
}
Beispiel #12
0
Reporter::Reporter(const char* name, const char* prompt) {
    WidgetKit& kit = *WidgetKit::instance();
    const LayoutKit& layout = *LayoutKit::instance();
    Style* s = new Style(kit.style());
    s->attribute("name", name);
    dialog_ = new Dialog(
	kit.outset_frame(
	    layout.margin(
		layout.vbox(
		    layout.hbox(kit.label(prompt), layout.hglue()),
		    layout.vglue(16, 20, 8),
		    layout.hbox(
			layout.hglue(36, fil, 0),
			kit.push_button("OK", new ReporterCallback(ok))
		    )
		),
		12, 12
	    )
	),
	s
    );
    Resource::ref(dialog_);
}
Beispiel #13
0
void GraphExportCmd::Execute () {
    Editor* ed = GetEditor();

    Style* style;
    boolean reset_caption = false;
    if (chooser_ == nil) {
	style = new Style(Session::instance()->style());
	style->attribute("subcaption", "Export selected graphics to file:");
	style->attribute("open", "Export");
	const char *formats_svg[] = {"EPS", "idraw EPS", "drawtool", "SVG"};
	const char *formats_nosvg[] = {"EPS", "idraw EPS", "drawtool", "dot"};
        const char *svg_arg = unidraw->GetCatalog()->GetAttribute("svgexport");
        const boolean svg_flag = svg_arg && strcmp(svg_arg, "true")==0;
	const char **formats = svg_flag ? formats_svg : formats_nosvg;
	int nformats = (svg_flag ? sizeof(formats_svg) : sizeof(formats_nosvg)) / sizeof(char*);
	const char *commands_svg[] = {"ghostview %s", "idraw %s", "drawtool %s", "firefox %s"};
	const char *commands_nosvg[] = {"ghostview %s", "idraw %s", "drawtool %s", "dot %s"};
	const char **commands = svg_flag ? commands_svg : commands_nosvg;
	chooser_ = new ExportChooser(".", WidgetKit::instance(), style,
				     formats, nformats, commands, nil, true);
	Resource::ref(chooser_);
    } else {
	style = chooser_->style();
    }
    boolean again; 
    while (again = chooser_->post_for(ed->GetWindow())) {
	const String* str = chooser_->selected();
	if (str != nil) {
	    NullTerminatedString ns(*str);
	    const char* name = ns.string();
	    style->attribute("caption", "              " );
	    chooser_->twindow()->repair();
	    chooser_->twindow()->display()->sync();

	    Catalog* catalog = unidraw->GetCatalog();
	    boolean ok = true;

	    if (!chooser_->to_printer() && catalog->Exists(name) && catalog->Writable(name)) {
		char buf[CHARBUFSIZE];
		sprintf(buf, "\"%s\" already exists,", name);
		GConfirmDialog* dialog = new GConfirmDialog(buf, "Overwrite?");
	    	Resource::ref(dialog);
	    	ok = dialog->post_for(ed->GetWindow());
	    	Resource::unref(dialog);
	    }

	    if (ok) { 
		ed->GetWindow()->cursor(hourglass);
		chooser_->twindow()->cursor(hourglass);
		if (Export(ns.string())) {
		    again = false;
		    break;
		}
		style->attribute("caption", "Export failed!" );
		reset_caption = true;
		ed->GetWindow()->cursor(arrow);
		chooser_->twindow()->cursor(arrow);
	    }
	}
    }

    chooser_->unmap();
    if (reset_caption) {
      style->attribute("caption", "              " );
    }
    if (!again)
	ed->GetWindow()->cursor(arrow);
    return;
}
Beispiel #14
0
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", "");
    }
}