changeset 178:1a3af8617ea4

* basic external editor selection (for hgignore)
author Chris Cannam
date Thu, 16 Dec 2010 22:11:38 +0000
parents bb89bcd8986b
children a51980a00dac
files common.cpp mainwindow.cpp settingsdialog.cpp settingsdialog.h
diffstat 4 files changed, 60 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/common.cpp	Thu Dec 16 20:23:43 2010 +0000
+++ b/common.cpp	Thu Dec 16 22:11:38 2010 +0000
@@ -48,9 +48,9 @@
     if (name != "") {
         if (name[0] != '/'
 #ifdef Q_OS_WIN32
-			&& (QRegExp("^[a-zA-Z]:").indexIn(name) != 0)
+            && (QRegExp("^\\w:").indexIn(name) != 0)
 #endif
-			) {
+            ) {
 #ifdef Q_OS_WIN32
             QChar pathSep = ';';
 #else
@@ -68,7 +68,7 @@
                 path = installPath + pathSep + path;
             }
 #ifndef Q_OS_WIN32
-			//!!!
+            //!!!
             path = path + ":/usr/local/bin";
             DEBUG << "... adding /usr/local/bin just in case (fix and add settings dlg please)"
                     << endl;
--- a/mainwindow.cpp	Thu Dec 16 20:23:43 2010 +0000
+++ b/mainwindow.cpp	Thu Dec 16 22:11:38 2010 +0000
@@ -376,26 +376,51 @@
 {
     QString hgIgnorePath;
     QStringList params;
-    QString editorName;
-
+    
     hgIgnorePath = workFolderPath;
-    hgIgnorePath += ".hgignore";
+    hgIgnorePath += "/.hgignore";
     
     params << hgIgnorePath;
 
-//!!!    
-#ifdef Q_OS_LINUX
+    QSettings settings;
+    settings.beginGroup("Locations");
+    QString editor = settings.value("editorbinary", "").toString();
+    if (editor == "") {
+        QStringList bases;
+        bases
+#if defined Q_OS_WIN32
+            << "wordpad.exe"
+            << "C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"
+            << "notepad.exe"
+#elif defined Q_OS_MAC
+            << "textedit"
+#else
+            << "gedit" << "kate"
+#endif
+            ;
+        bool found = false;
+        foreach (QString base, bases) {
+            editor = findInPath(base, m_myDirPath, true);
+            if (editor != base && editor != base + ".exe") {
+                found = true;
+                break;
+            }
+        }
+        if (found) {
+            settings.setValue("editorbinary", editor);
+        } else {
+            editor = "";
+        }
+    }
 
-        editorName = "gedit";
-
-#else
-
-        editorName = """C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe""";
-
-#endif
+    if (editor == "") {
+        DEBUG << "Failed to find a text editor" << endl;
+        //!!! visible error!
+        return;
+    }
 
     HgAction action(ACT_HG_IGNORE, workFolderPath, params);
-    action.executable = editorName;
+    action.executable = editor;
 
     runner->requestAction(action);
 }
@@ -1829,7 +1854,7 @@
 
     //Repository actions
     hgRefreshAct = new QAction(QIcon(":/images/status.png"), tr("Refresh"), this);
-    hgRefreshAct->setStatusTip(tr("Update the window to show the current state of the working folder"));
+    hgRefreshAct->setStatusTip(tr("Refresh the window to show the current state of the working folder"));
 
     hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Preview"), this);
     hgIncomingAct -> setStatusTip(tr("See what changes are available in the remote repository waiting to be pulled"));
--- a/settingsdialog.cpp	Thu Dec 16 20:23:43 2010 +0000
+++ b/settingsdialog.cpp	Thu Dec 16 22:11:38 2010 +0000
@@ -94,7 +94,7 @@
     browse = new QPushButton(tr("Browse..."));
     pathsLayout->addWidget(browse, row++, 2);
     connect(browse, SIGNAL(clicked()), this, SLOT(diffPathBrowse()));
-
+    
     pathsLayout->addWidget(new QLabel(tr("External file-merge program:")), row, 0);
 
     m_mergePathEdit = new QLineEdit();
@@ -107,6 +107,18 @@
     pathsLayout->addWidget(browse, row++, 2);
     connect(browse, SIGNAL(clicked()), this, SLOT(mergePathBrowse()));
 
+    pathsLayout->addWidget(new QLabel(tr("External text editor:")), row, 0);
+
+    m_editPathEdit = new QLineEdit();
+    m_editPathEdit->setText(settings.value("editorbinary").toString());
+    connect(m_editPathEdit, SIGNAL(textChanged(const QString &)),
+	    this, SLOT(editPathChanged(const QString &)));
+    pathsLayout->addWidget(m_editPathEdit, row, 1);
+
+    browse = new QPushButton(tr("Browse..."));
+    pathsLayout->addWidget(browse, row++, 2);
+    connect(browse, SIGNAL(clicked()), this, SLOT(editPathBrowse()));
+
     settings.endGroup();
     
     settings.beginGroup("Locations");
@@ -186,12 +198,12 @@
 }
 
 void
-SettingsDialog::editorPathChanged(const QString &s)
+SettingsDialog::editPathChanged(const QString &s)
 {
 }
 
 void
-SettingsDialog::editorPathBrowse()
+SettingsDialog::editPathBrowse()
 {
 }
 
--- a/settingsdialog.h	Thu Dec 16 20:23:43 2010 +0000
+++ b/settingsdialog.h	Thu Dec 16 22:11:38 2010 +0000
@@ -40,8 +40,8 @@
     void diffPathBrowse();
     void mergePathChanged(const QString &);
     void mergePathBrowse();
-    void editorPathChanged(const QString &);
-    void editorPathBrowse();
+    void editPathChanged(const QString &);
+    void editPathBrowse();
     void extensionPathChanged(const QString &);
     void extensionPathBrowse();
 
@@ -53,7 +53,7 @@
     QLineEdit *m_hgPathEdit;
     QLineEdit *m_diffPathEdit;
     QLineEdit *m_mergePathEdit;
-    QLineEdit *m_editorPathEdit;
+    QLineEdit *m_editPathEdit;
 
     QCheckBox *m_useExtension;
     QLineEdit *m_extensionPathEdit;