Skip to content

Commit

Permalink
Implement Open in Terminal for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 15, 2018
1 parent 326a74f commit 30692fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/native/win/qgswinnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QString>
#include <QDir>
#include <QWindow>
#include <QProcess>
#include <QAbstractEventDispatcher>
#include <QtWinExtras/QWinTaskbarButton>
#include <QtWinExtras/QWinTaskbarProgress>
Expand Down Expand Up @@ -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" };
Expand Down
3 changes: 2 additions & 1 deletion src/native/win/qgswinnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 30692fa

Please sign in to comment.