win32-shortcut 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,44 +1,49 @@
1
- == 0.2.0 - 30-Oct-2006
2
- * Replaced the C extension code with a pure Ruby version that uses win32ole
3
- and Wscript.Shell behind the scenes.
4
- * The Shortcut#icon_number method was dropped since that property isn't
5
- supported by Wscript.Shell. It was a useless method anyway.
6
- * The Shortcut#relative_path method was dropped since that property isn't
7
- actually supported by a Wsh.Shortcut object, contrary to what the MSDN
8
- documentation says.
9
- * The Shortcut.new method now takes a block, yields self, and automatically
10
- ensures that Shortcut#save is called at the end of the block.
11
- * The Shortcut#hotkey method now takes a human readable string instead of a
12
- hex value.
13
- * The Shortcut#show_cmd method was renamed Shortcut#window_style (though
14
- there's an alias for backwards compatability.
15
- * The Shortcut#window_style accessor now accepts/emits human readable
16
- strings as well as constants.
17
- * Removed the 'doc' directory. The documentation is now inlined as rdoc
18
- and/or in the README file.
19
-
20
- == 0.1.4 - 17-Jul-2005
21
- * Fixed a bug in the Shortcut.open method. Thanks go to an anonymous user
22
- for the spot.
23
- * Added a test for the Shortcut.open method.
24
- * Added a Shortcut.open example in the test script.
25
- * Modified the extconf.rb script to set _WIN32_WINNT macro as needed.
26
-
27
- == 0.1.3 - 9-Jun-2005
28
- * Removed shortcut.rd file.
29
- * The shortcut.txt file is now rdoc friendly.
30
- * Now Unicode friendly.
31
- * Minor test suite tweaks and additions.
32
- * Minor changes to the example program.
33
- * Code cleanup.
34
-
35
- == 0.1.2 - 1-Mar-2005
36
- * Moved the 'examples' directory to the toplevel directory.
37
- * Renamed the sample script to 'shortcut_test.rb'.
38
-
39
- == 0.1.1 - 12-Feb-2005
40
- * Modified the extconf.rb file to be more cygwin/mingw friendly.
41
- * Modified some documentation to be more rdoc friendly.
42
-
43
- == 0.1.0 - 28-Sep-2004
1
+ == 0.2.1 - 29-Jul-2007
2
+ * Added a Rakefile with tasks for installation and testing.
3
+ * Removed the install.rb file, since the Rakefile now handles installation.
4
+ * Doc updates.
5
+
6
+ == 0.2.0 - 30-Oct-2006
7
+ * Replaced the C extension code with a pure Ruby version that uses win32ole
8
+ and Wscript.Shell behind the scenes.
9
+ * The Shortcut#icon_number method was dropped since that property isn't
10
+ supported by Wscript.Shell. It was a useless method anyway.
11
+ * The Shortcut#relative_path method was dropped since that property isn't
12
+ actually supported by a Wsh.Shortcut object, contrary to what the MSDN
13
+ documentation says.
14
+ * The Shortcut.new method now takes a block, yields self, and automatically
15
+ ensures that Shortcut#save is called at the end of the block.
16
+ * The Shortcut#hotkey method now takes a human readable string instead of a
17
+ hex value.
18
+ * The Shortcut#show_cmd method was renamed Shortcut#window_style (though
19
+ there's an alias for backwards compatability.
20
+ * The Shortcut#window_style accessor now accepts/emits human readable
21
+ strings as well as constants.
22
+ * Removed the 'doc' directory. The documentation is now inlined as rdoc
23
+ and/or in the README file.
24
+
25
+ == 0.1.4 - 17-Jul-2005
26
+ * Fixed a bug in the Shortcut.open method. Thanks go to an anonymous user
27
+ for the spot.
28
+ * Added a test for the Shortcut.open method.
29
+ * Added a Shortcut.open example in the test script.
30
+ * Modified the extconf.rb script to set _WIN32_WINNT macro as needed.
31
+
32
+ == 0.1.3 - 9-Jun-2005
33
+ * Removed shortcut.rd file.
34
+ * The shortcut.txt file is now rdoc friendly.
35
+ * Now Unicode friendly.
36
+ * Minor test suite tweaks and additions.
37
+ * Minor changes to the example program.
38
+ * Code cleanup.
39
+
40
+ == 0.1.2 - 1-Mar-2005
41
+ * Moved the 'examples' directory to the toplevel directory.
42
+ * Renamed the sample script to 'shortcut_test.rb'.
43
+
44
+ == 0.1.1 - 12-Feb-2005
45
+ * Modified the extconf.rb file to be more cygwin/mingw friendly.
46
+ * Modified some documentation to be more rdoc friendly.
47
+
48
+ == 0.1.0 - 28-Sep-2004
44
49
  * Initial release
