Page 1 of 1

FileExplorer:Tabs & Drag'n'Drop

Posted: Fri Aug 31, 2012 2:39 pm
by A.D.
Hi there !

I would like to have Tabs for the FileExplorer which is on right side of the IDE so that you can easily copy files with drag'n'drop from other places into the source folder.
Drag'n'Drop from the FileExplorer to the Projekt-Tab would be nice too...

Greets

A.D:

Re: FileExplorer:Tabs & Drag'n'Drop

Posted: Thu Sep 06, 2012 8:57 am
by A.D.
Thanks for adding the Favorites to the IDE.
Could you make it possible to copy and replace files from the explorer tool into the favorite directories by drag'n'drop please, too !?!

There's another thing i would like to have, dear fred :

Code: Select all

LoadImage(1,"test.png")
It would be nice if we could drag'n'drop files from the explorer tool
onto the codeline to replace the filename automatically.

A.D.

Re: FileExplorer:Tabs & Drag'n'Drop

Posted: Thu Sep 06, 2012 4:42 pm
by Bisonte
This can be done with an external IDE tool...

There triggers about that handling.... Replace FileViewer - Special File

Re: FileExplorer:Tabs & Drag'n'Drop

Posted: Thu Sep 06, 2012 6:47 pm
by A.D.
I think you can't do it with an external tool because there isn't a way to retrieve the dragged file string. And how do you replace
the string in the source code ?

Re: FileExplorer:Tabs & Drag'n'Drop

Posted: Thu Sep 06, 2012 9:13 pm
by Bisonte
Basecode from StarGate: http://purebasic.fr/german/viewtopic.ph ... 45#p294445

Code: Select all

