mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-03 04:00:57 -06:00
Add open in text editor feature
This commit is contained in:
parent
40c329f3ac
commit
ab44f9fa17
@ -273,6 +273,7 @@
|
||||
<file>info.png</file>
|
||||
<file>DataVector.svg</file>
|
||||
<file>DataVectorCalculated.svg</file>
|
||||
<file>open-text-editor.svg</file>
|
||||
</qresource>
|
||||
<qresource prefix="/Shader">
|
||||
<file>fs_CellFace.glsl</file>
|
||||
|
7
ApplicationExeCode/Resources/open-text-editor.svg
Normal file
7
ApplicationExeCode/Resources/open-text-editor.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">
|
||||
<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>
|
||||
<g><path d="M909.8,514.5v405.2c0,7.1-5.8,12.8-12.8,12.8H88.1c-7.1,0-12.9-5.8-12.9-12.8V110.3c0-7.1,5.8-12.8,12.9-12.8h404.7c18,0,32.6-14.6,32.6-32.6c0-18-14.6-32.6-32.6-32.6H88.1C45,32.2,10,67.2,10,110.3v809.4c0,43.1,35,78.1,78.1,78.1h808.9c43.1,0,78.1-35,78.1-78.1V514.5c0-18-14.6-32.6-32.6-32.6S909.8,496.5,909.8,514.5L909.8,514.5z M281.5,545.8l-40,144.9c-4.8,17.4,5.4,35.3,22.8,40.1c17.4,4.8,35.3-5.4,40.1-22.8l40-144.9c4.8-17.4-5.4-35.3-22.8-40.1C304.2,518.2,286.2,528.4,281.5,545.8L281.5,545.8z M283.6,731.4l169.9-30c17.7-3.1,29.6-20,26.4-37.8c-3.1-17.7-20-29.6-37.8-26.4l-169.9,30c-17.7,3.1-29.6,20-26.4,37.8C248.9,722.7,265.9,734.6,283.6,731.4L283.6,731.4z M340.9,572.5l501.2-500c6.8-6.8,17.8-6.8,24.6,0l53,53c6.8,6.8,6.8,17.8,0,24.5l-490,491.3c-12.7,12.8-12.7,33.4,0.1,46.1c12.7,12.7,33.4,12.7,46.1-0.1l490-491.2c32.2-32.2,32.2-84.5,0-116.7l-53-53c-32.3-32.2-84.5-32.2-116.8,0L294.9,526.4c-12.7,12.7-12.8,33.4-0.1,46.1C307.5,585.2,328.2,585.3,340.9,572.5L340.9,572.5z"/></g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.4 KiB |
@ -19,6 +19,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSaveProjectNoGlobalPathsFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicShowClassNamesFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicShowPlotDataCtxFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicOpenInTextEditorFeature.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@ -42,6 +43,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSaveProjectNoGlobalPathsFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicShowClassNamesFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicShowPlotDataCtxFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicOpenInTextEditorFeature.cpp
|
||||
)
|
||||
|
||||
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
||||
|
@ -1,6 +1,6 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2022 Equinor ASA
|
||||
// Copyright (C) 2023- Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -16,68 +16,42 @@
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicEditPlotTemplateFeature.h"
|
||||
#include "RicOpenInTextEditorFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "PlotTemplates/RimPlotTemplateFileItem.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimPressureDepthData.h"
|
||||
|
||||
#include "RiuPlotMainWindow.h"
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QString>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicEditPlotTemplateFeature, "RicEditPlotTemplateFeature" );
|
||||
CAF_CMD_SOURCE_INIT( RicOpenInTextEditorFeature, "RicOpenInTextEditorFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicEditPlotTemplateFeature::isCommandEnabled()
|
||||
void RicOpenInTextEditorFeature::openFileInTextEditor( const QString& filePath, QObject* parent )
|
||||
{
|
||||
std::vector<caf::PdmUiItem*> uiItems;
|
||||
caf::SelectionManager::instance()->selectedItems( uiItems );
|
||||
if ( uiItems.size() != 1 ) return false;
|
||||
|
||||
RimPlotTemplateFileItem* file = dynamic_cast<RimPlotTemplateFileItem*>( uiItems[0] );
|
||||
return ( file != nullptr );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditPlotTemplateFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
std::vector<caf::PdmUiItem*> uiItems;
|
||||
caf::SelectionManager::instance()->selectedItems( uiItems );
|
||||
|
||||
if ( uiItems.size() != 1 ) return;
|
||||
|
||||
RimPlotTemplateFileItem* file = dynamic_cast<RimPlotTemplateFileItem*>( uiItems[0] );
|
||||
if ( file == nullptr ) return;
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString scriptEditor = app->scriptEditorPath();
|
||||
if ( !scriptEditor.isEmpty() )
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString textEditorExecutablePath = app->scriptEditorPath();
|
||||
if ( !textEditorExecutablePath.isEmpty() )
|
||||
{
|
||||
QStringList arguments;
|
||||
arguments << file->absoluteFilePath();
|
||||
arguments << filePath;
|
||||
|
||||
QProcess* myProcess = new QProcess( this );
|
||||
myProcess->start( scriptEditor, arguments );
|
||||
auto* myProcess = new QProcess( parent );
|
||||
myProcess->start( textEditorExecutablePath, arguments );
|
||||
|
||||
if ( !myProcess->waitForStarted( 1000 ) )
|
||||
{
|
||||
RiaLogging::errorInMessageBox( RiuPlotMainWindow::instance(),
|
||||
RiaLogging::errorInMessageBox( Riu3DMainWindowTools::mainWindowWidget(),
|
||||
"Text editor",
|
||||
"Failed to start text editor executable\n" + scriptEditor );
|
||||
"Failed to start text editor\n" + textEditorExecutablePath );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,7 +59,40 @@ void RicEditPlotTemplateFeature::onActionTriggered( bool isChecked )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditPlotTemplateFeature::setupActionLook( QAction* actionToSetup )
|
||||
bool RicOpenInTextEditorFeature::isCommandEnabled()
|
||||
{
|
||||
actionToSetup->setText( "Edit" );
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicOpenInTextEditorFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
std::vector<caf::PdmUiItem*> uiItems;
|
||||
caf::SelectionManager::instance()->selectedItems( uiItems );
|
||||
|
||||
QString filePath;
|
||||
|
||||
if ( !uiItems.empty() )
|
||||
{
|
||||
if ( auto templateFileItem = dynamic_cast<RimPlotTemplateFileItem*>( uiItems.front() ) )
|
||||
{
|
||||
filePath = templateFileItem->absoluteFilePath();
|
||||
}
|
||||
}
|
||||
|
||||
if ( !filePath.isEmpty() )
|
||||
{
|
||||
RicOpenInTextEditorFeature::openFileInTextEditor( filePath, this );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicOpenInTextEditorFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setText( "Open in Text Editor" );
|
||||
actionToSetup->setIcon( QIcon( ":/open-text-editor.svg" ) );
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2022 Equinor ASA
|
||||
// Copyright (C) 2023- Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -23,10 +23,12 @@
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicEditPlotTemplateFeature : public caf::CmdFeature
|
||||
class RicOpenInTextEditorFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
static void openFileInTextEditor( const QString& filePath, QObject* parent );
|
||||
|
||||
protected:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "RicEditScriptFeature.h"
|
||||
|
||||
#include "ApplicationCommands/RicOpenInTextEditorFeature.h"
|
||||
#include "RicScriptFeatureImpl.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
@ -40,7 +41,7 @@ CAF_CMD_SOURCE_INIT( RicEditScriptFeature, "RicEditScriptFeature" );
|
||||
bool RicEditScriptFeature::isCommandEnabled()
|
||||
{
|
||||
std::vector<RimCalcScript*> selection = RicScriptFeatureImpl::selectedScripts();
|
||||
return selection.size() > 0;
|
||||
return !selection.empty();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -49,28 +50,11 @@ bool RicEditScriptFeature::isCommandEnabled()
|
||||
void RicEditScriptFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
std::vector<RimCalcScript*> selection = RicScriptFeatureImpl::selectedScripts();
|
||||
CVF_ASSERT( selection.size() > 0 );
|
||||
CVF_ASSERT( !selection.empty() );
|
||||
|
||||
RimCalcScript* calcScript = selection[0];
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString scriptEditor = app->scriptEditorPath();
|
||||
if ( !scriptEditor.isEmpty() )
|
||||
{
|
||||
QStringList arguments;
|
||||
arguments << calcScript->absoluteFileName;
|
||||
|
||||
QProcess* myProcess = new QProcess( this );
|
||||
myProcess->setProcessEnvironment( app->pythonProcessEnvironment() );
|
||||
myProcess->start( scriptEditor, arguments );
|
||||
|
||||
if ( !myProcess->waitForStarted( 1000 ) )
|
||||
{
|
||||
RiaLogging::errorInMessageBox( Riu3DMainWindowTools::mainWindowWidget(),
|
||||
"Script editor",
|
||||
"Failed to start script editor executable\n" + scriptEditor );
|
||||
}
|
||||
}
|
||||
RicOpenInTextEditorFeature::openFileInTextEditor( calcScript->absoluteFileName, this );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "ApplicationCommands/RicOpenInTextEditorFeature.h"
|
||||
#include "RicRefreshScriptsFeature.h"
|
||||
#include "RicScriptFeatureImpl.h"
|
||||
|
||||
@ -115,23 +116,7 @@ void RicNewOctaveScriptFeature::onActionTriggered( bool isChecked )
|
||||
Riu3DMainWindowTools::selectAsCurrentItem( calcScript );
|
||||
}
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString scriptEditor = app->scriptEditorPath();
|
||||
if ( !scriptEditor.isEmpty() )
|
||||
{
|
||||
QStringList arguments;
|
||||
arguments << fullPathFilenameNewScript;
|
||||
|
||||
QProcess* myProcess = new QProcess( this );
|
||||
myProcess->start( scriptEditor, arguments );
|
||||
|
||||
if ( !myProcess->waitForStarted( 1000 ) )
|
||||
{
|
||||
RiaLogging::errorInMessageBox( Riu3DMainWindowTools::mainWindowWidget(),
|
||||
"Script editor",
|
||||
"Failed to start script editor executable\n" + scriptEditor );
|
||||
}
|
||||
}
|
||||
RicOpenInTextEditorFeature::openFileInTextEditor( fullPathFilenameNewScript, this );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "ApplicationCommands/RicOpenInTextEditorFeature.h"
|
||||
#include "RicRefreshScriptsFeature.h"
|
||||
#include "RicScriptFeatureImpl.h"
|
||||
|
||||
@ -125,23 +126,7 @@ void RicNewPythonScriptFeature::onActionTriggered( bool isChecked )
|
||||
Riu3DMainWindowTools::selectAsCurrentItem( calcScript );
|
||||
}
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString scriptEditor = app->scriptEditorPath();
|
||||
if ( !scriptEditor.isEmpty() )
|
||||
{
|
||||
QStringList arguments;
|
||||
arguments << fullPathFilenameNewScript;
|
||||
|
||||
QProcess* myProcess = new QProcess( this );
|
||||
myProcess->start( scriptEditor, arguments );
|
||||
|
||||
if ( !myProcess->waitForStarted( 1000 ) )
|
||||
{
|
||||
RiaLogging::errorInMessageBox( Riu3DMainWindowTools::mainWindowWidget(),
|
||||
"Script editor",
|
||||
"Failed to start script editor executable\n" + scriptEditor );
|
||||
}
|
||||
}
|
||||
RicOpenInTextEditorFeature::openFileInTextEditor( fullPathFilenameNewScript, this );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSaveMultiPlotTemplateFeatureSettings.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicCreateMultiPlotFromSelectionFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicRenamePlotTemplateFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSetAsDefaultTemplateFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicCreateNewPlotFromTemplateFeature.h
|
||||
@ -23,7 +22,6 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSaveMultiPlotTemplateFeatureSettings.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicCreateMultiPlotFromSelectionFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicRenamePlotTemplateFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSetAsDefaultTemplateFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicCreateNewPlotFromTemplateFeature.cpp
|
||||
|
@ -1036,7 +1036,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
||||
menuBuilder << "Separator";
|
||||
menuBuilder << "RicRenamePlotTemplateFeature";
|
||||
menuBuilder << "RicDeletePlotTemplateFeature";
|
||||
menuBuilder << "RicEditPlotTemplateFeature";
|
||||
menuBuilder << "RicOpenInTextEditorFeature";
|
||||
menuBuilder << "Separator";
|
||||
menuBuilder << "RicSetAsDefaultTemplateFeature";
|
||||
menuBuilder << "Separator";
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "RimEclipseResultCase.h"
|
||||
#include "RimMainPlotCollection.h"
|
||||
#include "RimObservedFmuRftData.h"
|
||||
#include "RimPressureDepthData.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimRftTools.h"
|
||||
#include "RimSummaryCase.h"
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RimPressureDepthData.h"
|
||||
#include "RimWellLogCurve.h"
|
||||
|
||||
#include "RifEclipseRftAddress.h"
|
||||
|
Loading…
Reference in New Issue
Block a user