Changeset 4d93728da871025d81db8def0f0fe41be31a0a8f
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r5e8e3af
|
r4d93728
|
|
| 81 | 81 | void on_chat(const Glib::ustring& message); |
| 82 | 82 | |
| | 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 | |
| 83 | 90 | // Obby signal handlers |
| 84 | 91 | void on_obby_close(); |
| … |
… |
|
| 95 | 102 | |
| 96 | 103 | // Helper functions |
| | 104 | void open_local_file(const Glib::ustring& file); |
| 97 | 105 | void close_document(DocWindow& doc); |
| 98 | 106 | void display_error(const Glib::ustring& message); |
-
|
r5e8e3af
|
r4d93728
|
|
| 170 | 170 | sigc::mem_fun(*this, &Window::on_obby_server_chat) ); |
| 171 | 171 | |
| | 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 | |
| 172 | 177 | // Delegate start of obby session |
| 173 | 178 | m_header.obby_start(*m_buffer); |
| … |
… |
|
| 199 | 204 | void Gobby::Window::obby_end() |
| 200 | 205 | { |
| | 206 | // No drag and drop anymore |
| | 207 | drag_dest_unset(); |
| | 208 | |
| 201 | 209 | // Nothing to do if no buffer is open |
| 202 | 210 | if(!m_buffer.get() ) return; |
| … |
… |
|
| 387 | 395 | void Gobby::Window::on_document_open() |
| 388 | 396 | { |
| | 397 | // Create FileChooser |
| 389 | 398 | Gtk::FileChooserDialog dlg(*this, _("Open new document")); |
| | 399 | // Create buttons to close it |
| 390 | 400 | dlg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
| 391 | 401 | dlg.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); |
| 392 | 402 | |
| | 403 | // TODO: MultiSelection? |
| | 404 | // Show FileChooser |
| 393 | 405 | if(dlg.run() == Gtk::RESPONSE_OK) |
| 394 | 406 | { |
| 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() ); |
| 399 | 409 | } |
| 400 | 410 | } |
| … |
… |
|
| 574 | 584 | } |
| 575 | 585 | |
| | 586 | /* Drag and Drop */ |
| | 587 | void 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 | |
| 576 | 622 | void Gobby::Window::on_obby_close() |
| 577 | 623 | { |
| … |
… |
|
| 649 | 695 | } |
| 650 | 696 | |
| 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(); |
| | 697 | void 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 | ); |
| 656 | 705 | } |
| 657 | 706 | |
| … |
… |
|
| 678 | 727 | } |
| 679 | 728 | |
| | 729 | void 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 | |