Make dialog-like windows centered. Work on implementing missing ede-desktop functions

This commit is contained in:
Sanel Zukan
2012-05-07 08:53:13 +00:00
parent 27b8bd888a
commit dd496f4780
12 changed files with 91 additions and 49 deletions

View File

@@ -30,7 +30,6 @@
#include "ede-desktop.h"
#include "DesktopIcon.h"
#include "MovableIcon.h"
#include "IconProperties.h"
#include "Utils.h"
/* minimal icon sizes */
@@ -51,15 +50,18 @@ EDELIB_NS_USING(MenuButton)
EDELIB_NS_USING(ICON_SIZE_HUGE)
EDELIB_NS_USING(ICON_SIZE_TINY)
EDELIB_NS_USING(input)
EDELIB_NS_USING(ask)
EDELIB_NS_USING(run_async)
static void open_cb(Fl_Widget*, void* d);
static void rename_cb(Fl_Widget*, void* d);
static void delete_cb(Fl_Widget*, void* d);
static void props_cb(Fl_Widget*, void* d);
static MenuItem icon_menu[] = {
{_("&Open"), 0, open_cb, 0},
{_("&Rename"), 0, rename_cb, 0},
{_("&Delete"), 0, delete_cb, 0, FL_MENU_DIVIDER},
{_("&Properties"), 0, props_cb, 0},
{0}
};
@@ -85,9 +87,15 @@ static void rename_cb(Fl_Widget*, void* d) {
di->rename(new_name);
}
static void delete_cb(Fl_Widget*, void* d) {
DesktopIcon* di = (DesktopIcon*)d;
if(ask(_("This icon will be permanently deleted. Proceed?")))
Desktop::instance()->remove_icon(di, true);
}
static void props_cb(Fl_Widget*, void* d) {
DesktopIcon* di = (DesktopIcon*)d;
show_icon_properties_dialog(di);
}
DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) :

View File

