Welcome to the NetCologne GmbH open source mirroring service!

This machine mirrors various open-source projects. 20 Gbit/s uplink.

If there are any issues or you want another project mirrored, please contact mirror-service -=AT=- netcologne DOT de !

gui_file_manager.cxx Source File
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

gui_file_manager.cxx

Go to the documentation of this file.
00001 //  $Id: gui_file_manager.cxx,v 1.9 2003/01/11 19:07:48 grumbel Exp $
00002 //
00003 //  Construo - A wire-frame construction gamee
00004 //  Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #include <assert.h>
00021 #include "construo.hxx"
00022 #include "zoom_graphic_context.hxx"
00023 #include "gui_file_manager.hxx"
00024 #include "screen_manager.hxx"
00025 #include "gui_buttons.hxx"
00026 
00027 void DirectoryUp ()
00028 {
00029   GUIFileManager::instance()->directory_up();
00030 }
00031 
00032 void ScrollUp ()
00033 {
00034   GUIFileManager::instance()->scroll_up();
00035 }
00036 
00037 void ScrollDown ()
00038 {
00039   GUIFileManager::instance()->scroll_down();
00040 }
00041 
00042 void ReReadCurrentDir ()
00043 {
00044   GUIFileManager::instance()->update_current_directory();
00045 }
00046 
00047 
00048 void CloseFileManager ()
00049 {
00050   ScreenManager::instance()->set_gui(ScreenManager::WORLD_GUI);
00051 }
00052 
00053 GUIFileManager* GUIFileManager::instance_ = 0;
00054 
00055 GUIFileManager::GUIFileManager (Mode m)
00056   : GUIChildManager (0, 0, 800, 600),
00057     mode (m)
00058 {
00059   if (mode == SAVE_MANAGER)
00060     current_directory = new GUIDirectory ("/", GUIDirectory::SAVE_DIRECTORY);
00061   else
00062     current_directory = new GUIDirectory ("/", GUIDirectory::LOAD_DIRECTORY);
00063 
00064   directories["/"] = current_directory;
00065   
00066   add (new GUIGenericButton("Up", 0,0, 100, 25, DirectoryUp));
00067   add (new GUIGenericButton("Close", 700, 0, 100, 25, CloseFileManager));
00068 
00069   add (new GUIGenericButton("^", 770, 200, 25, 50, ScrollUp));
00070   add (new GUIGenericButton("V", 770, 300, 25, 50, ScrollDown));
00071 
00072   add (new GUIGenericButton("Update Directory", 650, 575, 150, 25, ReReadCurrentDir));
00073 
00074   add(current_directory);
00075  
00076   instance_ = this;
00077 }
00078 
00079 GUIFileManager::~GUIFileManager ()
00080 {
00081   
00082 }
00083 
00084 void
00085 GUIFileManager::open_directory (const std::string& pathname)
00086 {
00087   std::cout << "GUIFileManager::open_directory: " << pathname << std::endl;
00088   GUIDirectory* old_directory = current_directory;
00089 
00090   if (directories[pathname] == 0)
00091     {
00092       if (mode == SAVE_MANAGER)
00093         {
00094           current_directory = directories[pathname] = new GUIDirectory(pathname, 
00095                                                                        GUIDirectory::SAVE_DIRECTORY);
00096         }
00097       else
00098         {
00099           current_directory = directories[pathname] = new GUIDirectory(pathname,
00100                                                                        GUIDirectory::LOAD_DIRECTORY);
00101         }
00102     }
00103   else
00104     {
00105       current_directory = directories[pathname];
00106     }
00107 
00108   std::cout << "Replace: " << old_directory << " " << current_directory << std::endl;
00109   replace (old_directory, current_directory);
00110 }
00111 
00112 void
00113 GUIFileManager::directory_up()
00114 {
00115   std::string pathname = current_directory->get_path ();
00116 
00117   // FIXME: UGLY code
00118   if (pathname == "/")
00119     {
00120       // already at the top most directory
00121       return;
00122     }
00123   else
00124     {
00125       assert(*(pathname.end()-1) == '/');
00126 
00127       for (std::string::size_type i = pathname.size() - 2; i >= 0; --i)
00128         {
00129           if (pathname[i] == '/') // Found second '/'
00130             {
00131               pathname = pathname.substr(0, i+1);
00132               break;
00133             }
00134         }
00135 
00136       std::cout << "Directory Up: " << current_directory->get_path () << " -> " << pathname << std::endl;
00137       open_directory (pathname);
00138     }
00139 }
00140 
00141 void
00142 GUIFileManager::draw_overlay (GraphicContext* gc)
00143 {
00144   gc->draw_string(200, 16, current_directory->get_path());
00145 }
00146 
00147 void
00148 GUIFileManager::scroll_up ()
00149 {
00150   current_directory->move_up(); 
00151 }
00152 
00153 void
00154 GUIFileManager::scroll_down ()
00155 {
00156   current_directory->move_down();   
00157 }
00158 
00159 void
00160 GUIFileManager::update_current_directory()
00161 {
00162   // Force a reread of the whole directory
00163   std::string pathname = current_directory->get_path();
00164 
00165   GUIDirectory* old_directory = current_directory;
00166 
00167   if (mode == SAVE_MANAGER)
00168     {
00169       current_directory = directories[pathname] = new GUIDirectory(pathname, 
00170                                                                    GUIDirectory::SAVE_DIRECTORY);
00171     }
00172   else
00173     {
00174       current_directory = directories[pathname] = new GUIDirectory(pathname,
00175                                                                    GUIDirectory::LOAD_DIRECTORY);
00176     }
00177   
00178   replace (old_directory, current_directory);
00179   delete old_directory;
00180 }
00181 
00182 /* EOF */

Generated on Thu Jul 24 10:24:30 2003 for Construo by doxygen1.3-rc3