Send selection to new UE document

Send selection to new UE document

2
NewbieNewbie
2

    Mar 26, 2013#1

    I was wondering if anyone has created, or has any ideas on how to create, a Windows app that will send the currently selected text (from any application) into UE, that is, create a new document in UE and automatically paste the selected text into that new document: all with 1 (right) click.

    I'm envisioning a right-click menu item "Send to UltraEdit". Note that I do not want to do this with a file, rather I want to do this with the currently selected text.

    Any ideas would be appreciated.

    6,686585
    Grand MasterGrand Master
    6,686585

      Mar 27, 2013#2

      You are surely not able to modify the context menu of other applications. So if you want Windows clipboard pasted into a new file in UltraEdit from any application you need first the following UltraEdit script saved for example as "PasteToNewFile.js".

      Code: Select all

      // First it must be determined if a new file must be created or if UltraEdit
      // was just started and a new and empty file was created already on startup.
      if (UltraEdit.document.length < 0)  // Is no file opened?
      {
         UltraEdit.newFile();    // Create a new file.
      }
      else
      {
         // Is the active file a named file with an extension?
         if (!UltraEdit.activeDocument.isName(""))
         {
            UltraEdit.newFile(); // Create a new file.
         }
         else  // The active file is an unnamed file.
         {
            // Is hex edit mode active for the unnamed file or something selected?
            if ((UltraEdit.activeDocument.hexMode == true) || UltraEdit.activeDocument.isSel())
            {
               UltraEdit.newFile(); // Create a new file.
            }
            else
            {
               var nColOffset = (typeof(UltraEdit.activeDocumentIdx) == "undefined") ? 1 : 0;
               // Get current position of the caret in the text file.
               var nLineNum = UltraEdit.activeDocument.currentLineNum;
               var nColNum = UltraEdit.activeDocument.currentColumnNum + nColOffset;
               // Is the caret not at line 1 column 1, the unnamed file is not empty.
               if ((nLineNum > 1) || (nColNum > 1))
               {
                  UltraEdit.newFile(); // Create a new file.
               }
               // Select a character to the right. This is only possible if the file
               // is not empty independent of setting "Allow positioning beyond line
               // end" which makes RIGHT ARROW possible even in an empty file, and
               // also independent of column editing or normal text editing mode.
               UltraEdit.activeDocument.startSelect();
               UltraEdit.activeDocument.key("RIGHT ARROW");
               UltraEdit.activeDocument.endSelect();
               if (UltraEdit.activeDocument.isSel())
               {
                  // Restore caret position in the not empty unnamed file.
                  UltraEdit.activeDocument.gotoLine(nLineNum,nColNum);
                  UltraEdit.newFile(); // Create a new file.
               }
               else UltraEdit.activeDocument.top();
            }
         }
      }
      UltraEdit.selectClipboard(0);               // Select the Windows clipboard.
      var bColumnMode = UltraEdit.columnMode;     // Remember column mode status.
      if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();   // Turn off column editing mode.
      else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
      UltraEdit.activeDocument.paste();           // Paste the clipboard content.
      UltraEdit.activeDocument.top();             // Move caret to top in new file.
      if (bColumnMode)                            // Restore column mode status.
      {
         if (typeof(UltraEdit.columnModeOn) == "function") UltraEdit.columnModeOn();
         else if (typeof(UltraEdit.activeDocument.columnModeOn) == "function") UltraEdit.activeDocument.columnModeOn();
      }
      Next create a shortcut on your desktop or anywhere in the Windows start menu for example with name "PasteToNewFile". Open the properties of this shortcut and modify the command line to

      "Full path to uedit32.exe\uedit32.exe" /fni /s="full path to PasteToNewFile.js\PasteToNewFile.js"

      In the properties of the shortcut define also a Windows wide hotkey for launching a new instance of UltraEdit with automatic execution of the script. You can use for example Win+V.

      Now you can copy a selection in any application with Ctrl+C to Windows clipboard and press the hotkey of the shortcut to start a new instance of UltraEdit with pasting the copied text into a new file.

      You can add this script in UltraEdit under Scripting - Script List to the list of UltraEdit scripts and assign a hotkey (not the one of the shortcut) to the script. This makes it possible to switch with Alt+Tab to UltraEdit after Ctrl+C in a different application and paste the copied text into a new file in already running instance of UltraEdit. Of course you can then also press Ctrl+C in UltraEdit and the hotkey of the script to paste the content into a new file, i.e. Ctrl+N and Ctrl+V replaced by a single hotkey.