1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="TexMathsSysConfig" script:language="StarBasic">'
' TexMathsSysConfig
'
' Copyright (C) 2012-2020 Roland Baudin (roland65@free.fr)
' Based on the work of Geoffroy Piroux (gpiroux@gmail.com)
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
'
' Macros used to create and manage the Sysconfig dialog
' Force variable declaration
Option Explicit
' Dialog declaration
Private oDlgSysConfig as Variant
' Main subroutine
Sub Main()
' The Draw component is required
If ComponentInstalled( "Draw" ) = FALSE Then
MsgBox( _("Please install the Draw component to run TexMaths!"), 0, "TexMaths")
Exit Sub
End If
DefaultSysConfig()
SysConfigDialog()
End Sub
' Create and show the config dialog
Sub SysConfigDialog()
' Load the library TexMaths
DialogLibraries.LoadLibrary( "TexMaths" )
' Create the dialog object
oDlgSysConfig = createUnoDialog( DialogLibraries.GetByName("TexMaths").GetByName("TexMathsSysConfig_GUI") )
' Dialog strings for translation
oDlgSysConfig.setTitle( _("TexMaths System Configuration") )
oDlgSysConfig.getControl("ShortcutFrame1").Model.Label = _("Equations Shortcuts")
oDlgSysConfig.getControl("ShortcutFrame2").Model.Label = _("Numbered Equations Shortcut")
oDlgSysConfig.getControl("SameShortcutKey").Model.Label = _("Same shortcut for Writer, Impress and Draw")
oDlgSysConfig.getControl("SameShortcutKey").Model.HelpText = _("Use the same shortcut for Writer, Impress and Draw")
oDlgSysConfig.getControl("SystempathsFrame").Model.Label = _("System Paths")
oDlgSysConfig.getControl("AllFrame").Model.Label = _("All")
oDlgSysConfig.getControl("Key1").Model.HelpText = _("Keyboard shortcut")
oDlgSysConfig.getControl("Key2").Model.HelpText = _("Keyboard shortcut")
oDlgSysConfig.getControl("Key3").Model.HelpText = _("Keyboard shortcut")
oDlgSysConfig.getControl("Key4").Model.HelpText = _("Keyboard shortcut")
oDlgSysConfig.getControl("LatexPath").Model.HelpText = _("Path of the latex program")
oDlgSysConfig.getControl("XelatexPath").Model.HelpText = _("Path of the xelatex program")
oDlgSysConfig.getControl("DvipngPath").Model.HelpText = _("Path of the dvipng program")
oDlgSysConfig.getControl("DvisvgmPath").Model.HelpText = _("Path of the dvisvgm program")
oDlgSysConfig.getControl("HelpButton").Model.Label = _("Help...")
oDlgSysConfig.getControl("HelpButton").Model.HelpText = _("Display help text")
oDlgSysConfig.getControl("SaveButton").Model.Label = _("Save")
oDlgSysConfig.getControl("SaveButton").Model.HelpText = _("Save system configuration")
oDlgSysConfig.getControl("NumLevelLabel").Model.Label = _("Numbering Level")
oDlgSysConfig.getControl("NumLevelLabel").Model.HelpText = _("Chapter level number to be included in equation numbers")
oDlgSysConfig.getControl("NumLevel").addItems(Array("0","1","2","3","4"),0)
oDlgSysConfig.getControl("NumLevel").Model.HelpText = _("Level number")
oDlgSysConfig.getControl("LeftAlignRadio").Model.Label = _("Caption left alignment")
oDlgSysConfig.getControl("LeftAlignRadio").Model.HelpText = _("Set equation caption alignment to left")
oDlgSysConfig.getControl("RightAlignRadio").Model.Label = _("Caption right alignment")
oDlgSysConfig.getControl("RightAlignRadio").Model.HelpText = _("Set equation caption alignment to right")
oDlgSysConfig.getControl("CompilerFrame").Model.Label = _("Compiler")
oDlgSysConfig.getControl("LatexCompiler").Model.HelpText = _("Equations will be compiled using the LaTeX compiler")
oDlgSysConfig.getControl("XelatexCompiler").Model.HelpText = _("Equations will be compiled using the XeLaTeX compiler")
oDlgSysConfig.getControl("PathsButton").Model.Label = _("Paths")
oDlgSysConfig.getControl("PathsButton").Model.HelpText = _("Display the Paths tab")
oDlgSysConfig.getControl("OptionsButton").Model.Label = _("Options")
oDlgSysConfig.getControl("OptionsButton").Model.HelpText = _("Display the Options tab")
oDlgSysConfig.getControl("InterfaceButton").Model.Label = _("Interface")
oDlgSysConfig.getControl("InterfaceButton").Model.HelpText = _("Display the Interface tab")
oDlgSysConfig.getControl("EditorFontFrame").Model.Label = _("Editor Font")
oDlgSysConfig.getControl("EditorFontName").Model.HelpText = _("Font name")
oDlgSysConfig.getControl("EditorFontNameLabel").Model.Label = _("Name")
oDlgSysConfig.getControl("EditorFontNameLabel").Model.HelpText = _("Name of the font used in the equation editor window")
oDlgSysConfig.getControl("EditorFontSize").addItems(Array("6","7","8","9","10","11","12","13","14","15","16","18","20","22","24","26","28","30","32","36","40","44","48","50"),0)
oDlgSysConfig.getControl("EditorFontSize").Model.HelpText = _("Font size")
oDlgSysConfig.getControl("EditorFontSizeLabel").Model.Label = _("Size")
oDlgSysConfig.getControl("EditorFontSizeLabel").Model.HelpText = _("Size of the font used in the equation editor window")
oDlgSysConfig.getControl("SymbolColorFrame").Model.Label = _("Symbol Color")
oDlgSysConfig.getControl("BlackSymbolsRadio").Model.Label = _("Black symbols")
oDlgSysConfig.getControl("BlackSymbolsRadio").Model.HelpText = _("Set LaTeX symbol color to black (for light themes)")
oDlgSysConfig.getControl("WhiteSymbolsRadio").Model.Label = _("White symbols")
oDlgSysConfig.getControl("WhiteSymbolsRadio").Model.HelpText = _("Set LaTeX symbol color to white (for dark themes)")
oDlgSysConfig.getControl("ShortcutsButton").Model.Label = _("Shortcuts")
oDlgSysConfig.getControl("ShortcutsButton").Model.HelpText = _("Display the Shortcuts tab")
oDlgSysConfig.getControl("NumberedEquationsFrame").Model.Label = _("Numbered Equations")
oDlgSysConfig.getControl("CompatibilityFrame").Model.Label = _("Compatibility")
oDlgSysConfig.getControl("VertAlign").Model.Label = _("Vertical alignment for Word export")
oDlgSysConfig.getControl("VertAlign").Model.HelpText = _("Improve vertical alignment of Writer equations for Word export")
oDlgSysConfig.getControl("BreakBeforeNumCheck").Model.Label = _("Paragraph break before numbered equations")
oDlgSysConfig.getControl("BreakBeforeNumCheck").Model.HelpText = _("Add a paragraph break before numbered equations")
oDlgSysConfig.getControl("BreakAfterNumCheck").Model.Label = _("Paragraph break after numbered equations")
oDlgSysConfig.getControl("BreakAfterNumCheck").Model.HelpText = _("Add a paragraph break after numbered equations")
oDlgSysConfig.getControl("CaptionLabel").Model.Label = _("Equation Caption")
oDlgSysConfig.getControl("CaptionTextField").Model.HelpText = _("Display text before equation number (leave blank if no text desired)")
' MacOSX uses Cmd key instead of Ctrl key for shortcuts
If getGUIType() <> 1 Then
If GetUname() = "Darwin" Then
oDlgSysConfig.getControl("Ctrl1Label").Model.Label = "Cmd +"
oDlgSysConfig.getControl("Ctrl2Label").Model.Label = "Cmd +"
oDlgSysConfig.getControl("Ctrl3Label").Model.Label = "Cmd +"
oDlgSysConfig.getControl("Ctrl4Label").Model.Label = "Cmd +"
End If
End If
Dim msg as String
msg = _("The TexMaths macro uses some external programs to generate the equation images. Enter below the paths of these programs. Note that only one of the dvisvgm or dvipng programs is required to generate equation images.")
' Windows
If getGUIType() = 1 Then
oDlgSysConfig.getControl("Description").setText( msg & chr(10) & chr(10) &_
_("Ex: For a standard MiKTeX 2.9 install on Windows, enter the following path into the latex.exe field:") & chr(10) &_
"C:\Program Files\MiKTeX 2.9\miktex\bin\latex.exe")
oDlgSysConfig.getControl("LatexLabel").setText( _("latex.exe (mandatory)") )
oDlgSysConfig.getControl("XelatexLabel").setText( _("xelatex.exe (optional)") )
oDlgSysConfig.getControl("DvipngLabel").setText( _("dvipng.exe (optional)") )
oDlgSysConfig.getControl("DvisvgmLabel").setText( _("dvisvgm.exe (optional)") )
oDlgSysConfig.getControl("CompatibilityFrame").Model.Height = 34
' Linux or Mac OS X
Else
' Mac OS X
If GetUname() = "Darwin" Then
oDlgSysConfig.getControl("Description").setText( msg & chr(10) & chr(10) &_
_("Ex: For a standard MacTeX install on Mac OS, enter the following path into the latex field:") & chr(10) &_
"/Library/TeX/texbin/latex")
oDlgSysConfig.getControl("LatexLabel").setText( _("latex (mandatory)") )
oDlgSysConfig.getControl("XelatexLabel").setText( _("xelatex (optional)") )
oDlgSysConfig.getControl("DvipngLabel").setText( _("dvipng (optional)") )
oDlgSysConfig.getControl("DvisvgmLabel").setText( _("dvisvgm (optional)") )
' Linux
Else
oDlgSysConfig.getControl("Description").setText( msg & chr(10) & chr(10) &_
_("Ex: For a standard LaTeX install on Linux, enter the following path into the latex field:") & chr(10) &_
"/usr/bin/latex")
oDlgSysConfig.getControl("LatexLabel").setText( _("latex (mandatory)") )
oDlgSysConfig.getControl("XelatexLabel").setText( _("xelatex (optional)") )
oDlgSysConfig.getControl("DvipngLabel").setText( _("dvipng (optional)") )
oDlgSysConfig.getControl("DvisvgmLabel").setText( _("dvisvgm (optional)") )
End If
End If
' Fill the file path values from the registry
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess("/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
oDlgSysConfig.getControl("LatexPath").setText(ConvertFromURL(oSystemInfo.LatexPath))
oDlgSysConfig.getControl("XelatexPath").setText(ConvertFromURL(oSystemInfo.XelatexPath))
oDlgSysConfig.getControl("DvipngPath").setText(ConvertFromURL(oSystemInfo.DvipngPath))
oDlgSysConfig.getControl("DvisvgmPath").setText(ConvertFromURL(oSystemInfo.DvisvgmPath))
' Set compiler
If oSystemInfo.Compiler = "latex" Then oDlgSysConfig.getControl("LatexCompiler").setState(1)
If oSystemInfo.Compiler = "xelatex" Then oDlgSysConfig.getControl("XelatexCompiler").setState(1)
' Set symbol color
If oSystemInfo.SymbolColor = "symbols-black" Then
oDlgSysConfig.getControl("BlackSymbolsRadio").setState(1)
oDlgSysConfig.getControl("WhiteSymbolsRadio").setState(0)
else
oDlgSysConfig.getControl("BlackSymbolsRadio").setState(0)
oDlgSysConfig.getControl("WhiteSymbolsRadio").setState(1)
End If
' Set the break before num and break after num options
If oSystemInfo.BreakBeforeNum = "TRUE" Then
oDlgSysConfig.getControl("BreakBeforeNumCheck").setState(1)
Else
oDlgSysConfig.getControl("BreakBeforeNumCheck").setState(0)
End If
If oSystemInfo.BreakAfterNum = "TRUE" Then
oDlgSysConfig.getControl("BreakAfterNumCheck").setState(1)
Else
oDlgSysConfig.getControl("BreakAfterNumCheck").setState(0)
End If
' Set the equation caption
oDlgSysConfig.getControl("CaptionTextField").setText(oSystemInfo.EquationCaption)
' Set the caption alignment
If oSystemInfo.CaptionLeftAlign = "TRUE" Then
oDlgSysConfig.getControl("LeftAlignRadio").setState(1)
oDlgSysConfig.getControl("RightAlignRadio").setState(0)
Else
oDlgSysConfig.getControl("LeftAlignRadio").setState(0)
oDlgSysConfig.getControl("RightAlignRadio").setState(1)
End If
' Set the vertical alignment compatibility option
If oSystemInfo.WordVertAlign = "TRUE" Then
oDlgSysConfig.getControl("VertAlign").setState(1)
Else
oDlgSysConfig.getControl("VertAlign").setState(0)
End If
' Set the numbering level
oDlgSysConfig.getControl("NumLevel").setText(oSystemInfo.NumLevel)
' Set editor font name
If oSystemInfo.EditorFontName = "" Then
oDlgSysConfig.getControl("EditorFontName").setText(_("(Default)"))
Else
oDlgSysConfig.getControl("EditorFontName").setText(oSystemInfo.EditorFontName)
End If
' Set editor font size
oDlgSysConfig.getControl("EditorFontSize").setText(oSystemInfo.EditorFontSize)
' Set the shortcuts
Dim iKey1 as Integer, iKey2 as Integer, iKey3 as Integer, iKey4 as Integer
iKey1 = oSystemInfo.EqWriterKey
If iKey1 <> 0 Then oDlgSysConfig.getControl("Key1").setText(Chr(iKey1-447)) Else oDlgSysConfig.getControl("Key1").setText("")
iKey2 = oSystemInfo.EqImpressKey
If iKey2 <> 0 Then oDlgSysConfig.getControl("Key2").setText(Chr(iKey2-447)) Else oDlgSysConfig.getControl("Key2").setText("")
iKey3 = oSystemInfo.EqDrawKey
If iKey3 <> 0 Then oDlgSysConfig.getControl("Key3").setText(Chr(iKey3-447)) Else oDlgSysConfig.getControl("Key3").setText("")
iKey4 = oSystemInfo.NumEqWriterKey
If iKey4 <> 0 Then oDlgSysConfig.getControl("Key4").setText(Chr(iKey4-447)) Else oDlgSysConfig.getControl("Key4").setText("")
' Check if same Equations shortcuts for all apps
If iKey1 = iKey2 and iKey1 = iKey3 Then
oDlgSysConfig.getControl("SameShortcutKey").setState(1)
SetEquationsShortcutControl(FALSE)
Else
oDlgSysConfig.getControl("SameShortcutKey").setState(0)
SetEquationsShortcutControl(TRUE)
End If
' Set the state of the tab buttons
oDlgSysConfig.getControl("PathsButton").Model.State=1
oDlgSysConfig.getControl("OptionsButton").Model.State=0
oDlgSysConfig.getControl("InterfaceButton").Model.State=0
oDlgSysConfig.getControl("ShortcutsButton").Model.State=0
oDlgSysConfig.Model.Step = 1
' Show the dialog window
oDlgSysConfig.Execute()
End Sub
' Paths tab button was pressed
Sub PathsButtonPressed(oEvent as Variant)
' Change the state of the tab buttons
Dim oDialog as Variant
oDialog = oEvent.Source.Context.View
oDialog.getControl("PathsButton").Model.State=1
oDialog.getControl("OptionsButton").Model.State=0
oDialog.getControl("InterfaceButton").Model.State=0
oDialog.getControl("ShortcutsButton").Model.State=0
oDialog.Model.Step = 1
End Sub
' Options tab button was pressed
Sub OptionsButtonPressed(oEvent as Variant)
' Change the state of the tab buttons
Dim oDialog as Variant
oDialog = oEvent.Source.Context.View
oDialog.getControl("PathsButton").Model.State=0
oDialog.getControl("OptionsButton").Model.State=1
oDialog.getControl("InterfaceButton").Model.State=0
oDialog.getControl("ShortcutsButton").Model.State=0
oDialog.Model.Step = 2
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess("/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
' xelatex path is empty
If oDlgSysConfig.getControl("XelatexPath").getText() = "" Then
oDlgSysConfig.getControl("LatexCompiler").setState(1)
oDlgSysConfig.getControl("XelatexCompiler").setEnable(FALSE)
oSystemInfo.Compiler = "latex"
oSystemInfo.commitChanges()
' xelatex doesn't exist
ElseIf Not FileExists(oSystemInfo.XelatexPath) Then
' Warn the user
oDlgSysConfig.getControl("XelatexSupport").Model.Label = "[" & _("xelatex not found, XeLateX is disabled") & "]"
' Set compiler to latex
oDlgSysConfig.getControl("LatexCompiler").setState(1)
oDlgSysConfig.getControl("XelatexCompiler").setEnable(FALSE)
oSystemInfo.Compiler = "latex"
oSystemInfo.commitChanges()
' dvisvgm doesn't exist
ElseIf Not FileExists(oSystemInfo.DvisvgmPath) Then
' Warn the user if dvisvgm doesn't support XeLaTeX
oDlgSysConfig.getControl("XelatexSupport").Model.Label = "[" & _("dvisvgm not found, XeLateX is disabled") & "]"
' Set compiler to latex
oDlgSysConfig.getControl("LatexCompiler").setState(1)
oDlgSysConfig.getControl("XelatexCompiler").setEnable(FALSE)
oSystemInfo.Compiler = "latex"
oSystemInfo.commitChanges()
' dvisvgm does not support XeLaTeX
ElseIf dvisvgmSupportsXelatex() = FALSE Then
' Warn the user if dvisvgm doesn't support XeLaTeX
oDlgSysConfig.getControl("XelatexSupport").Model.Label = "[" & _("dvisvgm too old, XeLateX is disabled") & "]"
' Set compiler to latex
oDlgSysConfig.getControl("LatexCompiler").setState(1)
oDlgSysConfig.getControl("XelatexCompiler").setEnable(FALSE)
oSystemInfo = GetConfigAccess("/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
oSystemInfo.Compiler = "latex"
oSystemInfo.commitChanges()
' dvisvgm supports XeLaTeX
Else
oDlgSysConfig.getControl("XelatexSupport").Model.Label = ""
End If
End Sub
' Interface tab button was pressed
Sub InterfaceButtonPressed(oEvent as Variant)
' Change the state of the tab buttons
Dim oDialog as Variant
oDialog = oEvent.Source.Context.View
oDialog.getControl("PathsButton").Model.State=0
oDialog.getControl("OptionsButton").Model.State=0
oDialog.getControl("InterfaceButton").Model.State=1
oDialog.getControl("ShortcutsButton").Model.State=0
oDialog.Model.Step = 3
End Sub
' Shortcut tab button was pressed
Sub ShortcutsButtonPressed(oEvent as Variant)
' Change the state of the tab buttons
Dim oDialog as Variant
oDialog = oEvent.Source.Context.View
oDialog.getControl("PathsButton").Model.State=0
oDialog.getControl("OptionsButton").Model.State=0
oDialog.getControl("InterfaceButton").Model.State=0
oDialog.getControl("ShortcutsButton").Model.State=1
oDialog.Model.Step = 4
' Refresh items related to the shortcut check box
If oDlgSysConfig.getControl("SameShortcutKey").getState() Then
SetEquationsShortcutControl(FALSE)
Else
SetEquationsShortcutControl(TRUE)
End If
End Sub
' Test the existence of the different external programs in the paths saved in the registry
Sub CheckProgramPaths
Dim str0 as String, str1 as String, str2 as String, str3 as String, str4 as String
Dim pgm1 as String, pgm2 as String, pgm3 as String, pgm4 as String
Dim prevLatexPath as String, prevXelatexPath as String, prevDvipngPath as String, prevDviSvgmPath as String
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess( "/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
' All systems
str1 = _("Please configure first TexMaths before using it...")
str2 = _("Can't find the external program ")
str3 = _("Please check the file paths in your TexMaths system configuration...")
str4 = _("Can't find at least one of the external programs ")
' Windows
If getGUIType() = 1 Then
pgm1 = "latex.exe"
pgm2 = "xelatex.exe"
pgm3 = "dvipng.exe"
pgm4 = "dvisvgm.exe"
' Linux or MacOSX
Else
pgm1 = "latex"
pgm2 = "xelatex"
pgm3 = "dvipng"
pgm4 = "dvisvgm"
End If
' Initial values of the external program paths
prevLatexPath = oSystemInfo.LatexPath
prevXelatexPath = oSystemInfo.XelatexPath
prevDvipngPath = oSystemInfo.DvipngPath
prevDvisvgmPath = oSystemInfo.DvisvgmPath
' If program paths are empty or are directories, check if programs are in the system path
If oSystemInfo.LatexPath = "" Or oSystemInfo.LatexPath = GetBaseDir(oSystemInfo.LatexPath) Then oSystemInfo.LatexPath = ConvertFromURL( ReadPgmPath( pgm1 ) )
If oSystemInfo.XelatexPath = "" Or oSystemInfo.XelatexPath = GetBaseDir(oSystemInfo.XelatexPath) Then oSystemInfo.XelatexPath = ConvertFromURL( ReadPgmPath( pgm2 ) )
If oSystemInfo.DvipngPath = "" Or oSystemInfo.DvipngPath = GetBaseDir(oSystemInfo.DvipngPath) Then oSystemInfo.DvipngPath = ConvertFromURL( ReadPgmPath( pgm3 ) )
If oSystemInfo.DvisvgmPath = "" Or oSystemInfo.DvisvgmPath = GetBaseDir(oSystemInfo.DvisvgmPath) Then oSystemInfo.DvisvgmPath = ConvertFromURL( ReadPgmPath( pgm4 ) )
' If the paths changed, save the registry, recreate the script and set default preferences
If oSystemInfo.LatexPath <> prevLatexPath Or oSystemInfo.XelatexPath <> prevXelatexPath Or oSystemInfo.DvipngPath <> prevDvipngPath Or oSystemInfo.DvisvgmPath <> prevDvisvgmPath Then
oSystemInfo.commitChanges()
WriteScript(oSystemInfo.LatexPath, oSystemInfo.XelatexPath, oSystemInfo.DvipngPath, oSystemInfo.DvisvgmPath)
DefaultPrefs()
End If
' Latex program doesn't exist
If Not FileExists(oSystemInfo.LatexPath) Then ProgramNotFound(str2 & pgm1 & chr(10) & str3)
' Read again the registry because it may have changed
oSystemInfo = GetConfigAccess( "/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
' Both dvipng and dvisvgm programs don't exist
If Not FileExists(oSystemInfo.DvipngPath) And Not FileExists(oSystemInfo.DvisvgmPath) Then ProgramNotFound(str4 & pgm3 & _(" or ") & pgm4 & chr(10) & str3)
' Programs still don't exist => stop
If Not FileExists(oSystemInfo.LatexPath) Or ( Not FileExists(oSystemInfo.DvipngPath) And Not FileExists(oSystemInfo.DvisvgmPath) ) Then Stop
' Script doesn't exist
If Not FileExists(GetScriptPath()) Then WriteScript(oSystemInfo.LatexPath, oSystemInfo.XelatexPath, oSystemInfo.DvipngPath, oSystemInfo.DvisvgmPath)
' Flag to say config was saved
If oSystemInfo.ConfigSaved = "" Then oSystemInfo.ConfigSaved = "TRUE"
' Save the registry
oSystemInfo.commitChanges()
End Sub
' Display an appropriate 'Program not found' message
' and launch the config dialog
Sub ProgramNotFound(message as String)
MsgBox(message, 0, "TexMaths")
SysConfigDialog()
End Sub
' Exit dialog
Sub QuitSysConfig()
oDlgSysConfig.endExecute()
end sub
Sub SetEquationsShortcutControl( b as Boolean )
oDlgSysConfig.getControl("AllFrame").Visible = Not b
oDlgSysConfig.getControl("WriterFrame").Visible = b
oDlgSysConfig.getControl("ImpressFrame").Visible = b
oDlgSysConfig.getControl("DrawFrame").Visible = b
oDlgSysConfig.getControl("Ctrl2Label").Visible = b
oDlgSysConfig.getControl("Ctrl3Label").Visible = b
oDlgSysConfig.getControl("Key2").Visible = b
oDlgSysConfig.getControl("Key3").Visible = b
End Sub
Sub SameShortcutKeyChanged()
If oDlgSysConfig.getControl("SameShortcutKey").getState() Then
SetEquationsShortcutControl(FALSE)
Else
SetEquationsShortcutControl(TRUE)
End If
End Sub
' Save configuration
Sub SaveSysConfig()
Dim sKey1 as String, sKey2 as String, sKey3 as String, sKey4 as String
sKey1 = oDlgSysConfig.getControl("Key1").getText()
If oDlgSysConfig.getControl("SameShortcutKey").getState() Then
sKey2 = sKey1
sKey3 = sKey1
Else
sKey2 = oDlgSysConfig.getControl("Key2").getText()
sKey3 = oDlgSysConfig.getControl("Key3").getText()
End If
If sKey1 = " " or sKey1 = "" Then
RemoveShortcut( "EqWriter" )
ElseIf TestKey(sKey1) <> 0 Then
SetShortcut( TestKey(sKey1), sKey1, "EqWriter")
Else
Exit Sub
End If
If sKey2 = " " or sKey2 = "" Then
RemoveShortcut( "EqImpress" )
ElseIf TestKey(sKey2) <> 0 Then
SetShortcut( TestKey(sKey2), sKey2, "EqImpress")
Else
Exit Sub
End If
If sKey3 = " " or sKey3 = "" Then
RemoveShortcut( "EqDraw" )
ElseIf TestKey(sKey3) <> 0 Then
SetShortcut( TestKey(sKey3), sKey3, "EqDraw")
Else
Exit Sub
End If
sKey4 = oDlgSysConfig.getControl("Key4").getText()
If sKey4 = " " or sKey4 = "" Then
RemoveShortcut( "NumEqWriter" )
ElseIf TestKey(sKey4) <> 0 Then
' Check if shortcuts are equal
If (TestKey(sKey4) = TestKey(sKey1)) Or (TestKey(sKey4) = TestKey(sKey2)) Or (TestKey(sKey4) = TestKey(sKey3)) Then
MsgBox(_("Shortcuts assigned to the Equations and NumberedEquations modules must be different!") & chr(10) &_
_("Please check your shortcuts..."), 0, "TexMaths")
Exit Sub
End If
SetShortcut( TestKey(sKey4), sKey4, "NumEqWriter")
Else
Exit Sub
End If
' Create the TexMaths script
' Get the variables from the sysconfig dialog
Dim sLatexPath as String, sXelatexPath as String, sDvipngPath as String, sDvisvgmPath as String
Dim oFileAccess as Variant
sLatexPath = oDlgSysConfig.getControl("LatexPath").getText()
sXelatexPath = oDlgSysConfig.getControl("XelatexPath").getText()
sDvipngPath = oDlgSysConfig.getControl("DvipngPath").getText()
sDvisvgmPath = oDlgSysConfig.getControl("DvisvgmPath").getText()
If sLatexPath = "" Then
MsgBox( _("Please set the latex path..."), 0, "TexMaths")
Exit Sub
End If
If sDvipngPath = "" and sDvisvgmPath = "" Then
MsgBox( _("Please set at least one dvipng path or the dvisvgm path..."), 0, "TexMaths")
Exit Sub
End If
' Windows
If getGUIType() = 1 Then
If CheckFile( sLatexPath, _("The program latex.exe was not found") ) Then Exit Sub
If sXelatexPath <> "" And oDlgSysConfig.getControl("XelatexCompiler").getState() Then
If CheckFile( sXelatexPath, _("The program xelatex.exe was not found, please check its path") ) Then Exit Sub
End If
If sDvipngPath <> "" Then
If CheckFile(sDvipngPath, _("The program dvipng.exe was not found, please check its path") & sDvipngPath ) Then Exit Sub
End If
If sDvisvgmPath <> "" Then
If CheckFile(sDvisvgmPath, _("The program dvisvgm.exe was not found, please check its path") & sDvisvgmPath ) Then Exit Sub
End If
' Linux or MacOSX
Else
If CheckFile( sLatexPath, _("The program latex was not found, please check its path") ) Then Exit Sub
If sXelatexPath <> "" And oDlgSysConfig.getControl("XelatexCompiler").getState() Then
If CheckFile( sXelatexPath, _("The program xelatex was not found, please check its path") ) Then Exit Sub
End If
If sDvipngPath <> "" Then
If CheckFile(sDvipngPath, _("The program dvipng was not found, please check its path") ) Then Exit Sub
End If
If sDvisvgmPath <> "" Then
If CheckFile( sDvisvgmPath, _("The program dvisvgm was not found, please check its path") ) Then Exit Sub
End If
End If
' Open service file and an output stream
Dim cURL as String
oFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")
cURL = ConvertToURL( GetScriptPath() )
' Get the path saved in the registry
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess( "/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
If sLatexPath <> oSystemInfo.LatexPath _
Or sXelatexPath <> oSystemInfo.XelatexPath _
Or sDvipngPath <> oSystemInfo.DvipngPath _
Or sDvisvgmPath <> oSystemInfo.DvisvgmPath _
Or Not oFileAccess.exists(cURL) Then
WriteScript(sLatexPath, sXelatexPath, sDvipngPath, sDvisvgmPath)
End If
oDlgSysConfig.endExecute()
' Set compiler
If oDlgSysConfig.getControl("LatexCompiler").getState() Then
oSystemInfo.Compiler = "latex"
Else
oSystemInfo.Compiler = "xelatex"
End If
' Set symbol color
If oDlgSysConfig.getControl("BlackSymbolsRadio").getState(1) Then
oSystemInfo.SymbolColor = "symbols-black"
Else
oSystemInfo.SymbolColor = "symbols-white"
End If
' Set vertical alignment compatibility option
If oDlgSysConfig.getControl("VertAlign").getState() Then oSystemInfo.WordVertAlign = "TRUE" Else oSystemInfo.WordVertAlign = "FALSE"
' Set caption alignment
If oDlgSysConfig.getControl("LeftAlignRadio").getState() Then oSystemInfo.CaptionLeftAlign = "TRUE" Else oSystemInfo.CaptionLeftAlign = "FALSE"
' Set break before num and break after num options
If oDlgSysConfig.getControl("BreakBeforeNumCheck").getState() Then oSystemInfo.BreakBeforeNum = "TRUE" Else oSystemInfo.BreakBeforeNum = "FALSE"
If oDlgSysConfig.getControl("BreakAfterNumCheck").getState() Then oSystemInfo.BreakAfterNum = "TRUE" Else oSystemInfo.BreakAfterNum = "FALSE"
' Set equation caption
oSystemInfo.EquationCaption = oDlgSysConfig.getControl("CaptionTextField").getText()
' Set numbering level
oSystemInfo.NumLevel = oDlgSysConfig.getControl("NumLevel").getText()
' Set editor font name
If oDlgSysConfig.getControl("EditorFontName").getText() = _("(Default)") Then
oSystemInfo.EditorFontName = ""
Else
oSystemInfo.EditorFontName = oDlgSysConfig.getControl("EditorFontName").getText()
End If
' Set editor font size
oSystemInfo.EditorFontSize = oDlgSysConfig.getControl("EditorFontSize").getText()
' Config was saved
oSystemInfo.ConfigSaved = "TRUE"
oSystemInfo.commitChanges()
' Set configuration in case we were called by TexMathsEquations
TexMathsEquations.SetConfig()
End Sub
' Test shortcut validity
Function TestKey(sKey as String) as Integer
If sKey = "" Then
TestKey = 0
Else
Dim i as Integer
i = Asc(sKey)
If 96 < i and i < 123 Then
TestKey = i + 415
ElseIf 64 < i and i < 91 Then
TestKey = i + 447
ElseIf sKey <> " " Then
MsgBox( _("Only characters from A to Z are allowed for shortcuts!"), 0, "TexMaths")
TestKey = 0
End If
End If
End Function
' Add shortcut to the registry
Sub SetShortcut(iKey as Integer, sKey as String, sRegId)
Dim sNewCommand as String, sCommand as String, sModule as String, sDoc as String
' Retrieve the module configuration manager from central module configuration manager supplier
Dim oModuleCfgMgrSupplier as Variant
oModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
' Retrieve the module configuration manager based on the registry identifier
Dim oModuleCfgMgr as Variant
If sRegId = "EqWriter" or sRegId = "NumEqWriter" Then
' Writer installed
If ComponentInstalled( "Writer" ) Then
sDoc = "Writer"
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.text.TextDocument")
' Writer not installed
Else
Exit Sub
End If
ElseIf sRegId = "EqImpress" Then
' Impress installed
If ComponentInstalled( "Impress" ) Then
sDoc = "Impress"
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.presentation.PresentationDocument")
' Impress not installed
Else
Exit Sub
End If
ElseIf sRegId = "EqDraw" Then
' Draw installation was already checked in Main()
sDoc = "Draw"
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.drawing.DrawingDocument")
End If
Dim oShortcutMgr as Variant
oShortcutMgr = oModuleCfgMgr.getShortcutManager
Dim aKeyEvent as New com.sun.star.awt.KeyEvent
With aKeyEvent
.Modifiers = com.sun.star.awt.KeyModifier.MOD1
.KeyCode = iKey ' com.sun.star.awt.Key.E
End With
' Get the actual command for the shortcut "iKey"
On Error Resume Next
sCommand = oShortcutMgr.getCommandByKeyEvent(aKeyEvent)
On Error GoTo 0 ' Restore the error handler
' Set the TexMaths module name
If sRegId = "NumEqWriter" Then
sModule = "NumberedEquations"
Else
sModule = "Equations"
End If
' Set the new command for the appropriate TexMaths module (Equations or NumberedEquations)
sNewCommand = "vnd.sun.star.script:TexMaths.TexMaths" & sModule & ".main?language=Basic&location=application"
' Get the shortcut repository
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess( "/ooo.ext.texmaths.Registry/SystemInfo" , TRUE)
If len(sCommand) = 0 Then ' New command
' Restore the previous shortcut command
If (sRegId = "EqWriter" And oSystemInfo.EqWriterKey > 0)_
Or (sRegId = "NumEqWriter" And oSystemInfo.NumEqWriterKey > 0)_
Or (sRegId = "EqImpress" And oSystemInfo.EqImpressKey > 0)_
Or (sRegId = "EqDraw" And oSystemInfo.EqDrawKey > 0) Then
RemoveShortcut( sRegId )
End If
oShortcutMgr.setKeyEvent( aKeyEvent, sNewCommand )
oShortcutMgr.store
' Store the current command
If (sRegId = "EqWriter") Then
oSystemInfo.EqWriterCmd = ""
ElseIf (sRegId = "NumEqWriter") Then
oSystemInfo.NumEqWriterCmd = ""
ElseIf (sRegId = "EqImpress") Then
oSystemInfo.EqImpressCmd = ""
ElseIf (sRegId = "EqDraw") Then
oSystemInfo.EqDrawCmd = ""
End If
ElseIf sCommand <> sNewCommand Then ' The key event is already used by another command
Dim sMsg as String
sMsg = sDoc & Chr(10) & Chr(10)
sMsg = sMsg & _("The key combination CTRL + ") & sKey & _(" is already assigned to the command ") & "'" & sCommand & "'" & Chr(10) & Chr(10)
sMsg = sMsg & _("Do you want to set the command") & " TexMaths" & sModule & ".main ?"
Dim iMsgResult as Variant
iMsgResult = MsgBox( sMsg, 1, "TexMaths")
If iMsgResult <> 1 Then Exit Sub
' Remove the previous shortcut command
If (sRegId = "EqWriter" And oSystemInfo.EqWriterKey > 0)_
Or (sRegId = "NumEqWriter" And oSystemInfo.NumEqWriterKey > 0)_
Or (sRegId = "EqImpress" And oSystemInfo.EqImpressKey > 0)_
Or (sRegId = "EqDraw" And oSystemInfo.EqDrawKey > 0) Then
RemoveShortcut( sRegId )
End If
oShortcutMgr.removeKeyEvent(aKeyEvent)
oShortcutMgr.setKeyEvent(aKeyEvent, sNewCommand )
oShortcutMgr.store
' Store the current command
If sRegId = "EqWriter" Then
oSystemInfo.EqWriterCmd = sCommand
ElseIf sRegId = "NumEqWriter" Then
oSystemInfo.NumEqWriterCmd = sCommand
ElseIf sRegId = "EqImpress" Then
oSystemInfo.EqImpressCmd = sCommand
ElseIf sRegId = "EqDraw" Then
oSystemInfo.EqDrawCmd = sCommand
End If
Else ' Same command
' Commmand previously set outside TexMaths => put it at spaces
If (sRegId = "EqWriter" And oSystemInfo.EqWriterCmd = sCommand)_
Or (sRegId = "NumEqWriter" And oSystemInfo.NumEqWriterCmd = sCommand)_
Or (sRegId = "EqImpress" And oSystemInfo.EqImpressCmd = sCommand)_
Or (sRegId = "EqDraw" And oSystemInfo.EqDrawCmd = sCommand) Then
sCommand = ""
End If
End if
' Save to the registry the new shortcut with the previous command
If sRegId = "EqWriter" Then
oSystemInfo.EqWriterKey = iKey
ElseIf sRegId = "NumEqWriter" Then
oSystemInfo.NumEqWriterKey = iKey
ElseIf sRegId = "EqImpress" Then
oSystemInfo.EqImpressKey = iKey
ElseIf sRegId = "EqDraw" Then
oSystemInfo.EqDrawKey = iKey
End If
oSystemInfo.commitChanges()
End Sub
' Remove shortcut from the registry
Sub RemoveShortcut(sRegId as String)
Dim iKey as Integer
Dim sCommand as String, sPrevCommand as String, sDoc as String
' Get the current shortcut and previous command from the registry
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess( "/ooo.ext.texmaths.Registry/SystemInfo/", TRUE)
If sRegId = "EqWriter" Then
iKey = oSystemInfo.EqWriterKey
sPrevCommand = oSystemInfo.EqWriterCmd
oSystemInfo.EqWriterKey = ""
oSystemInfo.EqWriterCmd = ""
sDoc = "Writer"
ElseIf sRegId = "NumEqWriter" Then
iKey = oSystemInfo.NumEqWriterKey
sPrevCommand = oSystemInfo.NumEqWriterCmd
oSystemInfo.NumEqWriterKey = ""
oSystemInfo.NumEqWriterCmd = ""
sDoc = "Writer"
ElseIf sRegId = "EqImpress" Then
iKey = oSystemInfo.EqImpressKey
sPrevCommand = oSystemInfo.EqImpressCmd
oSystemInfo.EqImpressKey = ""
oSystemInfo.EqImpressCmd = ""
sDoc = "Impress"
ElseIf sRegId = "EqDraw" Then
iKey = oSystemInfo.EqDrawKey
sPrevCommand = oSystemInfo.EqDrawCmd
oSystemInfo.EqDrawKey = ""
oSystemInfo.EqDrawCmd = ""
sDoc = "Draw"
End If
' If no shortcut defined in the registry => exit sub
If iKey = 0 or iKey = "" Then Exit Sub
' Retrieve the module configuration manager from central module configuration manager supplier
Dim oModuleCfgMgrSupplier as Variant
oModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
' Retrieve the module configuration manager with module identifier
Dim oModuleCfgMgr as Variant
If sDoc = "Writer" Then
' Writer installed
If ComponentInstalled( "Writer" ) Then
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.text.TextDocument")
' Writer not installed
Else
Exit Sub
End If
ElseIf sDoc = "Impress" Then
' Impress installed
If ComponentInstalled( "Impress" ) Then
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.presentation.PresentationDocument")
' Impress not installed
Else
Exit Sub
End If
ElseIf sDoc = "Draw" Then
' Draw installation was already checked in Main()
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.drawing.DrawingDocument")
End If
Dim oShortcutMgr as Variant
oShortcutMgr = oModuleCfgMgr.getShortcutManager
Dim aKeyEvent as New com.sun.star.awt.KeyEvent
With aKeyEvent
.Modifiers = com.sun.star.awt.KeyModifier.MOD1
.KeyCode = iKey
End With
On Error Resume Next
sCommand = oShortcutMgr.getCommandByKeyEvent(aKeyEvent)
On Error GoTo 0 ' Restore the error handler
' Remove the current shortcut
If len(sCommand) <> 0 Then
oShortcutMgr.removeKeyEvent(aKeyEvent)
oShortcutMgr.store
End If
' Set the previous shortcut
If len(sPrevCommand) <> 0 Then
oShortcutMgr.setKeyEvent( aKeyEvent, sPrevCommand )
oShortcutMgr.store
End If
' Save change in the registry
oSystemInfo.commitChanges()
End Sub
' Create the TexMaths script depending on the system
' Note : on Windows, for LibreOffice < 6.2.4.1 the Shell() command is buggy and does not work correctly
' if the script path contains spaces. As a workaround, we put the script in a
' directory named C:\texmaths-<username_without_spaces> and we set it as a
' hidden directory. For LibreOffice >= 6.2.4.1, the bug is fixed and we use
' the standard place C:\Users\[username]\AppData\Roaming\LibreOffice\4\user
Sub WriteScript(sLatexPath as String, sXelatexPath as String, sDvipngPath as String, sDvisvgmPath as String)
Dim cURL as String, sPath as String, sTexMaths as String
Dim sDvipngCmd as String, sDvisvgmCmd as String, sXelatexCmd as String
' Save the paths to the registry
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess( "/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
oSystemInfo.LatexPath = sLatexPath
oSystemInfo.XelatexPath = sXelatexPath
oSystemInfo.DvipngPath = sDvipngPath
oSystemInfo.DvisvgmPath = sDvisvgmPath
oSystemInfo.commitChanges()
' Get the base directory of the latex program
Dim sBasePath as String
sBasePath = GetBaseDir(sLatexPath)
' Open service file and an output stream
Dim oFileAccess as Variant, oTextStream as Variant
oFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")
oTextStream = createUnoService("com.sun.star.io.TextOutputStream")
' Generate the TexMaths script in the appropriate directory
cURL = ConvertToURL( GetScriptPath() )
If oFileAccess.exists( cURL ) Then oFileAccess.kill( cURL )
' => Windows: generate a .bat script
If getGUIType() = 1 Then
' Path
sPath = "set PATH=" & sBasePath & ";%PATH%" & chr(10)
' Script
If sDvipngPath = "" Then
sDvipngCmd = ""
Else
sDvipngCmd = "rem Conversion of the DVI file to a PNG image" & chr(10) &_
"if ""%EXT%"" == ""png"" (" & chr(10) &_
"if ""%TRANS%"" == ""TRUE"" (" & chr(10) &_
" " & """" & sDvipngpath & """" & " -q -T tight -bg Transparent --width --height --depth -D %DPI% -o %FILENAME%.png %FILENAME%.dvi > %FILENAME%.dat" & chr(10) &_
") else (" & chr(10) &_
" " & """" & sDvipngpath & """" & " -q -T tight --width --height --depth -D %DPI% -o %FILENAME%.png %FILENAME%.dvi > %FILENAME%.dat" & chr(10) &_
")" & chr(10) &_
")" & chr(10)
End If
If sDvisvgmPath = "" Then
sDvisvgmCmd = ""
Else
sDvisvgmCmd = "rem Conversion of the DVI file to a SVG image" & chr(10) &_
"if ""%EXT%"" == ""svg"" (" & chr(10) &_
" " & """" & sDvisvgmPath & """" & " -n1 -e %FILENAME%.dvi 2> %FILENAME%.dat" & chr(10) &_
")" & chr(10)
End If
If sXelatexPath = "" Then
sXelatexCmd = ")"
Else
sXelatexCmd = "rem Compile using xelatex" & chr(10) &_
") else (" & chr(10) &_
chr(10) &_
"rem Creation of the XDV file" & chr(10) &_
"""" & sXelatexPath & """" & " -no-pdf -shell-escape -interaction=nonstopmode %FILENAME%.tex > %FILENAME%.out" & chr(10) &_
chr(10) &_
"rem Conversion of the DVI file to a SVG image" & chr(10) &_
"""" & sDvisvgmPath & """" & " -n1 -e %FILENAME%.xdv 2> %FILENAME%.dat" & chr(10) &_
")"
End If
sTexMaths = "@echo off" & chr(10) &_
chr(10) &_
"rem This script is part of the TexMaths package" & chr(10) &_
"rem http://roland65.free.fr/texmaths" & chr(10) &_
"rem" & chr(10) &_
"rem Roland Baudin (roland65@free.fr)" & chr(10) &_
chr(10) &_
"rem Process the options" & chr(10) &_
"set EXT=%1" & chr(10) &_
"set DPI=%2" & chr(10) &_
"set TRANS=%3" & chr(10) &_
"set TMPPATH=%4" & chr(10) &_
"set FILENAME=tmpfile" & chr(10) &_
"set COMPILER=%5" & chr(10) &_
chr(10) &_
"rem Convert TMPPATH from URL to path" & chr(10) &_
"setlocal enabledelayedexpansion" & chr(10) &_
"set TMPPATH=%TMPPATH:file:///=%" & chr(10) &_
"set TMPPATH=%TMPPATH:/=\%" & chr(10) &_
"set TMPPATH=!TMPPATH:%%20= !" & chr(10) &_
"set TMPPATH=""%TMPPATH%""" & chr(10) &_
chr(10) &_
"rem Set Paths" & chr(10) &_
sPath & chr(10) &_
"rem Generate system log" & chr(10) &_
"call :SystemLog" & chr(10) &_
chr(10) &_
"rem Go to the tmp directory" & chr(10) &_
"if not %TMPPATH% == """" (" & chr(10) &_
" if not exist %TMPPATH% (" & chr(10) &_
" mkdir %TMPPATH%" & chr(10) &_
" )" & chr(10) &_
" cd /D %TMPPATH%" & chr(10) &_
")" & chr(10) &_
chr(10) &_
"rem Silently remove old files but not the tex file" & chr(10) &_
"del /Q *.aux >nul 2>&1" & chr(10) &_
"del /Q *.bsl >nul 2>&1" & chr(10) &_
"del /Q *.dvi >nul 2>&1" & chr(10) &_
"del /Q *.xdv >nul 2>&1" & chr(10) &_
"del /Q *.log >nul 2>&1" & chr(10) &_
"del /Q *.out >nul 2>&1" & chr(10) &_
"del /Q *.dat >nul 2>&1" & chr(10) &_
"del /Q *.png >nul 2>&1" & chr(10) &_
"del /Q *.svg >nul 2>&1" & chr(10) &_
chr(10) &_
"rem Compile using latex" & chr(10) &_
"if ""%COMPILER%"" == ""latex"" (" & chr(10) &_
chr(10) &_
"rem Creation of the DVI file" & chr(10) &_
"""" & sLatexPath & """" & " -shell-escape -interaction=nonstopmode %FILENAME%.tex > %FILENAME%.out" & chr(10) &_
chr(10) &_
sDvisvgmCmd & chr(10) &_
sDvipngCmd & chr(10) &_
sXelatexCmd & chr(10) &_
"Goto :EOF"& chr(10) &_
chr(10) &_
"rem Function used to generate system log" & chr(10) &_
":SystemLog" & chr(10) &_
chr(10) &_
"set SYSLOG=%TMPPATH%..\System.log" & chr(10) &_
"rem del %SYSLOG%" & chr(10) &_
"for /f ""tokens=*"" %%a in ('VER') do set VERSION=%%a" & chr(10) &_
"echo osType= %VERSION% > %SYSLOG%" & chr(10) &_
"echo. >> %SYSLOG%" & chr(10) &_
"echo PATH= %PATH% >> %SYSLOG%" & chr(10) &_
chr(10) &_
"Goto :EOF"
' => Linux or MacOSX: generate a shell script
Else
' Paths
sPath = "cpu=$(uname -p)" & chr(10) &_
"mac=$(uname -m)" & chr(10) &_
"sys=$(uname -s)" & chr(10) &_
"[ ""$cpu"" = ""powerpc"" -o ""$mac"" = ""ppc"" ] && cpuType=ppc || cpuType=i386 " & chr(10) &_
"[ ""$sys"" = ""Darwin"" ] && osType=MacOSX || osType=Linux " & chr(10) &_
"UserDir=""" & ConvertFromURL(glb_UserPath) & """" & chr(10) &_
"PkgDir=""" & ConvertFromURL(glb_PkgPath) & """" & chr(10) &_
chr(10) &_
"PATH=""${PkgDir}bin/${osType}${cpuType}:$PATH""" & chr(10) &_
"PATH=""" & sBasePath & ":$PATH""" & chr(10) &_
"export PATH" & chr(10) &_
chr(10)
' Script
If sDvipngPath = "" Then
sDvipngCmd = ""
Else
sDvipngCmd = "# Conversion of the DVI file to a PNG image" & chr(10) &_
"if [ -f ${filename}.dvi ]" & chr(10) &_
"then" & chr(10) &_
"if [ ""${ext}"" = ""png"" ]" & chr(10) &_
"then" & chr(10) &_
"if [ ""${Trans}"" = ""TRUE"" ]" & chr(10) &_
"then" & chr(10) &_
" " & """" & sDvipngPath & """" & " -q -T tight -bg Transparent --width --height --depth -D ${dpi} -o ${filename}.png ${filename}.dvi > ${filename}.dat" & chr(10) &_
"else" & chr(10) &_
" " & """" & sDvipngPath & """" & " -q -T tight --width --height --depth -D ${dpi} -o ${filename}.png ${filename}.dvi > ${filename}.dat" & chr(10) &_
"fi" & chr(10) &_
"fi" & chr(10) &_
"fi"
End If
If sDvisvgmPath = "" Then
sDvisvgmCmd = ""
Else
sDvisvgmCmd = "# Conversion of the DVI file to a SVG image" & chr(10) &_
"if [ -f ${filename}.dvi ]" & chr(10) &_
"then" & chr(10) &_
"if [ ""${ext}"" = ""svg"" ]" & chr(10) &_
"then" & chr(10) &_
" " & """" & sDvisvgmPath & """" & " -n1 -e ${filename}.dvi > ${filename}.dat 2>&1" & chr(10) &_
"fi" & chr(10) &_
"fi"
End If
If sXelatexPath = "" Then
sXelatexCmd = "fi"
Else
sXelatexCmd = "# Compile using xelatex" & chr(10) &_
"else" & chr(10) &_
"""" & sXelatexPath & """" & " -no-pdf -shell-escape -interaction=nonstopmode ${filename}.tex > ${filename}.out" & chr(10) &_
"# Conversion of the XDV file to a SVG image" & chr(10) &_
"if [ -f ${filename}.xdv ]" & chr(10) &_
"then" & chr(10) &_
"""" & sDvisvgmPath & """" & " -n1 -e ${filename}.xdv > ${filename}.dat 2>&1" & chr(10) &_
"fi" & chr(10) &_
"fi"
End If
sTexMaths = "#!/bin/sh" & chr(10) &_
"#" & chr(10) &_
"# This script is part of the TexMaths package" & chr(10) &_
"# http://roland65.free.fr/texmaths" & chr(10) &_
"#" & chr(10) &_
"# Roland Baudin (roland65@free.fr)" & chr(10) &_
chr(10) &_
"# Function used to generate system log" & chr(10) &_
"SystemLog(){" & chr(10) &_
"syslog=${UserDir}System.log" & chr(10) &_
"uname -a > ""$syslog""" & chr(10) &_
"echo """" >> ""$syslog""" & chr(10) &_
"echo ""osType=$osType"" >> ""$syslog""" & chr(10) &_
"echo ""cpuType=$cpuType"" >> ""$syslog""" & chr(10) &_
"echo """" >> ""$syslog""" & chr(10) &_
"echo ""PATH=$PATH"" >> ""$syslog""" & chr(10) &_
"echo """" >> ""$syslog""" & chr(10) &_
"}" & chr(10) &_
chr(10) &_
"# Definition of PATH and binary paths" & chr(10) &_
sPath & chr(10) &_
"# Process the options" & chr(10) &_
"ext=$1" & chr(10) &_
"dpi=$2" & chr(10) &_
"Trans=""$3""" & chr(10) &_
"tmpPath=""$4""" & chr(10) &_
"filename=tmpfile" & chr(10) &_
"compiler=$5" & chr(10) &_
chr(10) &_
"# Generate system log" & chr(10) &_
"SystemLog" & chr(10) &_
chr(10) &_
"# Go to the tmp directory" & chr(10) &_
"if [ ""$tmpPath"" != """" ] " & chr(10) &_
"then" & chr(10) &_
" [ ! -d ""$tmpPath"" ] && mkdir -p ""$tmpPath""" & chr(10) &_
" cd ""$tmpPath""" & chr(10) &_
"fi" & chr(10) &_
chr(10) &_
"# Remove old files but not the tex file" & chr(10) &_
"mv ${filename}.tex tmptex.tex" & chr(10) &_
"rm ${filename}*.* >/dev/null 2>&1" & chr(10) &_
"mv tmptex.tex ${filename}.tex" & chr(10) &_
chr(10) &_
"# Compile using latex" & chr(10) &_
"if [ ""${compiler}"" = ""latex"" ]" & chr(10) &_
"then" & chr(10) &_
"""" & sLatexPath & """" & " -shell-escape -interaction=nonstopmode ${filename}.tex > ${filename}.out" & chr(10) &_
chr(10) &_
sDvisvgmCmd & chr(10) &_
sDvipngCmd & chr(10) &_
chr(10) &_
sXelatexCmd & chr(10) &_
chr(10)
End if
oTextStream.setOutputStream(oFileAccess.openFileWrite(cURL))
oTextStream.writeString( sTexMaths )
oTextStream.closeOutput()
' On Windows, hide the script file because it is located in C:\ and the user should not see it
If getGUIType() = 1 Then
SetAttr( GetScriptDir() ,2 ) ' 2 => hidden attribute
End If
End Sub
</script:module>
|