class MyEditableList

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)

Attributes

caller[RW]
headers[RW]
headertypes[RW]
info[RW]
is_embedded[RW]
list_id[RW]
list_model[RW]
parentM[RW]
pop[RW]
selected[RW]
single_list_mode[R]
tip[RW]
title[RW]
tmp[RW]

Public Class Methods

new(caller) click to toggle source
Calls superclass method
# File lib/ListHolder/EditableList.rb, line 12
def initialize(caller)
        @caller=caller
        @back_button=false
        @list_id=nil
        @parentM=nil
        @info=caller.info
        @title="list"
        @tip=Gtk::Tooltips.new
        super(nil)
        @list_model=ListModel.new(self)
        set_enable_grid_lines(case get_conf(0,0,"grid")
                when "both" then Gtk::TreeView::GridLines::BOTH
                when "vertical" then Gtk::TreeView::GridLines::VERTICAL
                when "horizontal" then Gtk::TreeView::GridLines::HORIZONTAL
                        else Gtk::TreeView::GridLines::NONE
                end
        ) if Gtk.check_version?(2,10,9)
        set_enable_tree_lines(true)
        set_fixed_height_mode(false)
        set_reorderable(false)# drag and drop of rows
        headers_clickable=false
        set_rules_hint(true)
        selection.set_mode(Gtk::SELECTION_MULTIPLE)
        signal_connect('cursor-changed') { |me|
                if !cursor[0].nil? and iter=model.get_iter(cursor[0])
                        id_at_cursor=iter[@list_model.column_of_id]
                        else
                        id_at_cursor=-1
                end
                if id_at_cursor != get_cursor_id
                        save_cursor_id(id_at_cursor)
                        einfo("#{self} selection changed to #{id_at_cursor}, notifying observers","list")
                        changed
                        begin
                                notify_observers(self)
                        rescue =>err
                                eerror("error notifying observers:#{err}","list")
                        end
                end
        }

        signal_connect("button-press-event"){|me,ev|
                holder.buttonholder.activate_default if ev.event_type == Gdk::Event::BUTTON2_PRESS
                false
        }
        @tmp=Hash.new
        @is_embedded=nil
        @keep_expanded=false

        signal_connect("row-collapsed"){|me, iter, path|
                me.expand_all if @keep_expanded
        }
        
        @popup=Gtk::Menu.new
end

Public Instance Methods

add_row(caller, added_id=nil) click to toggle source
# File lib/ListHolder/EditableList.rb, line 291
        def add_row(caller, added_id=nil)
                if added_id.nil?
                        run_events(get_id,'list-OnInsert-BeforeSQL')
                        added_id=@list_model.add_iter
                        run_events(get_id,'list-OnInsert-AfterSQL')
                        else
                                row_modified(added_id)
                end
#               @rowcount=@rowcount+1
                #select insereted
                #scroll_to_cursor(added_id)
                set_conf(get_id,0,"cursor",added_id)
        end
child_by_id(mid) click to toggle source
# File lib/ListHolder/EditableList.rb, line 309
def child_by_id(mid)
        @caller.notebook.moditem_by_id(mid)
end
column_by_id(column_id) click to toggle source
# File lib/ListHolder/EditableList.rb, line 328
def column_by_id(column_id)
        ret=nil
        columns.each{|col|
                if col.header['id'].to_i == column_id.to_i
                        ret=col
                        break
                end
        }
        ret
end
columns_height() click to toggle source
# File lib/ListHolder/EditableList.rb, line 339
def columns_height
        colh=0
        columns.each{|col|
                colh=col.header_widget.allocation.height if col.header_widget.allocation.height > colh
        }
        colh
