void FileChooserImpl::accept_browser() { int i = int(fbrowser_->selected()); if (i == -1) { accept_editor(editor_); return; } i = filter_map_[i]; const String& path = *dir_->path(); const String& name = *dir_->name(i); int length = path.length() + name.length(); char* tmp = new char[length + 1]; sprintf( tmp, "%.*s%.*s", path.length(), path.string(), name.length(), name.string() ); editor_->field(tmp); selected_ = editor_->text(); if (dir_->is_directory(i)) { if (chdir(String(tmp, length))) { editor_->field(*dir_->path()); fchooser_->focus(editor_); } else { /* should generate an error message */ } } else { fchooser_->dismiss(true); } delete tmp; }
void SymChooserImpl::accept_browser() { int bi = browser_index_; int i = int(fbrowser_[bi]->selected()); if (i == -1) { editor_accept(editor_); return; } // i = filter_map_[i]; const String& path = dir_[bi]->path(); const String& name = dir_[bi]->name(i); int length = path.length() + name.length(); char* tmp = new char[length + 1]; sprintf( tmp, "%.*s%.*s", path.length(), path.string(), name.length(), name.string() ); //printf("accept_browser %s\n", tmp); editor_->field(tmp); selected_ = editor_->text(); if (dir_[bi]->is_directory(i)) { if (chdir(bi, i)) { fchooser_->focus(editor_); } else { /* should generate an error message */ } } else { fchooser_->dismiss(true); } delete [] tmp; }
void SymChooserImpl::accept_browser_index(int bindex) { int i = int(fbrowser_[bindex]->selected()); if (i == -1) { return; } // i = filter_map_[i]; SymDirectory* dir = dir_[bindex]; const String& path = dir->path(); const String& name = dir->name(i); Symbol* sym = dir->symbol(i); int length = path.length() + name.length(); char* tmp = new char[length + 2]; sprintf( tmp, "%.*s%.*s", path.length(), path.string(), name.length(), name.string() ); editor_->field(tmp); last_selected_ = tmp; last_index_ = i; selected_ = editor_->text(); if (dir->is_directory(i)) { if (chdir(bindex, i)) { fchooser_->focus(editor_); } else { /* should generate an error message */ } } else { clear(bindex+1); browser_index_ = bindex; // fchooser_->dismiss(true); } delete [] tmp; }
void SymChooserImpl::load(int bindex) { SymDirectory& d = *dir_[bindex]; Browser& b = *fbrowser_[bindex]; WidgetKit& kit = *kit_; kit.push_style(); kit.style(style_); const LayoutKit& layout = *LayoutKit::instance(); int dircount = d.count(); delete [] filter_map_; int* index = new int[dircount]; filter_map_ = index; //printf("loading %d\n", bindex); for (int i = 0; i < dircount; i++) { const String& f = d.name(i); boolean is_dir = d.is_directory(i); if ((is_dir && filtered(f, directory_filter_)) || (!is_dir && filtered(f, filter_)) ) { Glyph* name = kit.label(f); if (is_dir) { if (d.symbol(i) && d.symbol(i)->type == TEMPLATE) { name = layout.hbox(name, kit.label("_")); }else{ name = layout.hbox(name, kit.label(".")); } } Glyph* label = new Target( layout.h_margin(name, 3.0, 0.0, 0.0, 15.0, fil, 0.0), TargetPrimitiveHit ); TelltaleState* t = new TelltaleState(TelltaleState::is_enabled); b.append_selectable(t); b.append(new ChoiceItem(t, label, kit.bright_inset_frame(label))); *index++ = i; } } // the order of the following two statements is important for carbon // to avoid a premature browser request which ends up showing an // empty list. fbrowser_[bindex]->refresh(); editor_->field(d.path()); kit.pop_style(); }
void FileChooserImpl::build() { WidgetKit& kit = *kit_; const LayoutKit& layout = *LayoutKit::instance(); Style* s = style_; kit.push_style(); kit.style(s); String caption(""); s->find_attribute("caption", caption); String subcaption("Enter filename:"); s->find_attribute("subcaption", subcaption); String open("Open"); s->find_attribute("open", open); String close("Cancel"); s->find_attribute("cancel", close); long rows = 10; s->find_attribute("rows", rows); const Font* f = kit.font(); FontBoundingBox bbox; f->font_bbox(bbox); Coord height = rows * (bbox.ascent() + bbox.descent()) + 1.0; Coord width; if (!s->find_attribute("width", width)) { width = 16 * f->width('m') + 3.0; } Action* accept = new ActionCallback(FileChooserImpl)( this, &FileChooserImpl::accept_browser ); Action* cancel = new ActionCallback(FileChooserImpl)( this, &FileChooserImpl::cancel_browser ); if (editor_ == nil) { editor_ = DialogKit::instance()->field_editor( *dir_->path(), s, new FieldEditorCallback(FileChooserImpl)( this, &FileChooserImpl::accept_editor, &FileChooserImpl::cancel_editor ) ); } // added by ro2m: check for style for default selection String defsel(""); if(s->find_attribute("defaultSelection", defsel)) { editor_->field(defsel); } fbrowser_ = new FileBrowser(kit_, accept, cancel); fchooser_->remove_all_input_handlers(); fchooser_->append_input_handler(editor_); fchooser_->append_input_handler(fbrowser_); Glyph* g = layout.vbox(); if (caption.length() > 0) { g->append(layout.rmargin(kit.fancy_label(caption), 5.0, fil, 0.0)); } if (subcaption.length() > 0) { g->append(layout.rmargin(kit.fancy_label(subcaption), 5.0, fil, 0.0)); } g->append(layout.vglue(5.0, 0.0, 2.0)); g->append(editor_); g->append(layout.vglue(15.0, 0.0, 12.0)); g->append( layout.hbox( layout.vcenter( kit.inset_frame( layout.margin( layout.natural_span(fbrowser_, width, height), 1.0 ) ), 1.0 ), layout.hspace(4.0), kit.vscroll_bar(fbrowser_->adjustable()) ) ); g->append(layout.vspace(15.0)); if (s->value_is_on("filter")) { FieldEditorAction* action = new FieldEditorCallback(FileChooserImpl)( this, &FileChooserImpl::accept_filter, nil ); filter_ = add_filter( s, "filterPattern", "", "filterCaption", "Filter:", g, action ); if (s->value_is_on("directoryFilter")) { directory_filter_ = add_filter( s, "directoryFilterPattern", "", "directoryFilterCaption", "Directory Filter:", g, action ); } else { directory_filter_ = nil; } } else { filter_ = nil; directory_filter_ = nil; } g->append( layout.hbox( layout.hglue(10.0), layout.vcenter(kit.default_button(open, accept)), layout.hglue(10.0, 0.0, 5.0), layout.vcenter(kit.push_button(close, cancel)), layout.hglue(10.0) ) ); fchooser_->body( layout.back( layout.vcenter(kit.outset_frame(layout.margin(g, 5.0)), 1.0), new Target(nil, TargetPrimitiveHit) ) ); fchooser_->focus(editor_); kit.pop_style(); load(); }