Пример #1
0
		UpdateTitle:function(){
			if(this.main_widget){
				var body=this.main_widget;
				var s_name=UI.GetMainFileName((this.file_name));
				this.need_save=body.TestNeedSave();
				this.title=UI.Format("@1 (Sticker wall)",s_name)+(this.need_save?'*':'');
				this.tooltip=this.file_name;
			}
		},
Пример #2
0
UI.OpenStickerWallTab=function(file_name,is_quiet){
	var layout=UI.m_ui_metadata["<layout>"];
	layout.m_is_maximized=0;
	file_name=IO.NormalizeFileName(file_name);
	//coulddo: bring-up check
	UI.top.app.quit_on_zero_tab=0;
	var bk_current_tab_id=undefined;
	if(is_quiet){
		bk_current_tab_id=UI.top.app.document_area.current_tab_id;
	}
	var ret=UI.NewTab({
		file_name:file_name,
		title:UI.GetMainFileName((file_name)),
		tooltip:file_name,
		document_type:"stickerwall",
		//area_name:"v_tools",
		NeedRendering:function(){
			if(!this.main_widget){return 1;}
			if(this==UI.top.app.document_area.active_tab){return 1;}
			return 0;
		},
		UpdateTitle:function(){
			if(this.main_widget){
				var body=this.main_widget;
				var s_name=UI.GetMainFileName((this.file_name));
				this.need_save=body.TestNeedSave();
				this.title=UI.Format("@1 (Sticker wall)",s_name)+(this.need_save?'*':'');
				this.tooltip=this.file_name;
			}
		},
		body:function(){
			//use styling for editor themes
			UI.context_parent.body=this.main_widget;
			var common_style=UI.default_styles.sticker_wall.common_style;
			if(this.main_widget){this.file_name=this.main_widget.m_file_name}
			//sticker wall area
			var attrs={
				'x':0,'y':common_style.h_toolbar,
				'w':UI.context_parent.w,
				'h':UI.context_parent.h-common_style.h_toolbar,
				'm_file_name':this.file_name,
				'activated':this==UI.top.app.document_area.active_tab,
			};
			var body=W.StickerWall("body",attrs)
			if(!this.main_widget){
				this.main_widget=body;
			}
			this.need_save=this.main_widget.TestNeedSave();
			this.UpdateTitle();
			//toolbar
			UI.RoundRect({
				x:-common_style.toolbar_shadow_size,y:common_style.h_toolbar-common_style.toolbar_shadow_size,
				w:UI.context_parent.w+common_style.toolbar_shadow_size*2,h:common_style.toolbar_shadow_size*2,
				round:common_style.toolbar_shadow_size,
				border_width:-common_style.toolbar_shadow_size,
				color:common_style.toolbar_shadow_color,
			});
			UI.RoundRect({
				x:0,y:0,
				w:UI.context_parent.w,h:common_style.h_toolbar,
				color:common_style.toolbar_color,
			});
			//new sticker buttons
			var has_any_sel=0;
			var has_code_sel=0;
			for(var i=0;i<body.m_stickers.length;i++){
				if(body.m_stickers[i].m_is_selected){
					has_any_sel=1;
					if(body.m_stickers[i].type=="code"){
						has_code_sel=1;
					}
				}
			}
			var x_current=0;
			x_current+=W.Button("new_note",{
				x:x_current,y:0,
				w:32,h:32,
				font:UI.Font(UI.icon_font_name,28),
				text:"T",
				tooltip:"Add note - CTRL+M",
				OnClick:function(){body.InsertNote();},
			}).w;
			//if(UI.HasFocus(body)){
			W.Hotkey("",{
				key:"CTRL+M",
				action:function(){body.InsertNote();},
			});
			//}
			x_current+=W.Button("new group",{
				x:x_current,y:0,
				w:32,h:32,
				font:UI.Font(UI.icon_font_name,28),
				text:"组",
				tooltip:"Add group - SHIFT+CTRL+M",
				OnClick:function(){body.InsertGroup();},
			}).w;
			W.Hotkey("",{
				key:"SHIFT+CTRL+M",
				action:function(){body.InsertGroup();},
			});
			if(has_any_sel){
				x_current+=W.Button("del_note",{
					x:x_current,y:0,
					w:32,h:32,
					font:UI.Font(UI.icon_font_name,28),
					text:"剪",
					tooltip:"Cut stickers - SHIFT+CTRL+X",
					OnClick:function(){body.DeleteSelection();},
				}).w;
				W.Hotkey("",{
					key:"SHIFT+CTRL+X",
					action:function(){body.DeleteSelection();},
				});
				if(UI.HasFocus(body)){
					W.Hotkey("",{
						key:"DELETE",
						action:function(){body.DeleteSelection();},
					});
				}
			}
			if(UI.SDL_HasClipboardText()){
				x_current+=W.Button("paste",{
					x:x_current,y:0,
					w:32,h:32,
					font:UI.Font(UI.icon_font_name,28),
					text:"粘",
					tooltip:"Paste - CTRL+V",
					OnClick:function(){body.Paste();},
				}).w;
				if(UI.HasFocus(body)){
					W.Hotkey("",{
						key:"CTRL+V",
						action:function(){body.Paste();},
					});
				}
			}
			if(has_any_sel){
				x_current+=W.Button("font_bigger",{
					x:x_current,y:0,
					w:32,h:32,
					font:UI.Font(UI.icon_font_name,28),
					text:"大",
					tooltip:"Bigger font - SHIFT+CTRL+'+'",
					OnClick:function(){
						body.MultiplyScale(1.105);
					},
				}).w;
				x_current+=W.Button("font_smaller",{
					x:x_current,y:0,
					w:32,h:32,
					font:UI.Font(UI.icon_font_name,28),
					text:"小",
					tooltip:"Smaller font - SHIFT+CTRL+'-'",
					OnClick:function(){
						body.MultiplyScale(1.0/1.105);
					},
				}).w;
				//if(UI.HasFocus(body)){
				W.Hotkey("",{
					key:"SHIFT+CTRL+-",
					action:function(){body.MultiplyScale(1.0/1.105);},
				});
				W.Hotkey("",{
					key:"SHIFT+CTRL+=",
					action:function(){body.MultiplyScale(1.105);},
				});
				//}
			}
			if(has_code_sel){
				x_current+=W.Button("goto_code",{
					x:x_current,y:0,
					w:32,h:32,
					font:UI.Font(UI.icon_font_name,28),
					text:"去",
					tooltip:"Go to original - CTRL+ALT+G",
					OnClick:function(){
						body.GotoOriginal();
					},
				}).w;
				W.Hotkey("",{
					key:"CTRL+ALT+G",
					action:function(){body.GotoOriginal();},
				});
			}
			if(UI.HasFocus(body)){
				W.Hotkey("",{
					key:"ESC",
					action:function(){
						for(var i=0;i<body.m_stickers.length;i++){
							var sticker_i=body.m_stickers[i];
							if(sticker_i.m_is_selected&&sticker_i.doc){
								UI.SetFocus(sticker_i.doc);
								UI.Refresh();
								break;
							}
						}
					},
				});
				////////////////////
				//moving the cursor
				W.Hotkey("",{
					key:"UP",
					action:function(){
						//what is "up"? angle-based test
						body.MoveCursorKeyboard(0,-1);
					},
				});
				W.Hotkey("",{
					key:"DOWN",
					action:function(){
						body.MoveCursorKeyboard(0,1);
					},
				});
				W.Hotkey("",{
					key:"LEFT",
					action:function(){
						body.MoveCursorKeyboard(-1,0);
					},
				});
				W.Hotkey("",{
					key:"RIGHT",
					action:function(){
						body.MoveCursorKeyboard(1,0);
					},
				});
				////////////////////
				//move the stickers... by a fixed amount
				W.Hotkey("",{
					key:"SHIFT+UP",
					action:function(){
						body.MoveSelectionKeyboard(0,-32);
					},
				});
				W.Hotkey("",{
					key:"SHIFT+DOWN",
					action:function(){
						body.MoveSelectionKeyboard(0,32);
					},
				});
				W.Hotkey("",{
					key:"SHIFT+LEFT",
					action:function(){
						body.MoveSelectionKeyboard(-32,0);
					},
				});
				W.Hotkey("",{
					key:"SHIFT+RIGHT",
					action:function(){
						body.MoveSelectionKeyboard(32,0);
					},
				});
				////////////////////
				//resizing the sticker
				W.Hotkey("",{
					key:"CTRL+UP",
					action:function(){
						body.ResizeSelectionKeyboard(0,-32);
					},
				});
				W.Hotkey("",{
					key:"CTRL+DOWN",
					action:function(){
						body.ResizeSelectionKeyboard(0,32);
					},
				});
				W.Hotkey("",{
					key:"CTRL+LEFT",
					action:function(){
						body.ResizeSelectionKeyboard(-32,0);
					},
				});
				W.Hotkey("",{
					key:"CTRL+RIGHT",
					action:function(){
						body.ResizeSelectionKeyboard(32,0);
					},
				});
			}
			//file name
			var name_did={};
			var s_file_name=undefined;
			for(var i=0;i<body.m_stickers.length;i++){
				var sticker_i=body.m_stickers[i];
				if(sticker_i.m_is_selected){
					if(sticker_i.type=="code"&&sticker_i.doc){
						//if(!name_did[sticker_i.file_name]){
						//	name_did[sticker_i.file_name]=1;
						s_file_name=sticker_i.file_name;
						if(UI.HasFocus(sticker_i.doc)){
							break;
						}
					}
				}
			}
			W.Text("",{
				x:x_current+8,y:2,
				font:UI.Font(UI.font_name,24),
				text:s_file_name,
				color:common_style.file_name_color,
			});
			return body;
		},
		Save:function(){
			if(!this.main_widget){return;}
			if(this.main_widget.m_file_name&&this.main_widget.m_file_name.indexOf('<')>=0){
				this.SaveAs()
				return
			}
			this.main_widget.Save();
			this.need_save=this.main_widget.need_save;
		},
		SaveAs:function(){
			if(!this.main_widget){return;}
			var fn=IO.DoFileDialog(1,"wall",
				this.main_widget.m_file_name.indexOf('<')>=0?
					UI.m_new_document_search_path:
					UI.GetPathFromFilename(this.main_widget.m_file_name));
			if(!fn){return;}
			this.m_file_name=fn
			this.main_widget.m_file_name=fn
			this.Save()
		},
		SaveMetaData:function(){
			if(this.main_widget){this.main_widget.SaveMetaData();}
		},
		OnDestroy:function(){
			if(this.main_widget){this.main_widget.OnDestroy();}
		},
		Reload:function(){
			if(this.main_widget){this.main_widget.Reload();}
		},
	})
	if(is_quiet){
		UI.top.app.document_area.current_tab_id=bk_current_tab_id;
	}
	return ret;
};