📄 toolbar_toolconfig.erl
字号:
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %% $Id$%%-module(toolbar_toolconfig).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Erlang Toolbar%%%% Description %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tool configuration tool, edit and creates .tool files% This tool works separately from the toolbar.%%%% External data types %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% toolinfo() -- Tool configuration information-include("toolbar.hrl").%%%% Internal data types %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% tfwindow() -- Toolfile configuration window-record(tfwindow, {window, fileentry, toolentry,moduleentry,functionentry, iconentry,messageentry,htmlentry, label}).%%%% Exports %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-export([start/0]).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-export([init/0]). % spawn%%% Exported functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%----------------------------------------% start() => pid()%----------------------------------------start() -> spawn(toolbar_toolconfig,init,[]).%%% Internal functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=============================================================================% Main loop%=============================================================================%----------------------------------------% init()%----------------------------------------init() -> %% Start GS (or get the pid if it is already running) S = gs:start(), %% Draw the window Window = draw_window(S), loop(S,Window).%----------------------------------------% loop(S,Window)% S - pid() GS% Window - tfwindow()%----------------------------------------loop(S,Window) -> receive %% 'Return' pressed in the 'File' entry {gs,_Obj,keypress,file,['Return'|_]} -> %% Check if a file name is specified case string:strip(gs:read(Window#tfwindow.fileentry,text)) of %% No file name specified, move focus to next entry "" -> move_focus(Window,file); %% A name is specified String -> %% Add a .tool suffix to the file name if necessary FileName = tool_file(String), %% Write the complete file name to the file entry gs:config(Window#tfwindow.fileentry,{text,FileName}), %% Try to open the file case file:consult(FileName) of %% File exists and seems ok {ok,[{version,Vsn},T]} -> %% Check the syntax of the file contents %% (All mandatory information specified, %% correct types, etc) case toolbar_lib:tool_info_syntax(Vsn,T) of %% Ok -- Show the file contents in the window %% and move focus to the next entry {ok,Info} -> display(Window,"File: "++FileName++ " opened"), clear_info(Window), show_info(Window,Info), move_focus(Window,file); %% Erronous version number -- Notify user {error,version} -> Win = Window#tfwindow.window, tool_utils:notify(Win,[FileName, "File has wrong version number"]); %% Other error -- Notify user _Error -> Win = Window#tfwindow.window, tool_utils:notify(Win,[FileName, "File is on erronous format"]) end; %% The file can not be read, show default values %% according to the file name in the window and %% move focus to the next entry _ -> display(Window,"File: "++FileName ++ " could not be read, new file"), Tool = filename:basename(FileName,".tool"), clear_info(Window), show_info(Window,[{tool,Tool}, {start,{list_to_atom(Tool), start,[]}}, {icon,Tool++".gif"}, {html,Tool++".html"}]), move_focus(Window,file) end end, loop(S,Window); %% 'Return' pressed in another entry, move focus to next entry {gs,_Obj,keypress,Focus,['Return'|_]} -> move_focus(Window,Focus), loop(S,Window); %% Any oher keypress, clear the display {gs,_Obj,keypress,_Data,_Args} -> display_clear(Window), loop(S,Window); %% 'Clear' button pressed, clear the window {gs,_Obj,click,_Data,["Clear"|_]} -> clear_info(Window), loop(S,Window); %% 'Save' button pressed, save the given information to file {gs,_Obj,click,_Data,["Save"|_]} -> %% Check if a file name is specified case string:strip(gs:read(Window#tfwindow.fileentry,text)) of %% No file name specified, notify user "" -> Win = Window#tfwindow.window, tool_utils:notify(Win, "A file name must be specified"); %% A name is specified String -> %% Add a .tool suffix to the file name if necessary FileName = tool_file(String), %% Write the complete file name to the file entry gs:config(Window#tfwindow.fileentry,{text,FileName}), %% Check the other information given case check_info(Window) of %% If given info is correct, try to save %% it to the file {ok,ToolInfo} -> Win = Window#tfwindow.window, case save_info(Win,FileName,ToolInfo) of %% Ok, display confirmation ok -> display(Window, "Tool information saved to "++ FileName); %% Cancel, do nothing cancel -> ignore; %% Error, display error message {error,Reason} -> display(Window, toolbar_lib:error_string(Reason)++ FileName) end; %% Given info incorrect, notify user {error,Reason} -> Win = Window#tfwindow.window, Str = toolbar_lib:error_string(Reason), tool_utils:notify(Win,Str) end end, loop(S,Window); %% 'Stop' button, close window and exit {gs,_Obj,click,_Data,["Stop"|_]} -> gs:destroy(Window#tfwindow.window), finished; %% Window closed, exit {gs,_Obj,destroy,_Data,_Args} -> finished; Other -> io:format("toolbar_toolconfig: unexp msg: ~p~n",[Other]), loop(S,Window) end.%=============================================================================% Graphics%=============================================================================%----------------------------------------% draw_window(S)% S - pid() GS% Draw the main window.%----------------------------------------draw_window(S) -> %% ----- Open a new window ----- Win = gs:create(window,S,[{width,400},{height,390}, {title,"Create Tool File"}]), %% ----- Top frame containing a 'File name' label and entry ----- Top = gs:create(frame,Win,[{x,0},{y,0},{width,400},{height,60},{bw,2}, {keypress,true}]), %% File name gs:create(label,Top,[{x,10},{y,10},{width,80},{height,30},{align,e}, {keypress,true}, {label,{text,"File name:"}}]), File = gs:create(entry,Top,[{x,110},{y,10},{width,280},{height,30}, {keypress,true},{data,file}]), %% ----- Middle frame containing other labels and entries ----- Mid = gs:create(frame,Win,[{x,0},{y,60},{width,400},{height,250},{bw,2},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -