|
From: Hans F. <fu...@us...> - 2004-06-10 14:35:32
|
Update of /cvsroot/neelix/neelix/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9620/view Modified Files: fox.rb Log Message: The shelf is all but done now. I am adding, and subtracting. I am the operator of my pocket calculator... Index: fox.rb =================================================================== RCS file: /cvsroot/neelix/neelix/view/fox.rb,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- fox.rb 10 Jun 2004 06:25:29 -0000 1.19 +++ fox.rb 10 Jun 2004 14:35:23 -0000 1.20 @@ -1,48 +1,257 @@ require 'fox' include Fox -LAYOUT_FILL_XY = LAYOUT_FILL_X|LAYOUT_FILL_Y -# app -app = FXApp.new('Neelix', 'fugalh') -app.init(ARGV) +class CookbookForm < FXVerticalFrame + def initialize(parent,o) + super(parent) + @cookbook = o -# main window -mw = FXMainWindow.new(app, 'Neelix') -mw.resize(800,600) + FXLabel.new(self,"Name") + @name = FXTextField.new(self, 80) -# menu -menubar = FXMenubar.new(mw) + @name.connect(SEL_COMMAND) do |sender,sel,data| + @cookbook.name = data + end -filemenu = FXMenuPane.new(mw) -FXMenuCommand.new(filemenu, "&Exit", nil, mw.getApp(), FXApp::ID_QUIT) -FXMenuTitle.new(menubar, "&File", nil, filemenu) + populate + end + def populate + return if not @cookbook + @name.text = @cookbook.name + end + def cookbook=(o) + @cookbook = o + populate + end +end +class CategoryForm < FXVerticalFrame + def initialize(parent,o) + super(parent) + @category = o -actionmenu = FXMenuPane.new(mw) -actions={} -actions['add_cookbook'] = FXMenuCommand.new(actionmenu, "Add Cook&book", nil) -actions['add_cookbook'].enable -actions['add_category'] = FXMenuCommand.new(actionmenu, "Add &Category", nil) -actions['add_category'].disable -actions['add_recipe'] = FXMenuCommand.new(actionmenu, "Add &Recipe", nil) -actions['add_recipe'].disable -FXMenuTitle.new(menubar,"&Action",nil,actionmenu) -actions['add_cookbook'].connect(SEL_COMMAND) { - c = $replicator.create('cookbook',{'name'=>"New Cookbook"}) -} -actions['add_category'].connect(SEL_COMMAND) { puts "TODO: Add Category proc" } -actions['add_recipe'].connect(SEL_COMMAND) { puts "TODO: Add Recipe proc" } + FXLabel.new(self,"Name") + @name = FXTextField.new(self,80) -helpmenu = FXMenuPane.new(mw) -FXMenuCommand.new(helpmenu, "&About Neelix...").connect(SEL_COMMAND) { - FXMessageBox.information(mw, MBOX_OK, "About Neelix", - "Neelix is cool.\nhttp://sf.net/projects/neelix\n\nDedicated to Erin Fugal") -} -FXMenuTitle.new(menubar, "&Help", nil, helpmenu, LAYOUT_RIGHT) + @name.connect(SEL_COMMAND) do |sender,sel,data| + @category.name = data + end + + populate + end + def populate + return if not @category + @name.text = @category.name + end + def category=(o) + @category = o + populate + end +end +class RecipeForm < FXVerticalFrame + def initialize(parent,r) + super(parent) + @recipe = r -# splitter -splitter = FXSplitter.new(mw,SPLITTER_HORIZONTAL|LAYOUT_FILL_XY) + # create widgets + FXLabel.new(self,"Name") + @name = FXTextField.new(self, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) -# shelf + FXLabel.new(self,"Author") + @author = FXTextField.new(self, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + + FXLabel.new(self,"Oven Temp.") + @temp = FXTextField.new(self, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + + FXLabel.new(self,"Total Time") + @tottime = FXTextField.new(self, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + + FXLabel.new(self,"Yields") + @yields = FXTextField.new(self, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + + FXLabel.new(self,"Ingredients") + frame = FXHorizontalFrame.new(self,LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0) + ingredientFrame = FXVerticalFrame.new(frame, FRAME_NORMAL|LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0) + @ingredientList = FXList.new(ingredientFrame,5,nil,0,LAYOUT_FILL_X|LIST_SINGLESELECT) + + frame = FXVerticalFrame.new(frame) + @add = FXButton.new(frame,"Add Ingredient") + @up = FXButton.new(frame,"Move Up") + @delete = FXButton.new(frame,"Delete") + @up.enabled = false + @delete.enabled = false + + FXLabel.new(self,"Directions") + frame = FXVerticalFrame.new(self, FRAME_NORMAL|LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0) + @directions = FXText.new(frame, nil, 0, LAYOUT_FILL_X) + @directions.visCols=80 + + FXLabel.new(self,"Notes") + frame = FXVerticalFrame.new(self, FRAME_NORMAL|LAYOUT_FILL_X, 0,0,0,0, 0,0,0,0) + @notes = FXText.new(frame, nil, 0, LAYOUT_FILL_X) + @notes.visCols=80 + + # connections + @name.connect(SEL_COMMAND) do |sender,sel,data| + @recipe.name = data + end + + @author.connect(SEL_COMMAND) do |sender,sel,data| + @recipe.author = data + end + + @temp.connect(SEL_COMMAND) do |sender,sel,data| + @recipe.temp = data + end + + @tottime.connect(SEL_COMMAND) do |sender,sel,data| + @recipe.tottime = data + end + + @yields.connect(SEL_COMMAND) do |sender,sel,data| + @recipe.yields = data + end + + @ingredientList.connect(SEL_SELECTED) do |sender,sel,data| + @up.enabled = (data != 0) + @delete.enabled = true + @ingredientList.setCurrentItem(data) + end + + @ingredientList.connect(SEL_COMMAND) do |snd,sel,data| + @ingredientList.selectItem(data) + end + + @ingredientList.connect(SEL_DOUBLECLICKED) do |sender,sel,data| + ingredient = @recipe.ingredients.sort[data] + + ingredientDialog = FXDialogBox.new(self,"Edit Ingredient") + + FXLabel.new(ingredientDialog,"Quantity") + quantity = FXTextField.new(ingredientDialog, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + quantity.text = ingredient.quantity.to_s + + FXLabel.new(ingredientDialog,"Measure") + measures = FXListBox.new(ingredientDialog, 5, nil, 0, FRAME_SUNKEN|FRAME_THICK|LISTBOX_NORMAL|LAYOUT_FILL_X) + $replicator.measures.each do |measure| + measures << measure.name + measures.currentItem = measures.numItems - 1 if measure === ingredient.measure + end + + FXLabel.new(ingredientDialog,"Food") + food = FXTextField.new(ingredientDialog, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + food.text = ingredient.food.name + + FXLabel.new(ingredientDialog,"Modifier") + modifier = FXTextField.new(ingredientDialog, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + modifier.text = ingredient.modifier + + FXButton.new(ingredientDialog,"Accept",nil,ingredientDialog,FXDialogBox::ID_ACCEPT) + FXButton.new(ingredientDialog,"Cancel",nil,ingredientDialog,FXDialogBox::ID_CANCEL) + if ingredientDialog.execute == 1 then + ingredient.quantity = quantity.text + ingredient.measure = $replicator.measures[measures.currentItem] + ingredient.modifier = (modifier.text == '' ? nil : modifier.text) + + new_food = food.text + food = $replicator.find_food(new_food) + food = $replicator.create('food', {'name' => new_food}) if food.nil? + ingredient.food = food + end + end + + @add.connect(SEL_COMMAND) do |sender,sel,data| + ingredientDialog = FXDialogBox.new(self,"Add Ingredient") + + FXLabel.new(ingredientDialog,"Quantity") + quantity = FXTextField.new(ingredientDialog, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + quantity.text = '0.0' + + FXLabel.new(ingredientDialog,"Measure") + measures = FXListBox.new(ingredientDialog, 5, nil, 0, FRAME_SUNKEN|FRAME_THICK|LISTBOX_NORMAL|LAYOUT_FILL_X) + $replicator.measures.each { |measure| measures << measure.name } + + FXLabel.new(ingredientDialog,"Food") + food = FXTextField.new(ingredientDialog, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + + FXLabel.new(ingredientDialog,"Modifier") + modifier = FXTextField.new(ingredientDialog, 80, nil, 0, LAYOUT_FILL_X|TEXTFIELD_NORMAL) + + FXButton.new(ingredientDialog,"Accept",nil,ingredientDialog,FXDialogBox::ID_ACCEPT) + FXButton.new(ingredientDialog,"Cancel",nil,ingredientDialog,FXDialogBox::ID_CANCEL) + if ingredientDialog.execute == 1 then + quantity = quantity.text + measure = $replicator.measures[measures.currentItem] + modifier = (modifier.text == '' ? nil : modifier.text) + + new_food = food.text + food = $replicator.find_food(new_food) + food = $replicator.create('food', {'name' => new_food}) if food.nil? + + Presenter::addIngredient(@recipe, $replicator.create('ingredient',{ + 'recipe_id' => @recipe.id, + 'measure_id' => measure.id, + 'quantity' => quantity, + 'food_id' => food.id, + 'modifier' => modifier})) + end + end + + @up.connect(SEL_COMMAND) do |sender,sel,data| + index = @ingredientList.currentItem + if index > 0 + Presenter::promoteIngredient(@recipe, index) + @ingredientList.selectItem(index - 1,true) + end + end + + @delete.connect(SEL_COMMAND) do |sender,sel,data| + selectedIndices = (0 .. @ingredientList.numItems-1).select do |i| + @ingredientList.itemSelected?(i) + end + selectedIndices.each do |index| + Presenter::deleteIngredient(@recipe, index) + end + end + + @directions.connect(SEL_CHANGED) do |sender,sel,data| + @recipe.directions = @directions.text + end + + @notes.connect(SEL_CHANGED) do |sender,sel,data| + @recipe.note = @notes.text + end + + populate + end + + def populate + return if not @recipe + @name.text = @recipe.name + @author.text = @recipe.author + @temp.text = @recipe.temp + @tottime.text = @recipe.tottime + @yields.text = @recipe.yields + + refreshIngredients + @recipe.ingredients.add_observer { refreshIngredients } + + @directions.text = @recipe.directions + @notes.text = @recipe.note + end + + def refreshIngredients + @ingredientList.clearItems + @recipe.ingredients.sort.each do |ingredient| + @ingredientList.appendItem(ingredient.to_s) + end + end + + def recipe=(r) + @recipe = r + populate + update + end +end class Tree attr_accessor :data, :children def initialize(data=nil) @@ -56,7 +265,6 @@ TREELIST_SINGLESELECT| TREELIST_SHOWS_LINES|TREELIST_SHOWS_BOXES|TREELIST_ROOT_BOXES| LAYOUT_FILL_XY) - $replicator.cookbooks.add_observer { rebuild } rebuild end @@ -103,18 +311,23 @@ if ti ti.data = t.data n = ti.first - while n - if not t.children.inject(false) {|memo,obj| memo or obj.data == n.data} - removeItem(n) - end - n = n.next + else + n = self.firstItem + end + while n + n2 = n.next + if not t.children.inject(false) {|memo,obj| memo or obj.data == n.data} + removeItem(n) end + n = n2 end t.children.each do |n| - a = findItemByData(n.data) + i = n.data + a = findItemByData(i) if not a - a = FXTreeItem.new(n.data.name) - a.data = n.data + a = FXTreeItem.new(i.name) + a.data = i + i.add_observer { a.text = i.name; self.update } addItemLast(ti,a) end synctree(n,a) @@ -129,32 +342,93 @@ end end + +LAYOUT_FILL_XY = LAYOUT_FILL_X|LAYOUT_FILL_Y +# app +app = FXApp.new('Neelix', 'fugalh') +app.init(ARGV) + +# main window +mw = FXMainWindow.new(app, 'Neelix') +mw.resize(800,600) + +# menu +menubar = FXMenubar.new(mw) + +filemenu = FXMenuPane.new(mw) +FXMenuCommand.new(filemenu, "&Exit", nil, mw.getApp(), FXApp::ID_QUIT) +FXMenuTitle.new(menubar, "&File", nil, filemenu) + +actionmenu = FXMenuPane.new(mw) +actions={} +actions['add_cookbook'] = FXMenuCommand.new(actionmenu, "Add Cookbook", nil) +actions['add_cookbook'].enable +actions['add_category'] = FXMenuCommand.new(actionmenu, "Add Category", nil) +actions['add_category'].disable +actions['add_recipe'] = FXMenuCommand.new(actionmenu, "Add Recipe", nil) +actions['add_recipe'].disable +actions['del_cookbook'] = FXMenuCommand.new(actionmenu, "Delete Cookbook", nil) +actions['del_cookbook'].disable +actions['del_category'] = FXMenuCommand.new(actionmenu, "Delete Category", nil) +actions['del_category'].disable +actions['del_recipe'] = FXMenuCommand.new(actionmenu, "Delete Recipe", nil) +actions['del_recipe'].disable +FXMenuTitle.new(menubar,"&Action",nil,actionmenu) + +helpmenu = FXMenuPane.new(mw) +FXMenuCommand.new(helpmenu, "&About Neelix...").connect(SEL_COMMAND) { + FXMessageBox.information(mw, MBOX_OK, "About Neelix", + "Neelix is cool.\nhttp://sf.net/projects/neelix\n\nDedicated to Erin Fugal") +} +FXMenuTitle.new(menubar, "&Help", nil, helpmenu, LAYOUT_RIGHT) + +# splitter +splitter = FXSplitter.new(mw,SPLITTER_HORIZONTAL|LAYOUT_FILL_XY) shelfbox = FXGroupBox.new(splitter, "Shelf", FRAME_GROOVE) +counterbox = FXGroupBox.new(splitter,"Counter",FRAME_GROOVE) + +# counter +counter = FXSwitcher.new(counterbox,LAYOUT_FILL_XY) +FXWindow.new(counter) +CookbookForm.new(counter,nil) +CategoryForm.new(counter,nil) +RecipeForm.new(counter,nil) + +# shelf shelfbox.width = 200 shelf = Shelf.new(shelfbox) shelf.connect(SEL_SELECTED) do |sender,sel,ptr| case ptr.data when Cookbook - #counterSwitcher.children[1].cookbook = ptr.data - #counterSwitcher.current = 1 + counter.children[1].cookbook = ptr.data + counter.current = 1 actions['add_cookbook'].enable actions['add_category'].enable actions['add_recipe'].disable + actions['del_cookbook'].enable + actions['del_category'].disable + actions['del_recipe'].disable when Category - #counterSwitcher.children[2].category = ptr.data - #counterSwitcher.current = 2 + counter.children[2].category = ptr.data + counter.current = 2 actions['add_cookbook'].enable actions['add_category'].disable actions['add_recipe'].enable + actions['del_cookbook'].disable + actions['del_category'].enable + actions['del_recipe'].disable when Recipe - #counterSwitcher.children[3].recipe = ptr.data - #counterSwitcher.current = 3 + counter.children[3].recipe = ptr.data + counter.current = 3 actions['add_cookbook'].enable actions['add_category'].disable actions['add_recipe'].disable + actions['del_cookbook'].disable + actions['del_category'].disable + actions['del_recipe'].enable else - #counterSwitcher.current = 0 + counter.current = 0 actions['add_cookbook'].enable actions['add_category'].disable actions['add_recipe'].disable @@ -165,10 +439,40 @@ shelf.expandTree(shelf.firstItem.first) shelf.makeItemVisible(shelf.firstItem.first.first) - -# counter -counter = FXGroupBox.new(splitter, "Counter", FRAME_GROOVE) - +# menu actions +actions['add_cookbook'].connect(SEL_COMMAND) do + c = $replicator.create('cookbook',{'name'=>"New Cookbook"}) + shelf.rebuild +end +actions['add_category'].connect(SEL_COMMAND) do + c = $replicator.create('category', + {'name'=>"New Category",'cookbook_id'=>shelf.currentItem.data.id }) + shelf.rebuild +end +actions['add_recipe'].connect(SEL_COMMAND) do + r = $replicator.create('recipe',{'name'=>'New Recipe'}) + c = shelf.currentItem.data + c.recipes << r + shelf.rebuild +end +actions['del_cookbook'].connect(SEL_COMMAND) do + i = shelf.currentItem + c = i.data + $replicator.cookbooks.delete(c) + shelf.rebuild +end +actions['del_category'].connect(SEL_COMMAND) do + i = shelf.currentItem + c = i.data + i.parent.data.categories.delete(c) + shelf.rebuild +end +actions['del_recipe'].connect(SEL_COMMAND) do + i = shelf.currentItem + r = i.data + i.parent.data.recipes.delete(r) + shelf.rebuild +end app.create mw.show |