glom r2007 - in trunk: . glom glom/bakery



Author: murrayc
Date: Thu Mar 19 11:37:57 2009
New Revision: 2007
URL: http://svn.gnome.org/viewvc/glom?rev=2007&view=rev

Log:
Revert my last change because we really should use a real single instance system so we can still have New and Open menu items.

Modified:
   trunk/ChangeLog
   trunk/glom/application.cc
   trunk/glom/bakery/App.cc
   trunk/glom/bakery/App.h
   trunk/glom/bakery/App_Gtk.cc
   trunk/glom/bakery/App_Gtk.h
   trunk/glom/bakery/App_WithDoc.cc
   trunk/glom/bakery/App_WithDoc_Gtk.cc
   trunk/glom/bakery/Makefile.am

Modified: trunk/glom/application.cc
==============================================================================
--- trunk/glom/application.cc	(original)
+++ trunk/glom/application.cc	Thu Mar 19 11:37:57 2009
@@ -318,6 +318,8 @@
 
   m_refFileActionGroup->add(Gtk::Action::create("BakeryAction_File_Close", Gtk::Stock::CLOSE),
                         sigc::mem_fun((App_WithDoc&)*this, &App_WithDoc::on_menu_file_close));
+  /*m_refFileActionGroup->add(Gtk::Action::create("BakeryAction_File_Exit", Gtk::Stock::QUIT),
+                        sigc::mem_fun((App&)*this, &App::on_menu_file_exit));*/
 
   m_refUIManager->insert_action_group(m_refFileActionGroup);
 

Modified: trunk/glom/bakery/App.cc
==============================================================================
--- trunk/glom/bakery/App.cc	(original)
+++ trunk/glom/bakery/App.cc	Thu Mar 19 11:37:57 2009
@@ -24,6 +24,7 @@
 {
 
 //Initialize static member data:
+AppInstanceManager App::m_AppInstanceManager;
 HelpInfo App::m_HelpInfo;
 
 bool App::m_bAboutShown = false;
@@ -34,10 +35,18 @@
 App::App(const Glib::ustring& appname)
 {
   init_app_name(appname);
+  
+  //Register an instance of this app:
+  m_AppInstanceManager.add_app(this);
 }
 
 App::~App()
 {
+  //If this was the last instance:
+  if(m_AppInstanceManager.get_app_count() == 0)
+  {
+    
+  }
 }
 
 void App::init_app_name(const Glib::ustring& appname) //static
@@ -90,7 +99,16 @@
 
 void App::on_menu_file_close()
 {
-  ui_hide();
+  ui_hide(); //AppInstanceManager will delete this when the hide signal is emitted..
+}
+
+void App::on_menu_file_exit()
+{
+  // we don't want to quit directly as we should save our work
+  // therefore we need to send close to each window.
+
+  //Close each instance:
+  m_AppInstanceManager.close_all();
 }
 
 void App::on_menu_edit_cut()

Modified: trunk/glom/bakery/App.h
==============================================================================
--- trunk/glom/bakery/App.h	(original)
+++ trunk/glom/bakery/App.h	Thu Mar 19 11:37:57 2009
@@ -19,6 +19,7 @@
 #ifndef GLOM_BAKERY_APP_H
 #define GLOM_BAKERY_APP_H
 
+#include <glom/bakery/AppInstanceManager.h>
 #include <glibmm/object.h>
 
 #include <vector>
@@ -59,6 +60,7 @@
 class App : virtual public Glib::ObjectBase
 {
 public:
+  friend class AppInstanceManager;
 
   //The constructor has a default argument so that there is a default constructor,
   //so that derived classes do not need to call a specific constructor. This is
@@ -119,6 +121,7 @@
   //Menus:
   virtual void on_menu_file_new();
   virtual void on_menu_file_close();
+  virtual void on_menu_file_exit();
 
   //Edit menu handlers overriden in App_WithDoc:
   virtual void on_menu_edit_cut();
@@ -151,6 +154,7 @@
   static HelpInfo m_HelpInfo;
 
   //Instances
+  static AppInstanceManager m_AppInstanceManager;
 
   static bool m_bOperationCancelled; //see set/get_operation_cancelled().
 

Modified: trunk/glom/bakery/App_Gtk.cc
==============================================================================
--- trunk/glom/bakery/App_Gtk.cc	(original)
+++ trunk/glom/bakery/App_Gtk.cc	Thu Mar 19 11:37:57 2009
@@ -68,10 +68,15 @@
     m_pVBox = 0;
   }
   
-  if(m_pAbout)
+  //If this was the last instance:
+  if(m_AppInstanceManager.get_app_count() == 0)
   {
-    delete m_pAbout;
-    m_pAbout = 0;
+    //Delete shared static widgets if this was the last instance:
+    if(m_pAbout)
+    {
+      delete m_pAbout;
+      m_pAbout = 0;
+    }
   }
 }
 
@@ -245,6 +250,8 @@
                         sigc::mem_fun((GlomBakery::App&)*this, &App_Gtk::on_menu_file_new));
   m_refFileActionGroup->add(Action::create("BakeryAction_File_Close", Gtk::Stock::CLOSE),
                         sigc::mem_fun((GlomBakery::App&)*this, &App_Gtk::on_menu_file_close));
