Navigator.cpp

Zbigniew Rebacz, 10/05/2013 01:40 PM

Download (3.03 KB)

 
1
#include "ide.h"
2

    
3
void AssistEditor::SyncNavigator()
4
{
5
        if(IsNavigator()) {
6
                browser.Load();
7
                SyncCursor();
8
        }
9
        navigatorframe.Show(navigator);
10
}
11

    
12
void AssistEditor::SyncCursor()
13
{
14
        String k = "(" + GetKeyDesc(IdeKeys::AK_SEARCHCODE().key[0]) + ")";
15
        browser.search.NullText(String("Find ") + k);
16
        browser.search.Tip(IsNull(browser.search) ? String() : "Clear " + k);
17
        if(IsNavigator()) {
18
                int ii = GetCursorLine();
19
                String coderef;
20
                while(ii >= 0 && IsNull(coderef))
21
                        coderef = GetAnnotation(ii--);
22
                browser.Goto(coderef, theide->editfile);
23
        }
24
}
25

    
26
void AssistEditor::SelectionChanged()
27
{
28
        CodeEditor::SelectionChanged();
29
        SyncCursor();
30
        SyncParamInfo();
31
}
32

    
33
void AssistEditor::BrowserGotoNF()
34
{
35
        Value scope = browser.scope.GetKey(); // do not scroll browser.item erratically
36
        int scopesc = browser.scope.GetScroll();
37
        String item = browser.item.GetKey();
38
        int itemsc = browser.item.GetScroll();
39

    
40
        String cref = browser.GetCodeRef();
41
        if(theide && !theide->SwapSIf(cref))
42
                theide->IdeGotoCodeRef(cref);
43

    
44
        if(scope == browser.scope.GetKey()) {
45
                browser.scope.ScrollTo(scopesc);
46
                browser.scope.ScrollIntoCursor();
47
                if(item == browser.item.GetKey()) {
48
                        browser.item.ScrollTo(itemsc);
49
                        browser.item.ScrollIntoCursor();
50
                }
51
        }
52
}
53

    
54
void AssistEditor::BrowserGoto()
55
{
56
        BrowserGotoNF();
57
        SetFocus();
58
}
59

    
60
void AssistEditor::GotoBrowserScope()
61
{
62
        if(browser.scope.IsCursor()) {
63
                Value x = browser.scope.Get(2);
64
                if(IsNumber(x)) {
65
                        int file = (int)x;
66
                        theide->EditFile(GetCppFile(file));
67
                        return;
68
                }
69
        }
70
        if(browser.item.GetCount()) {
71
                browser.item.GoBegin();
72
                BrowserGoto();
73
        }
74
}
75

    
76
void AssistEditor::Navigator(bool nav)
77
{
78
        navigator = nav;
79
        navigatorframe.Show(navigator);
80
        if(IsNavigator()) {
81
                scope_item.Show();
82
                browser.ClearSearch();
83
                SetFocus();
84
        }
85
        SyncNavigator();
86
        SyncCursor();
87
}
88

    
89
void AssistEditor::SerializeNavigator(Stream& s)
90
{
91
        int version = 1;
92
        s / version;
93
        s % navigatorframe;
94
        s % navigator;
95
        if(version >= 1)
96
                s % scope_item;
97
        Navigator(navigator);
98
}
99

    
100
void Ide::ToggleNavigator()
101
{
102
        editor.Navigator(!editor.navigator);
103
}
104

    
105
void Ide::SearchCode()
106
{
107
        if(!editor.navigator)
108
                editor.Navigator(true);
109
        if(editor.browser.search.HasFocus() && editor.browser.IsSearch())
110
                editor.browser.ClearSearch();
111
        else {
112
                String id = editor.GetI().ToString();
113
                if(!IsNull(id)) {
114
                        editor.browser.search <<= Filter(id, SearchItemFilter);
115
                        editor.browser.search.SetSelection();
116
                        editor.browser.Load();
117
                        editor.browser.scope.GoBegin();
118
                }
119
                editor.browser.search.SetFocus();
120
        }
121
}
122

    
123
void Ide::SwitchHeader() {
124
        int c = filelist.GetCursor();
125
        if(c < 0) return;
126
        String currfile = filelist[c];
127
        const char *ext = GetFileExtPos(currfile);
128
        if(!stricmp(ext, ".h") || !stricmp(ext, ".hpp")
129
        || !stricmp(ext, ".lay") || !stricmp(ext, ".iml")) {
130
                int f = filelist.Find(ForceExt(currfile, ".cpp"));
131
                if(f < 0) f = filelist.Find(ForceExt(currfile, ".c"));
132
                if(f < 0) f = filelist.Find(ForceExt(currfile, ".cc"));
133
                if(f >= 0) filelist.SetCursor(f);
134
        }
135
}