tv_new_table.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 658 行 · 第 1/2 页
ERL
658 行
%% ``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(tv_new_table).-export([start/2, init/3 ]).-define(DEFAULT_BG_COLOR, {217, 217, 217}).-define(FONT, {screen, 12}).-define(WIN_WIDTH, 400).-define(WIN_HEIGHT, 555). %% 510-define(FRAME_WIDTH, 400).-define(FRAME1_HEIGHT, 170).-define(FRAME2_HEIGHT, 260).-define(FRAME3_HEIGHT, 125). %% 80-define(BW, 2).-define(FRAME_X, 0).-define(FRAME1_Y, 0).-define(FRAME2_Y, 170).-define(FRAME3_Y, 430).-define(LBL_HEIGHT, 30).-define(NODE_LBL_WIDTH, 45).-define(NAME_LBL_WIDTH, 85).-define(TYPE_LBL_WIDTH, 45).-define(PROT_LBL_WIDTH, 85).-define(KEYPOS_LBL_WIDTH, 95).-define(LBL_X, 10).-define(NODE_LBL_Y, 20).-define(NAME_LBL_Y, 80).-define(TYPE_LBL_Y, 10).-define(PROT_LBL_Y, 100).-define(KEYPOS_LBL_Y, 200).-define(ENTRY_HEIGHT, 30).-define(NODE_ENTRY_WIDTH, 275).-define(NAME_ENTRY_WIDTH, 275).-define(KEYPOS_ENTRY_WIDTH, 50).-define(ENTRY_X1, 110).-define(ENTRY_X2, 110).-define(NODE_ENTRY_Y, 20).-define(NAME_ENTRY_Y, 80).-define(KEYPOS_ENTRY_Y, 200).-define(RBTN_HEIGHT, 30).-define(RBTN_WIDTH1, 105).-define(RBTN_WIDTH2, 115).-define(RBTN_X1, 60).-define(RBTN_X2, 165).-define(RBTN_X3, 270).-define(RBTN_Y1, 40).-define(RBTN_Y1PLUS, 70).-define(RBTN_Y2, 130).-define(CBTN_HEIGHT, 30).-define(NAMED_TABLE_CBTN_WIDTH, 100).-define(OPEN_BROWSER_CBTN_WIDTH, 105).-define(NAMED_TABLE_CBTN_X, 110).-define(NAMED_TABLE_CBTN_Y, 120).-define(OPEN_BROWSER_CBTN_X, 85). %% 215-define(OPEN_BROWSER_CBTN_Y, 10). %% 200-define(BTN_WIDTH, 100).-define(BTN_HEIGHT, 30).-define(BTN_X1, 85). -define(BTN_X2, 225).-define(BTN_Y, 65). %% 30-define(VLINE_LBL_WIDTH, (380 - 2 * ?BW)).-define(VLINE_LBL_HEIGHT, 1).-define(HLINE_LBL_WIDTH, 1).-define(HLINE_LBL_HEIGHT, 70).-define(VLINE_LBL_X, (10 - ?BW)).-define(VLINE_LBL_Y1, 85).-define(VLINE_LBL_Y2, 180).-define(HLINE_LBL_X, 188).-define(HLINE_LBL_Y, 180).-define(DEFAULT_NAME, my_table).-define(DEFAULT_TYPE, set).-define(DEFAULT_PROT, public).-define(DEFAULT_KEYPOS, 1).start(Node, ErrMsgMode) -> spawn_link(?MODULE, init, [Node, ErrMsgMode, self()]).init(Node, ErrMsgMode, MPid) -> process_flag(trap_exit, true), put(error_msg_mode, ErrMsgMode), create_window(Node), loop(false, ?DEFAULT_TYPE, ?DEFAULT_PROT, true, MPid).loop(NamedTab, Type, Prot, OpenBrowser, MPid) -> receive {gs, ok, click, _Data, _Args} -> gs:config(win, [{cursor, busy}]), case create_table(NamedTab, Type, Prot, OpenBrowser, MPid) of ok -> exit(normal); error -> gs:config(win, [{cursor, arrow}]), loop(NamedTab, Type, Prot, OpenBrowser, MPid) end; {gs, cancel, click, _Data, _Args} -> exit(normal); {gs, set, click, _Data, _Args} -> loop(NamedTab, set, Prot, OpenBrowser, MPid); {gs, ordered_set, click, _Data, _Args} -> loop(NamedTab, ordered_set, Prot, OpenBrowser, MPid); {gs, bag, click, _Data, _Args} -> loop(NamedTab, bag, Prot, OpenBrowser, MPid); {gs, duplicate_bag, click, _Data, _Args} -> loop(NamedTab, duplicate_bag, Prot, OpenBrowser, MPid); {gs, public, click, _Data, _Args} -> gs:config(open_browser, [{enable, true}, {select, OpenBrowser}]), loop(NamedTab, Type, public, OpenBrowser, MPid); {gs, protected, click, _Data, _Args} -> gs:config(open_browser, [{enable, true}, {select, OpenBrowser}]), loop(NamedTab, Type, protected, OpenBrowser, MPid); {gs, private, click, _Data, _Args} -> gs:config(open_browser, [{select, false}, {enable, false}]), loop(NamedTab, Type, private, OpenBrowser, MPid); {gs, named_table, click, Data, _Args} -> gs:config(named_table, [{data, not(Data)}]), loop(Data, Type, Prot, OpenBrowser, MPid); {gs, open_browser, click, Data, _Args} -> gs:config(open_browser, [{data, not(Data)}]), loop(Data, Type, Prot, Data, MPid); {gs, EntryId, keypress, _Data, ['Tab', _No, 0 | _T]} -> case get_entry_term(EntryId) of {ok, _Term} -> gs:config(next_entry(EntryId, forward), [{setfocus, true}, {select, {0, 100000000}}]); error -> done end, loop(NamedTab, Type, Prot, OpenBrowser, MPid); {gs, EntryId, keypress, _Data, ['Tab', _No, 1 | _T]} -> case get_entry_term(EntryId) of {ok, _Term} -> gs:config(next_entry(EntryId, backward), [{setfocus, true}, {select, {0, 100000000}}]); error -> done end, loop(NamedTab, Type, Prot, OpenBrowser, MPid); {gs, EntryId, keypress, _Data, ['Down' | _T]} -> case get_entry_term(EntryId) of {ok, _Term} -> gs:config(next_entry(EntryId, forward), [{setfocus, true}, {select, {0, 100000000}}]); error -> done end, loop(NamedTab, Type, Prot, OpenBrowser, MPid); {gs, EntryId, keypress, _Data, ['Up' | _T]} -> case get_entry_term(EntryId) of {ok, _Term} -> gs:config(next_entry(EntryId, backward), [{setfocus, true}, {select, {0, 100000000}}]); error -> done end, loop(NamedTab, Type, Prot, OpenBrowser, MPid); {gs, _EntryId, keypress, _Data, ['Return' | _T]} -> gs:config(win, [{cursor, busy}]), case create_table(NamedTab, Type, Prot, OpenBrowser, MPid) of ok -> exit(normal); error -> gs:config(win, [{cursor, arrow}]), loop(NamedTab, Type, Prot, OpenBrowser, MPid) end; {gs, win, configure, _Data, _Args} -> gs:config(win, [{width, ?WIN_WIDTH}, {height, ?WIN_HEIGHT}]), loop(NamedTab, Type, Prot, OpenBrowser, MPid); {gs, win, destroy, _Data, _Args} -> exit(normal); raise -> gs:config(win, [raise]), loop(NamedTab, Type, Prot, OpenBrowser, MPid); {error_msg_mode, ErrMsgMode} -> put(error_msg_mode, ErrMsgMode), loop(NamedTab, Type, Prot, OpenBrowser, MPid); {'EXIT', _Pid, _Reason} -> exit(normal); _Other -> loop(NamedTab, Type, Prot, OpenBrowser, MPid) end.create_table(NamedTab, Type, Prot, OpenBrowser, MPid) -> case get_entry_term(node_entry) of error -> error; {ok, Node} -> case get_entry_term(name_entry) of error -> error; {ok, TabName} -> case get_entry_term(keypos_entry) of error -> error; {ok, KeyPos} -> Options = [Type, Prot, {keypos, KeyPos}] ++ case NamedTab of true -> [named_table]; false -> [] end, {Readable, NewOpenBrowser} = case Prot of private -> {false, false}; _Other -> {true, OpenBrowser} end, MPid ! {tv_new_table, self(), Node, TabName, Options, ets, Readable, NewOpenBrowser}, receive ok -> ok; error -> show_error_msg(), error after 5000 -> show_error_msg(), error end end end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?