Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
便捷应用管理源代码[开源]
Apps Section
2635
views ·
0
replies ·
To
floor
Go
gaochong
deepin
2011-08-16 18:43
Author
源代码我打包上传到了网盘,有需要的朋友可以下载BS 一下; ;)
http://u.115.com/file/clqhpeea#
appmenu_code.tar.gz
lazarus 的TForm 类里有一个方法,是可以响应文件拖入事件的;DropFiles
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
我们只需要实现这个方法,就能捕获到拖入到窗口中的文件名列表 FileNames ,文件可能不止一个,因为用户有可能会同时拖入多个文件,这个用个循环处理一下就可以把文件名都取出,FileNames 本身就一个数组;
listview 控件,是一种最常见的窗件上的列表控件,lazarus 有现成的类(可视化的VCL),直接放到窗体上就能使用;
我把获取到文件名(含路径),添加到 listview 中,配上一个图标,就能实现添加了;
鼠标双击这个事件,只从windows 时代开始被广泛支持的,这里也只需要实现一下就行了,
当鼠标双击事件发生时,执行我们实现过的响应事件代码;
比如:
ExecuteProcess(
UTF8ToSys( '/usr/bin/gnome-display-properties')
,'');
主要代码如下:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ComCtrls, Menus, StdCtrls, ExtCtrls, IpHtml, Ipfilebroker,IniFiles;
type
ShellFiles= record
fileName:string;
filePath:string;
filecode:string;
fileIMG:Integer;
end;
type
{ TForm1 }
TForm1 = class(TForm)
ImageList1: TImageList;
ListView1: TListView;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
PageControl1: TPageControl;
PopupMenu1: TPopupMenu;
StatusBar1: TStatusBar;
TabSheet1: TTabSheet;
// procedure Button1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
// procedure IdleTimer1Timer(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
procedure MenuItem1Click(Sender: TObject);
procedure MenuItem2Click(Sender: TObject);
procedure MenuItem3Click(Sender: TObject);
procedure MenuItem4Click(Sender: TObject);
procedure MenuItem5Click(Sender: TObject);
procedure ScrollBox1Click(Sender: TObject);
procedure TrayIcon1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
procedure ListShow;
procedure ListAdd(addfile:ShellFiles);
procedure MButtonFalse( Byn:Boolean );
end;
var
Form1: TForm1;
sedit:Boolean;
implementation
uses unit2,unit3,Unit4;
{ TForm1 }
procedure TForm1.MButtonFalse( Byn:Boolean );
begin
if not byn then
begin
MenuItem1.Enabled:=False;
MenuItem2.Enabled:=False;
MenuItem3.Enabled:=False;
Form1.AllowDropFiles:=False;
end else
begin
MenuItem1.Enabled:=true;
MenuItem2.Enabled:=true;
MenuItem3.Enabled:=true;
Form1.AllowDropFiles:=true;
end;
end;
procedure TForm1.ListAdd(addfile:ShellFiles);
var
addini:TIniFile;
begin
addini:=TIniFile.Create(ExtractFilePath(Application.ExeName)+'app.ini');
if sedit then
begin
addini.EraseSection(ListView1.Selected.Caption);
ListView1.Selected.Caption:= addfile.fileName;
ListView1.Selected.SubItems[0]:= addfile.filePath;
ListView1.Selected.SubItems[1]:= addfile.filecode;
ListView1.Selected.SubItems[2]:= inttostr( addfile.fileIMG );
ListView1.Selected.ImageIndex:= addfile.fileIMG ;
// ShowMessage(addfile.fileName);
end else
begin
with ListView1.Items.Add do
begin
Caption:= addfile.fileName;
SubItems.Add(addfile.filePath);
SubItems.Add(addfile.filecode);
ImageIndex:=addfile.fileIMG;
end;
end;
addini.WriteString(addfile.fileName,'APPName',addfile.fileName);
addini.WriteString(addfile.fileName,'APPpath',addfile.filePath);
addini.WriteString(addfile.fileName,'APPcode',addfile.filecode);
addini.WriteInteger(addfile.fileName,'imgindex',addfile.fileIMG);
addini.Free;
// ListShow;
end;
procedure TForm1.ListShow;
var
i:Integer;
test1F:TIniFile;
zdName:TStringList;
begin
ListView1.Clear;
test1F:=TIniFile.Create(ExtractFilePath(Application.ExeName)+'app.ini');
zdName:=TStringList.Create;
test1F.ReadSections(zdName);
for i:=0 to zdName.Count -1 do
begin
with ListView1.Items.Add do
begin
Caption:= test1F.ReadString(zdName[i],'APPName','' ) ;
SubItems.Add( test1F.ReadString(zdName[i],'APPpath','') );
SubItems.Add( test1F.ReadString(zdName[i],'APPcode','') );
SubItems.Add( test1F.ReadString(zdName[i],'imgindex','') );
ImageIndex:= test1F.ReadInteger(zdName[i],'imgindex',0);
end;
end;
test1F.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//
MButtonFalse(false);
ListShow;
end;
procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String
);
var
i:Integer;
add:ShellFiles;
begin
sedit:=False;
for i:=0 to Length(FileNames) -1 do
begin
add.fileName:=ExtractFileName(FileNames[i]);
add.filePath:=FileNames[i];
add.filecode:='';
add.fileIMG:=1;
ListAdd(add);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//gnome-accessibility-keyboard-properties
ExecuteProcess(
UTF8ToSys( '/usr/bin/gnome-display-properties')
,'');
end;
procedure TForm1.ListView1DblClick(Sender: TObject);
var
commanstr:Pcommanstr;
begin
if ListView1.Selected<>nil then
begin
commanstr.pathstr:= ListView1.Selected.SubItems[0];
commanstr.codestr:= ListView1.Selected.SubItems[1];
try
ExecuteProcess(
UTF8ToSys( commanstr.pathstr)
,commanstr.codestr);
except
Application.MessageBox('您调用不是一个有效的可以执行文件!','提示',32);
Close;
end;
end;
end;
//
procedure TForm1.MenuItem1Click(Sender: TObject);
begin
Form2.Caption:='添加应用';
Form2.Edit1.Text:='';
Form2.Edit2.Text:='';
Form2.ComboBox1.ItemIndex:=1;
ImageList1.GetBitmap(1,Form2.Image1.Picture.Bitmap);
sedit := False;
Form2.ShowModal;
end;
procedure TForm1.MenuItem2Click(Sender: TObject);
var
delini:TIniFile;
begin
if ListView1.Selected<>nil then
begin
delini:=TIniFile.Create(ExtractFilePath(Application.ExeName)+'app.ini');
delini.EraseSection(ListView1.Selected.Caption);
delini.Free;
ListView1.Selected.Delete;
end;
end;
procedure TForm1.MenuItem3Click(Sender: TObject);
var
imgindex:Integer;
begin
if ListView1.Selected <> nil then
begin
Form2.Caption:='修改应用设置';
Form2.Edit1.Text:= ListView1.Selected.Caption;
Form2.Edit2.Text:= ListView1.Selected.SubItems[0];
Form2.Edit3.Text:= ListView1.Selected.SubItems[1];
imgindex:= strtoint( ListView1.Selected.SubItems[2] );
Form2.ComboBox1.ItemIndex:= imgindex;
ImageList1.GetBitmap( imgindex , Form2.Image1.Picture.Bitmap );
sedit:=True;
Form2.ShowModal;
end;
end;
procedure TForm1.MenuItem4Click(Sender: TObject);
begin
Form4.ShowModal;
end;
procedure TForm1.MenuItem5Click(Sender: TObject);
begin
end;
procedure TForm1.ScrollBox1Click(Sender: TObject);
begin
end;
procedure TForm1.TrayIcon1Click(Sender: TObject);
begin
end;
initialization
{$I unit1.lrs}
end.
Copy the Code
Reply
Like 0
Favorite
View the author
All Replies
No replies yet
Please
sign
in first
New Thread
Popular Ranking
Change
deepin eighth Bi-Weekly Technical Report is online
Popular Events
More
http://u.115.com/file/clqhpeea#
appmenu_code.tar.gz
lazarus 的TForm 类里有一个方法,是可以响应文件拖入事件的;DropFiles
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
我们只需要实现这个方法,就能捕获到拖入到窗口中的文件名列表 FileNames ,文件可能不止一个,因为用户有可能会同时拖入多个文件,这个用个循环处理一下就可以把文件名都取出,FileNames 本身就一个数组;
listview 控件,是一种最常见的窗件上的列表控件,lazarus 有现成的类(可视化的VCL),直接放到窗体上就能使用;
我把获取到文件名(含路径),添加到 listview 中,配上一个图标,就能实现添加了;
鼠标双击这个事件,只从windows 时代开始被广泛支持的,这里也只需要实现一下就行了,
当鼠标双击事件发生时,执行我们实现过的响应事件代码;
比如:
ExecuteProcess(
UTF8ToSys( '/usr/bin/gnome-display-properties')
,'');
主要代码如下: