// OPENCURS.VDM - Open the filename or the URL at the cursor, // or Preview current file in the Browser. // // Written by: Ted Green and Christian Ziemski // Last change: 06-Jul-2005 // // STRIPPED DOWN TO "Open file at cursor" in VEDIT for testinf with Ian Davies // // Requires: VEDIT 6.12 or later. // // From VEDIT: Right-click and select "Open file here" or "Open URL here". // or {File, Open (More), ...} // // Input: #103==1 : "Open file at cursor" in VEDIT // #103==2 : "Open URL at cursor" in browser // #103==3 : {FILE, Open more, Preview current file in browser} // #103==4 : "Open URL from T-Reg 121" in browser (used from {Help, VEDIT Website, ...}) // //////////////// if (#103 != 1) { return } // // If "Open file at cursor" // Save_Pos() if (BE > -1 && Abs(BE-BB)<100 && CP >= Min(BB,BE) && CP <= Max(BB,BE)) { //If cursor within small block... Goto_Pos(BB) #104 = Cur_Line Goto_Pos(BE) #105 = Cur_Line if (#104 != #105) { Statline_Message("Error! Block on > 1 line!") Goto ERROR } Reg_Copy_Block(121,BB,BE) } else { #106 = Cur_Pos if (!At_BOL) { Search(`|{|W,",|<,<}`,REVERSE+ADVANCE+NOERR) } #104 = Cur_Pos Goto_Pos(#106) Search(`|{|W,",|>,>}`,NOERR) #105 = Cur_Pos if (Abs(#105-#104)>100) { Statline_Message("Error! Word too large!") Goto ERROR } Reg_Copy_Block(121,#104,#105) } if (Reg_Size(121)==0) { Statline_Message("Error! No filename/URL!") Goto ERROR } Restore_Pos() Statline_Message(" ") // empty possible previous error message // // If filename contains double-quotes, remove them. // #106=Buf_Num Buf_Switch(Buf_Free(EXTRA)) Buf_Empty(OK) Reg_Ins(121) Replace('"','',BEGIN+ALL+NOERR) // // Since File_Exist(r, NOERR) in Open_URL breaks if there is an URL like "file://localhost/C:/...." // we have to workaround that for now. // Replace("| 1) { //If current buffer has a file open... Reg_Set(99,CUR_DIR) // Save the current directory Chdir(@98) // Change to the path of the current file } if (File_Exist(@121,NOERR) < 1) { //If file does not exist... Message("File does not exist!", STATLINE) //Message on status line if (File_Exist("|@(103)\nul",NOERR) < 1) { //If path of file does not exist too if (Reg_Size(98) <= 1) { // If current buffer has no file open Reg_Set(98, CUR_DIR) // use current dir as path } Reg_Set(121, @98) // Add the path Reg_Set(121, "\", APPEND) Reg_Set(121, @104, APPEND) // and the filename for GF() } #106 = Get_Filename(121,@121,FORCE+NOERR) //Confirm it if (#106 == 0) { Goto DONE2 } //If User [Cancel] if (File_Exist(@121,NOERR) < 1) { //If file still does not exist... #106 = Dialog_Input_1(105,"`Warning - Preview file in browser`,`The file you have chosen does not exist.\n\nCreate a new one with that name?`,`[Yes]`,`[Cancel]`",APP+CENTER,0,0) if (#106 != 1) { Goto DONE2 } //If User [Cancel] } } File_Open("|@(121)",MRU) //Open the file } // :DONE2: if (Reg_Size(98) > 1) { // If current buffer has a file open... if (Reg_Size(99) > 0) { // If there is a path to restore... Chdir(@99) // Restore the original current directory } } Reg_Pop(98,99) // Restore T-Reg 98 & 99 return // :ERROR: Restore_Pos() Alert() return