win_gui 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +21 -21
- data/HISTORY +7 -0
- data/LICENSE +20 -20
- data/README.rdoc +77 -114
- data/Rakefile +24 -58
- data/VERSION +1 -1
- data/features/support/env.rb +7 -4
- data/features/win_gui.feature +9 -9
- data/lib/version.rb +8 -0
- data/lib/win_gui/window.rb +78 -69
- data/lib/win_gui.rb +25 -3
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +90 -118
- data/spec/win_gui/window_spec.rb +120 -123
- data/tasks/common.rake +14 -0
- data/tasks/doc.rake +14 -0
- data/tasks/gem.rake +39 -0
- data/tasks/git.rake +34 -0
- data/tasks/spec.rake +19 -0
- data/tasks/version.rake +71 -0
- metadata +68 -188
- data/.document +0 -5
- data/book_code/early_success/bundle.rb +0 -34
- data/book_code/early_success/english.txt +0 -1
- data/book_code/early_success/jruby_basics.rb +0 -47
- data/book_code/early_success/windows_basics.rb +0 -97
- data/book_code/guessing/locknote.rb +0 -379
- data/book_code/guessing/monkeyshines.rb +0 -14
- data/book_code/guessing/note.rb +0 -120
- data/book_code/guessing/note_spec.rb +0 -175
- data/book_code/guessing/replay.rb +0 -21
- data/book_code/guessing/seed.rb +0 -9
- data/book_code/guessing/spec_helper.rb +0 -69
- data/book_code/guessing/windows_gui.rb +0 -247
- data/book_code/home_stretch/junquenote.rb +0 -151
- data/book_code/home_stretch/locknote.rb +0 -180
- data/book_code/home_stretch/note.rb +0 -144
- data/book_code/home_stretch/note_spec.rb +0 -191
- data/book_code/home_stretch/spec_helper.rb +0 -55
- data/book_code/home_stretch/swing_gui.rb +0 -50
- data/book_code/home_stretch/windows_gui.rb +0 -232
- data/book_code/junquenote/exports.sh +0 -10
- data/book_code/junquenote/jruby_mac.sh +0 -10
- data/book_code/junquenote/junquenote_app.rb +0 -262
- data/book_code/novite/Rakefile +0 -10
- data/book_code/novite/app/controllers/application.rb +0 -18
- data/book_code/novite/app/controllers/guests_controller.rb +0 -28
- data/book_code/novite/app/controllers/parties_controller.rb +0 -77
- data/book_code/novite/app/helpers/application_helper.rb +0 -11
- data/book_code/novite/app/helpers/guests_helper.rb +0 -10
- data/book_code/novite/app/helpers/parties_helper.rb +0 -10
- data/book_code/novite/app/models/guest.rb +0 -11
- data/book_code/novite/app/models/party.rb +0 -32
- data/book_code/novite/app/models/party_mailer.rb +0 -19
- data/book_code/novite/app/views/layouts/application.rhtml +0 -44
- data/book_code/novite/app/views/parties/new.html.erb +0 -42
- data/book_code/novite/app/views/parties/show.html.erb +0 -43
- data/book_code/novite/app/views/party_mailer/invite.erb +0 -17
- data/book_code/novite/config/boot.rb +0 -117
- data/book_code/novite/config/database.yml +0 -19
- data/book_code/novite/config/environment.rb +0 -67
- data/book_code/novite/config/environments/development.rb +0 -29
- data/book_code/novite/config/environments/production.rb +0 -27
- data/book_code/novite/config/environments/test.rb +0 -30
- data/book_code/novite/config/initializers/inflections.rb +0 -18
- data/book_code/novite/config/initializers/mime_types.rb +0 -13
- data/book_code/novite/config/routes.rb +0 -47
- data/book_code/novite/db/migrate/001_create_parties.rb +0 -26
- data/book_code/novite/db/migrate/002_create_guests.rb +0 -23
- data/book_code/novite/db/schema.rb +0 -41
- data/book_code/novite/log/empty.txt +0 -0
- data/book_code/novite/public/.htaccess +0 -40
- data/book_code/novite/public/404.html +0 -38
- data/book_code/novite/public/422.html +0 -38
- data/book_code/novite/public/500.html +0 -38
- data/book_code/novite/public/dispatch.cgi +0 -10
- data/book_code/novite/public/dispatch.fcgi +0 -24
- data/book_code/novite/public/dispatch.rb +0 -18
- data/book_code/novite/public/favicon.ico +0 -0
- data/book_code/novite/public/images/rails.png +0 -0
- data/book_code/novite/public/index.html +0 -285
- data/book_code/novite/public/javascripts/application.js +0 -10
- data/book_code/novite/public/javascripts/controls.js +0 -971
- data/book_code/novite/public/javascripts/dragdrop.js +0 -980
- data/book_code/novite/public/javascripts/effects.js +0 -1128
- data/book_code/novite/public/javascripts/prototype.js +0 -4233
- data/book_code/novite/public/robots.txt +0 -5
- data/book_code/novite/script/about +0 -3
- data/book_code/novite/script/console +0 -3
- data/book_code/novite/script/destroy +0 -3
- data/book_code/novite/script/generate +0 -3
- data/book_code/novite/script/performance/benchmarker +0 -3
- data/book_code/novite/script/performance/profiler +0 -3
- data/book_code/novite/script/performance/request +0 -3
- data/book_code/novite/script/plugin +0 -3
- data/book_code/novite/script/process/inspector +0 -3
- data/book_code/novite/script/process/reaper +0 -3
- data/book_code/novite/script/process/spawner +0 -3
- data/book_code/novite/script/runner +0 -3
- data/book_code/novite/script/server +0 -3
- data/book_code/novite/test/test_helper.rb +0 -46
- data/book_code/one_more_thing/applescript.rb +0 -68
- data/book_code/one_more_thing/note_spec.rb +0 -50
- data/book_code/one_more_thing/spec_helper.rb +0 -17
- data/book_code/one_more_thing/textedit-pure.rb +0 -28
- data/book_code/one_more_thing/textedit.applescript +0 -26
- data/book_code/one_more_thing/textedit.rb +0 -32
- data/book_code/one_more_thing/textnote.rb +0 -87
- data/book_code/simplify/junquenote.rb +0 -48
- data/book_code/simplify/locknote.rb +0 -46
- data/book_code/simplify/note.rb +0 -35
- data/book_code/simplify/note_spec.rb +0 -28
- data/book_code/simplify/swing_gui.rb +0 -45
- data/book_code/simplify/windows_gui.rb +0 -232
- data/book_code/simplify/windows_gui_spec.rb +0 -35
- data/book_code/story/invite.story +0 -19
- data/book_code/story/journal.txt +0 -29
- data/book_code/story/novite_stories.rb +0 -156
- data/book_code/story/party.rb +0 -149
- data/book_code/story/password.rb +0 -61
- data/book_code/story/password.story +0 -26
- data/book_code/story/rsvp.story +0 -29
- data/book_code/tables/TestTime.html +0 -93
- data/book_code/tables/TestTimeSample.html +0 -63
- data/book_code/tables/calculate_time.rb +0 -39
- data/book_code/tables/calculator.rb +0 -108
- data/book_code/tables/calculator_actions.rb +0 -27
- data/book_code/tables/calculator_spec.rb +0 -47
- data/book_code/tables/fit.rb +0 -32
- data/book_code/tables/matrix.rb +0 -109
- data/book_code/tables/pseudocode.rb +0 -17
- data/book_code/tubes/book_selenium.rb +0 -67
- data/book_code/tubes/book_watir.rb +0 -60
- data/book_code/tubes/dragdrop.html +0 -81
- data/book_code/tubes/html_capture.rb +0 -33
- data/book_code/tubes/joke_list.rb +0 -67
- data/book_code/tubes/list_spec.rb +0 -41
- data/book_code/tubes/search_spec.rb +0 -32
- data/book_code/tubes/selenium_example.rb +0 -66
- data/book_code/tubes/selenium_link.rb +0 -23
- data/book_code/tubes/web_server.rb +0 -14
- data/book_code/windows/wgui.rb +0 -29
- data/book_code/windows/wobj.rb +0 -25
- data/book_code/windows/wsh.rb +0 -25
- data/book_code/with_rspec/empty_spec.rb +0 -13
- data/book_code/with_rspec/junquenote.rb +0 -60
- data/book_code/with_rspec/locknote.rb +0 -129
- data/book_code/with_rspec/note_spec.rb +0 -32
- data/book_code/with_rspec/should_examples.rb +0 -18
- data/lib/note/java/jemmy.jar +0 -0
- data/lib/note/java/jnote.rb +0 -48
- data/lib/note/java/jruby_basics.rb +0 -37
- data/lib/note/java/junquenote_app.rb +0 -262
- data/lib/note/java/note_spec.rb +0 -20
- data/lib/note/win/locknote.rb +0 -19
- data/lib/note.rb +0 -15
- data/lib/win_gui/constants.rb +0 -82
- data/lib/win_gui/def_api.rb +0 -160
- data/lib/win_gui/string_extensions.rb +0 -36
- data/lib/win_gui/win_gui.rb +0 -437
- data/old/windows_basics.rb +0 -80
- data/old/wnote.rb +0 -80
- data/old/wnote_spec.rb +0 -20
- data/spec/note/win/locknote_spec.rb +0 -7
- data/spec/test_apps/locknote/LockNote.exe +0 -0
- data/spec/win_gui/def_api_spec.rb +0 -339
- data/spec/win_gui/string_extensions_spec.rb +0 -61
- data/spec/win_gui/win_gui_spec.rb +0 -537
- data/win_gui.gemspec +0 -215
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#---
|
|
2
|
-
# Excerpted from "Scripted GUI Testing With Ruby",
|
|
3
|
-
# published by The Pragmatic Bookshelf.
|
|
4
|
-
# Copyrights apply to this code. It may not be used to create training material,
|
|
5
|
-
# courses, books, articles, and the like. Contact us if you are in doubt.
|
|
6
|
-
# We make no guarantees that this code is fit for any purpose.
|
|
7
|
-
# Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
|
|
8
|
-
#---
|
|
9
|
-
describe 'RSpec' do
|
|
10
|
-
it 'supports writing clear tests' do
|
|
11
|
-
|
|
12
|
-
(2 + 2).should == 4
|
|
13
|
-
1.should be < 2
|
|
14
|
-
['this', 'list'].should_not be_empty
|
|
15
|
-
{:color => 'red'}.should have_key(:color)
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
end
|
data/lib/note/java/jemmy.jar
DELETED
|
Binary file
|
data/lib/note/java/jnote.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
require 'java'
|
|
2
|
-
require 'jemmy.jar'
|
|
3
|
-
require 'junquenote_app'
|
|
4
|
-
|
|
5
|
-
include_class 'org.netbeans.jemmy.JemmyProperties'
|
|
6
|
-
include_class 'org.netbeans.jemmy.TestOut'
|
|
7
|
-
|
|
8
|
-
%w(Frame TextArea MenuBar Dialog Button).each do |o| #(1)
|
|
9
|
-
include_class "org.netbeans.jemmy.operators.J#{o}Operator"
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
JemmyProperties.set_current_timeout 'DialogWaiter.WaitDialogTimeout', 3000 #(2)
|
|
13
|
-
JemmyProperties.set_current_output TestOut.get_null_output #(3)
|
|
14
|
-
|
|
15
|
-
class Note
|
|
16
|
-
def initialize
|
|
17
|
-
JunqueNoteApp.new
|
|
18
|
-
@main_window = JFrameOperator.new 'JunqueNote'
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def type_in(text)
|
|
22
|
-
edit = JTextAreaOperator.new @main_window
|
|
23
|
-
edit.type_text text
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def text
|
|
27
|
-
edit = JTextAreaOperator.new @main_window
|
|
28
|
-
edit.text
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def exit!
|
|
32
|
-
begin
|
|
33
|
-
menu = JMenuBarOperator.new @main_window
|
|
34
|
-
menu.push_menu_no_block 'File|Exit', '|'
|
|
35
|
-
|
|
36
|
-
dialog = JDialogOperator.new "Quittin' time"
|
|
37
|
-
button = JButtonOperator.new dialog, "No"
|
|
38
|
-
button.push
|
|
39
|
-
|
|
40
|
-
@prompted = true
|
|
41
|
-
rescue
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def has_prompted?
|
|
46
|
-
@prompted
|
|
47
|
-
end
|
|
48
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
#---
|
|
2
|
-
# Excerpted from "Scripted GUI Testing With Ruby",
|
|
3
|
-
# published by The Pragmatic Bookshelf.
|
|
4
|
-
# Copyrights apply to this code. It may not be used to create training material,
|
|
5
|
-
# courses, books, articles, and the like. Contact us if you are in doubt.
|
|
6
|
-
# We make no guarantees that this code is fit for any purpose.
|
|
7
|
-
# Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
|
|
8
|
-
#---
|
|
9
|
-
|
|
10
|
-
require 'java'
|
|
11
|
-
require 'jemmy.jar'
|
|
12
|
-
require 'junquenote_app'
|
|
13
|
-
|
|
14
|
-
include_class 'org.netbeans.jemmy.JemmyProperties'
|
|
15
|
-
include_class 'org.netbeans.jemmy.TestOut'
|
|
16
|
-
|
|
17
|
-
%w(Frame TextArea MenuBar Dialog Button).each do |o| #(1)
|
|
18
|
-
include_class "org.netbeans.jemmy.operators.J#{o}Operator"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
JemmyProperties.set_current_timeout 'DialogWaiter.WaitDialogTimeout', 3000 #(2)
|
|
22
|
-
JemmyProperties.set_current_output TestOut.get_null_output #(3)
|
|
23
|
-
|
|
24
|
-
JunqueNoteApp.new
|
|
25
|
-
main_window = JFrameOperator.new 'JunqueNote'
|
|
26
|
-
|
|
27
|
-
puts "The main window's object ID is #{main_window.object_id}."
|
|
28
|
-
|
|
29
|
-
edit = JTextAreaOperator.new main_window #(4)
|
|
30
|
-
edit.type_text "this is some text" #(5)
|
|
31
|
-
|
|
32
|
-
menu = JMenuBarOperator.new main_window
|
|
33
|
-
menu.push_menu_no_block 'File|Exit', '|'
|
|
34
|
-
|
|
35
|
-
dialog = JDialogOperator.new "Quittin' time"
|
|
36
|
-
button = JButtonOperator.new dialog, "No"
|
|
37
|
-
button.push
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
#---
|
|
2
|
-
# Excerpted from "Scripted GUI Testing With Ruby",
|
|
3
|
-
# published by The Pragmatic Bookshelf.
|
|
4
|
-
# Copyrights apply to this code. It may not be used to create training material,
|
|
5
|
-
# courses, books, articles, and the like. Contact us if you are in doubt.
|
|
6
|
-
# We make no guarantees that this code is fit for any purpose.
|
|
7
|
-
# Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
|
|
8
|
-
#---
|
|
9
|
-
require 'java'
|
|
10
|
-
require 'rubygems'
|
|
11
|
-
require 'cheri/swing'
|
|
12
|
-
require 'crypt/gost'
|
|
13
|
-
|
|
14
|
-
include_class javax.swing.JOptionPane
|
|
15
|
-
|
|
16
|
-
class String
|
|
17
|
-
def encrypt(pw)
|
|
18
|
-
padded = pw + "\0" * [0, 8 - pw.length].max
|
|
19
|
-
Crypt::Gost.new(padded).encrypt_string(self)
|
|
20
|
-
rescue
|
|
21
|
-
return '(wrong password)'
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def decrypt(pw)
|
|
25
|
-
padded = pw + "\0" * [0, 8 - pw.length].max
|
|
26
|
-
Crypt::Gost.new(padded).decrypt_string(self)
|
|
27
|
-
rescue
|
|
28
|
-
return '(wrong password)'
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
class JunqueNoteApp
|
|
33
|
-
include Cheri::Swing
|
|
34
|
-
|
|
35
|
-
def initialize
|
|
36
|
-
swing[:auto]
|
|
37
|
-
|
|
38
|
-
@frame = swing.frame('JunqueNote') do |f|
|
|
39
|
-
size 400, 300
|
|
40
|
-
box_layout f, :Y_AXIS
|
|
41
|
-
|
|
42
|
-
menu_bar do
|
|
43
|
-
menu('File') do
|
|
44
|
-
menu_item('Open...') {on_click {open} }
|
|
45
|
-
menu_item('Change Password...') {on_click {change_password} }
|
|
46
|
-
menu_item('Save As...') {on_click {save_as} }
|
|
47
|
-
menu_item('Exit') {on_click {exit_app} }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
menu('Edit') do
|
|
51
|
-
menu_item('Undo') {on_click {@text_area.text = @state.pop} }
|
|
52
|
-
menu_item('Cut') {on_click {@state.push(@text_area.text); @text_area.cut} }
|
|
53
|
-
menu_item('Copy') {on_click {@state.push(@text_area.text); @text_area.copy} }
|
|
54
|
-
menu_item('Paste') {on_click {@state.push(@text_area.text); @text_area.paste} }
|
|
55
|
-
|
|
56
|
-
menu_item('Find...') {on_click {find} }
|
|
57
|
-
menu_item('Find Exact Case...') {on_click {find :case} }
|
|
58
|
-
menu_item('Reverse Find...') {on_click {find :reverse} }
|
|
59
|
-
menu_item('Reverse Find Exact Case...') {on_click {find :case_reverse} }
|
|
60
|
-
menu_item('Find Next') {on_click {find @how, @term} }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
menu('Help') do
|
|
64
|
-
menu_item('About JunqueNote...') {on_click {about} }
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
@text_area = text_area('Welcome to JunqueNote!') do
|
|
69
|
-
on_key_pressed {|event| @state.push(@text_area.text); @dirty = true}
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
@state = [@text_area.text]
|
|
74
|
-
@frame.visible = true
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def request_filename(button = 'Save')
|
|
78
|
-
pane = JOptionPane.new \
|
|
79
|
-
'Please enter a filename',
|
|
80
|
-
JOptionPane::PLAIN_MESSAGE,
|
|
81
|
-
JOptionPane::OK_CANCEL_OPTION,
|
|
82
|
-
nil,
|
|
83
|
-
[button,'Cancel'].to_java,
|
|
84
|
-
button
|
|
85
|
-
pane.wants_input = true
|
|
86
|
-
pane.create_dialog(@frame, 'Input').show
|
|
87
|
-
|
|
88
|
-
button == pane.value ? pane.input_value : nil
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def save_as(filename = nil)
|
|
92
|
-
save_name = filename || request_filename
|
|
93
|
-
return if save_name.nil?
|
|
94
|
-
|
|
95
|
-
@filename = save_name
|
|
96
|
-
|
|
97
|
-
if @password.nil?
|
|
98
|
-
@password = JOptionPane.show_input_dialog "Please assign a password"
|
|
99
|
-
return if @password.nil?
|
|
100
|
-
confirmation = JOptionPane.show_input_dialog "Please confirm the password"
|
|
101
|
-
return if confirmation.nil?
|
|
102
|
-
|
|
103
|
-
if @password != confirmation
|
|
104
|
-
JOptionPane.show_message_dialog(
|
|
105
|
-
@frame,
|
|
106
|
-
"The password and confirmation don't match",
|
|
107
|
-
"Oops",
|
|
108
|
-
JOptionPane::YES_NO_OPTION)
|
|
109
|
-
|
|
110
|
-
return
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
File.delete @filename if File.exists? @filename
|
|
115
|
-
File.open @filename, 'wb' do |f|
|
|
116
|
-
plaintext = "JunqueNote\n#{@text_area.text.length}\n#{@text_area.text}"
|
|
117
|
-
encrypted = plaintext.encrypt(@password)
|
|
118
|
-
f.write encrypted
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
@dirty = false
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def open
|
|
125
|
-
@filename = request_filename 'Open'
|
|
126
|
-
if @filename.nil?
|
|
127
|
-
@frame.dispose
|
|
128
|
-
return
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
@password = JOptionPane.show_input_dialog "Please enter the password"
|
|
132
|
-
if @password.nil?
|
|
133
|
-
@frame.dispose
|
|
134
|
-
return
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
encrypted = File.open(@filename, 'rb') {|f| f.read}
|
|
138
|
-
init, length, contents = encrypted.decrypt(@password).split($;, 3)
|
|
139
|
-
|
|
140
|
-
if init == 'JunqueNote'
|
|
141
|
-
contents = contents[0, length.to_i]
|
|
142
|
-
@text_area.text = contents
|
|
143
|
-
@state = [contents]
|
|
144
|
-
@dirty = false
|
|
145
|
-
else
|
|
146
|
-
JOptionPane.show_message_dialog(
|
|
147
|
-
@frame,
|
|
148
|
-
"The password doesn't match",
|
|
149
|
-
"Oops",
|
|
150
|
-
JOptionPane::YES_NO_OPTION)
|
|
151
|
-
|
|
152
|
-
@frame.dispose
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def change_password
|
|
157
|
-
old_password = JOptionPane.show_input_dialog "Please enter the password"
|
|
158
|
-
return if old_password.nil?
|
|
159
|
-
|
|
160
|
-
if old_password != @password
|
|
161
|
-
JOptionPane.show_message_dialog(
|
|
162
|
-
@frame,
|
|
163
|
-
"The password doesn't match",
|
|
164
|
-
"Oops",
|
|
165
|
-
JOptionPane::YES_NO_OPTION)
|
|
166
|
-
|
|
167
|
-
return
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
new_password = JOptionPane.show_input_dialog "Please enter a password"
|
|
171
|
-
return if new_password.nil?
|
|
172
|
-
confirmation = JOptionPane.show_input_dialog "Please confirm the password"
|
|
173
|
-
return if confirmation.nil?
|
|
174
|
-
|
|
175
|
-
if new_password != confirmation
|
|
176
|
-
JOptionPane.show_message_dialog(
|
|
177
|
-
@frame,
|
|
178
|
-
"The password and confirmation don't match",
|
|
179
|
-
"Oops",
|
|
180
|
-
JOptionPane::YES_NO_OPTION)
|
|
181
|
-
|
|
182
|
-
return
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
@password = new_password
|
|
186
|
-
|
|
187
|
-
File.delete @filename if File.exists? @filename
|
|
188
|
-
File.open @filename, 'wb' do |f|
|
|
189
|
-
plaintext = "JunqueNote\n#{@text_area.text.length}\n#{@text_area.text}"
|
|
190
|
-
encrypted = plaintext.encrypt(@password)
|
|
191
|
-
f.write encrypted
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
@dirty = false
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def exit_app
|
|
198
|
-
should_save = if @dirty
|
|
199
|
-
0 == JOptionPane.show_confirm_dialog(
|
|
200
|
-
nil,
|
|
201
|
-
"Wanna save first?",
|
|
202
|
-
"Quittin' time",
|
|
203
|
-
JOptionPane::YES_NO_OPTION)
|
|
204
|
-
else
|
|
205
|
-
false
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
save_as(@filename) if should_save
|
|
209
|
-
@frame.dispose
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
def about
|
|
213
|
-
JOptionPane.show_message_dialog(
|
|
214
|
-
@frame,
|
|
215
|
-
"A hypothetical JRuby port of LockNote",
|
|
216
|
-
"About JunqueNote",
|
|
217
|
-
JOptionPane::INFORMATION_MESSAGE)
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def find(how = nil, term = nil)
|
|
221
|
-
term ||= JOptionPane.show_input_dialog "Please enter the search term"
|
|
222
|
-
return unless term
|
|
223
|
-
|
|
224
|
-
@how = how
|
|
225
|
-
@term = term
|
|
226
|
-
|
|
227
|
-
pattern, backwards = case how
|
|
228
|
-
when :case
|
|
229
|
-
[/#{term}/, false]
|
|
230
|
-
when :reverse
|
|
231
|
-
[/#{term.reverse}/i, true]
|
|
232
|
-
when :case_reverse
|
|
233
|
-
[/#{term.reverse}/, true]
|
|
234
|
-
else
|
|
235
|
-
[/#{term}/i, false]
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
position = @text_area.get_selection_start || 0
|
|
239
|
-
contents = @text_area.text
|
|
240
|
-
|
|
241
|
-
if backwards
|
|
242
|
-
contents.reverse!
|
|
243
|
-
position = contents.length - position
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
next_position = contents.index pattern, position + 1
|
|
247
|
-
|
|
248
|
-
if next_position
|
|
249
|
-
next_position =
|
|
250
|
-
contents.length -
|
|
251
|
-
next_position -
|
|
252
|
-
term.length if backwards
|
|
253
|
-
|
|
254
|
-
@text_area.set_selection_start next_position
|
|
255
|
-
@text_area.set_selection_end next_position + term.length
|
|
256
|
-
end
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
if __FILE__ == $0
|
|
261
|
-
JunqueNoteApp.new
|
|
262
|
-
end
|
data/lib/note/java/note_spec.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
describe 'The main window' do
|
|
2
|
-
it 'launches with a welcome message' do
|
|
3
|
-
note = Note.new
|
|
4
|
-
note.text.should include('Welcome' )
|
|
5
|
-
note.exit!
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it 'exits without a prompt if nothing has changed' do
|
|
9
|
-
note = Note.new
|
|
10
|
-
note.exit!
|
|
11
|
-
note.should_not have_prompted
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'prompts before exiting if the document has changed' do
|
|
15
|
-
note = Note.new
|
|
16
|
-
note.type_in "changed"
|
|
17
|
-
note.exit!
|
|
18
|
-
note.should have_prompted
|
|
19
|
-
end
|
|
20
|
-
end
|
data/lib/note/win/locknote.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#require File.join(File.dirname(__FILE__), ".." , "..", "note" )
|
|
2
|
-
require 'win_gui/win_gui'
|
|
3
|
-
|
|
4
|
-
class LockNote < Note
|
|
5
|
-
include WinGui
|
|
6
|
-
|
|
7
|
-
APP_PATH = File.join(File.dirname(__FILE__),".." ,"test_apps/locknote/LockNote.exe" )
|
|
8
|
-
APP_START = 'start "" "' + APP_PATH + '"'
|
|
9
|
-
|
|
10
|
-
@@app = LockNote
|
|
11
|
-
@@titles[:save] = 'Steganos LockNote'
|
|
12
|
-
|
|
13
|
-
def initialize
|
|
14
|
-
system APP_START
|
|
15
|
-
@main_window = Window.top_level 'LockNote - Steganos LockNote'
|
|
16
|
-
@edit_window = @main_window.child 'ATL:00434310'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
data/lib/note.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
libdir = File.dirname(__FILE__)
|
|
2
|
-
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
|
|
3
|
-
|
|
4
|
-
# Abstract Note class (to be subclassed)
|
|
5
|
-
class Note
|
|
6
|
-
@@app = nil
|
|
7
|
-
@@titles = {}
|
|
8
|
-
|
|
9
|
-
def self.open
|
|
10
|
-
@@app.new
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
require 'note/win/locknote'
|
|
15
|
-
#require 'note/java/junquenote'
|
data/lib/win_gui/constants.rb
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
module WinGui
|
|
2
|
-
|
|
3
|
-
# Delay between key commands (events)
|
|
4
|
-
WG_KEY_DELAY = 0.00001
|
|
5
|
-
# Wait delay quant
|
|
6
|
-
WG_SLEEP_DELAY = 0.001
|
|
7
|
-
# Timeout waiting for Window to be closed
|
|
8
|
-
WG_CLOSE_TIMEOUT = 1
|
|
9
|
-
|
|
10
|
-
# Windows keyboard-related Constants:
|
|
11
|
-
# Virtual key codes:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# Control-break processing
|
|
15
|
-
VK_CANCEL = 0x03
|
|
16
|
-
# Backspace? key
|
|
17
|
-
VK_BACK = 0x08
|
|
18
|
-
# Tab key
|
|
19
|
-
VK_TAB = 0x09
|
|
20
|
-
# Shift key
|
|
21
|
-
VK_SHIFT = 0x10
|
|
22
|
-
# Ctrl key
|
|
23
|
-
VK_CONTROL = 0x11
|
|
24
|
-
# ENTER key
|
|
25
|
-
VK_RETURN = 0x0D
|
|
26
|
-
# ALT key
|
|
27
|
-
VK_ALT = 0x12
|
|
28
|
-
# ALT key alias
|
|
29
|
-
VK_MENU = 0x12
|
|
30
|
-
# PAUSE key
|
|
31
|
-
VK_PAUSE = 0x13
|
|
32
|
-
# CAPS LOCK key
|
|
33
|
-
VK_CAPITAL = 0x14
|
|
34
|
-
# ESC key
|
|
35
|
-
VK_ESCAPE = 0x1B
|
|
36
|
-
# SPACEBAR
|
|
37
|
-
VK_SPACE = 0x20
|
|
38
|
-
# PAGE UP key
|
|
39
|
-
VK_PRIOR = 0x21
|
|
40
|
-
# PAGE DOWN key
|
|
41
|
-
VK_NEXT = 0x22
|
|
42
|
-
# END key
|
|
43
|
-
VK_END = 0x23
|
|
44
|
-
# HOME key
|
|
45
|
-
VK_HOME = 0x24
|
|
46
|
-
# LEFT ARROW key
|
|
47
|
-
VK_LEFT = 0x25
|
|
48
|
-
# UP ARROW key
|
|
49
|
-
VK_UP = 0x26
|
|
50
|
-
# RIGHT ARROW key
|
|
51
|
-
VK_RIGHT = 0x27
|
|
52
|
-
# DOWN ARROW key
|
|
53
|
-
VK_DOWN = 0x28
|
|
54
|
-
# SELECT key
|
|
55
|
-
VK_SELECT = 0x29
|
|
56
|
-
# PRINT key
|
|
57
|
-
VK_PRINT = 0x2A
|
|
58
|
-
# EXECUTE key
|
|
59
|
-
VK_EXECUTE = 0x2B
|
|
60
|
-
# PRINT SCREEN key
|
|
61
|
-
VK_SNAPSHOT = 0x2C
|
|
62
|
-
# INS key
|
|
63
|
-
VK_INSERT = 0x2D
|
|
64
|
-
# DEL key
|
|
65
|
-
VK_DELETE = 0x2E
|
|
66
|
-
# HELP key
|
|
67
|
-
VK_HELP = 0x2F
|
|
68
|
-
|
|
69
|
-
# Key down keyboard event
|
|
70
|
-
KEYEVENTF_KEYDOWN = 0
|
|
71
|
-
# Key up keyboard event
|
|
72
|
-
KEYEVENTF_KEYUP = 2
|
|
73
|
-
|
|
74
|
-
# Windows Message Get Text
|
|
75
|
-
WM_GETTEXT = 0x000D
|
|
76
|
-
# Windows Message Sys Command
|
|
77
|
-
WM_SYSCOMMAND = 0x0112
|
|
78
|
-
# Sys Command Close
|
|
79
|
-
SC_CLOSE = 0xF060
|
|
80
|
-
|
|
81
|
-
end
|
|
82
|
-
|
data/lib/win_gui/def_api.rb
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
require 'Win32/api'
|
|
2
|
-
|
|
3
|
-
module WinGui
|
|
4
|
-
module DefApi
|
|
5
|
-
# DLL to use with API decarations by default ('user32')
|
|
6
|
-
DEFAULT_DLL = 'user32'
|
|
7
|
-
|
|
8
|
-
##
|
|
9
|
-
# Defines new method wrappers for Windows API function call:
|
|
10
|
-
# - Defines method with original (CamelCase) API function name and original signature (matches MSDN description)
|
|
11
|
-
# - Defines method with snake_case name (converted from CamelCase function name) with enhanced API signature
|
|
12
|
-
# When the defined wrapper method is called, it checks the argument count, executes underlying API
|
|
13
|
-
# function call and (optionally) transforms the result before returning it. If block is attached to
|
|
14
|
-
# method invocation, raw result is yielded to this block before final transformations
|
|
15
|
-
# - Defines aliases for enhanced method with more Rubyesque names for getters, setters and tests:
|
|
16
|
-
# GetWindowText -> window_test, SetWindowText -> window_text=, IsZoomed -> zoomed?
|
|
17
|
-
#
|
|
18
|
-
# You may modify default behavior of defined method by providing optional &define_block to def_api.
|
|
19
|
-
# If you do so, instead of directly calling API function, defined method just yields callable api
|
|
20
|
-
# object, arguments and (optional) runtime block to your &define_block and returns result coming out of it.
|
|
21
|
-
# So, &define_block should define all the behavior of defined method. You can use define_block to:
|
|
22
|
-
# - Change original signature of API function, provide argument defaults, check argument types
|
|
23
|
-
# - Pack arguments into strings for [in] or [in/out] parameters that expect a pointer
|
|
24
|
-
# - Allocate string buffers for pointers required by API functions [out] parameters
|
|
25
|
-
# - Unpack [out] and [in/out] parameters returned as pointers
|
|
26
|
-
# - Explicitly return results of API call that are returned in [out] and [in/out] parameters
|
|
27
|
-
# - Convert attached runtime blocks into callback functions and stuff them into [in] callback parameters
|
|
28
|
-
#
|
|
29
|
-
# Accepts following options:
|
|
30
|
-
# :dll:: Use this dll instead of default 'user32'
|
|
31
|
-
# :rename:: Use this name instead of standard (conventional) function name
|
|
32
|
-
# :alias(es):: Provides additional alias(es) for defined method
|
|
33
|
-
# :boolean:: Forces method to return true/false instead of nonzero/zero
|
|
34
|
-
# :zeronil:: Forces method to return nil if function result is zero
|
|
35
|
-
#
|
|
36
|
-
def def_api(function, params, returns, options={}, &define_block)
|
|
37
|
-
name, aliases = generate_names(function, options)
|
|
38
|
-
boolean = options[:boolean]
|
|
39
|
-
zeronil = options[:zeronil]
|
|
40
|
-
proto = params.respond_to?(:join) ? params.join : params # Convert params into prototype string
|
|
41
|
-
api = Win32::API.new(function, proto.upcase, returns.upcase, options[:dll] || DEFAULT_DLL)
|
|
42
|
-
|
|
43
|
-
define_method(function) {|*args| api.call(*args)} # define CamelCase method wrapper for api call
|
|
44
|
-
|
|
45
|
-
define_method(name) do |*args, &runtime_block| # define snake_case method with enhanced api
|
|
46
|
-
return api if args == [:api]
|
|
47
|
-
return define_block[api, *args, &runtime_block] if define_block
|
|
48
|
-
WinGui.enforce_count(args, proto)
|
|
49
|
-
result = api.call(*args)
|
|
50
|
-
result = runtime_block[result] if runtime_block
|
|
51
|
-
return result != 0 if boolean # Boolean function returns true/false instead of nonzero/zero
|
|
52
|
-
return nil if zeronil && result == 0 # Zeronil function returns nil instead of zero
|
|
53
|
-
result
|
|
54
|
-
end
|
|
55
|
-
aliases.each {|ali| alias_method ali, name } # define aliases
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Generates name and aliases for defined method based on function name,
|
|
59
|
-
# sets boolean flag for test functions (Is...)
|
|
60
|
-
#
|
|
61
|
-
def generate_names(function, options)
|
|
62
|
-
aliases = ([options[:alias]] + [options[:aliases]]).flatten.compact
|
|
63
|
-
name = options[:rename] || function.snake_case
|
|
64
|
-
case name
|
|
65
|
-
when /^is_/
|
|
66
|
-
aliases << name.sub(/^is_/, '') + '?'
|
|
67
|
-
options[:boolean] = true
|
|
68
|
-
when /^set_/
|
|
69
|
-
aliases << name.sub(/^set_/, '')+ '='
|
|
70
|
-
when /^get_/
|
|
71
|
-
aliases << name.sub(/^get_/, '')
|
|
72
|
-
end
|
|
73
|
-
[name, aliases]
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# Ensures that args count is equal to params count plus diff
|
|
77
|
-
#
|
|
78
|
-
def enforce_count(args, params, diff = 0)
|
|
79
|
-
num_args = args.size
|
|
80
|
-
num_params = params == 'V' ? 0 : params.size + diff
|
|
81
|
-
if num_args != num_params
|
|
82
|
-
raise ArgumentError, "wrong number of parameters: expected #{num_params}, got #{num_args}"
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# Converts block into API::Callback object that can be used as API callback argument
|
|
87
|
-
#
|
|
88
|
-
def callback(params, returns, &block)
|
|
89
|
-
Win32::API::Callback.new(params, returns, &block)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
private # Helper methods:
|
|
93
|
-
|
|
94
|
-
# Returns string buffer - used to supply string pointer reference to API functions
|
|
95
|
-
#
|
|
96
|
-
def buffer(size = 1024, code = "\x00")
|
|
97
|
-
code * size
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# Returns array of given args if none of them is zero,
|
|
101
|
-
# if any arg is zero, returns array of nils
|
|
102
|
-
#
|
|
103
|
-
def nonzero_array(*args)
|
|
104
|
-
args.any?{|arg| arg == 0 } ? args.map{||nil} : args
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# Procedure that returns (possibly encoded) string as a result of api function call
|
|
108
|
-
# or nil if zero characters was returned by api call
|
|
109
|
-
#
|
|
110
|
-
def return_string( encode = nil )
|
|
111
|
-
lambda do |api, *args|
|
|
112
|
-
WinGui.enforce_count( args, api.prototype, -2)
|
|
113
|
-
args += [string = buffer, string.length]
|
|
114
|
-
num_chars = api.call(*args)
|
|
115
|
-
return nil if num_chars == 0
|
|
116
|
-
string = string.force_encoding('utf-16LE').encode(encode) if encode
|
|
117
|
-
string.rstrip
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# Procedure that calls api function expecting a callback. If runtime block is given
|
|
122
|
-
# it is converted into callback, otherwise procedure returns an array of all handles
|
|
123
|
-
# pushed into callback by api enumeration
|
|
124
|
-
#
|
|
125
|
-
def return_enum
|
|
126
|
-
lambda do |api, *args, &block|
|
|
127
|
-
WinGui.enforce_count( args, api.prototype, -1)
|
|
128
|
-
handles = []
|
|
129
|
-
cb = if block
|
|
130
|
-
callback('LP', 'I', &block)
|
|
131
|
-
else
|
|
132
|
-
callback('LP', 'I') do |handle, message|
|
|
133
|
-
handles << handle
|
|
134
|
-
true
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
args[api.prototype.find_index('K'), 0] = cb # Insert callback into appropriate place of args Array
|
|
138
|
-
api.call *args
|
|
139
|
-
handles
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# Procedure that calls (DdeInitialize) function expecting a DdeCallback. Runtime block is converted
|
|
144
|
-
# into Dde callback and registered with DdeInitialize. Returns DDE init status and DDE instance id.
|
|
145
|
-
#
|
|
146
|
-
# TODO: Pushed into this module since RubyMine (wrongly) reports error on lambda args
|
|
147
|
-
#
|
|
148
|
-
def return_id_status
|
|
149
|
-
lambda do |api, id=0, cmd, &block|
|
|
150
|
-
raise ArgumentError, 'No callback block' unless block
|
|
151
|
-
callback = callback 'IIPPPPPP', 'L', &block
|
|
152
|
-
|
|
153
|
-
status = api.call(id = [id].pack('L'), callback, cmd, 0)
|
|
154
|
-
id = status == 0 ? id.unpack('L').first : nil
|
|
155
|
-
[id, status]
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
end
|
|
160
|
-
end
|