Class: QDA::GUI::SearchDialog

Inherits:
Wx::Dialog
  • Object
show all
Defined in:
lib/weft/wxgui/dialogs.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ SearchDialog

Returns a new instance of SearchDialog.



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

def initialize(parent)
  super( parent, -1, 'Search', DEF_POS, Wx::Size.new(500,175) )

  sizer = Wx::FlexGridSizer.new(2, 5)

  # search text entry
  sizer.add(Wx::StaticText.new(self, -1, 'Search for'), 
            0, Wx::ALIGN_CENTRE_VERTICAL|Wx::ALIGN_LEFT|Wx::ALL, 4)
  @term  = Wx::TextCtrl.new(self, -1, '', DEF_POS, DEF_SIZE,
                            Wx::TE_PROCESS_ENTER)
  evt_text_enter(@term.get_id) { | e | on_search(e) }
  sizer.add(@term, 2, Wx::GROW|Wx::ALL|Wx::ADJUST_MINSIZE, 4)

  # how much context to return
  sizer.add(Wx::StaticText.new(self, -1, 'Expand results by '), 
            0, Wx::ALIGN_CENTRE_VERTICAL|Wx::ALIGN_LEFT|Wx::ALL, 4)
  mini_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)

  @expand = Wx::SpinCtrl.new( self, -1, "")
  @expand.set_range(0, 1000)
  @expand.set_value(200)
  mini_sizer.add(@expand, 0, Wx::ALL, 4)
  mini_sizer.add(Wx::StaticText.new(self, -1, 'characters'),
                 0, Wx::ALL, 6)
  sizer.add(mini_sizer, 0)

  # options
  sizer.add(Wx::StaticText.new(self, -1, ''), 0, Wx::ALIGN_CENTRE, 4)
  @case_sensi  = Wx::CheckBox.new(self, -1, "Case sensitive?")
  sizer.add(@case_sensi, 0, Wx::ALL, 4)

  sizer.add(Wx::StaticText.new(self, -1, ''), 0, Wx::ALIGN_CENTRE, 4)
  @whole_word  = Wx::CheckBox.new(self, -1, "Whole words only?")
  sizer.add(@whole_word, 0, Wx::ALL, 4)

  # buttons
  button = Wx::Button.new(self, -1, 'Search')
  button.evt_button(button.get_id) { | e | on_search(e) }
  sizer.add(button, 0, Wx::ALL, 4)

  button = Wx::Button.new(self, -1, 'Cancel')
  button.evt_button(button.get_id) { | e | end_modal(Wx::ID_CANCEL) }
  sizer.add(button, 0, Wx::ALL|Wx::ALIGN_RIGHT, 4)

  self.set_sizer(sizer)
  # sizer.set_size_hints(self)
  sizer.fit(self)
end

Instance Method Details

#case_sensitiveObject



153
154
155
# File 'lib/weft/wxgui/dialogs.rb', line 153

def case_sensitive
  @case_sensi.is_checked 
end

#expandObject



161
162
163
# File 'lib/weft/wxgui/dialogs.rb', line 161

def expand
  @expand.get_value().to_i
end

#on_search(e) ⇒ Object



139
140
141
142
143
144
145
146
147
# File 'lib/weft/wxgui/dialogs.rb', line 139

def on_search(e)
  if term =~ /^\s*$/
    Wx::MessageDialog.new(nil, Lang::NO_SEARCH_TERM_SPECIFIED,
                      Lang::NO_SEARCH_TERM_SPECIFIED, 
                      Wx::OK|Wx::ICON_ERROR).show_modal()
    return false
  end
  end_modal(Wx::ID_OK)
end

#termObject



149
150
151
# File 'lib/weft/wxgui/dialogs.rb', line 149

def term
  @term.get_value
end

#whole_wordObject



157
158
159
# File 'lib/weft/wxgui/dialogs.rb', line 157

def whole_word
  @whole_word.is_checked
end