Class: Cosmos::FindReplaceDialog

Inherits:
Qt::Dialog show all
Defined in:
lib/cosmos/gui/dialogs/find_replace_dialog.rb

Constant Summary collapse

@@find_text =
""
@@replace_text =
""
@@match_whole_word =
false
@@match_case =
false
@@wrap_around =
true
@@find_up =
false
@@find_down =
true
@@find_flags =
0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, replace_dialog = false) ⇒ FindReplaceDialog

Returns a new instance of FindReplaceDialog.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 33

def initialize(parent, replace_dialog = false)
  # Call base class constructor
  super(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
  @replace_dialog = replace_dialog
  setWindowTitle('Find') unless @replace_dialog
  setWindowTitle('Replace') if @replace_dialog

  @layout = Qt::HBoxLayout.new

  @find_layout = Qt::FormLayout.new
  @find_box = Qt::LineEdit.new(@@find_text)
  @find_layout.addRow(tr("Fi&nd what:"), @find_box)
  if @replace_dialog
    @replace_box = Qt::LineEdit.new(@@replace_text)
    @find_layout.addRow(tr("Re&place with:"), @replace_box)
  end

  @match_whole_word = Qt::CheckBox.new("Match &whole word only")
  @match_whole_word.setChecked(@@match_whole_word)
  @match_case = Qt::CheckBox.new("Match &case")
  @match_case.setChecked(@@match_case)
  @wrap_around = Qt::CheckBox.new("Wrap ar&ound")
  @wrap_around.setChecked(@@wrap_around)
  @checkbox_layout = Qt::VBoxLayout.new
  @checkbox_layout.addWidget(@match_whole_word)
  @checkbox_layout.addWidget(@match_case)
  @checkbox_layout.addWidget(@wrap_around)
  @checkbox_layout.addStretch

  @up = Qt::RadioButton.new("&Up")
  @up.setChecked(@@find_up)
  @down = Qt::RadioButton.new("&Down")
  @down.setChecked(@@find_down)
  @direction_layout = Qt::VBoxLayout.new
  @direction_layout.addWidget(@up)
  @direction_layout.addWidget(@down)
  @direction_layout.addStretch
  @direction = Qt::GroupBox.new(tr("Direction"))
  @direction.setLayout(@direction_layout)

  @options_layout = Qt::HBoxLayout.new
  @options_layout.addLayout(@checkbox_layout)
  @options_layout.addWidget(@direction)

  @left_side = Qt::VBoxLayout.new
  @left_side.addLayout(@find_layout)
  @left_side.addLayout(@options_layout)

  @find_next = Qt::PushButton.new("&Find Next")
  @find_next.setDefault(true)
  @find_next.connect(SIGNAL('clicked()')) { emit find_next() }
  @cancel = Qt::PushButton.new("Cancel")
  @cancel.connect(SIGNAL('clicked()')) { self.reject }
  if @replace_dialog
    @replace = Qt::PushButton.new("&Replace")
    @replace.connect(SIGNAL('clicked()')) { emit replace() }
    @replace_all = Qt::PushButton.new("Replace &All")
    @replace_all.connect(SIGNAL('clicked()')) { emit replace_all() }
  end

  @button_layout = Qt::VBoxLayout.new
  @button_layout.addWidget(@find_next)
  if @replace_dialog
    @button_layout.addWidget(@replace)
    @button_layout.addWidget(@replace_all)
  end
  @button_layout.addWidget(@cancel)
  @button_layout.addStretch

  @layout.addLayout(@left_side)
  @layout.addLayout(@button_layout)

  setLayout(@layout)

  self.connect(SIGNAL('finished(int)')) { dialog_closing }
end

Class Method Details

.find_down?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 187

def self.find_down?
  @@find_down
end

.find_flagsObject



191
192
193
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 191

def self.find_flags
  @@find_flags
end

.find_textObject



163
164
165
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 163

def self.find_text
  @@find_text
end

.find_up?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 183

def self.find_up?
  @@find_up
end

.match_case?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 175

def self.match_case?
  @@match_case
end

.match_whole_word?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 171

def self.match_whole_word?
  @@match_whole_word
end

.replace_textObject



167
168
169
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 167

def self.replace_text
  @@replace_text
end

.wrap_around?Boolean

Returns:

  • (Boolean)


179
180
181
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 179

def self.wrap_around?
  @@wrap_around
end

Instance Method Details

#dialog_closingObject



152
153
154
155
156
157
158
159
160
161
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 152

def dialog_closing
  @@find_text = @find_box.text
  @@replace_text = @replace_box.text if @replace_dialog
  @@match_whole_word = @match_whole_word.isChecked
  @@match_case = @match_case.isChecked
  @@wrap_around = @wrap_around.isChecked
  @@find_up = @up.isChecked
  @@find_down = @down.isChecked
  @@find_flags = find_flags
end

#find_down?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 148

def find_down?
  @down.isChecked
end

#find_flagsObject



116
117
118
119
120
121
122
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 116

def find_flags
  flags = 0
  flags |= Qt::TextDocument::FindBackward.to_i if @up.isChecked
  flags |= Qt::TextDocument::FindCaseSensitively.to_i if @match_case.isChecked
  flags |= Qt::TextDocument::FindWholeWords.to_i if @match_whole_word.isChecked
  flags
end

#find_textObject



124
125
126
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 124

def find_text
  @find_box.text
end

#find_up?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 144

def find_up?
  @up.isChecked
end

#match_case?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 136

def match_case?
  @match_case.isChecked
end

#match_whole_word?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 132

def match_whole_word?
  @match_whole_word.isChecked
end

#replace_textObject



128
129
130
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 128

def replace_text
  @replace_box.text if @replace_dialog
end

#showObject

def initialize



110
111
112
113
114
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 110

def show
  super
  @find_box.selectAll
  @find_box.setFocus(Qt::PopupFocusReason)
end

#wrap_around?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/cosmos/gui/dialogs/find_replace_dialog.rb', line 140

def wrap_around?
  @wrap_around.isChecked
end