1 // $Id: gui_file_manager.cxx,v 1.10 2003/07/24 10:10:02 grumbel Exp $
3 // Construo - A wire-frame construction gamee
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "construo.hxx"
22 #include "zoom_graphic_context.hxx"
23 #include "gui_file_manager.hxx"
24 #include "screen_manager.hxx"
25 #include "gui_buttons.hxx"
29 GUIFileManager::instance()->directory_up();
34 GUIFileManager::instance()->scroll_up();
39 GUIFileManager::instance()->scroll_down();
42 void ReReadCurrentDir ()
44 GUIFileManager::instance()->update_current_directory();
48 void CloseFileManager ()
50 ScreenManager::instance()->set_gui(ScreenManager::WORLD_GUI
);
53 GUIFileManager
* GUIFileManager::instance_
= 0;
55 GUIFileManager::GUIFileManager (Mode m
)
56 : GUIChildManager (0, 0, 800, 600),
59 if (mode
== SAVE_MANAGER
)
60 current_directory
= new GUIDirectory ("/", GUIDirectory::SAVE_DIRECTORY
);
62 current_directory
= new GUIDirectory ("/", GUIDirectory::LOAD_DIRECTORY
);
64 directories
["/"] = current_directory
;
66 add (new GUIGenericButton("Up", 0,0, 100, 25, DirectoryUp
));
67 add (new GUIGenericButton("Close", 700, 0, 100, 25, CloseFileManager
));
69 add (new GUIGenericButton("^", 770, 200, 25, 50, ScrollUp
));
70 add (new GUIGenericButton("V", 770, 300, 25, 50, ScrollDown
));
72 add (new GUIGenericButton("Update Directory", 650, 575, 150, 25, ReReadCurrentDir
));
74 add(current_directory
);
79 GUIFileManager::~GUIFileManager ()
85 GUIFileManager::open_directory (const std::string
& pathname
)
87 std::cout
<< "GUIFileManager::open_directory: " << pathname
<< std::endl
;
88 GUIDirectory
* old_directory
= current_directory
;
90 if (directories
[pathname
] == 0)
92 if (mode
== SAVE_MANAGER
)
94 current_directory
= directories
[pathname
] = new GUIDirectory(pathname
,
95 GUIDirectory::SAVE_DIRECTORY
);
99 current_directory
= directories
[pathname
] = new GUIDirectory(pathname
,
100 GUIDirectory::LOAD_DIRECTORY
);
105 current_directory
= directories
[pathname
];
108 std::cout
<< "Replace: " << old_directory
<< " " << current_directory
<< std::endl
;
109 replace (old_directory
, current_directory
);
113 GUIFileManager::directory_up()
115 std::string pathname
= current_directory
->get_path ();
120 // already at the top most directory
125 assert(*(pathname
.end()-1) == '/');
127 for (std::string::size_type i
= pathname
.size() - 2; i
>= 0; --i
)
129 if (pathname
[i
] == '/') // Found second '/'
131 pathname
= pathname
.substr(0, i
+1);
136 std::cout
<< "Directory Up: " << current_directory
->get_path () << " -> " << pathname
<< std::endl
;
137 open_directory (pathname
);
142 GUIFileManager::draw_overlay (GraphicContext
* gc
)
144 gc
->draw_string(200, 16, current_directory
->get_path());
148 GUIFileManager::scroll_up ()
150 current_directory
->move_up();
154 GUIFileManager::scroll_down ()
156 current_directory
->move_down();
160 GUIFileManager::update_current_directory()
162 // Force a reread of the whole directory
163 std::string pathname
= current_directory
->get_path();
165 GUIDirectory
* old_directory
= current_directory
;
167 if (mode
== SAVE_MANAGER
)
169 current_directory
= directories
[pathname
] = new GUIDirectory(pathname
,
170 GUIDirectory::SAVE_DIRECTORY
);
174 current_directory
= directories
[pathname
] = new GUIDirectory(pathname
,
175 GUIDirectory::LOAD_DIRECTORY
);
178 replace (old_directory
, current_directory
);
179 delete old_directory
;