Skip to content

Commit

Permalink
add ControlSetText
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Dec 11, 2022
1 parent 9e3e4d5 commit 5ff47be
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AHK_X11 can be used completely without a terminal. You can however if you want u
<details><summary><strong>CLICK TO SEE WHICH COMMANDS ARE IMPLEMENTED AND WHICH ARE MISSING</strong>. Note however that this is not very representative. For example, no `Gui` sub command is included in the listing. For a better overview on what is already done, skim through the <a href="https://phil294.github.io/AHK_X11"><b>FULL DOCUMENTATION HERE</b></a>.</summary>

```diff
DONE ?% (90/219):
DONE ?% (91/219):
+ Else, { ... }, Break, Continue, Return, Exit, GoSub, GoTo, IfEqual, Loop, SetEnv, Sleep, FileCopy,
+ SetTimer, WinActivate, MsgBox, Gui, SendRaw, #Persistent, ExitApp,
+ EnvAdd, EnvSub, EnvMult, EnvDiv, ControlSendRaw, IfWinExist/IfWinNotExist, SetWorkingDir,
Expand All @@ -68,7 +68,7 @@ DONE ?% (90/219):
+ StringUpper, Suspend, URLDownloadToFile, WinClose, WinGetPos, WinKill, WinMaximize, WinMinimize,
+ WinMove, WinRestore, MouseGetPos, MouseMove, GetKeyState, KeyWait, ControlClick, WinGetText,
+ WinGetTitle, WinGetClass, PixelGetColor, CoordMode, GuiControl, ControlGetPos, ControlGetText,
+ WinGet, Input, Loop (parse a string), ToolTip, If var [not] in/contains MatchList
+ WinGet, Input, Loop (parse a string), ToolTip, If var [not] in/contains MatchList, ControlSetText

NEW ?% (8/219): (not part of spec or from a more recent version)
@@ Echo, ahk_x11_print_vars, FileRead, RegExGetPos, RegExReplace, EnvGet, @@
Expand All @@ -83,9 +83,9 @@ REMOVED ?% (12/219):
# AutoTrim: It's always Off. It would not differentiate between %a_space% and %some_var%.
# It's possible but needs significant work.

TO DO ?% (105/219): alphabetically
TO DO ?% (104/219): alphabetically
- BlockInput, ClipWait, Control, ControlFocus, ControlGet, ControlGetFocus,
- ControlMove, ControlSetText,
- ControlMove,
- DetectHiddenText, DetectHiddenWindows, Drive, DriveGet, DriveSpaceFree,
- FileCopyDir, FileCreateShortcut,
- FileInstall, FileGetAttrib, FileGetShortcut, FileGetSize, FileGetTime, FileGetVersion,
Expand Down
11 changes: 6 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ <h2>Table of contents </h2>
<a href="#ControlSend.htm">ControlSend/ControlSendRaw</a>
</li>
<li>
<a class="tbd" href="#ControlSetText.htm">ControlSetText</a>
<a href="#ControlSetText.htm">ControlSetText</a>
</li>
<li>
<a href="#Menu.htm">Menu</a>
Expand Down Expand Up @@ -2077,7 +2077,7 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<td height="16" class="calibre4">Sends simulated keystrokes to a window or control.</td>
</tr>
<tr class="calibre3">
<td height="16" class="tbd calibre4"><a href="#ControlSetText.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">ControlSetText</a></td>
<td height="16" class="calibre4"><a href="#ControlSetText.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">ControlSetText</a></td>
<td height="16" class="calibre4">Changes the text of a control.</td>
</tr>
<tr class="calibre3">
Expand Down Expand Up @@ -12909,7 +12909,7 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
return</pre>
</div>
</div>
<div class="calibreMain tbd">
<div class="calibreMain">
<div class="calibreEbookContent">
<a id="ControlSetText.htm" href="#ControlSetText.htm">#</a> <h2 class="calibre17">ControlSetText</h2>
<hr size="2" class="calibre24" />
Expand All @@ -12927,7 +12927,7 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<tbody class="calibre2">
<tr class="calibre3">
<td width="15%" class="calibre4">Control</td>
<td width="85%" class="calibre4">Can be either ClassNN (the classname and instance number of the control) or the name/text of the control, both of which can be determined via Window Spy. When using name/text, the matching behavior is determined by <a href="#SetTitleMatchMode.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetTitleMatchMode</a>. If this parameter is blank, the target window's topmost control will be used.</td>
<td width="85%" class="calibre4">Can be either ClassNN (the classname and instance number of the control (<span class="x11">recommended</span>)) or the name/text of the control (<span class="x11">can be slow</span>), both of which can be determined via Window Spy. When using name/text, the matching behavior is determined by <a href="#SetTitleMatchMode.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetTitleMatchMode</a>. <span class="tbd">If this parameter is blank, the target window's topmost control will be used.</span></td>
</tr>
<tr class="calibre3">
<td class="calibre4">NewText</td>
Expand Down Expand Up @@ -12956,7 +12956,8 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<p class="calibre8"><a href="#ErrorLevel.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Remarks</strong></p>
<p class="calibre8">To improve reliability, a delay is done automatically after every use of this command. That delay can be changed via <a href="#SetControlDelay.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetControlDelay</a>.</p>
<p class="x11">This command relies on accessibility support. <a href="#Accessibility.htm">Please read this section</a> to avoid problems.</p>
<p class="calibre8 tbd">To improve reliability, a delay is done automatically after every use of this command. That delay can be changed via <a href="#SetControlDelay.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetControlDelay</a>.</p>
<p class="calibre8">Window titles and text are always case sensitive. Hidden windows are not detected unless <a href="#DetectHiddenWindows.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">DetectHiddenWindows</a> has been turned on.</p>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Related</strong></p>
Expand Down
24 changes: 24 additions & 0 deletions src/cmd/x11/control/control-set-text.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "../window/win-util"

class Cmd::X11::Mouse::ControlSetText < Cmd::Base
def self.min_args; 1 end
def self.max_args; 6 end
def self.sets_error_level; true end
def run(thread, args)
class_nn_or_text = args[0]
new_text = args[1]
args.delete_at(0)
args.delete_at(0)
Cmd::X11::Window::Util.match(thread, args, empty_is_last_found: true, a_is_active: true) do |win|
success = thread.runner.display.at_spi do |at_spi|
acc = at_spi.find_descendant(thread, win, class_nn_or_text)
if acc
at_spi.set_text(acc, new_text)
end
false
end
return "1" if ! success
end
"0"
end
end
11 changes: 9 additions & 2 deletions src/run/display/at-spi.cr
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,22 @@ module Run
end
def get_text(accessible)
text = begin
# TODO: textareas etc?
# TODO: only if has no children?
accessible.text_iface.text(0, -1)
rescue e
accessible.name
end
text = text.gsub('', "").strip()
text.empty? ? nil : text
end
def set_text(accessible, text)
iface = begin
accessible.editable_text_iface
rescue e
return false
end
iface.set_text_contents text
true
end
# returns an array of recursive text strings, no duplication present.
# only 1,000 descendant nodes are queried each to not kill performance completely
# with windows with very large lists (e.g. Gtk tables: each cell is a child of the table)
Expand Down

0 comments on commit 5ff47be

Please sign in to comment.