Changeset 0f676825acafe08500114fc64f438732f780fb0a

Show
Ignore:
Timestamp:
01/06/07 23:33:37 (6 years ago)
Author:
Philipp Kern <phil@…>
Parents:
e51abc748ac27b1dfa0fccd9de3ba9cdecb743f0
Children:
f9c68bd2c0ebf3153d48dbda4861b51439515eec
git-committer:
Philipp Kern <phil@0x539.de> / 2007-01-06T22:33:37Z+0000
Message:

[project @ Separate mime map]

Original author: Armin Burgmeier <armin@…>
Date: 2005-05-07 10:32:46+00:00

Files:
2 added
5 modified

Legend:

Unmodified
Added
Removed
  • Makefile.am

    re51abc7 r0f67682  
    2222else 
    2323noinst_HEADERS += inc/buffer_wrapper_generic.hpp 
     24endif 
     25if WITH_GTKSOURCEVIEW 
     26noinst_HEADERS += inc/mimemap.hpp 
    2427endif 
    2528noinst_HEADERS += inc/historyentry.hpp 
     
    5457gobby_SOURCES += src/buffer_wrapper_generic.cpp 
    5558endif 
     59if WITH_GTKSOURCEVIEW 
     60gobby_SOURCES += src/mimemap.cpp 
     61endif 
    5662gobby_SOURCES += src/historyentry.cpp 
    5763gobby_SOURCES += src/logview.cpp 
  • inc/document.hpp

    re51abc7 r0f67682  
    3838{ 
    3939public: 
    40         typedef std::map<Glib::ustring, Glib::ustring> MimeMap; 
    4140        typedef sigc::signal<void> signal_update_type; 
    4241 
     
    8786        Gtk::TextView m_view; 
    8887#endif 
     88        /** Variable to prevent event functions from endless recursion. After 
     89         * an obby insert or textbuffer insert has occured, this variable is 
     90         * set to true, after the event has been handled, to false. If an 
     91         * obby event arrives and we insert the newly written text into the 
     92         * buffer, a textbuffer-insert event would occur. But if m_editing is 
     93         * true, the event is ignored. 
     94         */ 
    8995        bool m_editing; 
    9096         
    9197        signal_update_type m_signal_update; 
    92  
    93 public: 
    94 #ifdef WITH_GTKSOURCEVIEW 
    95         static const MimeMap& create_mime_map(); 
    96         static const MimeMap& m_mime_map; 
    97 #endif 
    9898}; 
    9999 
  • inc/folder.hpp

    re51abc7 r0f67682  
    2424#include <obby/user.hpp> 
    2525#include <obby/document.hpp> 
     26 
    2627#include "document.hpp" 
    2728#include "sourceview/sourcelanguage.hpp" 
     29 
     30#ifdef WITH_GTKSOURCEVIEW 
     31# include "mimemap.hpp" 
     32#endif 
    2833 
    2934namespace Gobby 
     
    4045        Folder(); 
    4146        ~Folder(); 
     47 
     48        // Access to the mime map 
     49        const MimeMap& get_mime_map() const; 
    4250 
    4351        // Calls from the window 
     
    5765 
    5866        signal_document_update_type m_signal_document_update; 
     67 
     68#ifdef WITH_GTKSOURCEVIEW 
     69        MimeMap m_mime_map; 
     70#endif 
    5971}; 
    6072 
  • src/document.cpp

    re51abc7 r0f67682  
    2424#include "folder.hpp" 
    2525 
    26 #ifdef WITH_GTKSOURCEVIEW 
    27 const Gobby::Document::MimeMap& Gobby::Document::m_mime_map = 
    28         Gobby::Document::create_mime_map(); 
    29 #endif 
    30  
    3126Gobby::Document::Document(obby::document& doc, const Folder& folder) 
    3227 : Gtk::ScrolledWindow(), m_doc(doc), m_folder(folder), m_editing(true) 
     
    4944 
    5045#ifdef WITH_GTKSOURCEVIEW 
    51         // Set source language by file extension 
    52         Glib::ustring title = doc.get_title(); 
    53         Glib::ustring::size_type pos = title.rfind('.'); 
    54         if(pos != Glib::ustring::npos) 
     46        // Set SourceLanguage by file extension 
     47        Glib::ustring mime_type = 
     48                folder.get_mime_map().get_mime_type_by_file(doc.get_title() ); 
     49        if(!mime_type.empty() ) 
    5550        { 
    56                 Glib::ustring extension = title.substr(pos + 1); 
    57                 MimeMap::const_iterator iter = m_mime_map.find(extension); 
    58                 if(iter != m_mime_map.end() ) 
     51                Glib::RefPtr<Gtk::SourceLanguage> language =  
     52                        m_lang_manager->get_language_from_mime_type(mime_type); 
     53                if(language) 
    5954                { 
    60                         Glib::ustring mime = iter->second; 
    61                         Glib::RefPtr<Gtk::SourceLanguage> language =  
    62                                 m_lang_manager->get_language_from_mime_type( 
    63                                         mime 
    64                                 ); 
    65                         if(language) 
    66                         { 
    67                                 buf->set_language(language); 
    68                         } 
    69                         else 
    70                         { 
    71                                 g_warning("Could not find syntax file for file " 
    72                                           "extension %s (mime-type %s)", 
    73                                           extension.c_str(), mime.c_str() ); 
    74                         } 
    75                 } 
    76                 else 
    77                 { 
    78                         g_warning("Could not detect file type of file " 
    79                                   "extension '%s'", extension.c_str() ); 
     55                        buf->set_language(language); 
    8056                } 
    8157        } 
     
    264240} 
    265241 
    266 #ifdef WITH_GTKSOURCEVIEW 
    267 const Gobby::Document::MimeMap& Gobby::Document::create_mime_map() 
    268 { 
    269         static MimeMap map; 
    270  
    271         // Translates file extension to mime type 
    272         map["ada"] = "text/x-ada"; 
    273         map["c"] = "text/x-c"; 
    274         map["h"] = "text/x-c++"; 
    275         map["hh"] = "text/x-c++"; 
    276         map["cpp"] = "text/x-c++"; 
    277         map["hpp"] = "text/x-c++"; 
    278         map["cc"] = "text/x-c++"; 
    279         map["css"] = "text/css"; 
    280         map["cs"] = "text/x-csharp"; 
    281         map["diff"] = "text/x-diff"; 
    282         map["f"] = "text/x-fortran"; 
    283         map["f77"] = "text/x-fortran"; 
    284         map["hs"] = "text/x-haskell"; 
    285         map["htm"] = "text/html"; 
    286         map["html"] = "text/html"; 
    287         map["xhtml"] = "text/html"; 
    288         // Wi geth IDL? 
    289         map["java"] = "text/x-java"; 
    290         map["js"] = "text/x-javascript"; 
    291         map["tex"] = "text/x-tex"; 
    292         map["latex"] = "text/x-tex"; 
    293         map["lua"] = "text/x-lua"; 
    294         // Wi geth MSIL? 
    295         map["dpr"] = "text/x-pascal"; 
    296         map["pas"] = "text/x-pascal"; 
    297         map["pl"] = "text/x-perl"; 
    298         map["pm"] = "text/x-perl"; 
    299         map["php"] = "text/x-php"; 
    300         map["php3"] = "text/x-php"; 
    301         map["php4"] = "text/x-php"; 
    302         map["php5"] = "text/x-php"; 
    303         map["po"] = "text/x-gettext-translation"; 
    304         map["py"] = "text/x-python"; 
    305         map["rb"] = "text/x-ruby"; 
    306         map["sql"] = "text/x-sql"; 
    307         // Wi geth texinfo? 
    308         // Wi geth vb.NET? 
    309         // Wi geth verilog? 
    310         map["xml"] = "text/xml"; 
    311  
    312         return map; 
    313 } 
    314 #endif 
  • src/folder.cpp

    re51abc7 r0f67682  
    3030        for(int i = 0; i < get_n_pages(); ++ i) 
    3131                delete get_nth_page(i); 
     32} 
     33 
     34const Gobby::MimeMap& Gobby::Folder::get_mime_map() const 
     35{ 
     36        return m_mime_map; 
    3237} 
    3338