data/MANIFEST CHANGED
@@ -1,11 +1,8 @@
1
- CHANGES
2
- MANIFEST
3
- README
4
- install.rb
5
- win32-shortcut.gemspec
6
-
7
- examples/example_shortcut.rb
8
-
9
- lib/win32/shortcut.rb
10
-
11
- test/tc_shortcut.rb
1
+ * CHANGES
2
+ * MANIFEST
3
+ * README
4
+ * Rakefile
5
+ * win32-shortcut.gemspec
6
+ * examples/example_shortcut.rb
7
+ * lib/win32/shortcut.rb
8
+ * test/tc_shortcut.rb
data/README CHANGED
@@ -3,14 +3,11 @@
3
3
 
4
4
  == Requirements
5
5
  Ruby 1.8.2 or later.
6
- The win32ole package (part of the stdlib).
6
+ The win32ole package (part of the Ruby stdlib).
7
7
 
8
8
  == Installation
9
- === Gem Installation
10
- * ruby win32-shortcut.gemspec
11
- * gem install win32-shortcut-x.y.z.gem
12
- === Standard Installation
13
- * ruby install.rb
9
+ rake test (optional)
10
+ rake install (non-gem) or rake install_gem (gem)
14
11
 
15
12
  == Synopsis
16
13
  require 'win32/shortcut'
@@ -39,7 +36,7 @@
39
36
  "Feature Request".
40
37
 
41
38
  == Copyright
42
- (C) 2003-2006, Daniel J. Berger, All Rights Reserved
39
+ (C) 2003-2007, Daniel J. Berger, All Rights Reserved
43
40
 
44
41
  == License
45
42
  Ruby's
@@ -54,7 +51,7 @@
54
51
  Win32::Shortcut Perl module, and I copied some of the documentation as
55
52
  well.
56
53
 
57
- The current version is based on a patch by Jano Svitok.
54
+ The current version (0.2.0 and later) is based on a patch by Jano Svitok.
58
55
 
59
56
  == Author(s)
