Changeset c006fa359f7823874cf7a814cb87823276535eae

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

[project @ Replaced mime map by file list in preferences]

Original author: Armin Burgmeier <armin@…>
Date: 2006-03-08 20:56:37+00:00

Files:
2 removed
14 modified

Legend:

Unmodified
Added
Removed
  • inc/config.hpp

    rbfb82f7 rc006fa3  
    6666        { 
    6767        public: 
     68                class iterator 
     69                { 
     70                private: 
     71                        typedef std::map<Glib::ustring, Entry>::iterator 
     72                                base_type; 
     73 
     74                public: 
     75                        iterator(const base_type& base); 
     76 
     77                        iterator& operator++(); 
     78                        iterator operator++(int); 
     79 
     80                        bool operator==(const iterator& other) const; 
     81                        bool operator!=(const iterator& other) const; 
     82 
     83                        const Glib::ustring& index() const; 
     84                        Entry& entry(); 
     85 
     86                private: 
     87                        base_type m_iter; 
     88                }; 
     89 
    6890                Entry(); 
    6991                Entry(const Entry& other); 
     
    7597                void save(xmlpp::Element& element) const; 
    7698 
     99                bool has_entry(const Glib::ustring& index) const; 
    77100                Entry& operator[](const Glib::ustring& index); 
     101 
     102                iterator begin(); 
     103                iterator end(); 
    78104 
    79105                template<typename T> T get(const T& default_value = T()) const 
  • inc/document_settings.hpp

    rba89078 rc006fa3  
    9999        /** @brief Returns the columns for the underlaying ListStore. 
    100100         */ 
    101         const Columns& get_columns() const; 
     101//      const Columns& get_columns() const; 
    102102 
    103103        /** @brief Returns the underlaying list that may be displayed by 
     
    124124        signal_document_remove_type document_remove_event() const; 
    125125 
     126        const Columns columns; 
    126127private: 
    127128        void on_document_insert(DocumentInfo& info); 
     
    139140 
    140141        Glib::RefPtr<Gtk::ListStore> m_data; 
    141         Columns m_cols; 
     142        //Columns m_cols; 
    142143 
    143144        Glib::RefPtr<Gdk::Pixbuf> m_icon; 
  • inc/folder.hpp

    r0c6e731 rc006fa3  
    8989        const MimeMap& get_mime_map() const; 
    9090 
     91#if 0 
    9192        Glib::RefPtr<const Gtk::SourceLanguagesManager> 
    9293                get_lang_manager() const; 
     94#endif 
    9395 
    9496        // Calls from the window 
  • inc/header.hpp

    r0c6e731 rc006fa3  
    114114        }; 
    115115 
    116         Header(const ApplicationState& state); 
     116        typedef Glib::RefPtr<Gtk::SourceLanguagesManager> LangManager; 
     117 
     118        Header(const ApplicationState& state, const LangManager& lang_mgr); 
    117119 
    118120        // Access to accelerator groups of the ui manager 
     
    120122        Glib::RefPtr<const Gtk::AccelGroup> get_accel_group() const; 
    121123 
    122         Glib::RefPtr<Gtk::SourceLanguagesManager> 
     124        /*Glib::RefPtr<Gtk::SourceLanguagesManager> 
    123125                get_lang_manager(); 
    124126        Glib::RefPtr<const Gtk::SourceLanguagesManager> 
    125                 get_lang_manager() const; 
     127                get_lang_manager() const;*/ 
    126128 
    127129        // Access to toolbar & menubar 
     
    180182 
    181183        const Glib::RefPtr<Gtk::UIManager> m_ui_manager; 
    182         Glib::RefPtr<Gtk::SourceLanguagesManager> m_lang_manager; 
     184        //Glib::RefPtr<Gtk::SourceLanguagesManager> m_lang_manager; 
    183185 
    184186        Gtk::MenuBar* m_menubar; 
  • inc/preferences.hpp

    r0586368 rc006fa3  
    2323#include "config.hpp" 
    2424 
     25#include "sourceview/sourcelanguage.hpp" 
     26#include "sourceview/sourcelanguagesmanager.hpp" 
     27 
    2528namespace Gobby 
    2629{ 
     
    2932{ 
    3033public: 
     34        typedef Glib::RefPtr<Gtk::SourceLanguage> Language; 
     35        typedef Glib::RefPtr<Gtk::SourceLanguagesManager> LangManager; 
     36 
    3137        /** Uninitialised preferences. 
    3238         */ 
    3339        Preferences(); 
    3440 
    35         /** Reads preferences values out of a config. 
     41        /** Reads preferences values out of a config, using default values 
     42         * for values that do not exist in the config. 
    3643         */ 
    37         Preferences(Config& m_config); 
    38  
    39         /** Copies preferences. 
    40          */ 
    41         Preferences(const Preferences& other); 
    42         ~Preferences(); 
    43  
    44         /** Copies preferences. 
    45          */ 
    46         Preferences& operator=(const Preferences& other); 
     44        Preferences(Config& m_config, const LangManager& lang_mgr); 
    4745 
    4846        /** Serialises preferences back to config. 
    4947         */ 
    50         void serialise(Config& config); 
     48        void serialise(Config& config) const; 
    5149 
    52         struct 
     50        class Editor 
    5351        { 
     52        public: 
     53                Editor(); 
     54                Editor(Config::Entry& entry); 
     55                void serialise(Config::Entry& entry) const; 
     56 
    5457                unsigned int tab_width; 
    5558                bool tab_spaces; 
    5659                bool indentation_auto; 
    5760                bool homeend_smart; 
    58         } editor; 
     61        }; 
    5962 
    60         struct 
     63        class View 
    6164        { 
     65        public: 
     66                View(); 
     67                View(Config::Entry& entry); 
     68                void serialise(Config::Entry& entry) const; 
     69 
    6270                bool wrap_text; 
    6371                bool wrap_words; 
     
    6775                unsigned int margin_pos; 
    6876                bool bracket_highlight; 
    69         } view; 
     77        }; 
    7078 
    71         struct 
     79        class Appearance 
    7280        { 
     81        public: 
     82                Appearance(); 
     83                Appearance(Config::Entry& entry); 
     84                void serialise(Config::Entry& entry) const; 
     85 
    7386                Gtk::ToolbarStyle toolbar_show; 
    7487                bool remember; 
    75         } appearance; 
     88        }; 
     89 
     90        class FileList 
     91        { 
     92        public: 
     93                typedef std::map<Glib::ustring, Language> map_type; 
     94 
     95                class iterator 
     96                { 
     97                private: 
     98                        typedef map_type::const_iterator base_iterator; 
     99 
     100                public: 
     101                        iterator(base_iterator iter); 
     102 
     103                        iterator& operator++(); 
     104                        iterator operator++(int); 
     105 
     106                        const Glib::ustring& pattern() const; 
     107                        const Language& language() const; 
     108                private: 
     109                        base_iterator m_iter; 
     110                }; 
     111 
     112                FileList(); 
     113                FileList(Config::Entry& entry, const LangManager& lang_mgr); 
     114 
     115                void serialise(Config::Entry& entry) const; 
     116 
     117                // This function may also return an already existing iterator 
     118                // when pattern is already in the map. Compare lang to be sure 
     119                // that the entry actually has been inserted. 
     120                iterator add(const Glib::ustring& pattern, 
     121                             const Language& lang); 
     122 
     123                iterator begin() const; 
     124                iterator end() const; 
     125        protected: 
     126                iterator add_by_mime_type(const Glib::ustring& pattern, 
     127                                          const Glib::ustring& mime_type, 
     128                                          const LangManager& lang_mgr); 
     129 
     130                map_type m_files; 
     131        }; 
     132 
     133        Editor editor; 
     134        View view; 
     135        Appearance appearance; 
     136        FileList files; 
    76137}; 
    77138 
  • inc/window.hpp

    r0c6e731 rc006fa3  
    133133        // Config 
    134134        Config& m_config; 
     135        Glib::RefPtr<Gtk::SourceLanguagesManager> m_lang_manager; 
    135136        Preferences m_preferences; 
    136137        const IconManager& m_icon_mgr; 
  • src/config.cpp

    r67caaea rc006fa3  
    9393} 
    9494 
     95Gobby::Config::Entry::iterator::iterator(const base_type& base): 
     96        m_iter(base) 
     97{ 
     98} 
     99 
     100Gobby::Config::Entry::iterator& Gobby::Config::Entry::iterator::operator++() 
     101{ 
     102        ++ m_iter; 
     103        return *this; 
     104} 
     105 
     106Gobby::Config::Entry::iterator Gobby::Config::Entry::iterator::operator++(int) 
     107{ 
     108        iterator temp(*this); 
     109        ++ *this; 
     110        return temp; 
     111} 
     112 
     113bool Gobby::Config::Entry::iterator::operator==(const iterator& other) const 
     114{ 
     115        return m_iter == other.m_iter; 
     116} 
     117 
     118bool Gobby::Config::Entry::iterator::operator!=(const iterator& other) const 
     119{ 
     120        return m_iter != other.m_iter; 
     121} 
     122 
     123const Glib::ustring& Gobby::Config::Entry::iterator::index() const 
     124{ 
     125        return m_iter->first; 
     126} 
     127 
     128Gobby::Config::Entry& Gobby::Config::Entry::iterator::entry() 
     129{ 
     130        return m_iter->second; 
     131} 
     132 
    95133Gobby::Config::Entry::Entry() 
    96134{ 
     
    146184} 
    147185 
     186bool Gobby::Config::Entry::has_entry(const Glib::ustring& index) const 
     187{ 
     188        return m_table.find(index) != m_table.end(); 
     189} 
     190 
    148191Gobby::Config::Entry& 
    149192Gobby::Config::Entry::operator[](const Glib::ustring& index) 
    150193{ 
    151194        return m_table[index]; 
     195} 
     196 
     197Gobby::Config::Entry::iterator Gobby::Config::Entry::begin() 
     198{ 
     199        return iterator(m_table.begin() ); 
     200} 
     201 
     202Gobby::Config::Entry::iterator Gobby::Config::Entry::end() 
     203{ 
     204        return iterator(m_table.end() ); 
    152205} 
    153206 
  • src/document_settings.cpp

    rba89078 rc006fa3  
    5757        m_icon(window.render_icon(Gtk::Stock::EDIT, Gtk::ICON_SIZE_BUTTON)) 
    5858{ 
    59         m_data = Gtk::ListStore::create(m_cols); 
     59        m_data = Gtk::ListStore::create(columns); 
    6060} 
    6161 
     
    8888        get_original_encoding(const LocalDocumentInfo& info) const 
    8989{ 
    90         return (*get_iter(info))[m_cols.original_encoding]; 
     90        return (*get_iter(info))[columns.original_encoding]; 
    9191} 
    9292 
     
    9595                              const Glib::ustring& encoding) 
    9696{ 
    97         (*get_iter(info))[m_cols.original_encoding] = encoding; 
     97        (*get_iter(info))[columns.original_encoding] = encoding; 
    9898} 
    9999 
     
    101101        get_path(const LocalDocumentInfo& info) const 
    102102{ 
    103         return (*get_iter(info))[m_cols.path]; 
     103        return (*get_iter(info))[columns.path]; 
    104104} 
    105105 
     
    107107                                       const Glib::ustring& path) 
    108108{ 
    109         (*get_iter(info))[m_cols.path] = path; 
     109        (*get_iter(info))[columns.path] = path; 
    110110} 
    111111 
     
    114114{ 
    115115        return m_columns; 
    116 }*/ 
     116} 
    117117 
    118118const Gobby::DocumentSettings::Columns& 
    119119Gobby::DocumentSettings::get_columns() const 
    120120{ 
    121         return m_cols; 
    122 } 
     121        return columns; 
     122}*/ 
    123123 
    124124Glib::RefPtr<Gtk::ListStore> Gobby::DocumentSettings::get_list() 
     
    169169 
    170170        Gtk::TreeIter iter = m_data->append(); 
    171         (*iter)[m_cols.info] = &local_info; 
    172         (*iter)[m_cols.icon] = m_icon; 
    173         (*iter)[m_cols.color] = document_color(local_info); 
    174         (*iter)[m_cols.title] = local_info.get_title(); 
     171        (*iter)[columns.info] = &local_info; 
     172        (*iter)[columns.icon] = m_icon; 
     173        (*iter)[columns.color] = document_color(local_info); 
     174        (*iter)[columns.title] = local_info.get_title(); 
    175175 
    176176        m_map[&local_info] = iter; 
     
    201201{ 
    202202        LocalDocumentInfo& local_info = dynamic_cast<LocalDocumentInfo&>(info); 
    203         (*get_iter(local_info))[m_cols.title] = local_info.get_title(); 
     203        (*get_iter(local_info))[columns.title] = local_info.get_title(); 
    204204} 
    205205 
     
    208208{ 
    209209        if(&user == &info.get_buffer().get_self() ) 
    210                 (*get_iter(info))[m_cols.color] = document_color(info); 
     210                (*get_iter(info))[columns.color] = document_color(info); 
    211211} 
    212212 
     
    215215{ 
    216216        if(&user == &info.get_buffer().get_self() ) 
    217                 (*get_iter(info))[m_cols.color] = document_color(info); 
     217                (*get_iter(info))[columns.color] = document_color(info); 
    218218} 
    219219 
  • src/documentlist.cpp

    rba89078 rc006fa3  
    4848        m_btn_subscribe(_("Subscribe") ) 
    4949{ 
    50         m_view_col.pack_start(settings.get_columns().icon, false); 
    51         m_view_col.pack_start(settings.get_columns().title, false); 
     50        m_view_col.pack_start(settings.columns.icon, false); 
     51        m_view_col.pack_start(settings.columns.title, false); 
    5252        m_view_col.set_spacing(5); 
    5353 
     
    6868        m_view_col.add_attribute( 
    6969                renderer->property_foreground_gdk(), 
    70                 settings.get_columns().color 
     70                settings.columns.color 
    7171        ); 
    7272 
    73         m_view_col.set_sort_column(settings.get_columns().title); 
     73        m_view_col.set_sort_column(settings.columns.title); 
    7474 
    7575        m_tree_view.add_events(Gdk::BUTTON_PRESS_MASK); 
     
    178178 
    179179                LocalDocumentInfo* info = 
    180                         (*tree_iter)[m_settings.get_columns().info]; 
     180                        (*tree_iter)[m_settings.columns.info]; 
    181181 
    182182                if(can_subscribe(*info) ) 
     
    202202 
    203203                LocalDocumentInfo* info = 
    204                         (*tree_iter)[m_settings.get_columns().info]; 
     204                        (*tree_iter)[m_settings.columns.info]; 
    205205 
    206206                if(can_subscribe(*info) ) 
  • src/docwindow.cpp

    r1ae339e rc006fa3  
    6363 
    6464        // TODO: Set source language by filename 
    65         buf->set_highlight(true); 
     65        buf->set_highlight(false); 
    6666 
    6767        buf->signal_mark_set().connect( 
     
    148148void Gobby::DocWindow::grab_focus() 
    149149{ 
     150        Gtk::ScrolledWindow::grab_focus(); 
    150151        m_view.grab_focus(); 
    151152} 
  • src/folder.cpp

    r0c6e731 rc006fa3  
    145145} 
    146146 
     147#if 0 
    147148Glib::RefPtr<const Gtk::SourceLanguagesManager> 
    148149Gobby::Folder::get_lang_manager() const 
     
    150151        return m_header.get_lang_manager(); 
    151152} 
     153#endif 
    152154 
    153155void Gobby::Folder::obby_start(LocalBuffer& buf) 
  • src/header.cpp

    r0c6e731 rc006fa3  
    203203} 
    204204 
    205 Gobby::Header::Header(const ApplicationState& state): 
     205Gobby::Header::Header(const ApplicationState& state, 
     206                      const LangManager& lang_mgr): 
    206207        group_app(Gtk::ActionGroup::create() ), 
    207208        group_session(Gtk::ActionGroup::create() ), 
     
    409410        ), 
    410411 
    411         m_ui_manager(Gtk::UIManager::create() ), 
    412         m_lang_manager(Gtk::SourceLanguagesManager::create() ) 
     412        m_ui_manager(Gtk::UIManager::create() ) 
    413413{ 
    414414        // Assign auto actions 
     
    600600        // Get available languages 
    601601        std::list<Glib::RefPtr<Gtk::SourceLanguage> > lang_list = 
    602                 m_lang_manager->get_available_languages(); 
     602                lang_mgr->get_available_languages(); 
    603603 
    604604        // Sort languages by name 
     
    708708} 
    709709 
     710#if 0 
    710711Glib::RefPtr<Gtk::SourceLanguagesManager> Gobby::Header::get_lang_manager() 
    711712{ 
     
    718719        return m_lang_manager; 
    719720} 
     721#endif 
    720722 
    721723Gtk::MenuBar& Gobby::Header::get_menubar() 
  • src/preferences.cpp

    r0586368 rc006fa3  
    1919#include "preferences.hpp" 
    2020 
     21Gobby::Preferences::Editor::Editor() 
     22{ 
     23} 
     24 
     25Gobby::Preferences::Editor::Editor(Config::Entry& entry): 
     26        tab_width(entry["tab"]["width"].get<unsigned int>(8)), 
     27        tab_spaces(entry["tab"]["spaces"].get<bool>(false)), 
     28        indentation_auto(entry["indentation"]["auto"].get<bool>(true)), 
     29        homeend_smart(entry["homeend"]["smart"].get<bool>(true) ) 
     30{ 
     31} 
     32 
     33void Gobby::Preferences::Editor::serialise(Config::Entry& entry) const 
     34{ 
     35        entry["tab"]["width"].set(tab_width); 
     36        entry["tab"]["spaces"].set(tab_spaces); 
     37        entry["indentation"]["auto"].set(indentation_auto); 
     38        entry["homeend"]["smart"].set(homeend_smart); 
     39} 
     40 
     41Gobby::Preferences::View::View() 
     42{ 
     43} 
     44 
     45Gobby::Preferences::View::View(Config::Entry& entry): 
     46        wrap_text(entry["wrap"]["text"].get<bool>(true) ), 
     47        wrap_words(entry["wrap"]["words"].get<bool>(true) ), 
     48        linenum_display(entry["linenum"]["display"].get<bool>(true) ), 
     49        curline_highlight(entry["curline"]["highlight"].get<bool>(true) ), 
     50        margin_display(entry["margin"]["display"].get<bool>(true) ), 
     51        margin_pos(entry["margin"]["pos"].get<unsigned int>(80) ), 
     52        bracket_highlight(entry["bracket"]["highlight"].get<bool>(true) ) 
     53{ 
     54} 
     55 
     56void Gobby::Preferences::View::serialise(Config::Entry& entry) const 
     57{ 
     58        entry["wrap"]["text"].set(wrap_text); 
     59        entry["wrap"]["words"].set(wrap_words); 
     60        entry["linenum"]["display"].set(linenum_display); 
     61        entry["curline"]["highlight"].set(curline_highlight); 
     62        entry["margin"]["display"].set(margin_display); 
     63        entry["margin"]["pos"].set(margin_pos); 
     64        entry["bracket"]["highlight"].set(bracket_highlight); 
     65} 
     66 
     67Gobby::Preferences::Appearance::Appearance() 
     68{ 
     69} 
     70 
     71Gobby::Preferences::Appearance::Appearance(Config::Entry& entry): 
     72        toolbar_show( 
     73                static_cast<Gtk::ToolbarStyle>( 
     74                        entry["toolbar"]["show"].get<int>( 
     75                                static_cast<int>(Gtk::TOOLBAR_BOTH) 
     76                        ) 
     77                ) 
     78        ), 
     79        remember(entry["windows"]["remember"].get<bool>(true) ) 
     80{ 
     81} 
     82 
     83void Gobby::Preferences::Appearance::serialise(Config::Entry& entry) const 
     84{ 
     85        entry["toolbar"]["show"].set(static_cast<int>(toolbar_show) ); 
     86        entry["windows"]["remember"].set(remember); 
     87} 
     88 
     89Gobby::Preferences::FileList::iterator::iterator(const base_iterator iter): 
     90        m_iter(iter) 
     91{ 
     92} 
     93 
     94Gobby::Preferences::FileList::iterator& 
     95Gobby::Preferences::FileList::iterator::operator++() 
     96{ 
     97        ++ m_iter; 
     98        return *this; 
     99} 
     100 
     101Gobby::Preferences::FileList::iterator 
     102Gobby::Preferences::FileList::iterator::operator++(int) 
     103{ 
     104        iterator temp(m_iter); 
     105        ++ *this; 
     106        return temp; 
     107} 
     108 
     109const Glib::ustring& Gobby::Preferences::FileList::iterator::pattern() const 
     110{ 
     111        return m_iter->first; 
     112} 
     113 
     114const Gobby::Preferences::Language& 
     115Gobby::Preferences::FileList::iterator::language() const 
     116{ 
     117        return m_iter->second; 
     118} 
     119 
     120Gobby::Preferences::FileList::FileList() 
     121{ 
     122} 
     123 
     124Gobby::Preferences::FileList::FileList(Config::Entry& entry, 
     125                                       const LangManager& lang_mgr) 
     126{ 
     127        if(entry.begin() != entry.end() ) 
     128        { 
     129                for(Config::Entry::iterator iter = entry.begin(); 
     130                    iter != entry.end(); 
     131                    ++ iter) 
     132                { 
     133                        Config::Entry& ent = iter.entry(); 
     134 
     135                        Glib::ustring pattern = 
     136                                ent["pattern"].get<Glib::ustring>("unknown"); 
     137                        Glib::ustring mime = 
     138                                ent["mime_type"].get<Glib::ustring>("unknown"); 
     139 
     140                        Glib::RefPtr<Gtk::SourceLanguage> lang = 
     141                                lang_mgr->get_language_from_mime_type(mime); 
     142 
     143                        if(lang) m_files[pattern] = lang; 
     144                } 
     145        } 
     146        else 
     147        { 
     148                // Default list 
     149                add_by_mime_type("*.ada", "text/x-ada", lang_mgr); 
     150                add_by_mime_type("*.ada", "text/x-ada", lang_mgr); 
     151                add_by_mime_type("*.c", "text/x-c", lang_mgr); 
     152                add_by_mime_type("*.h", "text/x-c++", lang_mgr); 
     153                add_by_mime_type("*.hh", "text/x-c++", lang_mgr); 
     154                add_by_mime_type("*.cpp", "text/x-c++", lang_mgr); 
     155                add_by_mime_type("*.hpp", "text/x-c++", lang_mgr); 
     156                add_by_mime_type("*.cc", "text/x-c++", lang_mgr); 
     157                add_by_mime_type("*.cs", "text/x-csharp", lang_mgr); 
     158                add_by_mime_type("*.css", "text/css", lang_mgr); 
     159                add_by_mime_type("*.diff", "text/x-diff", lang_mgr); 
     160                add_by_mime_type("*.patch", "text/x-diff", lang_mgr); 
     161                add_by_mime_type("*.f", "text/x-fortran", lang_mgr); 
     162                add_by_mime_type("*.f77", "text/x-fortran", lang_mgr); 
     163                add_by_mime_type("*.hs", "text/x-haskell", lang_mgr); 
     164                add_by_mime_type("*.htm", "text/html", lang_mgr); 
     165                add_by_mime_type("*.html", "text/html", lang_mgr); 
     166                add_by_mime_type("*.xhtml", "text/html", lang_mgr); 
     167                add_by_mime_type("*.idl", "text/x-idl", lang_mgr); 
     168                add_by_mime_type("*.java", "text/x-java", lang_mgr); 
     169                add_by_mime_type("*.js", "text/x-javascript", lang_mgr); 
     170                add_by_mime_type("*.tex", "text/x-tex", lang_mgr); 
     171                add_by_mime_type("*.latex", "text/x-tex", lang_mgr); 
     172                add_by_mime_type("*.lua", "text/x-lua", lang_mgr); 
     173                add_by_mime_type("*.dpr", "text/x-pascal", lang_mgr); 
     174                add_by_mime_type("*.pas", "text/x-pascal", lang_mgr); 
     175                add_by_mime_type("*.pl", "text/x-perl", lang_mgr); 
     176                add_by_mime_type("*.pm", "text/x-perl", lang_mgr); 
     177                add_by_mime_type("*.php", "text/x-php", lang_mgr); 
     178                add_by_mime_type("*.php3", "text/x-php", lang_mgr); 
     179                add_by_mime_type("*.php4", "text/x-php", lang_mgr); 
     180                add_by_mime_type("*.php5", "text/x-php", lang_mgr); 
     181                add_by_mime_type( 
     182                        "*.po", 
     183                        "text/x-gettext-translation", 
     184                        lang_mgr 
     185                ); 
     186                add_by_mime_type("*.py", "text/x-python", lang_mgr); 
     187                add_by_mime_type("*.rb", "text/x-ruby", lang_mgr); 
     188                add_by_mime_type("*.sql", "text/x-sql", lang_mgr); 
     189                add_by_mime_type("*.texi", "text/x-texinfo", lang_mgr); 
     190                add_by_mime_type("*.bas", "text/x-vb", lang_mgr); 
     191                add_by_mime_type("*.vbs", "text/x-vb", lang_mgr); 
     192                add_by_mime_type("*.v", "text/x-verilog-src", lang_mgr); 
     193                add_by_mime_type("*.xml", "text/xml", lang_mgr); 
     194                add_by_mime_type( 
     195                        "*.desktop", 
     196                        "application/x-gnome-app-info", 
     197                        lang_mgr 
     198                ); 
     199                add_by_mime_type("*.tcl", "text/x-tcl", lang_mgr); 
     200                add_by_mime_type("Makefile", "text/x-Maxefile", lang_mgr); 
     201        } 
     202} 
     203 
     204void Gobby::Preferences::FileList::serialise(Config::Entry& entry) const 
     205{ 
     206        int num = 0; 
     207 
     208        for(map_type::const_iterator iter = m_files.begin(); 
     209            iter != m_files.end(); 
     210            ++ iter) 
     211        { 
     212                std::stringstream stream; 
     213                stream << "file" << (++num); 
     214 
     215                std::list<Glib::ustring> mime_types = 
     216                        iter->second->get_mime_types(); 
     217 
     218                Config::Entry& main = entry[stream.str()]; 
     219 
     220                main["pattern"].set(iter->first); 
     221                main["mime_type"].set(mime_types.front()); 
     222        } 
     223} 
     224 
     225Gobby::Preferences::FileList::iterator 
     226Gobby::Preferences::FileList::add(const Glib::ustring& pattern, 
     227                                  const Language& lang) 
     228{ 
     229        //map_type::iterator iter = m_files.find(pattern); 
     230        //if(iter != m_files.end() ) return iter; 
     231        return iterator(m_files.insert(std::make_pair(pattern, lang) ).first); 
     232} 
     233 
     234Gobby::Preferences::FileList::iterator 
     235Gobby::Preferences::FileList::add_by_mime_type(const Glib::ustring& pattern, 
     236                                               const Glib::ustring& mime_type, 
     237                                               const LangManager& lang_mgr) 
     238{ 
     239        Glib::RefPtr<Gtk::SourceLanguage> lang = 
     240                lang_mgr->get_language_from_mime_type(mime_type); 
     241 
     242        if(lang) 
     243                return add(pattern, lang); 
     244        else 
     245                return iterator(m_files.end()); 
     246} 
     247 
     248Gobby::Preferences::FileList::iterator 
     249Gobby::Preferences::FileList::begin() const 
     250{ 
     251        return iterator(m_files.begin() ); 
     252} 
     253 
     254Gobby::Preferences::FileList::iterator 
     255Gobby::Preferences::FileList::end() const 
     256{ 
     257        return iterator(m_files.end() ); 
     258} 
     259 
    21260Gobby::Preferences::Preferences() 
    22261{ 
     
    24263} 
    25264 
    26 Gobby::Preferences::Preferences(Config& config) 
    27 { 
    28         // Read preferences from config 
    29         editor.tab_width = 
    30                 config["editor"]["tab"]["width"].get<unsigned int>(8); 
    31         editor.tab_spaces = config["editor"]["tab"]["spaces"].get<bool>(false); 
    32         editor.indentation_auto = 
    33                 config["editor"]["indentation"]["auto"].get<bool>(true); 
    34         editor.homeend_smart = 
    35                 config["editor"]["homeend"]["smart"].get<bool>(true); 
    36  
    37         view.wrap_text = config["view"]["wrap"]["text"].get<bool>(true); 
    38         view.wrap_words = config["view"]["wrap"]["words"].get<bool>(true); 
    39         view.linenum_display = 
    40                 config["view"]["linenum"]["display"].get<bool>(true); 
    41         view.curline_highlight = 
    42                 config["view"]["curline"]["highlight"].get<bool>(true); 
    43         view.margin_display = 
    44                 config["view"]["margin"]["display"].get<bool>(true); 
    45         view.margin_pos = 
    46                 config["view"]["margin"]["pos"].get<unsigned int>(80); 
    47         view.bracket_highlight = 
    48                 config["view"]["bracket"]["highlight"].get<bool>(true); 
    49  
    50         appearance.toolbar_show = static_cast<Gtk::ToolbarStyle>( 
    51                 config["appearance"]["toolbar"]["show"].get<int>( 
    52                         static_cast<int>(Gtk::TOOLBAR_BOTH) 
    53                 ) 
    54         ); 
    55         appearance.remember = 
    56                 config["appearance"]["windows"]["remember"].get<bool>(true); 
    57 } 
    58  
    59 Gobby::Preferences::Preferences(const Preferences& other) 
    60 { 
    61         *this = other; 
    62 } 
    63  
    64 Gobby::Preferences::~Preferences() 
    65 { 
    66 } 
    67  
    68 void Gobby::Preferences::serialise(Config& config) 
     265Gobby::Preferences::Preferences(Config& config, const LangManager& lang_mgr): 
     266        editor(config["editor"]), 
     267        view(config["view"]), 
     268        appearance(config["appearance"]), 
     269        files(config["files"], lang_mgr) 
     270{ 
     271} 
     272 
     273void Gobby::Preferences::serialise(Config& config) const 
    69274{ 
    70275        // Serialise into config 
    71         config["editor"]["tab"]["width"].set(editor.tab_width); 
    72         config["editor"]["tab"]["spaces"].set(editor.tab_spaces); 
    73         config["editor"]["indentation"]["auto"].set(editor.indentation_auto); 
    74         config["editor"]["homeend"]["smart"].set(editor.homeend_smart); 
    75  
    76         config["view"]["wrap"]["text"].set(view.wrap_text); 
    77         config["view"]["wrap"]["words"].set(view.wrap_words); 
    78         config["view"]["linenum"]["display"].set(view.linenum_display); 
    79         config["view"]["curline"]["highlight"].set(view.curline_highlight); 
    80         config["view"]["margin"]["display"].set(view.margin_display); 
    81         config["view"]["margin"]["pos"].set(view.margin_pos); 
    82         config["view"]["bracket"]["highlight"].set(view.bracket_highlight); 
    83  
    84         config["appearance"]["toolbar"]["show"].set( 
    85                 static_cast<int>(appearance.toolbar_show) ); 
    86         config["appearance"]["windows"]["remember"].set(appearance.remember); 
    87 } 
    88  
    89 Gobby::Preferences& Gobby::Preferences::operator=(const Preferences& other) 
    90 { 
    91         editor = other.editor; 
    92         view = other.view; 
    93         appearance = other.appearance; 
    94  
    95         return *this; 
    96 } 
    97  
     276        editor.serialise(config["editor"]); 
     277        view.serialise(config["view"]); 
     278        appearance.serialise(config["appearance"]); 
     279        files.serialise(config["files"]); 
     280} 
  • src/window.cpp

    r0c6e731 rc006fa3  
    5151Gobby::Window::Window(const IconManager& icon_mgr, Config& config): 
    5252        Gtk::Window(Gtk::WINDOW_TOPLEVEL), m_config(config), 
    53         m_preferences(m_config), m_icon_mgr(icon_mgr), 
     53        m_lang_manager(Gtk::SourceLanguagesManager::create() ), 
     54        m_preferences(m_config, m_lang_manager), m_icon_mgr(icon_mgr), 
    5455#ifdef WITH_HOWL 
    5556        m_zeroconf(NULL), 
    5657#endif 
    5758        m_application_state(APPLICATION_NONE), 
    58         m_document_settings(*this), m_header(m_application_state), 
     59        m_document_settings(*this), 
     60        m_header(m_application_state, m_lang_manager), 
    5961        m_userlist(*this, m_header, m_preferences, config["windows"]), 
    6062        m_documentlist( 
     
    472474        dlg.get_vbox()->pack_start(m_chk_default_ext, Gtk::PACK_SHRINK); 
    473475        // This option confuses the overwrite confirmation :/ 
    474 //      m_chk_default_ext.show(); 
     476        //m_chk_default_ext.show(); 
    475477 
    476478#ifdef GTKMM_GEQ_28 
     
    529531        dlg.set_version(PACKAGE_VERSION); 
    530532        dlg.set_comments(_("A collaborative text editor")); 
    531         dlg.set_copyright("Copyright (C) 2005 0x539 dev group <crew@0x539.de>"); 
     533 
     534        dlg.set_copyright( 
     535                "Copyright (C) 2005, 2006 0x539 dev " 
     536                "group <crew@0x539.de>" 
     537        ); 
     538 
    532539        dlg.set_logo(m_icon_mgr.gobby); 
    533540 
     
    986993        { 
    987994                // Quit session 
    988                 obby_end(); 
     995                if(m_buffer.get() != NULL && m_buffer->is_open() ) 
     996                        obby_end(); 
    989997                // End program 
    990998                Gtk::Main::quit();