AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Select filename only during Rename in Windows Explorer

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
bobbo



Joined: 19 Mar 2007
Posts: 14

PostPosted: Thu Mar 29, 2007 8:06 pm    Post subject: Select filename only during Rename in Windows Explorer Reply with quote

This code selects just the filename (and not the extension) when you press F2 in Windows Explorer to rename a file/folder.

I wrote this because I like having the file extensions visible, but I dislike having to manually de-select a file's extension when renaming the file. This gives me the best of both.

Code:
F2::GoSub,CheckActiveWindow

; from http://www.autohotkey.com/forum/topic13509.html
CheckActiveWindow:
  Hotkey,F2,Off
  ID := WinExist("A")
  WinGetClass,Class, ahk_id %ID%
  WClasses := "CabinetWClass ExploreWClass"
  IfInString, WClasses, %Class%
    GoSub, EditNameOnly
  else
    Send {F2}   
  Hotkey,F2,On
Return

EditNameOnly:
  filename := GetExplorerSelectedFile()
  IfInString,filename,.
  {
      pos := StrLen(filename) - InStr(filename,".",false,0) + 1
      Send {F2}{Shift Down}{Left %pos%}{Shift Up}
  }
  else
      Send {F2}
Return

; from http://www.autohotkey.com/forum/viewtopic.php?t=10085
GetExplorerSelectedFile()
{
   local selectedFiles, file

   ControlGet, selectedFiles, List, Selected Col1, SysListView321, ahk_class ExploreWClass
   Loop, Parse, selectedFiles, `n  ; Rows are delimited by linefeeds (`n).
   {
      If (A_Index = 1)
         file := A_LoopField
      Else
         ErrorLevel := A_Index ; Indicate that several files are selected, we return only the first one
   }
   Return file
}


Thanks to Skan for the CheckActiveWindow routine, and to PhiLho for the GetExplorerSelectedFile function.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3624
Location: Belgrade

PostPosted: Thu Mar 29, 2007 8:26 pm    Post subject: Reply with quote

Total commander has that by default. SIngle F2 opens the editor, if you press it again you select only file name without ext.
_________________
Back to top
View user's profile Send private message MSN Messenger
bobbo



Joined: 19 Mar 2007
Posts: 14

PostPosted: Fri Mar 30, 2007 3:55 pm    Post subject: Simplified Reply with quote

I greatly simplified the code:
Code:
F2::GoSub,EditNameOnly

EditNameOnly:
   Hotkey,F2,Off
   ControlGet, filename, List, Focused Col1, SysListView321, ahk_class ExploreWClass
   ControlGetFocus, CurrentControl,,FolderView
   If (StrLen(filename)>0 and CurrentControl="SysListView321")
   {
      ; find the ".", de-select text to the right of it
      IfInString, filename, .
      {
         pos := StrLen(filename) - InStr(filename,".",false,0) + 1
         Send {F2}{Shift Down}{Left %pos%}{Shift Up}
      }
      else
         Send {F2}
   }
   Else
   {
      ; not a Windows explorer window
      Send {F2}
   }
   Hotkey,F2,On
Return

EDIT: Bug fixed.
Quote:
The only remaining bug is that I can't detect if I'm in the folder toolbar or in the explorer window. That means it occasionally adjusts the selected text in the folder bar based on the file selected in explorer window.

Anyone know how to detect if you're in the folder pane? Winspy tells me the text should be blank, but WinGetText always returns "FolderView" (as if the explorer window had focus).
Back to top
View user's profile Send private message
elchapin



Joined: 06 Mar 2007
Posts: 58
Location: Columbus, OH, USA

PostPosted: Mon Apr 09, 2007 6:56 pm    Post subject: Reply with quote

Vista only selects the file name too, and I loved that. Since I work between XP and Vista all day, I was excited to see this! Thanks for sharing.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group