60
57
  Daniel J. Berger
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ desc "Install the win32-shortcut package (non-gem)"
5
+ task :install do
6
+ dest = File.join(Config::CONFIG['sitelibdir'], 'win32')
7
+ Dir.mkdir(dest) unless File.exists? dest
8
+ cp 'lib/win32/shortcut.rb', dest, :verbose => true
9
+ end
10
+
11
+ desc "Install the win32-shortcut package as a gem"
12
+ task :install_gem do
13
+ ruby 'win32-shortcut.gemspec'
14
+ file = Dir["*.gem"].first
15
+ sh "gem install #{file}"
16
+ end
17
+
18
+ Rake::TestTask.new do |t|
19
+ t.libs << 'lib'
20
+ t.warning = true
21
+ t.test_files = FileList['test/tc*']
22
+ end
@@ -1,206 +1,206 @@
1
- require 'win32ole'
2
-
3
- module Win32
4
- class Shortcut
5
- VERSION = '0.2.0'
6
-
7
- # Activates and displays a window. If the window is minimized or maximized,
8
- # the system restores it to its original size and position. An application
9
- # should specify this flag when displaying the window for the first time.
10
- #
11
- SHOWNORMAL = 1
12
-
13
- # Activates the window and displays it as a maximized window.
14
- #
15
- SHOWMAXIMIZED = 3
16
-
17
- # Displays the window in its minimized state, leaving the currently active
18
- # window as active.
19
- #
20
- SHOWMINNOACTIVE = 7
21
-
22
- # Creates and returns a Shortcut object. In block form it yields +self+
23
- # and automatically ensures that Shortcut#save is called at the end of
24
- # the block. In non-block form it does not actually create the shortcut
25
- # until the Shorcut#save method is called.
26
- #
27
- def initialize(file)
28
- @file = file
29
- @shell = WIN32OLE.new('WScript.Shell')
30
- @link = @shell.CreateShortcut(file)
31
-
32
- if block_given?
33
- begin
34
- yield self
35
- ensure
36
- save
37
- end
38
- end
39
- end
40
-
41
- # Identical to Shortcut#new except that it will raise an ArgumentError
42
- # unless the +file+ already exists.
43
- #
44
- def self.open(file)
45
- raise ArgumentError, 'shortcut not found' unless File.exists?(file)
46
- self.new(file)
47
- end
48
-
49
- # Returns any arguments (i.e. command line options) for the shortcut.
50
- #
51
- def arguments
52
- @link.Arguments
53
- end
54
-
55
- # Sets the arguments (i.e. command line options) for the shortcut.
56
- #
57
- def arguments=(args)
58
- @link.Arguments = args
59
- end
60
-
61
- # Returns the description (i.e. comment) for the shortcut.
62
- #
63
- def description
64
- @link.Description
65
- end
66
-
67
- # Sets the description for the shortcut.
68
- #
69
- def description=(desc)
70
- @link.Description = desc
71
- end
72
-
73
- # Returns the file name of the shortcut.
74
- #
75
- def file
76
- @file
77
- end
78
-
79
- # Returns the hotkey (i.e. shortcut key) associated to the shortcut, in
80
- # the form of a 2-byte number of which the first byte identifies the
81
- # modifiers (Ctrl, Alt, Shift) and the second is the ASCII code of
82
- # the character key.
83
- #
84
- def hotkey
85
- @link.HotKey
86
- end
87
-
88
- # Sets the hotkey for the shortcut.
89
- #
90
- def hotkey=(key)
91
- @link.HotKey = key
92
- end
93
-
94
- # Returns the name of the file that contain the icon for the shortcut.
95
- # In practice this is almost always blank. YMMV.
96
- #
97
- def icon_location
98
- @link.IconLocation
99
- end
100
-
101
- # Sets the name of the icon file to be used for the shortcut.
102
- #
103
- def icon_location=(location)
104
- @link.IconLocation = location
105
- end
106
-
107
- # Returns the target of the shortcut. This is, joined with arguments, the
108
- # content of the "Target" field in a Shortcut Properties Dialog Box. The
109
- # target name is returned in 8.3 format.
110
- #
111
- def path
112
- @link.TargetPath
113
- end
114
-
115
- alias target_path path
116
-
117
- # Sets the target of the shortcut.
118
- #
119
- def path=(link_path)
120
- @link.TargetPath = link_path
121
- end
122
-
123
- alias target_path= path=
124
-
125
- # Attempts to automatically resolve a shortcut and returns the resolved path,
126
- # or raises an error. In case no resolution was made, the path is returned
127
- # unchanged.
128
- #
129
- # Note that the path is automatically updated in the path attribute of the
130
- # Shortcut object.
131
- #
132
- def resolve
133
- @link.FullName
134
- end
135
-
136
- # Returns the type of window style used by a shortcut. The possible
137
- # return values are 'normal', 'maximized', or 'minimized'.
138
- #
139
- def window_style
140
- case @link.WindowStyle
141
- when SHOWNORMAL
142
- 'normal'
143
- when SHOWMAXIMIZED
144
- 'maximized'
145
- when SHOWMINNOACTIVE
146
- 'minimized'
147
- else
148
- 'unknown' # Should never reach here
149
- end
150
- end
151
-
152
- # Deprecated.
153
- alias show_cmd window_style
154
-
155
- # Sets the window style to a shortcut. The +style+ can be one of the
156
- # following three constants or equivalent string values:
157
- #
158
- # * SHOWNORMAL or 'normal'
159
- # * SHOWMAXIMIZED or 'maximized'
160
- # * SHOWMINNOACTIVE or 'minimized'
161
- #
162
- # Please see the documentation for those constants for further details.
163
- #
164
- def window_style=(style)
165
- valid = [SHOWNORMAL, SHOWMAXIMIZED, SHOWMINNOACTIVE]
166
- valid.concat(['normal', 'maximized', 'minimized'])
167
-
168
- unless valid.include?(style)
169
- raise ArgumentError, 'invalid style'
170
- end
171
-
172
- if style.is_a?(String)
173
- case style.downcase
174
- when 'normal'
175
- style = SHOWNORMAL
176
- when 'maximized'
177
- style = SHOWMAXIMIZED
178
- when 'minimized'
179
- style = SHOWMINNOACTIVE
180
- end
181
- end
182
-
183
- @link.WindowStyle = style
184
- end
185
-
186
- # Deprecated.
187
- alias show_cmd= window_style=
188
-
189
- # Returns directory in which the targeted program will be executed.
190
- # Correspond to the "Start in" field of a Shortcut Properties Dialog Box.
191
- #
192
- def working_directory
193
- @link.WorkingDirectory
194
- end
195
-
196
- # Sets the directory in which the targeted program will be executed.
197
- #
198
- def working_directory=(directory)
199
- @link.WorkingDirectory = directory
200
- end
201
-
202
- def save
203
- @link.Save
204
- end
205
- end
1
+ require 'win32ole'
2
+
3
+ module Win32
4
+ class Shortcut
5
+ VERSION = '0.2.1'
6
+
7
+ # Activates and displays a window. If the window is minimized or maximized,
8
+ # the system restores it to its original size and position. An application
9
+ # should specify this flag when displaying the window for the first time.
10
+ #
11
+ SHOWNORMAL = 1
12
+
13
+ # Activates the window and displays it as a maximized window.
14
+ #
15
+ SHOWMAXIMIZED = 3
16
+
17
+ # Displays the window in its minimized state, leaving the currently active
18
+ # window as active.
19
+ #
20
+ SHOWMINNOACTIVE = 7
21
+
22
+ # Creates and returns a Shortcut object. In block form it yields +self+
23
+ # and automatically ensures that Shortcut#save is called at the end of
24
+ # the block. In non-block form it does not actually create the shortcut
25
+ # until the Shorcut#save method is called.
26
+ #
27
+ def initialize(file)
28
+ @file = file
29
+ @shell = WIN32OLE.new('WScript.Shell')
30
+ @link = @shell.CreateShortcut(file)
31
+
32
+ if block_given?
33
+ begin
34
+ yield self
35
+ ensure
36
+ save
37
+ end
38
+ end
39
+ end
40
+
41
+ # Identical to Shortcut#new except that it will raise an ArgumentError
42
+ # unless the +file+ already exists.
43
+ #
44
+ def self.open(file)
45
+ raise ArgumentError, 'shortcut not found' unless File.exists?(file)
46
+ self.new(file)
47
+ end
48
+
49
+ # Returns any arguments (i.e. command line options) for the shortcut.
50
+ #
51
+ def arguments
52
+ @link.Arguments
53
+ end
54
+
55
+ # Sets the arguments (i.e. command line options) for the shortcut.
56
+ #
57
+ def arguments=(args)
58
+ @link.Arguments = args
59
+ end
60
+
61
+ # Returns the description (i.e. comment) for the shortcut.
62
+ #
63
+ def description
64
+ @link.Description
65
+ end
66
+
67
+ # Sets the description for the shortcut.
68
+ #
69
+ def description=(desc)
70
+ @link.Description = desc
71
+ end
72
+
73
+ # Returns the file name of the shortcut.
74
+ #
75
+ def file
76
+ @file
77
+ end
78
+
79
+ # Returns the hotkey (i.e. shortcut key) associated to the shortcut, in
80
+ # the form of a 2-byte number of which the first byte identifies the
81
+ # modifiers (Ctrl, Alt, Shift) and the second is the ASCII code of
82
+ # the character key.
83
+ #
84
+ def hotkey
85
+ @link.HotKey
86
+ end
87
+
88
+ # Sets the hotkey for the shortcut.
89
+ #
90
+ def hotkey=(key)
91
+ @link.HotKey = key
92
+ end
93
+
94
+ # Returns the name of the file that contain the icon for the shortcut.
95
+ # In practice this is almost always blank. YMMV.
96
+ #
97
+ def icon_location
98
+ @link.IconLocation
99
+ end
100
+
101
+ # Sets the name of the icon file to be used for the shortcut.
102
+ #
103
+ def icon_location=(location)
104
+ @link.IconLocation = location
105
+ end
106
+
107
+ # Returns the target of the shortcut. This is, joined with arguments, the
108
+ # content of the "Target" field in a Shortcut Properties Dialog Box. The
109
+ # target name is returned in 8.3 format.
110
+ #
111
+ def path
112
+ @link.TargetPath
113
+ end
114
+
115
+ alias target_path path
116
+
117
+ # Sets the target of the shortcut.
118
+ #
119
+ def path=(link_path)
120
+ @link.TargetPath = link_path
121
+ end
122
+
123
+ alias target_path= path=
124
+
125
+ # Attempts to automatically resolve a shortcut and returns the resolved path,
126
+ # or raises an error. In case no resolution was made, the path is returned
127
+ # unchanged.
128
+ #
129
+ # Note that the path is automatically updated in the path attribute of the
130
+ # Shortcut object.
131
+ #
132
+ def resolve
133
+ @link.FullName
134
+ end
135
+
136
+ # Returns the type of window style used by a shortcut. The possible
137
+ # return values are 'normal', 'maximized', or 'minimized'.
138
+ #
139
+ def window_style
140
+ case @link.WindowStyle
141
+ when SHOWNORMAL
142
+ 'normal'
143
+ when SHOWMAXIMIZED
144
+ 'maximized'
145
+ when SHOWMINNOACTIVE
146
+ 'minimized'
147
+ else
148
+ 'unknown' # Should never reach here
149
+ end
150
+ end
151
+
152
+ # Deprecated.
153
+ alias show_cmd window_style
154
+
155
+ # Sets the window style to a shortcut. The +style+ can be one of the
156
+ # following three constants or equivalent string values:
157
+ #
158
+ # * SHOWNORMAL or 'normal'
159
+ # * SHOWMAXIMIZED or 'maximized'
160
+ # * SHOWMINNOACTIVE or 'minimized'
161
+ #
162
+ # Please see the documentation for those constants for further details.
163
+ #
164
+ def window_style=(style)
165
+ valid = [SHOWNORMAL, SHOWMAXIMIZED, SHOWMINNOACTIVE]
166
+ valid.concat(['normal', 'maximized', 'minimized'])
167
+
168
+ unless valid.include?(style)
169
+ raise ArgumentError, 'invalid style'
170
+ end
171
+
172
+ if style.is_a?(String)
173
+ case style.downcase
174
+ when 'normal'
175
+ style = SHOWNORMAL
176
+ when 'maximized'
177
+ style = SHOWMAXIMIZED
178
+ when 'minimized'
179
+ style = SHOWMINNOACTIVE
180
+ end
181
+ end
182
+
183
+ @link.WindowStyle = style
184
+ end
185
+
186
+ # Deprecated.
187
+ alias show_cmd= window_style=
188
+
189
+ # Returns directory in which the targeted program will be executed.
190
+ # Correspond to the "Start in" field of a Shortcut Properties Dialog Box.
191
+ #
192
+ def working_directory
193
+ @link.WorkingDirectory
194
+ end
195
+
196
+ # Sets the directory in which the targeted program will be executed.
197
+ #
198
+ def working_directory=(directory)
199
+ @link.WorkingDirectory = directory
200
+ end
201
+
202
+ def save
203
+ @link.Save
204
+ end
205
+ end
206
206
  end
