'use strict' ; declare var appshell ; define ( ( require , exports , module ) => { const VERSION = '3.7.1' ; const AUTHOR = 'Alexandre Bento Freire' ; const COPYRIGHTS = 'Alexandre Bento Freire' ; const IX_MENU = "IX" ; const IX_MENU_TT = "IX TT" ; const MODULE_NAME = 'bracketstoix' ; const HELP_LINK = '' ; const EXPAND_TAGS = ';bu=button;d=div;sp=span;te=textarea;in=input' ; const PROJ_SETTINGS_FILE = '.projecttoix.json' ; const SP_FORCE_ALL = - 1 ; const SP_ALL = 1 ; const SP_WORD = 2 ; const SP_SENTENCE = 3 ; const SP_LINE = 4 ; const SP_NONE = 5 ; const __SP_FUNC = 6 ; const SP_FORCE_LINE = - 4 ; const SOCIAL = { home : HELP_LINK , twitter : 'https://twitter.com/devpieces' , github : 'http://github.com/a-bentofreire/bracketstoix' , } ; const brk = { } as any ; const ix = { } as any ; brk . Dialogs = brackets . getModule ( 'widgets/Dialogs' ) ; brk . CommandManager = brackets . getModule ( 'command/CommandManager' ) ; brk . Commands = brackets . getModule ( 'command/Commands' ) ; brk . EditorManager = brackets . getModule ( 'editor/EditorManager' ) ; brk . ProjectManager = brackets . getModule ( "project/ProjectManager" ) ; brk . DocumentManager = brackets . getModule ( "document/DocumentManager" ) ; brk . PreferencesManager = brackets . getModule ( 'preferences/PreferencesManager' ) ; brk . MainViewManager = brackets . getModule ( 'view/MainViewManager' ) ; brk . LanguageManager = brackets . getModule ( 'language/LanguageManager' ) ; brk . KeyBindingManager = brackets . getModule ( 'command/KeyBindingManager' ) ; brk . CoreStrings = brackets . getModule ( 'strings' ) ; brk . Strings = require ( "i18n!nls/strings" ) ; brk . ExtensionUtils = brackets . getModule ( 'utils/ExtensionUtils' ) ; brk . StringUtils = brackets . getModule ( 'utils/StringUtils' ) ; brk . KeyEvent = brackets . getModule ( 'utils/KeyEvent' ) ; brk . NodeDomain = brackets . getModule ( 'utils/NodeDomain' ) ; brk . FileUtils = brackets . getModule ( 'file/FileUtils' ) ; brk . FileSystem = brackets . getModule ( 'filesystem/FileSystem' ) ; brk . WorkspaceManager = brackets . getModule ( 'view/WorkspaceManager' ) ; brk . extprefs = brk . PreferencesManager . getExtensionPrefs ( MODULE_NAME ) ; brk . moduleroot = brk . FileUtils . getNativeModuleDirectoryPath ( module ) + '/' ; brk . Editor = brackets . getModule ( "editor/Editor" ) . Editor ; brk . Mustache = brackets . getModule ( "thirdparty/mustache/mustache" ) as MustacheStatic ; const ui = require ( 'uitoix' ) ; const transformutilities = require ( 'common/transformutilities' ) . transformutilities ; const lineutilities = require ( 'common/lineutilities' ) . lineutilities ; const um = require ( 'common/utilitymanager' ) . um ; um . utilityManager = utilityManager_ ; function utilityManager_ ( params , f ? ) { switch ( params . utilType ) { case um . TIXUtilityType . utInTransform : changeSelectionRegEx ( params . pat , params . repl , params . sp ) ; break ; case um . TIXUtilityType . utTransform : changeSelection ( ( text ) => { return f ( { intext : text } ) ; } , params . sp ) ; break ; case um . TIXUtilityType . utLinesUtility : changeSelection ( ( arr ) : string [ ] => { return f ( { inlines : arr } ) ; } , params . sp , true ) ; break ; case um . TIXUtilityType . utLineUtility : changeSelection ( ( arr ) : string [ ] => { arr . forEach ( ( value , index ) => { arr [ index ] = f ( { intext : value } ) ; } ) ; return arr ; } , params . sp , true ) ; break ; } } const optstoix = require ( 'optionstoix' ) ; const optshtml = require ( 'text!html/optionstoix.html' ) ; const prefs = require ( 'prefstoix' ) ; const ixDomains = new brk . NodeDomain ( 'IXDomains' , brk . ExtensionUtils . getModulePath ( module , 'node/IXDomains' ) ) ; const namedcmdlist = [ ] ; let cmdlist ; const storeidmap = { } ; const queueExternalSave = [ ] ; let externalQueueIsBusy = false ; const projSettings = { data : { } , applied : false , } ; let globalDoc = null ; const tools = { htmlEscape ( str ) { return String ( str ) . replace ( /&/g , '&amp;' ) . replace ( /"/g , '&quot;' ) . replace ( /'/g , '&#39;' ) . replace ( /</g , '&lt;' ) . replace ( />/g , '&gt;' ) ; } , processSplit ( text ) { return text . replace ( /\\t/g , "\t" ) . replace ( /\\\t/g , "\\t" ) . replace ( /\\n/g , "\n" ) . replace ( /\\\n/g , "\\n" ) ; } , strRepeat : ( ch , size ) => size > 0 ? new Array ( size + 1 ) . join ( ch ) : '' , textToID : ( text ) => text . toLowerCase ( ) . replace ( /\./g , '' ) . replace ( / /g , '' ) , getSpaceText : ( text ) => text . replace ( /\\\$/g , ' ' ) , } ; function i18n ( text , defText ? ) { return brk . Strings [ text ] || ( defText !== undefined ? defText : text ) ; } function logErr ( msg ) { console . error ( '[' + MODULE_NAME + '] ' + msg ) ; } function checkExt ( file , ext ) { return file . substr ( file . length - ext . length ) === ext ; } const REGNIZE_FIND = /([\\.()\[\]*+\^$])/g ; const REGNIZE_REPL = '\\$1' ; function getRegnize ( text , isFind ) { return text . replace ( isFind ? REGNIZE_FIND : /(\$\d)/g , REGNIZE_REPL ) ; } function loadExtPrefs ( ) { prefs . load ( prefs , brk . extprefs ) ; prefs . commands . value . showinctxmenu = prefs . commands . value . showinctxmenu || [ ] ; } function saveExtPrefs ( ) { prefs . save ( prefs , brk . extprefs ) ; } function clipbrdCopy ( text ) { const d = document . createElement ( 'textarea' ) as any ; d . contentEditable = true ; document . body . appendChild ( d ) ; d . value = text ; d . unselectable = 'off' ; d . style . position = 'absolute' ; d . focus ( ) ; document . execCommand ( 'SelectAll' ) ; document . execCommand ( 'Copy' , false , null ) ; document . body . removeChild ( d ) ; } function clipbrdPaste ( ) { let text ; const d = document . createElement ( 'textarea' ) as any ; d . contentEditable = true ; document . body . appendChild ( d ) ; d . unselectable = 'off' ; d . style . position = 'absolute' ; d . focus ( ) ; document . execCommand ( 'Paste' , false , null ) ; document . execCommand ( 'SelectAll' ) ; text = d . value ; document . body . removeChild ( d ) ; return text ; } interface SO { cm : any ; selfunc : any ; selpolicy : any ; start ? : { ch : number ; line : number ; } ; selected ? : boolean ; end ? : { ch : number ; line : number ; } ; cursor ? : any ; cursel ? : any ; } function getSelObj ( selPolicy ) { let so ; let len ; let inf ; if ( globalDoc ) { globalDoc . _ensureMasterEditor ( ) ; so = { cm : globalDoc . _masterEditor . _codeMirror , selfunc : selPolicy , selpolicy : SP_FORCE_ALL , start : { ch : 0 , line : 0 , } , selected : false , } ; so . end = { ch : 0 , line : so . cm . lineCount ( ) , } ; so . cursor = so . cm . getCursor ( ) ; so . cursel = so . cm . getRange ( so . start , so . end ) ; return so ; } so = { cm : brk . EditorManager . getActiveEditor ( ) . _codeMirror , selfunc : selPolicy , selpolicy : typeof selPolicy !== 'function' ? selPolicy : __SP_FUNC , } ; so . cursor = so . cm . getCursor ( ) ; so . selected = ( so . selpolicy >= 0 ) && so . cm . somethingSelected ( ) ; if ( so . selected ) { so . cursel = so . cm . getSelection ( ) ; } else { so . cursel = '' ; switch ( so . selpolicy ) { case SP_FORCE_LINE : case SP_LINE : so . cursel = so . cm . getLine ( so . cursor . line ) ; so . start = { ch : 0 , line : so . cursor . line , } ; so . end = { ch : so . cursel . length , line : so . cursor . line , } ; break ; case SP_SENTENCE : case SP_WORD : so . cursel = so . cm . getLine ( so . cursor . line ) ; len = so . cursel . length ; if ( selPolicy === SP_WORD ) { so . cursel = so . cursel . replace ( /(\W)/g , ' ' ) ; } so . start = { ch : so . cursor . ch , line : so . cursor . line , } ; so . end = { ch : so . cursor . ch , line : so . cursor . line , } ; while ( ( so . start . ch > 0 ) && ( so . cursel [ so . start . ch - 1 ] !== ' ' ) ) { so . start . ch -- ; } while ( ( so . end . ch < len ) && ( so . cursel [ so . end . ch ] !== ' ' ) ) { so . end . ch ++ ; } so . cursel = so . cursel . substring ( so . start . ch , so . end . ch ) ; break ; case SP_FORCE_ALL : case SP_ALL : so . start = { ch : 0 , line : 0 , } ; so . end = { ch : 0 , line : so . cm . lineCount ( ) , } ; so . cursel = so . cm . getRange ( so . start , so . end ) ; break ; case SP_NONE : so . start = { ch : so . cursor . ch , line : so . cursor . line , } ; so . end = { ch : so . cursor . ch , line : so . cursor . line , } ; break ; case __SP_FUNC : so . cursel = so . cm . getLine ( so . cursor . line ) ; so . start = { ch : so . cursor . ch , line : so . cursor . line , } ; so . end = { ch : so . cursor . ch + 1 , line : so . cursor . line , } ; inf = { so , dir : - 1 , } ; while ( so . start . ch > 0 ) { if ( ! so . selfunc ( inf , so . cursel [ so . start . ch ] ) ) { so . start . ch -= inf . dir ; break ; } so . start . ch += inf . dir ; } inf . dir = 1 ; while ( so . end . ch < so . cursel . length ) { if ( ! so . selfunc ( inf , so . cursel [ so . end . ch - 1 ] ) ) { so . end . ch -= inf . dir ; break ; } so . end . ch += inf . dir ; } so . cursel = so . cursel . substring ( so . start . ch , so . end . ch ) ; break ; } } so . cm . focus ( ) ; return so ; } function changeSelection ( callback , selPolicy ? , hasArray ? , forceAll ? ) { const so = getSelObj ( selPolicy ) ; let newSel ; if ( ! so . cursel && selPolicy !== SP_NONE ) { return ; } if ( ! hasArray ) { newSel = callback ( so . cursel , so ) ; } else { newSel = callback ( so . cursel . split ( "\n" ) , so ) . join ( "\n" ) ; } if ( so . cursel !== newSel ) { if ( so . selected ) { so . cm . replaceSelection ( newSel , so ) ; } else { so . cm . replaceRange ( newSel , so . start , so . end ) ; if ( so . cursor ) { so . cm . setCursor ( so . cursor ) ; } } } } function setSelection ( so , newSel ) { so . cm . replaceSelection ( newSel , so ) ; } function getSelection ( callback , selPolicy ) { const so = getSelObj ( selPolicy ) ; if ( ! so . cursel ) { return ; } callback ( so . cursel , so ) ; } function changeSelectionRegEx ( regex , repl , selPolicy ) { changeSelection ( ( text ) => text . replace ( regex , repl ) , selPolicy , false ) ; } function sortSelection ( sortFunc , selPolicy ) { changeSelection ( ( arr ) => { arr . sort ( sortFunc ) ; return arr ; } , selPolicy , true ) ; } function setRow ( row , text , so ) { so . cm . replaceRange ( text + '\n' , { ch : 0 , line : row , } , { ch : 0 , line : row + 1 , } ) ; } function insertRow ( row , text , so ) { so . cm . replaceRange ( text + '\n' , { ch : 0 , line : row , } , { ch : 0 , line : row , } ) ; } function getCurFileName ( ) { const curFile = brk . ProjectManager . getSelectedItem ( ) ; return curFile ? curFile . _path || curFile . path : '' ; } function getProjectRoot ( ) { const root = brk . ProjectManager . getProjectRoot ( ) ; return root ? root . _path : '' ; } function copyToClipboard ( callback ) { clipbrdCopy ( callback ( brk . ProjectManager . getSelectedItem ( ) ) ) ; } function sendToBottomPanel ( header , msgArray ) { function getTableFromEvent ( event ) { let node = event . target ; while ( node . tagName . toUpperCase ( ) !== 'TABLE' ) { node = node . parentElement ; } return $ ( node ) ; } let html = '' ; let ppanel ; if ( ! ix . panel ) { ix . panel = { headers : { } , lastid : 1 } ; ix . panel . panel = brk . WorkspaceManager . createBottomPanel ( '' , $ ( ix . htmltempl . BOTTOMPANEL ) ) ; ppanel = ix . panel . panel ; ix . panel . $msg = ppanel . $panel . find ( '#msg' ) ; ppanel . $panel . find ( '.close' ) . click ( ( ) => { ix . panel . panel . hide ( ) ; } ) ; ppanel . $panel . find ( '#cleartoix' ) . click ( ( ) => { ix . panel . $msg . html ( '' ) ; ix . panel . headers = { } ; } ) ; } let headerId = ix . panel . headers [ header ] ; if ( headerId ) { ix . panel . $msg . find ( '#' + headerId ) . remove ( ) ; } headerId = ix . panel . lastid ; ix . panel . headers [ header ] = headerId ; ix . panel . lastid ++ ; html = brk . Mustache . render ( ix . htmltempl . BOTTOMPANELITEMHEAD , { id : headerId , header } ) ; msgArray . forEach ( ( msg ) => { html += '<tr><td>' + tools . htmlEscape ( msg ) + '</td></tr>' ; } ) ; html += '</table>' ; ix . panel . $msg . html ( html + ix . panel . $msg . html ( ) ) ; ix . panel . $msg . find ( '#cleartoix' ) . click ( ( event ) => { const $table = getTableFromEvent ( event ) ; $table . remove ( ) ; } ) ; ix . panel . $msg . find ( '#copytoix' ) . click ( ( event ) => { const $table = getTableFromEvent ( event ) ; const output = [ ] ; $table . find ( 'td' ) . each ( ( index , el ) => { output . push ( $ ( el ) . text ( ) ) ; } ) ; clipbrdCopy ( output . join ( '' ) ) ; } ) ; if ( ! ix . panel . panel . isVisible ( ) ) { ix . panel . panel . show ( ) ; } } function nodeOpenUrl ( url ) { appshell . app . openURLInDefaultBrowser ( url ) ; } function displayNodeResult ( _callSuccess , out , name ) { function send ( tag_ , start , end ) { const arr = out . slice ( start , end ) ; if ( arr . length && ! arr [ arr . length - 1 ] . trim ( ) ) { arr . splice ( arr . length - 1 , 1 ) ; } if ( arr . length ) { sendToBottomPanel ( tag_ + name , arr ) ; } } out = out . split ( /\n/ ) ; const stdOutLen = out [ 1 ] >> 0 ; out . splice ( 0 , 2 ) ; send ( '' , 0 , stdOutLen - 1 ) ; send ( '[stderr] ' , stdOutLen , out . length ) ; } function nodeExec ( cmdLine , cwd , name , toShowOutput , toShowStdErr , fileParams ) { let root ; const replList = [ ] ; function addRepl ( list , prefix , filename , root_ ) { const parts = filename . match ( /^(.*)\/([^\/]*)$/ ) ; const relFile = filename . indexOf ( root_ ) === 0 ? filename . substr ( root_ . length ) : filename ; list . push ( [ prefix , filename ] ) ; list . push ( [ prefix + 'file' , parts ? parts [ 2 ] : '' ] ) ; list . push ( [ prefix + 'path' , parts ? parts [ 1 ] : '' ] ) ; list . push ( [ prefix + 'relfile' , relFile ] ) ; } if ( fileParams ) { root = getProjectRoot ( ) ; Object . keys ( fileParams ) . forEach ( ( key ) => { addRepl ( replList , key , fileParams [ key ] , root ) ; } ) ; replList . forEach ( ( macro ) => { cmdLine = cmdLine . replace ( '{{' + macro [ 0 ] + '}}' , macro [ 1 ] ) ; } ) ; } ixDomains . exec ( 'exec' , cmdLine , cwd ) . fail ( ( out ) => { if ( toShowStdErr ) { displayNodeResult ( false , out , name ) ; } } ) . done ( ( out ) => { if ( toShowOutput ) { displayNodeResult ( true , out , name ) ; } } ) ; } function buildDlgTitle ( title ) { return brk . Mustache . render ( ix . htmltempl . DLGTITLE , { root : brk . moduleroot , title , social : brk . Mustache . render ( ix . htmltempl . SOCIAL , SOCIAL ) , } ) ; } function handleSocial ( _$dlg ) { } function ask ( title , cmd , fieldList , callback , opts ? , fields ? ) { return ui . ask ( buildDlgTitle ( title || cmd . cleanlabel ) , cmd ? cmd . storeid : '' , fieldList , callback , opts , fields || prefs , opts && opts . nosaveprefs ? undefined : saveExtPrefs , prefs . historySize . value , i18n , brk , handleSocial ) ; } function showMessage ( title , message ) { brk . Dialogs . showModalDialog ( 'bracketstoix-dialog' , buildDlgTitle ( i18n ( title ) ) , message , [ { className : brk . Dialogs . DIALOG_BTN_CLASS_PRIMARY , id : brk . Dialogs . DIALOG_BTN_OK , text : brk . CoreStrings . CLOSE , } ] , true ) ; } function splitText ( cmd ) { ask ( '' , cmd , [ 'splitMarker' ] , ( ) => { changeSelectionRegEx ( new RegExp ( tools . processSplit ( prefs . splitMarker . value ) , 'g' ) , '\n' , SP_ALL ) ; } ) ; } function numberText ( cmd ) { ask ( '' , cmd , [ 'startNum' , 'numSep' ] , ( ) => { let num = prefs . startNum . value ; const numSep = tools . getSpaceText ( prefs . numSep . value ) ; changeSelectionRegEx ( /^(.*)$/gm , ( _match , p1 ) => ( num ++ ) + numSep + p1 , SP_ALL ) ; } ) ; } function trimLeading ( ) { changeSelectionRegEx ( /^[ \t]+/gm , '' , SP_ALL ) ; } function trimTrailingex ( selPolicy ) { changeSelectionRegEx ( /[ \t]+$/gm , '' , selPolicy ) ; } function trimTrailing ( ) { trimTrailingex ( SP_ALL ) ; } function markdownTrimTrailing ( ) { changeSelectionRegEx ( /[ \t]+$/gm , '  ' , SP_ALL ) ; } function sortAscending ( ) { sortSelection ( ( a , b ) => a > b ? 1 : ( a < b ? - 1 : 0 ) , SP_ALL ) ; } function sortDescending ( ) { sortSelection ( ( a , b ) => a < b ? 1 : ( a > b ? - 1 : 0 ) , SP_ALL ) ; } function tabToSpace ( ) { changeSelectionRegEx ( /\t/gm , tools . strRepeat ( ' ' , prefs . tabSize . value ) , SP_ALL ) ; } function spaceToTab ( ) { changeSelectionRegEx ( /^(\s+)/gm , ( spaces ) : string => { const len = spaces . length ; const tabs = Math . floor ( len / prefs . tabSize . value ) ; return ! tabs ? spaces : tools . strRepeat ( "\t" , tabs ) + tools . strRepeat ( ' ' , len - tabs * prefs . tabSize . value ) ; } , SP_ALL ) ; } function regnize ( ) { getSelection ( ( text ) : void => { clipbrdCopy ( getRegnize ( text , true ) ) ; } , SP_SENTENCE ) ; } function rgbHex ( ) { changeSelectionRegEx ( /(?:#([a-f0-9]{2,2})([a-f0-9]{2,2})([a-f0-9]{2,2}))|(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/ig , ( text , h1 , h2 , h3 , r1 , r2 , r3 ) => { function toHex2 ( v ) { const res = parseInt ( v , 10 ) . toString ( 16 ) ; return res . length < 2 ? '0' + res : res ; } if ( h1 === undefined ) { return '#' + toHex2 ( r1 ) + toHex2 ( r2 ) + toHex2 ( r3 ) ; } else { return 'rgb(' + parseInt ( h1 , 16 ) + ', ' + parseInt ( h2 , 16 ) + ', ' + parseInt ( h3 , 16 ) + ')' ; } } , SP_SENTENCE ) ; } function untag ( ) { changeSelectionRegEx ( /<(\w+)(?:.*?)>(.*?)<\/(\1)\s*>/ , "$2" , ( inf , ch ) => { if ( inf . stop ) { inf . stop = false ; return false ; } inf . stop = ch === ( inf . dir === - 1 ? '<' : '>' ) ; return true ; } ) ; } function tag ( ) { changeSelection ( ( text , so ) => { let tagname ; function getAttr ( ch , prefix ) { let attr = tagname . split ( ch ) ; if ( attr . length > 1 ) { tagname = attr [ 0 ] ; attr . splice ( 0 , 1 ) ; attr = ' ' + prefix + '="' + attr . join ( ' ' ) + '"' ; } else { attr = '' ; } return attr ; } let id ; let cls ; let at ; let base ; let removelen ; let tokens ; tokens = text . match ( /^(\s*)(\b.*\b)(\s*)$/ ) ; if ( ! tokens ) { return ; } tagname = tokens [ 2 ] . split ( ' ' , 1 ) [ 0 ] ; removelen = tagname . length + 1 ; text = text . substr ( removelen ) . trim ( ) ; cls = getAttr ( '.' , 'class' ) ; id = getAttr ( '#' , 'id' ) ; at = EXPAND_TAGS . indexOf ( ';' + tagname + '=' ) ; if ( at !== - 1 ) { tagname = EXPAND_TAGS . substr ( at + tagname . length + 2 ) . split ( ';' , 1 ) [ 0 ] ; } base = '<' + tagname + id + cls + '>' ; if ( so . start ) { so . cursor = { ch : so . start . ch + base . length , line : so . start . line , } ; } return tokens [ 1 ] + base + text + '</' + tagname + '>' + tokens [ 3 ] ; } , SP_SENTENCE ) ; } function declJSLintGlobal ( ) { getSelection ( ( ident , so ) => { let row = 0 ; const max = so . cm . lineCount ( ) ; let line ; let trimline ; let tokens ; let identlist ; let trimidentlist ; function coreProcess ( regMatch ) { line = so . cm . getLine ( row ) ; tokens = null ; trimidentlist = null ; trimline = line . trim ( ) ; if ( trimline ) { tokens = line . match ( regMatch ) ; if ( tokens ) { if ( tokens . length > 1 ) { identlist = tokens [ 1 ] ; if ( identlist . replace ( / /g , '' ) . split ( ',' ) . indexOf ( ident ) > - 1 ) { return null ; } trimidentlist = identlist . trim ( ) ; } } } return true ; } ident = ident . trim ( ) ; if ( ! ident ) { return ; } while ( row < max ) { line = so . cm . getLine ( row ) ; trimline = line . trim ( ) ; if ( ! coreProcess ( /^\s*\/\*\s*global\s*(.*?)\s*(\*\/){0,1}\s*$/ ) ) { return ; } if ( trimline ) { if ( tokens ) { if ( tokens . length > 1 ) { while ( trimidentlist [ trimidentlist . length - 1 ] === ',' ) { row ++ ; if ( row === max || ! coreProcess ( /^\s*(.*?)\s*(\*\/){0,1}\s*$/ ) || ! trimline || tokens . length <= 1 ) { return ; } } setRow ( row , line . replace ( identlist , identlist + ', ' + ident ) , so ) ; } else { setRow ( row , line . replace ( 'global' , 'global ' + ident ) , so ) ; } return ; } else { if ( trimline [ 0 ] !== '/' && trimline [ 0 ] !== '*' ) { insertRow ( row , '/*global ' + ident + ' */' , so ) ; break ; } } } row ++ ; } } , SP_WORD ) ; } const Q_SINGLE = 0 ; const Q_DOUBLE = 1 ; const Q_TOGGLE = 2 ; function quoteOp ( op ) { changeSelection ( ( text ) => { const arr = text . split ( '' ) ; let isin = false ; let i ; let ch ; for ( i = 0 ; i <= arr . length ; i ++ ) { ch = arr [ i ] ; switch ( ch ) { case "'" : if ( ( op === Q_SINGLE ) || ( op === Q_TOGGLE ) ) { arr [ i ] = '"' ; isin = ! isin ; } break ; case '"' : if ( ( op === Q_DOUBLE ) || ( op === Q_TOGGLE ) ) { arr [ i ] = "'" ; isin = ! isin ; } break ; } } return arr . join ( '' ) ; } , ( inf , ch ) => { if ( inf . stop ) { inf . stop = false ; return false ; } if ( ( ch === "'" || ch === '"' ) && ( ch === inf . quote || ! inf . quote ) ) { inf . stop = true ; inf . quote = ch ; } return true ; } ) ; } function singleToDoubleQuote ( ) { quoteOp ( Q_SINGLE ) ; } function doubleToSingleQuote ( ) { quoteOp ( Q_DOUBLE ) ; } function toggleQuote ( ) { quoteOp ( Q_TOGGLE ) ; } function openUrl ( ) { getSelection ( ( text ) => { if ( ! prefs . checkForHttp ( text ) ) { text = 'http://' + text ; } nodeOpenUrl ( text ) ; } , SP_SENTENCE ) ; } function webSearch ( ) { getSelection ( ( text ) => { nodeOpenUrl ( prefs . webSearch . value + encodeURIComponent ( text ) ) ; } , SP_SENTENCE ) ; } function browseFile ( ) { nodeOpenUrl ( 'file:///' + getCurFileName ( ) ) ; } function extractortoix ( cmd ) { ask ( '' , cmd , [ 'findre' , 'splitMarkerExtr' , 'isignorecase' ] , ( ) => { getSelection ( ( text ) => { const foundtext = [ ] ; const spliter = tools . processSplit ( prefs . splitMarkerExtr . value ) ; text . replace ( new RegExp ( prefs . findre . value , 'g' + ( prefs . isignorecase . value ? 'i' : '' ) ) , ( ) => { const record = [ ] ; let i = 1 ; if ( arguments && arguments . length ) { if ( typeof arguments [ 1 ] === 'number' ) { foundtext . push ( arguments [ 0 ] ) ; } else { while ( typeof arguments [ i ] !== 'number' ) { record . push ( arguments [ i ] ) ; i ++ ; } foundtext . push ( record . join ( spliter ) ) ; } } return arguments ? arguments [ 0 ] : '' ; } ) ; if ( foundtext . length ) { clipbrdCopy ( foundtext . join ( '\n' ) ) ; } else { showMessage ( '' , brk . CoreStrings . FIND_NO_RESULTS ) ; } } , SP_ALL ) ; } , { msg : i18n ( 'EXTRACTOR_MSG' ) , } ) ; } function replacetoix ( cmd ) { const text = getSelObj ( SP_LINE ) . cursel . split ( '\n' ) ; prefs . find . value = text . length > 0 ? text [ 0 ] . trim ( ) : '' ; prefs . replace . value = '' ; ask ( '' , cmd , [ 'find' , 'replace' , 'startValue' , 'stepValue' , 'iswordsonly' , 'isregexpr' , 'isignorecase' , 'isimultiline' , 'isall' , 'isselonly' , ] , ( ) => { let findtext = prefs . isregexpr . value ? prefs . find . value : getRegnize ( prefs . find . value , true ) ; const repltext = prefs . isregexpr . value ? prefs . replace . value : getRegnize ( prefs . replace . value , false ) ; let startValue = prefs . startValue . value ? parseInt ( prefs . startValue . value , 10 ) : undefined ; const stepValue = prefs . stepValue . value ? parseInt ( prefs . stepValue . value , 10 ) : undefined ; if ( prefs . iswordsonly . value && ! prefs . isregexpr . value ) { findtext = '\\b' + findtext + '\\b' ; } changeSelectionRegEx ( new RegExp ( findtext , ( prefs . isall . value ? 'g' : '' ) + ( prefs . isignorecase . value ? 'i' : '' ) + ( prefs . isimultiline . value ? 'm' : '' ) ) , ( startValue !== undefined ) && ( stepValue !== undefined ) ? ( ) => { let out = repltext ; for ( let i = 1 ; i < arguments . length - 2 ; i ++ ) { out = out . replace ( new RegExp ( '\\$' + i , 'g' ) , arguments [ i ] ) ; } out = out . replace ( /(\#\{(0*)(\d*)(\w+)\}\#)/ , ( str , pall , pzero , pdigit , pmacro ) => { function formatvalue ( pzero_ , pdigit_ , value ) { const prefix = [ ] ; value = value + '' ; if ( ! pdigit_ ) { return value ; } pdigit_ = pdigit_ >> 0 ; if ( value . length > pdigit_ ) { return value ; } prefix . length = pdigit_ + 1 - value . length ; return prefix . join ( pzero_ ? '0' : ' ' ) + value ; } switch ( pmacro ) { case 'd' : return formatvalue ( pzero , pdigit , startValue ) ; case 'X' : return formatvalue ( pzero , pdigit , startValue . toString ( 16 ) . toUpperCase ( ) ) ; case 'x' : return formatvalue ( pzero , pdigit , startValue . toString ( 16 ) ) ; default : return pall ; } } ) ; startValue += stepValue ; return out ; } : repltext , prefs . isselonly . value ? SP_ALL : SP_FORCE_ALL ) ; } ) ; } function buildFuncJSDoc ( ) { getSelection ( ( text , so ) => { const match = text . match ( /(?:(\w+)\s*[:=]\s*){0,1}function(?:\s+(\w+)){0,1}\s*\((.*?)\)/i ) ; let func ; let initialspace ; if ( match && match . length > 1 ) { func = match [ 1 ] || match [ 2 ] ; if ( ! func ) { return ; } const vars = match [ 3 ] ; initialspace = text . match ( /^\s*/i ) [ 0 ] ; let jsdoc = '|/**\n' + ( func [ 0 ] === '_' ? '|* @private\n' : '' ) + '|* ' + func + '\n' ; if ( vars ) { vars . split ( ',' ) . forEach ( ( v ) => { jsdoc += '|* @param {} ' + v . trim ( ) + '\n' ; } ) ; } jsdoc += '|* @return {} \n' ; jsdoc += '|*/\n' ; jsdoc = jsdoc . replace ( /\|/g , initialspace ) ; so . cm . replaceRange ( jsdoc , so . start , so . start ) ; } } , SP_FORCE_LINE ) ; } function execBreakLineAt ( line , maxChars , toBreakWords ) { let start = 0 ; let at ; let stest ; while ( start + maxChars < line . length ) { at = start + maxChars ; if ( ! toBreakWords ) { stest = line . substring ( start , at ) . replace ( /[\w_]/g , '0' ) ; for ( at -= start ; at > 0 && stest [ at - 1 ] === '0' ; at -- ) { } if ( ( ! at ) && ( stest [ 0 ] === '0' ) ) { at = maxChars ; } at += start ; } line = line . substr ( 0 , at ) + '\n' + line . substr ( at ) ; start = at + 1 ; } return line ; } function breakLineAt ( cmd ) { ask ( '' , cmd , [ 'maxcharsperline' , 'tobreakwords' ] , ( ) => { const maxchars = Math . max ( 1 , prefs . maxcharsperline . value . trim ( ) >> 0 ) ; const toBreakWords = prefs . tobreakwords . value ; changeSelection ( ( array , so ) => { array . forEach ( ( line , index ) => { array [ index ] = execBreakLineAt ( line , maxchars , toBreakWords ) ; } ) ; return array ; } , SP_LINE , true ) ; } ) ; } function loremIpsum ( cmd ) { $ . get ( brk . moduleroot + 'lorem.txt' , ( data ) => { ask ( '' , cmd , [ 'linrparagraphs' , 'limaxcharsperline' , 'lihtmlparawrap' ] , ( ) => { changeSelection ( ( text , so ) => { const lines = data . split ( '\n' , Math . min ( 100 , Math . max ( prefs . linrparagraphs . value >> 0 ) ) ) ; const wrap = prefs . lihtmlparawrap . value . trim ( ) ; const wrapst = '<' + wrap + '>' ; const wrapend = '</' + wrap . replace ( /\s.+$/ , '' ) + '>' ; const maxchars = prefs . limaxcharsperline . value >> 0 ; lines . forEach ( ( line , index ) => { if ( maxchars ) { line = execBreakLineAt ( line , maxchars , false ) ; } if ( wrap ) { line = wrapst + line + wrapend ; } lines [ index ] = line ; } ) ; return lines . join ( '\n' ) ; } , SP_NONE ) ; } ) ; } ) ; } function fileToClipboard ( ) { copyToClipboard ( ( curfile ) => { return curfile . _name || curfile . name ; } ) ; } function fullnameToClipboard ( ) { copyToClipboard ( ( curfile ) => { const fullname = curfile . _path || curfile . path ; return brackets . platform === 'win' ? fullname . replace ( /\//g , "\\" ) : fullname ; } ) ; } function buidHtmlReport ( ) { getSelection ( ( text ) => { let outp = [ ] ; [ [ 'link rel="stylesheet" href' , 'stylesheet' , true ] , [ 'id' ] , [ 'class' ] , ] . forEach ( ( item ) => { const token = item [ 0 ] ; const list = [ ] ; let i ; text . replace ( new RegExp ( token + '=(?:(\\w+)|(?:"(.+?)"))' , 'gi' ) , ( data , p1 , p2 ) => { list . push ( p1 || p2 ) ; return data ; } ) ; if ( ! item [ 2 ] ) { list . sort ( ) ; } for ( i = list . length ; i > 0 ; i -- ) { if ( list [ i ] === list [ i - 1 ] ) { list . splice ( i , 1 ) ; } } outp . push ( '[' + ( item [ 1 ] || token ) + ']' ) ; outp = outp . concat ( list ) ; outp . push ( '' ) ; } ) ; clipbrdCopy ( outp . join ( '\n' ) ) ; } , SP_ALL ) ; } function runExecute ( cmd ) { const fields = { cmdline : { value : '' , label : 'FLD_Cmdline_label' , } , tools : { value : '' , canempty : true , type : 'dropdown' , values : [ '' ] , label : 'CAT_Tools' , events : [ { name : 'change' , f ( inf ) { let idx ; let tool ; idx = ( inf . $dlg . find ( '#toixtools' ) [ 0 ] . selectedIndex >> 0 ) - 1 ; if ( idx >= 0 ) { tool = prefs . tools . value [ idx ] ; inf . $dlg . find ( '#toixcmdline' ) . val ( tool . cmdline ) ; inf . $dlg . find ( '#toixshowoutput' ) . get ( 0 ) . checked = tool . showoutput ; } } , } ] , } , path : { value : getProjectRoot ( ) , label : 'FLD_Path_label' , } , showoutput : { value : true , type : 'boolean' , label : 'FLD_ShowOutput_label' , canempty : true , } , } ; prefs . tools . value . forEach ( ( tool ) => { fields . tools . values . push ( tool . name ) ; } ) ; ask ( '' , cmd , [ 'cmdline' , 'path' , 'tools' , 'showoutput' ] , ( ) => { const cmdline = fields . cmdline . value ; nodeExec ( cmdline , getProjectRoot ( ) , cmdline , fields . showoutput . value , true , { in : getCurFileName ( ) } ) ; } , { nosaveprefs : true , } , fields ) ; } function runCompilerEx ( toAutoSave , filename ? ) { const exts = [ { inext : '.js6' , outext : '.js' , } , { inext : '.scss' , outext : '.css' , } , { inext : '.js' , outext : '.min.js' , } ] ; const infile = filename || getCurFileName ( ) ; let outfile ; let ext ; let pref ; for ( let i = 0 ; i < exts . length ; i ++ ) { ext = exts [ i ] ; if ( checkExt ( infile , ext . inext ) ) { pref = prefs [ ext . inext . substr ( 1 ) ] ; if ( pref . value && ( ( pref . fields && pref . fields . autosave && pref . fields . autosave . value ) || ! toAutoSave ) ) { outfile = infile . substr ( 0 , infile . length - ext . inext . length ) + ext . outext ; nodeExec ( pref . value , getProjectRoot ( ) , 'Compile ' + infile , false , true , { in : infile , out : outfile } ) ; break ; } } } } function runCompiler ( ) { runCompilerEx ( false ) ; } function handleDocumentChanged ( event , doc ) { let file ; let idx ; let recentFiles ; applyEditorProjSettings ( projSettings . data ) ; if ( doc && doc . file && doc . file . _isFile ) { file = doc . file . _path ; if ( file . indexOf ( '/_brackets_' ) === - 1 ) { recentFiles = prefs . recentFiles . files ; idx = recentFiles . indexOf ( file ) ; if ( idx === - 1 ) { recentFiles . splice ( 0 , 0 , file ) ; if ( recentFiles . length > prefs . recentSize . value ) { recentFiles . length = prefs . recentSize . value ; } } else { recentFiles . splice ( idx , 1 ) ; recentFiles . splice ( 0 , 0 , file ) ; } saveExtPrefs ( ) ; } } } function showRecentFiles ( cmd ) { const rf = prefs . recentFiles ; let rlen ; rf . value = '' ; rf . values = [ ] ; const root = getProjectRoot ( ) ; rlen = root . length ; rf . files . forEach ( ( file ) => { if ( file . substr ( 0 , rlen ) === root ) { file = file . substr ( rlen ) ; } rf . values . push ( file ) ; } ) ; ask ( '' , cmd , [ 'recentFiles' ] , ( ) => { const rf_ = prefs . recentFiles ; brk . CommandManager . execute ( brk . Commands . CMD_ADD_TO_WORKINGSET_AND_OPEN , { fullPath : rf_ . files [ rf_ . values . indexOf ( rf_ . value ) ] , silent : true , options : { paneId : brk . MainViewManager . ACTIVE_PANE , } , } ) ; } , { nosaveprefs : true , } ) ; } function showHelp ( ) { nodeOpenUrl ( HELP_LINK ) ; } function showAbout ( cmd ) { showMessage ( cmd . cleanlabel , brk . Mustache . render ( ix . htmltempl . ABOUTTEXT , { helplink : HELP_LINK , version : VERSION , devby : brk . StringUtils . format ( brk . Strings . DEVBY_MSG , AUTHOR ) , } ) ) ; } function showOptions ( cmd ) { optstoix . prepare ( prefs , namedcmdlist , ix , tools , projSettings ) ; ask ( '' , cmd , prefs . OPTIONFIELDS , undefined , { dlgtemplate : optshtml , handler : optstoix , setSpaceUnits ( aProjSetsData , enabled ) { if ( enabled ) { aProjSetsData . useTabChar = brk . Editor . getUseTabChar ( ) ; aProjSetsData . spaceUnits = brk . Editor . getSpaceUnits ( ) ; aProjSetsData . tabSize = brk . Editor . getTabSize ( ) ; } else { delete aProjSetsData [ 'useTabChar' ] ; delete aProjSetsData [ 'spaceUnits' ] ; delete aProjSetsData [ 'tabSize' ] ; } } , saveProjSettings ( aProjSetsData ) { brk . FileUtils . writeText ( brk . FileSystem . getFileForPath ( getProjectRoot ( ) + PROJ_SETTINGS_FILE ) , JSON . stringify ( aProjSetsData , null , ' ' ) ) ; } , } ) ; } function showCommands ( cmd ) { const fields = { cmd : { value : '' , type : 'dropdown' , values : namedcmdlist . map ( cmd_ => cmd_ . cleanlabel ) , } , } ; fields . cmd . values . sort ( ) ; ask ( '' , cmd , [ 'cmd' ] , ( ) => { const selcmd = fields . cmd . value ; namedcmdlist . every ( ( cmd_ ) => { if ( selcmd === cmd_ . cleanlabel ) { runCommand ( cmd_ ) ; return false ; } return true ; } ) ; } , { nosaveprefs : true , } , fields ) ; } function showCommandMapper ( cmd ) { const fields = { } ; const fieldlist = [ ] ; let showinmenu = prefs . commands . value . showinmenu ; let showinctxmenu = prefs . commands . value . showinctxmenu ; let hotkeys = prefs . commands . value . hotkeys ; namedcmdlist . forEach ( ( cmd_ ) => { const key = cmd_ . storeid ; fields [ key ] = { value : hotkeys [ key ] || '' , label : cmd_ . cleanlabel , size : 15 , canempty : true , hint : i18n ( 'SHORTCUT_HINT' ) , fields : { showinmenu : { value : showinmenu . indexOf ( key ) > - 1 , type : 'boolean' , align : 'center' , canempty : true , } , showinctxmenu : { value : showinctxmenu . indexOf ( key ) > - 1 , type : 'boolean' , align : 'center' , canempty : true , } , } , } ; fieldlist . push ( key ) ; } ) ; ask ( '' , cmd , fieldlist , ( ) => { showinmenu = [ ] ; showinctxmenu = [ ] ; hotkeys = { } ; namedcmdlist . forEach ( ( cmd_ ) => { const key = cmd_ . storeid ; const field = fields [ key ] ; if ( field . value ) { hotkeys [ key ] = field . value . replace ( /\b(Cmd|Shift|Alt|Ctrl|\w)\b/gi , ( txt , p1 ) => p1 [ 0 ] . toUpperCase ( ) + p1 . substr ( 1 ) . toLowerCase ( ) ) . replace ( /\+/g , '-' ) ; } if ( field . fields . showinmenu . value ) { showinmenu . push ( key ) ; } if ( field . fields . showinctxmenu . value ) { showinctxmenu . push ( key ) ; } } ) ; prefs . commands . value . showinmenu = showinmenu ; prefs . commands . value . showinctxmenu = showinctxmenu ; prefs . commands . value . hotkeys = hotkeys ; saveExtPrefs ( ) ; } , { nosaveprefs : true , msg : i18n ( 'NEED_RESTART_MSG' ) , header : [ 'Command' , 'Hotkey' , 'Show on Menu' , 'Show on CtxMenu' ] , } , fields ) ; } function runLanguageMapper ( ) { const lang = brk . LanguageManager . getLanguage ( 'javascript' ) ; lang . addFileExtension ( 'js6' ) ; } const SHOWONMENU = 1 ; function initCommandList ( ) { cmdlist = [ { name : 'UpperCase' , f : transformutilities . upperCase , priority : SHOWONMENU , canonsave : true } , { name : 'LowerCase' , f : transformutilities . lowerCase , priority : SHOWONMENU , canonsave : true } , { name : 'Capitalize' , f : transformutilities . capitalize , priority : SHOWONMENU , canonsave : true } , { name : 'CamelCase' , f : transformutilities . camelCase , priority : SHOWONMENU } , { name : 'DashCase' , f : transformutilities . dashCase , priority : SHOWONMENU } , { name : 'CycleCase' , f : transformutilities . cycleCase , priority : SHOWONMENU } , { name : 'spaceByUpper' , f : transformutilities . spaceByUpper } , { name : 'HtmlEncode' , f : transformutilities . htmlEncode , priority : SHOWONMENU } , { name : 'HtmlDecode' , f : transformutilities . htmlDecode , priority : SHOWONMENU } , { name : 'UrlEncode' , f : transformutilities . urlEncode , priority : SHOWONMENU } , { name : 'UrlDecode' , f : transformutilities . urlDecode , priority : SHOWONMENU } , { name : 'Join' , f : transformutilities . joinText , priority : SHOWONMENU } , { name : 'Split...' , f : splitText , priority : SHOWONMENU } , { name : 'Number...' , f : numberText , priority : SHOWONMENU } , { name : 'Reverse' , f : transformutilities . reverseAssignment , priority : SHOWONMENU } , { name : 'Trim Leading' , f : trimLeading , priority : SHOWONMENU , canonsave : true } , { name : 'Trim Trailing' , f : trimTrailing , priority : SHOWONMENU , canonsave : true } , { name : 'Markdown Trim Trailing' , f : markdownTrimTrailing , priority : SHOWONMENU , canonsave : true } , { name : 'Sort Ascending' , f : sortAscending , priority : SHOWONMENU , canonsave : true } , { name : 'Sort Descending' , f : sortDescending , priority : SHOWONMENU , canonsave : true } , { name : 'Remove Duplicates' , f : lineutilities . removeDuplicatedLines , priority : SHOWONMENU , canonsave : true } , { name : 'Remove Empty Lines' , f : lineutilities . removeEmptyLines , priority : SHOWONMENU , canonsave : true } , { name : 'Indent One Space' , f : lineutilities . indentOneSpace , canonsave : true } , { name : 'Outdent One Space' , f : lineutilities . outdentOneSpace , canonsave : true } , { } , { name : 'Unix To Win' , f : transformutilities . unixToWinSlash , priority : SHOWONMENU , canonsave : true } , { name : 'Win To Unix' , f : transformutilities . winToUnixSlash , priority : SHOWONMENU , canonsave : true } , { name : 'Single Slash To Double' , f : transformutilities . singleToDoubleSlash , priority : SHOWONMENU } , { name : 'Double To Single Slash' , f : transformutilities . doubleToSingleSlash , priority : SHOWONMENU } , { name : 'Single Quote To Double' , f : singleToDoubleQuote , priority : SHOWONMENU } , { name : 'Double To Single Quote' , f : doubleToSingleQuote , priority : SHOWONMENU } , { name : 'Toggle Quote' , f : toggleQuote , priority : SHOWONMENU } , { name : 'Tab To Space' , f : tabToSpace , priority : SHOWONMENU , canonsave : true } , { name : 'Space To Tab' , f : spaceToTab , priority : SHOWONMENU , canonsave : true } , { name : 'rgb-hex' , f : rgbHex , priority : SHOWONMENU } , { name : 'Untag' , f : untag , priority : SHOWONMENU } , { name : 'Tag' , f : tag , priority : SHOWONMENU } , { menu : 1 } , { name : 'Break Line At...' , f : breakLineAt , priority : SHOWONMENU } , { name : 'Lorem ipsum...' , f : loremIpsum , priority : SHOWONMENU } , { name : 'Function JSDoc' , f : buildFuncJSDoc , priority : SHOWONMENU } , { name : 'Declare JSLint Global' , f : declJSLintGlobal , priority : SHOWONMENU } , { } , { name : 'ExtractortoIX...' , f : extractortoix , priority : SHOWONMENU } , { name : 'ReplacetoIX...' , f : replacetoix , priority : SHOWONMENU } , { } , { name : 'Open Url' , f : openUrl , priority : SHOWONMENU } , { name : 'Web Search' , f : webSearch , priority : SHOWONMENU } , { name : 'Browse File' , f : browseFile , priority : SHOWONMENU } , { } , { name : 'Recent Files...' , f : showRecentFiles , priority : SHOWONMENU } , { name : 'Copy Filename' , f : fileToClipboard , priority : SHOWONMENU } , { name : 'Copy Fullname' , f : fullnameToClipboard , priority : SHOWONMENU } , { name : 'Regnize' , f : regnize , priority : SHOWONMENU } , { name : 'Html Report' , f : buidHtmlReport , priority : SHOWONMENU } , { } , { name : 'Compiler' , f : runCompiler , priority : SHOWONMENU } , { name : 'Execute' , f : runExecute , showalways : true , priority : SHOWONMENU , toolinsertpoint : true } , { } , { name : 'Commands...' , f : showCommands , priority : SHOWONMENU } , { name : 'Commands Mapper...' , f : showCommandMapper , showalways : true , priority : SHOWONMENU } , { name : 'Options...' , f : showOptions , priority : SHOWONMENU } , { name : 'About' , f : showAbout , corelabel : 'ABOUT' , showalways : true , priority : SHOWONMENU } , ] ; cmdlist . forEach ( ( cmd ) => { if ( cmd . name ) { namedcmdlist . push ( cmd ) ; } } ) ; namedcmdlist . forEach ( ( cmd ) => { const txt = cmd . name ; const fullen = txt . length ; let len = fullen ; let lab ; if ( cmd . corelabel ) { lab = brk . CoreStrings [ cmd . corelabel ] ; } else { while ( txt [ len - 1 ] === '.' ) { len -- ; } if ( txt . substr ( len - 4 , 4 ) === 'toIX' ) { len -= 4 ; } lab = brk . Strings [ txt . substr ( 0 , len ) ] ; if ( lab ) { lab += txt . substr ( len ) ; } } cmd . label = lab || txt ; cmd . cleanlabel = cmd . label . replace ( /\./g , '' ) ; cmd . storeid = tools . textToID ( cmd . name ) ; storeidmap [ cmd . storeid ] = cmd ; } ) ; } function runCommand ( cmd , isglobal ? ) { if ( ( isglobal !== undefined ) === ( globalDoc !== null ) ) { cmd . f ( cmd ) ; } } function registerCommand ( cmd , id ) { brk . CommandManager . register ( cmd . label , id , ( ) => { runCommand ( cmd ) ; } ) ; } function registerToolCommand ( tool , id ) { brk . CommandManager . register ( tool . name , id , ( ) => { nodeExec ( tool . cmdline , getProjectRoot ( ) , tool . cmdline , tool . showoutput , true , { in : getCurFileName ( ) } ) ; } ) ; } function runEditCmd ( cmd ) { const so = getSelObj ( SP_NONE ) ; if ( cmd === 'CMD_PASTE' ) { setSelection ( so , clipbrdPaste ( ) ) ; } if ( so . cursel ) { clipbrdCopy ( so . cursel ) ; if ( cmd === 'CMD_CUT' ) { setSelection ( so , '' ) ; } } } function registerEditCtxCommand ( cmd , label , id ) { brk . CommandManager . register ( label , id , ( ) => { runEditCmd ( cmd ) ; } ) ; } function addEditCmdsToLocalMenu ( ctxMenu ) { const EDIT_CMDS = [ 'CMD_CUT' , 'CMD_COPY' , 'CMD_PASTE' ] ; if ( ! prefs . showcxtedit . value ) { return ; } for ( let i = 0 ; i < EDIT_CMDS . length ; i ++ ) { const cmd = EDIT_CMDS [ i ] ; const id = MODULE_NAME + "." + tools . textToID ( cmd ) ; registerEditCtxCommand ( cmd , brk . CoreStrings [ cmd ] , id ) ; ctxMenu . addMenuItem ( id , [ ] ) ; } } function addToolCommands ( menu ) { prefs . tools . value . forEach ( ( tool , index ) => { let id ; if ( tool . showonmenu ) { id = MODULE_NAME + ".TOOL." + index ; registerToolCommand ( tool , id ) ; menu . addMenuItem ( id , [ ] ) ; } } ) ; } function buildCommands ( ) { function addToMenu ( cmd_ , menu , lastId , nm_ , hotkeys_ ) { let opts ; let hotkey ; const id = MODULE_NAME + "." + cmd_ . storeid ; if ( id !== lastId ) { registerCommand ( cmd_ , id ) ; } opts = [ ] ; hotkey = hotkeys_ [ nm_ ] ; if ( hotkey ) { opts . push ( { key : hotkey , platform : brackets . platform , } ) ; } menu . addMenuItem ( id , opts ) ; return id ; } let menuidx = 0 ; const Menus = brackets . getModule ( 'command/Menus' ) ; const menulist = [ Menus . addMenu ( IX_MENU_TT , tools . textToID ( IX_MENU_TT ) ) , Menus . addMenu ( IX_MENU , tools . textToID ( IX_MENU ) ) ] ; const ctxmenu = Menus . getContextMenu ( Menus . ContextMenuIds . EDITOR_MENU ) ; let i ; let cmd ; let nm ; let lastid ; const showinmenu = prefs . commands . value . showinmenu ; const showinctxmenu = prefs . commands . value . showinctxmenu ; const hotkeys = prefs . commands . value . hotkeys ; let hasdiv = false ; for ( i = 0 ; i < cmdlist . length ; i ++ ) { cmd = cmdlist [ i ] ; if ( ! cmd . name ) { if ( cmd . menu ) { menuidx = cmd . menu ; } else { if ( ! hasdiv ) { menulist [ menuidx ] . addMenuDivider ( ) ; } } hasdiv = true ; continue ; } nm = cmd . storeid ; if ( cmd . showalways || ( showinmenu . indexOf ( nm ) > - 1 ) ) { hasdiv = false ; lastid = addToMenu ( cmd , menulist [ menuidx ] , lastid , nm , hotkeys ) ; } if ( cmd . toolinsertpoint ) { addToolCommands ( menulist [ menuidx ] ) ; } if ( showinctxmenu . indexOf ( nm ) > - 1 ) { lastid = addToMenu ( cmd , ctxmenu , lastid , nm , hotkeys ) ; } } addEditCmdsToLocalMenu ( ctxmenu ) ; } function fillShowonMenu ( ) { cmdlist . forEach ( ( cmd ) => { if ( cmd . priority === SHOWONMENU ) { prefs . commands . value . showinmenu . push ( cmd . storeid ) ; } } ) ; } function initPrefButtons ( ) { prefs . find . buttons [ 0 ] . f = ( text ) => getRegnize ( text , true ) ; prefs . findre . buttons [ 0 ] . f = prefs . find . buttons [ 0 ] . f ; prefs . scss . buttons [ 0 ] . f = ( ) => prefs . scss . buttons [ 0 ] . setvalue ; prefs . scss . buttons [ 1 ] . f = ( ) => prefs . scss . buttons [ 1 ] . setvalue ; } function _verReq ( prevver , checkver , list ) { if ( prevver < checkver ) { list . forEach ( ( item ) => { if ( prefs . commands . value . showinmenu . indexOf ( item ) === - 1 ) { prefs . commands . value . showinmenu . push ( item ) ; } } ) ; } } function versionCheck ( ) { let prevver = prefs . version . value ; if ( prevver !== VERSION ) { if ( ! prevver ) { prevver = 0 ; } else { prevver = prevver . split ( '.' ) ; prevver = ( ( prevver [ 0 ] >> 0 ) * 1000 ) + ( prevver [ 1 ] >> 0 ) ; } if ( prevver === 2011 && prefs . beforesave && prefs . beforesave . value && prefs . beforesave . value . length === 1 && prefs . beforesave . value [ 0 ] . name === 'def' ) { prefs . beforesave . value = [ ] ; } if ( prevver < 2000 ) { prefs . commands . value . showinmenu = prefs . commands . svshowinmenu ; } else { _verReq ( prevver , 2001 , [ 'recentfiles' ] ) ; } if ( prevver < 3002 ) { prefs . version . showwelcome = true ; } prefs . version . value = VERSION ; saveExtPrefs ( ) ; } } function posVersionCheck ( ) { } function execExternalQueue ( ) { let tool ; if ( externalQueueIsBusy || ! queueExternalSave . length ) { return ; } externalQueueIsBusy = true ; while ( queueExternalSave . length ) { tool = queueExternalSave . shift ( ) ; nodeExec ( tool . cmdline , getProjectRoot ( ) , tool . cmdline , false , false , { in : tool . infile , out : tool . outfile } ) ; } externalQueueIsBusy = false ; } function runEventSaveCommands ( doc , ext , prefvar ) { let toolmap ; prefvar . value . forEach ( ( st ) => { if ( st . exts . indexOf ( ext ) > - 1 ) { st . cmds . forEach ( ( storeid ) => { let cmd ; if ( storeid [ 0 ] === '@' ) { if ( ! toolmap ) { toolmap = { } ; prefs . tools . value . forEach ( ( tool_ ) => { toolmap [ '@' + tool_ . name ] = tool_ ; } ) ; } const tool = toolmap [ storeid ] ; if ( tool ) { queueExternalSave . push ( { cmdline : tool . cmdline , infile : doc . file . _path , outfile : '' } ) ; } } else { cmd = storeidmap [ storeid ] ; if ( cmd ) { globalDoc = doc ; try { runCommand ( cmd , true ) ; } finally { globalDoc = null ; } } } } ) ; } } ) ; } function runEventSave ( isAll , execSaveCommand , prefvar ) { function exec ( doc ) { if ( doc && doc . isDirty && doc . file && doc . file . isFile && ! doc . isUntitled ( ) ) { const ext = doc . file . name . replace ( /^.*(\.[^\.]+)$/ , '$1' ) ; if ( ext . length ) { execSaveCommand ( doc , ext , prefvar ) ; } } } if ( isAll ) { brk . DocumentManager . getAllOpenDocuments ( ) . forEach ( ( doc ) => { exec ( doc ) ; } ) ; } else { exec ( brk . DocumentManager . getCurrentDocument ( ) ) ; } execExternalQueue ( ) ; } function applyEditorProjSettings ( ps ) { projSettings . applied = true ; if ( ps . spaceUnits ) { if ( brk . Editor . getUseTabChar ( ) !== ps . useTabChar ) { $ ( '#indent-type' ) . click ( ) ; const value = ps . useTabChar ? ps . tabSize : ps . spaceUnits ; $ ( '#indent-width-label' ) . text ( value ) ; $ ( '#indent-width-input' ) . val ( value ) ; brk . Editor . setSpaceUnits ( ps . spaceUnits >> 0 ) ; brk . Editor . setTabSize ( ps . tabSize >> 0 ) ; } else { projSettings . applied = false ; } } } function applyProjSettings ( ps ) { applyEditorProjSettings ( ps ) ; } function handleAfterProjectOpen ( ) { const projFile = getProjectRoot ( ) + PROJ_SETTINGS_FILE ; projSettings . applied = false ; projSettings . data = { } ; $ . getJSON ( projFile , ( data ) => { applyProjSettings ( data ) ; projSettings . data = data ; optstoix . setPrefsFromProject ( prefs , projSettings ) ; } ) . fail ( ( ) => { if ( projSettings . data ) { applyProjSettings ( projSettings . data ) ; } } ) ; } function handleDocumentSaved ( event , doc ) { runEventSaveCommands ( doc , doc . file . name . replace ( /^.*(\.[^\.]+)$/ , '$1' ) , prefs . aftersave ) ; runCompilerEx ( true , doc . file . _path ) ; execExternalQueue ( ) ; } function init ( ) { brk . ExtensionUtils . loadStyleSheet ( module , "styles/bracketstoix.css" ) ; initCommandList ( ) ; fillShowonMenu ( ) ; initPrefButtons ( ) ; prefs . commands . svshowinmenu = prefs . commands . value . showinmenu ; loadExtPrefs ( ) ; versionCheck ( ) ; buildCommands ( ) ; runLanguageMapper ( ) ; initPrefButtons ( ) ; posVersionCheck ( ) ; brk . EditorManager . on ( 'activeEditorChange' , handleDocumentChanged ) ; brk . DocumentManager . on ( 'documentSaved' , handleDocumentSaved ) ; brk . ProjectManager . on ( 'projectOpen' , handleAfterProjectOpen ) ; brk . CommandManager . on ( 'beforeExecuteCommand' , ( event , type ) => { if ( type . indexOf ( "file.save" ) === 0 ) { runEventSave ( type === "file.saveAll" , runEventSaveCommands , prefs . beforesave ) ; } } ) ; } $ . getJSON ( brk . moduleroot + 'html/htmltemplatestoix.json' , ( data ) => { ix . htmltempl = data ; $ . getJSON ( brk . moduleroot + 'pdtoolstoix.json' , ( pdtools ) => { ix . pdtools = pdtools ; init ( ) ; } ) ; } ) ; } ) ;