; Arguments : "%FILE"
; Trigger : Replace FileViewer Special File
; Wait till tool ends
; supported extension : png,bmp,jpg 
EnableExplicit
Procedure GetProcessFromWindow(WindowID.i)
   Protected ProcessID.i
   If GetWindowThreadProcessId_(WindowID, @ProcessID)
      ProcedureReturn OpenProcess_(#PROCESS_ALL_ACCESS, #False, ProcessID)
   EndIf
EndProcedure
Procedure SendText(ScintillaID.i, Text.s)
   Protected ProcessID.i = GetProcessFromWindow(ScintillaID)
   Protected Length.i
   Protected *MemoryID, *Buffer, Format.i
   If ProcessID
      Select SendMessage_(ScintillaID, #SCI_GETCODEPAGE, #Null, #Null)
         Case 0     : Format = #PB_Ascii
         Case 65001 : Format = #PB_UTF8
      EndSelect
      Length.i = StringByteLength(Text, Format)
      *Buffer = AllocateMemory(Length+SizeOf(Character))
      If *Buffer
         PokeS(*Buffer, Text, #PB_Default, Format)
         *MemoryID = VirtualAllocEx_(ProcessID, #Null, Length, #MEM_RESERVE|#MEM_COMMIT, #PAGE_EXECUTE_READWRITE)
         If *MemoryID
            WriteProcessMemory_(ProcessID, *MemoryID, *Buffer, Length, #Null)
            SendMessage_(ScintillaID, #SCI_ADDTEXT, Length, *MemoryID)
            VirtualFreeEx_(ProcessID, *MemoryID, Length, #MEM_RELEASE)
         EndIf
         FreeMemory(*Buffer)
      EndIf
      CloseHandle_(ProcessID)
   EndIf
EndProcedure

Define FileName.s = ProgramParameter(0)
Define Output.s
Define WindowID.i = Val(GetEnvironmentVariable("PB_TOOL_MAINWINDOW"))

If Not WindowID
   MessageRequester("FileNameToEditor.Tool", "Fehler: Das Programm kann nicht außerhalb von PureBasic gestartet werden!")
   End
EndIf

If Not FileName
   MessageRequester("FileNameToEditor.Tool", "Fehler: Es wurde keine Datei übergeben!")
   End
EndIf

Output = Chr(34) + FileName + Chr(34)
SendText(FindWindowEx_(WindowID,0,"Scintilla",0), Output)
Only a little example what can be made ;)

Re: FileExplorer:Tabs & Drag'n'Drop

Posted: Thu Sep 06, 2012 11:08 pm
by A.D.
Wow, okay, it's such a looong way to become a code guru :)
It would be perfect if the old filename would be replaced by the new one, i don't know at the moment how
to add that but i will try to.

Greets
A.D.

P.S.: Can you show me how to read text / complete line from a scintilla gadget? I guess this code won't work : :|

Code: Select all

Procedure GetProcessFromWindow(WindowID.i)
   Protected ProcessID.i
   If GetWindowThreadProcessId_(WindowID, @ProcessID)
      ProcedureReturn OpenProcess_(#PROCESS_ALL_ACCESS, #False, ProcessID)
   EndIf
EndProcedure

Procedure GetText(ScintillaID.i)

Protected ProcessID.i = GetProcessFromWindow(ScintillaID)
   Protected Length.i
   Protected *MemoryID, *Buffer, Format.i
   If ProcessID
      Select SendMessage_(ScintillaID, #SCI_GETCODEPAGE, #Null, #Null)
         Case 0     : Format = #PB_Ascii
         Case 65001 : Format = #PB_UTF8
      EndSelect
   
      Length.i = StringByteLength(String.s{20}, Format)
      *Buffer = AllocateMemory(Length+SizeOf(Character))
       
       *MemoryID = VirtualAllocEx_(ProcessID, #Null, Length, #MEM_RESERVE|#MEM_COMMIT, #PAGE_EXECUTE_READWRITE)
        If *MemoryID
         WriteProcessMemory_(ProcessID, *MemoryID, *Buffer, Length, #Null)
         SendMessage_(ScintillaID, #SCI_GETTEXT,20, *Buffer)
         VirtualFreeEx_(ProcessID, *MemoryID, Length, #MEM_RELEASE)
        EndIf
      
      Debug PeekS(*Buffer)   
      CloseHandle_(ProcessID)
      FreeMemory(*Buffer)
      
   EndIf
   
EndProcedure


Define WindowID.i = Val(GetEnvironmentVariable("PB_TOOL_MAINWINDOW"))
GetText(FindWindowEx_(WindowID,0,"Scintilla",0))


Re: FileExplorer:Tabs & Drag'n'Drop

Posted: Fri Sep 07, 2012 4:51 am
by Bisonte
A.D. wrote:Wow, okay, it's such a looong way to become a code guru :)
It would be perfect if the old filename would be replaced by the new one, i don't know at the moment how
to add that but i will try to.

Greets
A.D.

P.S.: Can you show me how to read text / complete line from a scintilla gadget? I guess this code won't work : :|
I don't know what you want exactly .... but you have on this example only mark up the filename and then drop a file on
the IDE window... Readtext is not necessary.

But if you add "%TEMPFILE" to the arguments and "%CURSOR" you have the exact position and the filename of the sourcecode
and you have to parse it by yourself ... or only the "%WORD" under the cursor... (and don't forget to mark "Reload Source after....")
But if your source is very huge...

Its all explained at the help file of pb (F1) - IDE External Tools

Re: FileExplorer:Tabs & Drag'n'Drop

Posted: Fri Sep 07, 2012 1:01 pm
by A.D.
I want that you can replace the file without having a current selection or the cursor in the right place, just the drag'n'drop . So I need to read the whole line, replace the filename and then write
the modified line back to scintilla. There is a command for reading text from scintilla (#SCI_GETTEXT,#SCI_GETLINE) but i don't understand how to get readaccess to the scintilla process:

Code: Select all

*MemoryID = VirtualAllocEx_(ProcessID, #Null, Length, #MEM_RESERVE|#MEM_COMMIT, #PAGE_EXECUTE_READWRITE)
        If *MemoryID
         WriteProcessMemory_(ProcessID, *MemoryID, *Buffer, Length, #Null)
         SendMessage_(ScintillaID, #SCI_GETTEXT,20, *Buffer)
         VirtualFreeEx_(ProcessID, *MemoryID, Length, #MEM_RELEASE)
        EndIf
I replaced the SendMessage Command, but theres nothing in the buffer. What are VirtualAllocEx_ , WriteProcessMemory_ for ?

Greets
A.D.