Changeset 883ac1c0c36c0f5370a1dcb4bcde33f4b72c0a7f
- Timestamp:
- 06/22/08 01:06:41 (5 years ago)
- Parents:
- 91aa9b20f84f5db304446175b7e75cccb2f4bab7
- Children:
- b00f66c045b9598773e5dcadfdcf887be78d63a3
- git-committer:
- Armin Burgmeier <armin@arbur.net> / 2008-06-22T01:06:41Z+0200
- Files:
-
- 7 added
- 16 modified
-
ChangeLog (modified) (1 diff)
-
configure.ac (modified) (1 diff)
-
inc/commands/file-commands.hpp (modified) (3 diffs)
-
inc/operations/.operation-open.hpp.swp (added)
-
inc/operations/Makefile.am (modified) (1 diff)
-
inc/operations/documentinfostorage.hpp (added)
-
inc/operations/operation-open.hpp (added)
-
inc/operations/operations.hpp (modified) (4 diffs)
-
inc/util/Makefile.am (modified) (1 diff)
-
inc/util/config.hpp (modified) (1 diff)
-
inc/util/file.hpp (added)
-
inc/util/resolv.hpp (modified) (1 diff)
-
inc/window.hpp (modified) (1 diff)
-
src/commands/file-commands.cpp (modified) (2 diffs)
-
src/main.cpp (modified) (2 diffs)
-
src/operations/Makefile.am (modified) (1 diff)
-
src/operations/documentinfostorage.cpp (added)
-
src/operations/operation-open.cpp (added)
-
src/operations/operations.cpp (modified) (3 diffs)
-
src/util/Makefile.am (modified) (1 diff)
-
src/util/config.cpp (modified) (4 diffs)
-
src/util/file.cpp (added)
-
src/window.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r91aa9b2 r883ac1c 1 2008-06-22 Armin Burgmeier <armin@0x539.de> 2 3 * inc/util/file.hpp: 4 * src/util/file.cpp: 5 * inc/util/Makefile.am: 6 * src/util/Makefile.am: Added file.hpp/.cpp containing utility 7 functions to deal with the filesystem. Currently, a function that 8 creates a directory and all its parent if necessary is implemented. 9 10 * inc/util/config.hpp: 11 * src/util/config.cpp: Make use of that function in the destructor. 12 13 * inc/util/resolv.hpp: Include <memory> since we use std::auto_ptr<>. 14 15 * inc/operations/documentinfostorage.hpp: 16 * src/operations/documentinfostorage.cpp: Added class that stores 17 local information on known documents such as the local location, the 18 encoding and the eol style. 19 20 * inc/operations/operation-open.hpp: 21 * src/operations/operation-open.cpp: Implemented opening documents 22 from files, via giomm. 23 24 * inc/operations/Makefile.am: 25 * src/operations/Makefile.am: Add the new source files to the build. 26 27 * inc/operations/operations.hpp: 28 * src/operations/operations.cpp: Added encoding parameter to 29 create_document(), added DocumentInfoStorage member. 30 31 * inc/commands/file-commands.hpp: 32 * src/commands/file-commands.cpp: Added functionlity for the Open menu 33 item. 34 35 * inc/window.hpp: 36 * src/window.cpp: Instantiate a DocumentInfoStorage, pass to 37 Operations. 38 39 * src/main.cpp: Initialize giomm. 40 41 * configure.ac: Added giomm as a dependency. 42 1 43 2008-05-19 Armin Burgmeier <armin@0x539.de> 2 44 -
configure.ac
r91aa9b2 r883ac1c 37 37 AM_CONDITIONAL(WIN32, test x$win32 = xtrue) 38 38 39 required_libs="libxml++-2.6 glibmm-2.4 >= 2.16.0 g tkmm-2.4 >= 2.12.0 gthread-2.0 gtksourceview-2.0 libinfinity-1.0 libinftext-1.0 libinfgtk-1.0 libinftextgtk-1.0"39 required_libs="libxml++-2.6 glibmm-2.4 >= 2.16.0 giomm-2.4 >= 2.16.0 gtkmm-2.4 >= 2.12.0 gthread-2.0 gtksourceview-2.0 libinfinity-1.0 libinftext-1.0 libinfgtk-1.0 libinftextgtk-1.0" 40 40 41 41 # Checks for libraries. -
inc/commands/file-commands.hpp
r91aa9b2 r883ac1c 26 26 27 27 #include <gtkmm/window.h> 28 #include <gtkmm/filechooserdialog.h> 28 29 #include <sigc++/trackable.h> 29 30 … … 39 40 40 41 protected: 42 enum Mode { 43 MODE_NEW, 44 MODE_OPEN, 45 MODE_SAVE 46 }; 47 48 void create_file_dialog(); 49 void create_location_dialog(); 50 41 51 void on_new(); 52 void on_open(); 53 54 void on_file_dialog_response(int id); 42 55 void on_location_dialog_response(int id); 43 56 … … 47 60 Operations& m_operations; 48 61 62 std::string m_open_uri; 63 64 Mode m_mode; 49 65 std::auto_ptr<DocumentLocationDialog> m_location_dialog; 66 std::auto_ptr<Gtk::FileChooserDialog> m_file_dialog; 50 67 }; 51 68 -
inc/operations/Makefile.am
r91aa9b2 r883ac1c 1 1 2 2 noinst_HEADERS = \ 3 documentinfostorage.hpp \ 3 4 operations.hpp \ 4 operation-new.hpp 5 operation-new.hpp \ 6 operation-open.hpp -
inc/operations/operations.hpp
r91aa9b2 r883ac1c 20 20 #define _GOBBY_OPERATIONS_OPERATIONS_HPP_ 21 21 22 #include "operations/documentinfostorage.hpp" 22 23 #include "core/statusbar.hpp" 23 24 … … 47 48 } 48 49 50 DocumentInfoStorage& get_info_storage() 51 { 52 return m_operations.m_info_storage; 53 } 54 49 55 void remove() { m_operations.remove_operation(this); } 50 56 private: … … 52 58 }; 53 59 54 Operations( StatusBar& status_bar);60 Operations(DocumentInfoStorage& info_storage, StatusBar& status_bar); 55 61 ~Operations(); 56 62 … … 62 68 InfcBrowserIter* parent, 63 69 const Glib::ustring name, 64 const Glib::ustring& from_uri); 70 const Glib::ustring& from_uri, 71 const char* encoding); 65 72 66 73 protected: 67 74 void remove_operation(Operation* operation); 68 75 76 DocumentInfoStorage& m_info_storage; 69 77 StatusBar& m_status_bar; 70 78 -
inc/util/Makefile.am
rdddf956 r883ac1c 5 5 defaultaccumulator.hpp \ 6 6 encoding.hpp \ 7 file.hpp \ 7 8 i18n.hpp \ 8 9 resolv.hpp \ -
inc/util/config.hpp
rdddf956 r883ac1c 38 38 { 39 39 public: 40 class Error: public Glib::Error41 {42 public:43 enum Code {44 PATH_CREATION_FAILED45 };46 47 Error(Code error_code, const Glib::ustring& error_message);48 Code code() const;49 };50 51 40 /** @brief Abstract base class for configuration file entries. 52 41 */ -
inc/util/resolv.hpp
rdddf956 r883ac1c 24 24 #include <glibmm/ustring.h> 25 25 #include <sigc++/sigc++.h> 26 26 27 #include <stdexcept> 28 #include <memory> 27 29 28 30 namespace Gobby -
inc/window.hpp
r91aa9b2 r883ac1c 89 89 90 90 // Functionality 91 DocumentInfoStorage m_info_storage; 91 92 Operations m_operations; 92 93 -
src/commands/file-commands.cpp
r91aa9b2 r883ac1c 20 20 #include "util/i18n.hpp" 21 21 22 #include <gtkmm/stock.h> 23 22 24 Gobby::FileCommands::FileCommands(Gtk::Window& parent, Header& header, 23 25 const Browser& browser, Folder& folder, 24 26 Operations& operations): 25 27 m_parent(parent), m_browser(browser), m_folder(folder), 26 m_operations(operations) 28 m_operations(operations), m_mode(MODE_NEW) 27 29 { 28 30 header.action_file_new->signal_activate().connect( 29 31 sigc::mem_fun(*this, &FileCommands::on_new)); 32 header.action_file_open->signal_activate().connect( 33 sigc::mem_fun(*this, &FileCommands::on_open)); 34 } 35 36 void Gobby::FileCommands::create_location_dialog() 37 { 38 m_location_dialog.reset( 39 new DocumentLocationDialog( 40 m_parent, 41 INF_GTK_BROWSER_MODEL( 42 m_browser.get_store()))); 43 44 m_location_dialog->signal_response().connect( 45 sigc::mem_fun( 46 *this, 47 &FileCommands::on_location_dialog_response)); 48 } 49 50 void Gobby::FileCommands::create_file_dialog() 51 { 52 m_file_dialog.reset(new Gtk::FileChooserDialog(m_parent, "")); 53 m_file_dialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 54 m_file_dialog->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); 55 m_file_dialog->signal_response().connect( 56 sigc::mem_fun(*this, &FileCommands::on_file_dialog_response)); 30 57 } 31 58 32 59 void Gobby::FileCommands::on_new() 33 60 { 61 if(m_file_dialog.get() != NULL) 62 m_file_dialog->hide(); 63 34 64 if(m_location_dialog.get() == NULL) 65 create_location_dialog(); 66 67 m_mode = MODE_NEW; 68 m_location_dialog->set_document_name(_("New Document")); 69 m_location_dialog->present(); 70 } 71 72 void Gobby::FileCommands::on_open() 73 { 74 if(m_location_dialog.get() != NULL) 75 m_location_dialog->hide(); 76 77 if(m_file_dialog.get() == NULL) 78 create_file_dialog(); 79 80 // TODO: Allow multiple selection 81 // TODO: Encoding selection in file chooser 82 m_mode = MODE_OPEN; 83 m_file_dialog->set_title("Choose a text file to open"); 84 m_file_dialog->set_action(Gtk::FILE_CHOOSER_ACTION_OPEN); 85 m_file_dialog->present(); 86 } 87 88 void Gobby::FileCommands::on_file_dialog_response(int id) 89 { 90 if(id == Gtk::RESPONSE_ACCEPT) 35 91 { 36 m_location_dialog.reset(37 new DocumentLocationDialog(38 m_parent,39 INF_GTK_BROWSER_MODEL(40 m_browser.get_store())));92 switch(m_mode) 93 { 94 case MODE_OPEN: 95 if(m_location_dialog.get() == NULL) 96 create_location_dialog(); 41 97 42 m_location_dialog->signal_response().connect( 43 sigc::mem_fun( 44 *this, 45 &FileCommands::on_location_dialog_response)); 98 // TODO: Handle multiple selection 99 m_open_uri = m_file_dialog->get_uri(); 100 m_location_dialog->set_document_name( 101 Glib::path_get_basename( 102 m_file_dialog->get_filename())); 103 m_location_dialog->present(); 104 105 break; 106 case MODE_SAVE: 107 // TODO: 108 break; 109 case MODE_NEW: 110 default: 111 g_assert_not_reached(); 112 } 46 113 } 47 114 48 m_location_dialog->set_document_name(_("New Document")); 49 m_location_dialog->present(); 115 m_file_dialog->hide(); 50 116 } 51 117 … … 59 125 g_assert(browser != NULL); 60 126 61 m_operations.create_document( 62 browser, &iter, 63 m_location_dialog->get_document_name()); 127 switch(m_mode) 128 { 129 case MODE_NEW: 130 m_operations.create_document( 131 browser, &iter, 132 m_location_dialog->get_document_name()); 133 break; 134 case MODE_OPEN: 135 m_operations.create_document( 136 browser, &iter, 137 m_location_dialog->get_document_name(), 138 m_open_uri, NULL); 139 break; 140 case MODE_SAVE: 141 default: 142 g_assert_not_reached(); 143 } 64 144 } 65 145 -
src/main.cpp
rdddf956 r883ac1c 25 25 #include <gtkmm/main.h> 26 26 #include <gtkmm/messagedialog.h> 27 #include <giomm/init.h> 27 28 #include <glibmm/optionentry.h> 28 29 #include <glibmm/optiongroup.h> 29 30 #include <glibmm/optioncontext.h> 30 31 32 #include <libintl.h> // bindtextdomain 31 33 #include <iostream> 32 34 … … 48 50 g_thread_init(NULL); 49 51 gnutls_global_init(); 52 Gio::init(); 50 53 51 54 setlocale(LC_ALL, ""); -
src/operations/Makefile.am
r91aa9b2 r883ac1c 2 2 3 3 libgobby_operations_a_SOURCES = \ 4 documentinfostorage.cpp \ 4 5 operations.cpp \ 5 operation-new.cpp 6 operation-new.cpp \ 7 operation-open.cpp 6 8 7 9 libgobby_operations_a_CPPFLAGS = $(gobby_CFLAGS) -I../../inc/ \ -
src/operations/operations.cpp
r91aa9b2 r883ac1c 18 18 19 19 #include "operations/operation-new.hpp" 20 #include "operations/operation-open.hpp" 20 21 #include "operations/operations.hpp" 21 22 … … 25 26 Gobby::Operations::Operation::~Operation() {} 26 27 27 Gobby::Operations::Operations(StatusBar& status_bar): 28 m_status_bar(status_bar) 28 Gobby::Operations::Operations(DocumentInfoStorage& info_storage, 29 StatusBar& status_bar): 30 m_info_storage(info_storage), m_status_bar(status_bar) 29 31 { 30 32 } … … 49 51 InfcBrowserIter* parent, 50 52 const Glib::ustring name, 51 const Glib::ustring& from_uri) 53 const Glib::ustring& from_uri, 54 const char* encoding) 52 55 { 56 m_operations.insert(new OperationOpen(*this, browser, parent, name, 57 from_uri, encoding)); 53 58 } 54 59 -
src/util/Makefile.am
rdddf956 r883ac1c 5 5 config.cpp \ 6 6 encoding.cpp \ 7 file.cpp \ 7 8 i18n.cpp \ 8 9 resolv.cpp \ -
src/util/config.cpp
rdddf956 r883ac1c 18 18 19 19 #include "util/config.hpp" 20 #include "util/file.hpp" 20 21 #include "util/i18n.hpp" 21 22 … … 26 27 #include <libxml++/exceptions/exception.h> 27 28 28 // For mkdir / CreateDirectory29 #ifdef WIN3230 #include <windows.h>31 #else32 #include <sys/stat.h>33 #include <sys/types.h>34 #include <cerrno>35 #endif36 37 #include <cstring>38 29 #include <stdexcept> 39 30 40 31 namespace 41 32 { 42 // Creates a new directory43 void create_directory(const char* path)44 {45 using namespace Gobby;46 #ifdef WIN3247 if(CreateDirectoryA(path, NULL) == FALSE)48 {49 LPVOID msgbuf;50 DWORD err = GetLastError();51 52 FormatMessageA(53 FORMAT_MESSAGE_ALLOCATE_BUFFER |54 FORMAT_MESSAGE_FROM_SYSTEM,55 NULL,56 err,57 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),58 reinterpret_cast<LPSTR>(&msgbuf),59 0,60 NULL61 );62 63 std::string error_message = static_cast<LPSTR>(msgbuf);64 LocalFree(msgbuf);65 66 // TODO: Convert to UTF-8?67 68 throw Gobby::Config::Error(69 Gobby::Config::Error::PATH_CREATION_FAILED,70 Glib::ustring::compose(71 _("Could not create directory "72 "\"%1\": %2"), std::string(path),73 error_message));74 }75 #else76 if(mkdir(path, 0755) == -1)77 {78 throw Gobby::Config::Error(79 Gobby::Config::Error::PATH_CREATION_FAILED,80 Glib::ustring::compose(81 _("Could not create directory "82 "\"%1\": %2"), std::string(path),83 strerror(errno)));84 }85 #endif86 }87 88 void create_path_to(const std::string& to)89 {90 // Directory exists, nothing to do91 if(Glib::file_test(to, Glib::FILE_TEST_IS_DIR) )92 return;93 94 // Find path to the directory to create95 Glib::ustring path_to = Glib::path_get_dirname(to);96 97 // Create this path, if it doesn't exists98 create_path_to(path_to);99 100 // Create new directory101 create_directory(to.c_str() );102 }103 104 33 template<typename Map> 105 34 typename Map::mapped_type ptrmap_find(const Map& map, … … 110 39 return iter->second; 111 40 } 112 }113 114 Gobby::Config::Error::Error(Code error_code,115 const Glib::ustring& error_message):116 Glib::Error(117 g_quark_from_static_string("GOBBY_CONFIG_ERROR"),118 static_cast<int>(error_code),119 error_message120 )121 {122 }123 124 Gobby::Config::Error::Code Gobby::Config::Error::code() const125 {126 return static_cast<Code>(gobject_->code);127 41 } 128 42 … … 318 232 { 319 233 Glib::ustring dirname = Glib::path_get_dirname(m_filename); 320 create_ path_to(dirname);234 create_directory_with_parents(dirname); 321 235 322 236 document.write_to_file_formatted(m_filename, "UTF-8"); -
src/window.cpp
r91aa9b2 r883ac1c 31 31 m_statusbar(m_folder), 32 32 m_browser(*this, Plugins::TEXT, m_statusbar, m_preferences), 33 m_operations(m_statusbar), 33 m_info_storage(INF_GTK_BROWSER_MODEL(m_browser.get_store())), 34 m_operations(m_info_storage, m_statusbar), 34 35 m_commands_browser(m_browser, m_folder, m_statusbar, m_preferences), 35 36 m_commands_file(*this, m_header, m_browser, m_folder, m_operations)