@@ -3,10 +3,9 @@
3
3
  #
4
4
  # Test suite for the win32-shortcut package. This will temporarily create
5
5
  # a link to Notepad on C:\, which should be automatically deleted.
6
+ #
7
+ # You should run this test case via the 'rake test' task.
6
8
  ##############################################################################
7
- Dir.chdir('..') if File.basename(Dir.pwd) == 'test'
8
- $LOAD_PATH.unshift(Dir.pwd + '/lib')
9
-
10
9
  require 'win32/shortcut'
11
10
  require 'test/unit'
12
11
  include Win32
@@ -18,7 +17,7 @@ class TC_Shortcut < Test::Unit::TestCase
18
17
  end
19
18
 
20
19
  def test_version
21
- assert_equal('0.2.0', Shortcut::VERSION)
20
+ assert_equal('0.2.1', Shortcut::VERSION)
22
21
  end
23
22
 
24
23
  def test_arguments
@@ -2,7 +2,7 @@ require "rubygems"
2
2
 
3
3
  spec = Gem::Specification.new do |gem|
4
4
  gem.name = "win32-shortcut"
5
- gem.version = "0.2.0"
5
+ gem.version = "0.2.1"
6
6
  gem.author = "Daniel J. Berger"
7
7
  gem.email = "djberg96@gmail.com"
