2007-07-16 11:35:32 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* EDE FileView class
|
|
|
|
* Part of edelib.
|
|
|
|
* Copyright (c) 2005-2007 EDE Authors.
|
|
|
|
*
|
|
|
|
* This program is licenced under terms of the
|
|
|
|
* GNU General Public Licence version 2 or newer.
|
|
|
|
* See COPYING for details.
|
|
|
|
*/
|
|
|
|
|
2007-08-23 14:54:12 +04:00
|
|
|
/**
|
|
|
|
* \class FileView
|
|
|
|
* \brief Widget for displaying a list of files
|
|
|
|
*
|
|
|
|
* FileView is a generic widget that displays files in a
|
|
|
|
* certain way. To get/change the type of view, use method
|
|
|
|
* type() which sets or returns a value of type enum FileViewType.
|
|
|
|
* Allowed values are:
|
|
|
|
* FILE_LIST_VIEW - a multicolumn list of files (if necessary,
|
|
|
|
* a horizontal scrollbar will be shown)
|
|
|
|
* FILE_DETAILS_VIEW - each file is in a single row, and columns
|
|
|
|
* contain information such as file type, size, date of last change
|
|
|
|
* and permission
|
|
|
|
* FILE_ICON_VIEW - large icons are shown, and filenames are
|
|
|
|
* displayed below icons (if necessary, a vertical scrollbar will be
|
|
|
|
* shown), additional data is shown in tooltips
|
|
|
|
*
|
|
|
|
* Of course, you are free to directly use classes FileListView,
|
|
|
|
* FileDetailsView and FileIconView respectively (however, you have
|
|
|
|
* to include FileView.h to get them).
|
|
|
|
*
|
|
|
|
* Unlike some similar classes, FileView doesn't do any scanning of
|
|
|
|
* directories. Instead, a program using FileView should use methods
|
|
|
|
* such as add(), insert(), remove() and update(). These methods take
|
|
|
|
* values of type struct FileItem, which contains all the data shown
|
|
|
|
* by FileDetailsView. The reason for this is to enable reuse in
|
|
|
|
* programs that don't work with standard filesystem.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-07-16 11:35:32 +04:00
|
|
|
|
|
|
|
#ifndef EDE_FileView_H
|
|
|
|
#define EDE_FileView_H
|
|
|
|
|
2007-08-20 16:16:10 +04:00
|
|
|
|
2007-07-16 11:35:32 +04:00
|
|
|
#include <edelib/String.h>
|
|
|
|
|
|
|
|
struct FileItem {
|
|
|
|
edelib::String name; // just the name
|
|
|
|
edelib::String icon;
|
|
|
|
edelib::String size;
|
|
|
|
edelib::String realpath; // whatever the caller uses to access the file
|
|
|
|
edelib::String description;
|
|
|
|
edelib::String date;
|
|
|
|
edelib::String permissions;
|
|
|
|
};
|
|
|
|
|
2007-08-23 14:54:12 +04:00
|
|
|
// Type for callbacks
|
2007-07-23 23:59:48 +04:00
|
|
|
// I don't know how to do this without creating a new type :(
|
2007-07-27 12:36:05 +04:00
|
|
|
typedef void (rename_callback_type)(const char*);
|
2007-08-01 22:04:35 +04:00
|
|
|
typedef void (paste_callback_type)(const char*);
|
|
|
|
|
2007-07-23 23:59:48 +04:00
|
|
|
|
2007-08-20 16:16:10 +04:00
|
|
|
|
2007-08-23 14:54:12 +04:00
|
|
|
#include "EDE_FileDetailsView.h"
|
|
|
|
#include "EDE_FileIconView.h"
|
2007-08-20 16:16:10 +04:00
|
|
|
|
|
|
|
|
|
|
|
enum FileViewType {
|
|
|
|
FILE_DETAILS_VIEW,
|
|
|
|
FILE_ICON_VIEW
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-23 14:54:12 +04:00
|
|
|
|
|
|
|
|
|
|
|
class FileView : public Fl_Group {
|
2007-08-20 16:16:10 +04:00
|
|
|
private:
|
2007-08-23 14:54:12 +04:00
|
|
|
FileDetailsView* browser;
|
|
|
|
FileIconView* icons;
|
2007-08-20 16:16:10 +04:00
|
|
|
FileViewType m_type;
|
|
|
|
public:
|
2007-08-23 14:54:12 +04:00
|
|
|
FileView(int X, int Y, int W, int H, char*label=0) : Fl_Group(X,Y,W,H,label) {
|
|
|
|
browser = new FileDetailsView(X,Y,W,H,label);
|
2007-08-20 16:16:10 +04:00
|
|
|
browser->end();
|
|
|
|
// browser->hide();
|
2007-08-23 14:54:12 +04:00
|
|
|
icons = new FileIconView(X,Y,W,H,label);
|
2007-08-20 16:16:10 +04:00
|
|
|
icons->end();
|
|
|
|
end();
|
|
|
|
|
|
|
|
// Set default to FILE_DETAILS_VIEW
|
|
|
|
icons->hide();
|
|
|
|
m_type=FILE_DETAILS_VIEW;
|
|
|
|
}
|
|
|
|
|
2007-08-20 22:34:22 +04:00
|
|
|
void type(FileViewType t) {
|
2007-08-20 16:16:10 +04:00
|
|
|
m_type=t;
|
|
|
|
if (t==FILE_DETAILS_VIEW) {
|
2007-08-20 22:34:22 +04:00
|
|
|
icons->hide();
|
|
|
|
browser->show();
|
|
|
|
// browser->resize(x(),y(),w(),h());
|
|
|
|
// browser->redraw();
|
|
|
|
Fl_Group::add(browser);
|
2007-08-20 16:16:10 +04:00
|
|
|
}
|
|
|
|
if (t==FILE_ICON_VIEW) {
|
2007-08-20 22:34:22 +04:00
|
|
|
browser->hide();
|
2007-08-20 16:16:10 +04:00
|
|
|
icons->show();
|
2007-08-20 22:34:22 +04:00
|
|
|
Fl_Group::add(icons);
|
|
|
|
// icons->show();
|
|
|
|
// icons->redraw();
|
2007-08-20 16:16:10 +04:00
|
|
|
//redraw();
|
|
|
|
}
|
2007-08-20 22:34:22 +04:00
|
|
|
redraw();
|
2007-08-20 16:16:10 +04:00
|
|
|
}
|
2007-08-20 22:34:22 +04:00
|
|
|
FileViewType type() { return m_type; }
|
2007-08-20 16:16:10 +04:00
|
|
|
|
2007-08-23 14:54:12 +04:00
|
|
|
|
|
|
|
// Methods that must be implemented by each view
|
|
|
|
|
|
|
|
// Setter methods (forwarded to all views)
|
2007-08-20 16:16:10 +04:00
|
|
|
void insert(int row, FileItem *item) { browser->insert(row,item); icons->insert(row,item); }
|
|
|
|
void add(FileItem *item) { browser->add(item); icons->add(item); }
|
|
|
|
void remove(FileItem *item) { browser->remove(item); icons->remove(item); }
|
|
|
|
void update(FileItem *item) { browser->update(item); icons->update(item); }
|
|
|
|
|
|
|
|
void update_path(const char* oldpath,const char* newpath) { browser->update_path(oldpath,newpath); icons->update_path(oldpath,newpath); }
|
|
|
|
|
2007-08-23 14:54:12 +04:00
|
|
|
void callback(Fl_Callback*cb) { browser->callback(cb); icons->callback(cb);}
|
2007-08-20 16:16:10 +04:00
|
|
|
void rename_callback(rename_callback_type* cb) { browser->rename_callback(cb); icons->rename_callback(cb); }
|
|
|
|
void paste_callback(paste_callback_type* cb) { browser->paste_callback(cb); icons->paste_callback(cb); }
|
|
|
|
void context_callback(Fl_Callback* cb) { browser->context_callback(cb); icons->context_callback(cb); }
|
|
|
|
|
2007-08-23 14:54:12 +04:00
|
|
|
void remove(int i) { browser->remove(i); icons->remove(i);}
|
|
|
|
void clear() { browser->clear(); icons->clear();}
|
|
|
|
|
|
|
|
// Methods forwarded to just the active view
|
|
|
|
void gray(int row) { if (m_type==FILE_DETAILS_VIEW) browser->gray(row); else icons->gray(row); }
|
|
|
|
void ungray(int row) { if (m_type==FILE_DETAILS_VIEW) browser->ungray(row); else icons->ungray(row); }
|
|
|
|
|
|
|
|
const char* path(int i) { if (m_type==FILE_DETAILS_VIEW) return browser->path(i); else return icons->path(i); }
|
2007-08-20 16:16:10 +04:00
|
|
|
int size() { if (m_type==FILE_DETAILS_VIEW) return browser->size(); else return icons->children();}
|
|
|
|
int selected(int i) { if (m_type==FILE_DETAILS_VIEW) return browser->selected(i); else return icons->selected(i); }
|
2007-08-23 14:54:12 +04:00
|
|
|
void select(int i, int k) { if (m_type==FILE_DETAILS_VIEW) { browser->select(i,k); browser->show_item(i); } else { icons->select(i,k); icons->show_item(i); } }
|
2007-08-20 16:16:10 +04:00
|
|
|
int get_focus() { if (m_type==FILE_DETAILS_VIEW) return browser->get_focus(); else return icons->get_focus(); }
|
2007-08-20 22:34:22 +04:00
|
|
|
void set_focus(int i) { if (m_type==FILE_DETAILS_VIEW) browser->set_focus(i); else icons->set_focus(i);}
|
2007-08-20 16:16:10 +04:00
|
|
|
int take_focus() { if (m_type==FILE_DETAILS_VIEW) return browser->take_focus(); else return icons->take_focus(); }
|
2007-08-24 13:19:53 +04:00
|
|
|
|
|
|
|
void start_rename() { if (m_type==FILE_DETAILS_VIEW) return browser->start_rename(); else return icons->start_rename(); }
|
2007-08-01 22:04:35 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-20 16:16:10 +04:00
|
|
|
|
2007-07-16 11:35:32 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* $Id */
|