+  m_refFileActionGroup->add(Action::create("BakeryAction_File_Exit", Gtk::Stock::QUIT),
+                        sigc::mem_fun((GlomBakery::App&)*this, &App_Gtk::on_menu_file_exit));
   m_refUIManager->insert_action_group(m_refFileActionGroup);
 
   //Build part of the menu structure, to be merged in by using the "PH" placeholders:
@@ -259,6 +266,7 @@
     "      <menu action='BakeryAction_Menu_File'>" 
     "        <menuitem action='BakeryAction_File_New' />"
     "        <menuitem action='BakeryAction_File_Close' />"
+    "        <menuitem action='BakeryAction_File_Exit' />"
     "      </menu>"
     "    </placeholder>"
 #ifdef GLOM_ENABLE_MAEMO

Modified: trunk/glom/bakery/App_Gtk.h
==============================================================================
--- trunk/glom/bakery/App_Gtk.h	(original)
+++ trunk/glom/bakery/App_Gtk.h	Thu Mar 19 11:37:57 2009
@@ -57,6 +57,7 @@
 #else
   typedef Gtk::Window ParentWindow;
 #endif
+  friend class AppInstanceManager;
 
   ///Don't forget to call init() too.
   App_Gtk(const Glib::ustring& appname);

Modified: trunk/glom/bakery/App_WithDoc.cc
==============================================================================
--- trunk/glom/bakery/App_WithDoc.cc	(original)
+++ trunk/glom/bakery/App_WithDoc.cc	Thu Mar 19 11:37:57 2009
@@ -63,7 +63,7 @@
   }
 
   if(!get_operation_cancelled())
-    ui_hide();
+    ui_hide(); //The AppInstanceManager will delete it.
 }
 
 bool App_WithDoc::open_document_from_data(const guchar* data, std::size_t length)
@@ -100,6 +100,40 @@
 
 bool App_WithDoc::open_document(const Glib::ustring& file_uri)
 {
+  //Check whether it's already open:
+  //It could even be open in this instance.
+  bool bAlreadyOpen = false;
+  App_WithDoc* pAppAlreadyOpen = 0;
+
+  AppInstanceManager::type_listAppInstances apps =  m_AppInstanceManager.get_instances();
+  for(AppInstanceManager::type_listAppInstances::iterator iter = apps.begin(); iter != apps.end(); iter++)
+  {
+    App_WithDoc* pApp = dynamic_cast<App_WithDoc*>(*iter);
+    if(pApp)
+    {
+      Document* pDoc = pApp->get_document();
+      if(pDoc->get_file_uri() == file_uri)
+      {
+        bAlreadyOpen = true;
+        pAppAlreadyOpen = pApp;
+      }
+    }
+  }
+
+  if(bAlreadyOpen)
+  {
+    //Bring it to the front:
+    if(pAppAlreadyOpen)
+    {
+      pAppAlreadyOpen->ui_bring_to_front();
+    }
+
+    //Tell user that it's already open:
+    ui_warning(_("Document already open"), _("This document is already open."));
+
+    return true; //success.
+  }
+  else
   {
     //Open it:
         
@@ -402,6 +436,7 @@
 {
   set_operation_cancelled();
   m_bCloseAfterSave = false;
+  m_AppInstanceManager.cancel_close_all();
 
   //exit_destroy_marked_instances(); //Clean up after an exit.
 }

Modified: trunk/glom/bakery/App_WithDoc_Gtk.cc
==============================================================================
--- trunk/glom/bakery/App_WithDoc_Gtk.cc	(original)
+++ trunk/glom/bakery/App_WithDoc_Gtk.cc	Thu Mar 19 11:37:57 2009
@@ -167,6 +167,8 @@
                         
   m_refFileActionGroup->add(Gtk::Action::create("BakeryAction_File_Close", Gtk::Stock::CLOSE),
                         sigc::mem_fun((App_WithDoc&)*this, &App_WithDoc::on_menu_file_close));
+  m_refFileActionGroup->add(Gtk::Action::create("BakeryAction_File_Exit", Gtk::Stock::QUIT),
+                        sigc::mem_fun((App&)*this, &App::on_menu_file_exit));
                         
   m_refUIManager->insert_action_group(m_refFileActionGroup);
 
@@ -188,6 +190,7 @@
     "        <menuitem action='BakeryAction_File_SaveAs' />"
     "        <separator/>"
     "        <menuitem action='BakeryAction_File_Close' />"
+    "        <menuitem action='BakeryAction_File_Exit' />"
     "      </menu>"
     "    </placeholder>"
 #ifdef GLOM_ENABLE_MAEMO

Modified: trunk/glom/bakery/Makefile.am
==============================================================================
--- trunk/glom/bakery/Makefile.am	(original)
+++ trunk/glom/bakery/Makefile.am	Thu Mar 19 11:37:57 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 AppInstanceManager.h App_WithDoc.h GtkDialogs.h App.h App_WithDoc_Gtk.h Dialog_OfferSave.h
+cc_sources = App_Gtk.cc AppInstanceManager.cc App_WithDoc.cc GtkDialogs.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]