Welcome to mirror list, hosted at ThFree Co, Russian Federation.

init.lua « qtide « packages - github.com/torch/qtlua.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bd624f129ddbe21fcbb6b47926f09028299ac35f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

require 'paths'
require 'qtcore'
require 'qtgui'

if qt and qt.qApp and qt.qApp:runsWithoutGraphics() then
   print("qlua: not loading module qtide (running with -nographics)")
   return
end

qt.require 'libqtide'

local G = _G
local error = error
local dofile = dofile
local loadstring = loadstring
local print = print
local qt = qt
local string = string
local tonumber = tonumber
local tostring = tostring
local type = type
local paths = paths
local pcall = pcall

qtide = qtide or {}

-- Startup --

local qluaide = qt.QLuaIde()

local function realmode(mode)  
   local defaultmode = 'sdi'
   -- if qluaide.mdiDefault then defaultmode = 'mdi' end
   return mode or qt.qApp:readSettings("ide/mode") or defaultmode
end

function qtide.setup(mode)
   mode = realmode(mode)
   if mode == "mdi" then     -- subwindows within a big window
      local mdi = qluaide:createMdiMain()
      mdi.tabMode = false
      mdi.clientClass = "QWidget"
      mdi:adoptAll()
   elseif mode == "tab" then     -- groups all editors in tabs
      local mdi = qluaide:createMdiMain()
      mdi.tabMode = true
      mdi.clientClass = "QLuaEditor"
      mdi:adoptAll()
   elseif mode == "tab2" then    -- groups all editors + console in tabs
      local mdi = qluaide:createMdiMain()
      mdi.tabMode = true
      mdi.clientClass = "QLuaMainWindow"
      mdi:adoptAll()
   else                            -- all windows separate
      if mode ~= "sdi" then
         print("Warning: The recognized ide styles are: sdi, mdi, tab")
         mode = 'sdi'
      end
      local mdi = qt.qLuaMdiMain
      if mdi then
         mdi:hide()
         mdi.tabMode = false
         mdi.clientClass = "-none"
         mdi:adoptAll()
         mdi:deleteLater()
      end
   end
   qt.qApp:writeSettings("ide/mode", mode)
end

function qtide.start(mode)
   qtide.setup(mode)
   if not qt.qLuaSdiMain then
      qluaide:createSdiMain()
      qluaide.editOnError = true
   end
end



-- Editor --

function qtide.editor(s)
   local e = qluaide:editor(s or "")
   if e == nil and type(s) == "string" then
      error(string.format("Unable to read file '%s'", s))
   end
   return e
end


function qtide.doeditor(e)
   -- validate parameter
   if not qt.isa(e, 'QLuaEditor*') then 
      error(string.format("QLuaEditor expected, got %s.", s)); 
   end
   -- retrieve text
   local n = "qt." .. tostring(e.objectName)
   local currentfile = nil;
   if e.fileName:tobool() then
      currentfile = e.fileName:tostring()
   end
   if (currentfile and not e.windowModified) then
      dofile(currentfile)
   else
      -- load data from editor
      local chunk, m = loadstring(e:widget().plainText:tostring(), n)
      if not chunk then
         print(m)
         -- error while parsing the data
         local _,_,l,m = string.find(m,"^%[string.*%]:(%d+): +(.*)")
         if l and m and qluaide.editOnError then 
            e:widget():showLine(tonumber(l)) 
            e:showStatusMessage(m)
         end
      else
         -- execution starts
         chunk()
      end
   end
end


-- Inspector --

function qtide.inspector(...)
   error("Function qtide.inspector is not yet working")
end





-- Browser --

function qtide.browser(url)
   return qluaide:browser(url or "about:/")
end


-- Help --

local function locate_help_files()
   local appname = qt.qApp.applicationName:tostring()
   local html = paths.install_html or "."
   local index1 = paths.concat(html, appname:lower(), "index.html")
   local index2 = paths.concat(html,"index.html")
   if index1 and paths.filep(index1) then
      return qt.QUrl.fromlocalfile(index1)
   elseif index2 and paths.filep(index2) then
      return qt.QUrl.fromlocalfile(index2)
   else
      return qt.QUrl("http://torch.ch/#packages")
   end
end


helpbrowser = nil
helpurl = locate_help_files()

function qtide.help()
   local appname = qt.qApp.applicationName:tostring()
   if not helpurl then
      error("The html help files are not installed.")
   end
   if not qt.isa(helpbrowser, "QWidget") then
      helpbrowser = qluaide:browser()
   end
   helpbrowser.baseTitle =  appname .. " Help Browser"
   helpbrowser.homeUrl = helpurl;
   helpbrowser.url = helpurl
   helpbrowser:raise()
   return helpbrowser
end

qt.disconnect(qluaide, 'helpRequested(QWidget*)')
qt.connect(qluaide,'helpRequested(QWidget*)', 
           function(main) 
              local success, message = pcall(help)
              if not success and type(message) == "string" then
                 qluaide:messageBox("QLua Warning", message)
              end
           end)


-- Preferences --


function qtide.preferences()
   G.require 'qtide.prefs'
   local d = prefs.createPreferencesDialog()
   if d and d.dialog:exec() > 0 then
      prefs.savePreferences(d)
   end
end

qt.disconnect(qluaide,'prefsRequested(QWidget*)')
qt.connect(qluaide,'prefsRequested(QWidget*)',
           function(main) 
              local success, message = pcall(preferences)
              if not success and type(message) == "string" then
                 qluaide:messageBox("QLua Warning", message)
              end
           end)

return qtide