Class: QDA::GUI::DocumentWindow

Inherits:
InspectorWindow show all
Includes:
Subscriber
Defined in:
lib/weft/wxgui/inspectors/document.rb

Constant Summary

Constants inherited from InspectorWindow

InspectorWindow::INSPECTOR_NB_STYLE

Constants inherited from WorkAreaWindow

WorkAreaWindow::W_WINDOW_DEF_SIZE

Instance Attribute Summary

Attributes inherited from InspectorWindow

#client

Instance Method Summary collapse

Methods included from Subscriber

#notify, #subscribe

Methods inherited from InspectorWindow

#associated_subscribers, #get_current_category, #on_activate, #on_code, #on_key_down, #on_uncode, #receive_text_font_changed

Methods inherited from WorkAreaWindow

#active?, #layout, #layout=, #on_focus

Constructor Details

#initialize(doc, client, workarea, layout) ⇒ DocumentWindow

Returns a new instance of DocumentWindow.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/weft/wxgui/inspectors/document.rb', line 7

def initialize(doc, client, workarea, layout)
		@doc = doc
		@client = client

  super(workarea, doc.title, layout) do | txt_parent | 
    text_box = DocTextViewer.new(txt_parent, @doc.dbid)
    text_box.set_font(@client.display_font)
    text_box.append_text( @doc.text )
    text_box.evt_enter_window do | e | 
      set_cursor Wx::Cursor.new(Wx::CURSOR_IBEAM)
    end
    text_box.evt_leave_window do | e | 
      set_cursor Wx::Cursor.new(Wx::CURSOR_ARROW)
    end
    text_box.show_position(0)
    text_box.insertion_point = 0
    text_box
  end

  construct_details_panel()
  set_icon( client.fetch_icon("document") )
  subscribe(@client, :document_changed, :document_deleted)
end

Instance Method Details

#construct_details_panelObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/weft/wxgui/inspectors/document.rb', line 81

def construct_details_panel()
  main_panel = Wx::Panel.new(@notebook, -1)
  sizer = Wx::BoxSizer.new(Wx::VERTICAL)
  title_box_label = Wx::StaticBox.new(main_panel, -1, 'Title')
  title_box_sizer = Wx::StaticBoxSizer.new(title_box_label,
                                          Wx::VERTICAL)
  @title_box = Wx::TextCtrl.new(main_panel, -1, @doc.title ) 
  title_box_sizer.add(@title_box, 0, 
                      Wx::ADJUST_MINSIZE|Wx::ALL|Wx::GROW, 4)
  sizer.add(title_box_sizer,0, Wx::ADJUST_MINSIZE|Wx::ALL|Wx::GROW, 4)

  info_panel = Wx::Panel.new(main_panel, -1)
  info_box_label = Wx::StaticBox.new(info_panel, -1, 'Information')
  info_box_sizer = Wx::StaticBoxSizer.new(info_box_label,
                                          Wx::VERTICAL)

  info_sizer = Wx::FlexGridSizer.new(2, 2, 5, 6)

  # Create date label
  info_sizer.add( Wx::StaticText.new(info_panel, -1, 'Created:') )
  date_text = @doc.create_date.strftime("%a %d/%m/%Y %H:%M:%S")
  @create_date_label = Wx::StaticText.new(info_panel, -1, date_text )
  info_sizer.add( @create_date_label )

  # Modified date label
  info_sizer.add( Wx::StaticText.new(info_panel, -1, 'Modified:') )
  date_text = @doc.mod_date.strftime("%a %d/%m/%Y %H:%M:%S")
  @mod_date_label =  Wx::StaticText.new(info_panel, -1, date_text)
  info_sizer.add(@mod_date_label)
  info_box_sizer.add(info_sizer, 0, 
                     Wx::GROW|Wx::ADJUST_MINSIZE|Wx::ALL, 4)
  info_panel.set_sizer( info_box_sizer )
  sizer.add(info_panel, 0, Wx::GROW|Wx::ALL|Wx::ADJUST_MINSIZE, 4)

  # The memo box
  memo_label = Wx::StaticBox.new(main_panel, -1, 'Memo')
  memo_sizer = Wx::StaticBoxSizer.new(memo_label, Wx::VERTICAL)

  @memo_box = Wx::TextCtrl.new(main_panel, -1, @doc.memo, 
                               Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                               Wx::TE_MULTILINE|Wx::TE_NOHIDESEL)
  @memo_box.evt_enter_window do | e | 
    set_cursor Wx::Cursor.new(Wx::CURSOR_IBEAM)
  end

  @memo_box.evt_leave_window do | e | 
    set_cursor Wx::Cursor.new(Wx::CURSOR_ARROW)
  end
  memo_sizer.add(@memo_box, 10, Wx::GROW|Wx::ALL|Wx::ADJUST_MINSIZE, 4)
  sizer.add(memo_sizer, 1, Wx::GROW|Wx::ADJUST_MINSIZE, 4)

  
  button = Wx::Button.new(main_panel, -1, 'Apply')
		button.evt_button(button.get_id) { | e | on_save_details(e) }
  sizer.add(button, 0, Wx::ALL|Wx::ALIGN_RIGHT|Wx::ADJUST_MINSIZE, 4)
  main_panel.set_sizer( sizer )

  @notebook.add_page(main_panel, 'details')
end

#jump_to(pos) ⇒ Object

scroll the window’s text box to the line containing the character at pos



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/weft/wxgui/inspectors/document.rb', line 66

def jump_to(pos)
  # p "----"
  # p pos
  true_pos = @text_box.true_index_to_pos(pos) 
  # p true_pos
  # there's something weird going on here. For some reason, if
  # jump_to is called just after the window has been constructed, 
  # the lines haven't yet been wrapped, and so it jumps to the
  # wrong position .. weird
  point =  @text_box.position_to_xy(true_pos)
  # p point.x
  # p point.y
  @text_box.show_position( true_pos )
end

#objectObject



31
32
33
# File 'lib/weft/wxgui/inspectors/document.rb', line 31

def object()
  @doc
end

#on_save_details(e) ⇒ Object



58
59
60
61
62
# File 'lib/weft/wxgui/inspectors/document.rb', line 58

def on_save_details(e)
  @doc.memo = @memo_box.value
  @doc.title = @title_box.value
  Wx::BusyCursor.busy { @client.app.save_document( @doc ) }
end

#on_set_text_font(font) ⇒ Object



46
47
48
# File 'lib/weft/wxgui/inspectors/document.rb', line 46

def on_set_text_font(font)
  @text_box.font = font
end

#receive_document_changed(new_doc) ⇒ Object



39
40
41
42
43
44
# File 'lib/weft/wxgui/inspectors/document.rb', line 39

def receive_document_changed(new_doc)
  if new_doc.dbid == @doc.dbid
    @doc = new_doc
    refresh() 
  end
end

#receive_document_deleted(doc) ⇒ Object



35
36
37
# File 'lib/weft/wxgui/inspectors/document.rb', line 35

def receive_document_deleted(doc)
  close() if doc.dbid == @doc.dbid
end

#refreshObject

update the display from the currently stored @doc TODO - currently doesn’t update text as this shouldn’t ever change



52
53
54
55
56
# File 'lib/weft/wxgui/inspectors/document.rb', line 52

def refresh()
  set_title(@doc.title)
  label = Time.now.strftime("%a %d/%m/%Y %H:%M:%S")
  @mod_date_label.set_label( label )
end