end
create_skeleton() click to toggle source
# File lib/ListHolder/EditableList.rb, line 199
def create_skeleton
        if get_id.nil?
                edebug(" can't update","list","error")
                return
        end
        @keep_expanded=(gtk_attribute("keep_expanded") || "false") == "true"
        @single_list_mode=(gtk_attribute('single_list_mode')  || "false") == "true"
        set_model(nil)
        @list_model.create_skeleton
        set_info("initializing")
        @title=moditem["display"]
        while c=get_column(0)
                remove_column(c)
                c.wipe
        end

        
        col_num=1;
        @list_model.headers.sort{|a,b| a[1]["oid"].to_f<=>b[1]["oid"].to_f}.each{|hk,header|
                header['editable']="false" if header['writable']=="0"
                column=nil
                if column=MyColumn.new(self,header)
                        append_column(column)
                        col_num+=1
                end if header['visible']
        }
        einfo("#{self} skeleton created","list")
        set_search_column(get_conf(get_id,0,"search").to_i)
        
        set_info("loading")
        @caller.list_panel.update(self)
        @caller.advanced_filter.update
        @caller.sum_button.update
        @caller.buttonholder.update(self)
        #build context menu
        if single_list_mode
                @list_model.drbmodel.childs.each{|ch|
                        @popup.append(item=Gtk::MenuItem.new(ch["display"]))
                        item.signal_connect("activate",ch["id"].to_i){|me,child_id|
                                einfo("#{me.label.inspect}(#{child_id}) activated on #{get_cursor_id}")
                                holder.pack_child(child_id)
                        }
                }
        end
        #add back
        if @back_button
                @popup.append(item=Gtk::MenuItem.new("back"))
                        item.signal_connect("activate"){|me|
                        einfo("#{me.label} activated on #{get_cursor_id}")
                        parentM.holder.repack_self
                }
        end

        @popup.show_all
        signal_connect("button_release_event"){|me,ev|
          if ev.kind_of? Gdk::EventButton and ev.button == 3
                        @popup.popup(nil,nil,ev.button,ev.time)
                end
        }

        self
end
duplicate_selected(caller) click to toggle source
# File lib/ListHolder/EditableList.rb, line 275
def duplicate_selected(caller)
        ret=nil
        run_events(get_id,'list-OnDuplicate-BeforeSQL')
        selection.selected_each { |model, path, iter| ret=@list_model.duplicate_iter(iter)}
        run_events(get_id,'list-OnDuplicate-AfterSQL')
        ret
end
embedd?() click to toggle source
# File lib/ListHolder/EditableList.rb, line 94
def embedd?
        if @moditem && @moditem['on_embed'].length >0 
                eeval(@moditem['on_embed'],self)
                else 
                true
        end
end
get_cursor_id() click to toggle source
# File lib/ListHolder/EditableList.rb, line 166
def get_cursor_id
        get_conf(get_id,0,"cursor").to_i
end
get_id() click to toggle source
# File lib/ListHolder/EditableList.rb, line 102
def get_id
        @list_id
end
get_model() click to toggle source
# File lib/ListHolder/EditableList.rb, line 74
def get_model
        @list_model
end
holder() click to toggle source
# File lib/ListHolder/EditableList.rb, line 70
def holder
        @caller
end
inspect() click to toggle source
# File lib/ListHolder/EditableList.rb, line 363
def inspect
        "List(#{title})"
end
load_data(notifier,the_one=nil) click to toggle source
# File lib/ListHolder/EditableList.rb, line 133
def load_data(notifier,the_one=nil)
        @list_model.load_data(notifier,the_one=nil)
end
moditem() click to toggle source
# File lib/ListHolder/EditableList.rb, line 83
def moditem
        @list_model.moditem
end
my() click to toggle source
# File lib/ListHolder/EditableList.rb, line 127
def my
        @@my
end
next_editable_column(column) click to toggle source
# File lib/ListHolder/EditableList.rb, line 313
def next_editable_column(column)
        next_col=nil
        col_num=nil
        i=0
        columns.each{|col|
                col_num=i if col == column
                if !col_num.nil? and i > col_num and col.header["editable"]=="true" and col.header["type"]!='gtk_toggle'
                        next_col=col
                        break
                end
                i+=1
        }
        next_col
end
parentselected() click to toggle source
# File lib/ListHolder/EditableList.rb, line 80
def parentselected
        @list_model.parentselected
end
progress() click to toggle source
# File lib/ListHolder/EditableList.rb, line 86
def progress
        @caller.progress
end
refilter() click to toggle source
# File lib/ListHolder/EditableList.rb, line 137
def refilter
        @list_model.refilter
end
remove_selected(caller,ids=nil) click to toggle source
# File lib/ListHolder/EditableList.rb, line 283
def remove_selected(caller,ids=nil)
        ids=[get_cursor_id] if ids.nil?
        @removing=ids
        run_events(get_id,'list-OnRemove-BeforeSQL')
        @list_model.remove_iters(ids)
        run_events(get_id,'list-OnRemove-AfterSQL')
end
row_modified(modified_id=list.get_cursor_id) click to toggle source
# File lib/ListHolder/EditableList.rb, line 305
def row_modified(modified_id=list.get_cursor_id)
        @list_model.row_modified(modified_id)
