From 3ecced27a3e8179e8568379cdf088c6dac8c457c Mon Sep 17 00:00:00 2001
From: con <qtc-committer@nokia.com>
Date: Fri, 10 Dec 2010 17:04:24 +0100
Subject: [PATCH] Start implementing "edit in vi" for mac.

---
 share/qtcreator/externaltools/lrelease.xml    |  4 +-
 share/qtcreator/externaltools/lupdate.xml     |  4 +-
 share/qtcreator/externaltools/sort.xml        |  4 +-
 share/qtcreator/externaltools/vi.xml          |  4 +-
 share/qtcreator/externaltools/vi_mac.xml      | 50 +++++++++++++++++++
 share/qtcreator/static.pro                    |  3 +-
 .../editormanager/editormanager.cpp           | 23 +++++++++
 .../coreplugin/editormanager/editormanager.h  |  1 +
 .../projectexplorer/projectexplorer.cpp       |  8 +--
 .../qt4projectmanager/qt4projectmanager.cpp   | 10 ++--
 src/plugins/texteditor/texteditorplugin.cpp   |  4 +-
 11 files changed, 95 insertions(+), 20 deletions(-)
 create mode 100644 share/qtcreator/externaltools/vi_mac.xml

diff --git a/share/qtcreator/externaltools/lrelease.xml b/share/qtcreator/externaltools/lrelease.xml
index 86b05343c4c..70f69c12fd6 100644
--- a/share/qtcreator/externaltools/lrelease.xml
+++ b/share/qtcreator/externaltools/lrelease.xml
@@ -40,7 +40,7 @@
     <executable>
         <path>%{QT_INSTALL_BINS}/lrelease</path>
         <path>lrelease</path>
-        <arguments>%{CurrentProjectFilePath}</arguments>
-        <workingdirectory>%{CurrentProjectPath}</workingdirectory>
+        <arguments>%{CurrentProject:FilePath}</arguments>
+        <workingdirectory>%{CurrentProject:Path}</workingdirectory>
     </executable>
 </externaltool>
diff --git a/share/qtcreator/externaltools/lupdate.xml b/share/qtcreator/externaltools/lupdate.xml
index ba8b05053ac..65ce542efd4 100644
--- a/share/qtcreator/externaltools/lupdate.xml
+++ b/share/qtcreator/externaltools/lupdate.xml
@@ -40,7 +40,7 @@
     <executable>
         <path>%{QT_INSTALL_BINS}/lupdate</path>
         <path>lupdate</path>
-        <arguments>%{CurrentProjectFilePath}</arguments>
-        <workingdirectory>%{CurrentProjectPath}</workingdirectory>
+        <arguments>%{CurrentProject:FilePath}</arguments>
+        <workingdirectory>%{CurrentProject:Path}</workingdirectory>
     </executable>
 </externaltool>
diff --git a/share/qtcreator/externaltools/sort.xml b/share/qtcreator/externaltools/sort.xml
index 7687fa801b8..c13858289d9 100644
--- a/share/qtcreator/externaltools/sort.xml
+++ b/share/qtcreator/externaltools/sort.xml
@@ -38,7 +38,7 @@
     <category xml:lang="de">Text</category>
     <executable output="replaceselection" error="ignore">
         <path>sort</path>
-        <input>%{CurrentSelection}</input>
-        <workingdirectory>%{CurrentPath}</workingdirectory>
+        <input>%{CurrentDocument:Selection}</input>
+        <workingdirectory>%{CurrentDocument:Path}</workingdirectory>
     </executable>
 </externaltool>
diff --git a/share/qtcreator/externaltools/vi.xml b/share/qtcreator/externaltools/vi.xml
index dd4a88a4530..b8b3025802b 100644
--- a/share/qtcreator/externaltools/vi.xml
+++ b/share/qtcreator/externaltools/vi.xml
@@ -38,7 +38,7 @@
     <category xml:lang="de">Text</category>
     <executable output="reloaddocument">
         <path>xterm</path>
