glom r2019 - in trunk: . glom/bakery
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r2019 - in trunk: . glom/bakery
- Date: Tue, 24 Mar 2009 00:13:39 +0000 (UTC)
Author: murrayc
Date: Tue Mar 24 00:13:39 2009
New Revision: 2019
URL: http://svn.gnome.org/viewvc/glom?rev=2019&view=rev
Log:
2009-03-24 Murray Cumming <murrayc murrayc com>
* glom/bakery/Makefile.am:
* glom/bakery/GtkDialogs.[h|cc]: Remove this, moving the code into
these functions that previously just called the same named functions
in GtkDialogs, for reasons that are no longer relevant:
* glom/bakery/App_WithDoc_Gtk.cc ui_warning(),
ui_file_select_open(), uri_is_writable(),
ui_file_select_save(), ui_offer_to_save_changes().
Removed:
trunk/glom/bakery/GtkDialogs.cc
trunk/glom/bakery/GtkDialogs.h
Modified:
trunk/ChangeLog
trunk/glom/bakery/App.cc
trunk/glom/bakery/App_WithDoc_Gtk.cc
trunk/glom/bakery/Makefile.am
Modified: trunk/glom/bakery/App.cc
==============================================================================
--- trunk/glom/bakery/App.cc (original)
+++ trunk/glom/bakery/App.cc Tue Mar 24 00:13:39 2009
@@ -49,8 +49,6 @@
{
//set_wmclass(m_strAppName, m_strTitle); //The docs say "Don't use this".
- //TODO: set_statusbar(m_Status);
-
init_ui_manager();
init_menus();
init_toolbars();
Modified: trunk/glom/bakery/App_WithDoc_Gtk.cc
==============================================================================
--- trunk/glom/bakery/App_WithDoc_Gtk.cc (original)
+++ trunk/glom/bakery/App_WithDoc_Gtk.cc Tue Mar 24 00:13:39 2009
@@ -19,12 +19,15 @@
#include <config.h>
#include <glom/bakery/App_WithDoc_Gtk.h>
-#include <glom/bakery/GtkDialogs.h>
+#include <glom/bakery/Dialog_OfferSave.h>
//#include <libgnomevfsmm/utils.h> //For escape_path_string()
//#include <libgnomevfsmm/mime-handlers.h> //For type_is_known().
#include <gtkmm/toolbutton.h>
#include <gtkmm/stock.h>
#include <gtkmm/recentchoosermenu.h>
+#include <gtkmm/messagedialog.h>
+#include <gtkmm/filechooserdialog.h>
+#include <giomm.h>
#include <algorithm>
#include <glibmm/i18n-lib.h>
@@ -212,17 +215,181 @@
void App_WithDoc_Gtk::ui_warning(const Glib::ustring& text, const Glib::ustring& secondary_text)
{
- GtkDialogs::ui_warning(*this, text, secondary_text);
+ Gtk::Window* pWindow = this;
+
+#ifdef GLOM_ENABLE_MAEMO
+ Hildon::Note dialog(Hildon::NOTE_TYPE_INFORMATION, text, Gtk::Stock::DIALOG_WARNING);
+#else
+ Gtk::MessageDialog dialog(App_Gtk::util_bold_message(text), true /* use markup */, Gtk::MESSAGE_WARNING);
+ dialog.set_secondary_text(secondary_text);
+
+ dialog.set_title(""); //The HIG says that alert dialogs should not have titles. The default comes from the message type.
+#endif
+
+ if(pWindow)
+ dialog.set_transient_for(*pWindow);
+
+ dialog.run();
}
Glib::ustring App_WithDoc_Gtk::ui_file_select_open(const Glib::ustring& starting_folder_uri)
{
- return GtkDialogs::ui_file_select_open(*this, starting_folder_uri);
+ Gtk::Window* pWindow = this;
+
+#ifdef GLOM_ENABLE_MAEMO
+ Hildon::FileChooserDialog fileChooser_Open(Gtk::FILE_CHOOSER_ACTION_OPEN);
+#else
+ Gtk::FileChooserDialog fileChooser_Open(_("Open Document"), Gtk::FILE_CHOOSER_ACTION_OPEN);
+ fileChooser_Open.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ fileChooser_Open.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
+ fileChooser_Open.set_default_response(Gtk::RESPONSE_OK);
+#endif // GLOM_ENABLE_MAEMO
+
+ if(pWindow)
+ fileChooser_Open.set_transient_for(*pWindow);
+
+ if(!starting_folder_uri.empty())
+ fileChooser_Open.set_current_folder_uri(starting_folder_uri);
+
+ const int response_id = fileChooser_Open.run();
+ fileChooser_Open.hide();
+ if(response_id != Gtk::RESPONSE_CANCEL)
+ {
+ return fileChooser_Open.get_uri();
+ }
+ else
+ return Glib::ustring();
+}
+
+static bool uri_is_writable(const Glib::RefPtr<const Gio::File>& uri)
+{
+ if(!uri)
+ return false;
+
+ Glib::RefPtr<const Gio::FileInfo> file_info;
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ try
+ {
+ file_info = uri->query_info(G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+ }
+ catch(const Glib::Error& /* ex */)
+ {
+ return false;
+ }
+#else
+ std::auto_ptr<Gio::Error> error;
+ file_info = uri->query_info(G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, Gio::FILE_QUERY_INFO_NONE, error);
+ if(error.get())
+ return false;
+#endif
+
+ if(file_info)
+ {
+ return file_info->get_attribute_boolean(G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+ }
+ else
+ return true; //Not every URI protocol supports access rights, so assume that it's writable and complain later.
}
Glib::ustring App_WithDoc_Gtk::ui_file_select_save(const Glib::ustring& old_file_uri)
{
- return GtkDialogs::ui_file_select_save(*this, old_file_uri);
+ Gtk::Window* pWindow = this;
+
+#ifdef GLOM_ENABLE_MAEMO
+ Hildon::FileChooserDialog fileChooser_Save(Gtk::FILE_CHOOSER_ACTION_SAVE);
+#else
+ Gtk::FileChooserDialog fileChooser_Save(_("Save Document"), Gtk::FILE_CHOOSER_ACTION_SAVE);
+ fileChooser_Save.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ fileChooser_Save.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
+ fileChooser_Save.set_default_response(Gtk::RESPONSE_OK);
+#endif // GLOM_ENABLE_MAEMO
+
+ if(pWindow)
+ fileChooser_Save.set_transient_for(*pWindow);
+
+ fileChooser_Save.set_do_overwrite_confirmation(); //Ask the user if the file already exists.
+
+ //Make the save dialog show the existing filename, if any:
+ if(!old_file_uri.empty())
+ {
+ //Just start with the parent folder,
+ //instead of the whole name, to avoid overwriting:
+ Glib::RefPtr<Gio::File> gio_file = Gio::File::create_for_uri(old_file_uri);
+ if(gio_file)
+ {
+ Glib::RefPtr<Gio::File> parent = gio_file->get_parent();
+ if(parent)
+ {
+ const Glib::ustring uri_parent = parent->get_uri();
+ fileChooser_Save.set_uri(uri_parent);
+ }
+ }
+ }
+
+
+ //bool tried_once_already = false;
+
+ bool try_again = true;
+ while(try_again)
+ {
+ try_again = false;
+
+ //Work around bug #330680 "GtkFileChooserDialog is too small when shown a second time.":
+ //(Commented-out because the workaround doesn't work)
+ /*
+ if(tried_once_already)
+ {
+ fileChooser_Save.set_default_size(-1, 600);
+ }
+ else
+ tried_once_already = true;
+ */
+
+ const int response_id = fileChooser_Save.run();
+ fileChooser_Save.hide();
+ if(response_id != Gtk::RESPONSE_CANCEL)
+ {
+ const Glib::ustring uri = fileChooser_Save.get_uri();
+
+ Glib::RefPtr<Gio::File> gio_file = Gio::File::create_for_uri(uri);
+
+ //If the file exists (the FileChooser offers a "replace?" dialog, so this is possible.):
+ if(App_WithDoc::file_exists(uri))
+ {
+ //Check whether we have rights to the file to change it:
+ //Really, GtkFileChooser should do this for us.
+ if(!uri_is_writable(gio_file))
+ {
+ //Warn the user:
+ ui_warning(_("Read-only File."), _("You may not overwrite the existing file, because you do not have sufficient access rights."));
+ try_again = true; //Try again.
+ continue;
+ }
+ }
+
+ //Check whether we have rights to the directory, to create a new file in it:
+ //Really, GtkFileChooser should do this for us.
+ Glib::RefPtr<const Gio::File> gio_file_parent = gio_file->get_parent();
+ if(gio_file_parent)
+ {
+ if(!uri_is_writable(gio_file_parent))
+ {
+ //Warn the user:
+ ui_warning(_("Read-only Directory."), _("You may not create a file in this directory, because you do not have sufficient access rights."));
+ try_again = true; //Try again.
+ continue;
+ }
+ }
+
+ if(!try_again)
+ return uri;
+ }
+ else
+ return Glib::ustring(); //The user cancelled.
+ }
+
+ return Glib::ustring();
}
void App_WithDoc_Gtk::ui_show_modification_status()
@@ -240,7 +407,30 @@
App_WithDoc_Gtk::enumSaveChanges App_WithDoc_Gtk::ui_offer_to_save_changes()
{
- return GtkDialogs::ui_offer_to_save_changes(*this, m_pDocument->get_file_uri());
+ App_WithDoc::enumSaveChanges result = App_WithDoc::SAVECHANGES_Cancel;
+
+ if(!m_pDocument)
+ return result;
+
+ GlomBakery::Dialog_OfferSave* pDialogQuestion
+ = new GlomBakery::Dialog_OfferSave( m_pDocument->get_file_uri() );
+
+ Gtk::Window* pWindow = this;
+ if(pWindow)
+ pDialogQuestion->set_transient_for(*pWindow);
+
+ GlomBakery::Dialog_OfferSave::enumButtons buttonClicked = (GlomBakery::Dialog_OfferSave::enumButtons)pDialogQuestion->run();
+ delete pDialogQuestion;
+ pDialogQuestion = 0;
+
+ if(buttonClicked == GlomBakery::Dialog_OfferSave::BUTTON_Save)
+ result = App_WithDoc::SAVECHANGES_Save;
+ else if(buttonClicked == GlomBakery::Dialog_OfferSave::BUTTON_Discard)
+ result = App_WithDoc::SAVECHANGES_Discard;
+ else
+ result = App_WithDoc::SAVECHANGES_Cancel;
+
+ return result;
}
void App_WithDoc_Gtk::document_history_add(const Glib::ustring& file_uri)
Modified: trunk/glom/bakery/Makefile.am
==============================================================================
--- trunk/glom/bakery/Makefile.am (original)
+++ trunk/glom/bakery/Makefile.am Tue Mar 24 00:13:39 2009
@@ -1,7 +1,7 @@
AM_CPPFLAGS = -I top_srcdir@/ -I top_srcdir@/glom $(GLOM_CFLAGS)
-h_sources = App_Gtk.h App_WithDoc.h GtkDialogs.h App.h App_WithDoc_Gtk.h Dialog_OfferSave.h
-cc_sources = App_Gtk.cc App_WithDoc.cc GtkDialogs.cc App.cc App_WithDoc_Gtk.cc Dialog_OfferSave.cc
+h_sources = App_Gtk.h App_WithDoc.h App.h App_WithDoc_Gtk.h Dialog_OfferSave.h
+cc_sources = App_Gtk.cc App_WithDoc.cc App.cc App_WithDoc_Gtk.cc Dialog_OfferSave.cc
noinst_LIBRARIES = libbakery_app.a
libbakery_app_a_SOURCES = $(h_sources) $(cc_sources)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]