Implementing creating folders from menu. Also, try to store icon of created item when mouse last clicked

This commit is contained in:
Sanel Zukan 2012-04-23 12:43:20 +00:00
parent 8aa9d550b2
commit b16aa99e08
4 changed files with 56 additions and 28 deletions

View File

@ -60,7 +60,6 @@ static void props_cb(Fl_Widget*, void* d);
static MenuItem icon_menu[] = { static MenuItem icon_menu[] = {
{_("&Open"), 0, open_cb, 0}, {_("&Open"), 0, open_cb, 0},
{_("&Rename"), 0, rename_cb, 0}, {_("&Rename"), 0, rename_cb, 0},
{_("&Delete"), 0, 0, 0, FL_MENU_DIVIDER},
{_("&Properties"), 0, props_cb, 0}, {_("&Properties"), 0, props_cb, 0},
{0} {0}
}; };

View File

@ -3,7 +3,7 @@
* *
* ede-desktop, desktop and icon manager * ede-desktop, desktop and icon manager
* Part of Equinox Desktop Environment (EDE). * Part of Equinox Desktop Environment (EDE).
* Copyright (c) 2006-2008 EDE Authors. * Copyright (c) 2006-2012 EDE Authors.
* *
* This program is licensed under terms of the * This program is licensed under terms of the
* GNU General Public License version 2 or newer. * GNU General Public License version 2 or newer.
@ -42,6 +42,7 @@
#include <edelib/Netwm.h> #include <edelib/Netwm.h>
#include <edelib/WindowXid.h> #include <edelib/WindowXid.h>
#include <edelib/FontCache.h> #include <edelib/FontCache.h>
#include <edelib/Nls.h>
#include <edelib/Ede.h> #include <edelib/Ede.h>
#include "ede-desktop.h" #include "ede-desktop.h"
@ -73,6 +74,9 @@ EDELIB_NS_USING(MenuItem)
EDELIB_NS_USING(String) EDELIB_NS_USING(String)
EDELIB_NS_USING(DesktopFile) EDELIB_NS_USING(DesktopFile)
EDELIB_NS_USING(run_async) EDELIB_NS_USING(run_async)
EDELIB_NS_USING(input)
EDELIB_NS_USING(alert)
EDELIB_NS_USING(dir_create)
EDELIB_NS_USING(foreign_callback_add) EDELIB_NS_USING(foreign_callback_add)
EDELIB_NS_USING(foreign_callback_remove) EDELIB_NS_USING(foreign_callback_remove)
EDELIB_NS_USING(window_xid_create) EDELIB_NS_USING(window_xid_create)
@ -90,10 +94,11 @@ EDELIB_NS_USING(NETWM_CHANGED_CURRENT_WORKSPACE)
static void background_conf_cb(Fl_Widget*, void*); static void background_conf_cb(Fl_Widget*, void*);
static void icons_conf_cb(Fl_Widget*, void*); static void icons_conf_cb(Fl_Widget*, void*);
static void folder_create_cb(Fl_Widget*, void*);
MenuItem desktop_menu[] = { MenuItem desktop_menu[] = {
{_("Create &launcher..."), 0, 0}, {_("Create &launcher..."), 0, 0},
{_("Create &folder..."), 0, 0, 0, FL_MENU_DIVIDER}, {_("Create &folder..."), 0, folder_create_cb, 0, FL_MENU_DIVIDER},
{_("&Icons settings..."), 0, icons_conf_cb, 0}, {_("&Icons settings..."), 0, icons_conf_cb, 0},
{_("&Background..."), 0, background_conf_cb, 0}, {_("&Background..."), 0, background_conf_cb, 0},
{0} {0}
@ -137,6 +142,17 @@ static void icons_conf_cb(Fl_Widget*, void*) {
run_async("ede-launch ede-desktop-conf --icons"); run_async("ede-launch ede-desktop-conf --icons");
} }
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);
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());
}
static void desktop_message_handler(int action, Window xid, void *data) { static void desktop_message_handler(int action, Window xid, void *data) {
switch(action) { switch(action) {
case NETWM_CHANGED_CURRENT_WORKSPACE: case NETWM_CHANGED_CURRENT_WORKSPACE:
@ -150,6 +166,7 @@ static void desktop_message_handler(int action, Window xid, void *data) {
Desktop::Desktop() : EDE_DESKTOP_WINDOW(0, 0, 100, 100, "") { Desktop::Desktop() : EDE_DESKTOP_WINDOW(0, 0, 100, 100, "") {
selection_x = selection_y = 0; selection_x = selection_y = 0;
last_px = last_py = -1;
moving = false; moving = false;
do_dirwatch = true; do_dirwatch = true;
@ -279,10 +296,7 @@ void Desktop::update_workarea(void) {
if(!netwm_workarea_get_size(X, Y, W, H)) { if(!netwm_workarea_get_size(X, Y, W, H)) {
E_DEBUG(E_STRLOC ": wm does not support _NET_WM_WORKAREA; using screen sizes...\n"); E_DEBUG(E_STRLOC ": wm does not support _NET_WM_WORKAREA; using screen sizes...\n");
Fl::screen_xywh(X, Y, W, H);
X = Y = 0;
W = DisplayWidth(fl_display, fl_screen);
H = DisplayHeight(fl_display, fl_screen);
} }
resize(X, Y, W, H); resize(X, Y, W, H);
@ -494,8 +508,16 @@ bool Desktop::add_icon_by_path(const char* path, edelib::Resource* conf) {
int icon_x = random_pos(w() - 10); int icon_x = random_pos(w() - 10);
int icon_y = random_pos(w() - 10); int icon_y = random_pos(w() - 10);
/* assign if we have it */
if(last_px != -1 && last_py != -1) {
icon_x = last_px;
icon_y = last_py;
last_px = last_py = -1;
}
if(conf) { if(conf) {
/* we load positions from used ede-desktop-icos.conf only */ /* we load positions from used ede-desktop-icons.conf only */
conf->get(base, "X", icon_x, icon_x, edelib::RES_USER_ONLY); conf->get(base, "X", icon_x, icon_x, edelib::RES_USER_ONLY);
conf->get(base, "Y", icon_y, icon_y, edelib::RES_USER_ONLY); conf->get(base, "Y", icon_y, icon_y, edelib::RES_USER_ONLY);
} }
@ -969,6 +991,9 @@ int Desktop::handle(int event) {
selbox->x = Fl::event_x(); selbox->x = Fl::event_x();
selbox->y = Fl::event_y(); selbox->y = Fl::event_y();
} else if(Fl::event_button() == 3) { } else if(Fl::event_button() == 3) {
last_px = Fl::event_x();
last_py = Fl::event_y();
const edelib::MenuItem* item = dmenu->menu()->popup(Fl::event_x(), Fl::event_y()); const edelib::MenuItem* item = dmenu->menu()->popup(Fl::event_x(), Fl::event_y());
dmenu->picked(item); dmenu->picked(item);
} }

View File

@ -94,6 +94,10 @@ private:
static Desktop* pinstance; static Desktop* pinstance;
int selection_x, selection_y; int selection_x, selection_y;
/* last recorded pointer position, so icon can be created at position where menu is clicked */
int last_px, last_py;
bool moving; bool moving;
bool do_dirwatch; bool do_dirwatch;
@ -101,8 +105,8 @@ private:
GlobalIconSettings* gisett; GlobalIconSettings* gisett;
edelib::MenuButton* dmenu; edelib::MenuButton* dmenu;
Wallpaper* wallpaper; Wallpaper* wallpaper;
edelib::EdbusConnection* dbus; edelib::EdbusConnection* dbus;
DesktopIconList icons; DesktopIconList icons;

View File

@ -1,42 +1,42 @@
# data file for the Fltk User Interface Designer (fluid) # data file for the Fltk User Interface Designer (fluid)
version 1.0108 version 1.0300
header_name {.h} header_name {.h}
code_name {.cxx} code_name {.cxx}
Function {} {open Function {} {open
} { } {
Fl_Window {} {open selected Fl_Window {} {open
xywh {393 364 390 170} type Double visible xywh {474 344 430 170} type Double visible
} { } {
Fl_Button {} { Fl_Button {} {
label {&OK} xywh {10 10 75 75}
xywh {195 135 90 25}
}
Fl_Button {} {
label {&Cancel}
xywh {290 135 90 25}
}
Fl_Button {} {
xywh {10 10 75 75} labelsize 14
} }
Fl_Input {} { Fl_Input {} {
label {Name:} label {Name:}
xywh {165 10 215 25} xywh {205 10 215 25}
} }
Fl_Input {} { Fl_Input {} {
label {Comment:} label {Comment:}
xywh {165 40 215 25} xywh {205 40 215 25}
} }
Fl_Input {} { Fl_Input {} {
label {Execute:} label {Execute:} selected
xywh {165 70 185 25} xywh {205 70 185 25}
} }
Fl_Button {} { Fl_Button {} {
label {...} label {...}
xywh {355 70 25 25} xywh {395 70 25 25}
} }
Fl_Choice {} { Fl_Choice {} {
label {Type:} open label {Type:} open
xywh {165 100 215 25} down_box BORDER_BOX xywh {205 100 215 25} down_box BORDER_BOX
} {} } {}
Fl_Button {} {
label {&OK}
xywh {235 135 90 25}
}
Fl_Button {} {
label {&Cancel}
xywh {330 135 90 25}
}
} }
} }