Patch #2908 2010-01-19 04:01

terryp

Try MINE before internal editor, on double click of files
Download
2908-Try_MINE_befor.patch (5.7 KB)
Category
Application::Refinement
Status
Out of date
Close date
2011-11-24 12:27
Assigned to
mortenmacfly
Index: debian/changelog
===================================================================
--- debian/changelog    (revision 6089)
+++ debian/changelog    (working copy)
@@ -1,4 +1,4 @@
-codeblocks (8.02svn5933) unstable; urgency=low
+codeblocks (8.02svn6089) unstable; urgency=low
 
   * more fixes to debian build system, sources and packages are now
     lintian-clean, except for some words guessed as spelling-errors.
Index: src/sdk/projectmanager.cpp
===================================================================
--- src/sdk/projectmanager.cpp    (revision 6089)
+++ src/sdk/projectmanager.cpp    (working copy)
@@ -1437,50 +1437,49 @@
     }
 
     FileType ft = FileTypeOf(filename);
-    if (ft == ftHeader || ft == ftSource)
+
+    // first look for custom editors
+    // if that fails, try MIME handlers
+    EditorBase* eb = Manager::Get()->GetEditorManager()->IsOpen(filename);
+    if (eb && !eb->IsBuiltinEditor())
     {
-        // C/C++ header/source files, always get opened inside Code::Blocks
-        cbEditor* ed = Manager::Get()->GetEditorManager()->Open(filename);
-        if (ed)
-        {
-            ed->SetProjectFile(pf);
-            ed->Activate();
-        }
-        else
-        {
-            wxString msg;
-            msg.Printf(_("Failed to open '%s'."), filename.c_str());
-            Manager::Get()->GetLogManager()->LogError(msg);
-        }
+        // custom editors just get activated
+        eb->Activate();
+        return;
     }
-    else
+
+    // then try MIME handlers
+    cbMimePlugin* plugin = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(filename);
+    if (!plugin)
     {
-        // first look for custom editors
-        // if that fails, try MIME handlers
-        EditorBase* eb = Manager::Get()->GetEditorManager()->IsOpen(filename);
-        if (eb && !eb->IsBuiltinEditor())
+        if (ft == ftHeader || ft == ftSource)
         {
-            // custom editors just get activated
-            eb->Activate();
-            return;
+            // try falling back on the internal editor before
+            // resorting to an error message.
+            cbEditor* ed = Manager::Get()->GetEditorManager()->Open(filename);
+            if (ed)
+            {
+                ed->SetProjectFile(pf);
+                ed->Activate();
+            }
+            else
+            {
+                wxString msg;
+                msg.Printf(_("Failed to open '%s'."), filename.c_str());
+                Manager::Get()->GetLogManager()->LogError(msg);
+            }
         }
-
-        // not a recognized file type
-        cbMimePlugin* plugin = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(filename);
-        if (!plugin)
-        {
-            wxString msg;
-            msg.Printf(_("Could not open file '%s'.\nNo handler registered for this type of file."), filename.c_str());
-            Manager::Get()->GetLogManager()->LogError(msg);
-        }
-        else if (plugin->OpenFile(filename) != 0)
-        {
-            const PluginInfo* info = Manager::Get()->GetPluginManager()->GetPluginInfo(plugin);
-            wxString msg;
-            msg.Printf(_("Could not open file '%s'.\nThe registered handler (%s) could not open it."), filename.c_str(), info ? info->title.c_str() : wxString(_("<Unknown plugin>")).c_str());
-            Manager::Get()->GetLogManager()->LogError(msg);
-        }
+        wxString msg;
+        msg.Printf(_("Could not open file '%s'.\nNo handler registered for this type of file."), filename.c_str());
+        Manager::Get()->GetLogManager()->LogError(msg);
     }
+    else if (plugin->OpenFile(filename) != 0)
+    {
+        const PluginInfo* info = Manager::Get()->GetPluginManager()->GetPluginInfo(plugin);
+        wxString msg;
+        msg.Printf(_("Could not open file '%s'.\nThe registered handler (%s) could not open it."), filename.c_str(), info ? info->title.c_str() : wxString(_("<Unknown plugin>")).c_str());
+        Manager::Get()->GetLogManager()->LogError(msg);
+    }
 }
 
 void ProjectManager::DoOpenSelectedFile()
Index: src/src/main.cpp
===================================================================
--- src/src/main.cpp    (revision 6089)
+++ src/src/main.cpp    (working copy)
@@ -1566,25 +1566,28 @@
             }
         }
         //
-        // Source files
-        //
-        case ftHeader:
-            // fallthrough
-        case ftSource:
-            // fallthrough
-        case ftResource:
-            return DoOpenFile(filename, addToHistory);
-        //
         // For all other files, ask MIME plugin for a suitable handler
         //
         default:
         {
             cbMimePlugin* plugin = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(filename);
-            // warn user that "Files extension handler" is disabled
+            // attempt fall back on the internal editor
             if (!plugin)
             {
-                cbMessageBox(_("Could not open file ") +
download for full patch...
terryp 2010-01-19 04:04

This makes double clicking a file in the project manager open using the users file extension/mime handlers, even when they're already known to Code::Blocks as source/header files. Which is exactly what a user would expect the IDE to do!

Note however that making C::B behave similarly when dealing with build messages / etc, would require more in depth changes, or just uglification of a couple functions.

mortenmacfly 2010-02-25 14:15

I doubt this will be applied any time soon.

After it's application Code::Blocks will ask for every file (including *.c, *.cpp etc.) how to open.

Code::Blocks is a C / C++ IDE, so nobody will expect it asks what to do with a C / C++ file. That's really not convenient to me.

No other C / C++ IDE I know will ask how to operate a C / C++ file. What makes you say "Which is exactly what a user would expect the IDE to do!"? I doubt this is true.

terryp 2010-02-25 16:57

Ahh, sorry, looks like the MIME stuff must be taking it upon itself to prompt the user for what to do when there's no MIME type set, making the fall backs on the internals virtually a no-op. I didn't notice that.

When I have the free time, I'll resync my working copy with the trunk, and experiment with fixing that. It should only take a few bytes in changes, unless Code::Blocks' architecture purposely makes both sane and proper behavior near impossible :-o.

mortenmacfly 2011-08-13 05:13

Any news on that? I'd close the patch otherwise.

mortenmacfly 2011-11-24 12:27

No activity - invalidating.