-        <arguments>-geom %{EditorCharWidth}x%{EditorCharHeight}+%{EditorXPos}+%{EditorYPos} -e vi %{CurrentFilePath} +%{EditorLine} +"normal %{EditorColumn}|"</arguments>
-        <workingdirectory>%{CurrentPath}</workingdirectory>
+        <arguments>-geom %{CurrentDocument:Width}x%{CurrentDocument:Height}+%{CurrentDocument:XPos}+%{CurrentDocument:YPos} -e vi %{CurrentDocument:FilePath} +%{CurrentDocument:Line} +"normal %{CurrentDocument:Column}|"</arguments>
+        <workingdirectory>%{CurrentDocument:Path}</workingdirectory>
     </executable>
 </externaltool>
diff --git a/share/qtcreator/externaltools/vi_mac.xml b/share/qtcreator/externaltools/vi_mac.xml
new file mode 100644
index 00000000000..07862c3c5f1
--- /dev/null
+++ b/share/qtcreator/externaltools/vi_mac.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+-->
+<externaltool id="vi">
+    <description>Opens the current file in vi</description>
+    <description xml:lang="de">Öffnet die aktuelle Datei in vi</description>
+    <displayname>Edit with vi</displayname>
+    <displayname xml:lang="de">In vi öffnen</displayname>
+    <category>Text</category>
+    <category xml:lang="de">Text</category>
+    <executable output="reloaddocument">
+        <path>osascript</path>
+        <input>
+        tell application "Terminal"
+            do script "vi \"%{CurrentDocument:FilePath}\"; exit"
+            set currentTab to the result
+            activate
+        end tell
+        </input>
+        <workingdirectory>%{CurrentDocument:Path}</workingdirectory>
+    </executable>
+</externaltool>
diff --git a/share/qtcreator/static.pro b/share/qtcreator/static.pro
index 161b7a81c8b..f870be90935 100644
--- a/share/qtcreator/static.pro
+++ b/share/qtcreator/static.pro
@@ -44,7 +44,8 @@ DATA_FILES = \
     externaltools/lupdate.xml
 unix:DATA_FILES += externaltools/sort.xml
 linux-*:DATA_FILES += externaltools/vi.xml
-macx:DATA_FILES += runInTerminal.command
+macx:DATA_FILES += externaltools/vi_mac.xml
+#macx:DATA_FILES += runInTerminal.command
 win32:DATA_FILES ~= s|\\\\|/|g
 
 OTHER_FILES += $$DATA_FILES
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 64fafead4ec..fbaf5cb6cbe 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -477,6 +477,9 @@ void EditorManager::init()
 
     m_d->m_openEditorsFactory = new OpenEditorsViewFactory();
     pluginManager()->addObject(m_d->m_openEditorsFactory);
+
+    connect(VariableManager::instance(), SIGNAL(variableUpdateRequested(QString)),
+            this, SLOT(updateVariable(QString)));
 }
 
 
@@ -2134,3 +2137,23 @@ QString EditorManager::windowTitleAddition() const
     return m_d->m_titleAddition;
 }
 
+void EditorManager::updateVariable(const QString &variable)
+{
+    static const char * const kCurrentDocumentFilePath = "CurrentDocument:FilePath";
+    static const char * const kCurrentDocumentPath = "CurrentDocument:Path";
+    if (variable == QLatin1String(kCurrentDocumentFilePath)
+            || variable == QLatin1String(kCurrentDocumentPath)) {
+        QString value;
+        IEditor *curEditor = currentEditor();
+        if (curEditor) {
+            QString fileName = curEditor->file()->fileName();
+            if (!fileName.isEmpty()) {
+                if (variable == QLatin1String(kCurrentDocumentFilePath))
+                    value = QFileInfo(fileName).filePath();
+                else if (variable == QLatin1String(kCurrentDocumentPath))
+                    value = QFileInfo(fileName).path();
+            }
+        }
+        VariableManager::instance()->insert(variable, value);
+    }
+}
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index a94a23e3c76..8731fe31f15 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -228,6 +228,7 @@ private slots:
     void makeCurrentEditorWritable();
     void updateWindowTitle();
     void handleEditorStateChange();
