PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

Dragging files to other applications | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

The good news: Unlike the drop problems, all tested programs (Konqueror, Kate, Firefox, Opera, Nautilus) seem to be able to handle correct URIs dragged to them in the right way. Even Firefox accepts text/uri-list data.

The first step is again to tell the widget that it has the ability to act as a source for drag data. Furthermore, we need to provide the data we want to drag, which can be done by connecting the widget to the "drag-data-get" signal.

We told the widget the following:

Next is to provide the data for the drop target in the dragDataGet function:

The data are passed by overwriting the selection data via the set() method of the selection_data. As we want to follow the standards, the file name has to be converted to a full-flagged url-encoded URI, with the terminating \r\n at the end of the line. When nothing is selected in the tree, we don't change the selection data.

When trying to drag a file to your favorite application, you will note that nothing happens. Why? The URI passed to the program looks like that: file%3A%2F%2Flocalhost%2Fdata%2Fphp-gtk. Yes, urlencode doesn't take care of the character's meaning in the URI. Now it would cost some effort to make a function which does a correct encoding while taking care of special characters, as http URIs can contain slashes in a parameter which would have to be encoded, but slashes in the filename not. For that reason, only a simple back-translation of some chars is done after urlencoding the string:

With that, we can change our dragDataGet function:
$selection_data->set($selection_data->target, 8, $this->pathurlencode($this->getUriFromFile($file)) . "\r\n");

忘却曲線を使ってこの知識を確実に記憶に残す

フォーラムで「Dragging files to other applications」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | Dragging files to other applications」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: