20130420
[gdash.git] / src / framework / selectfileactivity.hpp
blobf65cfb35779ea4ae4b923b0f3a3d2fc0fedfc996
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
19 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef SELECTFILEACTIVITY_HPP_INCLUDED
25 #define SELECTFILEACTIVITY_HPP_INCLUDED
27 #include <vector>
28 #include <string>
30 #include "framework/activity.hpp"
31 #include "misc/smartptr.hpp"
33 template <typename T> class Command1Param;
35 /**
36 * Allow the user to select a file (maybe type the name of a new file),
37 * parametrize a command with the filename and finally execute the parametrized command.
38 * This Activity is like a file selection dialog in modern UIs.
40 class SelectFileActivity: public Activity {
41 public:
42 /** Constructor for file selection Activity.
43 * @param app The parent App.
44 * @param title Window title - this should describe the purpose of file selection.
45 * @param start_dir The directory to start the selecting in.
46 * @param glob Glob pattern - semicolon separated list of globs. For example "*.png;*.jpg"
47 * @param for_save Set to true, if the file selection is for saving a file, and therefore typing a new name should be allowed.
48 * @param defaultname The default name to set.
49 * @param command_when_successful Parametrize this command with the filename and execute it - if the file selection is successful. */
50 SelectFileActivity(App *app, const char *title, const char *start_dir, const char *glob, bool for_save, const char *defaultname, SmartPtr<Command1Param<std::string> > command_when_successful);
51 ~SelectFileActivity();
53 virtual void keypress_event(KeyCode keycode, int gfxlib_keycode);
54 virtual void redraw_event(bool full) const;
55 virtual void pushed_event();
57 void jump_to_directory(char const *jump_to);
58 void file_selected(char const *filename);
59 void file_selected_do_command();
61 private:
62 SmartPtr<Command1Param<std::string> > command_when_successful;
63 std::string title;
64 bool for_save;
65 int yd;
66 unsigned names_per_page;
67 char **globs;
68 char *directory;
69 char *directory_of_process;
70 int sel;
72 std::vector<std::string> files;
73 std::string defaultname;
74 std::string start_dir;
76 void read_dir();
77 void process_enter();
80 #endif