/** * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved. * * DirectDistanceEntry handling added 2013 by Robert S. * * This file is part of the QCAD project. * * QCAD 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 3 of the License, or * (at your option) any later version. * * QCAD 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 QCAD. */ include("scripts/EAction.js"); include("scripts/WidgetFactory.js"); function CommandLine(guiAction) { EAction.call(this, guiAction); } CommandLine.getPreferencesCategory = function() { return [ qsTr("Widgets"), qsTr("Command Line") ]; }; CommandLine.prototype = new EAction(); /** * Shows / hides the command line widget. */ CommandLine.prototype.beginEvent = function() { EAction.prototype.beginEvent.call(this); var appWin = RMainWindowQt.getMainWindow(); var dock = appWin.findChild("CommandLineDock"); if (!RSettings.getOriginalArguments().contains("-no-show")) { dock.visible = !dock.visible; if (dock.visible) dock.raise(); } }; CommandLine.prototype.finishEvent = function() { EAction.prototype.finishEvent.call(this); var appWin = RMainWindowQt.getMainWindow(); var dock = appWin.findChild("CommandLineDock"); this.getGuiAction().setChecked(dock.visible); }; //CommandLine.initStyle = function() { // var appWin = RMainWindowQt.getMainWindow(); // var formWidget = appWin.findChild("CommandLine"); // var frame = formWidget.findChild("Frame"); // var p = frame.palette; // if (!RSettings.hasDarkGuiBackground()) { // // white background of command line label: // p.setColor(QPalette.Active, QPalette.Window, new QColor(Qt.white)); // } // else { // p.setColor(QPalette.Active, QPalette.Window, new QColor("#1e1e1e")); // } // frame.palette = p; // frame.autoFillBackground = true; // frame.repaint(); //} CommandLine.blue = ""; CommandLine.infoBlue = ""; CommandLine.red = ""; CommandLine.initColors = function() { var oldBlue = CommandLine.blue; var oldInfoBlue = CommandLine.infoBlue; var oldRed = CommandLine.red; if (RSettings.hasDarkGuiBackground()) { CommandLine.blue = "#2E9AFF"; CommandLine.infoBlue = "#91c1ff"; CommandLine.red = "#FF6060"; } else { CommandLine.blue = "#0000CC"; CommandLine.infoBlue = "#0066CC"; CommandLine.red = "#CC0000"; } var replacements = []; if (oldBlue!==CommandLine.blue && oldBlue.length>0) { replacements.push([oldBlue, CommandLine.blue]); } if (oldInfoBlue!==CommandLine.infoBlue && oldInfoBlue.length>0) { replacements.push([oldInfoBlue, CommandLine.infoBlue]); } if (oldRed!==CommandLine.red && oldRed.length>0) { replacements.push([oldRed, CommandLine.red]); } var appWin = RMainWindowQt.getMainWindow(); var formWidget = appWin.findChild("CommandLine"); var teHistory = formWidget.findChild("History"); if (replacements.length>0) { var s = teHistory.html; for (var i=0; i," by selecting // the entities with the given IDs: teHistory.openLinks = false; teHistory.anchorClicked.connect(function(url) { var di = appWin.getDocumentInterface(); if (isNull(di)) { return; } if (!url.hasFragment()) { return; } var frag = url.fragment(); var entityIds = frag.split(","); for (var i=0; i historySize) { teHistory.setPlainText(buf.slice(-historySize).join("\n")); } leCommand.setFocus(); }); // user pressed tab: leCommand.completeCommand.connect(function(command) { var choices = RGuiAction.getAvailableCommands(command, true); if (choices.length === 0) { // no commands match. beep? } else if (choices.length == 1) { // only one command matches. complete it: leCommand.text = choices[0]; } else { // suggest multiple commands that match so far: appendAndScroll(choices.join(", ")); // complete as much as possible: var done = false; var i = command.length; do { for (var k=0; k" + message + ""); }); // show warning to user: appWin.userWarning.connect(function(message, messageBox, escape) { // TODO: refactor: if (message==="#transaction_failed") { message = qsTr("Transaction failed. Please check for block recursions and locked or invisible layers or blocks."); } if (escape) { message = RS.escape(message); // workaround for Qt showing " in label: message = message.replace(/"/g, "\""); } appendAndScroll("" + message + ""); if (RSettings.getBoolValue("CommandLine/WarningsAsDialog", false) || messageBox) { QMessageBox.warning(appWin, qsTr("Warning"), message); } }); // show info to user: appWin.userInfo.connect(function(message, escape) { if (escape) { message = RS.escape(message); } appendAndScroll("" + message + ""); if (RSettings.getBoolValue("CommandLine/InfoAsDialog", false)) { QMessageBox.information(appWin, qsTr("Info"), message); } }); // show previously entered command: appWin.userCommand.connect(function(message, escape) { // prevent some very frequent commands from being displayed every time: if (message==="snapauto" || message==="restrictoff" || message==="escape") { return; } var msgEsc = message; if (escape) { msgEsc = RS.escape(message); } var cartCoordSep = RSettings.getStringValue("Input/CartesianCoordinateSeparator", ','); var polCoordSep = RSettings.getStringValue("Input/PolarCoordinateSeparator", '<'); var what; if (message.startsWith("=")) { what = qsTr("Expression"); } else if (message.contains(cartCoordSep) || message.contains(polCoordSep)) { what = qsTr("Coordinate"); } else { what = qsTr("Command"); } leCommand.appendCommand(message); appendAndScroll( "" + "" + what + ": " + msgEsc + ""); }); // change command prompt label: appWin.commandPrompt.connect(function(text) { if (text.length===0) { lCommand.text = qsTr("Command:") + " "; } else { lCommand.text = text + qsTr(": "); } }); var system; switch (RS.getSystemId()) { case "win": system = "Windows"; break; case "osx": system = "macOS"; break; case "linux": system = "Linux"; break; case "freebsd": system = "FreeBSD"; break; case "netbsd": system = "NetBSD"; break; case "openbsd": system = "OpenBSD"; break; case "solaris": system = "Solaris"; break; } EAction.handleUserMessage( "%1 %2 / Qt %3 / %4 %5" .arg(qApp.applicationName) .arg(RSettings.getVersionString()) .arg(RSettings.getQtVersionString()) .arg(system) .arg(RS.getBuildCpuArchitecture()) ); var pl = new RPaletteListenerAdapter(); appWin.addPaletteListener(pl); pl.paletteChanged.connect(CommandLine.initColors); };