+    void updateVariable(const QString &variable);
 
 public slots:
     void goBackInNavigationHistory();
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index a3dfffc0536..cda7db40d8c 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -1001,16 +1001,16 @@ void ProjectExplorerPlugin::loadCustomWizards()
 
 void ProjectExplorerPlugin::updateVariable(const QString &variable)
 {
-    static const char * const currentProjectPathVar = "CurrentProjectPath";
-    static const char * const currentProjectFilePathVar = "CurrentProjectFilePath";
-    if (variable == QLatin1String(currentProjectFilePathVar)) {
+    static const char * const kCurrentProjectPath= "CurrentProject:Path";
+    static const char * const kCurrentProjectFilePath= "CurrentProject:FilePath";
+    if (variable == QLatin1String(kCurrentProjectFilePath)) {
         if (currentProject() && currentProject()->file()) {
             Core::VariableManager::instance()->insert(variable,
                                                       currentProject()->file()->fileName());
         } else {
             Core::VariableManager::instance()->remove(variable);
         }
-    } else if (variable == QLatin1String(currentProjectPathVar)) {
+    } else if (variable == QLatin1String(kCurrentProjectPath)) {
         if (currentProject() && currentProject()->file()) {
             Core::VariableManager::instance()->insert(variable,
                                                       QFileInfo(currentProject()->file()->fileName()).filePath());
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.cpp b/src/plugins/qt4projectmanager/qt4projectmanager.cpp
index 842861475df..0ba8a73ff61 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.cpp
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.cpp
@@ -179,16 +179,16 @@ void Qt4Manager::editorAboutToClose(Core::IEditor *editor)
 
 void Qt4Manager::updateVariable(const QString &variable)
 {
-    static const char * const installBinsVar = "QT_INSTALL_BINS";
-    if (variable == QLatin1String(installBinsVar)) {
+    static const char * const kInstallBins = "QT_INSTALL_BINS";
+    if (variable == QLatin1String(kInstallBins)) {
         Qt4Project *qt4pro = qobject_cast<Qt4Project *>(projectExplorer()->currentProject());
         if (!qt4pro) {
-            Core::VariableManager::instance()->remove(QLatin1String(installBinsVar));
+            Core::VariableManager::instance()->remove(QLatin1String(kInstallBins));
             return;
         }
         QString value = qt4pro->activeTarget()->activeBuildConfiguration()
-                ->qtVersion()->versionInfo().value(QLatin1String(installBinsVar));
-        Core::VariableManager::instance()->insert(QLatin1String(installBinsVar), value);
+                ->qtVersion()->versionInfo().value(QLatin1String(kInstallBins));
+        Core::VariableManager::instance()->insert(QLatin1String(kInstallBins), value);
     }
 }
 
diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp
index 692d885d82a..09e135a691f 100644
--- a/src/plugins/texteditor/texteditorplugin.cpp
+++ b/src/plugins/texteditor/texteditorplugin.cpp
@@ -216,8 +216,8 @@ void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings)
 
 void TextEditorPlugin::updateVariable(const QString &variable)
 {
-    static const char * const kCurrentSelectionVar = "CurrentSelection";
-    if (variable == QLatin1String(kCurrentSelectionVar)) {
+    static const char * const kCurrentDocumentSelection= "CurrentDocument:Selection";
+    if (variable == QLatin1String(kCurrentDocumentSelection)) {
         QString selectedText;
         Core::IEditor *iface = Core::EditorManager::instance()->currentEditor();
         ITextEditor *editor = qobject_cast<ITextEditor *>(iface);
-- 
GitLab