Class: QDA::GUI::InspectorWindow

Inherits:
WorkAreaWindow show all
Defined in:
lib/weft/wxgui/inspectors.rb

Overview

a WorkArea Window with a notebook layout with a coding panel including a text display in the first pane. Documents, Categories and Queries are all displayed using this model.

Constant Summary collapse

INSPECTOR_NB_STYLE =

GTK uses a notebook to fake MDI windows, so if running under WXGTK and using MDI mode, place the real notebook tabs on the right instead. Note that this combo (GTK+MDI) is not recommended

[]

Constants inherited from WorkAreaWindow

WorkAreaWindow::W_WINDOW_DEF_SIZE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from WorkAreaWindow

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

Constructor Details

#initialize(workarea, title, last_layout, &text_constructor) ⇒ InspectorWindow

Returns a new instance of InspectorWindow.



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
# File 'lib/weft/wxgui/inspectors.rb', line 89

def initialize(workarea, title, last_layout, &text_constructor)
  super(workarea, title, last_layout)

  @notebook = Wx::Notebook.new(self, -1, *INSPECTOR_NB_STYLE)
  panel_1 = Wx::Panel.new(@notebook, -1)
  sizer_1 = Wx::BoxSizer.new(Wx::VERTICAL)

  @text_box = text_constructor.call(panel_1)
  @text_box.evt_key_down { | e | on_key_down(e) }
  sizer_1.add(@text_box, 10, Wx::GROW|Wx::ALL, 4)

  butt_panel = Wx::Panel.new(panel_1, -1)
  bott_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
  
  @drop_down = CategoryDropDown.new(client, butt_panel, @text_box)
  bott_sizer.add(@drop_down, 3, Wx::ALL, 4)

  button = Wx::Button.new(butt_panel, -1, 'Mark')
  button.evt_button(button.get_id) { | e | on_code(e) }
  bott_sizer.add(button, 1, Wx::ALL, 4)

  button = Wx::Button.new(butt_panel, -1, 'Unmark')
  button.evt_button(button.get_id) { | e | on_uncode(e) }
  bott_sizer.add(button, 1, Wx::ALL, 4)
  
  if @text_box.respond_to?(:start_find)
    button = Wx::Button.new(butt_panel, -1, 'Find')
    button.evt_button(button.get_id) { @text_box.start_find(self) }
    bott_sizer.add(button, 1, Wx::ALL, 4)
  end
  
  # 		button = Wx::Button.new(butt_panel, -1, 'Note')
  # 		button.evt_button(button.get_id) { | e | on_code(e) }
  # 		bott_sizer.add(button, 1, Wx::ALL, 4, Wx::ALIGN_RIGHT)


  butt_panel.sizer = bott_sizer
  sizer_1.add(butt_panel, 0,
               Wx::GROW|Wx::ADJUST_MINSIZE|Wx::ALIGN_BOTTOM) 

  panel_1.set_sizer( sizer_1 )
  @notebook.add_page(panel_1, 'text') 
  evt_activate() { | e | on_activate(e) }
  subscribe(client, :text_font_changed)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



87
88
89
# File 'lib/weft/wxgui/inspectors.rb', line 87

def client
  @client
end

Instance Method Details

#associated_subscribersObject

(hopefully temporary) method – when this window is closed, all widgets containsed within it that are subscribers to application events should also be unsubscribed so their notify method isn’t later called - which causes a crash in wxruby 0.6.0



139
140
141
# File 'lib/weft/wxgui/inspectors.rb', line 139

def associated_subscribers()
  [ @drop_down ]
end

#get_current_categoryObject

the current category active in this window



200
201
202
203
204
205
206
# File 'lib/weft/wxgui/inspectors.rb', line 200

def get_current_category()
  if curr = @drop_down.current_category
    return curr
  else
    return nil
  end
end

#on_activate(e) ⇒ Object

this method should update the code combo box - this is done by the MDI Parent. But - the ActivateEvent class is not currently available in wxruby 0.6.0, so there’s no way to distinguish an activate from a deactivate



147
148
149
150
151
152
# File 'lib/weft/wxgui/inspectors.rb', line 147

def on_activate(e)
  # e.methods.each { | m | p m }
  # if e.get_active
  #		  p "FOO"
  # end
end

#on_code(e) ⇒ Object

code from the main text window



155
156
157
158
159
160
161
162
163
164
165
# File 'lib/weft/wxgui/inspectors.rb', line 155

def on_code(e)
  return unless category = get_current_category() # from drop-down

  Wx::BusyCursor.busy do
    codes = @text_box.selection_to_fragments()
    codes.each { | c | category.code(c.docid, c.offset, c.length) }

    @client.app.save_category( category )
    @drop_down.sticky = true
  end
end

#on_key_down(evt) ⇒ Object

implements keyboard shortcuts for this window - these are activated by interaction with the text-box. currently,

CTRL-m is mapped to "Mark" 
CTRL-, is mapped to "Unmark"
CTRL-f is mapped to "Start find"


185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/weft/wxgui/inspectors.rb', line 185

def on_key_down(evt)
  return evt.skip() unless evt.control_down()
  case evt.key_code()
  when 70 # "f"
    @text_box.start_find(self) if @text_box.respond_to?(:start_find)
  when 77 # "m"
    on_code(evt)
  when 44 # ","
    on_uncode(evt)
  end
  # required so default shortcuts like CTRL-C, CTRL-V work
  evt.skip()
end

#on_uncode(e) ⇒ Object

uncode from the main text window



168
169
170
171
172
173
174
175
176
# File 'lib/weft/wxgui/inspectors.rb', line 168

def on_uncode(e)
  return unless category = get_current_category()
  Wx::BusyCursor.busy do 
    codes = @text_box.selection_to_fragments()
    codes.each { | c | category.uncode(c.docid, c.offset, c.length) }
    @client.app.save_category( category )
    @drop_down.sticky = true
  end
end

#receive_text_font_changed(font) ⇒ Object

set the display font for use in this inspector



209
210
211
# File 'lib/weft/wxgui/inspectors.rb', line 209

def receive_text_font_changed(font)
  @text_box.set_font(font)
end