autostart.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("library.js");
  20. include("AddOn.js");
  21. include("scripts/File/OpenFile/OpenFile.js");
  22. include("scripts/File/AutoSave/AutoSave.js");
  23. include("scripts/Tools/arguments.js");
  24. // allow plugins to extend autostart through autostart1.js, autostart2.js, ...:
  25. for (var i=1; i<10; i++) {
  26. var fn = "scripts/autostart" + i + ".js";
  27. if (new QFileInfo(fn).exists() || new QFileInfo(":/" + fn).exists()) {
  28. include(fn);
  29. }
  30. }
  31. /**
  32. * Prints version information.
  33. */
  34. function version() {
  35. print();
  36. print("Version: " + RSettings.getVersionString());
  37. print("Qt Version: " + RSettings.getQtVersionString());
  38. print("Release Date: " + RSettings.getReleaseDate());
  39. print();
  40. }
  41. /**
  42. * Prints command line usage information on stdout.
  43. */
  44. function usage() {
  45. print("\nUsage: " + RSettings.getOriginalArguments()[0] + " [Options] [Files to open]\n"
  46. + "\n"
  47. + "-allow-multiple-instances Don't try to avoid multiple instances from running\n"
  48. + " simultaneously.\n"
  49. + "-always-load-scripts Forces reloading of scripts when they are used.\n"
  50. + " This is mainly useful during script development,\n"
  51. + " to apply changes without restarting QCAD.\n"
  52. + "-app-id [ID] Set application ID. Multiple instances of the\n"
  53. + " same application (same ID) cannot run\n"
  54. + " simultaneously unless -allow-multiple-instances\n"
  55. + " is used.\n"
  56. + "-autostart [script file] Starts the given script file instead of the default\n"
  57. + " scripts/autostart.js. Note that with this option,\n"
  58. + " QCAD is not started but rather the application \n"
  59. + " implemented in the given script.\n"
  60. + "-config [path] Reads and stores settings in a configuration file\n"
  61. + " at the given location instead of the default location.\n"
  62. + "-debug-action-order Print action order information in menus\n"
  63. + "-enable-script-debugger Enables the script debugger.\n"
  64. + " NOT recommended as this may cause unexpected\n"
  65. + " behavior when using QCAD.\n"
  66. + "-exec [script file] [options] Executes the given script file directly\n"
  67. + " after staring QCAD. Options after the script\n"
  68. + " file are passed on to the script.\n"
  69. + "-help Displays this help.\n"
  70. + "-ignore-script-files Ignore script files on disk.\n"
  71. + " Only load scripts from plugins if applicable.\n"
  72. + "-locale [locale] Sets the locale to be used (overrides\n"
  73. + " the language set in the preferences).\n"
  74. + " E.g. '-locale de' starts QCAD in German.\n"
  75. + "-no-gui Don't use GUI. X11: don't connect to X11 server.\n"
  76. + "-no-show Use but don't display GUI.\n"
  77. + "-filter [filter] Opens the subsequent file(s) with the explicitly \n"
  78. + " given import filter.\n"
  79. + "-font-substitution A B Substitute font A with font B.\n"
  80. + "-rescan Rescan scripts folder for new add-ons\n"
  81. + "-version Displays the application version.\n"
  82. + "-enable-xdata Enables XData (custom properties) support.\n"
  83. + "-quit Quits QCAD, for example after executing the\n"
  84. + " given script(s).\n"
  85. );
  86. printGenericUsage();
  87. print("\n");
  88. }
  89. /**
  90. * Executes the scripts that are given as arguments of -exec.
  91. * \return true if the application should quit after executing the
  92. * scripts, false otherwise.
  93. */
  94. function execScripts(args) {
  95. for (var i = 1; i < args.length; ++i) {
  96. if (args[i] === "-exec") {
  97. ++i;
  98. if (isNull(args[i])) {
  99. break;
  100. }
  101. // check for existing action (e.g. "scripts/File/NewFile/NewFile.js"):
  102. var action = RGuiAction.getByScriptFile(args[i]);
  103. // script is not an existing action:
  104. if (isNull(action)) {
  105. // include (run) script which might or might not be action:
  106. var scriptFile = args[i];
  107. var scriptFilePath = getAbsolutePathForArg(scriptFile);
  108. if (new QFileInfo(scriptFilePath).exists()) {
  109. // including the script evaluates (runs) it:
  110. include(scriptFilePath);
  111. // check if script created a class of same name as file base name:
  112. var fi = new QFileInfo(scriptFile);
  113. var className = fi.baseName();
  114. if (!isNull(global[className])) {
  115. // gui action might not exist yet for this script, create one:
  116. action = new RGuiAction("");
  117. action.setScriptFile(scriptFilePath);
  118. action.setRequiresDocument(false);
  119. }
  120. }
  121. else {
  122. qWarning("script not found: ", args[i]);
  123. }
  124. }
  125. // script is action or created action:
  126. if (!isNull(action)) {
  127. ++i;
  128. // handle script arguments:
  129. while (!isNull(args[i]) && args[i] !== "-exec") {
  130. action.addArgument(args[i]);
  131. ++i;
  132. }
  133. --i;
  134. action.slotTrigger();
  135. }
  136. }
  137. if (args[i] === "-quit") {
  138. RSettings.setQuitFlag();
  139. }
  140. }
  141. }
  142. /**
  143. * Sets up drag and drop support (dropping files on the application window
  144. * opens them).
  145. */
  146. function setUpDragAndDrop(appWin) {
  147. appWin.dragEnter.connect(function(event) {
  148. event.acceptProposedAction();
  149. });
  150. appWin.drop.connect(function(event) {
  151. // workaround for Qt keyboard focus bug:
  152. var appWin = RMainWindowQt.getMainWindow();
  153. if (!isNull(appWin)) {
  154. appWin.activateWindow();
  155. appWin.raise();
  156. appWin.setFocus(Qt.OtherFocusReason);
  157. }
  158. var urls = getUrlsFromMimeData(event.mimeData());
  159. var urlStrings = [];
  160. for (var i = 0; i < urls.length; ++i) {
  161. urlStrings.push(urls[i].toString());
  162. }
  163. openFiles(urlStrings, false);
  164. event.acceptProposedAction();
  165. });
  166. }
  167. /**
  168. * Loads translations for all add-ons if appropriate.
  169. */
  170. function loadTranslations(addOns, splash) {
  171. var locale = RSettings.getLocale();
  172. if (!isNull(splash)) {
  173. // no translations yet:
  174. splash.showMessage("Loading translations...\n", Qt.AlignBottom);
  175. }
  176. // load C++ translations:
  177. var modules = ["qt", "assistant", "qt_help", "qcadcore", "qcadentity", "qcadgui"];
  178. if (RSettings.isQt(5) || RSettings.isQt(6)) {
  179. modules.unshift("qtbase");
  180. }
  181. var i;
  182. var module;
  183. for (var mi=0; mi<modules.length; ++mi) {
  184. module = modules[mi];
  185. RSettings.loadTranslations(module);
  186. }
  187. //RSettings.loadTranslations("scripts_" + locale, [autoPath("scripts/ts")]);
  188. // load translations from arguments:
  189. var args = RSettings.getOriginalArguments();
  190. for (i = 0; i < args.length; ++i) {
  191. if (args[i] === "-ts") {
  192. if (++i>=args.length) {
  193. break;
  194. }
  195. module = args[i];
  196. if (++i>=args.length) {
  197. break;
  198. }
  199. var dir = args[i];
  200. RSettings.loadTranslations(module, [autoPath(dir)]);
  201. }
  202. }
  203. // RSettings.loadTranslations("scripts", [autoPath("ts")]);
  204. // RSettings.loadTranslations("proscripts", [autoPath("../qcadpro/ts")]);
  205. // RSettings.loadTranslations("camscripts", [autoPath("../qcadcam/ts")]);
  206. // install one QTranslator for each script add-on if available:
  207. if (!isNull(splash)) {
  208. splash.showMessage(qsTr("Loading add-on translations...") + "\n", Qt.AlignBottom);
  209. QCoreApplication.processEvents();
  210. }
  211. //RSettings.loadTranslations("Scripts_" + locale, [autoPath("scripts/ts")]);
  212. for (i = 0; i < addOns.length; ++i) {
  213. var addOn = addOns[i];
  214. if (isNull(addOn)) {
  215. qWarning("Null add on found");
  216. continue;
  217. }
  218. var fi = new QFileInfo(addOn.getPath() + "/ts");
  219. if (!fi.exists()) {
  220. // no ts dir:
  221. continue;
  222. }
  223. RSettings.loadTranslations(addOn.getClassName(), [addOn.getPath() + "/ts"]);
  224. }
  225. }
  226. /**
  227. * Loads and initializes all add-ons.
  228. *
  229. * \param addOns array of AddOn objects.
  230. * \param splash the splash window for displaying status updates.
  231. */
  232. function loadAddOns(addOns, splash) {
  233. if (!isNull(splash)) {
  234. splash.showMessage(qsTr("Loading add-ons...") + "\n", Qt.AlignBottom);
  235. QCoreApplication.processEvents();
  236. }
  237. var addOn;
  238. var i;
  239. for (i=0; i<addOns.length; ++i) {
  240. addOn = addOns[i];
  241. addOn.load(true);
  242. }
  243. }
  244. function initAddOns(addOns, splash) {
  245. if (!isNull(splash)) {
  246. splash.showMessage(qsTr("Initializing add-ons...") + "\n", Qt.AlignBottom);
  247. QCoreApplication.processEvents();
  248. }
  249. var addOn;
  250. var i;
  251. var text = "";
  252. for (i=0; i<addOns.length; ++i) {
  253. addOn = addOns[i];
  254. if (i%10===0 && !isNull(splash)) {
  255. text = qsTr("Initializing add-ons:") +
  256. " %1%\n%2"
  257. .arg(Math.round(i/addOns.length*100))
  258. .arg(addOn.getClassName());
  259. splash.showMessage(text, Qt.AlignBottom);
  260. QCoreApplication.processEvents();
  261. }
  262. addOn.init(splash, text);
  263. }
  264. }
  265. function postInitAddOns(addOns, splash) {
  266. // if (!isNull(splash)) {
  267. // splash.showMessage(qsTr("Post-initializing add-ons...") + "\n", Qt.AlignBottom);
  268. // QCoreApplication.processEvents();
  269. // }
  270. var addOn;
  271. var i;
  272. var viewToolBarsAddOn = undefined;
  273. for (i=0; i<addOns.length; ++i) {
  274. addOn = addOns[i];
  275. if (addOn.getClassName()==="ViewToolbars") {
  276. viewToolBarsAddOn = addOn;
  277. }
  278. else {
  279. addOn.postInit();
  280. }
  281. }
  282. if (!isNull(viewToolBarsAddOn)) {
  283. viewToolBarsAddOn.postInit();
  284. }
  285. }
  286. function uninitAddOns(addOns) {
  287. var addOn;
  288. var i;
  289. for (i=0; i<addOns.length; ++i) {
  290. addOn = addOns[i];
  291. addOn.uninit();
  292. }
  293. }
  294. /**
  295. * Loads the add-ons and starts QCAD.
  296. */
  297. function main() {
  298. var i;
  299. var filesToOpen = [];
  300. // open file that was clicked in Finder if application was not yet running (macOS):
  301. qApp.fileOpenRequestReceived.connect(function(fileName) {
  302. filesToOpen.push(fileName);
  303. });
  304. // open file(s) given on command line when application is started but
  305. // already running:
  306. qApp.messageReceived.connect(function(message) {
  307. var args = message.split("\n");
  308. openFiles(args.slice(1), false);
  309. execScripts(args);
  310. });
  311. var args = RSettings.getOriginalArguments();
  312. if (args.contains("-help") || args.contains("-h")) {
  313. usage();
  314. return;
  315. }
  316. if (args.contains("-version") || args.contains("-v")) {
  317. version();
  318. return;
  319. }
  320. if (args.contains("-enable-xdata")) {
  321. RSettings.setXDataEnabled(true);
  322. }
  323. // app name for ini file differs to avoid conflict with
  324. // older QCAD versions:
  325. // note that a plugin might have set a name override already:
  326. if (!RSettings.hasApplicationNameOverride()) {
  327. RSettings.setApplicationNameOverride("QCAD3");
  328. }
  329. // make sure settings file path is reinitialized:
  330. RSettings.uninit();
  331. // alternative path for QCAD3.ini:
  332. for (i=1; i<args.length; ++i) {
  333. if (args[i] === "-config") {
  334. ++i;
  335. if (i < args.length) {
  336. QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, getAbsolutePathForArg(args[i]));
  337. }
  338. }
  339. }
  340. // ignore config file if it does not identify itself with a version
  341. // number or is known as being incompatible
  342. var reset = false;
  343. var ignoreDockappWindows = false;
  344. var newVersion = false;
  345. if (RSettings.getStringValue("Application/Version", "").length===0) {
  346. reset = true;
  347. }
  348. // Prevent errors with old configuration files:
  349. // QCAD 3 Beta
  350. if (RSettings.getIntValue("Application/Version", 0)<=3000003) {
  351. reset = true;
  352. }
  353. // Prevent errors with old configuration files:
  354. // QCAD 3 RC2/3: Reset toolbar location
  355. if (RSettings.hasValue("Application/Version") && RSettings.getIntValue("Application/Version", 0)<=3000006) {
  356. ignoreDockappWindows = true;
  357. }
  358. // Prevent errors with old configuration files:
  359. // QCAD 3 <= RC5: grid color without alpha, RC6: alpha added, ignore some color settings:
  360. if (RSettings.getIntValue("Application/Version", 0)<=3000008) {
  361. RSettings.removeValue("GraphicsViewColors/MetaGridColor");
  362. RSettings.removeValue("GraphicsViewColors/OriginColor");
  363. RSettings.removeValue("GraphicsViewColors/RelativeZeroColor");
  364. RSettings.removeValue("GraphicsViewColors/GridColor");
  365. RSettings.removeValue("GraphicsViewColors/SelectionColor");
  366. }
  367. if (RSettings.getStringValue("Application/Version", "")!==RSettings.getNumericalVersionString()) {
  368. newVersion = true;
  369. }
  370. if (reset===true) {
  371. var configFile = RSettings.getFileName();
  372. RSettings.uninit();
  373. var fi = new QFileInfo(configFile);
  374. if (fi.exists()) {
  375. var configPath = fi.absolutePath();
  376. var configBak = configPath + QDir.separator + fi.baseName() + "_old." + fi.suffix();
  377. qDebug("Renaming old unversioned config file from '" + configFile + "' to '"+ configBak + "'");
  378. QFile.remove(configBak);
  379. QFile.rename(configFile, configBak);
  380. }
  381. }
  382. // detect very first start of this installation:
  383. var fiSettings = new QFileInfo(RSettings.getFileName());
  384. var isFirstStart = !fiSettings.exists();
  385. var numPlugins = RPluginLoader.countPlugins();
  386. var pluginInfo;
  387. // look up app name override:
  388. for (i=0; i<numPlugins; i++) {
  389. pluginInfo = RPluginLoader.getPluginInfo(i);
  390. var n = pluginInfo.get("NameOverride", "");
  391. if (n.length>0) {
  392. qApp.applicationName = n;
  393. }
  394. }
  395. // if locale is given, don't show first start dialog:
  396. if (isFirstStart && !args.contains("-locale")) {
  397. include("scripts/Widgets/FirstStart/FirstStart.js");
  398. var first = new FirstStart();
  399. first.showDialog();
  400. }
  401. RPluginLoader.initTranslations();
  402. // correct library paths from 'library' to 'libraries':
  403. if (RSettings.getIntValue("Application/Version", 0)<=3000008) {
  404. var oldDefaultSource = new QFileInfo("library").absoluteFilePath();
  405. var librarySources = RSettings.getValue("LibraryBrowser/SourceList", []);
  406. if (!isNull(librarySources)) {
  407. for (i=0; i<librarySources.length; i++) {
  408. if (new QFileInfo(librarySources[i]).absoluteFilePath()===oldDefaultSource) {
  409. librarySources[i] = new QFileInfo("libraries/default").absoluteFilePath();
  410. }
  411. }
  412. RSettings.setValue("LibraryBrowser/SourceList", librarySources);
  413. }
  414. }
  415. // theme:
  416. applyTheme();
  417. // native / non-native menubar:
  418. if (RSettings.getBoolValue("MenuBar/UseNativeMenuBar", true)===false) {
  419. QCoreApplication.setAttribute(Qt.AA_DontUseNativeMenuBar);
  420. }
  421. // splash:
  422. var splash = undefined;
  423. if (RSettings.getBoolValue("Startup/EnableSplashScreen", true)) {
  424. var fn;
  425. var key;
  426. if (RSettings.getDevicePixelRatio()===2) {
  427. key = "SplashOverride@2x";
  428. fn = "scripts/splashscreen@2x.png";
  429. }
  430. else {
  431. key = "SplashOverride";
  432. fn = "scripts/splashscreen.png";
  433. }
  434. // look up slash screen override:
  435. var maxPri = undefined;
  436. for (i=0; i<numPlugins; i++) {
  437. pluginInfo = RPluginLoader.getPluginInfo(i);
  438. // override priority:
  439. var pri = pluginInfo.get("OverridePriority");
  440. if (!isNull(pri)) {
  441. pri = parseInt(pri);
  442. }
  443. else {
  444. // default to lowest priority:
  445. pri = 0;
  446. }
  447. if (isNull(maxPri) || pri>maxPri) {
  448. var s = pluginInfo.get(key);
  449. if (!isNull(s)) {
  450. fn = s;
  451. maxPri = pri;
  452. }
  453. }
  454. }
  455. var pixmap = new QPixmap(fn);
  456. splash = new QSplashScreen(pixmap);
  457. splash.objectName = "Splash";
  458. if (!args.contains("-no-show")) {
  459. splash.show();
  460. }
  461. }
  462. RFontList.initSubstitutions();
  463. // mark config file with current version number:
  464. var previousVersion = RSettings.getStringValue("Application/Version", "");
  465. RSettings.setValue("Application/Version", RSettings.getNumericalVersionString());
  466. // save first start information:
  467. RSettings.setFirstStart(isFirstStart);
  468. // save new version information:
  469. RSettings.setNewVersion(newVersion);
  470. RSettings.setPreviousVersion(parseInt(previousVersion, 10));
  471. RPluginLoader.postInitPlugins(RPluginInterface.GotSplashWindow);
  472. // scan for script add-ons (forced for first start, first start after
  473. // update, if configured):
  474. var addOns;
  475. var addOnFilePaths = RSettings.getValue("AddOns/List", []);
  476. if (addOnFilePaths.length===0 || newVersion ||
  477. args.contains("-rescan") ||
  478. RSettings.getBoolValue("Scripting/Rescan", true)===true) {
  479. if (!isNull(splash)) {
  480. // no translations yet:
  481. splash.showMessage("...\n", Qt.AlignBottom);
  482. QCoreApplication.processEvents();
  483. }
  484. addOns = AddOn.getAddOns();
  485. var addOnList = [];
  486. for (i = 0; i < addOns.length; ++i) {
  487. addOnList.push(addOns[i].getFilePath());
  488. }
  489. RSettings.setValue("AddOns/List", addOnList);
  490. }
  491. else {
  492. addOns = [];
  493. for (i=0; i<addOnFilePaths.length; i++) {
  494. addOns.push(new AddOn(addOnFilePaths[i]));
  495. }
  496. }
  497. // load add-on translations:
  498. loadTranslations(addOns, splash);
  499. // create application window:
  500. var appWin = new RMainWindowQt();
  501. // Note: animated MUST be true for Qt 5.7:
  502. // Qt 5.7.0 will not allow tabifying dock widgets if animations are turned off:
  503. if (RSettings.getQtVersion()<0x050600) {
  504. // animated must be false for Qt 4.7.2, 5.6.0 (crashes):
  505. appWin.animated = false;
  506. }
  507. appWin.objectName = "MainWindow";
  508. appWin.windowTitle = qApp.applicationName;
  509. // save locale
  510. appWin.setProperty("Locale", RSettings.getLocale());
  511. // set some object names for later look up:
  512. var menuBar = appWin.menuBar();
  513. menuBar.objectName = "MenuBar";
  514. // load add-ons:
  515. //RDebug.startTimer(0);
  516. loadAddOns(addOns, splash);
  517. //RDebug.stopTimer(0, "loading add-ons");
  518. //RDebug.startTimer(0);
  519. initAddOns(addOns, splash);
  520. //RDebug.stopTimer(0, "initializing add-ons");
  521. // auto load scripts in AutoLoad folders for global script engine:
  522. var files;
  523. if (RSettings.isQt(6)) {
  524. files = RAutoLoadJs.getAutoLoadFiles();
  525. }
  526. else {
  527. files = RAutoLoadEcma.getAutoLoadFiles();
  528. }
  529. for (i=0; i<files.length; i++) {
  530. include(files[i]);
  531. }
  532. RPluginLoader.postInitPlugins(RPluginInterface.AddOnsInitialized);
  533. addActionsToWidgets();
  534. RPluginLoader.postInitPlugins(RPluginInterface.ActionsAdded);
  535. appWin.updateGuiActions();
  536. appWin.acceptDrops = true;
  537. appWin.dockNestingEnabled = true;
  538. appWin.setCorner(Qt.TopLeftCorner, Qt.LeftDockWidgetArea);
  539. appWin.setCorner(Qt.BottomLeftCorner, Qt.LeftDockWidgetArea);
  540. appWin.setCorner(Qt.TopRightCorner, Qt.RightDockWidgetArea);
  541. appWin.setCorner(Qt.BottomRightCorner, Qt.RightDockWidgetArea);
  542. appWin.setTabPosition(Qt.RightDockWidgetArea, QTabWidget.West);
  543. appWin.setTabPosition(Qt.LeftDockWidgetArea, QTabWidget.East);
  544. appWin.setTabPosition(Qt.TopDockWidgetArea, QTabWidget.South);
  545. appWin.setTabPosition(Qt.BottomDockWidgetArea, QTabWidget.South);
  546. setUpDragAndDrop(appWin);
  547. appWin.windowIcon = new QIcon(autoPath("scripts/qcad_icon.png"));
  548. if (!ignoreDockappWindows) {
  549. appWin.readSettings();
  550. }
  551. RPluginLoader.postInitPlugins(RPluginInterface.GotMainWindowBeforeShow);
  552. if (!args.contains("-no-show")) {
  553. appWin.show();
  554. }
  555. if (!isNull(splash)) {
  556. splash.close();
  557. destr(splash);
  558. }
  559. postInitAddOns(addOns);
  560. RPluginLoader.postInitPlugins(RPluginInterface.GotMainWindow);
  561. // if the window position / size was not read from a config file,
  562. // automatically position property editor and library browser (first start):
  563. if (isFirstStart) {
  564. var propertyEditorDock = appWin.findChild("PropertyEditorDock");
  565. if (!isNull(propertyEditorDock)) {
  566. if (propertyEditorDock["Initialized"]!==true) {
  567. propertyEditorDock.floating = true;
  568. propertyEditorDock.move(appWin.x + appWin.width + 20, appWin.y);
  569. propertyEditorDock.resize(300, appWin.height/3*2);
  570. }
  571. }
  572. var libraryBrowserDock = appWin.findChild("LibraryBrowserDock");
  573. if (!isNull(libraryBrowserDock)) {
  574. if (libraryBrowserDock["Initialized"]!==true) {
  575. libraryBrowserDock.floating = true;
  576. libraryBrowserDock.move(appWin.x + appWin.width + 20, appWin.y + appWin.height/3*2+20);
  577. libraryBrowserDock.resize(300, appWin.height/3-20);
  578. }
  579. }
  580. }
  581. // open files clicked in Finder if application is already running (Mac):
  582. qApp.fileOpenRequestReceived.connect(function(fileName) {
  583. openFiles([fileName], false);
  584. });
  585. // recover auto save files:
  586. var recovered = AutoSave.recoverUntitled();
  587. // open files given on command line:
  588. var clickedFilesAndArgs = filesToOpen.concat(args.slice(1));
  589. QCoreApplication.processEvents();
  590. appWin.setProperty("starting", true);
  591. var restored = false;
  592. if (typeof(restoreFiles)=="function") {
  593. restored = restoreFiles();
  594. }
  595. openFiles(clickedFilesAndArgs, !recovered && !restored);
  596. appWin.setProperty("starting", false);
  597. RPluginLoader.postInitPlugins(RPluginInterface.LoadedFiles);
  598. // execute scripts given on command line:
  599. execScripts(args);
  600. RPluginLoader.postInitPlugins(RPluginInterface.ScriptsExecuted);
  601. //var statusBar = appWin.statusBar();
  602. //var action = RGuiAction.getByScriptFile("scripts/View/ToggleStatusBar/ToggleStatusBar.js");
  603. //action.setChecked(statusBar.visible);
  604. RPluginLoader.postInitPlugins(RPluginInterface.AllDone);
  605. appWin.setFocus();
  606. var w = appWin.getMdiChild();
  607. if (!isNull(w)) {
  608. w.setFocus();
  609. }
  610. if (!RSettings.hasQuitFlag()) {
  611. // start and enter the main application loop:
  612. QCoreApplication.exec();
  613. }
  614. uninitAddOns(addOns);
  615. // don't use RSettings below this point
  616. // and we're done:
  617. destr(appWin);
  618. qDebug("done");
  619. }
  620. // call main here, in the global context:
  621. main();