# This file is part of the LibreOffice project. # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
Script to generate https://wiki.documentfoundation.org/Development/DispatchCommands
3 types of source files are scanned to identify and describe a list of relevant UNO commands:
- .hxx files: containing the symbolic and numeric id's, and the respective modes and groups
- .xcu files; containing several english labels as they appear in menus or tooltips
- .sdi files: containing a list of potential arguments for the commands, and their types """
import os import sys
# It is assumed that the script is called from $BUILDDIR; # and __file__ refers to the script location in $SRCDIR. # This allows to use it in separate builddir configuration.
srcdir = os.path.dirname(os.path.realpath(__file__)) + '/..'# go up from /bin
builddir = os.getcwd()
def analyze_hxx(all_commands): for filename in HXX_FILES: with open(filename) as fh:
ln = 0
mode = '' for line in fh:
ln += 1 ifnot line.startswith('// Slot Nr. '): continue
def analyze_sdi(all_commands): def SplitArguments(params): # Split a string like : SfxStringItem Name SID_CHART_NAME,SfxStringItem Range SID_CHART_SOURCE,SfxBoolItem ColHeaders FN_PARAM_1,SfxBoolItem RowHeaders FN_PARAM_2 # in : Name (string)\nRange (string)\nRowHeaders (bool)
CR = ' '
split = ''
params = params.strip(' ,').replace(', ', ',') # At least 1 case of ', ' in svx/sdi/svx.sdi line 3592 if len(params) > 0: for p in params.split(','): if len(split) > 0:
split += CR
elems = p.split() if len(elems) >= 2:
split += elems[1] if'String'in elems[0]:
split += ' (string)' elif'Bool'in elems[0]:
split += ' (bool)' elif'Int16'in elems[0]:
split += ' (integer)' elif'Int32'in elems[0]:
split += ' (long)' else:
split += ' (' + elems[0].replace('Sfx', '').replace('Svx', '').replace('Item', '').lower() + ')' return split
for filename in SDI_FILES:
ln = 0
comment, square, command, param = False, False, False, False with open(filename) as fh: for line in fh:
ln += 1
line = line.replace(' ', ' ').strip() # Anomaly met in svx/sdi/svx.sdi if line.startswith('//'): pass elif comment isFalseand line.startswith('/*') andnot line.endswith('*/'):
comment = True elif comment isTrueand line.endswith('*/'):
comment = False elif comment isFalseand line.startswith('/*') and line.endswith('*/'): pass elif comment isTrue: pass elif square isFalseand line.startswith('['):
square = True
mode = ''
command = False elif square isTrueand line.endswith(']'):
all_commands[command_name]['mode'] = mode
square = False elif square isTrue:
squaremode = line.strip(',;').split() if len(squaremode) == 3:
mode += 'U'if squaremode[0] == 'AutoUpdate'and squaremode[2] == 'TRUE'else''
mode += 'M'if squaremode[0] == 'MenuConfig'and squaremode[2] == 'TRUE'else''
mode += 'T'if squaremode[0] == 'ToolBoxConfig'and squaremode[2] == 'TRUE'else''
mode += 'A'if squaremode[0] == 'AccelConfig'and squaremode[2] == 'TRUE'else'' elif comment isFalseand square isFalseand command isFalseand len(line) == 0: pass elif command isFalse:
command_name = get_uno(line.split(' ')[1]) if command_name notin all_commands:
all_commands[command_name] = newcommand(command_name)
all_commands[command_name]['sdifile'] = SDI_FILES.index(filename)
all_commands[command_name]['sdilinenumber'] = ln
all_commands[command_name]['sdioccurs'] += 1 if len(all_commands[command_name]['resourceid']) == 0:
all_commands[command_name]['resourceid'] = line.split(' ')[2]
command = True elif command isTrueand (line == ''or line == '()'):
command = False elif command isTrueand (param isTrueor line.startswith('(')) and line.endswith(')'): if param:
params += line.strip(' (),').replace(', ', ',') # At least 1 case of ", " in svx/sdi/svx.sdi line 8767 # At least 1 case of "( " in sw/sdi/swriter.sdi line 5477 else:
params = line.strip(' (),').replace(', ', ',') # At least 1 case in sw/sdi/swriter.sdi line 7083
all_commands[command_name]['arguments'] = SplitArguments(params)
command = False
param = False elif command isTrueand line.startswith('('): # Arguments always on 1 line, except in some cases (cfr.BasicIDEAppear)
params = line.strip(' ()').replace(', ', ',')
param = True elif param isTrue:
params += line
def categorize(all_commands): # Clean black listed commands for command in BLACKLIST:
cmd = get_uno(command) if cmd in all_commands: del all_commands[cmd] # Set category based on the file name where the command was found first for cmd in all_commands:
command = all_commands[cmd]
cxcu, chxx, csdi = '', '', ''
fxcu = command['xcufile'] if fxcu > -1:
cxcu = os.path.basename(XCU_FILES[fxcu]).split('.')[0].replace('Commands', '')
fhxx = command['hxxfile'] if fhxx > -1:
chxx = os.path.basename(HXX_FILES[fhxx]).split('.')[0]
fsdi = command['sdifile'] if fsdi > -1:
csdi = os.path.basename(SDI_FILES[fsdi]).split('.')[0] # General rule: if len(cxcu) > 0:
cat = cxcu elif len(chxx) > 0:
cat = chxx else:
cat = csdi # Exceptions on general rule if cat == 'Generic'and chxx == 'basslots':
cat = chxx
command['module'] = MODULES[cat]
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.