@@ -17,6 +17,7 @@
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl_Shared_Image.H>
#include <edelib/Nls.h>
@@ -44,6 +45,12 @@ static Fl_Input *name, *comment, *execute;
static Fl_Choice *icon_type;
static String img_path;
/* the only supported type for now is application */
static Fl_Menu_Item menu_items[] = {
{_("Application"), 0, 0, 0},
{0}
};
static bool is_empty(const char *str) {
if(!str) return true;
const char *p = str;
@@ -155,12 +162,14 @@ void icon_dialog_icon_create(void) {
browse = new Fl_Button(395, 70, 25, 25, "...");
icon_type = new Fl_Choice(205, 100, 215, 25, _("Type:"));
icon_type->down_box(FL_BORDER_BOX);
icon_type->menu(menu_items);
ok = new Fl_Button(235, 135, 90, 25, _("&OK"));
ok->callback(ok_cb);
cancel = new Fl_Button(330, 135, 90, 25, _("&Cancel"));
cancel->callback(cancel_cb);
win->end();
win->set_modal();
win->show();
}

View File

@@ -17,8 +17,7 @@ SOURCE = ede-desktop.cpp
Wallpaper.cpp
DesktopIcon.cpp
MovableIcon.cpp
IconDialog.cpp
IconProperties.cpp ;
IconDialog.cpp ;
ObjectC++Flags $(SOURCE) : $(EDELIB_DBUS_INCLUDE) ;

View File

@@ -74,6 +74,8 @@
EDELIB_NS_USING(MenuItem)
EDELIB_NS_USING(String)
EDELIB_NS_USING(DesktopFile)
EDELIB_NS_USING(DirWatch)
EDELIB_NS_USING(Resource)
EDELIB_NS_USING(run_async)
EDELIB_NS_USING(input)
EDELIB_NS_USING(alert)
@@ -89,9 +91,18 @@ EDELIB_NS_USING(netwm_window_set_type)
EDELIB_NS_USING(netwm_callback_add)
EDELIB_NS_USING(netwm_callback_remove)
EDELIB_NS_USING(font_cache_find)
EDELIB_NS_USING(file_test)
EDELIB_NS_USING(dir_home)
EDELIB_NS_USING(build_filename)
EDELIB_NS_USING(FILE_TEST_IS_DIR)
EDELIB_NS_USING(FILE_TEST_IS_REGULAR)
EDELIB_NS_USING(NETWM_WINDOW_TYPE_DESKTOP)
EDELIB_NS_USING(NETWM_CHANGED_CURRENT_WORKAREA)
EDELIB_NS_USING(NETWM_CHANGED_CURRENT_WORKSPACE)
EDELIB_NS_USING(DW_CREATE)
EDELIB_NS_USING(DW_MODIFY)
EDELIB_NS_USING(DW_RENAME)
EDELIB_NS_USING(DW_DELETE)
static void background_conf_cb(Fl_Widget*, void*);
static void icons_conf_cb(Fl_Widget*, void*);
@@ -148,8 +159,8 @@ static void folder_create_cb(Fl_Widget*, void*) {
const char *n = input(_("New folder with name"));
if(!n) return;
String h = edelib::dir_home();
String dp = edelib::build_filename(h.c_str(), "Desktop", n);
String h = dir_home();
String dp = build_filename(h.c_str(), "Desktop", n);
if(!dir_create(dp.c_str()))
alert(_("Unable to create directory '%s'! Please check if directory already exists or you have enough permissions to create it"), dp.c_str());
@@ -210,13 +221,11 @@ Desktop::~Desktop() {
delete selbox;
delete dbus;
edelib::DirWatch::shutdown();
DirWatch::shutdown();
foreign_callback_remove(settings_changed_cb);
}
void Desktop::init_internals(void) {
String p;
update_workarea();
/*
@@ -242,25 +251,22 @@ void Desktop::init_internals(void) {
/* read main config */
read_config();
/* location of Desktop folder */
desktop_dir_path = build_filename(dir_home().c_str(), "Desktop");
/* now try to load icons from "Desktop" directory */
p = edelib::dir_home();
String desktop_path = edelib::build_filename(p.c_str(), "Desktop");
if(file_test(desktop_dir_path.c_str(), FILE_TEST_IS_DIR)) {
/* now try load icons from "Desktop" directory */
load_icons(desktop_dir_path.c_str());
/* setup watcher used for Desktop directory */
edelib::DirWatch::init();
/* setup watcher used for Desktop directory */
DirWatch::init();
if(edelib::file_test(desktop_path.c_str(), edelib::FILE_TEST_IS_DIR)) {
load_icons(desktop_path.c_str());
if(!edelib::DirWatch::add(desktop_path.c_str(),
edelib::DW_CREATE | edelib::DW_MODIFY | edelib::DW_RENAME | edelib::DW_DELETE))
{
E_WARNING(E_STRLOC ": Unable to watch %s\n", desktop_path.c_str());
}
if(!DirWatch::add(desktop_dir_path.c_str(), DW_CREATE | DW_MODIFY | DW_RENAME | DW_DELETE))
E_WARNING(E_STRLOC ": Unable to watch %s\n", desktop_dir_path.c_str());
else
DirWatch::callback(dir_watch_cb);
}
edelib::DirWatch::callback(dir_watch_cb);
running = true;
}
@@ -309,7 +315,7 @@ void Desktop::update_workarea(void) {
}
void Desktop::read_config(void) {
edelib::Resource conf;
Resource conf;
if(!conf.load(CONFIG_NAME)) {
E_WARNING(E_STRLOC ": Can't load %s, using default values\n", CONFIG_NAME);
@@ -372,7 +378,7 @@ void Desktop::read_config(void) {
void Desktop::load_icons(const char* path) {
E_ASSERT(path != NULL);
edelib::Resource conf, *conf_ptr = NULL;
Resource conf, *conf_ptr = NULL;
if(!conf.load(ICONS_CONFIG_NAME))
E_WARNING(E_STRLOC ": Can't load icons positions; arranging them somehow...\n");
@@ -397,7 +403,7 @@ void Desktop::load_icons(const char* path) {
}
void Desktop::save_icons_positions(void) {
edelib::Resource conf;
Resource conf;
char* icon_base;
DesktopIconListIter it = icons.begin(), it_end = icons.end();
@@ -472,7 +478,7 @@ IconSettings* Desktop::read_desktop_file(const char* path) {
return is;
}
bool Desktop::add_icon_by_path(const char* path, edelib::Resource* conf) {
bool Desktop::add_icon_by_path(const char* path, Resource* conf) {
E_ASSERT(path != NULL);
IconSettings* is = NULL;
@@ -561,12 +567,17 @@ DesktopIcon* Desktop::find_icon_by_path(const char* path, DesktopIconListIter* r
return NULL;
}
bool Desktop::remove_icon(DesktopIcon *d, bool real_delete) {
bool ret = remove_icon_by_path(d->path().c_str());
return ret;
}
bool Desktop::remove_icon_by_path(const char* path) {
DesktopIconListIter pos;
DesktopIcon* ic = find_icon_by_path(path, &pos);
if(!ic) {
E_DEBUG(">>> Didn't find %s\n", path);
E_DEBUG(E_STRLOC ": Didn't find '%s' as path marked for removal\n", path);
return false;
}
@@ -752,13 +763,13 @@ void Desktop::select_in_area(void) {
if(intersects(ax, ay, ax+aw, ay+ah, ic->x(), ic->y(), ic->w()+ic->x(), ic->h()+ic->y())) {
if(!ic->is_focused()) {
ic->do_focus();
// updated from Desktop::draw()
/* updated from Desktop::draw() */
ic->damage(EDAMAGE_CHILD_LABEL);
}
} else {
if(ic->is_focused()) {
ic->do_unfocus();
// updated from Desktop::draw()
/* updated from Desktop::draw() */
ic->fast_redraw();
//ic->damage(EDAMAGE_CHILD_LABEL);
//ic->redraw();
@@ -794,6 +805,8 @@ void Desktop::notify_desktop_changed(void) {
XFreeStringList(names);
}
/* leaving for the future */
#if 0
void Desktop::dnd_drop_source(const char* src, int src_len, int x, int y) {
if(!src)
return;
@@ -831,7 +844,7 @@ void Desktop::dnd_drop_source(const char* src, int src_len, int x, int y) {
else
sptr = src_copy;
if(!edelib::file_test(sptr, edelib::FILE_TEST_IS_REGULAR) || !edelib::file_test(sptr, edelib::FILE_TEST_IS_DIR)) {
if(!file_test(sptr, FILE_TEST_IS_REGULAR) || !file_test(sptr, FILE_TEST_IS_DIR)) {
edelib::message("Droping file content is not implemented yet ;)");
delete [] src_copy;
return;
@@ -900,6 +913,7 @@ void Desktop::dnd_drop_source(const char* src, int src_len, int x, int y) {
redraw();
}
#endif
void Desktop::draw(void) {
if(!damage())
@@ -1124,7 +1138,7 @@ int Desktop::handle(int event) {
if(di)
return di->handle(event);
dnd_drop_source(Fl::event_text(), Fl::event_length(), Fl::event_x(), Fl::event_y());
//dnd_drop_source(Fl::event_text(), Fl::event_length(), Fl::event_x(), Fl::event_y());
return 1;
}

View File

@@ -101,6 +101,8 @@ private:
bool moving;
bool do_dirwatch;
edelib::String desktop_dir_path;
SelectionOverlay* selbox;
GlobalIconSettings* gisett;
@@ -134,7 +136,7 @@ private:
void select_in_area(void);
void dnd_drop_source(const char* src, int src_len, int x, int y);
//void dnd_drop_source(const char* src, int src_len, int x, int y);
DesktopIcon* below_mouse(int px, int py);
@@ -154,6 +156,7 @@ public:
void read_config(void);
bool add_icon_by_path(const char* path, edelib::Resource* conf);
bool remove_icon(DesktopIcon *d, bool real_delete);
void update_workarea(void);
void area(int& X, int& Y, int& W, int& H) { X = x(); Y = y(); W = w(); H = h(); }