Skip to content
Permalink
Browse files

Implement Open in Terminal for windows

  • Loading branch information
nyalldawson committed Nov 15, 2018
1 parent 326a74f commit 30692fa9a3f641260dff4c6039155009e1c08981
Showing with 25 additions and 1 deletion.
  1. +23 −0 src/native/win/qgswinnative.cpp
  2. +2 −1 src/native/win/qgswinnative.h
@@ -21,6 +21,7 @@
#include <QString>
#include <QDir>
#include <QWindow>
#include <QProcess>
#include <QAbstractEventDispatcher>
#include <QtWinExtras/QWinTaskbarButton>
#include <QtWinExtras/QWinTaskbarProgress>
@@ -200,6 +201,28 @@ QgsNative::NotificationResult QgsWinNative::showDesktopNotification( const QStri
return result;
}

bool QgsWinNative::openTerminalAtPath( const QString &path )
{
// logic from https://github.com/Microsoft/vscode/blob/fec1775aa52e2124d3f09c7b2ac8f69c57309549/src/vs/workbench/parts/execution/electron-browser/terminal.ts#L44
const bool isWow64 = qEnvironmentVariableIsSet( "PROCESSOR_ARCHITEW6432" );
QString windir = qgetenv( "WINDIR" );
if ( windir.isEmpty() )
windir = QStringLiteral( "C:\\Windows" );
const QString term = QStringLiteral( "%1\\%2\\cmd.exe" ).arg( windir, isWow64 ? QStringLiteral( "Sysnative" ) : QStringLiteral( "System32" ) );

QProcess process;
process.setProgram( term );
process.setCreateProcessArgumentsModifier( []( QProcess::CreateProcessArguments * args )
{
args->flags |= CREATE_NEW_CONSOLE;
args->startupInfo->dwFlags &= ~ STARTF_USESTDHANDLES;
} );
process.setWorkingDirectory( path );

qint64 pid;
return process.startDetached( &pid );
}

bool QgsWinNativeEventFilter::nativeEventFilter( const QByteArray &eventType, void *message, long * )
{
static const QByteArray sWindowsGenericMSG{ "windows_generic_MSG" };
@@ -63,11 +63,12 @@ class NATIVE_EXPORT QgsWinNative : public QgsNative
void hideApplicationProgress() override;
void onRecentProjectsChanged( const std::vector< RecentProjectProperties > &recentProjects ) override;
NotificationResult showDesktopNotification( const QString &summary, const QString &body, const NotificationSettings &settings = NotificationSettings() ) override;
bool openTerminalAtPath( const QString &path ) override;

private:

QWindow *mWindow = nullptr;
Capabilities mCapabilities = NativeFilePropertiesDialog;
Capabilities mCapabilities = NativeFilePropertiesDialog | NativeOpenTerminalAtPath;
bool mWinToastInitialized = false;
QWinTaskbarButton *mTaskButton = nullptr;
QWinTaskbarProgress *mTaskProgress = nullptr;

0 comments on commit 30692fa

Please sign in to comment.
You can’t perform that action at this time.