8
8
  gem.homepage = "http://www.rubyforge.org/projects/win32utils"
@@ -14,7 +14,7 @@ spec = Gem::Specification.new do |gem|
14
14
  gem.files = Dir["lib/win32/*.rb"] + Dir["test/*"] + Dir["[A-Z]*"]
15
15
  gem.files.reject! { |fn| fn.include? "CVS" }
16
16
  gem.require_path = "lib"
17
- gem.extra_rdoc_files = ["README", "CHANGES"]
17
+ gem.extra_rdoc_files = ["README", "CHANGES", "MANIFEST"]
18
18
  end
19
19
 
20
20
  if $0 == __FILE__
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: win32-shortcut
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2006-10-30 00:00:00 -07:00
6
+ version: 0.2.1
7
+ date: 2007-07-29 00:00:00 -06:00
8
8
  summary: An interface for creating or modifying Windows shortcuts.
9
9
  require_paths:
10
10
  - lib
@@ -30,12 +30,15 @@ authors:
30
30
  - Daniel J. Berger
31
31
  files:
32
32
  - lib/win32/shortcut.rb
33
+ - test/CVS
33
34
  - test/tc_shortcut.rb
34
35
  - CHANGES
36
+ - CVS
35
37
  - examples
36
- - install.rb
38
+ - ext
37
39
  - lib
38
40
  - MANIFEST
41
+ - Rakefile
39
42
  - README
40
43
  - test
41
44
  - win32-shortcut.gemspec
@@ -46,6 +49,7 @@ rdoc_options: []
46
49
  extra_rdoc_files:
47
50
  - README
48
51
  - CHANGES
52
+ - MANIFEST
49
53
  executables: []
50
54
 
51
55
  extensions: []
data/install.rb DELETED
@@ -1,11 +0,0 @@
1
- # For those who don't like gems...
2
- require 'rbconfig'
3
- require 'ftools'
4
- include Config
5
-
6
- sitelibdir = CONFIG['sitelibdir']
7
- installdir = sitelibdir + '/win32'
8
- file = 'lib\win32\shortcut.rb'
9
-
10
- Dir.mkdir(installdir) unless File.exists?(installdir)
11
- File.copy(file, installdir, true)