1 #include "ide.h"
2 
EditorTabBar()3 EditorTabBar::EditorTabBar()
4 {
5 	Stacking();
6 	AutoScrollHide(false);
7 	FileIcons(false);
8 	SetBorder(1);
9 }
10 
GetFile(int n) const11 String EditorTabBar::GetFile(int n) const
12 {
13 	return tabs[n].key;
14 }
15 
FindSetFile(const String & fn)16 bool EditorTabBar::FindSetFile(const String& fn)
17 {
18 	int n = FindKey(fn);
19 	if(n >= 0)
20 	{
21 		SetCursor(n);
22 		return true;
23 	}
24 	return false;
25 }
26 
SetAddFile(const String & fn)27 void EditorTabBar::SetAddFile(const String& fn)
28 {
29 	if(IsNull(fn))
30 		return;
31 	if(FindSetFile(fn))
32 		return;
33 	AddFile(WString(fn), IdeFileImage(fn, false, false), true);
34 }
35 
RenameFile(const String & fn,const String & nn)36 void EditorTabBar::RenameFile(const String& fn, const String& nn)
37 {
38 	FileTabs::RenameFile(WString(fn), WString(nn));
39 }
40 
FixIcons()41 void EditorTabBar::FixIcons()
42 {
43 	for(int i = 0; i < tabs.GetCount(); i++)
44 		tabs[i].img = IdeFileImage(GetFile(i), false, false);
45 	Repos();
46 	Refresh();
47 }
48 
SetSplitColor(const String & fn,const Color & c)49 void EditorTabBar::SetSplitColor(const String& fn, const Color& c)
50 {
51 	int n = -1;
52 
53 	for(int i = 0; i < tabs.GetCount(); i++)
54 	{
55 		tabs[i].col = Null;
56 
57 		if(n < 0 && tabs[i].key == fn)
58 			n = i;
59 	}
60 
61 	if(n >= 0)
62 	{
63 		if(stacking)
64 			n = FindStackHead(tabs[n].stack);
65 		tabs[n].col = c;
66 	}
67 
68 	Refresh();
69 }
70 
ClearSplitColor()71 void EditorTabBar::ClearSplitColor()
72 {
73 	for(int i = 0; i < tabs.GetCount(); i++)
74 		tabs[i].col = Null;
75 	Refresh();
76 }
77 
TabFile()78 void Ide::TabFile()
79 {
80 	int q = tabs.GetCursor();
81 	if(q >= 0)
82 		EditFile(tabs.GetFile(q));
83 }
84 
ClearTab()85 void Ide::ClearTab()
86 {
87 	int c = tabs.GetCursor();
88 	if(c >= 0)
89 		tabs.Close(c);
90 }
91 
ClearTabs()92 void Ide::ClearTabs()
93 {
94 	tabs.Clear();
95 	FileSelected();
96 }
97 
CloseRest(EditorTabBar * tabs)98 void Ide::CloseRest(EditorTabBar *tabs)
99 {
100 	Index<String> fn;
101 	const Workspace& wspc = IdeWorkspace();
102 	for(int i = 0; i < wspc.GetCount(); i++)
103 		for(int j = 0; j < wspc.GetPackage(i).file.GetCount(); j++)
104 			fn.Add(SourcePath(wspc[i], wspc.GetPackage(i).file[j]));
105 	String cfn;
106 	if(tabs->GetCursor() >= 0)
107 		cfn = tabs->GetFile(tabs->GetCursor());
108 	for(int i = tabs->GetCount() - 1; i >= 0; i--)
109 		if(fn.Find(tabs->GetFile(i)) < 0)
110 			tabs->Close(i);
111 	tabs->FindSetFile(cfn);
112 }
113 
TabsLR(int jd)114 void Ide::TabsLR(int jd)
115 {
116 	TabBar::JumpStack js;
117 	int tc = tabs.GetCount();
118 
119 	int n = tabs.GetTabLR(jd);
120 	if(n >= 0 && n < tc) {
121 		js = tabs.jump_stack;
122 		EditFile(tabs.GetFile(n));
123 		tabs.jump_stack = js;
124 	}
125 }
126 
TabsStackLR(int jd)127 void Ide::TabsStackLR(int jd)
128 {
129 	int tc = tabs.GetCount();
130 
131 	int n = tabs.GetTabStackLR(jd);
132 	if(n >= 0 && n < tc)
133 		EditFile(tabs.GetFile(n));
134 }
135 
FileSelected()136 void Ide::FileSelected()
137 {
138 	if(IsNull(editfile))
139 		return;
140 
141 	tabs.SetAddFile(editfile);
142 }
143