end
save_config() click to toggle source
# File lib/ListHolder/EditableList.rb, line 77
def save_config
        set_conf(get_id,0,"search",search_column)
end
save_cursor_id(id_to_set) click to toggle source
# File lib/ListHolder/EditableList.rb, line 162
def save_cursor_id(id_to_set)
        edebug("saving cursor to #{id_to_set.inspect}","list")
        set_conf(get_id,0,"cursor",id_to_set)
end
scroll_to_cursor(id_to_scroll=get_cursor_id,scroll=true) click to toggle source
# File lib/ListHolder/EditableList.rb, line 170
def scroll_to_cursor(id_to_scroll=get_cursor_id,scroll=true)
        set_cursor_id(id_to_scroll,scroll)
        changed
        notify_observers(self)
        expand_all if @keep_expanded
        get_cursor_id
end
selected_ids() click to toggle source
# File lib/ListHolder/EditableList.rb, line 269
def selected_ids
        ids=Array.new
        selection.selected_each { |model, path, iter| ids.push(iter[@list_model.column_of_id])}
        ids
end
set_back_button(bb=true) click to toggle source
# File lib/ListHolder/EditableList.rb, line 117
def set_back_button(bb=true)
        @back_button=bb
        self
end
set_cursor_id(id_to_set=get_cursor_id,scroll=true) click to toggle source
# File lib/ListHolder/EditableList.rb, line 141
def set_cursor_id(id_to_set=get_cursor_id,scroll=true)
        current_id=cursor[0] ? @list_model.sorter.get_iter(cursor[0])[@list_model.column_of_id] : -1

        if current_id != id_to_set.to_i
                if iter=@list_model.iter_of_id(id_to_set)
                        edebug("setting cursor to #{id_to_set.inspect}","list")
                        expand_to_path(iter.path)
                        scroll_to_cell(iter.path,nil,false,0,0) if scroll
                        set_cursor(iter.path,nil,nil)
                        save_cursor_id(id_to_set)
                else
                        unless cursor[0].nil?
                                edebug("setting cursor none #{id_to_set != -1?"insted of #{id_to_set.inspect}":""}","list")
                                set_cursor(Gtk::TreePath.new,nil,nil)
                        end
                        save_cursor_id(-1)
                end
        end
        iter
end
set_id(newid) click to toggle source
# File lib/ListHolder/EditableList.rb, line 107
        def set_id(newid)
                if newid.to_i != @list_id.to_i
#                       save_config
                        @list_id=newid.to_i
                        @caller.set_id(list_id)
                        create_skeleton
                end
                self
        end
set_info(new_info) click to toggle source
# File lib/ListHolder/EditableList.rb, line 178
def set_info(new_info)
        info.set_label(new_info)
end
set_parentM(parentM) click to toggle source
# File lib/ListHolder/EditableList.rb, line 122
def set_parentM(parentM)
        @parentM=parentM
        self
end
to_s() click to toggle source
# File lib/ListHolder/EditableList.rb, line 366
def to_s
        inspect
end
update(notifier) click to toggle source
# File lib/ListHolder/EditableList.rb, line 262
def update(notifier)
        @list_model.update(notifier)
        scroll_to_cursor
        update_tip
        self
end
update_tip() click to toggle source
# File lib/ListHolder/EditableList.rb, line 182
def update_tip
        case get_conf(0,0,"list-tooltip")
                when "filters" then
                        t="filters:"
                        @caller.list_panel.list_filter.columns.each_value{|frenderer|
                                fl=get_conf(get_id,frenderer.header['id'],"filter")
                                case frenderer.header['type']
                                        when 'gtk_combo', 'gtk_const_combo' then fl = (fl=="-1" or fl=="") ? "" : "=#{fl}"
                                end
                                t+="\n#{frenderer.header['header']}: #{fl}" if !fl.nil? and fl.length>0
                        }
                        t="#{t}\nnone" if t=="filters:"
                        @tip.set_tip(self,t,'extra hint')
                        @tip.enable
        end
end
wipe() click to toggle source
# File lib/ListHolder/EditableList.rb, line 347
def wipe
        save_config
        set_model(nil)
        if @list_model.thread and @list_model.thread.alive?
                progress.killed(object_id)
                p Thread.kill(@list_model.thread)
                while @list_model.thread.alive? do ecode("waiting for thread"); end
        end
  @list_model.wipe
  while c=get_column(0)
                remove_column(c)
                c.wipe
  end
        destroy
end