Changeset 4d93728da871025d81db8def0f0fe41be31a0a8f

Show
Ignore:
Timestamp:
01/06/07 23:43:10 (6 years ago)
Author:
Philipp Kern <phil@…>
Parents:
5e8e3af711c40ac00f6c9e31414997faee48d83e
Children:
42eed7fcd5c2709d714983be46e3a133cc732b73
git-committer:
Philipp Kern <phil@0x539.de> / 2007-01-06T22:43:10Z+0000
Message:

[project @ Drag+Drop of files into open Gobby session]

Original author: Armin Burgmeier <armin@…>
Date: 2005-07-23 19:25:58+00:00

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • inc/window.hpp

    r5e8e3af r4d93728  
    8181        void on_chat(const Glib::ustring& message); 
    8282 
     83        // Drag and drop 
     84        virtual void on_drag_data_received( 
     85                const Glib::RefPtr<Gdk::DragContext>& context, 
     86                int x, int y, const Gtk::SelectionData& data, 
     87                guint info, guint time 
     88        ); 
     89 
    8390        // Obby signal handlers 
    8491        void on_obby_close(); 
     
    95102 
    96103        // Helper functions 
     104        void open_local_file(const Glib::ustring& file); 
    97105        void close_document(DocWindow& doc); 
    98106        void display_error(const Glib::ustring& message); 
  • src/window.cpp

    r5e8e3af r4d93728  
    170170                sigc::mem_fun(*this, &Window::on_obby_server_chat) ); 
    171171 
     172        // Accept drag and drop of files into the gobby window 
     173        std::list<Gtk::TargetEntry> targets; 
     174        targets.push_back(Gtk::TargetEntry("text/uri-list") ); 
     175        drag_dest_set(targets); 
     176 
    172177        // Delegate start of obby session 
    173178        m_header.obby_start(*m_buffer); 
     
    199204void Gobby::Window::obby_end() 
    200205{ 
     206        // No drag and drop anymore 
     207        drag_dest_unset(); 
     208 
    201209        // Nothing to do if no buffer is open 
    202210        if(!m_buffer.get() ) return; 
     
    387395void Gobby::Window::on_document_open() 
    388396{ 
     397        // Create FileChooser 
    389398        Gtk::FileChooserDialog dlg(*this, _("Open new document")); 
     399        // Create buttons to close it 
    390400        dlg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 
    391401        dlg.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); 
    392402 
     403        // TODO: MultiSelection? 
     404        // Show FileChooser 
    393405        if(dlg.run() == Gtk::RESPONSE_OK) 
    394406        { 
    395                 // TODO: Set path in newly generated document 
    396                 m_buffer->create_document( 
    397                         Glib::path_get_basename(dlg.get_filename()), 
    398                         Glib::file_get_contents(dlg.get_filename()) ); 
     407                // Open chosen file 
     408                open_local_file(dlg.get_filename() ); 
    399409        } 
    400410} 
     
    574584} 
    575585 
     586/* Drag and Drop */ 
     587void Gobby::Window::on_drag_data_received( 
     588        const Glib::RefPtr<Gdk::DragContext>& context, 
     589        int x, int y, const Gtk::SelectionData& data, 
     590        guint info, guint time 
     591) 
     592{ 
     593        // We only accept uri-lists as new files to open 
     594        if(data.get_target() == "text/uri-list") 
     595        { 
     596                // Get files by dragdata 
     597                std::vector<std::string> files = data.get_uris(); 
     598 
     599                // Open all of them 
     600                for(std::vector<std::string>::iterator iter = files.begin(); 
     601                    iter != files.end(); 
     602                    ++ iter) 
     603                { 
     604                        try 
     605                        { 
     606                                // Convert URI to filename 
     607                                open_local_file( 
     608                                        Glib::filename_from_uri(*iter) ); 
     609                        } 
     610                        catch(Glib::Exception& e) 
     611                        { 
     612                                // Show any errors while converting a file 
     613                                display_error(e.what() ); 
     614                        } 
     615                } 
     616        } 
     617 
     618        // Call base function 
     619        Gtk::Window::on_drag_data_received(context, x, y, data, info, time); 
     620} 
     621 
    576622void Gobby::Window::on_obby_close() 
    577623{ 
     
    649695} 
    650696 
    651 void Gobby::Window::display_error(const Glib::ustring& message) 
    652 { 
    653         Gtk::MessageDialog dlg(*this, message, false, Gtk::MESSAGE_ERROR, 
    654                                Gtk::BUTTONS_OK, true); 
    655         dlg.run(); 
     697void Gobby::Window::open_local_file(const Glib::ustring& file) 
     698{ 
     699        // TODO: Set path in newly generated document 
     700        // TODO: Convert file to UTF-8 
     701        m_buffer->create_document( 
     702                Glib::path_get_basename(file), 
     703                Glib::file_get_contents(file) 
     704        ); 
    656705} 
    657706 
     
    678727} 
    679728 
     729void Gobby::Window::display_error(const Glib::ustring& message) 
     730{ 
     731        Gtk::MessageDialog dlg(*this, message, false, Gtk::MESSAGE_ERROR, 
     732                               Gtk::BUTTONS_OK, true); 
     733        dlg.run(); 
     734} 
     735